package com.gkhy.safePlatform.specialWork.service.impl;
|
|
import cn.hutool.core.util.IdUtil;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountUserService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserInfoRPCRespDTO;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.enums.ResultCodes;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.exception.BusinessException;
|
import com.gkhy.safePlatform.commons.query.PageQuery;
|
import com.gkhy.safePlatform.commons.utils.RequestContextHolder;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRule;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleStep;
|
import com.gkhy.safePlatform.specialWork.entity.ApprovalRuleUnit;
|
import com.gkhy.safePlatform.specialWork.enums.ApprovalStepPersonTypeEnum;
|
import com.gkhy.safePlatform.specialWork.enums.RuleContinueTimeUnitEnum;
|
import com.gkhy.safePlatform.specialWork.enums.WorkTypeEnum;
|
import com.gkhy.safePlatform.specialWork.model.bo.ApprovalRuleBO;
|
import com.gkhy.safePlatform.specialWork.model.dto.req.*;
|
import com.gkhy.safePlatform.specialWork.entity.*;
|
import com.gkhy.safePlatform.specialWork.enums.*;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleStepRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleUnitItemRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.dto.resp.ApprovalRuleUnitRespDTO;
|
import com.gkhy.safePlatform.specialWork.model.query.db.*;
|
import com.gkhy.safePlatform.specialWork.service.RuleService;
|
import com.gkhy.safePlatform.specialWork.service.baseService.*;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.redisson.api.RLock;
|
import org.redisson.api.RedissonClient;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.security.Guard;
|
import java.time.LocalDateTime;
|
import java.util.*;
|
import java.util.concurrent.TimeUnit;
|
import java.util.stream.Collectors;
|
|
@Service("ruleService")
|
public class RuleServiceImpl implements RuleService {
|
@DubboReference
|
private AccountDepartmentService accountDepartmentService;
|
|
@DubboReference
|
private AccountUserService accountUserService;
|
@Autowired
|
private ApprovalRuleService approvalRuleService;
|
|
@Autowired
|
private ApprovalRuleStepService approvalRuleStepService;
|
|
@Autowired
|
private ApprovalRuleUnitItemService approvalRuleUnitItemService;
|
|
@Autowired
|
private ApprovalRuleUnitService approvalRuleUnitService;
|
|
@Autowired
|
private ApprovalRuleStandService approvalRuleStandService;
|
|
@Autowired
|
private ApprovalRuleItemMeasureService approvalRuleItemMeasureService;
|
|
@Autowired
|
private RedissonClient redissonClient;
|
|
|
@Override
|
@Transactional
|
public ResultVO save(ApprovalRuleAddReqDTO ruleReqDTO) {
|
|
//加分布式锁,防止重复创建规则
|
RLock lock = redissonClient.getLock("LOCK_RULE_INSERT");
|
try {
|
lock.lock(10, TimeUnit.SECONDS);
|
// 部门验证
|
DepInfoRPCRespDTO depInfoByDepId = getDepInfoByDepId(ruleReqDTO.getDepId());
|
// 作业类型验证
|
WorkTypeEnum workType = WorkTypeEnum.parse(ruleReqDTO.getWorkType());
|
if(workType == null){
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"作业类型不合法");
|
}
|
// 作业等级验证
|
// 是否是特殊作业
|
boolean specialWork = this.isSpecialWork(workType);
|
WorkLevelEnum workLevel = WorkLevelEnum.parse(ruleReqDTO.getWorkLevel());
|
if (specialWork) {
|
// 检查等级 不能是无等级
|
if (workLevel == null || workLevel == WorkLevelEnum.DEFAULT) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"特殊作业需要作业等级");
|
}
|
}else{
|
// 不是特殊作业默认无等级
|
workLevel = WorkLevelEnum.DEFAULT;
|
}
|
|
// 同一个部门下审批规则有且仅有一个
|
// 验证该部门下是否创建审批流程
|
ApprovalRuleListDbQuery query = new ApprovalRuleListDbQuery();
|
query.setDepId(ruleReqDTO.getDepId());
|
query.setWorkType(ruleReqDTO.getWorkType());
|
query.setWorkLevel(workLevel.getLevel());
|
// todo 改成count
|
List<ApprovalRule> ruleList = approvalRuleService.listRule(query);
|
if (ruleList.size() > 0) {
|
throw new AusinessException(E.DATA_DATABASE_EXIST, "该部门下该项已存在,不可重复");
|
}
|
|
|
// 层级
|
List<ApprovalRuleStepAddReqDTO> stepReqDTOList = ruleReqDTO.getStepList();
|
|
if (stepReqDTOList == null || stepReqDTOList.size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "至少存在一个审批层级");
|
}
|
|
List<UserInfoRPCRespDTO> userList;
|
List<ApprovalRuleItemMeasureDO> measureList;
|
List<ApprovalRuleItemStandDO> standList;
|
|
// 循环出数据用于后面验证
|
|
List<Long> uIdList = new ArrayList<>();
|
|
Set<Long> mIdList = new HashSet<>();
|
|
Set<Long> sIdList = new HashSet<>();
|
stepReqDTOList.forEach(step -> {
|
//单元
|
List<ApprovalRuleUnitAddReqDTO> units = step.getUnitList();
|
if (null != units && units.size() > 0) {
|
units.forEach(unit -> {
|
uIdList.add(unit.getBindUid());
|
});
|
}
|
|
//审批项
|
List<ApprovalRuleUnitItemAddReqDTO> items = step.getItemList();
|
if (null != items && items.size() > 0) {
|
items.forEach(item -> {
|
if (null != item.getMeasureId()) {
|
mIdList.add(item.getMeasureId());
|
}
|
if (null != item.getStandId()) {
|
sIdList.add(item.getStandId());
|
}
|
});
|
}
|
|
|
});
|
// 用于后面验证
|
measureList = new ArrayList<>(mIdList.size());
|
standList = new ArrayList<>(sIdList.size());
|
userList = listAccountUsers(uIdList);
|
if (mIdList.size() > 0) {
|
measureList = approvalRuleItemMeasureService.listItemMeasureByIds(mIdList);
|
}
|
if (sIdList.size() > 0) {
|
standList = approvalRuleStandService.listItemStandByIds(sIdList);
|
}
|
|
// 0.层级排序
|
// 1.八大作业都有监护人层级
|
// 2.动火作业 和 受限弓箭 需要分析人层级
|
checkRuleStepValid(workType, stepReqDTOList, userList, standList, measureList);
|
|
ContextCacheUser currentUser = RequestContextHolder.contextUserLocal.get();
|
// exc
|
// rule
|
ApprovalRule rule = new ApprovalRule();
|
rule.setRuleId(IdUtil.getSnowflake(0,0).nextId());
|
rule.setDepId(ruleReqDTO.getDepId());
|
rule.setRuleName(ruleReqDTO.getRuleName());
|
rule.setWorkType(ruleReqDTO.getWorkType());
|
rule.setWorkLevel(workLevel.getLevel());
|
rule.setCreateUid(currentUser.getUid());
|
rule.setCreateUname(currentUser.getUsername());
|
// 上一层 id
|
Long preStepId = null;
|
// 层级List
|
List<ApprovalRuleStep> saveStepList = new ArrayList<>(stepReqDTOList.size());
|
// 单元List
|
List<ApprovalRuleUnit> saveUnitList = new ArrayList<>();
|
// 审批项List
|
List<ApprovalRuleUnitItem> saveUnitItemList = new ArrayList<>();
|
for (ApprovalRuleStepAddReqDTO stepReqDTO : stepReqDTOList) {
|
// 填充层级
|
ApprovalRuleStep step = new ApprovalRuleStep();
|
// 填充规则id
|
step.setStepId(IdUtil.getSnowflake(0, 0).nextId());
|
step.setRuleId(rule.getRuleId());
|
step.setStepName(stepReqDTO.getStepName());
|
step.setStepSerial(stepReqDTO.getStepSerial());
|
step.setApprovalType(stepReqDTO.getApprovalType());
|
step.setPersonType(stepReqDTO.getPersonType());
|
step.setContentType(stepReqDTO.getContentType());
|
step.setGmtCreate(LocalDateTime.now());
|
step.setStatus(RuleStepStatusEnum.VALID.getCode());
|
step.setCreateUname(currentUser.getUsername());
|
step.setCreateUid(currentUser.getUid());
|
step.setAuditType(stepReqDTO.getAuditType());
|
step.setPreStepId(preStepId);
|
if (stepReqDTO.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_ANALYST.getType())) {
|
// 分析人 标准
|
step.setContinueTime(stepReqDTO.getContinueTime());
|
step.setContinueTimeUnit(stepReqDTO.getContinueTimeUnit());
|
}
|
saveStepList.add(step);
|
preStepId = step.getStepId();
|
|
//单元
|
List<ApprovalRuleUnitAddReqDTO> unitReqDTOList = stepReqDTO.getUnitList();
|
//遍历审批单元
|
for (ApprovalRuleUnitAddReqDTO unitReqDTO : unitReqDTOList) {
|
// 筛选用户
|
List<UserInfoRPCRespDTO> uList = userList.stream()
|
.filter(user -> user.getUid().equals(unitReqDTO.getBindUid()))
|
.collect(Collectors.toList());
|
//填充单元数据
|
ApprovalRuleUnit unit = new ApprovalRuleUnit();
|
unit.setUnitId(IdUtil.getSnowflake(0, 0).nextId());
|
unit.setRuleId(rule.getRuleId());
|
unit.setStepId(step.getStepId());
|
unit.setBindDepId(ruleReqDTO.getDepId());
|
unit.setBindDepName(depInfoByDepId.getDepName());
|
unit.setBindUid(unitReqDTO.getBindUid());
|
unit.setBindUname(uList.get(0).getUsername());
|
unit.setGmtCreate(LocalDateTime.now());
|
unit.setStatus(RuleUnitStatusEnum.VALID.getCode());
|
unit.setCreateUid(currentUser.getUid());
|
unit.setCreateUname(currentUser.getUsername());
|
saveUnitList.add(unit);
|
}
|
|
|
// 审批项
|
List<ApprovalRuleUnitItemAddReqDTO> itemReqDTOList = stepReqDTO.getItemList();
|
//遍历审批项
|
if (itemReqDTOList != null && itemReqDTOList.size() > 0) {
|
for (ApprovalRuleUnitItemAddReqDTO item : itemReqDTOList) {
|
// 填充审批项数据
|
ApprovalRuleUnitItem itemVo = new ApprovalRuleUnitItem();
|
itemVo.setId(IdUtil.getSnowflake(0, 0).nextId());
|
itemVo.setItemName(item.getItemName());
|
itemVo.setRuleId(rule.getRuleId());
|
itemVo.setStepId(step.getStepId());
|
itemVo.setType(item.getType());
|
itemVo.setStatus(RuleItemStatusEnum.VALID.getCode());
|
itemVo.setGmtCreate(LocalDateTime.now());
|
itemVo.setCreateUid(currentUser.getUid());
|
itemVo.setCreateUname(currentUser.getUsername());
|
// 是否分析人审批
|
if (stepReqDTO.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_ANALYST.getType())) {
|
// 分析人 标准
|
itemVo.setStandId(item.getStandId());
|
} else {
|
// 安全措施
|
itemVo.setMeasureId(item.getMeasureId());
|
}
|
saveUnitItemList.add(itemVo);
|
}
|
}
|
}
|
// 插入规则
|
approvalRuleService.saveOneRule(rule);
|
// 批量插入层级
|
if (saveStepList.size() > 0) {
|
approvalRuleStepService.saveStepList(saveStepList);
|
}
|
// 批量插入单元
|
if (saveUnitList.size() > 0) {
|
approvalRuleUnitService.saveUnitList(saveUnitList);
|
}
|
// 批量插入审批项
|
if (saveUnitItemList.size() > 0) {
|
approvalRuleUnitItemService.batchSaveItemList(saveUnitItemList);
|
}
|
|
//创建成功,释放锁
|
lock.unlock();
|
|
}catch (AusinessException e) {
|
e.printStackTrace();
|
throw new AusinessException(e.getCode(), e.getMessage());
|
}catch (BusinessException e) {
|
e.printStackTrace();
|
throw new BusinessException(e.getCode(), e.getMessage());
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new BusinessException(ResultCodes.SERVER_ERROR);
|
}finally {
|
if(lock.isLocked()){
|
lock.unlock();
|
}
|
}
|
|
return new ResultVO(ResultCodes.OK);
|
}
|
|
private boolean isSpecialWork(WorkTypeEnum workType) {
|
boolean result = false;
|
// 动火
|
if (workType == WorkTypeEnum.WORK_FIRE ||
|
// 高处
|
workType == WorkTypeEnum.WORK_HIGH_SPACE ||
|
// 吊装
|
workType == WorkTypeEnum.WORK_HANG ||
|
// 盲板
|
workType == WorkTypeEnum.WORK_BLIND_PLATE) {
|
result = true;
|
}
|
return result;
|
}
|
|
|
|
// 1.八大作业都有监护人层级 监护人有且仅有一个
|
// 2.动火作业 和 受限弓箭 需要分析人层级 其他不需要分析人层级 分析人有且仅有一个
|
private void checkRuleStepValid(WorkTypeEnum workType,
|
List<ApprovalRuleStepAddReqDTO> stepReqDTOList,
|
List<UserInfoRPCRespDTO> userList,
|
List<ApprovalRuleItemStandDO> standList,
|
List<ApprovalRuleItemMeasureDO> measureList) {
|
// 检查序号是否存在重复和重新排序
|
List<Integer> collect = stepReqDTOList.stream()
|
// 序号
|
.map(ApprovalRuleStepAddReqDTO::getStepSerial)
|
// 去重
|
.distinct()
|
// 集合
|
.collect(Collectors.toList());
|
|
if (stepReqDTOList.size() > collect.size()) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "排序号不可重复!");
|
}
|
// 按照升序排序
|
Collections.sort(stepReqDTOList, new Comparator<ApprovalRuleStepAddReqDTO>() {
|
@Override
|
public int compare(ApprovalRuleStepAddReqDTO o1, ApprovalRuleStepAddReqDTO o2) {
|
//升序
|
return o1.getStepSerial().compareTo(o2.getStepSerial());
|
}
|
});
|
// 监护人层级个数
|
int guardianStepCount = 0;
|
// 分析人层级个数
|
int analystStepCount = 0;
|
for (ApprovalRuleStepAddReqDTO step : stepReqDTOList) {
|
// 层级类型
|
if (step.getPersonType() == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"层级人员类型为空");
|
}
|
if (ApprovalStepPersonTypeEnum.parse(step.getPersonType()) == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"层级人员类型不合法");
|
}
|
// 审批单位
|
if (step.getUnitList() == null || step.getUnitList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"层级人员为空");
|
}
|
// 审批内容类型
|
if (step.getContentType() == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"审批内容类型为空");
|
}
|
ApprovalStepContentTypeEnum stepContentType = ApprovalStepContentTypeEnum.parse(step.getContentType());
|
if (stepContentType == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"审批内容类型不合法");
|
}
|
// 审批类型 多人 还是单人
|
ApprovalStepApprovalTypeEnum approvalType = ApprovalStepApprovalTypeEnum.parse(step.getApprovalType());
|
if (approvalType == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"审批人数类型不合法");
|
}
|
AuditTypeEnum auditTypeEnum = AuditTypeEnum.parse(step.getAuditType());
|
if (auditTypeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"并行审批类型不合法");
|
}
|
|
// 审批层级单元
|
List<ApprovalRuleUnitAddReqDTO> unitList = step.getUnitList();
|
if (unitList == null || unitList.size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, step.getStepName() + "未选择审批人!");
|
}
|
/// 审批类型(单人审批 | 多人审批) 匹配 选择人数
|
this.checkPersonTypeMatchCounts(approvalType, unitList);
|
// 分析人层级
|
if (step.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_ANALYST.getType())) {
|
// 分析人层级 ++
|
analystStepCount++;
|
// 有效时间 有效时间单位
|
if (null == step.getContinueTime() || null == step.getContinueTimeUnit()) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "分析审批人层级,有效时间或者有效时间单位不可为空!");
|
}
|
// 有效时间单位
|
if (RuleContinueTimeUnitEnum.parse(step.getContinueTimeUnit()) == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "有效时间单位不合法!");
|
}
|
if (approvalType == ApprovalStepApprovalTypeEnum.TYPE_MULTIPLE_PEOPLE && auditTypeEnum == AuditTypeEnum.CONCURRENT_JOINT_TRIAL) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "分析人选择多人只能并行单审");
|
}
|
|
// 审批内容类型为审批项审批
|
if (stepContentType != ApprovalStepContentTypeEnum.APP_ITEM) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "分析层级必须为审批项审批");
|
}
|
// 审批(分析)项不可为空
|
if (null == step.getItemList() || step.getItemList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "分析审批人层级,请添加分析项!");
|
}
|
// 校验审批项的标准
|
for (ApprovalRuleUnitItemAddReqDTO item : step.getItemList()) {
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(item.getType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项类型不合法");
|
}
|
if (!item.getType().equals(RuleItemTypeEnum.NUMERIC.getCode())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项只适用数值类型标准");
|
}
|
assert item.getStandId() != null;
|
long count = standList.stream().filter(stand -> stand.getId().equals(item.getStandId())).count();
|
if (count < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, step.getStepName() + ",审批项标准不存在!");
|
}
|
}
|
|
|
|
}
|
// 监护人层级
|
if (step.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_GUARDIAN.getType())) {
|
// 监护人层级 ++
|
guardianStepCount++;
|
// 1.审批项审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_ITEM) {
|
// 审批(分析)项不可为空
|
if (null == step.getItemList() || step.getItemList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "审批项目审批,审批项不可为空!");
|
}
|
for (ApprovalRuleUnitItemAddReqDTO item : step.getItemList()) {
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(item.getType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项类型不合法");
|
}
|
// 审批项 => 填空 | 选择
|
if (typeEnum != RuleItemTypeEnum.FILL && typeEnum != RuleItemTypeEnum.OPTION) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "监护层审批项类型不合法");
|
}
|
if (item.getMeasureId() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL,"安全措施id为空");
|
}
|
List<ApprovalRuleItemMeasureDO> measures = measureList.stream()
|
.filter(measure -> measure.getId().equals(item.getMeasureId()))
|
.collect(Collectors.toList());
|
if (measures.size() < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, step.getStepName() + ",审批项安全措施不存在!");
|
}
|
if (typeEnum == RuleItemTypeEnum.FILL && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_INPUT.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择填空类型安全措施");
|
}
|
if (typeEnum == RuleItemTypeEnum.OPTION && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_CHOSE.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择选择类型安全措施");
|
}
|
}
|
}
|
// 2.简单审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_SIMPLE) {
|
|
}
|
}
|
|
// 普通人审批
|
if (step.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_NORMAL.getType())) {
|
|
// 审批人数类型
|
// 单人审批 <=> 1人 单审
|
if (approvalType == ApprovalStepApprovalTypeEnum.TYPE_SINGLE_PERSON) {
|
if (step.getUnitList().size() != 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, step.getStepName() + "层单人审批只能选择一个审批人");
|
}
|
if (auditTypeEnum != AuditTypeEnum.CONCURRENT_SINGLE_TRIAL) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, step.getStepName() + "层单人审批只能选择并行单审");
|
}
|
}
|
// 多人审批
|
if (approvalType == ApprovalStepApprovalTypeEnum.TYPE_MULTIPLE_PEOPLE) {
|
if (step.getUnitList().size() < 2) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, step.getStepName() + "层多人审批需选择多个审批人");
|
}
|
}
|
|
// 1.审批项审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_ITEM) {
|
// 审批(分析)项不可为空
|
if (null == step.getItemList() || step.getItemList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "审批项目审批,审批项不可为空!");
|
}
|
for (ApprovalRuleUnitItemAddReqDTO item : step.getItemList()) {
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(item.getType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项类型不合法");
|
}
|
// 审批项 => 填空 | 选择
|
if (typeEnum != RuleItemTypeEnum.FILL && typeEnum != RuleItemTypeEnum.OPTION) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "监护层审批项类型不合法");
|
}
|
if (item.getMeasureId() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL,"安全措施id为空");
|
}
|
List<ApprovalRuleItemMeasureDO> measures = measureList.stream()
|
.filter(measure -> measure.getId().equals(item.getMeasureId()))
|
.collect(Collectors.toList());
|
|
if (measures.size() < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, step.getStepName() + ",审批项安全措施不存在!");
|
}
|
|
if (typeEnum == RuleItemTypeEnum.FILL && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_INPUT.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择填空类型安全措施");
|
}
|
if (typeEnum == RuleItemTypeEnum.OPTION && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_CHOSE.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择选择类型安全措施");
|
}
|
}
|
}
|
// 2.简单审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_SIMPLE) {
|
|
}
|
}
|
|
|
|
|
// 统一做 人员id 是否存在
|
for (ApprovalRuleUnitAddReqDTO unit : unitList) {
|
long count = userList.stream().filter(user -> user.getUid().equals(unit.getBindUid())).count();
|
if (count < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "审批人员不存在!");
|
}
|
}
|
|
|
}
|
// 动火 || 受限
|
if (workType == WorkTypeEnum.WORK_FIRE || workType == WorkTypeEnum.WORK_CLOSE_SPACE) {
|
if (analystStepCount == 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "缺少分析人层级");
|
}
|
if (analystStepCount > 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "分析人层级有且仅有一层");
|
}
|
}else{
|
// !动火 && !受限
|
if (analystStepCount > 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "非动火和受限空间作业,不需要分析人层级");
|
}
|
}
|
|
if (guardianStepCount == 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "缺少监护人层级");
|
}
|
if (guardianStepCount > 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "监护人层级有且仅有一层");
|
}
|
|
|
}
|
|
@Override
|
@Transactional
|
public ResultVO update(ApprovalRuleModReqDTO ruleReqDTO) {
|
|
//主键
|
if(null == ruleReqDTO.getRuleId()){
|
throw new BusinessException(ResultCodes.CLIENT_PARAM_NULL);
|
}
|
ApprovalRule approvalRule = approvalRuleService.getById(ruleReqDTO.getRuleId());
|
if (approvalRule == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"作业规则不存在");
|
}
|
if (!approvalRule.getDepId().equals(ruleReqDTO.getDepId())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"部门不能修改");
|
}
|
|
//部门验证
|
DepInfoRPCRespDTO depInfoByDepId = getDepInfoByDepId(ruleReqDTO.getDepId());
|
|
//根据规则id获取所有层级
|
List<ApprovalRuleStep> stepList = approvalRuleStepService.listByRuleId(ruleReqDTO.getRuleId());
|
//根据规则id获取所有单元
|
List<ApprovalRuleUnit> unitList = approvalRuleUnitService.listByRuleId(ruleReqDTO.getRuleId());
|
//根据规则id获取所有审批项
|
List<ApprovalRuleUnitItem> unitItemList = approvalRuleUnitItemService.listByRuleId(ruleReqDTO.getRuleId());
|
|
ContextCacheUser currentUser = RequestContextHolder.contextUserLocal.get();
|
|
// 是否是特殊作业
|
WorkTypeEnum workType= WorkTypeEnum.parse(ruleReqDTO.getWorkType());
|
boolean specialWork = this.isSpecialWork(workType);
|
WorkLevelEnum workLevel = WorkLevelEnum.parse(ruleReqDTO.getWorkLevel());
|
if (specialWork) {
|
// 检查等级 不能是无等级
|
if (workLevel == null || workLevel == WorkLevelEnum.DEFAULT) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"特殊作业需要作业等级");
|
}
|
}else{
|
// 不是特殊作业默认无等级
|
workLevel = WorkLevelEnum.DEFAULT;
|
}
|
|
//填充规则信息
|
ApprovalRule rule = new ApprovalRule();
|
rule.setRuleId(ruleReqDTO.getRuleId());
|
rule.setRuleName(ruleReqDTO.getRuleName());
|
rule.setModifiedUid(currentUser.getUid());
|
rule.setModifiedUname(currentUser.getUsername());
|
|
//层级List
|
List<ApprovalRuleStep> saveStepList = new ArrayList<>();
|
List<ApprovalRuleStep> updateStepList = new ArrayList<>();
|
//单元List
|
List<ApprovalRuleUnit> saveUnitList = new ArrayList<>();
|
//审批项List
|
List<ApprovalRuleUnitItem> saveUnitItemList = new ArrayList<>();
|
List<ApprovalRuleUnitItem> updateUnitItemList = new ArrayList<>();
|
|
//层级
|
List<ApprovalRuleStepModReqDTO> stepModReqDTOList = ruleReqDTO.getStepList();
|
if(stepModReqDTOList != null && stepModReqDTOList.size()>0) {
|
|
List<Long> uIdList = new ArrayList<>();
|
Set<Long> mIdList = new HashSet<>();
|
Set<Long> sIdList = new HashSet<>();
|
//循环出数据用于后面验证
|
stepModReqDTOList.forEach(step ->{
|
//单元
|
List<ApprovalRuleUnitModReqDTO> units = step.getUnitList();
|
if(null != units && units.size()>0){
|
units.forEach(unit ->{
|
uIdList.add(unit.getBindUid());
|
});
|
}
|
|
//审批项
|
List<ApprovalRuleUnitItemModReqDTO> items = step.getItemList();
|
if(null != items && items.size()>0){
|
items.forEach(item ->{
|
if (null != item.getMeasureId()){
|
mIdList.add(item.getMeasureId());
|
}
|
if (null != item.getStandId()){
|
sIdList.add(item.getStandId());
|
}
|
});
|
}
|
|
|
});
|
//用于后面验证
|
List<UserInfoRPCRespDTO> userList = new ArrayList<>();
|
List<ApprovalRuleItemMeasureDO> measureList = new ArrayList<>();
|
List<ApprovalRuleItemStandDO> standList = new ArrayList<>();
|
if(uIdList.size()>0){
|
userList = listAccountUsers(uIdList);
|
}
|
if(mIdList.size()>0){
|
measureList = approvalRuleItemMeasureService.listItemMeasureByIds(mIdList);
|
}
|
if(sIdList.size()>0){
|
standList = approvalRuleStandService.listItemStandByIds(sIdList);
|
}
|
//检查序号是否存在重复
|
List<Integer> collect = stepModReqDTOList.stream().map(ApprovalRuleStepModReqDTO::getStepSerial).distinct().collect(Collectors.toList());
|
if (stepModReqDTOList.size() > collect.size()) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "排序号不可重复!");
|
}
|
//按照升序排序
|
Collections.sort(stepModReqDTOList, new Comparator<ApprovalRuleStepModReqDTO>() {
|
@Override
|
public int compare(ApprovalRuleStepModReqDTO o1, ApprovalRuleStepModReqDTO o2) {
|
//升序
|
return o1.getStepSerial().compareTo(o2.getStepSerial());
|
}
|
});
|
|
//过滤出要删除的层级 做删除以及解绑操作
|
List<ApprovalRuleStep> deleteOldStepList = stepList.stream().parallel().filter(a ->
|
stepModReqDTOList.stream().noneMatch(b ->
|
a.getStepId().equals(b.getStepId())))
|
.collect(Collectors.toList());
|
List<Long> deleteOldStepIdList = deleteOldStepList.stream().map(step -> step.getStepId()).collect(Collectors.toList());
|
if(deleteOldStepIdList != null && deleteOldStepIdList.size()>0){
|
//删除关联的审批项
|
approvalRuleUnitItemService.updateStatusByStepIds(deleteOldStepIdList);
|
//删除关联的单元
|
approvalRuleUnitService.updateStatusByStepIds(deleteOldStepIdList);
|
//先删除原有层级
|
approvalRuleStepService.updateStatusByStepIds(deleteOldStepIdList);
|
}
|
|
Long stepId = null;
|
WorkTypeEnum workTypeEnum = WorkTypeEnum.parse(ruleReqDTO.getWorkType());
|
|
checkRuleStepValid2(workTypeEnum, ruleReqDTO.getStepList(), userList, standList, measureList);
|
|
//循环层级 更新的层级
|
for (ApprovalRuleStepModReqDTO stepReqDTO : stepModReqDTOList) {
|
//填充层级数据
|
ApprovalRuleStep step = new ApprovalRuleStep();
|
|
List<ApprovalRuleUnit> oldUnitList = new ArrayList<>();
|
List<ApprovalRuleUnitItem> oldUnitItemList = new ArrayList<>();
|
|
//填充规则id
|
step.setRuleId(rule.getRuleId());
|
step.setStepName(stepReqDTO.getStepName());
|
step.setStepSerial(stepReqDTO.getStepSerial());
|
step.setPersonType(stepReqDTO.getPersonType());
|
step.setApprovalType(stepReqDTO.getApprovalType());
|
step.setContentType(stepReqDTO.getContentType());
|
step.setAuditType(stepReqDTO.getAuditType());
|
if (stepReqDTO.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_ANALYST.getType())) {
|
// 分析人 标准
|
step.setContinueTime(stepReqDTO.getContinueTime());
|
step.setContinueTimeUnit(stepReqDTO.getContinueTimeUnit());
|
}
|
//判断是否第一个节点
|
if (null != stepId) {
|
step.setPreStepId(stepId);
|
}
|
//层级主键不为空 做更新操作
|
if(null != stepReqDTO.getStepId()){
|
step.setModifiedUid(currentUser.getUid());
|
step.setModifiedUname(currentUser.getUsername());
|
step.setStepId(stepReqDTO.getStepId());
|
updateStepList.add(step);
|
|
//过滤出层级原有的单元人员
|
oldUnitList = unitList.stream().filter(unit -> unit.getStepId().equals(stepReqDTO.getStepId())).collect(Collectors.toList());
|
//过滤出层级原有的审批项
|
oldUnitItemList = unitItemList.stream().filter(item -> item.getStepId().equals(stepReqDTO.getStepId())).collect(Collectors.toList());
|
}else{
|
step.setStepId(IdUtil.getSnowflake(0,0).nextId());
|
step.setStatus(RuleStepStatusEnum.VALID.getCode());
|
step.setGmtCreate(LocalDateTime.now());
|
step.setCreateUid(currentUser.getUid());
|
step.setCreateUname(currentUser.getUsername());
|
saveStepList.add(step);
|
|
}
|
//赋值
|
stepId = step.getStepId();
|
|
//单元
|
List<ApprovalRuleUnitModReqDTO> unitModReqDTOList = stepReqDTO.getUnitList();
|
//过滤出原来存在的单元
|
List<ApprovalRuleUnit> undeleteOldUnitList = oldUnitList.stream().parallel().filter(oldUnit -> unitModReqDTOList.stream()
|
.anyMatch(newUnit-> newUnit.getBindUid().equals(oldUnit.getBindUid()))).collect(Collectors.toList());
|
//过滤出要删除的单元 做删除操作
|
List<ApprovalRuleUnit> deleteOldUnitList = oldUnitList.stream().parallel().filter(a ->
|
unitModReqDTOList.stream().noneMatch(b ->
|
a.getBindUid().equals(b.getBindUid())))
|
.collect(Collectors.toList());
|
if(deleteOldUnitList.size()>0 && deleteOldUnitList != null){
|
List<Long> deleteOldUnitIdList = deleteOldUnitList.stream().map(unit->unit.getUnitId()).collect(Collectors.toList());
|
//删除审批单元
|
approvalRuleUnitService.updateStatusByUnitIds(deleteOldUnitIdList);
|
}
|
|
//遍历单元
|
for (ApprovalRuleUnitModReqDTO unitReqDTO : unitModReqDTOList) {
|
List<UserInfoRPCRespDTO> uList = userList.stream().filter(user -> user.getUid().equals(unitReqDTO.getBindUid())).collect(Collectors.toList());
|
if (uList.size() == 0) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "审批人员不存在!");
|
}
|
List<ApprovalRuleUnit> selectUnit = undeleteOldUnitList.stream().filter(u -> u.getBindUid().equals(unitReqDTO.getBindUid())).collect(Collectors.toList());
|
if(selectUnit.size() == 0){ //如果非原有单元,则插入
|
ApprovalRuleUnit unit = new ApprovalRuleUnit();
|
unit.setUnitId(IdUtil.getSnowflake(0,0).nextId());
|
unit.setRuleId(rule.getRuleId());
|
unit.setStepId(step.getStepId());
|
unit.setBindDepId(ruleReqDTO.getDepId());
|
unit.setBindDepName(depInfoByDepId.getDepName());
|
unit.setBindUid(unitReqDTO.getBindUid());
|
unit.setBindUname(uList.get(0).getUsername());
|
unit.setGmtCreate(LocalDateTime.now());
|
unit.setStatus(RuleUnitStatusEnum.VALID.getCode());
|
unit.setCreateUid(currentUser.getUid());
|
unit.setCreateUname(currentUser.getUsername());
|
saveUnitList.add(unit);
|
}
|
}
|
|
//审批项
|
List<ApprovalRuleUnitItemModReqDTO> itemModReqDTOList = stepReqDTO.getItemList();
|
if(itemModReqDTOList != null){
|
//过滤出要删除的审批项 做删除操作
|
List<ApprovalRuleUnitItem> deleteOldItemList = oldUnitItemList.stream().parallel().filter(a ->
|
itemModReqDTOList.stream().noneMatch(b ->
|
a.getId().equals(b.getId())))
|
.collect(Collectors.toList());
|
if(deleteOldItemList.size()>0 && deleteOldItemList != null){
|
List<Long> deleteOldUnitIdList = deleteOldItemList.stream().map(item->item.getId()).collect(Collectors.toList());
|
//删除审批项
|
approvalRuleUnitItemService.updateStatusByIds(deleteOldUnitIdList);
|
|
}
|
//遍历审批项
|
for (ApprovalRuleUnitItemModReqDTO itemReqDTO : itemModReqDTOList) {
|
|
ApprovalRuleUnitItem itemVo = new ApprovalRuleUnitItem();
|
itemVo.setItemName(itemReqDTO.getItemName());
|
itemVo.setRuleId(rule.getRuleId());
|
itemVo.setStepId(step.getStepId());
|
itemVo.setType(itemReqDTO.getType());
|
// 是否分析人审批
|
if (stepReqDTO.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_ANALYST.getType())) {
|
// 分析人 标准
|
itemVo.setStandId(itemReqDTO.getStandId());
|
} else {
|
// 安全措施
|
itemVo.setMeasureId(itemReqDTO.getMeasureId());
|
}
|
//主键为空 则新增
|
if(null == itemReqDTO.getId()){
|
itemVo.setId(IdUtil.getSnowflake(0,0).nextId());
|
itemVo.setStatus(RuleItemStatusEnum.VALID.getCode());
|
itemVo.setGmtCreate(LocalDateTime.now());
|
itemVo.setCreateUid(currentUser.getUid());
|
itemVo.setCreateUname(currentUser.getUsername());
|
saveUnitItemList.add(itemVo);
|
}else{ //修改操作
|
//填充主键
|
itemVo.setId(itemReqDTO.getId());
|
itemVo.setGmtModified(LocalDateTime.now());
|
itemVo.setModifiedUid(currentUser.getUid());
|
itemVo.setModifiedUname(currentUser.getUsername());
|
updateUnitItemList.add(itemVo);
|
}
|
}
|
}
|
}
|
}
|
//更新规则
|
approvalRuleService.updateRule(rule);
|
|
if(saveStepList.size()>0){
|
//批量插入层级
|
approvalRuleStepService.saveStepList(saveStepList);
|
}
|
if(updateStepList.size()>0){
|
//批量更新层级
|
approvalRuleStepService.updateBatchStep(updateStepList);
|
}
|
if(saveUnitList.size()>0){
|
//批量插入单元
|
approvalRuleUnitService.saveUnitList(saveUnitList);
|
}
|
if(saveUnitItemList.size()>0){
|
//批量插入审批项
|
approvalRuleUnitItemService.batchSaveItemList(saveUnitItemList);
|
}
|
if(updateUnitItemList.size()>0){
|
//批量更新审批项
|
approvalRuleUnitItemService.updateBatchItem(updateUnitItemList);
|
}
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
@Override
|
@Transactional
|
public ResultVO removeBatchRule(DeleteForm deleteForm) {
|
|
//删除规则表中数据
|
approvalRuleService.updateStutsByRuleIds(deleteForm.getIds());
|
|
//删除关联该规则的层级
|
approvalRuleStepService.updateStatusByRuleIds(deleteForm.getIds());
|
|
//删除单元
|
approvalRuleUnitService.updateStatusByRuleIds(deleteForm.getIds());
|
|
//删除审批项
|
approvalRuleUnitItemService.updateStatusByRuleIds(deleteForm.getIds());
|
|
return new ResultVO<>(ResultCodes.OK);
|
}
|
|
|
|
// 1.八大作业都有监护人层级 监护人有且仅有一个
|
// 2.动火作业 和 受限弓箭 需要分析人层级 其他不需要分析人层级 分析人有且仅有一个
|
private void checkRuleStepValid2(WorkTypeEnum workType,
|
List<ApprovalRuleStepModReqDTO> stepReqDTOList,
|
List<UserInfoRPCRespDTO> userList,
|
List<ApprovalRuleItemStandDO> standList,
|
List<ApprovalRuleItemMeasureDO> measureList) {
|
// 检查序号是否存在重复和重新排序
|
List<Integer> collect = stepReqDTOList.stream()
|
// 序号
|
.map(ApprovalRuleStepModReqDTO::getStepSerial)
|
// 去重
|
.distinct()
|
// 集合
|
.collect(Collectors.toList());
|
|
if (stepReqDTOList.size() > collect.size()) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "排序号不可重复!");
|
}
|
// 按照升序排序
|
Collections.sort(stepReqDTOList, new Comparator<ApprovalRuleStepModReqDTO>() {
|
@Override
|
public int compare(ApprovalRuleStepModReqDTO o1, ApprovalRuleStepModReqDTO o2) {
|
//升序
|
return o1.getStepSerial().compareTo(o2.getStepSerial());
|
}
|
});
|
// 监护人层级个数
|
int guardianStepCount = 0;
|
// 分析人层级个数
|
int analystStepCount = 0;
|
for (ApprovalRuleStepModReqDTO step : stepReqDTOList) {
|
// 层级类型
|
if (step.getPersonType() == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"层级人员类型为空");
|
}
|
if (ApprovalStepPersonTypeEnum.parse(step.getPersonType()) == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"层级人员类型不合法");
|
}
|
// 审批单位
|
if (step.getUnitList() == null || step.getUnitList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"层级人员为空");
|
}
|
// 审批内容类型
|
if (step.getContentType() == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"审批内容类型为空");
|
}
|
ApprovalStepContentTypeEnum stepContentType = ApprovalStepContentTypeEnum.parse(step.getContentType());
|
if (stepContentType == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"审批内容类型不合法");
|
}
|
// 审批类型 多人 还是单人
|
ApprovalStepApprovalTypeEnum approvalType = ApprovalStepApprovalTypeEnum.parse(step.getApprovalType());
|
if (approvalType == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"审批人数类型不合法");
|
}
|
AuditTypeEnum auditTypeEnum = AuditTypeEnum.parse(step.getAuditType());
|
if (auditTypeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"并行审批类型不合法");
|
}
|
|
// 审批层级单元
|
List<ApprovalRuleUnitModReqDTO> unitList = step.getUnitList();
|
if (unitList == null || unitList.size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, step.getStepName() + "未选择审批人!");
|
}
|
// 多人审批 单人审批 匹配上 人数
|
this.checkPersonTypeMatchCounts(approvalType, unitList);
|
|
|
// 分析人层级
|
if (step.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_ANALYST.getType())) {
|
// 分析人层级 ++
|
analystStepCount++;
|
// 有效时间 有效时间单位
|
if (null == step.getContinueTime() || null == step.getContinueTimeUnit()) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "分析审批人层级,有效时间或者有效时间单位不可为空!");
|
}
|
// 有效时间单位
|
if (RuleContinueTimeUnitEnum.parse(step.getContinueTimeUnit()) == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "有效时间单位不合法!");
|
}
|
|
if (approvalType == ApprovalStepApprovalTypeEnum.TYPE_MULTIPLE_PEOPLE && auditTypeEnum == AuditTypeEnum.CONCURRENT_JOINT_TRIAL) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "分析人选择多人只能并行单审");
|
}
|
|
// 审批内容类型为审批项审批
|
if (stepContentType != ApprovalStepContentTypeEnum.APP_ITEM) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "分析层级必须为审批项审批");
|
}
|
// 审批(分析)项不可为空
|
if (null == step.getItemList() || step.getItemList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "分析审批人层级,请添加分析项!");
|
}
|
// 校验审批项的标准
|
for (ApprovalRuleUnitItemModReqDTO item : step.getItemList()) {
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(item.getType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项类型不合法");
|
}
|
if (!item.getType().equals(RuleItemTypeEnum.NUMERIC.getCode())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项只适用数值类型标准");
|
}
|
assert item.getStandId() != null;
|
long count = standList.stream().filter(stand -> stand.getId().equals(item.getStandId())).count();
|
if (count < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, step.getStepName() + ",审批项标准不存在!");
|
}
|
}
|
|
|
|
}
|
// 监护人层级
|
if (step.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_GUARDIAN.getType())) {
|
// 监护人层级 ++
|
guardianStepCount++;
|
|
// 1.审批项审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_ITEM) {
|
// 审批(分析)项不可为空
|
if (null == step.getItemList() || step.getItemList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "审批项目审批,审批项不可为空!");
|
}
|
for (ApprovalRuleUnitItemModReqDTO item : step.getItemList()) {
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(item.getType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项类型不合法");
|
}
|
// 审批项 => 填空 | 选择
|
if (typeEnum != RuleItemTypeEnum.FILL && typeEnum != RuleItemTypeEnum.OPTION) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "监护层审批项类型不合法");
|
}
|
if (item.getMeasureId() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL,"安全措施id为空");
|
}
|
List<ApprovalRuleItemMeasureDO> measures = measureList.stream()
|
.filter(measure -> measure.getId().equals(item.getMeasureId()))
|
.collect(Collectors.toList());
|
if (measures.size() < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, step.getStepName() + ",审批项安全措施不存在!");
|
}
|
if (typeEnum == RuleItemTypeEnum.FILL && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_INPUT.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择填空类型安全措施");
|
}
|
if (typeEnum == RuleItemTypeEnum.OPTION && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_CHOSE.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择选择类型安全措施");
|
}
|
}
|
}
|
// 2.简单审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_SIMPLE) {
|
|
}
|
}
|
|
// 普通人审批
|
if (step.getPersonType().equals(ApprovalStepPersonTypeEnum.TYPE_NORMAL.getType())) {
|
|
// 审批人数类型
|
// 单人审批 <=> 1人 单审
|
if (approvalType == ApprovalStepApprovalTypeEnum.TYPE_SINGLE_PERSON) {
|
if (step.getUnitList().size() != 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, step.getStepName() + "层单人审批只能选择一个审批人");
|
}
|
if (auditTypeEnum != AuditTypeEnum.CONCURRENT_SINGLE_TRIAL) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, step.getStepName() + "层单人审批只能选择并行单审");
|
}
|
}
|
// 多人审批
|
if (approvalType == ApprovalStepApprovalTypeEnum.TYPE_MULTIPLE_PEOPLE) {
|
if (step.getUnitList().size() < 2) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, step.getStepName() + "层多人审批需选择多个审批人");
|
}
|
}
|
|
// 1.审批项审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_ITEM) {
|
// 审批(分析)项不可为空
|
if (null == step.getItemList() || step.getItemList().size() == 0) {
|
throw new AusinessException(E.DATA_PARAM_NULL, "审批项目审批,审批项不可为空!");
|
}
|
for (ApprovalRuleUnitItemModReqDTO item : step.getItemList()) {
|
RuleItemTypeEnum typeEnum = RuleItemTypeEnum.parse(item.getType());
|
if (typeEnum == null) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "审批项类型不合法");
|
}
|
// 审批项 => 填空 | 选择
|
if (typeEnum != RuleItemTypeEnum.FILL && typeEnum != RuleItemTypeEnum.OPTION) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "监护层审批项类型不合法");
|
}
|
if (item.getMeasureId() == null) {
|
throw new AusinessException(E.DATA_PARAM_NULL,"安全措施id为空");
|
}
|
List<ApprovalRuleItemMeasureDO> measures = measureList.stream()
|
.filter(measure -> measure.getId().equals(item.getMeasureId()))
|
.collect(Collectors.toList());
|
|
if (measures.size() < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, step.getStepName() + ",审批项安全措施不存在!");
|
}
|
|
if (typeEnum == RuleItemTypeEnum.FILL && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_INPUT.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择填空类型安全措施");
|
}
|
if (typeEnum == RuleItemTypeEnum.OPTION && !measures.get(0).getType().equals(MeasureTypeEnum.TYPE_CHOSE.getType())) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "请选择选择类型安全措施");
|
}
|
}
|
}
|
// 2.简单审批
|
if (stepContentType == ApprovalStepContentTypeEnum.APP_SIMPLE) {
|
|
}
|
}
|
|
|
|
|
// 统一做 人员id 是否存在
|
for (ApprovalRuleUnitModReqDTO unit : unitList) {
|
long count = userList.stream().filter(user -> user.getUid().equals(unit.getBindUid())).count();
|
if (count < 1) {
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT, "审批人员不存在!");
|
}
|
}
|
|
|
}
|
// 动火 || 受限
|
if (workType == WorkTypeEnum.WORK_FIRE || workType == WorkTypeEnum.WORK_CLOSE_SPACE) {
|
if (analystStepCount == 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "缺少分析人层级");
|
}
|
if (analystStepCount > 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "分析人层级有且仅有一层");
|
}
|
}else{
|
// !动火 && !受限
|
if (analystStepCount > 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "非动火和受限空间作业,不需要分析人层级");
|
}
|
}
|
|
if (guardianStepCount == 0) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "缺少监护人层级");
|
}
|
if (guardianStepCount > 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "监护人层级有且仅有一层");
|
}
|
|
|
}
|
|
|
|
@Override
|
public SearchResultVO<List<ApprovalRuleRespDTO>> listRuleByPage(PageQuery<ApprovalRuleListDbQuery> pageQuery) {
|
Page<ApprovalRule> page = new Page<>(pageQuery.getPageIndex(),pageQuery.getPageSize());
|
List<ApprovalRule> approvalRules = approvalRuleService.listRuleByPage(page,pageQuery.getSearchParams());
|
//获取层级列表
|
List<ApprovalRuleStep> stepList = approvalRuleStepService.listStepByNoConditions();
|
//获取单元列表
|
List<ApprovalRuleUnit> unitList = approvalRuleUnitService.listByNoConditions();
|
//获取审批项列表
|
List<ApprovalRuleUnitItem> itemList = approvalRuleUnitItemService.listByNoConditions();
|
//获取对应的审批标准
|
//获取安全措施列表
|
|
List<ApprovalRuleRespDTO> ruleRespList = new ArrayList<>();
|
for (ApprovalRule rule : approvalRules) {
|
//复制
|
ApprovalRuleRespDTO ruleRespDTO = new ApprovalRuleRespDTO();
|
BeanUtils.copyProperties(rule,ruleRespDTO);
|
//刷选层级
|
List<ApprovalRuleStep> selectStepList = stepList.stream().filter(step -> step.getRuleId().equals(rule.getRuleId())).collect(Collectors.toList());
|
List<ApprovalRuleStepRespDTO> stepRespList = new ArrayList<>();
|
for (ApprovalRuleStep step : selectStepList) {
|
//复制
|
ApprovalRuleStepRespDTO stepRespDTO = new ApprovalRuleStepRespDTO();
|
BeanUtils.copyProperties(step,stepRespDTO);
|
//过滤单元
|
List<ApprovalRuleUnit> selectUnitList = unitList.stream().filter(unit -> unit.getStepId().equals(step.getStepId())).collect(Collectors.toList());
|
List<ApprovalRuleUnitRespDTO> unitRespDTOList = new ArrayList<>();
|
for (ApprovalRuleUnit unit: selectUnitList) {
|
//复制
|
ApprovalRuleUnitRespDTO unitRespDTO = new ApprovalRuleUnitRespDTO();
|
BeanUtils.copyProperties(unit,unitRespDTO);
|
unitRespDTOList.add(unitRespDTO);
|
}
|
//过滤审批项
|
List<ApprovalRuleUnitItem> selectItemList = itemList.stream().filter(item -> item.getStepId().equals(step.getStepId())).collect(Collectors.toList());
|
List<ApprovalRuleUnitItemRespDTO> itemRespDTOList = new ArrayList<>();
|
for (ApprovalRuleUnitItem item: selectItemList) {
|
//复制
|
ApprovalRuleUnitItemRespDTO itemRespDTO = new ApprovalRuleUnitItemRespDTO();
|
BeanUtils.copyProperties(item,itemRespDTO);
|
itemRespDTOList.add(itemRespDTO);
|
}
|
stepRespDTO.setUnitList(unitRespDTOList);
|
stepRespDTO.setItemList(itemRespDTOList);
|
stepRespList.add(stepRespDTO);
|
}
|
ruleRespDTO.setStepList(stepRespList);
|
ruleRespList.add(ruleRespDTO);
|
}
|
|
//需要获取层级、单元、审批项、以及审批规则 等后面封装进去
|
return new SearchResultVO<>(true,
|
page.getCurrent(),
|
page.getSize(),
|
page.getPages(),
|
page.getTotal(),
|
ruleRespList,
|
ResultCodes.OK);
|
}
|
|
@Override
|
public ApprovalRuleBO recursiveQueryRule(Long depId, Byte workType, Byte workLevel) {
|
ApprovalRuleBO ruleBO = null;
|
// rpc获取部门
|
if (depId == null) {
|
return null;
|
}
|
ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(depId);
|
|
if (rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
|
if (rpcResult.getData() != null) {
|
DepInfoRPCRespDTO department = (DepInfoRPCRespDTO)rpcResult.getData();
|
ApprovalRule rule = approvalRuleService.getApprovalRuleInfo(depId, workType, workLevel);
|
if (rule == null) {
|
ruleBO = recursiveQueryRule(department.getParentDepId(), workType, workLevel);
|
}else{
|
ruleBO = new ApprovalRuleBO();
|
ruleBO.setDepId(rule.getDepId());
|
ruleBO.setDepName(department.getDepName());
|
ruleBO.setEid(rule.getEid());
|
ruleBO.setRuleId(rule.getRuleId());
|
ruleBO.setRuleName(rule.getRuleName());
|
ruleBO.setStatus(rule.getStatus());
|
ruleBO.setWorkLevel(rule.getWorkLevel());
|
ruleBO.setWorkType(rule.getWorkType());
|
}
|
}
|
}else{
|
throw new BusinessException(rpcResult.getCode(), rpcResult.getMsg());
|
}
|
|
|
return ruleBO;
|
|
}
|
//调用Rpc 获取部门
|
private DepInfoRPCRespDTO getDepInfoByDepId(Long deptId) {
|
DepInfoRPCRespDTO dep = new DepInfoRPCRespDTO();
|
ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(deptId);
|
if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
|
if (rpcResult.getData() != null) {
|
dep = (DepInfoRPCRespDTO) rpcResult.getData();
|
}else{
|
throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
|
}
|
} else {
|
throw new BusinessException(ResultCodes.RPC_ACCESS_EXCEPTION);
|
}
|
return dep;
|
}
|
|
//调用RPC 获取去人员
|
private List<UserInfoRPCRespDTO> listAccountUsers(List<Long> userIds){
|
List<UserInfoRPCRespDTO> userInfoRPCRespDTOList = new ArrayList<>();
|
ResultVO<List<UserInfoRPCRespDTO>> listResultVO = accountUserService.listUserInfoByUids(userIds);
|
if (listResultVO != null && listResultVO.getCode().equals(ResultCodes.OK.getCode())) {
|
if (listResultVO.getData() != null) {
|
userInfoRPCRespDTOList = (List<UserInfoRPCRespDTO>) listResultVO.getData();
|
}else{
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"审批人员不存在");
|
}
|
} else {
|
throw new BusinessException(ResultCodes.RPC_ACCESS_EXCEPTION);
|
}
|
return userInfoRPCRespDTOList;
|
}
|
|
|
/**
|
* @Description: 匹配 审批类型(单人审批|多人审批) 和 人员个数
|
*/
|
private void checkPersonTypeMatchCounts(ApprovalStepApprovalTypeEnum stepApprovalTypeEnum,List<?> persons) {
|
if (persons != null && stepApprovalTypeEnum != null) {
|
switch (stepApprovalTypeEnum) {
|
case TYPE_SINGLE_PERSON:
|
if (persons.size() != 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID,"单人审批情况下只能选择一人");
|
}
|
case TYPE_MULTIPLE_PEOPLE:
|
if (persons.size() < 1) {
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "多人审批情况下人数请选择多人");
|
}
|
}
|
}else{
|
throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "人员入参为空");
|
}
|
}
|
}
|