|
|
|
@ -1,19 +1,25 @@
|
|
|
|
|
package com.supervision.knowsub.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.supervision.knowsub.enums.FlowTypeEnum;
|
|
|
|
|
import com.supervision.knowsub.exception.BusinessException;
|
|
|
|
|
import com.supervision.knowsub.mapper.KnowledgeFlowRecordMapper;
|
|
|
|
|
import com.supervision.knowsub.model.KnowledgeFlowRecord;
|
|
|
|
|
import com.supervision.knowsub.service.KnowledgeFlowRecordService;
|
|
|
|
|
import com.supervision.knowsub.service.KnowledgeFlowService;
|
|
|
|
|
import com.supervision.knowsub.model.*;
|
|
|
|
|
import com.supervision.knowsub.service.*;
|
|
|
|
|
import com.supervision.knowsub.vo.knowledge.KnowledgeFlowResVO;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
@ -22,6 +28,12 @@ public class KnowledgeFlowServiceImpl implements KnowledgeFlowService {
|
|
|
|
|
|
|
|
|
|
private final KnowledgeFlowRecordService knowledgeFlowRecordService;
|
|
|
|
|
|
|
|
|
|
private final SystemFlowTypeRelationService systemFlowTypeRelationService;
|
|
|
|
|
|
|
|
|
|
private final SystemFlowRuleService systemFlowRuleService;
|
|
|
|
|
|
|
|
|
|
private final SystemFlowRuleUserService systemFlowRuleUserService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public IPage<KnowledgeFlowResVO> queryKnowledgeFlowPage(Integer processStatus, String title, String publishDeptId, String baseId,
|
|
|
|
|
String submittedDeptId, Instant flowType,
|
|
|
|
@ -39,4 +51,68 @@ public class KnowledgeFlowServiceImpl implements KnowledgeFlowService {
|
|
|
|
|
}
|
|
|
|
|
throw new BusinessException("不支持的状态类型");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提交审批流程
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void submitFlowProcess(Knowledge knowledge, FlowTypeEnum flowTypeEnum, String userId, String deptId, String remark) {
|
|
|
|
|
// 首先查询到知识对应的子库
|
|
|
|
|
String baseId = knowledge.getBaseId();
|
|
|
|
|
if (StrUtil.isBlank(baseId)) {
|
|
|
|
|
throw new BusinessException("未找到对应的子库");
|
|
|
|
|
}
|
|
|
|
|
// 首先找到对应的审批流
|
|
|
|
|
Optional<SystemFlowTypeRelation> systemFlowTypeRelationOpt = systemFlowTypeRelationService.lambdaQuery()
|
|
|
|
|
.eq(SystemFlowTypeRelation::getBaseId, baseId)
|
|
|
|
|
.eq(SystemFlowTypeRelation::getFlowType, flowTypeEnum.getFlowType())
|
|
|
|
|
.last(" limit 1").oneOpt();
|
|
|
|
|
SystemFlowTypeRelation systemFlowTypeRelation = systemFlowTypeRelationOpt.orElseThrow(() -> new BusinessException("未找到审批流程,请联系管理员配置审批流程"));
|
|
|
|
|
List<SystemFlowRule> ruleList = systemFlowRuleService.lambdaQuery().eq(SystemFlowRule::getFlowId, systemFlowTypeRelation.getFlowId()).list();
|
|
|
|
|
if (CollUtil.isEmpty(ruleList)) {
|
|
|
|
|
throw new BusinessException("审批流节点为空,请联系管理员配置审批流节点");
|
|
|
|
|
}
|
|
|
|
|
// 根据rule_order进行升序排序
|
|
|
|
|
List<SystemFlowRule> orderList = ruleList.stream().sorted(Comparator.comparingInt(SystemFlowRule::getRuleOrder)).toList();
|
|
|
|
|
// 应该最少有两个节点,一个是起始节点,一个是审批节点才行
|
|
|
|
|
if (orderList.size() < 2) {
|
|
|
|
|
throw new BusinessException("审批流节点数量不足,请联系管理员确认审批流节点是否正确");
|
|
|
|
|
}
|
|
|
|
|
// 首先获取第一个节点,校验当前用户是否有权限提交
|
|
|
|
|
SystemFlowRule firstRule = orderList.get(0);
|
|
|
|
|
Optional<SystemFlowRuleUser> systemFlowRuleUserOpt = systemFlowRuleUserService.lambdaQuery().eq(SystemFlowRuleUser::getFlowId, firstRule.getId())
|
|
|
|
|
.eq(SystemFlowRuleUser::getUserId, userId).eq(SystemFlowRuleUser::getRuleId, firstRule.getId()).oneOpt();
|
|
|
|
|
if (systemFlowRuleUserOpt.isEmpty()) {
|
|
|
|
|
throw new BusinessException("当前用户没有权限提交:" + flowTypeEnum.getDesc() + " 流程,请联系管理员确认");
|
|
|
|
|
}
|
|
|
|
|
// 然后找到下一个节点
|
|
|
|
|
SystemFlowRule nextRule = orderList.get(1);
|
|
|
|
|
List<SystemFlowRuleUser> nextRuleUserList = systemFlowRuleUserService.lambdaQuery().eq(SystemFlowRuleUser::getFlowId, nextRule.getId()).eq(SystemFlowRuleUser::getRuleId, nextRule.getId()).list();
|
|
|
|
|
if (CollUtil.isEmpty(nextRuleUserList)) {
|
|
|
|
|
throw new BusinessException("审批节点未配置审批用户,流程提交失败");
|
|
|
|
|
}
|
|
|
|
|
// 创建审批记录的对象
|
|
|
|
|
KnowledgeFlowRecord knowledgeFlowRecord = KnowledgeFlowRecord.builder()
|
|
|
|
|
.type(1)
|
|
|
|
|
.knowledgeId(knowledge.getId())
|
|
|
|
|
.flowId(systemFlowTypeRelation.getFlowId())
|
|
|
|
|
.flowType(flowTypeEnum.getFlowType())
|
|
|
|
|
.flowRuleId(firstRule.getId())
|
|
|
|
|
.processName(firstRule.getRuleName())
|
|
|
|
|
.remark(remark)
|
|
|
|
|
.submitUserId(userId)
|
|
|
|
|
.submitDeptId(deptId)
|
|
|
|
|
.build();
|
|
|
|
|
knowledgeFlowRecordService.save(knowledgeFlowRecord);
|
|
|
|
|
// 生成下一个节点的TODO
|
|
|
|
|
for (SystemFlowRuleUser todoUser : nextRuleUserList) {
|
|
|
|
|
KnowledgeFlowTodo todo = new KnowledgeFlowTodo();
|
|
|
|
|
todo.setFlowId(nextRule.getFlowId());
|
|
|
|
|
todo.setFlowType(flowTypeEnum.getFlowType());
|
|
|
|
|
todo.setKnowledgeId(knowledge.getId());
|
|
|
|
|
todo.setRuleId(nextRule.getId());
|
|
|
|
|
todo.setTodoUserId(todoUser.getUserId());
|
|
|
|
|
todo.insert();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|