新增项目名称是否存在接口

master
pd 4 years ago
parent b62d61d468
commit b02bee632b
  1. 26
      src/main/java/com/yipin/liuwanr/controller/Project_ManagementController.java
  2. 39
      src/main/java/com/yipin/liuwanr/service/Project_ManagementService.java

@ -372,4 +372,30 @@ public class Project_ManagementController {
} }
return resp; 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<String, Object> 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;
}
} }

@ -401,16 +401,9 @@ public class Project_ManagementService {
* @return * @return
*/ */
@Transactional @Transactional
public HashMap<String, Object> insertProjectManagement(Project_Management pro, List<Judgment_Points> points, public HashMap<String, Object> insertProjectManagement(Project_Management pro, List<Judgment_Points> points, List<Integer> roles) {
List<Integer> roles) {
HashMap<String, Object> resp = new HashMap<String, Object>(); HashMap<String, Object> resp = new HashMap<String, Object>();
try { try {
String projectName = pro.getProjectName();
Integer count = mapper.getByprojectName(projectName);
if (count != null) {
projectName += (count + 1);
pro.setProjectName(projectName);
}
// 添加项目信息 // 添加项目信息
mapper.insertProjectManagement(pro); mapper.insertProjectManagement(pro);
// 取出添加的项目信息的id // 取出添加的项目信息的id
@ -472,6 +465,25 @@ public class Project_ManagementService {
} }
public HashMap<String, Object> getByName(String projectName){
HashMap<String, Object> resp = new HashMap<String, Object>();
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 // 修改对应角色的项目id
mapper.updateRoleProjectId(roleid, project); 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); mapper.updateProjectManagement(pro);

Loading…
Cancel
Save