songhuangfeng123
2022-08-12 5703d0e9865df3ba05bb02bc382ce59fbf5f7da0
goal-manage/goal-manage-service/src/main/java/com/gkhy/safePlatform/targetDuty/service/impl/TargetDutyWorkApproveServiceImpl.java
对比新文件
@@ -0,0 +1,177 @@
package com.gkhy.safePlatform.targetDuty.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
import com.gkhy.safePlatform.targetDuty.enums.TargetDutyResultCodes;
import com.gkhy.safePlatform.targetDuty.excepiton.TargetDutyException;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.ListCheckDataDto;
import com.gkhy.safePlatform.targetDuty.repository.TargetDutyWorkApproveRepository;
import com.gkhy.safePlatform.targetDuty.entity.TargetDutyWorkApprove;
import com.gkhy.safePlatform.targetDuty.service.CommonService;
import com.gkhy.safePlatform.targetDuty.service.TargetDutyWorkApproveService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.query.PageQuery;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.targetDuty.model.dto.req.TargetDutyWorkApproveQueryCriteria;
import com.gkhy.safePlatform.targetDuty.model.dto.resp.TargetDutyWorkApproveDto;
import com.gkhy.safePlatform.targetDuty.utils.QueryHelpPlus;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.*;
/**
 * 目标责任管理工作流审批表(TargetDutyWorkApprove)表服务实现类
 *
 * @author xurui
 * @since 2022-08-11 10:13:37
 */
@Service("targetDutyWorkApproveService")
public class TargetDutyWorkApproveServiceImpl extends ServiceImpl<TargetDutyWorkApproveRepository, TargetDutyWorkApprove> implements TargetDutyWorkApproveService {
    @Autowired
    private TargetDutyWorkApproveRepository targetDutyWorkApproveRepository;
    @Resource
    private CommonService commonService;
   @Override
    public ResultVO queryAll(PageQuery<TargetDutyWorkApproveQueryCriteria> pageQuery) {
        Long pageIndex = pageQuery.getPageIndex();
        Long pageSize = pageQuery.getPageSize();
        IPage<TargetDutyWorkApprove> page = new Page<>(pageIndex, pageSize);
        QueryWrapper queryWrapper = QueryHelpPlus.getPredicate(TargetDutyWorkApprove.class, pageQuery.getSearchParams());
        queryWrapper.eq("del_flag","0");
        page = baseMapper.selectPage(page,queryWrapper);
        List<TargetDutyWorkApproveDto> respList = BeanCopyUtils.copyBeanList(page.getRecords(), TargetDutyWorkApproveDto.class);
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
        );
    }
    @Override
    public List<TargetDutyWorkApprove> queryAll(TargetDutyWorkApproveQueryCriteria criteria) {
        return baseMapper.selectList(QueryHelpPlus.getPredicate(TargetDutyWorkApprove.class, criteria));
    }
    @Override
    public void updateInfo(ContextCacheUser currentUser, TargetDutyWorkApprove targetDutyWorkApprove) {
        Date nowDate = new Date();
        Long uid = currentUser.getUid();
        String uName = currentUser.getRealName();
        //新增下级审批记录
        TargetDutyWorkApprove addInfo = new TargetDutyWorkApprove();
        if (targetDutyWorkApprove.getApproveStatus() == 2){
            BeanUtils.copyProperties(targetDutyWorkApprove, addInfo);
            addInfo.setId(null);
            addInfo.setDelFlag(0);
            addInfo.setCreateUid(uid);
            addInfo.setGmtCreate(new Timestamp(nowDate.getTime()));
            addInfo.setSubmitPersonId(uid);
            addInfo.setSubmitPersonName(uName);
            addInfo.setApproveResult(null);
            addInfo.setApproveMemo(null);
            addInfo.setSort(addInfo.getSort()+1);
            targetDutyWorkApproveRepository.insert(addInfo);
        }
        // 更新原审批记录
        TargetDutyWorkApprove updateInfo = new TargetDutyWorkApprove();
        updateInfo.setId(targetDutyWorkApprove.getId());
        updateInfo.setUpdateUid(uid);
        updateInfo.setGmtModitify(new Timestamp(nowDate.getTime()));
        updateInfo.setApproveStatus(targetDutyWorkApprove.getApproveStatus());
        updateInfo.setApproveResult(targetDutyWorkApprove.getApproveResult());
        updateInfo.setApproveMemo(targetDutyWorkApprove.getApproveMemo());
        updateInfo.setChildId(addInfo.getId());
        targetDutyWorkApproveRepository.updateById(updateInfo);
    }
    @Override
    public void addInfo(ContextCacheUser currentUser, TargetDutyWorkApprove targetDutyWorkApprove) {
        // 业务类型
        if (targetDutyWorkApprove.getRelateType()==null){
            throw new TargetDutyException(TargetDutyResultCodes.APPROVE_RELATE_ID_NULL);
        }
        // 业务主表id
        if (targetDutyWorkApprove.getRelateId()==null){
            throw new TargetDutyException(TargetDutyResultCodes.APPROVE_RELATE_TYPE_NULL);
        }
        // 审批人
        if (targetDutyWorkApprove.getApprovePersonId()==null){
            throw new TargetDutyException(TargetDutyResultCodes.APPROVE_PERSON_NULL);
        }
        // 审批状态
        if (targetDutyWorkApprove.getApproveStatus()==null){
            throw new TargetDutyException(TargetDutyResultCodes.APPROVE_STATUS_NULL);
        }
        Date nowDate = new Date();
        Long uid = currentUser.getUid();
        String uName = currentUser.getRealName();
        //1.新增应急审批
        TargetDutyWorkApprove info = new TargetDutyWorkApprove();
        BeanUtils.copyProperties(targetDutyWorkApprove, info);
        info.setDelFlag(0);
        info.setCreateUid(uid);
        info.setGmtCreate(new Timestamp(nowDate.getTime()));
        info.setSubmitPersonId(uid);
        info.setSubmitPersonName(uName);
        info.setSort(1);
        targetDutyWorkApproveRepository.insert(info);
    }
    @Override
    public ResultVO listCheckData(PageQuery<TargetDutyWorkApproveQueryCriteria> pageQuery) {
        Long pageIndex = pageQuery.getPageIndex();
        Long pageSize = pageQuery.getPageSize();
        IPage<ListCheckDataDto> page = new Page<>(pageIndex, pageSize);
        page = targetDutyWorkApproveRepository.listCheckData(page,pageQuery.getSearchParams().getRelateId());
        List<ListCheckDataDto> respList = page.getRecords();
        // --------------------------- 获取部门信息-----------------------
        //收集所用到的部门ID
        Set<Long> collectDepIdSet = new HashSet();
        respList.forEach(f->{
            collectDepIdSet.add(f.getDutyDepartmentId());
            collectDepIdSet.add(f.getMakerDepartmentId());
        });
        //获取部门名集合
        Map<Long,String> depNameMap = commonService.getDepName(collectDepIdSet);
        respList.forEach(f->{
            f.setDutyDepartmentName(depNameMap.get(f.getDutyDepartmentId()));
            f.setMakerDepartmentName(depNameMap.get(f.getMakerDepartmentId()));
        });
        return new SearchResultVO<>(
                true,
                pageIndex,
                pageSize,page.getPages(),
                page.getTotal(),
                respList,
                ResultCodes.OK
        );
    }
}