use of com.itrus.portal.db.VersionChange in project portal by ixinportal.
the class ProjectKeyInfoController method updateSnProject.
// 修正序列号项目归属
@RequestMapping("/updateSnProject")
@ResponseBody
public Map<String, Object> updateSnProject(@RequestParam(value = "projectId", required = true) Long projectId) {
Map<String, Object> map = new HashMap<String, Object>();
// 10000代表处理成功
map.put("retCode", "10000");
// 检查是否有权限操作
Long[] projects = getProjectLongIdsOfAdmin();
List<Long> list = Arrays.asList(projects);
Long adminProject = getProjectOfAdmin();
if (list != null && !list.contains(projectId)) {
map.put("retCode", "10001");
map.put("retMsg", "您不能进行该操作");
return map;
}
if (projectId.toString().equals("0")) {
map.put("retCode", "10002");
map.put("retMsg", "请先选择一个项目进行修正");
return map;
}
// 1、查询对应项目下的 所有 序列号配置;
ProjectKeyInfoExample projectKeyInfoExample = new ProjectKeyInfoExample();
ProjectKeyInfoExample.Criteria projectKeyInfoCriteria = projectKeyInfoExample.or();
projectKeyInfoCriteria.andProjectEqualTo(projectId);
List<ProjectKeyInfo> projectKeyInfos = sqlSession.selectList("com.itrus.portal.db.ProjectKeyInfoMapper.selectByExample", projectKeyInfoExample);
int updateNum = 0;
if (!projectKeyInfos.isEmpty()) {
// 2、基于所有序列号配置,组织查询语句,将该项目的软件更新记录全部查询处理
for (ProjectKeyInfo projectKeyInfo : projectKeyInfos) {
if (StringUtils.isBlank(projectKeyInfo.getSn1())) {
// sn1为空 不进行处理
continue;
}
VersionChange versionChange = new VersionChange();
// 设置正确的projet
versionChange.setProject(projectKeyInfo.getProject());
VersionChangeExample example = new VersionChangeExample();
VersionChangeExample.Criteria criteria = example.or();
// 非该项目的软件更新记录
criteria.andProjectNotEqualTo(projectKeyInfo.getProject());
if (!projectKeyInfo.getSn1().endsWith("$")) {
if (StringUtils.isNotBlank(projectKeyInfo.getSn2())) {
// 范围匹配 sn1和sn2都存在
criteria.andKeySnBetween(projectKeyInfo.getSn1(), projectKeyInfo.getSn2());
} else {
// 前缀匹配 只有sn1
criteria.andKeySnLike(projectKeyInfo.getSn1() + "%");
}
} else if (projectKeyInfo.getSn1().endsWith("$")) {
// 后缀匹配 sn1以$结尾
String sn1 = projectKeyInfo.getSn1().substring(0, projectKeyInfo.getSn1().length() - 1);
criteria.andKeySnLike("%" + sn1);
} else {
continue;
}
// 查询需要修改的总数
Integer num = sqlSession.selectOne("com.itrus.portal.db.VersionChangeMapper.countByExample", example);
updateNum += num;
// 3、逐条处理查询出来的记录,如果记录的项目不是当前项目,则进行修正
// 执行批量修改
Map<String, Object> retmap = new HashMap<String, Object>();
retmap.put("record", versionChange);
retmap.put("example", example);
sqlSession.update("com.itrus.portal.db.VersionChangeMapper.updateByExampleSelective", retmap);
}
}
VersionChangeExample vexample = new VersionChangeExample();
VersionChangeExample.Criteria vcriteria = vexample.or();
vcriteria.andProjectEqualTo(projectId);
Integer projectAllNum = sqlSession.selectOne("com.itrus.portal.db.VersionChangeMapper.countByExample", vexample);
// 4、修正完成后显示结果:a 修正记录数 b 项目当前 软件更新记录 数
// 修改的总记录数
map.put("updateNum", updateNum);
// 该项目软件更新总记录数
map.put("projectAllNum", projectAllNum);
return map;
}
Aggregations