From cdd6551b190b981b807a3b95e9635c559ccc769d Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期一, 19 五月 2025 09:45:07 +0800
Subject: [PATCH] git ch

---
 server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java |  169 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 105 insertions(+), 64 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java
index 73b4e79..f3210d9 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java
@@ -10,10 +10,7 @@
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.*;
 import com.doumee.dao.business.dto.*;
-import com.doumee.dao.business.join.DispatchUnitJoinMapper;
-import com.doumee.dao.business.join.DuLogJoinMapper;
-import com.doumee.dao.business.join.DuSolutionJoinMapper;
-import com.doumee.dao.business.join.DuWorkTypeJoinMapper;
+import com.doumee.dao.business.join.*;
 import com.doumee.dao.business.model.*;
 import com.doumee.dao.system.model.SystemUser;
 import com.doumee.service.business.DispatchUnitService;
@@ -49,6 +46,9 @@
 
     @Autowired
     private DuSolutionMapper duSolutionMapper;
+
+    @Autowired
+    private SolutionWorktypeJoinMapper solutionWorktypeJoinMapper;
 
     @Autowired
     private DuWorktypeMapper    duWorktypeMapper;
@@ -102,10 +102,9 @@
         dispatchUnitMapper.updateById(update);
         if(Constants.equalsInteger(param.getWorktypeStatus(),Constants.ONE)){
             //瀹℃牳閫氳繃锛屼慨鏀圭姸鎬侊紝浜х敓鍘嗗彶鐗堟湰
-            newVersionData(dispatchUnitMapper.selectById(param.getId()),update);
+            newVersionData(model,update,false);
             //瀛樺偍鎿嶄綔鍘嗗彶
             this.saveDuLog(update,Constants.DispatchUnitLogType.WORK_TYPE_AUDIT_PASS,update.getCheckInfo());
-
         }else{
             //鏇存柊鏄庣粏鏁版嵁涓哄鏍稿け璐�
             duSolutionMapper.update(null,new UpdateWrapper<DuSolution>().lambda()
@@ -136,23 +135,34 @@
         return  1;
     }
 
-    private void newVersionData(DispatchUnit model, DispatchUnit update) {
-        dispatchUnitMapper.update(null,new UpdateWrapper<DispatchUnit>().lambda()
-                .set(DispatchUnit::getDataType,Constants.ZERO)
-                .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
-                .eq(DispatchUnit::getBaseId,model.getId()));
+    private void newVersionData(DispatchUnit model, DispatchUnit update,Boolean flag) {
         DispatchUnit newVersion = new DispatchUnit();
-        BeanUtils.copyProperties(model, newVersion);
-        newVersion.setWorktypeStatus(Constants.ONE);
-        newVersion.setCheckDate(update.getEditDate());
-        newVersion.setCheckUserId(update.getCheckUserId());
-        newVersion.setCheckInfo(update.getCheckInfo());
-        newVersion.setCreateDate(update.getCreateDate());
-        newVersion.setCreator(update.getEditor());
-        newVersion.setBaseId(model.getBaseId());
-        newVersion.setDataType(Constants.TWO);
-        dispatchUnitMapper.insert(newVersion);
-
+        if(flag){
+            dispatchUnitMapper.update(null,new UpdateWrapper<DispatchUnit>().lambda()
+                    .set(DispatchUnit::getDataType,Constants.ZERO)
+                    .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
+                    .eq(DispatchUnit::getBaseId,model.getId()));
+            BeanUtils.copyProperties(model, newVersion);
+            newVersion.setWorktypeStatus(Constants.ONE);
+            newVersion.setCheckDate(update.getEditDate());
+            newVersion.setCheckUserId(update.getCheckUserId());
+            newVersion.setCheckInfo(update.getCheckInfo());
+            newVersion.setStatus(Constants.ZERO);
+            newVersion.setCreateDate(update.getCreateDate());
+            newVersion.setCreator(update.getEditor());
+            newVersion.setBaseId(model.getId());
+            newVersion.setDataType(Constants.TWO);
+            dispatchUnitMapper.insert(newVersion);
+        }else{
+            newVersion = dispatchUnitMapper.selectOne(new QueryWrapper<DispatchUnit>().lambda()
+                    .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
+                    .eq(DispatchUnit::getDataType,Constants.TWO)
+                    .eq(DispatchUnit::getBaseId,model.getId())
+                    .last(" limit 1"));
+        }
+        if(Objects.isNull(newVersion)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌娲鹃仯鍗曚綅鏈�鏂扮増鏈�");
+        }
         List<DuWorktype> newWorktypes = new ArrayList<>();
         List<DuSolution> solutions = duSolutionMapper.selectList(new QueryWrapper<DuSolution>().lambda()
                 .eq(DuSolution::getIsdeleted,Constants.ZERO)
@@ -169,13 +179,13 @@
         );
 
 
-
         if(solutions == null || solutions.size() ==0){
             throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝璇ユ淳閬e崟浣嶆湭璁剧疆鏂规宸ョ淇℃伅锛屽鏍搁�氳繃澶辫触锛�");
         }
         for (DuSolution s : solutions){
             DuSolution ns = new DuSolution();
             BeanUtils.copyProperties(s, ns);
+            ns.setId(null);
             ns.setDispatchUnitId(newVersion.getId());
             ns.setCheckDate(update.getEditDate());
             ns.setStatus(Constants.ONE);
@@ -201,8 +211,13 @@
 
 
             for (DuWorktype w : worktypes) {
+                if(Constants.equalsInteger(w.getStatus(),Constants.TWO)){
+                    continue;
+                }
                 DuWorktype nw = new DuWorktype();
                 BeanUtils.copyProperties(w, nw);
+                nw.setId(null);
+                nw.setCreateDate(new Date());
                 nw.setCheckDate(update.getEditDate());
                 nw.setStatus(Constants.ONE);
                 nw.setDuSolutionId(ns.getId());
@@ -247,7 +262,7 @@
         DispatchUnit dispatchUnit = dispatchUnitMapper.selectById(param.getId());
         if(Constants.equalsInteger(param.getUnitStatus(),Constants.ONE)){
             //瀹℃牳閫氳繃锛屼慨鏀圭姸鎬侊紝浜х敓鍘嗗彶鐗堟湰
-            newVersionData(dispatchUnit,update);
+            newVersionData(dispatchUnit,update,true);
             //瀛樺偍鎿嶄綔鍘嗗彶
             this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.AUDIT_PASS,update.getCheckInfo());
         }else{
@@ -276,7 +291,6 @@
         //鍒犻櫎鍏朵粬寰呭姙
         noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,dispatchUnit.getId()));
 
-
         return  1;
     }
     @Override
@@ -284,8 +298,6 @@
     public Integer create(SaveDispatchUnitDTO saveDispatchUnitDTO) {
         if(Objects.isNull(saveDispatchUnitDTO)
             || StringUtils.isEmpty(saveDispatchUnitDTO.getName())
-            || StringUtils.isEmpty(saveDispatchUnitDTO.getCode())
-            || StringUtils.isEmpty(saveDispatchUnitDTO.getContent())
             || CollectionUtils.isEmpty(saveDispatchUnitDTO.getSaveDuSolutionDTOList())
         ){
             throw new BusinessException(ResponseStatus.BAD_REQUEST);
@@ -295,16 +307,17 @@
                 .eq(DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
                 .eq(DispatchUnit::getName,saveDispatchUnitDTO.getName())
                 .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
+                .eq(DispatchUnit::getDataType,Constants.ZERO)
         )> Constants.ZERO){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆愭淳閬e崟浣嶅悕绉般�戝凡瀛樺湪");
         };
-        if(dispatchUnitMapper.selectCount(new QueryWrapper<DispatchUnit>().lambda()
-                .eq(DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
-                .eq(DispatchUnit::getCode,saveDispatchUnitDTO.getCode())
-                .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
-        )> Constants.ZERO){
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆愭淳閬e崟浣嶄俊鐢ㄤ唬鐮併�戝凡瀛樺湪");
-        };
+//        if(dispatchUnitMapper.selectCount(new QueryWrapper<DispatchUnit>().lambda()
+//                .eq(DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
+//                .eq(DispatchUnit::getCode,saveDispatchUnitDTO.getCode())
+//                .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
+//        )> Constants.ZERO){
+//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆愭淳閬e崟浣嶄俊鐢ㄤ唬鐮併�戝凡瀛樺湪");
+//        };
         DispatchUnit dispatchUnit = new DispatchUnit();
         dispatchUnit.setCreateDate(new Date());
         dispatchUnit.setCreator(loginUserInfo.getId());
@@ -371,7 +384,6 @@
             }
         }
 
-
         //瀛樺偍寰呭姙淇℃伅
         Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.DISPATCH_UNIT;
         //鍒犻櫎鍏朵粬寰呭姙
@@ -399,20 +411,14 @@
         }
         if(dispatchUnitMapper.selectCount(new QueryWrapper<DispatchUnit>().lambda()
                 .ne(DispatchUnit::getId,saveDispatchUnitDTO.getId())
+                .ne(DispatchUnit::getBaseId,saveDispatchUnitDTO.getId())
                 .eq(DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
                 .eq(DispatchUnit::getName,saveDispatchUnitDTO.getName())
                 .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
+                .eq(DispatchUnit::getDataType,Constants.ZERO)
         )> Constants.ZERO){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆愭淳閬e崟浣嶅悕绉般�戝凡瀛樺湪");
         };
-        if(dispatchUnitMapper.selectCount(new QueryWrapper<DispatchUnit>().lambda()
-                .ne(DispatchUnit::getId,saveDispatchUnitDTO.getId())
-                .eq(DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
-                .eq(DispatchUnit::getCode,saveDispatchUnitDTO.getCode())
-                .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
-        )> Constants.ZERO){
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆愭淳閬e崟浣嶄俊鐢ㄤ唬鐮併�戝凡瀛樺湪");
-        }
         dispatchUnit.setCode(saveDispatchUnitDTO.getCode());
         dispatchUnit.setContent(saveDispatchUnitDTO.getContent());
         dispatchUnit.setName(saveDispatchUnitDTO.getName());
@@ -421,11 +427,13 @@
         dispatchUnit.setEditor(loginUserInfo.getId());
         dispatchUnitMapper.updateById(dispatchUnit);
 
+        dispatchUnitMapper.update(null,new UpdateWrapper<DispatchUnit>().lambda().set(DispatchUnit::getDataType,Constants.ONE).eq(DispatchUnit::getBaseId,dispatchUnit.getId())
+                .eq(DispatchUnit::getDataType,Constants.TWO)
+        );
+
+
         //瀛樺偍鎿嶄綔璁板綍
         this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.EDIT_UNIT,null);
-
-//        this.dealDuData(saveDispatchUnitDTO,loginUserInfo);
-
 
         //瀛樺偍寰呭姙淇℃伅
         Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.DISPATCH_UNIT;
@@ -455,6 +463,9 @@
         }
         LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         DispatchUnit dispatchUnit = this.dispatchUnitMapper.selectById(saveDispatchUnitDTO.getId());
+        if(!dispatchUnit.getUnitStatus().equals(Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"娲鹃仯鍗曚綅鏈鎵归�氳繃,鏃犳硶杩涜璇ユ搷浣�");
+        }
         dispatchUnit.setWorktypeStatus(Constants.ZERO);
         dispatchUnit.setEditDate(new Date());
         dispatchUnit.setEditor(loginUserInfo.getId());
@@ -489,7 +500,7 @@
             DuSolution duSolution = duSolutionMapper.selectOne(new QueryWrapper<DuSolution>().lambda().eq(DuSolution::getDispatchUnitId,saveDispatchUnitDTO.getId())
                     .eq(DuSolution::getIsdeleted,Constants.ZERO)
                     .eq(DuSolution::getSolutionId,saveDuSolutionDTO.getSolutionId()).last("limit 1"));
-            Integer duSolutionNum = duSolutionMapper.selectCount(new QueryWrapper<DuSolution>().lambda().eq(DuSolution::getDispatchUnitId,saveDuSolutionDTO.getId()));
+            Integer duSolutionNum = duSolutionMapper.selectCount(new QueryWrapper<DuSolution>().lambda().eq(DuSolution::getDispatchUnitId,saveDuSolutionDTO.getId())).intValue();
             if(Objects.isNull(duSolution)){
                 duSolution = new DuSolution();
                 duSolution.setCreateDate(new Date());
@@ -510,13 +521,18 @@
                 if(Objects.isNull(saveDuWorkTypeDTO.getWorkTypeId())){
                     throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+saveDuSolutionDTO.getSolutionName()+"銆戣鏂规涓�"+saveDuWorkTypeDTO.getWorkTypeName()+"璇ュ伐绉嶄俊鎭紓甯�");
                 }
+                //楠岃瘉鏂规涓庡伐绉嶇殑鍏崇郴
+                if(solutionWorktypeJoinMapper.selectCount(new QueryWrapper<SolutionWorktype>().lambda().eq(SolutionWorktype::getSolutionId,saveDuSolutionDTO.getSolutionId())
+                        .eq(SolutionWorktype::getWorktypeId,saveDuWorkTypeDTO.getWorkTypeId()))<=0){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+saveDuSolutionDTO.getSolutionName()+"銆戣鏂规涓�"+saveDuWorkTypeDTO.getWorkTypeName()+"璇ュ伐绉嶄俊鎭棤缁戝畾鍏崇郴");
+                };
                 if(duWorktypeMapper.selectCount(new QueryWrapper<DuWorktype>()
                         .lambda().eq(DuWorktype::getDuSolutionId,duSolution.getId())
                         .eq(DuWorktype::getIsdeleted,Constants.ZERO)
                         .eq(DuWorktype::getWorkTypeId,saveDuWorkTypeDTO.getWorkTypeId()))>0){
                     throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+saveDuSolutionDTO.getSolutionName()+"銆戣鏂规涓�"+saveDuWorkTypeDTO.getWorkTypeName()+"璇ュ伐绉嶅凡瀛樺湪");
                 }
-                Integer duWorkTypeNum = duWorktypeMapper.selectCount(new QueryWrapper<DuWorktype>().lambda().eq(DuWorktype::getDuSolutionId,duSolution.getId()));
+                Integer duWorkTypeNum = duWorktypeMapper.selectCount(new QueryWrapper<DuWorktype>().lambda().eq(DuWorktype::getDuSolutionId,duSolution.getId())).intValue();
                 DuWorktype duWorktype = new DuWorktype();
                 duWorktype.setCreateDate(new Date());
                 duWorktype.setCreator(loginUserInfo.getId());
@@ -668,7 +684,20 @@
 
     @Override
     public void deleteById(Integer id) {
-        dispatchUnitMapper.deleteById(id);
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        DispatchUnit dispatchUnit = dispatchUnitMapper.selectById(id);
+        if(Objects.isNull(dispatchUnit)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY);
+        }
+        if(dispatchUnit.getUnitStatus().equals(Constants.TWO)){
+            dispatchUnitMapper.update(null,new UpdateWrapper<DispatchUnit>().lambda()
+                            .set(DispatchUnit::getEditor,loginUserInfo.getId())
+                        .set(DispatchUnit::getEditDate,new Date())
+                    .set(DispatchUnit::getIsdeleted,Constants.ONE)
+                    .eq(DispatchUnit::getId,id));
+        }else{
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠娲鹃仯鍗曚綅鐘舵�佹棤娉曡繘琛岃鎿嶄綔");
+        }
     }
 
     @Override
@@ -688,6 +717,14 @@
     @Override
     public void updateById(DispatchUnit dispatchUnit) {
         dispatchUnitMapper.updateById(dispatchUnit);
+        //鏇存柊鍘嗗彶琛ㄧ姸鎬�
+        if(Objects.nonNull(dispatchUnit.getId())&& Objects.nonNull(dispatchUnit.getStatus())){
+            dispatchUnitMapper.update(null,new UpdateWrapper<DispatchUnit>().lambda()
+                    .set(DispatchUnit::getStatus,dispatchUnit.getStatus())
+                    .eq(DispatchUnit::getDataType,Constants.TWO)
+                    .eq(DispatchUnit::getBaseId,dispatchUnit.getId())
+            );
+        }
     }
 
     @Override
@@ -810,13 +847,16 @@
         if (pageWrap.getModel().getBaseId() != null) {
             queryWrapper.eq(DispatchUnit::getBaseId, pageWrap.getModel().getBaseId());
         }
-        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
-            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
-                queryWrapper.orderByDesc(sortData.getProperty());
-            } else {
-                queryWrapper.orderByAsc(sortData.getProperty());
-            }
-        }
+        queryWrapper.orderByAsc(DispatchUnit::getUnitStatus);
+        queryWrapper.orderByAsc(DispatchUnit::getWorktypeStatus);
+        queryWrapper.orderByDesc(DispatchUnit::getCreateDate);
+//        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
+//            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
+//                queryWrapper.orderByDesc(sortData.getProperty());
+//            } else {
+//                queryWrapper.orderByAsc(sortData.getProperty());
+//            }
+//        }
         PageData<DispatchUnit> pageData = PageData.from(dispatchUnitJoinMapper.selectJoinPage(page,DispatchUnit.class, queryWrapper));
         return pageData;
     }
@@ -842,7 +882,9 @@
                         .selectAll(DuSolution.class)
                         .selectAs(Solutions::getName,DuSolution::getSolutionName)
                         .leftJoin(Solutions.class,Solutions::getId,DuSolution::getSolutionId)
+                        .leftJoin(CompanySolution.class,CompanySolution::getSolutionId,Solutions::getId)
                         .eq(DuSolution::getDispatchUnitId,dispatchUnit.getId())
+                        .eq(CompanySolution::getCompanyId,dispatchUnit.getCompanyId())
                         .orderByAsc(DuSolution::getSortnum)
         );
         if(CollectionUtils.isNotEmpty(duSolutionList)){
@@ -893,16 +935,15 @@
         LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         List<DispatchUnit> dispatchUnitList  = dispatchUnitJoinMapper.selectJoinList(DispatchUnit.class,
                 new MPJLambdaWrapper<DispatchUnit>().selectAll(DispatchUnit.class)
-//                        .selectAs(DuSolution::getId,DispatchUnit::getDuSolutionId)
-//                        .leftJoin(DuSolution.class,DuSolution::getDispatchUnitId,DispatchUnit::getId)
                         .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
-                        .select("(select b.id from du_solution b where b.isdeleted=0 and b.dispatch_unit_id=t.id and b.solution_id="+dispatchUnitQueryDTO.getSolutionId()+" limit 1) as du_solution_id" )
-                        .eq(loginUserInfo.getType().equals(Constants.ONE),DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
                         .eq(DispatchUnit::getStatus,Constants.ZERO)
-                        //.eq(DispatchUnit::getDataType,dispatchUnitQueryDTO.getDataType())
-                        .eq(DispatchUnit::getDataType,Constants.TWO)
-                        .exists("select b.id from du_solution b where b.isdeleted=0 and b.dispatch_unit_id=t.id and  b.solution_id="+dispatchUnitQueryDTO.getSolutionId() )
-//                        .eq(!Objects.isNull(dispatchUnitQueryDTO.getSolutionId()),DuSolution::getSolutionId,dispatchUnitQueryDTO.getSolutionId())
+                        .select("(select b.id from du_solution b where b.isdeleted=0 and b.dispatch_unit_id=t.id and b.solution_id="+dispatchUnitQueryDTO.getSolutionId()+"  order by b.CHECK_DATE desc  limit 1) as du_solution_id" )
+                        .eq(loginUserInfo.getType().equals(Constants.ONE),DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
+                        .eq(Objects.nonNull(dispatchUnitQueryDTO.getCompanyId()),DispatchUnit::getCompanyId,dispatchUnitQueryDTO.getCompanyId())
+                        .eq(Objects.isNull(dispatchUnitQueryDTO.getDataType()),DispatchUnit::getDataType,Constants.TWO)
+                        .eq(!Objects.isNull(dispatchUnitQueryDTO.getDataType()),DispatchUnit::getDataType,dispatchUnitQueryDTO.getDataType())
+                        .exists(!Objects.isNull(dispatchUnitQueryDTO.getSolutionId()),
+                                "select b.id from du_solution b where b.isdeleted=0 and b.dispatch_unit_id=t.id and b.status = 1 and  b.solution_id="+dispatchUnitQueryDTO.getSolutionId() )
                         .exists(!Objects.isNull(dispatchUnitQueryDTO.getApplyId()),
                                 " select 1 from apply_detail ad where ad.isdeleted = 0 and ad.apply_id = "+dispatchUnitQueryDTO.getApplyId()+" " +
                                         " and ad.du_id = t.id ")

--
Gitblit v1.9.3