From b02bee632be6c886b422a4cc7aa58d9c8aff1053 Mon Sep 17 00:00:00 2001 From: pd <2776455882@qq.com> Date: Tue, 28 Jul 2020 20:28:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Project_ManagementController.java | 26 +++++++++++++ .../service/Project_ManagementService.java | 39 ++++++++++--------- 2 files changed, 46 insertions(+), 19 deletions(-) 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);