111
k94314517
2024-01-29 c9df4cfec262ca54af52715af60a1276c37d08c5
server/service/src/main/java/com/doumee/service/business/impl/DispatchUnitServiceImpl.java
@@ -1,5 +1,6 @@
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;
@@ -12,10 +13,12 @@
import com.doumee.dao.business.DuSolutionMapper;
import com.doumee.dao.business.DuWorktypeMapper;
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.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;
@@ -31,6 +34,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
 * 派遣单位信息表Service实现
@@ -42,6 +46,9 @@
    @Autowired
    private DispatchUnitMapper dispatchUnitMapper;
    @Autowired
    private DispatchUnitJoinMapper dispatchUnitJoinMapper;
    @Autowired
    private DuSolutionMapper duSolutionMapper;
@@ -60,6 +67,9 @@
    @Autowired
    private DuWorkTypeJoinMapper duWorkTypeJoinMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
@@ -125,7 +135,17 @@
        List<DuWorktype> newWorktypes = new ArrayList<>();
        List<DuSolution> solutions = duSolutionMapper.selectList(new QueryWrapper<DuSolution>().lambda()
                .eq(DuSolution::getIsdeleted,Constants.ZERO)
                .eq(DuSolution::getDispatchUnitId,model.getSolutionId()));
                .eq(DuSolution::getDispatchUnitId,model.getId()));
        duSolutionMapper.update(null,new UpdateWrapper<DuSolution>().lambda()
                        .set(DuSolution::getStatus,Constants.ONE)
                .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(),"对不起,该派遣单位未设置方案工种信息,审核通过失败!");
        }
@@ -141,9 +161,18 @@
            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)
                    .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(),"对不起,该派遣单位方案存在方案是未设置工种信息信息,审核通过失败!");
            }
            for (DuWorktype w : worktypes) {
                DuWorktype nw = new DuWorktype();
                BeanUtils.copyProperties(w, nw);
@@ -166,31 +195,34 @@
    public Integer check(DispatchUnit param) {
        if(Objects.isNull(param)
                ||Objects.isNull(param.getId())
                ||param.getStatus() == null
                ||!(param.getStatus() ==Constants.ONE || param.getStatus() == Constants.TWO)){
                ||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)){
        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)){
        if(!Constants.equalsInteger(model.getUnitStatus(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该派遣单位工种已审核,请勿重复提交~");
        }
        DispatchUnit update = new DispatchUnit();
        update.setEditor(user.getId());
        update.setEditDate(new Date());
        update.setId(model.getId());
        update.setStatus(param.getStatus());
        update.setUnitStatus(param.getUnitStatus());
        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)){
        DispatchUnit dispatchUnit = dispatchUnitMapper.selectById(param.getId());
        if(Constants.equalsInteger(param.getUnitStatus(),Constants.ONE)){
            //审核通过,修改状态,产生历史版本
            newVersionData(dispatchUnitMapper.selectById(param.getId()),update);
            newVersionData(dispatchUnit,update);
            //存储操作历史
            this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.AUDIT_PASS,null);
        }else{
            //更新明细数据为审核失败
            duSolutionMapper.update(null,new UpdateWrapper<DuSolution>().lambda()
@@ -199,6 +231,28 @@
                    .set(DuSolution::getCheckUserId,update.getCheckUserId())
                    .set(DuSolution::getCheckInfo,update.getCheckInfo())
                    .eq(DuSolution::getDispatchUnitId,update.getId()));
            List<DuSolution> solutions = duSolutionMapper.selectList(new QueryWrapper<DuSolution>().lambda()
                    .eq(DuSolution::getIsdeleted,Constants.ZERO)
                    .eq(DuSolution::getDispatchUnitId,model.getId()));
            if(solutions == null || solutions.size() ==0){
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该派遣单位未设置方案工种信息,审核通过失败!");
            }
            for (DuSolution s : solutions){
                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::getDuSolutionId,s.getId()));
            }
            //存储操作历史
            this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.AUDIT_UN_PASS,update.getCheckInfo());
        }
        return  1;
    }
@@ -247,11 +301,19 @@
        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);
@@ -259,6 +321,13 @@
            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()+"】该方案下未选择工种!");
            }
@@ -269,6 +338,7 @@
                duWorktype.setCreator(loginUserInfo.getId());
                duWorktype.setIsdeleted(Constants.ZERO);
                duWorktype.setDuSolutionId(duSolution.getId());
                duWorktype.setStatus(Constants.ZERO);
                duWorktype.setSortnum(j);
                duWorktype.setWorkTypeId(saveDuWorkTypeDTO.getWorkTypeId());
                duWorktype.setVideoUrl(saveDuWorkTypeDTO.getVideoUrl());
@@ -285,7 +355,6 @@
    public Integer editDispatchUnit(SaveDispatchUnitDTO saveDispatchUnitDTO) {
        if(Objects.isNull(saveDispatchUnitDTO)
                ||Objects.isNull(saveDispatchUnitDTO.getId())
                || CollectionUtils.isEmpty(saveDispatchUnitDTO.getSaveDuSolutionDTOList())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
@@ -314,7 +383,6 @@
        dispatchUnit.setContent(saveDispatchUnitDTO.getContent());
        dispatchUnit.setName(saveDispatchUnitDTO.getName());
        dispatchUnit.setUnitStatus(Constants.ZERO);
        dispatchUnit.setWorktypeStatus(Constants.ZERO);
        dispatchUnit.setEditDate(new Date());
        dispatchUnit.setEditor(loginUserInfo.getId());
        dispatchUnitMapper.updateById(dispatchUnit);
@@ -322,7 +390,7 @@
        //存储操作记录
        this.saveDuLog(dispatchUnit,Constants.DispatchUnitLogType.EDIT_UNIT,null);
        this.dealDuData(saveDispatchUnitDTO,loginUserInfo);
//        this.dealDuData(saveDispatchUnitDTO,loginUserInfo);
        return dispatchUnit.getId();
    }
@@ -338,7 +406,7 @@
    public Integer createSolution(SaveDispatchUnitDTO saveDispatchUnitDTO) {
        if(Objects.isNull(saveDispatchUnitDTO)
                ||Objects.isNull(saveDispatchUnitDTO.getId())
                || CollectionUtils.isEmpty(saveDispatchUnitDTO.getSaveDuSolutionDTOList())
                || !CollectionUtils.isNotEmpty(saveDispatchUnitDTO.getSaveDuSolutionDTOList())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
@@ -363,7 +431,10 @@
        List<SaveDuSolutionDTO> saveDuSolutionDTOList = saveDispatchUnitDTO.getSaveDuSolutionDTOList();
        for (int i = 0; i < saveDuSolutionDTOList.size(); i++) {
            SaveDuSolutionDTO saveDuSolutionDTO = saveDuSolutionDTOList.get(i);
            DuSolution duSolution = duSolutionMapper.selectOne(new QueryWrapper<DuSolution>().lambda().eq(DuSolution::getDispatchUnitId,saveDuSolutionDTO.getId())
            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()));
@@ -372,6 +443,7 @@
                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());
@@ -383,10 +455,14 @@
            }
            for (int j = 0; j < saveDuWorkTypeDTOList.size(); j++) {
                SaveDuWorkTypeDTO saveDuWorkTypeDTO = saveDuWorkTypeDTOList.get(j);
                if(duWorktypeMapper.selectCount(new QueryWrapper<DuWorktype>().lambda().eq(DuWorktype::getDuSolutionId,duSolution.getId())
                if(Objects.isNull(saveDuWorkTypeDTO.getWorkTypeId())){
                    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()+"该工种已存在工种已存在");
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+saveDuSolutionDTO.getSolutionName()+"】该方案下"+saveDuWorkTypeDTO.getWorkTypeName()+"该工种已存在");
                }
                Integer duWorkTypeNum = duWorktypeMapper.selectCount(new QueryWrapper<DuWorktype>().lambda().eq(DuWorktype::getDuSolutionId,duSolution.getId()));
                DuWorktype duWorktype = new DuWorktype();
@@ -394,6 +470,7 @@
                duWorktype.setCreator(loginUserInfo.getId());
                duWorktype.setIsdeleted(Constants.ZERO);
                duWorktype.setDuSolutionId(duSolution.getId());
                duWorktype.setStatus(Constants.ZERO);
                duWorktype.setSortnum(duWorkTypeNum + j);
                duWorktype.setWorkTypeId(saveDuWorkTypeDTO.getWorkTypeId());
                duWorktype.setVideoUrl(saveDuWorkTypeDTO.getVideoUrl());
@@ -587,12 +664,14 @@
        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<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.lambda().eq(DispatchUnit::getIsdeleted,Constants.ZERO);
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(DispatchUnit::getId, pageWrap.getModel().getId());
        }
@@ -666,7 +745,8 @@
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(dispatchUnitMapper.selectPage(page, queryWrapper));
        PageData<DispatchUnit> dispatchUnitPageData = PageData.from(dispatchUnitMapper.selectPage(page, queryWrapper));
        return dispatchUnitPageData;
    }
    @Override
@@ -685,7 +765,7 @@
                        .selectAll(DuSolution.class)
                        .selectAs(Solutions::getName,DuSolution::getSolutionName)
                        .leftJoin(Solutions.class,Solutions::getId,DuSolution::getSolutionId)
                        .eq(DuSolution::getSolutionId,dispatchUnit.getId())
                        .eq(DuSolution::getDispatchUnitId,dispatchUnit.getId())
                        .orderByAsc(DuSolution::getSortnum)
        );
        if(CollectionUtils.isNotEmpty(duSolutionList)){
@@ -698,6 +778,14 @@
                                .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);
@@ -706,10 +794,10 @@
        List<DuLog> duLogList = duLogJoinMapper.selectJoinList(DuLog.class,
                new MPJLambdaWrapper<DuLog>()
                        .selectAll(DuLog.class)
                        .selectAs(Member::getName,DuLog::getCreatorName)
                        .selectAs(SystemUser::getRealname,DuLog::getCreatorName)
                        .selectAs(Company::getName,DuLog::getCompanyName)
                        .leftJoin(Member.class,Member::getId,DuLog::getCreator)
                        .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                        .leftJoin(SystemUser.class,SystemUser::getId,DuLog::getCreator)
                        .leftJoin(Company.class,Company::getId,SystemUser::getCompanyId)
                        .eq(DuLog::getDuId,dispatchUnit.getId())
                        .orderByAsc(DuLog::getCreateDate)
        );
@@ -725,17 +813,35 @@
    @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)
//        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.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()+" " +
//                                " ad.du_id = t.id ")
//                .orderByAsc(DispatchUnit::getSortnum)
//        );
        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)
                        .eq(loginUserInfo.getType().equals(Constants.ONE),DispatchUnit::getCompanyId,loginUserInfo.getCompanyId())
                        .eq(DispatchUnit::getStatus,Constants.ZERO)
                        .eq(DispatchUnit::getDataType,dispatchUnitQueryDTO.getDataType())
                        .eq(!Objects.isNull(dispatchUnitQueryDTO.getSolutionId()),DuSolution::getSolutionId,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 ")
        );
        return dispatchUnitList;
    }