|
@@ -12,9 +12,11 @@ import com.management.platform.mapper.CustomerInfoMapper;
|
|
|
import com.management.platform.mapper.ProjectMapper;
|
|
|
import com.management.platform.mapper.ReportExtraDegreeMapper;
|
|
|
import com.management.platform.mapper.UserMapper;
|
|
|
+import com.management.platform.service.ProjectService;
|
|
|
import com.management.platform.service.ReportExtraDegreeService;
|
|
|
import com.management.platform.service.ReportService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.apache.poi.util.StringUtil;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
@@ -23,9 +25,11 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -45,6 +49,10 @@ public class ReportExtraDegreeController {
|
|
|
UserMapper userMapper;
|
|
|
@Resource
|
|
|
ReportExtraDegreeMapper reportExtraDegreeMapper;
|
|
|
+ @Resource
|
|
|
+ ProjectMapper projectMapper;
|
|
|
+ @Resource
|
|
|
+ ProjectService projectService;
|
|
|
|
|
|
/**
|
|
|
* addOrMod添加或者修改
|
|
@@ -61,8 +69,39 @@ public class ReportExtraDegreeController {
|
|
|
reportExtraDegreeMapper.insert(info);
|
|
|
} else {
|
|
|
info.setCompanyId(user.getCompanyId());
|
|
|
- reportExtraDegreeMapper.updateById(info);
|
|
|
+ //检查名字是否发生变化
|
|
|
+ ReportExtraDegree reportExtraDegree = reportExtraDegreeMapper.selectById(info.getId());
|
|
|
+ if (!reportExtraDegree.getName().equals(info.getName())) {
|
|
|
+ //检查是否已经被使用
|
|
|
+ int id = info.getId();
|
|
|
+ List<Project> existsProjects = projectMapper.selectList(new QueryWrapper<Project>()
|
|
|
+ .eq("company_id", user.getCompanyId())
|
|
|
+ .and(wrapper->wrapper.eq("associate_degrees", id)
|
|
|
+ .or().like("associate_degrees", id+",%")
|
|
|
+ .or().like("associate_degrees", "%,"+id+",%")
|
|
|
+ .or().like("associate_degrees", "%,"+id)));
|
|
|
+ if (existsProjects.size() > 0) {
|
|
|
+ List<Project> updateList = new ArrayList<>();
|
|
|
+ for (Project p : existsProjects) {
|
|
|
+ String associateDegrees = p.getAssociateDegrees();
|
|
|
+ String[] split = associateDegrees.split("\\,");
|
|
|
+ String[] names = p.getAssociateDegreeNames().split("\\,");
|
|
|
|
|
|
+ for (int i=0;i<split.length; i++) {
|
|
|
+ if (split[i].equals(id+"")) {
|
|
|
+ names[i] = info.getName();//更换新名字
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String replaceNames = StringUtil.join(names, ",");
|
|
|
+ Project newP = new Project();
|
|
|
+ newP.setId(p.getId());
|
|
|
+ newP.setAssociateDegreeNames(replaceNames);
|
|
|
+ updateList.add(newP);
|
|
|
+ }
|
|
|
+ projectService.updateBatchById(updateList);
|
|
|
+ }
|
|
|
+ reportExtraDegreeMapper.updateById(info);
|
|
|
+ }
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
@@ -77,6 +116,17 @@ public class ReportExtraDegreeController {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
String token = request.getHeader("TOKEN");
|
|
|
User user = userMapper.selectById(token);
|
|
|
+ //检查是否已经被使用
|
|
|
+ List<Project> existsProjects = projectMapper.selectList(new QueryWrapper<Project>()
|
|
|
+ .eq("associate_degrees", id)
|
|
|
+ .or().like("associate_degrees", id+",%")
|
|
|
+ .or().like("associate_degrees", "%,"+id+",%")
|
|
|
+ .or().like("associate_degrees", "%,"+id));
|
|
|
+ if (existsProjects.size() > 0) {
|
|
|
+ String names = existsProjects.stream().map(Project::getProjectName).collect(Collectors.joining(","));
|
|
|
+ msg.setError("该数据已经被以下项目关联,无法删除:"+names);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
int r = reportExtraDegreeMapper.delete(new QueryWrapper<ReportExtraDegree>().eq("id", id).eq("company_id", user.getCompanyId()));
|
|
|
if (r <= 0) {
|
|
|
msg.setError("无权删除");
|