| | |
| | | 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.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.ApproveMapper; |
| | | import com.doumee.dao.business.model.Approve; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.dao.CompanyMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | 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.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 org.apache.commons.lang3.StringUtils; |
| | | 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.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 审批信息记录表Service实现 |
| | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Autowired |
| | | private ApproveTemplMapper approveTemplMapper; |
| | | |
| | | @Autowired |
| | | private ApproveParamMapper approveParamMapper; |
| | | |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | @Autowired |
| | | private CompanyMapper companyMapper; |
| | | |
| | | @Autowired |
| | | private CarUseBookMapper carUseBookMapper; |
| | | |
| | | @Autowired |
| | | private CarDriverMapper carDriverMapper; |
| | | |
| | | @Override |
| | | public Integer create(Approve approve) { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 创建审批流程 |
| | | * @param tempType 模板类型 0非施工人员访客申请 1非施工人员访客申请 2访客报备 3公车市内用车 4公车室外用车 5市公司物流车预约 |
| | | * @param businessId 业务主键 根据 tempType |
| | | * @param createMemberId 提交流程人员 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | public void createApproveFlow(Integer tempType,Integer businessId,Integer createMemberId){ |
| | | //查询处理模板 |
| | | ApproveTempl approveTempl = approveTemplMapper.selectOne(new QueryWrapper<ApproveTempl>().lambda() |
| | | .eq(ApproveTempl::getType,tempType) |
| | | .eq(ApproveTempl::getIsdeleted,Constants.ZERO) |
| | | .last(" limit 1 ") |
| | | ); |
| | | if(Objects.isNull(approveTempl)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到配置模板"); |
| | | } |
| | | //查询配置流程 |
| | | List<ApproveParam> approveParamAllList = approveParamMapper.selectList(new QueryWrapper<ApproveParam>() |
| | | .lambda().eq(ApproveParam::getIsdeleted,Constants.ZERO) |
| | | .eq(ApproveParam::getTemplId,approveTempl.getId()) |
| | | .orderByAsc(ApproveParam::getType) |
| | | .orderByAsc(ApproveParam::getLevel) |
| | | ); |
| | | if(Objects.isNull(approveParamAllList)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未配置审批流程"); |
| | | } |
| | | //审批配置 |
| | | List<ApproveParam> approveParamList = approveParamAllList.stream().filter(i->i.getType().equals(Constants.ZERO)).collect(Collectors.toList()); |
| | | if(Objects.isNull(approveParamList)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未配置审批流程"); |
| | | } |
| | | List<ApproveParam> approveCopyList = approveParamAllList.stream().filter(i->i.getType().equals(Constants.ONE)).collect(Collectors.toList()); |
| | | |
| | | Member createMember = memberMapper.selectById(createMemberId); |
| | | if(Objects.isNull(createMember)|| Objects.isNull(createMember.getCompanyId())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"申请人组织信息异常"); |
| | | } |
| | | List<Approve> approveList = new ArrayList<>(); |
| | | |
| | | this.organizeApproveData(approveTempl,approveParamList,createMember,businessId,approveList); |
| | | |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(approveList)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流配置错误"); |
| | | } |
| | | |
| | | //处理抄送数据 |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(approveCopyList)){ |
| | | this.organizeApproveCopyData(approveTempl,approveParamList,businessId,approveList); |
| | | } |
| | | approveMapper.insertBatchSomeColumn(approveList); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 组织审批流数据 |
| | | * @param approveTempl |
| | | * @param approveParamList |
| | | * @param createMember |
| | | * @param businessId |
| | | * @param approveList |
| | | */ |
| | | public void organizeApproveData(ApproveTempl approveTempl,List<ApproveParam> approveParamList,Member createMember,Integer businessId,List<Approve> approveList){ |
| | | //审批业务数据 |
| | | for (int i = 0; i < approveParamList.size(); i++) { |
| | | ApproveParam approveParam = approveParamList.get(i); |
| | | List<Integer> ids = this.getApproveUserIds(approveParam,createMember); |
| | | for (Integer memberId:ids) { |
| | | Approve approve = new Approve(); |
| | | approve.setCreateDate(new Date()); |
| | | approve.setIsdeleted(Constants.ZERO); |
| | | approve.setTemplatId(approveTempl.getId()); |
| | | approve.setChekorId(memberId); |
| | | approve.setStatus(Constants.ZERO); |
| | | approve.setStatusInfo("待审批"); |
| | | approve.setIsEndCheck((i+1) == approveParamList.size()?Constants.ONE:Constants.ZERO); |
| | | approve.setObjId(businessId); |
| | | approve.setLevel(i+1); |
| | | approve.setApproveType(approveParam.getApproveType()); |
| | | approve.setDriverParam(approveParam.getDriverParam()); |
| | | approve.setAddrParam(approveParam.getAddrParam()); |
| | | approve.setType(Constants.ZERO); |
| | | approveList.add(approve); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public void organizeApproveCopyData(ApproveTempl approveTempl,List<ApproveParam> approveCopyList,Integer businessId,List<Approve> approveList){ |
| | | for (ApproveParam approveParam:approveCopyList) { |
| | | if(StringUtils.isBlank(approveParam.getObjIds())){ |
| | | return; |
| | | } |
| | | List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getIsdeleted,Constants.ZERO) |
| | | .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)){ |
| | | userIds.addAll(memberList.stream().map(m->m.getId()).collect(Collectors.toList())); |
| | | } |
| | | //公务用车 默认加入 司机抄送 |
| | | if(approveTempl.getType()==Constants.THREE||approveTempl.getType()==Constants.FOUR){ |
| | | CarUseBook carUseBook = carUseBookMapper.selectById(businessId); |
| | | if(Objects.isNull(carUseBook)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"为查询到用车申请信息"); |
| | | } |
| | | CarDriver carDriver = carDriverMapper.selectById(carUseBook.getDriverId()); |
| | | if(Objects.isNull(carDriver)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"为查询到司机信息"); |
| | | } |
| | | userIds.add(carDriver.getMemberId()); |
| | | } |
| | | |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(userIds)){ |
| | | for (Integer memberId:userIds) { |
| | | Approve approve = new Approve(); |
| | | approve.setCreateDate(new Date()); |
| | | approve.setIsdeleted(Constants.ZERO); |
| | | approve.setTemplatId(approveTempl.getId()); |
| | | approve.setChekorId(memberId); |
| | | approve.setObjId(businessId); |
| | | approve.setType(Constants.ONE); |
| | | approveList.add(approve); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public List<Integer> getApproveUserIds(ApproveParam approveParam,Member createMember){ |
| | | List<Integer> userIds = new ArrayList<>(); |
| | | if(approveParam.getMemberType().equals(Constants.ZERO)){ |
| | | //申请人 |
| | | userIds.add(createMember.getId()); |
| | | }else if(approveParam.getMemberType().equals(Constants.ONE)){ |
| | | //指定人员 |
| | | if(StringUtils.isBlank(approveParam.getObjIds())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"审批流配置错误[未配置指定审批人员]"); |
| | | } |
| | | List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getIsdeleted,Constants.ZERO) |
| | | .in(Member::getId,approveParam.getObjIds().split(","))); |
| | | if(memberList.size()!=approveParam.getObjIds().split(",").length){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流配置错误[指定审批人员信息异常]"); |
| | | } |
| | | userIds.addAll(memberList.stream().map(m->m.getId()).collect(Collectors.toList())); |
| | | }else if(approveParam.getMemberType().equals(Constants.TWO)){ |
| | | //部门主管审批 |
| | | //审批部门 |
| | | Company memberCompany = companyMapper.selectById(createMember.getCompanyId()); |
| | | if(Objects.isNull(memberCompany)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流配置错误[指定审批部门未查询到]"); |
| | | } |
| | | Company auditCompany = this.getAuditCompanyHead(memberCompany.getParentId(),approveParam.getObjLevel()); |
| | | if(Objects.isNull(auditCompany)){ |
| | | //审批部门为空 自动流转下一级审批配置 |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流配置错误[指定审批部门未查询到]"); |
| | | }else{ |
| | | //查询部门负责人 |
| | | Member headMember = memberMapper.selectById(auditCompany.getHeadId()); |
| | | if(Objects.isNull(headMember)){ |
| | | //未查询到部门负责人 根据配置处理 由上级主管代替审核/直接结束流程 |
| | | if(approveParam.getNoleaderOpt().equals(Constants.ONE)&&!Objects.isNull(auditCompany.getParentId())){ |
| | | auditCompany = companyMapper.selectOne(new QueryWrapper<Company>().lambda().eq(Company::getId,auditCompany.getParentId())); |
| | | //无父级 直接流传下一级审批 |
| | | if(Objects.isNull(auditCompany)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流配置错误[指定审批部门未查询到]"); |
| | | } |
| | | headMember = memberMapper.selectById(auditCompany.getHeadId()); |
| | | if(Objects.isNull(headMember)){ |
| | | //查询部门负责人 为空 自动流转下一级审批配置 |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批流配置错误[指定审批部门未设置负责人]"); |
| | | }else{ |
| | | //添加审批人 |
| | | userIds.add(headMember.getId()); |
| | | } |
| | | }else{ |
| | | //添加审批人 |
| | | userIds.add(headMember.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return userIds; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据配置查询上级数据 |
| | | * @param companyId 父级部门主键 |
| | | * @param objLevel 查询级别 |
| | | */ |
| | | public Company getAuditCompanyHead(Integer companyId, Integer objLevel){ |
| | | Integer queryLevel = Constants.ZERO; |
| | | Company auditCompany = companyMapper.selectById(companyId); |
| | | while(queryLevel.equals(objLevel)){ |
| | | auditCompany = companyMapper.selectById(auditCompany.getParentId()); |
| | | if(Objects.isNull(auditCompany)){ |
| | | return null; |
| | | } |
| | | queryLevel = queryLevel + 1; |
| | | } |
| | | return auditCompany; |
| | | } |
| | | |
| | | |
| | | } |