From 9703dd782af4d87af8a944a054aa133a699030a4 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期六, 22 二月 2025 20:23:34 +0800
Subject: [PATCH] 优化、bug
---
business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java | 39 +++++++++++++++++++++++++++++++++++++--
1 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java
index 4bdbcd7..7f9ff2e 100644
--- a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java
+++ b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java
@@ -116,6 +116,9 @@
if (ProjectConstant.COMMIT.equals(entity.getUsedStatus()) && ProjectStatusEnum.PENDDING.getType().equals(entity.getProjectStatus())) {
entity.setUsedStatus(ProjectConstant.PASS);
}
+ if(!checkProjectNameAndIdIsUnique(entity,null)){
+ return Result.error("椤圭洰閲嶅锛岄」鐩悕绉般�侀」鐩爜宸插瓨鍦�");
+ }
baseMapper.insert(entity);
addPlan(entity.getId()); //娣诲姞璁″垝琛�
//娣诲姞鏂囦欢
@@ -133,6 +136,32 @@
return Result.ok("娣诲姞鎴愬姛").data(entity.getId());
}
+ /**
+ * 鍒ゆ柇椤圭洰鍚嶅拰椤圭洰鐮佹槸鍚﹀敮涓�
+ * @param entity from true 鏉ヨ嚜add() false 鏉ヨ嚜edit()
+ * @return
+ */
+ public boolean checkProjectNameAndIdIsUnique(ProjectInfo entity,Long updateId){
+ QueryWrapper<ProjectInfo> queryWrapper = new QueryWrapper<ProjectInfo>();
+ if (updateId == null) {
+
+ queryWrapper.eq("project_name", entity.getProjectName());
+
+ if (StringUtils.isNotEmpty(entity.getProjectCode())) {
+ queryWrapper.eq("project_code", entity.getProjectCode());
+ }
+
+ List<ProjectInfo> project = projectInfoMapper.selectList(queryWrapper);
+
+ return project == null || project.isEmpty();
+ }else {
+
+ List<ProjectInfo> project = projectInfoMapper.checkProjectNameAndIdIsUnique(updateId,entity.getProjectName(),entity.getProjectCode());
+
+ return project == null || project.isEmpty();
+ }
+
+ }
public void addPlan(Long projectInfoId) {
Plan plan = new Plan();
@@ -154,6 +183,7 @@
@Override
public Result update(ProjectInfoForm form) {
ProjectInfo entity = baseMapper.selectById(form.getId());
+
// 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊
Assert.notNull(entity, "璁板綍涓嶅瓨鍦�");
ProjectInfoForm.getEntityByForm(form, entity);
@@ -162,6 +192,9 @@
//濡傛灉鏄偍澶囬」鐩�(鏈紑宸ラ」鐩�)涓嶉渶瑕佸鏍�
if (ProjectConstant.COMMIT.equals(entity.getUsedStatus()) && ProjectStatusEnum.PENDDING.getType().equals(entity.getProjectStatus())) {
entity.setUsedStatus(ProjectConstant.PASS);
+ }
+ if(!checkProjectNameAndIdIsUnique(entity,form.getId())){
+ return Result.error("椤圭洰閲嶅锛岄」鐩悕绉般�侀」鐩爜宸插瓨鍦�");
}
//鏇存柊椤圭洰淇℃伅
baseMapper.updateById(entity);
@@ -775,12 +808,14 @@
@Transactional(rollbackFor = Exception.class)
public Result editProject(ProjectForm form) {
if (ObjectUtil.isNotNull(form.getProjectInfoForm())) {
+
if (ObjectUtil.isNull(form.getProjectInfoForm().getId())) {
//鏂板
- ((ProjectInfoServiceImpl) AopContext.currentProxy()).add(form.getProjectInfoForm());
+ return ((ProjectInfoServiceImpl) AopContext.currentProxy()).add(form.getProjectInfoForm());
+
} else {
//鏇存柊
- ((ProjectInfoServiceImpl) AopContext.currentProxy()).update(form.getProjectInfoForm());
+ return ((ProjectInfoServiceImpl) AopContext.currentProxy()).update(form.getProjectInfoForm());
}
}
if (ObjectUtil.isNotNull(form.getProjectInvestmentInfoForm())) {
--
Gitblit v1.8.0