jiangping
2024-06-11 7f9273568d9341948ed0286077e1521bb29bff4b
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/ApproveServiceImpl.java
@@ -1,16 +1,25 @@
package com.doumee.service.business.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.api.R;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dao.CompanyMapper;
import com.doumee.dao.business.dto.ApproveDTO;
import com.doumee.dao.business.join.ApproveJoinMapper;
import com.doumee.dao.business.join.CarUseBookJoinMapper;
import com.doumee.dao.business.join.VisitsJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.business.vo.ApproveDataVO;
import com.doumee.dao.system.join.NoticesJoinMapper;
import com.doumee.dao.system.model.Notices;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.web.response.InternalHomeVO;
import com.doumee.service.business.ApproveService;
@@ -18,11 +27,17 @@
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.doumee.service.system.NoticesService;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.xpath.operations.Bool;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
@@ -33,10 +48,14 @@
 * @date 2023/12/28 14:09
 */
@Service
@Slf4j
public class ApproveServiceImpl implements ApproveService {
    @Autowired
    private ApproveMapper approveMapper;
    @Autowired
    private ApproveJoinMapper approveJoinMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
@@ -58,6 +77,19 @@
    @Autowired
    private CarDriverMapper carDriverMapper;
    @Autowired
    private VisitsMapper visitsMapper;
    @Autowired
    private VisitsJoinMapper visitsJoinMapper;
    @Autowired
    private CarUseBookJoinMapper carUseBookJoinMapper;
    @Autowired
    private NoticesJoinMapper noticesJoinMapper;
    @Override
    public Integer create(Approve approve) {
@@ -204,20 +236,53 @@
    /**
     * 内部人员H5页面首页
     * @param memberId
     * @param isDetail 是否查询详细 1是;0否
     * @return
     */
    @Override
    public InternalHomeVO getHomeData(Integer memberId){
    public InternalHomeVO getHomeData(Integer memberId,Integer isDetail){
        InternalHomeVO internalHomeVO = new InternalHomeVO();
        internalHomeVO.setHomeImg(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.HOME_IMAGE).getCode());
        internalHomeVO.setTaskNum(approveMapper.selectCount(new QueryWrapper<Approve>().lambda().eq(Approve::getChekorId,memberId).eq(Approve::getStatus,Constants.ZERO)));
        //任务数据
        List<Notices> noticesList = noticesJoinMapper.
                selectList(new QueryWrapper<Notices>().lambda()
                        .eq(Notices::getUserId,memberId).orderByDesc(Notices::getCreateDate));
        internalHomeVO.setTaskNum(noticesList.size());
        if(Constants.equalsInteger(Constants.ONE,isDetail)){
            if(CollectionUtils.isNotEmpty(noticesList)){
                //待我处理的数据
                internalHomeVO.setNoticeWaitNum(
                        noticesList.stream().filter(i->Constants.equalsInteger(i.getUserId(),memberId)
                                &&Constants.equalsInteger(i.getStatus(),Constants.ZERO)
                                &&Constants.equalsInteger(i.getSendacopy(),Constants.ZERO)
                        ).count()
                );
                internalHomeVO.setNoticeDealNum(
                        noticesList.stream().filter(i->Constants.equalsInteger(i.getUserId(),memberId)
                                &&Constants.equalsInteger(i.getStatus(),Constants.ONE)
                                &&Constants.equalsInteger(i.getSendacopy(),Constants.ZERO)
                        ).count()
                );
                internalHomeVO.setNoticeCreateNum(
                        noticesJoinMapper.selectCount(new QueryWrapper<Notices>().lambda().eq(Notices::getParam3,memberId))
                );
                internalHomeVO.setNoticeCopyNum(
                        noticesList.stream().filter(i->Constants.equalsInteger(i.getUserId(),memberId)
                                &&Constants.equalsInteger(i.getSendacopy(),Constants.ONE)
                        ).count()
                );
            }
        }
        return internalHomeVO;
    }
    /**
     * 创建审批流程
     * @param tempType 模板类型  0非施工人员访客申请 1非施工人员访客申请 2访客报备 3公车市内用车 4公车室外用车 5市公司物流车预约
     * @param tempType 模板类型  0非施工人员访客申请 1施工人员访客申请 2访客报备 3公车市内用车 4公车室外用车 5市公司物流车预约
     * @param businessId 业务主键 根据 tempType
     * @param createMemberId 提交流程人员
     */
@@ -231,7 +296,7 @@
                .last(" limit 1 ")
        );
        if(Objects.isNull(approveTempl)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到配置模板");
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到审批流配置模板");
        }
        //查询配置流程
        List<ApproveParam> approveParamAllList = approveParamMapper.selectList(new QueryWrapper<ApproveParam>()
@@ -258,12 +323,12 @@
        this.organizeApproveData(approveTempl,approveParamList,createMember,businessId,approveList);
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(approveList)){
        if(CollectionUtils.isEmpty(approveList)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流配置错误");
        }
        //处理抄送数据
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(approveCopyList)){
        if(CollectionUtils.isNotEmpty(approveCopyList)){
            this.organizeApproveCopyData(approveTempl,approveParamList,businessId,approveList);
        }
        approveMapper.insertBatchSomeColumn(approveList);
@@ -280,21 +345,89 @@
     * @param approveList
     */
    public void organizeApproveData(ApproveTempl approveTempl,List<ApproveParam> approveParamList,Member createMember,Integer businessId,List<Approve> approveList){
        //创建默认人信息
        Approve createUserApprove = new Approve();
        createUserApprove.setRemark("发起申请");
        createUserApprove.setCreateDate(new Date());
        createUserApprove.setIsdeleted(Constants.ZERO);
        createUserApprove.setTemplatId(approveTempl.getId());
        createUserApprove.setChekorId(createMember.getId());
        createUserApprove.setStatus(Constants.approveStatus.pass);
        createUserApprove.setTitle("发起申请");
        createUserApprove.setStatusInfo("");
        createUserApprove.setIsEndCheck(Constants.ZERO);
        createUserApprove.setObjId(businessId);
        createUserApprove.setLevel(-1);
        createUserApprove.setObjType(approveTempl.getType());
        createUserApprove.setApproveType(Constants.TWO);
        createUserApprove.setDriverParam(Constants.ZERO);
        createUserApprove.setAddrParam(Constants.ZERO);
        createUserApprove.setType(Constants.ZERO);
        approveList.add(createUserApprove);
        //审批业务数据
        for (int i = 0; i < approveParamList.size(); i++) {
            ApproveParam approveParam = approveParamList.get(i);
            List<Integer> ids = this.getApproveUserIds(approveParam,createMember);
            for (Integer memberId:ids) {
            Integer noticeType = Constants.approveTypeToNoticeType(approveTempl.getType());
            String title = "【访客申请】申请人 - ";
            Map<String,Object> jsonMap = new HashMap<>();
            for (int j = 0; j < ids.size(); j++) {
                Integer memberId = ids.get(j);
                //生成待办 notices 表数据
                if(i==0){
                    if(jsonMap.isEmpty()){
                        title = this.createNoticesData(noticeType,businessId,title,jsonMap);
                    }
                    if(j==0){
                        //默认生成一条 申请人的数据 标记删除状态用于处理到 任务中心(我发起)使用
                        Notices notices = new Notices();
                        notices.setCreateDate(new Date());
                        notices.setIsdeleted(Constants.ONE);
                        notices.setObjId(businessId);
                        notices.setObjType(noticeType);
                        notices.setType(noticeType);
                        notices.setTitle(title);
                        notices.setParam1(JSONObject.toJSONString(jsonMap));
                        notices.setStatus(Constants.ZERO);
                        notices.setReaded(Constants.ZERO);
                        notices.setSendacopy(Constants.ZERO);
                        notices.setParam2("0");
                        notices.setParam3(createMember.getId().toString());
                        notices.setInfo("处理中");
                        noticesJoinMapper.insert(notices);
                    }
                    Notices notices = new Notices();
                    notices.setCreateDate(new Date());
                    notices.setIsdeleted(Constants.ZERO);
                    notices.setObjId(businessId);
                    notices.setObjType(noticeType);
                    notices.setType(noticeType);
                    notices.setTitle(title);
                    notices.setParam1(JSONObject.toJSONString(jsonMap));
                    notices.setUserId(memberId);
                    notices.setPalt(Constants.ZERO);
                    notices.setStatus(Constants.ZERO);
                    notices.setReaded(Constants.ZERO);
                    notices.setSendacopy(Constants.ZERO);
                    notices.setParam2("0");
                    notices.setParam3("");
                    notices.setInfo("待处理");
                    noticesJoinMapper.insert(notices);
                }
                Approve approve = new Approve();
                approve.setRemark(approveParam.getRemark());
                approve.setCreateDate(new Date());
                approve.setIsdeleted(Constants.ZERO);
                approve.setTemplatId(approveTempl.getId());
                approve.setChekorId(memberId);
                approve.setStatus(Constants.ZERO);
                approve.setStatusInfo("待审批");
                approve.setStatus(i==0?Constants.ONE:Constants.ZERO);
                approve.setStatusInfo(i==0?"审批中":"待审批");
                approve.setIsEndCheck((i+1) == approveParamList.size()?Constants.ONE:Constants.ZERO);
                approve.setObjId(businessId);
                approve.setLevel(i+1);
                approve.setObjType(approveTempl.getType());
                approve.setApproveType(approveParam.getApproveType());
                approve.setDriverParam(approveParam.getDriverParam());
                approve.setAddrParam(approveParam.getAddrParam());
@@ -302,6 +435,61 @@
                approveList.add(approve);
            }
        }
    }
    public String createNoticesData(Integer noticeType,Integer businessId,String title,Map<String,Object> jsonMap){
        jsonMap.clear();
        if(Constants.equalsInteger(noticeType,Constants.noticesObjectType.visit)
                || Constants.equalsInteger(noticeType,Constants.noticesObjectType.visitReporting)){
            //访客记录与访客报备
            Visits visits = visitsJoinMapper.selectJoinOne(Visits.class,
                    new MPJLambdaWrapper<Visits>().selectAll(Visits.class)
                            .selectAs(Member::getName,Visits::getReceptMemberName)
                            .selectAs(Company::getName,Visits::getReceptMemberDepartment)
                            .leftJoin(Member.class,Member::getId,Visits::getReceptMemberId)
                            .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                            .eq(Visits::getId,businessId)
                            .last(" limit 1 ")
            );
            if(Objects.isNull(visits)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到业务数据信息");
            }
            if(Constants.equalsInteger(noticeType,Constants.noticesObjectType.visit)){
                title = title + visits.getName();
            }else{
                title = "【访客报备】申请人 - " + visits.getName();
            }
            jsonMap.put("name", "访问人:" + visits.getCompanyName() + " - " + visits.getReceptMemberName());
            jsonMap.put("sTime", "入园时间:" + DateUtil.DateToStr(visits.getStarttime() , "yyyy-MM-dd HH:mm"));
            jsonMap.put("eTime", "离园时间:" + DateUtil.DateToStr(visits.getEndtime() , "yyyy-MM-dd HH:mm"));
            jsonMap.put("reason", StringUtils.isBlank(visits.getReason())?"来访事由: - ": "来访事由:" +visits.getReason());
            jsonMap.put("carNos", StringUtils.isBlank(visits.getCarNos())?"随行车辆: - ": "随行车辆:" +visits.getCarNos());
        }else if(Constants.equalsInteger(noticeType,Constants.noticesObjectType.useCar)){
            //用车申请
            CarUseBook carUseBook = carUseBookJoinMapper.selectJoinOne(CarUseBook.class,
                    new MPJLambdaWrapper<CarUseBook>().selectAll(CarUseBook.class)
                            .selectAs(Member::getName,CarUseBook::getMemberName)
                            .selectAs(Company::getName,CarUseBook::getCompanyName)
                            .leftJoin(Member.class,Member::getId,CarUseBook::getMemberId)
                            .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                            .eq(CarUseBook::getId,businessId)
                            .last(" limit 1 ")
            );
            if(Objects.isNull(carUseBook)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到业务数据信息");
            }
            title = "【用车申请】申请人 - " + carUseBook.getMemberName();
            jsonMap.put("name", "申请人:" + carUseBook.getCompanyName() + " - " + carUseBook.getMemberName());
            jsonMap.put("sTime", "开始时间:" + DateUtil.DateToStr(carUseBook.getStartTime() , "yyyy-MM-dd HH:mm"));
            jsonMap.put("eTime", "结束时间:" + DateUtil.DateToStr(carUseBook.getEndTime() , "yyyy-MM-dd HH:mm"));
            jsonMap.put("usrNum", StringUtils.isBlank(carUseBook.getMemberIds())?"乘车人数: 0人": "乘车人数: " +carUseBook.getMemberIds().split(",").length +"人");
            jsonMap.put("mdd", StringUtils.isBlank(carUseBook.getAddr())?"目的地: - ": "目的地:" +carUseBook.getAddr());
        }else {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
        }
        return title;
    }
@@ -315,7 +503,7 @@
                    .eq(Member::getWorkStatus,Constants.ZERO)
                    .in(Member::getId,approveParam.getObjIds().split(",")));
            List<Integer> userIds = new ArrayList<>();
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(memberList)){
            if(CollectionUtils.isNotEmpty(memberList)){
                userIds.addAll(memberList.stream().map(m->m.getId()).collect(Collectors.toList()));
            }
            //公务用车 默认加入 司机抄送
@@ -331,7 +519,7 @@
                userIds.add(carDriver.getMemberId());
            }
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(userIds)){
            if(CollectionUtils.isNotEmpty(userIds)){
                for (Integer memberId:userIds) {
                    Approve approve = new Approve();
                    approve.setCreateDate(new Date());
@@ -424,5 +612,613 @@
        return auditCompany;
    }
    @Override
    public ApproveDataVO arrangeApprovedData(Integer businessId, Integer businessType, Integer memberId){
        ApproveDataVO approveDateVO = new ApproveDataVO();
        approveDateVO.setApproveList(new ArrayList<>());
        approveDateVO.setCanBeApproved(Constants.ZERO);
        List<Approve> approveGroupList = approveJoinMapper.selectJoinList(Approve.class,
                new MPJLambdaWrapper<Approve>().
                        selectAll(Approve.class)
                        .selectAs(Member::getName,Approve::getMemberName)
                        .selectAs(Member::getPhone,Approve::getMemberPhone)
                        .selectAs(Member::getFaceImg,Approve::getFaceImg)
                        .selectAs(Company::getCompanyNamePath,Approve::getCompanyName)
                        .leftJoin(Member.class,Member::getId,Approve::getChekorId)
                        .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                        .eq(Approve::getIsdeleted,Constants.ZERO)
                        .ne(Approve::getStatus,Constants.approveStatus.cancel)
                        .eq(Approve::getObjId,businessId)
                        .eq(Approve::getObjType,businessType)
                        .orderByAsc(Approve::getLevel)
        );
        //查找全部levelList
        List<Approve> levelList = getLevelListFromResult(approveGroupList,approveDateVO,memberId);
        List<Approve> copyList = getAllCopyList(approveGroupList);
        //遍历level查询每一级别业务数据
        if(levelList!=null){
            for(Approve level:levelList){
                List<Approve> tlist = getLevelInfoFromList(level,approveGroupList);
                approveDateVO.getApproveList().addAll(tlist);
                if(tlist.size() ==0
                        ||Constants.equalsInteger(Constants.approveStatus.unPass,  tlist.get(0).getStatus())
                        ||Constants.equalsInteger(Constants.approveStatus.cancel,  tlist.get(0).getStatus())){
                    break;
                }
            }
        }
        //处理抄送记录
        if (CollectionUtils.isNotEmpty(copyList)) {
            Approve waitModel = new Approve();
            waitModel.setApproveType(Constants.ONE);
            waitModel.setTitle("抄送人");
            waitModel.setStatus(copyList.get(Constants.ZERO).getStatus());
            waitModel.setType(Constants.ONE);
            waitModel.setApproveList(copyList);
            approveDateVO.getApproveList().add(waitModel);
        }
        return approveDateVO;
    }
    private List<Approve> getAllCopyList(List<Approve> approveGroupList) {
        List<Approve> copyList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(approveGroupList)) {
            copyList.addAll(approveGroupList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)).collect(Collectors.toList()));
        }
        return copyList;
    }
    private List<Approve> getLevelInfoFromList(Approve level,List<Approve> approveGroupList) {
        List<Approve> list = new ArrayList<>();
        if(Constants.equalsInteger(level.getApproveType(),Constants.TWO)){
            level.setApproveType(Constants.ZERO);
            //如果是单人审批
            list.add(level);
            return list;
        }
        //查找全部已处理的集合
        List<Approve> passList = new ArrayList<>();//已同意的记录集
        Approve  refuseModel = new Approve();//已拒绝的记录
        List<Approve> waitList = new ArrayList<>();  //查询全部未处理的集合
        List<Approve> otherPassList = new ArrayList<>();//他人已处理的记录集
        int appType = Constants.formatIntegerNum(level.getApproveType());//当前审批类型
        dealGroupListBiz(level,approveGroupList,passList,refuseModel,waitList,otherPassList);
        if(Objects.nonNull(refuseModel) && Objects.nonNull(refuseModel.getId())){
            //存在拒绝的,只需要返回一条处理数据,后续不需要回显
            refuseModel.setApproveType(Constants.ZERO);
            list.add(refuseModel);
            return list;
        }
        list.addAll(sortByCreateTime(passList));
        if(Constants.equalsInteger(appType,Constants.ONE)){
            //如果是会签
            if(waitList.size()>1){
                Approve waitModel = new Approve();
                waitModel.setApproveType(Constants.ONE);
                waitModel.setType(Constants.ZERO);
                waitModel.setTitle(StringUtils.defaultString(level.getTitle(),"审批人"));
                waitModel.setStatus(Constants.equalsInteger(waitList.get(Constants.ZERO).getStatus(),Constants.ONE)?Constants.ONE:Constants.ZERO);
                waitModel.setStatusInfo("处理中");
                if(Constants.equalsInteger(level.getStatus(),Constants.approveStatus.auditIng)
                        ||Constants.equalsInteger(level.getStatus(),Constants.approveStatus.pass)){
                    waitModel.setMemberName(waitList.size() +"人会签");
                }
                waitModel.setApproveList(waitList);
                list.add(waitModel);
            }else if(waitList.size()>0){
                Approve approve = waitList.get(Constants.ZERO);
                approve.setApproveType(Constants.ZERO);
                approve.setType(Constants.ZERO);
                list.add(approve);
            }
        }else {
            if((waitList.size()> 0 || otherPassList.size()>0)){
                Approve waitModel = new Approve();
                waitModel.setApproveType(Constants.ONE);
                if(Constants.equalsInteger(level.getStatus(),Constants.approveStatus.pass)){
                    waitModel.setStatus(Constants.approveStatus.pass);
                    waitModel.setType(Constants.ONE);
                    waitModel.setTitle("审批人(抄送或签审批人)");
                }else{
                    waitModel.setType(Constants.ZERO);
                    waitModel.setStatusInfo(passList.size()<=0?StringUtils.defaultString(level.getTitle(),"审批人"):"抄送或签审批人");
                    waitModel.setStatus(passList.size()>0?Constants.ONE:Constants.ZERO);
                }
                List<Approve> approveList = new ArrayList<>();
                approveList.addAll(waitList);
                //如果是或签
                if(passList.size()>0){
                    approveList.addAll(otherPassList);
                }
                waitModel.setMemberName("已抄送"+ approveList.size() +"人");
                waitModel.setApproveList(approveList);
                list.add(waitModel);
            }
            //如果是或签
//            if(otherPassList.size()>0){
//                Approve waitModel = new Approve();
//                waitModel.setApproveType(Constants.ONE);
//                waitModel.setStatusInfo(StringUtils.defaultString(level.getTitle(),"审批人")+"(抄送或签审批人)");
//                waitModel.setStatus(Constants.ONE);
//                waitModel.setApproveList(otherPassList);
//                list.add(waitModel);
//            }
        }
        return  list;
    }
    private void dealGroupListBiz(Approve level, List<Approve> approveGroupList,  List<Approve> passList, Approve refuseModel, List<Approve> waitList, List<Approve> otherPassList) {
        //查询是否存在拒绝数据
        List<Approve> levelApprove = approveGroupList.stream().filter(i->Constants.equalsInteger(i.getLevel(),level.getLevel())).collect(Collectors.toList());
        for (Approve approve:levelApprove) {
            if(!Constants.equalsInteger(level.getLevel(),approve.getLevel())){
                continue;
            }
            if(Constants.equalsInteger(Constants.approveStatus.pass,approve.getStatus())){
                approve.setApproveType(Constants.ZERO);
                passList.add(approve);
            }else if(Constants.equalsInteger(Constants.approveStatus.otherDeal,approve.getStatus())){
                otherPassList.add(approve);
            }else if(Constants.equalsInteger(Constants.approveStatus.auditIng,approve.getStatus())||Constants.equalsInteger(Constants.approveStatus.wait,approve.getStatus())){
                waitList.add(approve);
            }else if(Constants.equalsInteger(Constants.approveStatus.unPass,approve.getStatus())){
                refuseModel = approve;
            }
        }
    }
    private List<Approve> sortByCreateTime(List<Approve> passList) {
        Collections.sort(passList, (a, b) -> a.getCheckDate().compareTo(b.getCheckDate()));
        return  passList;
    }
    private List<Approve> getLevelListFromResult(List<Approve> approveGroupList,ApproveDataVO approveDataVO,Integer memberId) {
        approveDataVO.setCanBeApproved(Constants.ZERO);
        approveDataVO.setDriverParam(Constants.ZERO);
        List<Approve> approveList = new ArrayList<>();
        String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode()
                +systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode();
        for (Approve approve:approveGroupList) {
            if(StringUtils.isNotBlank(approve.getFaceImg())){
                approve.setFaceImg(path + approve.getFaceImg());
            }
            if(Constants.equalsInteger(approve.getType(),Constants.ONE)){
                continue;
            }
            if(Constants.equalsInteger(approve.getChekorId(),memberId)
                    &&Constants.equalsInteger(approve.getStatus(), Constants.ONE)){
                approveDataVO.setCanBeApproved(Constants.ONE);
                approveDataVO.setDriverParam(approve.getDriverParam());
            }
            if(notExsits(approveList,approve.getLevel())){
                approveList.add(approve);
            }
        }
        if(CollectionUtils.isEmpty(approveList)){
         //   throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批信息:级别数据异常");
        }
        return  approveList;
    }
    private boolean notExsits(List<Approve> approveList, Integer level) {
        for (Approve approve:approveList) {
            if(Constants.equalsInteger(approve.getLevel(),level)){
                return false;
            }
        }
        return true;
    }
    /**
     * 整理 审批数据
     * @param businessId
     * @param businessType
     * @return
     */
//    @Override
    public ApproveDataVO arrangeApprovedDataOld(Integer businessId, Integer businessType, Integer memberId){
        ApproveDataVO approveDateVO = new ApproveDataVO();
        approveDateVO.setCanBeApproved(Constants.ZERO);
        List<Approve> approveGroupList = approveJoinMapper.selectJoinList(Approve.class,
                new MPJLambdaWrapper<Approve>().
                        select(Approve::getLevel,Approve::getType,Approve::getTitle,Approve::getApproveType)
                        .eq(Approve::getIsdeleted,Constants.ZERO)
                        .eq(Approve::getObjId,businessId)
                        .isNotNull(Approve::getLevel)
                        .eq(Approve::getObjType,businessType)
                        .groupBy(Approve::getLevel,Approve::getType,Approve::getTitle,Approve::getApproveType)
        );
        if(CollectionUtils.isEmpty(approveGroupList)){
            return approveDateVO;
        }
        //所有的审批记录
        List<Approve> approveAllList = approveJoinMapper.selectJoinList(Approve.class,
                new MPJLambdaWrapper<Approve>()
                        .selectAll(Approve.class)
                        .selectAs(Member::getName,Approve::getMemberName)
                        .selectAs(Member::getPhone,Approve::getMemberPhone)
                        .selectAs(Member::getFaceImg,Approve::getFaceImg)
                        .selectAs(Company::getName,Approve::getCompanyName)
                        .leftJoin(Member.class,Member::getId,Approve::getChekorId)
                        .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                        .leftJoin(SystemUser.class,SystemUser::getMemberId,Member::getId)
                        .eq(Approve::getIsdeleted,Constants.ZERO)
                        .eq(Approve::getObjId,businessId)
                        .eq(Approve::getObjType,businessType)
                        .orderByAsc(Approve::getType)
                        .orderByAsc(Approve::getLevel)
                        .orderByAsc(Approve::getId)
        );
        String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode()
                +systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode();
        for (Approve approve:approveAllList ) {
            if(StringUtils.isNotBlank(approve.getFaceImg())){
                approve.setFaceImg(path + approve.getFaceImg());
            }
        }
        if(CollectionUtils.isEmpty(approveAllList)){
            return approveDateVO;
        }
        List<Approve> approveList = approveAllList.stream().filter(i->Constants.equalsInteger(i.getType(),(Constants.ZERO)))
                .collect(Collectors.toList());
        if(CollectionUtils.isEmpty(approveList)){
            return approveDateVO;
        }
        approveDateVO.setCanBeApproved(this.canBeApproved(approveList,memberId));
        approveDateVO.setDriverParam(this.canDriverParam(approveList,memberId));
        //根据审批级别 处理数据
        for (Approve approve:approveGroupList) {
            approve.setApproveList(
                    approveList.stream().filter(i->Objects.nonNull(i.getLevel())&&i.getLevel().equals(approve.getLevel())).collect(Collectors.toList())
            );
        }
        approveDateVO.setApproveList(approveGroupList);
        approveDateVO.setCopyList(approveAllList.stream().filter(i->i.getType().equals(Constants.ONE)).collect(Collectors.toList()));
        return approveDateVO;
    }
    public Integer canBeApproved(List<Approve> approveList,Integer memberId){
        //获取所有待审批的数据
        List<Approve> waitApprovedList = approveList.stream().filter(i->i.getType().equals(Constants.ZERO)&&i.getStatus().equals(Constants.ZERO)).collect(Collectors.toList());
        if(CollectionUtils.isNotEmpty(waitApprovedList)){
            //下个审批流程等级
            Integer nextApprovedLevel = waitApprovedList.get(Constants.ZERO).getLevel();
            //下个审批流程的 所有数据
            List<Approve> nextApprovedList = waitApprovedList.stream().filter(i->i.getStatus().equals(Constants.ZERO)&&i.getLevel().equals(nextApprovedLevel)).collect(Collectors.toList());
            //下个审批流程内 如果存在当前 用户的抓紧 则可以进行审批
            if(nextApprovedList.stream().filter(i->i.getChekorId().equals(memberId)).collect(Collectors.toList()).size()>0){
                return Constants.ONE;
            }
        }
        return Constants.ZERO;
    }
    public Integer canDriverParam(List<Approve> approveList,Integer memberId){
        //获取所有待审批的数据
        List<Approve> waitApprovedList = approveList.stream().filter(i->i.getType().equals(Constants.ZERO)&&i.getStatus().equals(Constants.ZERO)).collect(Collectors.toList());
        if(CollectionUtils.isNotEmpty(waitApprovedList)){
            //下个审批流程等级
            Integer nextApprovedLevel = waitApprovedList.get(Constants.ZERO).getLevel();
            //下个审批流程的 所有数据
            List<Approve> nextApprovedList = waitApprovedList.stream().filter(i->i.getStatus().equals(Constants.ZERO)&&i.getLevel().equals(nextApprovedLevel)).collect(Collectors.toList());
            //下个审批流程内 如果存在当前 用户的抓紧 则可以进行审批
            List<Approve> auditApproveList  = nextApprovedList.stream().filter(i->i.getChekorId().equals(memberId)).collect(Collectors.toList());
            if(auditApproveList.size() >0){
                Approve auditApprove = auditApproveList.get(Constants.ZERO);
                return auditApprove.getDriverParam();
            }
        }
        return Constants.ZERO;
    }
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void approved(ApproveDTO approveDTO){
        if(Objects.isNull(approveDTO)
        || Objects.isNull(approveDTO.getObjId())
                || Objects.isNull(approveDTO.getObjType())
                || Objects.isNull(approveDTO.getStatus())
                || Objects.isNull(approveDTO.getLoginUserInfo())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(approveDTO.getStatus().equals(Constants.THREE)&&StringUtils.isBlank(approveDTO.getCheckInfo())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请输入拒绝说明");
        }
        Approve approve = approveMapper.selectOne(new QueryWrapper<Approve>()
                .lambda()
                .eq(Approve::getObjId,approveDTO.getObjId())
                .eq(Approve::getObjType,approveDTO.getObjType())
                .eq(Approve::getChekorId,approveDTO.getLoginUserInfo().getMemberId())
                .eq(Approve::getType,Constants.ZERO)
                .eq(Approve::getStatus,Constants.approveStatus.auditIng)
                .last(" limit 1")
        );
        if(Objects.isNull(approve)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到审批数据");
        }
        if(!approve.getStatus().equals(Constants.ONE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批记录状态错误!");
        }
        //根据审批记录查询 当前处理数据对应的 通知记录
        Integer noticeType = Constants.approveTypeToNoticeType(approve.getObjType());
        Notices  notices = noticesJoinMapper.selectOne(new QueryWrapper<Notices>().lambda()
                .eq(Notices::getObjId,approve.getObjId())
                .eq(Notices::getObjType,noticeType)
                .eq(Notices::getUserId,approve.getChekorId())
                .eq(Notices::getSendacopy,Constants.ZERO)
                .eq(Notices::getIsdeleted,Constants.ZERO)
        );
        if(Objects.isNull(notices)){
            log.info("未查询到通知记录");
            return;
        }
        //处理审批信息
        approve.setStatus(approveDTO.getStatus());
        approve.setCheckInfo(approveDTO.getCheckInfo());
        approve.setCheorId(approveDTO.getLoginUserInfo().getMemberId().toString());
        approve.setCheckorName(approveDTO.getLoginUserInfo().getRealname());
        approve.setCheckDate(new Date());
        approve.setStatusInfo(approveDTO.getStatus()==Constants.TWO?"已同意":approveDTO.getCheckInfo());
        //本级所有 待审批记录
        List<Approve> approveList = approveJoinMapper.selectJoinList(Approve.class,
                new MPJLambdaWrapper<Approve>()
                        .selectAll(Approve.class)
                        .eq(Approve::getIsdeleted,Constants.ZERO)
                        .eq(Approve::getObjId,approveDTO.getObjId())
                        .eq(Approve::getObjType,approveDTO.getObjType())
                        .eq(Approve::getLevel,approve.getLevel())
                        .eq(Approve::getStatus,Constants.ONE)
                        .eq(Approve::getType,Constants.ZERO)
                        .ne(Approve::getId,approve.getId())
        );
        //业务数据下配置的所有抄送记录
        List<Approve> approveCopyList = approveJoinMapper.selectJoinList(Approve.class,
                new MPJLambdaWrapper<Approve>()
                        .selectAll(Approve.class)
                        .eq(Approve::getIsdeleted,Constants.ZERO)
                        .eq(Approve::getObjId,approveDTO.getObjId())
                        .eq(Approve::getObjType,approveDTO.getObjType())
                        .eq(Approve::getType,Constants.ONE)
        );
        //处理本次审批的业务数据
        approveMapper.updateById(approve);
        //是否处理 业务数据
        Boolean dealBusinessBean = false;
        //审批驳回情况
        if(approveDTO.getStatus().equals(Constants.THREE)){
            //修改其他所有待审批和审批中记录数据
            approveJoinMapper.update(null,new UpdateWrapper<Approve>()
                    .lambda()
                    .set(Approve::getStatus,Constants.approveStatus.otherUnPass)
                    .in(Approve::getStatus,Constants.approveStatus.auditIng,Constants.approveStatus.wait)
                    .eq(Approve::getObjId,approve.getObjId())
                    .eq(Approve::getObjType,approve.getObjType())
                    .ne(Approve::getId,approve.getId()));
            //处理所有Notice通知为已处理
            if(approve.getApproveType().equals(Constants.ZERO)){
                //修改自己的通知记录
                noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda()
                        .set(Notices::getEditDate,new Date())
                        .set(Notices::getReaded,Constants.ONE)
                        .set(Notices::getParam2,approve.getStatus())
                        .eq(Notices::getId,notices.getId())
                );
                //修改 未处理的 通知数据 为抄送
                if (!Constants.equalsInteger(approve.getApproveType(),Constants.TWO)){
                    noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda()
                            .set(Notices::getEditDate,new Date())
                            .set(Notices::getSendacopy,Constants.ONE)
                            .set(Notices::getParam2,approve.getStatus())
                            .eq(Notices::getObjId,notices.getObjId())
                            .eq(Notices::getObjType,notices.getObjType())
                            .eq(Notices::getReaded,Constants.ZERO)
                            .ne(Notices::getId,notices.getId())
                    );
                }
            }
            return;
        }else{
            //处理其他业务数据
            if((Constants.equalsInteger(approve.getApproveType(),Constants.ZERO)
                    || Constants.equalsInteger( approve.getApproveType(),Constants.TWO)) && Constants.equalsInteger(approve.getIsEndCheck(),Constants.ONE)){
                //或签 / 单人审 且 终审
                approveJoinMapper.update(null,new UpdateWrapper<Approve>()
                        .lambda()
                        .set(Approve::getStatus,Constants.approveStatus.otherDeal)
                        .in(Approve::getId,approveList.stream().map(m->m.getId()).collect(Collectors.toList())));
                dealBusinessBean = true;
            }else if((approve.getApproveType().equals(Constants.ZERO)
                    || approve.getApproveType().equals(Constants.TWO)) &&approve.getIsEndCheck()!=Constants.ONE){
                //或签 / 单人审 非终审 则开启下一步业务流程
                /**处理本级数据**/
                approveJoinMapper.update(null,new UpdateWrapper<Approve>()
                        .lambda()
                        .set(Approve::getStatus,Constants.approveStatus.otherDeal)
                        .in(Approve::getId,approveList.stream().map(m->m.getId()).collect(Collectors.toList())));
                /**开启下一级别的数据为待审核**/
                approveJoinMapper.update(null,new UpdateWrapper<Approve>()
                        .lambda()
                        .set(Approve::getStatus,Constants.approveStatus.auditIng)
                        .eq(Approve::getStatus,Constants.approveStatus.wait)
                        .eq(Approve::getObjId,approve.getObjId())
                        .eq(Approve::getObjType,approve.getObjType())
                        .eq(Approve::getLevel,(approve.getLevel()+1))
                );
            }else if(approve.getApproveType().equals(Constants.ONE)){
                //会签 且终审
                //无他人审批的情况 则修改数据状态
                if(Constants.equalsInteger(approveList.size(),Constants.ZERO)&&Constants.equalsInteger(approve.getIsEndCheck(),Constants.ONE)){
                    dealBusinessBean = true;
                }
            }
            this.passNextNotices(dealBusinessBean,notices,approve,approveList,approveCopyList);
        }
        //处理业务数据
        if(dealBusinessBean){
            this.dealBusinessData(approveDTO,approve);
        }
    }
    /**
     * 处理待办信息
     * @param dealBusinessBean  是否需要进行更新业务数据状态
     * @param approve  审批记录
     * @param approveList  同级待审批数据
     */
    public void passNextNotices(Boolean dealBusinessBean,Notices notices,Approve approve,List<Approve> approveList,List<Approve> copyList){
        //1、修改自己的数据记录
        noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda()
                .set(Notices::getEditDate,new Date())
                .set(Notices::getReaded,Constants.ONE)
                .set(dealBusinessBean,Notices::getParam2,approve.getStatus())
                .eq(Notices::getId,notices.getId())
        );
        if(Constants.equalsInteger(approve.getApproveType(),Constants.ZERO)){
            //或签
            //2、更新他人的同级记录 为抄送
            noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda()
                    .set(Notices::getEditDate,new Date())
                    .set(Notices::getReaded,Constants.ONE)
                    .set(Notices::getSendacopy,Constants.ONE)
                    .set(dealBusinessBean,Notices::getParam2,approve.getStatus())
                    .eq(Notices::getObjId,notices.getObjId())
                    .eq(Notices::getObjType,notices.getObjType())
                    .ne(Notices::getId,notices.getId())
            );
            //3、如果不是终审生成下一级的数据记录
            if(Constants.equalsInteger(approve.getIsEndCheck(),Constants.ZERO)&&!dealBusinessBean){
              this.saveNextNotice(notices,approve);
            }
        }else if(Constants.equalsInteger(approve.getApproveType(),Constants.ONE)){
            //会签
            //2、如果是最后一位审批人 且不是终审开启下一级数据
            if(Constants.equalsInteger(Constants.ZERO,approveList.size())){
                if(Constants.equalsInteger(approve.getIsEndCheck(),Constants.ZERO)){
                    this.saveNextNotice(notices,approve);
                }
            }
        }else{
            //单人签
            //2、 是否是终审 开启下一级数据
            if(Constants.equalsInteger(approve.getIsEndCheck(),Constants.ZERO)){
                this.saveNextNotice(notices,approve);
            }
        }
        //终审业务 且 处理数据  进行抄送发送
        if (Constants.equalsInteger(approve.getIsEndCheck(),Constants.ONE) && dealBusinessBean) {
            if(CollectionUtils.isNotEmpty(copyList)){
                Notices copyNotices = new Notices();
                for (Approve copyApprove:copyList) {
                    if(Objects.isNull(copyNotices)){
                        BeanUtils.copyProperties(notices,copyNotices);
                        notices.setId(null);
                        notices.setCreateDate(new Date());
                        notices.setEditDate(new Date());
                        notices.setParam2("2");
                        notices.setParam3("");
                        notices.setUserId(copyApprove.getChekorId());
                        notices.setStatus(Constants.ZERO);
                        notices.setSendacopy(Constants.ONE);
                        notices.setReaded(Constants.ZERO);
                        noticesJoinMapper.insert(notices);
                    }else{
                        notices.setId(null);
                        notices.setUserId(copyApprove.getChekorId());
                        noticesJoinMapper.insert(notices);
                    }
                }
            }
        }
    }
    public void saveNextNotice(Notices notices,Approve approve){
        List<Approve> nextApproveList = approveJoinMapper.selectList(new QueryWrapper<Approve>()
                .lambda()
                .eq(Approve::getObjId,approve.getObjId())
                .eq(Approve::getObjType,approve.getObjType())
                .eq(Approve::getType,Constants.ZERO)
                .eq(Approve::getLevel,(approve.getLevel() + Constants.ONE))
        );
        if(CollectionUtils.isNotEmpty(nextApproveList)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流数据异常");
        }
        Notices newNotices = new Notices();
        for (Approve nextDealApprove:nextApproveList) {
            if(Objects.isNull(newNotices)){
                BeanUtils.copyProperties(notices,newNotices);
                notices.setId(null);
                notices.setCreateDate(new Date());
                notices.setParam2("0");
                notices.setParam3("");
                notices.setEditDate(new Date());
                notices.setUserId(nextDealApprove.getChekorId());
                notices.setStatus(Constants.ZERO);
                notices.setSendacopy(Constants.ZERO);
                notices.setReaded(Constants.ZERO);
                noticesJoinMapper.insert(notices);
            }else{
                notices.setId(null);
                notices.setUserId(nextDealApprove.getChekorId());
                noticesJoinMapper.insert(notices);
            }
        }
    }
    public void dealBusinessData(ApproveDTO approveDTO,Approve approve){
        if(approveDTO.getObjType().equals(Constants.approveObjectType.unConstructionVisit)
                ||approveDTO.getObjType().equals(Constants.approveObjectType.constructionVisit)
                ||approveDTO.getObjType().equals(Constants.approveObjectType.visitReporting)){
            // 访客 三类业务数据
            Visits visits = visitsMapper.selectById(approveDTO.getObjId());
            if(Objects.isNull(visits)){
                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到申请记录");
            }
            visits.setStatus(approveDTO.getStatus());
            visits.setEditDate(new Date());
            visits.setEditor(approveDTO.getLoginUserInfo().getMemberId());
            visitsMapper.updateById(visits);
        }else if(approveDTO.getObjType().equals(Constants.approveObjectType.cityUseCar)||approveDTO.getObjType().equals(
                Constants.approveObjectType.unCityUseCar)){
            // 市内外用车申请
            CarUseBook carUseBook = carUseBookMapper.selectById(approveDTO.getObjId());
            if(Objects.isNull(carUseBook)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到用车记录");
            }
            carUseBook.setStatus(approveDTO.getStatus());
            carUseBook.setEditDate(new Date());
            carUseBook.setEditor(approveDTO.getLoginUserInfo().getMemberId());
            //如果配置修改司机 且 入参了更换后司机信息
            if(approveDTO.getStatus()==Constants.TWO&&Constants.equalsInteger(approve.getDriverParam(),Constants.ONE)){
                CarDriver carDriver = carDriverMapper.selectById(approveDTO.getDriverId());
                if(Objects.isNull(carDriver)){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到司机信息");
                }
                carUseBook.setDriverId(carDriver.getId());
            }
            carUseBookMapper.updateById(carUseBook);
        }else if(approveDTO.getObjType().equals(Constants.approveObjectType.logisticsCarUse)){
            //TODO  物流车预约
        }else{
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
    }
}