|
@@ -4087,15 +4087,36 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
//兼容中英文逗号
|
|
|
String[] subNames = subNameCell.getStringCellValue().trim().split(",|\\,");
|
|
|
if (subNames != null) {
|
|
|
- subProjectMapper.delete(new QueryWrapper<SubProject>().eq("project_id",project.getId()));
|
|
|
+ //执行插入,删除操作。不能全部删除,避免已经有的子项目被填写了工时,而造成查不到的情况
|
|
|
+ List<SubProject> subProjectList = subProjectMapper.selectList(new QueryWrapper<SubProject>().eq("project_id",project.getId()));
|
|
|
+ List<Integer> readyToRemoveIds = subProjectList.stream().filter(subProject -> {
|
|
|
+ boolean notExist = true;
|
|
|
+ for (String s : subNames) {
|
|
|
+ if (!StringUtils.isEmpty(s)) {
|
|
|
+ if (subProject.getName().equals(s)) {
|
|
|
+ //找到了本次有的子项目
|
|
|
+ notExist = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return notExist;
|
|
|
+ }).map(SubProject::getId).collect(Collectors.toList());
|
|
|
+ if (readyToRemoveIds.size() > 0) {
|
|
|
+ subProjectMapper.deleteBatchIds(readyToRemoveIds);
|
|
|
+ }
|
|
|
for (String s : subNames) {
|
|
|
if (!StringUtils.isEmpty(s)) {
|
|
|
- SubProject sp = new SubProject();
|
|
|
- sp.setName(s);
|
|
|
- sp.setProjectId(project.getId());
|
|
|
- subProjectMapper.insert(sp);
|
|
|
+ //数据库里面没有的子项目,新增进来
|
|
|
+ if (!subProjectList.stream().anyMatch(subProject -> s.equals(subProject.getName()))) {
|
|
|
+ SubProject sp = new SubProject();
|
|
|
+ sp.setName(s);
|
|
|
+ sp.setProjectId(project.getId());
|
|
|
+ sp.setCompanyId(user.getCompanyId());
|
|
|
+ subProjectMapper.insert(sp);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}else {
|