From 50fb58286ed3b718c39a97e0987ee7561a295651 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期五, 04 七月 2025 17:56:41 +0800
Subject: [PATCH] git ch

---
 server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java |  872 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 829 insertions(+), 43 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 1aaa562..d8dd059 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
@@ -1,25 +1,39 @@
 package com.doumee.service.business.impl;
 
+import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
+import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
-import com.doumee.dao.business.DispatchUnitMapper;
-import com.doumee.dao.business.model.DispatchUnit;
+import com.doumee.dao.business.*;
+import com.doumee.dao.business.dto.*;
+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;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 娲鹃仯鍗曚綅淇℃伅琛⊿ervice瀹炵幇
  * @author 姹熻箘韫�
- * @date 2024/01/15 15:07
+ * @date 2024/01/16 10:03
  */
 @Service
 public class DispatchUnitServiceImpl implements DispatchUnitService {
@@ -27,15 +41,664 @@
     @Autowired
     private DispatchUnitMapper dispatchUnitMapper;
 
+    @Autowired
+    private DispatchUnitJoinMapper dispatchUnitJoinMapper;
+
+    @Autowired
+    private DuSolutionMapper duSolutionMapper;
+
+    @Autowired
+    private SolutionWorktypeJoinMapper solutionWorktypeJoinMapper;
+
+    @Autowired
+    private DuWorktypeMapper    duWorktypeMapper;
+
+    @Autowired
+    private DuLogMapper duLogMapper;
+
+    @Autowired
+    private DuLogJoinMapper duLogJoinMapper;
+
+    @Autowired
+    private DuSolutionJoinMapper duSolutionJoinMapper;
+
+    @Autowired
+    private DuWorkTypeJoinMapper duWorkTypeJoinMapper;
+
+    @Autowired
+    private SystemDictDataBiz systemDictDataBiz;
+
+    @Autowired
+    private NoticesMapper noticesMapper;
+
     @Override
-    public Integer create(DispatchUnit dispatchUnit) {
-        dispatchUnitMapper.insert(dispatchUnit);
-        return dispatchUnit.getId();
+    @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.getUnitStatus(),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(model,update,false);
+            //瀛樺偍鎿嶄綔鍘嗗彶
+            this.saveDuLog(update,Constants.DispatchUnitLogType.WORK_TYPE_AUDIT_PASS,update.getCheckInfo());
+        }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()));
+
+            duWorktypeMapper.update(null,new UpdateWrapper<DuWorktype>().lambda()
+                    .set(DuWorktype::getStatus,Constants.TWO)
+                    .set(DuWorktype::getCheckUserId,update.getCheckUserId())
+                    .set(DuWorktype::getCheckInfo,update.getCheckInfo())
+                    .set(DuWorktype::getCheckDate,new Date() )
+                    .eq(DuWorktype::getIsdeleted,Constants.ZERO)
+                    .eq(DuWorktype::getStatus,Constants.ZERO)
+                    .eq(DuWorktype::getDispatchUnitId,update.getId()));
+            //瀛樺偍鎿嶄綔鍘嗗彶
+            this.saveDuLog(update,Constants.DispatchUnitLogType.WORK_TYPE_AUDIT_UN_PASS,update.getCheckInfo());
+        }
+
+
+        //瀛樺偍寰呭姙淇℃伅
+        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.DISPATCH_UNIT;
+        //鍒犻櫎鍏朵粬寰呭姙
+        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,model.getId()));
+
+        return  1;
+    }
+
+    private void newVersionData(DispatchUnit model, DispatchUnit update,Boolean flag) {
+        DispatchUnit newVersion = new DispatchUnit();
+        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.setId(null);
+            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)
+                .eq(DuSolution::getDispatchUnitId,model.getId()));
+
+        duSolutionMapper.update(null,new UpdateWrapper<DuSolution>().lambda()
+                        .set(DuSolution::getStatus,Constants.ONE)
+                .set(DuSolution::getCheckDate,update.getEditDate() )
+                .set(DuSolution::getCheckUserId,update.getCheckUserId())
+                .set(DuSolution::getCheckInfo,update.getCheckInfo())
+                .eq(DuSolution::getIsdeleted,Constants.ZERO)
+                .eq(DuSolution::getStatus,Constants.ZERO)
+                .eq(DuSolution::getDispatchUnitId,model.getId())
+        );
+
+
+        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);
+            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()));
+
+            duWorktypeMapper.update(null,new UpdateWrapper<DuWorktype>().lambda()
+                    .set(DuWorktype::getStatus,Constants.ONE)
+                    .set(DuWorktype::getCheckDate,update.getEditDate())
+                    .set(DuWorktype::getCheckUserId,update.getCheckUserId())
+                    .set(DuWorktype::getCheckInfo,update.getCheckInfo())
+                    .eq(DuWorktype::getIsdeleted,Constants.ZERO)
+                    .eq(DuWorktype::getStatus,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) {
+                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());
+                nw.setCheckInfo(update.getCheckInfo());
+                nw.setCheckUserId(update.getCheckUserId());
+                newWorktypes.add(nw);
+            }
+        }
+        if(newWorktypes!=null &&newWorktypes.size()>0){
+            //鎵归噺鏌ヨ宸ョ鍏宠仈璁板綍
+            duWorktypeMapper.insert(newWorktypes);
+        }
     }
 
     @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
+    public Integer check(DispatchUnit param) {
+        if(Objects.isNull(param)
+                ||Objects.isNull(param.getId())
+                ||param.getUnitStatus() == null
+                ||!(param.getUnitStatus() ==Constants.ONE || param.getUnitStatus() == 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.getUnitStatus(),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.setUnitStatus(param.getUnitStatus());
+        update.setWorktypeStatus(param.getUnitStatus());
+        update.setCheckDate(update.getEditDate());
+        update.setCheckUserId(user.getId());
+        update.setCheckInfo(param.getCheckInfo());
+        dispatchUnitMapper.updateById(update);
+        DispatchUnit dispatchUnit = dispatchUnitMapper.selectById(param.getId());
+        if(Constants.equalsInteger(param.getUnitStatus(),Constants.ONE)){
+            //瀹℃牳閫氳繃锛屼慨鏀圭姸鎬侊紝浜х敓鍘嗗彶鐗堟湰
+            newVersionData(dispatchUnit,update,true);
+            //瀛樺偍鎿嶄綔鍘嗗彶
+            this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.AUDIT_PASS,update.getCheckInfo());
+        }else{
+            //鏇存柊鏄庣粏鏁版嵁涓哄鏍稿け璐�
+            duSolutionMapper.update(null,new UpdateWrapper<DuSolution>().lambda()
+                    .set(DuSolution::getStatus,Constants.TWO)
+                    .set(DuSolution::getCheckDate,new Date() )
+                    .set(DuSolution::getCheckUserId,update.getCheckUserId())
+                    .set(DuSolution::getCheckInfo,update.getCheckInfo())
+                    .eq(DuSolution::getDispatchUnitId,update.getId()));
+
+            duWorktypeMapper.update(null,new UpdateWrapper<DuWorktype>().lambda()
+                    .set(DuWorktype::getStatus,Constants.TWO)
+                    .set(DuWorktype::getCheckUserId,update.getCheckUserId())
+                    .set(DuWorktype::getCheckInfo,update.getCheckInfo())
+                    .set(DuWorktype::getCheckDate,new Date() )
+                    .eq(DuWorktype::getIsdeleted,Constants.ZERO)
+                    .eq(DuWorktype::getStatus,Constants.ZERO)
+                    .eq(DuWorktype::getDispatchUnitId,update.getId()));
+            //瀛樺偍鎿嶄綔鍘嗗彶
+            this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.AUDIT_UN_PASS,update.getCheckInfo());
+        }
+
+        //瀛樺偍寰呭姙淇℃伅
+        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.DISPATCH_UNIT;
+        //鍒犻櫎鍏朵粬寰呭姙
+        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,dispatchUnit.getId()));
+
+        return  1;
+    }
+    @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
+    public Integer create(SaveDispatchUnitDTO saveDispatchUnitDTO) {
+        if(Objects.isNull(saveDispatchUnitDTO)
+            || StringUtils.isEmpty(saveDispatchUnitDTO.getName())
+            || CollectionUtils.isEmpty(saveDispatchUnitDTO.getSaveDuSolutionDTOList())
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if(dispatchUnitMapper.selectCount(new QueryWrapper<DispatchUnit>().lambda()
+                .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崟浣嶄俊鐢ㄤ唬鐮併�戝凡瀛樺湪");
+//        };
+        DispatchUnit dispatchUnit = new DispatchUnit();
+        dispatchUnit.setCreateDate(new Date());
+        dispatchUnit.setCreator(loginUserInfo.getId());
+        dispatchUnit.setCompanyId(loginUserInfo.getCompanyId());
+        dispatchUnit.setIsdeleted(Constants.ZERO);
+        dispatchUnit.setName(saveDispatchUnitDTO.getName());
+        dispatchUnit.setCode(saveDispatchUnitDTO.getCode());
+        dispatchUnit.setContent(saveDispatchUnitDTO.getContent());
+        dispatchUnit.setStatus(Constants.ZERO);
+        dispatchUnit.setVersion(UUID.randomUUID().toString());
+        dispatchUnit.setUnitStatus(Constants.ZERO);
+        dispatchUnit.setWorktypeStatus(Constants.ZERO);
+        dispatchUnit.setDataType(Constants.ZERO);
+        dispatchUnitMapper.insert(dispatchUnit);
+
+        //瀛樺偍鎿嶄綔鍘嗗彶
+        this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.UPLOAD,null);
+
+        List<SaveDuSolutionDTO> saveDuSolutionDTOList = saveDispatchUnitDTO.getSaveDuSolutionDTOList();
+
+        List<Integer> duSolutionIdS = saveDuSolutionDTOList.stream().map(m->m.getSolutionId()).collect(Collectors.toList());
+        HashSet<Integer> setDuSolutionIdS=new HashSet<>(duSolutionIdS);
+        if(duSolutionIdS.size()!=setDuSolutionIdS.size()){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏂规淇℃伅閲嶅");
+        }
+
+        for (int i = 0; i < saveDuSolutionDTOList.size(); i++) {
+            SaveDuSolutionDTO saveDuSolutionDTO = saveDuSolutionDTOList.get(i);
+            DuSolution duSolution = new DuSolution();
+            duSolution.setCreateDate(new Date());
+            duSolution.setCreator(loginUserInfo.getId());
+            duSolution.setStatus(Constants.ZERO);
+            duSolution.setIsdeleted(Constants.ZERO);
+            duSolution.setDispatchUnitId(dispatchUnit.getId());
+            duSolution.setSortnum(i);
+            duSolution.setSolutionId(saveDuSolutionDTO.getSolutionId());
+            duSolutionMapper.insert(duSolution);
+
+            List<SaveDuWorkTypeDTO> saveDuWorkTypeDTOList = saveDuSolutionDTO.getSaveDuWorkTypeDTOList();
+
+            List<Integer> duWorkTypeIdS = saveDuWorkTypeDTOList.stream().map(m->m.getWorkTypeId()).collect(Collectors.toList());
+            HashSet<Integer> setDuWorkTypeIdS=new HashSet<>(duWorkTypeIdS);
+            if(duWorkTypeIdS.size()!=setDuWorkTypeIdS.size()){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+saveDuSolutionDTO.getSolutionName()+"銆戣鏂规涓嬪瓨鍦ㄩ噸澶嶅伐绉嶏紒");
+            }
+
+            if(!CollectionUtils.isNotEmpty(saveDuSolutionDTOList)){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+saveDuSolutionDTO.getSolutionName()+"銆戣鏂规涓嬫湭閫夋嫨宸ョ锛�");
+            }
+            for (int j = 0; j < saveDuWorkTypeDTOList.size(); j++) {
+                SaveDuWorkTypeDTO saveDuWorkTypeDTO = saveDuWorkTypeDTOList.get(j);
+                DuWorktype duWorktype = new DuWorktype();
+                duWorktype.setCreateDate(new Date());
+                duWorktype.setCreator(loginUserInfo.getId());
+                duWorktype.setIsdeleted(Constants.ZERO);
+                duWorktype.setDuSolutionId(duSolution.getId());
+                duWorktype.setStatus(Constants.ZERO);
+                duWorktype.setSortnum(j);
+                duWorktype.setDispatchUnitId(dispatchUnit.getId());
+                duWorktype.setWorkTypeId(saveDuWorkTypeDTO.getWorkTypeId());
+                duWorktype.setVideoUrl(saveDuWorkTypeDTO.getVideoUrl());
+                duWorktype.setStatus2(Constants.ZERO);
+                duWorktypeMapper.insert(duWorktype);
+            }
+        }
+
+        //瀛樺偍寰呭姙淇℃伅
+        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.DISPATCH_UNIT;
+        //鍒犻櫎鍏朵粬寰呭姙
+        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,dispatchUnit.getId()));
+        Notices notices = new Notices(noticeObjectType,Constants.ZERO,dispatchUnit.getId(),dispatchUnit.getName(),
+                dispatchUnit.getCompanyId(), Constants.NoticeType.ZERO);
+        noticesMapper.insert(notices);
+
+        return dispatchUnit.getId();
+    }
+
+
+    @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
+    public Integer editDispatchUnit(SaveDispatchUnitDTO saveDispatchUnitDTO) {
+        if(Objects.isNull(saveDispatchUnitDTO)
+                ||Objects.isNull(saveDispatchUnitDTO.getId())
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        DispatchUnit dispatchUnit = this.dispatchUnitMapper.selectById(saveDispatchUnitDTO.getId());
+        if(Objects.isNull(dispatchUnit)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈煡璇㈠埌娲鹃仯鍗曚綅淇℃伅");
+        }
+        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崟浣嶅悕绉般�戝凡瀛樺湪");
+        };
+        dispatchUnit.setCode(saveDispatchUnitDTO.getCode());
+        dispatchUnit.setContent(saveDispatchUnitDTO.getContent());
+        dispatchUnit.setName(saveDispatchUnitDTO.getName());
+        dispatchUnit.setUnitStatus(Constants.ZERO);
+        dispatchUnit.setEditDate(new Date());
+        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);
+
+        //瀛樺偍寰呭姙淇℃伅
+        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.DISPATCH_UNIT;
+        //鍒犻櫎鍏朵粬寰呭姙
+        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,dispatchUnit.getId()));
+        Notices notices = new Notices(noticeObjectType,Constants.ZERO,dispatchUnit.getId(),dispatchUnit.getName(),
+                dispatchUnit.getCompanyId(), Constants.NoticeType.ZERO);
+        noticesMapper.insert(notices);
+
+        return dispatchUnit.getId();
+    }
+
+
+    /**
+     * 娣诲姞鏂规淇℃伅
+     * @param saveDispatchUnitDTO
+     * @return
+     */
+    @Override
+    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
+    public Integer createSolution(SaveDispatchUnitDTO saveDispatchUnitDTO) {
+        if(Objects.isNull(saveDispatchUnitDTO)
+                ||Objects.isNull(saveDispatchUnitDTO.getId())
+                || !CollectionUtils.isNotEmpty(saveDispatchUnitDTO.getSaveDuSolutionDTOList())
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        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());
+        dispatchUnitMapper.updateById(dispatchUnit);
+
+        if(Objects.isNull(dispatchUnit)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈煡璇㈠埌娲鹃仯鍗曚綅淇℃伅");
+        }
+        //瀛樺偍鎿嶄綔鍘嗗彶
+        this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.ADD_WORK_TYPE,null);
+        this.dealDuData(saveDispatchUnitDTO,loginUserInfo);
+
+        //瀛樺偍寰呭姙淇℃伅
+        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.DISPATCH_UNIT;
+        //鍒犻櫎鍏朵粬寰呭姙
+        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,dispatchUnit.getId()));
+        Notices notices = new Notices(noticeObjectType,Constants.ZERO,dispatchUnit.getId(),dispatchUnit.getName(),
+                dispatchUnit.getCompanyId(), Constants.NoticeType.ONE);
+        noticesMapper.insert(notices);
+
+        return dispatchUnit.getId();
+    }
+
+
+    public void dealDuData(SaveDispatchUnitDTO saveDispatchUnitDTO,LoginUserInfo loginUserInfo){
+        List<SaveDuSolutionDTO> saveDuSolutionDTOList = saveDispatchUnitDTO.getSaveDuSolutionDTOList();
+        for (int i = 0; i < saveDuSolutionDTOList.size(); i++) {
+            SaveDuSolutionDTO saveDuSolutionDTO = saveDuSolutionDTOList.get(i);
+            if(Objects.isNull(saveDuSolutionDTO.getSolutionId())){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+saveDuSolutionDTO.getSolutionName()+"銆戣鏂规涓嬮�夋嫨鏂规淇℃伅寮傚父锛�");
+            }
+            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())).intValue();
+            if(Objects.isNull(duSolution)){
+                duSolution = new DuSolution();
+                duSolution.setCreateDate(new Date());
+                duSolution.setCreator(loginUserInfo.getId());
+                duSolution.setIsdeleted(Constants.ZERO);
+                duSolution.setStatus(Constants.ZERO);
+                duSolution.setDispatchUnitId(saveDispatchUnitDTO.getId());
+                duSolution.setSortnum(duSolutionNum + i);
+                duSolution.setSolutionId(saveDuSolutionDTO.getSolutionId());
+                duSolutionMapper.insert(duSolution);
+            }
+            List<SaveDuWorkTypeDTO> saveDuWorkTypeDTOList = saveDuSolutionDTO.getSaveDuWorkTypeDTOList();
+            if(!CollectionUtils.isNotEmpty(saveDuSolutionDTOList)){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+saveDuSolutionDTO.getSolutionName()+"銆戣鏂规涓嬫湭閫夋嫨宸ョ锛�");
+            }
+            for (int j = 0; j < saveDuWorkTypeDTOList.size(); j++) {
+                SaveDuWorkTypeDTO saveDuWorkTypeDTO = saveDuWorkTypeDTOList.get(j);
+                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())).intValue();
+                DuWorktype duWorktype = new DuWorktype();
+                duWorktype.setCreateDate(new Date());
+                duWorktype.setCreator(loginUserInfo.getId());
+                duWorktype.setIsdeleted(Constants.ZERO);
+                duWorktype.setDuSolutionId(duSolution.getId());
+                duWorktype.setStatus(Constants.ZERO);
+                duWorktype.setSortnum(duWorkTypeNum + j);
+                duWorktype.setDispatchUnitId(saveDispatchUnitDTO.getId());
+                duWorktype.setWorkTypeId(saveDuWorkTypeDTO.getWorkTypeId());
+                duWorktype.setVideoUrl(saveDuWorkTypeDTO.getVideoUrl());
+                duWorktype.setStatus2(Constants.ZERO);
+                duWorktypeMapper.insert(duWorktype);
+            }
+        }
+    }
+
+
+
+    @Override
+    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
+    public void auditData(DispatchUnitAuditDTO dispatchUnitAuditDTO){
+        if(Objects.isNull(dispatchUnitAuditDTO)
+                || Objects.isNull(dispatchUnitAuditDTO.getId())
+                || Objects.isNull(dispatchUnitAuditDTO.getAuditType())
+                || Objects.isNull(dispatchUnitAuditDTO.getStatus())
+                || !(dispatchUnitAuditDTO.getAuditType().equals(Constants.ZERO) || dispatchUnitAuditDTO.getAuditType().equals(Constants.ONE))
+                || !(dispatchUnitAuditDTO.getStatus().equals(Constants.ONE) || dispatchUnitAuditDTO.getAuditType().equals(Constants.TWO))
+        ){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        if(loginUserInfo.getType().equals(Constants.ONE)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛绫诲瀷閿欒锛氫紒涓氱敤鎴锋棤娉曡繘琛岃鎿嶄綔");
+        }
+        DispatchUnit dispatchUnit = this.dispatchUnitMapper.selectById(dispatchUnitAuditDTO.getId());
+        if(Objects.isNull(dispatchUnit)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈煡璇㈠埌娲鹃仯鍗曚綅淇℃伅");
+        }
+        //娲鹃仯鍗曚綅瀹℃牳
+        if(dispatchUnitAuditDTO.getAuditType().equals(Constants.ZERO)){
+            if(dispatchUnit.getStatus().equals(Constants.ONE)){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"娲鹃仯鍗曚綅淇℃伅宸插鏍�");
+            }
+            dispatchUnit.setStatus(dispatchUnitAuditDTO.getStatus());
+            dispatchUnit.setCheckDate(new Date());
+            dispatchUnit.setCheckUserId(loginUserInfo.getId());
+            dispatchUnit.setCheckInfo(dispatchUnitAuditDTO.getAuditRemark());
+            dispatchUnitMapper.updateById(dispatchUnit);
+            if(dispatchUnitAuditDTO.getStatus().equals(Constants.ONE)){
+                this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.AUDIT_PASS,dispatchUnitAuditDTO.getAuditRemark());
+            }else{
+                this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.AUDIT_UN_PASS,dispatchUnitAuditDTO.getAuditRemark());
+            }
+
+        }else if(dispatchUnitAuditDTO.getAuditType().equals(Constants.ONE)){
+            if(!dispatchUnit.getStatus().equals(Constants.ONE)){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"娲鹃仯鍗曚綅淇℃伅鏈鏍�,鏃犳硶杩涜璇ユ搷浣�");
+            }
+            if(dispatchUnitAuditDTO.getStatus().equals(Constants.ONE)){
+                this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.WORK_TYPE_AUDIT_PASS,dispatchUnitAuditDTO.getAuditRemark());
+            }else{
+                this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.WORK_TYPE_AUDIT_UN_PASS,dispatchUnitAuditDTO.getAuditRemark());
+            }
+        }else{
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        //鏇存柊鏂规鏁版嵁
+        List<DuSolution> duSolutionList = duSolutionMapper.selectList(new QueryWrapper<DuSolution>().lambda()
+                .eq(DuSolution::getStatus,Constants.ZERO)
+                .eq(DuSolution::getIsdeleted,Constants.ZERO)
+                .eq(DuSolution::getDispatchUnitId,dispatchUnit.getId()));
+        for (DuSolution duSolution:duSolutionList) {
+            duSolution.setStatus(dispatchUnitAuditDTO.getStatus());
+            duSolution.setCheckDate(new Date());
+            duSolution.setCheckUserId(loginUserInfo.getId());
+            duSolution.setCheckInfo(dispatchUnitAuditDTO.getAuditRemark());
+            dispatchUnitMapper.updateById(dispatchUnit);
+            //鏌ヨ宸ョ鏁版嵁
+            List<DuWorktype> duWorktypeList = duWorktypeMapper.selectList(new QueryWrapper<DuWorktype>().lambda()
+                    .eq(DuWorktype::getStatus,Constants.ZERO)
+                    .eq(DuWorktype::getIsdeleted,Constants.ZERO)
+                    .eq(DuWorktype::getDuSolutionId,duSolution.getId()));
+            for (DuWorktype duWorktype:duWorktypeList) {
+                duWorktype.setStatus(dispatchUnitAuditDTO.getStatus());
+                duWorktype.setCheckDate(new Date());
+                duWorktype.setCheckUserId(loginUserInfo.getId());
+                duWorktype.setCheckInfo(dispatchUnitAuditDTO.getAuditRemark());
+                dispatchUnitMapper.updateById(dispatchUnit);
+            }
+        }
+        this.saveHistory(dispatchUnit);
+    }
+
+
+    public void saveHistory(DispatchUnit dispatchUnit){
+        if(dispatchUnit.getStatus().equals(Constants.ONE)){
+            DispatchUnit his = new DispatchUnit();
+            BeanUtils.copyProperties(dispatchUnit,his);
+            his.setBaseId(dispatchUnit.getId());
+            his.setId(null);
+            his.setDataType(Constants.TWO);
+            dispatchUnitMapper.insert(his);
+            //淇敼鍏朵粬鍘嗗彶鐗堟湰鏁版嵁涓� 鍘嗗彶鐗堟湰
+            dispatchUnitMapper.update(null,new UpdateWrapper<DispatchUnit>().lambda().set(DispatchUnit::getDataType,Constants.ONE).eq(DispatchUnit::getBaseId,dispatchUnit.getId())
+                    .eq(DispatchUnit::getDataType,Constants.TWO).ne(DispatchUnit::getId,his.getId())
+            );
+            //瀛樺偍鏂规鏁版嵁
+            List<DuSolution> duSolutionList = duSolutionMapper.selectList(new QueryWrapper<DuSolution>().lambda()
+                    .eq(DuSolution::getStatus,Constants.ONE)
+                    .eq(DuSolution::getDispatchUnitId,dispatchUnit.getId()));
+            for (DuSolution duSolution:duSolutionList) {
+                DuSolution hisDuSolution = new DuSolution();
+                BeanUtils.copyProperties(duSolution,hisDuSolution);
+                hisDuSolution.setId(null);
+                hisDuSolution.setDispatchUnitId(his.getId());
+                duSolutionMapper.insert(hisDuSolution);
+                //鏌ヨ宸ョ鏁版嵁
+                List<DuWorktype> duWorktypeList = duWorktypeMapper.selectList(new QueryWrapper<DuWorktype>().lambda()
+                        .eq(DuWorktype::getStatus,Constants.ONE)
+                        .eq(DuWorktype::getDuSolutionId,duSolution.getId()));
+                for (DuWorktype duWorktype:duWorktypeList) {
+                    DuWorktype hisDuWorktype = new DuWorktype();
+                    BeanUtils.copyProperties(duWorktype,hisDuWorktype);
+                    hisDuWorktype.setId(null);
+                    hisDuWorktype.setDuSolutionId(hisDuSolution.getId());
+                    duWorktypeMapper.insert(hisDuWorktype);
+                }
+            }
+        }
+    }
+
+
+
+    public void saveDuLog(DispatchUnit dispatchUnit,Constants.DispatchUnitLogType dispatchUnitLogType,String content){
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        DuLog duLog = new DuLog();
+        duLog.setCreateDate(new Date());
+        duLog.setCreator(loginUserInfo.getId());
+        duLog.setIsdeleted(Constants.ZERO);
+        duLog.setDuId(dispatchUnit.getId());
+        duLog.setTitle(dispatchUnitLogType.getName());
+        duLog.setContent(content);
+        duLog.setObjType(dispatchUnitLogType.getKey());
+        duLog.setObjId(Integer.toString(dispatchUnit.getId()));
+        duLog.setStatus(Constants.ZERO);
+        duLogMapper.insert(duLog);
+    }
+
+
+    @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
@@ -55,6 +718,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
@@ -80,89 +751,115 @@
 
     @Override
     public List<DispatchUnit> findList(DispatchUnit dispatchUnit) {
+        dispatchUnit.setIsdeleted(Constants.ZERO);
         QueryWrapper<DispatchUnit> wrapper = new QueryWrapper<>(dispatchUnit);
         return dispatchUnitMapper.selectList(wrapper);
     }
-  
+
+
     @Override
     public PageData<DispatchUnit> findPage(PageWrap<DispatchUnit> pageWrap) {
         IPage<DispatchUnit> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
-        QueryWrapper<DispatchUnit> queryWrapper = new QueryWrapper<>();
+        if(pageWrap.getModel().getDataType() ==null){
+            pageWrap.getModel().setDataType(Constants.ZERO);
+        }
+
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         Utils.MP.blankToNull(pageWrap.getModel());
+        MPJLambdaWrapper<DispatchUnit>  queryWrapper =    new MPJLambdaWrapper<DispatchUnit>();
+        queryWrapper.selectAll(DispatchUnit.class)
+                .selectAs(Company::getName,DispatchUnit::getCompanyName)
+                .leftJoin(Company.class,Company::getId,DispatchUnit::getCompanyId);
+        queryWrapper.eq(DispatchUnit::getIsdeleted,Constants.ZERO);
+        if(Constants.equalsInteger(user.getType(),Constants.ZERO)){
+            //鍙兘鐪嬫潈闄愯寖鍥村唴
+            if(user.getCompanyIdList() == null || user.getCompanyIdList().size() == 0){
+                queryWrapper. eq(Company::getId,-1);//璁剧疆鏃犳晥璁块棶
+            }else {
+                queryWrapper. in(Company::getId, user.getCompanyIdList());
+            }
+        } else  {
+            //浼佷笟鐢ㄦ埛鍙湅鑷繁鐨勬暟鎹�
+            pageWrap.getModel().setCompanyId(user.getCompanyId());
+        }
         if (pageWrap.getModel().getId() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getId, pageWrap.getModel().getId());
+            queryWrapper.eq(DispatchUnit::getId, pageWrap.getModel().getId());
         }
         if (pageWrap.getModel().getCreator() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getCreator, pageWrap.getModel().getCreator());
+            queryWrapper.eq(DispatchUnit::getCreator, pageWrap.getModel().getCreator());
         }
         if (pageWrap.getModel().getCreateDate() != null) {
-            queryWrapper.lambda().ge(DispatchUnit::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
-            queryWrapper.lambda().le(DispatchUnit::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
+            queryWrapper.ge(DispatchUnit::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
+            queryWrapper.le(DispatchUnit::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
         }
         if (pageWrap.getModel().getEditor() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getEditor, pageWrap.getModel().getEditor());
+            queryWrapper.eq(DispatchUnit::getEditor, pageWrap.getModel().getEditor());
         }
         if (pageWrap.getModel().getEditDate() != null) {
-            queryWrapper.lambda().ge(DispatchUnit::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
-            queryWrapper.lambda().le(DispatchUnit::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
+            queryWrapper.ge(DispatchUnit::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
+            queryWrapper.le(DispatchUnit::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
         }
         if (pageWrap.getModel().getIsdeleted() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getIsdeleted, pageWrap.getModel().getIsdeleted());
+            queryWrapper.eq(DispatchUnit::getIsdeleted, pageWrap.getModel().getIsdeleted());
         }
         if (pageWrap.getModel().getName() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getName, pageWrap.getModel().getName());
+            queryWrapper.like(DispatchUnit::getName, pageWrap.getModel().getName());
         }
         if (pageWrap.getModel().getRemark() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getRemark, pageWrap.getModel().getRemark());
+            queryWrapper.eq(DispatchUnit::getRemark, pageWrap.getModel().getRemark());
         }
         if (pageWrap.getModel().getStatus() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getStatus, pageWrap.getModel().getStatus());
+            queryWrapper.eq(DispatchUnit::getStatus, pageWrap.getModel().getStatus());
         }
         if (pageWrap.getModel().getUnitStatus() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getUnitStatus, pageWrap.getModel().getUnitStatus());
+            queryWrapper.eq(DispatchUnit::getUnitStatus, pageWrap.getModel().getUnitStatus());
         }
         if (pageWrap.getModel().getWorktypeStatus() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getWorktypeStatus, pageWrap.getModel().getWorktypeStatus());
+            queryWrapper.eq(DispatchUnit::getWorktypeStatus, pageWrap.getModel().getWorktypeStatus());
         }
         if (pageWrap.getModel().getSortnum() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getSortnum, pageWrap.getModel().getSortnum());
+            queryWrapper.eq(DispatchUnit::getSortnum, pageWrap.getModel().getSortnum());
         }
         if (pageWrap.getModel().getCompanyId() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getCompanyId, pageWrap.getModel().getCompanyId());
+            queryWrapper.eq(DispatchUnit::getCompanyId, pageWrap.getModel().getCompanyId());
         }
         if (pageWrap.getModel().getPhone() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getPhone, pageWrap.getModel().getPhone());
+            queryWrapper.eq(DispatchUnit::getPhone, pageWrap.getModel().getPhone());
         }
         if (pageWrap.getModel().getLinkname() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getLinkname, pageWrap.getModel().getLinkname());
+            queryWrapper.eq(DispatchUnit::getLinkname, pageWrap.getModel().getLinkname());
         }
         if (pageWrap.getModel().getCheckDate() != null) {
-            queryWrapper.lambda().ge(DispatchUnit::getCheckDate, Utils.Date.getStart(pageWrap.getModel().getCheckDate()));
-            queryWrapper.lambda().le(DispatchUnit::getCheckDate, Utils.Date.getEnd(pageWrap.getModel().getCheckDate()));
+            queryWrapper.ge(DispatchUnit::getCheckDate, Utils.Date.getStart(pageWrap.getModel().getCheckDate()));
+            queryWrapper.le(DispatchUnit::getCheckDate, Utils.Date.getEnd(pageWrap.getModel().getCheckDate()));
         }
         if (pageWrap.getModel().getCheckInfo() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getCheckInfo, pageWrap.getModel().getCheckInfo());
+            queryWrapper.eq(DispatchUnit::getCheckInfo, pageWrap.getModel().getCheckInfo());
         }
         if (pageWrap.getModel().getCheckUserId() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getCheckUserId, pageWrap.getModel().getCheckUserId());
+            queryWrapper.eq(DispatchUnit::getCheckUserId, pageWrap.getModel().getCheckUserId());
         }
         if (pageWrap.getModel().getVersion() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getVersion, pageWrap.getModel().getVersion());
+            queryWrapper.eq(DispatchUnit::getVersion, pageWrap.getModel().getVersion());
         }
         if (pageWrap.getModel().getDataType() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getDataType, pageWrap.getModel().getDataType());
+            queryWrapper.eq(DispatchUnit::getDataType, pageWrap.getModel().getDataType());
         }
         if (pageWrap.getModel().getBaseId() != null) {
-            queryWrapper.lambda().eq(DispatchUnit::getBaseId, pageWrap.getModel().getBaseId());
+            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());
-            }
-        }
-        return PageData.from(dispatchUnitMapper.selectPage(page, queryWrapper));
+        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;
     }
 
     @Override
@@ -170,4 +867,93 @@
         QueryWrapper<DispatchUnit> wrapper = new QueryWrapper<>(dispatchUnit);
         return dispatchUnitMapper.selectCount(wrapper);
     }
+
+
+    @Override
+    public DispatchUnit detailById(Integer id) {
+        DispatchUnit dispatchUnit = dispatchUnitJoinMapper.selectJoinOne(DispatchUnit.class,
+                new MPJLambdaWrapper<DispatchUnit>()
+                        .selectAll(DispatchUnit.class)
+                        .selectAs(Company::getName,DispatchUnit::getCompanyName)
+                        .leftJoin(Company.class,Company::getId,DispatchUnit::getCompanyId)
+                        .eq(DispatchUnit::getId,id) );
+        //鏂规閰嶇疆琛�
+        List<DuSolution> duSolutionList = duSolutionJoinMapper.selectJoinList(DuSolution.class,
+                new MPJLambdaWrapper<DuSolution>()
+                        .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)){
+            for (DuSolution duSolution:duSolutionList) {
+                //鏌ヨ鏂规涓嬬殑宸ョ淇℃伅
+                List<DuWorktype> duWorkTypeList = duWorkTypeJoinMapper.selectJoinList(DuWorktype.class,
+                        new MPJLambdaWrapper<DuWorktype>()
+                                .selectAll(DuWorktype.class)
+                                .selectAs(Worktype::getName,DuWorktype::getWorkTypeName)
+                                .leftJoin(Worktype.class,Worktype::getId,DuWorktype::getWorkTypeId)
+                                .eq(DuWorktype::getDuSolutionId,duSolution.getId())
+                );
+                if(CollectionUtils.isNotEmpty(duWorkTypeList)){
+                    String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.DU_FILE).getCode();
+                    duWorkTypeList.forEach(i->{
+                        if(StringUtils.isNotBlank(i.getVideoUrl())){
+                            i.setVideoUrlFull(path + i.getVideoUrl());
+                        }
+                    });
+                }
+                duSolution.setDuWorktypeList(duWorkTypeList);
+            }
+            dispatchUnit.setDuSolutionList(duSolutionList);
+        }
+        //鏌ヨ鎿嶄綔璁板綍
+        List<DuLog> duLogList = duLogJoinMapper.selectJoinList(DuLog.class,
+                new MPJLambdaWrapper<DuLog>()
+                        .selectAll(DuLog.class)
+                        .selectAs(SystemUser::getType,DuLog::getCreatorType)
+                        .selectAs(SystemUser::getRealname,DuLog::getCreatorName)
+                        .selectAs(Company::getName,DuLog::getCompanyName)
+                        .leftJoin(SystemUser.class,SystemUser::getId,DuLog::getCreator)
+                        .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId)
+                        .eq(DuLog::getDuId,dispatchUnit.getId())
+                        .orderByAsc(DuLog::getCreateDate)
+        );
+        dispatchUnit.setDuLogList(duLogList);
+        return dispatchUnit;
+    }
+
+
+    /**
+     * 鏌ヨ浼佷笟涓嬬殑娲鹃仯鍗曚綅
+     * @return
+     */
+    @Override
+    public List<DispatchUnit> findByDTO(DispatchUnitQueryDTO dispatchUnitQueryDTO) {
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        List<DispatchUnit> dispatchUnitList  = dispatchUnitJoinMapper.selectJoinList(DispatchUnit.class,
+                new MPJLambdaWrapper<DispatchUnit>().selectAll(DispatchUnit.class)
+                        .eq(DispatchUnit::getIsdeleted,Constants.ZERO)
+                        .eq(DispatchUnit::getStatus,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()+"  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 ")
+        );
+
+        return dispatchUnitList;
+    }
+
+
+
+
 }

--
Gitblit v1.9.3