| | |
| | | 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.model.*; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | import com.doumee.dao.business.vo.ApproveDataVO; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.dao.web.response.InternalHomeVO; |
| | | import com.doumee.service.business.ApproveService; |
| | |
| | | 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.xpath.operations.Bool; |
| | | 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; |
| | |
| | | |
| | | @Autowired |
| | | private ApproveMapper approveMapper; |
| | | |
| | | @Autowired |
| | | private ApproveJoinMapper approveJoinMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | |
| | | |
| | | @Autowired |
| | | private CarDriverMapper carDriverMapper; |
| | | |
| | | @Autowired |
| | | private VisitsMapper visitsMapper; |
| | | |
| | | @Override |
| | | public Integer create(Approve approve) { |
| | |
| | | |
| | | /** |
| | | * 创建审批流程 |
| | | * @param tempType 模板类型 0非施工人员访客申请 1非施工人员访客申请 2访客报备 3公车市内用车 4公车室外用车 5市公司物流车预约 |
| | | * @param tempType 模板类型 0非施工人员访客申请 1施工人员访客申请 2访客报备 3公车市内用车 4公车室外用车 5市公司物流车预约 |
| | | * @param businessId 业务主键 根据 tempType |
| | | * @param createMemberId 提交流程人员 |
| | | */ |
| | |
| | | .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>() |
| | |
| | | |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | .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())); |
| | | } |
| | | //公务用车 默认加入 司机抄送 |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 整理 审批数据 |
| | | * @param businessId |
| | | * @param businessType |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ApproveDataVO arrangeApprovedData(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) |
| | | .eq(Approve::getIsdeleted,Constants.ZERO) |
| | | .eq(Approve::getObjId,businessId) |
| | | .isNotNull(Approve::getLevel) |
| | | .eq(Approve::getObjType,businessType) |
| | | .groupBy(Approve::getLevel,Approve::getType) |
| | | ); |
| | | 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(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) |
| | | ); |
| | | if(CollectionUtils.isEmpty(approveAllList)){ |
| | | return approveDateVO; |
| | | } |
| | | List<Approve> approveList = approveAllList.stream().filter(i->i.getType().equals(Constants.ZERO)).collect(Collectors.toList()); |
| | | if(CollectionUtils.isEmpty(approveList)){ |
| | | return approveDateVO; |
| | | } |
| | | approveDateVO.setCanBeApproved(this.canBeApproved(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; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | @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()) |
| | | .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(),"审批记录状态错误!"); |
| | | } |
| | | |
| | | //处理审批信息 |
| | | approve.setStatus(approveDTO.getStatus()); |
| | | approve.setCheckInfo(approveDTO.getCheckInfo()); |
| | | approve.setCheorId(approveDTO.getLoginUserInfo().getMemberId().toString()); |
| | | approve.setCheckorName(approve.getLoginUserInfo().getRealname()); |
| | | approve.setStatusInfo(approveDTO.getStatus()==Constants.TWO?"审批通过":approveDTO.getCheckInfo()); |
| | | Visits visits = new Visits(); |
| | | CarUseBook carUseBook = new CarUseBook(); |
| | | this.dealBusinessData(approveDTO,approve,visits,carUseBook); |
| | | //本级所有 待审批记录 |
| | | 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) |
| | | .ne(Approve::getId,approve.getId()) |
| | | ); |
| | | //处理本次审批的业务数据 |
| | | 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())); |
| | | }else{ |
| | | //处理其他业务数据 |
| | | if(approve.getApproveType().equals(Constants.ZERO)&&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.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)&&approve.getIsEndCheck()==Constants.ONE){ |
| | | //会签 且终审 |
| | | if(approveList.size()==Constants.ZERO){ |
| | | dealBusinessBean = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(approveDTO.getObjType().equals(Constants.approveObjectType.unConstructionVisit) |
| | | ||approveDTO.getObjType().equals(Constants.approveObjectType.constructionVisit) |
| | | ||approveDTO.getObjType().equals(Constants.approveObjectType.visitReporting)){ |
| | | // 访客 三类业务数据 |
| | | visitsMapper.updateById(visits); |
| | | if(dealBusinessBean){ |
| | | //TODO 发送审批通过消息 |
| | | |
| | | }else if(approveDTO.getStatus().equals(Constants.THREE)){ |
| | | //TODO 审批未通过通知 |
| | | |
| | | } |
| | | |
| | | |
| | | }else if(approveDTO.getObjType().equals(Constants.approveObjectType.cityUseCar)||approveDTO.getObjType().equals( |
| | | Constants.approveObjectType.unCityUseCar)){ |
| | | // 市内外用车申请 |
| | | carUseBookMapper.updateById(carUseBook); |
| | | if(dealBusinessBean){ |
| | | //TODO 发送审批通过消息 |
| | | |
| | | }else if(approveDTO.getStatus().equals(Constants.THREE)){ |
| | | //TODO 审批未通过通知 |
| | | |
| | | } |
| | | |
| | | |
| | | }else if(approveDTO.getObjType().equals(Constants.approveObjectType.logisticsCarUse)){ |
| | | //TODO 物流车预约 |
| | | |
| | | } |
| | | } |
| | | |
| | | public void dealBusinessData(ApproveDTO approveDTO,Approve approve,Visits visits,CarUseBook carUseBook){ |
| | | if(approveDTO.getObjType().equals(Constants.approveObjectType.unConstructionVisit) |
| | | ||approveDTO.getObjType().equals(Constants.approveObjectType.constructionVisit) |
| | | ||approveDTO.getObjType().equals(Constants.approveObjectType.visitReporting)){ |
| | | // 访客 三类业务数据 |
| | | 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()); |
| | | |
| | | |
| | | }else if(approveDTO.getObjType().equals(Constants.approveObjectType.cityUseCar)||approveDTO.getObjType().equals( |
| | | Constants.approveObjectType.unCityUseCar)){ |
| | | // 市内外用车申请 |
| | | 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&&approve.getDriverParam().equals(Constants.ONE)){ |
| | | CarDriver carDriver = carDriverMapper.selectById(approveDTO.getDriverId()); |
| | | if(Objects.isNull(carDriver)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到司机信息"); |
| | | } |
| | | carUseBook.setDriverId(carDriver.getId()); |
| | | } |
| | | |
| | | }else if(approveDTO.getObjType().equals(Constants.approveObjectType.logisticsCarUse)){ |
| | | //TODO 物流车预约 |
| | | |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |