diff --git a/src/main/java/com/yipin/liuwanr/controller/Project_ManagementController.java b/src/main/java/com/yipin/liuwanr/controller/Project_ManagementController.java index 3100dae..2749de7 100644 --- a/src/main/java/com/yipin/liuwanr/controller/Project_ManagementController.java +++ b/src/main/java/com/yipin/liuwanr/controller/Project_ManagementController.java @@ -372,4 +372,30 @@ public class Project_ManagementController { } return resp; } + + + /** + * 判断项目名称是否存在 + * @param projectName + * @return + */ + @GetMapping("/isNameExistis") + Response isNameExistis(@RequestParam String projectName){ + Response resp = new Response(); + if (StringUtils.isEmpty(projectName)) { + resp.setStatus(300); + resp.setMessage("项目名称为空"); + }else{ + HashMap ret = service.getByName(projectName); + int status = (int) ret.get("retcode"); + if (status == 200) { + resp.setStatus(status); + resp.setMessage(ret.get("retvalue")); + } else { + resp.setStatus(status); + resp.setErrmessage(ret.get("retvalue").toString()); + } + } + return resp; + } } diff --git a/src/main/java/com/yipin/liuwanr/service/Project_ManagementService.java b/src/main/java/com/yipin/liuwanr/service/Project_ManagementService.java index a9e52fc..b952728 100644 --- a/src/main/java/com/yipin/liuwanr/service/Project_ManagementService.java +++ b/src/main/java/com/yipin/liuwanr/service/Project_ManagementService.java @@ -401,16 +401,9 @@ public class Project_ManagementService { * @return */ @Transactional - public HashMap insertProjectManagement(Project_Management pro, List points, - List roles) { + public HashMap insertProjectManagement(Project_Management pro, List points, List roles) { HashMap resp = new HashMap(); try { - String projectName = pro.getProjectName(); - Integer count = mapper.getByprojectName(projectName); - if (count != null) { - projectName += (count + 1); - pro.setProjectName(projectName); - } // 添加项目信息 mapper.insertProjectManagement(pro); // 取出添加的项目信息的id @@ -472,6 +465,25 @@ public class Project_ManagementService { } + public HashMap getByName(String projectName){ + HashMap resp = new HashMap(); + try{ + Integer count = mapper.getByprojectName(projectName); + if(count>1){ + resp.put("retcode", 300); + resp.put("retvalue", "该项目名称已存在"); + }else{ + resp.put("retcode", 200); + } + }catch (RuntimeException e){ + logger.error(e.getMessage()); + resp.put("retcode", 500); + resp.put("retvalue", "QUERY Failed"); + throw new RuntimeException(); + } + return resp; + } + /** * 修改项目管理信息 * @@ -590,17 +602,6 @@ public class Project_ManagementService { // 修改对应角色的项目id mapper.updateRoleProjectId(roleid, project); } - //项目名称去重 - String projectName = pro.getProjectName(); - - String name = mapper.getNameByProjectId(pro.getProjectId()); - if (projectName != null && !projectName.equals(name)) { - Integer count = mapper.getByprojectName(projectName); - if (count != null && count > 1) { - projectName += (count + 1); - pro.setProjectName(projectName); - } - } //修改项目信息 mapper.updateProjectManagement(pro);