From c21d5551744f8f55aa44157c17985243670bec24 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期五, 26 一月 2024 13:56:53 +0800
Subject: [PATCH] 111

---
 server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java |  179 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 171 insertions(+), 8 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 226e031..8483330 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
@@ -11,10 +11,7 @@
 import com.doumee.dao.business.DuLogMapper;
 import com.doumee.dao.business.DuSolutionMapper;
 import com.doumee.dao.business.DuWorktypeMapper;
-import com.doumee.dao.business.dto.DispatchUnitAuditDTO;
-import com.doumee.dao.business.dto.SaveDispatchUnitDTO;
-import com.doumee.dao.business.dto.SaveDuSolutionDTO;
-import com.doumee.dao.business.dto.SaveDuWorkTypeDTO;
+import com.doumee.dao.business.dto.*;
 import com.doumee.dao.business.join.DuLogJoinMapper;
 import com.doumee.dao.business.join.DuSolutionJoinMapper;
 import com.doumee.dao.business.join.DuWorkTypeJoinMapper;
@@ -33,10 +30,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
-import java.util.UUID;
+import java.util.*;
 
 /**
  * 娲鹃仯鍗曚綅淇℃伅琛⊿ervice瀹炵幇
@@ -67,7 +61,147 @@
     @Autowired
     private DuWorkTypeJoinMapper duWorkTypeJoinMapper;
 
+    @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
+    public Integer checkWorktype(DispatchUnit param) {
+        if(Objects.isNull(param)
+                ||Objects.isNull(param.getId())
+                ||param.getWorktypeStatus() == null
+                ||!(param.getWorktypeStatus() ==Constants.ONE || param.getWorktypeStatus() == Constants.TWO)){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        DispatchUnit model = dispatchUnitMapper.selectById(param.getId());
+        if(Objects.isNull(model) || Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO) ||!Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌娲鹃仯鍗曚綅淇℃伅");
+        }
+        if(!Constants.equalsInteger(model.getStatus(),Constants.ONE)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝璇ユ淳閬e崟浣嶅皻鏈鏍搁�氳繃锛屼笉鏀寔璇ユ搷浣滐紒");
+        }
+        if(Constants.equalsInteger(model.getWorktypeStatus(),Constants.ZERO)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝璇ユ淳閬e崟浣嶅伐绉嶅凡瀹℃牳锛岃鍕块噸澶嶆彁浜");
+        }
+        DispatchUnit update = new DispatchUnit();
+        update.setEditor(user.getId());
+        update.setEditDate(new Date());
+        update.setId(model.getId());
+        update.setWorktypeStatus(param.getWorktypeStatus());
+        update.setCheckDate(update.getEditDate());
+        update.setCheckUserId(user.getId());
+        update.setCheckInfo(param.getCheckInfo());
+        dispatchUnitMapper.updateById(update);
+        if(Constants.equalsInteger(param.getWorktypeStatus(),Constants.ONE)){
+            //瀹℃牳閫氳繃锛屼慨鏀圭姸鎬侊紝浜х敓鍘嗗彶鐗堟湰
+            newVersionData(dispatchUnitMapper.selectById(param.getId()),update);
+        }else{
+            //鏇存柊鏄庣粏鏁版嵁涓哄鏍稿け璐�
+            duSolutionMapper.update(null,new UpdateWrapper<DuSolution>().lambda()
+                    .set(DuSolution::getCheckDate,new Date() )
+                    .set(DuSolution::getStatus,Constants.TWO)
+                    .set(DuSolution::getCheckUserId,update.getCheckUserId())
+                    .set(DuSolution::getCheckInfo,update.getCheckInfo())
+                    .eq(DuSolution::getDispatchUnitId,update.getId()));
+        }
+        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()));
+        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);
+
+        List<DuWorktype> newWorktypes = new ArrayList<>();
+        List<DuSolution> solutions = duSolutionMapper.selectList(new QueryWrapper<DuSolution>().lambda()
+                .eq(DuSolution::getIsdeleted,Constants.ZERO)
+                .eq(DuSolution::getDispatchUnitId,model.getSolutionId()));
+        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.setDispatchUnitId(newVersion.getId());
+            ns.setCheckDate(update.getEditDate());
+            ns.setStatus(Constants.ONE);
+            ns.setCheckInfo(update.getCheckInfo());
+            ns.setCheckUserId(update.getCheckUserId());
+            duSolutionMapper.insert(ns);
+            List<DuWorktype> worktypes = duWorktypeMapper.selectList(new QueryWrapper<DuWorktype>().lambda()
+                    .eq(DuWorktype::getIsdeleted,Constants.ZERO)
+                    .eq(DuWorktype::getDuSolutionId,s.getId()));
+            if(worktypes == null || worktypes.size() ==0){
+                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝璇ユ淳閬e崟浣嶆柟妗堝瓨鍦ㄦ柟妗堟槸鏈缃伐绉嶄俊鎭俊鎭紝瀹℃牳閫氳繃澶辫触锛�");
+            }
+            for (DuWorktype w : worktypes) {
+                DuWorktype nw = new DuWorktype();
+                BeanUtils.copyProperties(w, nw);
+                nw.setCheckDate(update.getEditDate());
+                nw.setStatus(Constants.ONE);
+                nw.setDuSolutionId(ns.getId());
+                nw.setCheckInfo(update.getCheckInfo());
+                nw.setCheckUserId(update.getCheckUserId());
+                newWorktypes.add(nw);
+            }
+        }
+        if(newWorktypes!=null &&newWorktypes.size()>0){
+            //鎵归噺鏌ヨ宸ョ鍏宠仈璁板綍
+            duWorktypeMapper.insertBatchSomeColumn(newWorktypes);
+        }
+    }
+
+    @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
+    public Integer check(DispatchUnit param) {
+        if(Objects.isNull(param)
+                ||Objects.isNull(param.getId())
+                ||param.getStatus() == null
+                ||!(param.getStatus() ==Constants.ONE || param.getStatus() == Constants.TWO)){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        DispatchUnit model = dispatchUnitMapper.selectById(param.getId());
+        if(Objects.isNull(model) || Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO) ||!Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
+            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌娲鹃仯鍗曚綅淇℃伅");
+        }
+        if(Constants.equalsInteger(model.getStatus(),Constants.ZERO)){
+            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀵逛笉璧凤紝璇ユ淳閬e崟浣嶅伐绉嶅凡瀹℃牳锛岃鍕块噸澶嶆彁浜");
+        }
+        DispatchUnit update = new DispatchUnit();
+        update.setEditor(user.getId());
+        update.setEditDate(new Date());
+        update.setId(model.getId());
+        update.setStatus(param.getStatus());
+        update.setWorktypeStatus(param.getWorktypeStatus());
+        update.setCheckDate(update.getEditDate());
+        update.setCheckUserId(user.getId());
+        update.setCheckInfo(param.getCheckInfo());
+        dispatchUnitMapper.updateById(update);
+        if(Constants.equalsInteger(model.getStatus(),Constants.ONE)){
+            //瀹℃牳閫氳繃锛屼慨鏀圭姸鎬侊紝浜х敓鍘嗗彶鐗堟湰
+            newVersionData(dispatchUnitMapper.selectById(param.getId()),update);
+        }else{
+            //鏇存柊鏄庣粏鏁版嵁涓哄鏍稿け璐�
+            duSolutionMapper.update(null,new UpdateWrapper<DuSolution>().lambda()
+                    .set(DuSolution::getCheckDate,new Date() )
+                    .set(DuSolution::getStatus,Constants.TWO)
+                    .set(DuSolution::getCheckUserId,update.getCheckUserId())
+                    .set(DuSolution::getCheckInfo,update.getCheckInfo())
+                    .eq(DuSolution::getDispatchUnitId,update.getId()));
+        }
+        return  1;
+    }
     @Override
     @Transactional(rollbackFor = {Exception.class,BusinessException.class})
     public Integer create(SaveDispatchUnitDTO saveDispatchUnitDTO) {
@@ -449,6 +583,7 @@
 
     @Override
     public List<DispatchUnit> findList(DispatchUnit dispatchUnit) {
+        dispatchUnit.setIsdeleted(Constants.ZERO);
         QueryWrapper<DispatchUnit> wrapper = new QueryWrapper<>(dispatchUnit);
         return dispatchUnitMapper.selectList(wrapper);
     }
@@ -570,6 +705,11 @@
         //鏌ヨ鎿嶄綔璁板綍
         List<DuLog> duLogList = duLogJoinMapper.selectJoinList(DuLog.class,
                 new MPJLambdaWrapper<DuLog>()
+                        .selectAll(DuLog.class)
+                        .selectAs(Member::getName,DuLog::getCreatorName)
+                        .selectAs(Company::getName,DuLog::getCompanyName)
+                        .leftJoin(Member.class,Member::getId,DuLog::getCreator)
+                        .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                         .eq(DuLog::getDuId,dispatchUnit.getId())
                         .orderByAsc(DuLog::getCreateDate)
         );
@@ -578,5 +718,28 @@
     }
 
 
+    /**
+     * 鏌ヨ浼佷笟涓嬬殑娲鹃仯鍗曚綅
+     * @return
+     */
+    @Override
+    public List<DispatchUnit> findByDTO(DispatchUnitQueryDTO dispatchUnitQueryDTO) {
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        List<DispatchUnit> dispatchUnitList = dispatchUnitMapper.selectList(new QueryWrapper<DispatchUnit>().lambda()
+                .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
+                .eq(loginUserInfo.getType().equals(Constants.ONE),DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
+                .eq(DispatchUnit::getStatus,Constants.ZERO)
+                .eq(DispatchUnit::getDataType,dispatchUnitQueryDTO.getDataType())
+                .apply(!Objects.isNull(dispatchUnitQueryDTO.getSolutionId()), " id in ( select d.dispatch_unit_id from du_solution d where d.solutionId = "+dispatchUnitQueryDTO.getSolutionId()+"  ) " )
+                .exists(!Objects.isNull(dispatchUnitQueryDTO.getApplyId()),
+                        " select 1 from apply_detail ad where ad.isdeleted = 0 and ad.apply_id = "+dispatchUnitQueryDTO.getApplyId()+" " +
+                                " ad.du_id = t.id ")
+                .orderByAsc(DispatchUnit::getSortnum)
+        );
+        return dispatchUnitList;
+    }
+
+
+
 
 }

--
Gitblit v1.9.3