|
@@ -1,21 +1,283 @@
|
|
|
package com.fjhx.flow.service.flow.impl;
|
|
|
|
|
|
-import com.fjhx.flow.entity.flow.po.FlowExample;
|
|
|
-import com.fjhx.flow.mapper.flow.FlowExampleMapper;
|
|
|
-import com.fjhx.flow.service.flow.FlowExampleService;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.flow.entity.flow.dto.FlowExampleSelectDto;
|
|
|
+import com.fjhx.flow.entity.flow.po.*;
|
|
|
+import com.fjhx.flow.entity.flow.vo.ApprovalRecordVo;
|
|
|
+import com.fjhx.flow.entity.flow.vo.FlowExampleVo;
|
|
|
+import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
+import com.fjhx.flow.enums.HandleTypeEnum;
|
|
|
+import com.fjhx.flow.enums.NodeTypeEnum;
|
|
|
+import com.fjhx.flow.mapper.flow.FlowExampleMapper;
|
|
|
+import com.fjhx.flow.service.flow.*;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.ruoyi.common.core.text.Convert;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
+import com.ruoyi.system.utils.UserUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
* 流程实例 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
- * @author
|
|
|
+ * @author
|
|
|
* @since 2023-03-16
|
|
|
*/
|
|
|
@Service
|
|
|
public class FlowExampleServiceImpl extends ServiceImpl<FlowExampleMapper, FlowExample> implements FlowExampleService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FlowExampleDetailService flowExampleDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FlowDefinitionService flowDefinitionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FlowInfoService flowInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FlowDefinitionNodeService flowDefinitionNodeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FlowInfo> getFlowType() {
|
|
|
+ List<Long> flowInofIdList = flowDefinitionService.getDistinctList(FlowDefinition::getFlowInfoId);
|
|
|
+ return flowInfoService.listByIds(flowInofIdList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<FlowExampleVo> getToBeProcessedPage(FlowExampleSelectDto dto) {
|
|
|
+
|
|
|
+ IWrapper<FlowExample> wrapper = getWrapper()
|
|
|
+ .lt("fe", FlowExample::getStatus, 2)
|
|
|
+ .eq("fe", FlowExample::getHandleUserId, SecurityUtils.getUserId());
|
|
|
+
|
|
|
+ return doSelectExample(dto, wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<FlowExampleVo> getHaveInitiatedPage(FlowExampleSelectDto dto) {
|
|
|
+ IWrapper<FlowExample> wrapper = getWrapper().eq("fe", FlowExample::getCreateUser, SecurityUtils.getUserId());
|
|
|
+ return doSelectExample(dto, wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<FlowExampleVo> getProcessedPage(FlowExampleSelectDto dto) {
|
|
|
+
|
|
|
+ List<Long> flowExampleId = flowExampleDetailService.listObject(FlowExampleDetail::getFlowExampleId,
|
|
|
+ q -> q.eq(BasePo::getCreateUser, SecurityUtils.getUserId()));
|
|
|
+
|
|
|
+ if (flowExampleId.size() == 0) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ IWrapper<FlowExample> wrapper = getWrapper().in("fe", FlowExample::getId, flowExampleId);
|
|
|
+
|
|
|
+ return doSelectExample(dto, wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApprovalRecordVo getApprovalRecord(Long id) {
|
|
|
+
|
|
|
+ if (id == null) {
|
|
|
+ throw new ServiceException("id不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ ApprovalRecordVo result = new ApprovalRecordVo();
|
|
|
+
|
|
|
+ // 流程实例
|
|
|
+ FlowExample flowExample = getById(id);
|
|
|
+
|
|
|
+ if (flowExample == null) {
|
|
|
+ throw new ServiceException("没有找到流程");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取已完成节点
|
|
|
+ List<FlowExampleDetail> flowExampleDetailList = flowExampleDetailService.list(
|
|
|
+ q -> q.eq(FlowExampleDetail::getFlowExampleId, id));
|
|
|
+
|
|
|
+ // 获取流程全部节点
|
|
|
+ List<FlowDefinitionNode> flowDefinitionNodeList = flowDefinitionNodeService.list(
|
|
|
+ q -> q.eq(FlowDefinitionNode::getFlowDefinitionId, flowExample.getDefinitionId()));
|
|
|
+
|
|
|
+ // 审批记录list
|
|
|
+ List<ApprovalRecordVo.Record> recordList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 添加已处理记录
|
|
|
+ addProcessed(recordList, flowExampleDetailList);
|
|
|
+
|
|
|
+ // 添加进行中记录
|
|
|
+ addInProgress(recordList, flowExample);
|
|
|
+
|
|
|
+ // 赋值节点信息以及处理人名称
|
|
|
+ setNodeInfoAndHandleUserName(recordList, flowDefinitionNodeList);
|
|
|
+
|
|
|
+ // 添加未开始记录
|
|
|
+ addNotStarted(recordList, flowExample, flowDefinitionNodeList);
|
|
|
+
|
|
|
+ // 获取button列表
|
|
|
+ List<ApprovalRecordVo.ButtonInfo> buttonInfoList = getButtonInfoList(flowExample, flowDefinitionNodeList);
|
|
|
+
|
|
|
+ result.setId(id);
|
|
|
+ result.setVersion(result.getVersion());
|
|
|
+ result.setRecordList(recordList);
|
|
|
+ result.setButtonInfoList(buttonInfoList);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ApprovalRecordVo.ButtonInfo> getButtonInfoList(FlowExample flowExample,
|
|
|
+ List<FlowDefinitionNode> flowDefinitionNodeList) {
|
|
|
+
|
|
|
+ List<ApprovalRecordVo.ButtonInfo> buttonInfoList = new ArrayList<>();
|
|
|
+
|
|
|
+ Integer status = flowExample.getStatus();
|
|
|
+
|
|
|
+ if (FlowStatusEnum.PASS.getKey().equals(status)
|
|
|
+ || FlowStatusEnum.REJECT.getKey().equals(status)
|
|
|
+ || !Objects.equals(flowExample.getHandleUserId(), SecurityUtils.getUserId())) {
|
|
|
+ return buttonInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ FlowDefinitionNode flowDefinitionNode = flowDefinitionNodeList.stream()
|
|
|
+ .filter(item -> Objects.equals(item.getId(), flowExample.getDefinitionNodeId()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+
|
|
|
+ if (flowDefinitionNode == null) {
|
|
|
+ return buttonInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ String nodeButtonSet = flowDefinitionNode.getNodeButtonSet();
|
|
|
+ for (String buttonTypeStr : nodeButtonSet.split(",")) {
|
|
|
+ ApprovalRecordVo.ButtonInfo buttonInfo = new ApprovalRecordVo.ButtonInfo();
|
|
|
+ Integer buttonType = Convert.toInt(buttonTypeStr);
|
|
|
+ buttonInfo.setType(buttonType);
|
|
|
+ buttonInfo.setName(HandleTypeEnum.getEnum(buttonType).getValue());
|
|
|
+ buttonInfoList.add(buttonInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return buttonInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加未开始记录
|
|
|
+ */
|
|
|
+ private void addNotStarted(List<ApprovalRecordVo.Record> recordList, FlowExample flowExample,
|
|
|
+ List<FlowDefinitionNode> flowDefinitionNodeList) {
|
|
|
+
|
|
|
+ Integer status = flowExample.getStatus();
|
|
|
+
|
|
|
+ if (FlowStatusEnum.PASS.getKey().equals(status) || FlowStatusEnum.REJECT.getKey().equals(status)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 父节点id map
|
|
|
+ Map<Long, FlowDefinitionNode> flowDefinitionNodeMap = flowDefinitionNodeList.stream()
|
|
|
+ .collect(Collectors.toMap(FlowDefinitionNode::getParentId, Function.identity()));
|
|
|
+
|
|
|
+ FlowDefinitionNode nextNode = flowDefinitionNodeMap.get(flowExample.getDefinitionNodeId());
|
|
|
+
|
|
|
+ while (nextNode != null) {
|
|
|
+
|
|
|
+ Integer nodeType = nextNode.getNodeType();
|
|
|
+
|
|
|
+ ApprovalRecordVo.Record record = new ApprovalRecordVo.Record();
|
|
|
+ record.setStatus(3);
|
|
|
+ record.setNodeId(nextNode.getId());
|
|
|
+ record.setNodeType(nodeType);
|
|
|
+ record.setNodeName(nextNode.getNodeName());
|
|
|
+ recordList.add(record);
|
|
|
+
|
|
|
+ if (NodeTypeEnum.BRANCH.getKey().equals(nodeType) || NodeTypeEnum.END.getKey().equals(nodeType)) {
|
|
|
+ nextNode = null;
|
|
|
+ } else {
|
|
|
+ nextNode = flowDefinitionNodeMap.get(nextNode.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赋值节点信息以及处理人名称
|
|
|
+ */
|
|
|
+ private void setNodeInfoAndHandleUserName(List<ApprovalRecordVo.Record> recordList,
|
|
|
+ List<FlowDefinitionNode> flowDefinitionNodeList) {
|
|
|
+
|
|
|
+ Map<Long, FlowDefinitionNode> flowDefinitionNodeMap = flowDefinitionNodeList.stream()
|
|
|
+ .collect(Collectors.toMap(FlowDefinitionNode::getId, Function.identity()));
|
|
|
+
|
|
|
+ for (ApprovalRecordVo.Record record : recordList) {
|
|
|
+ FlowDefinitionNode flowDefinitionNode = flowDefinitionNodeMap.get(record.getNodeId());
|
|
|
+ record.setNodeName(flowDefinitionNode.getNodeName());
|
|
|
+ record.setNodeType(flowDefinitionNode.getNodeType());
|
|
|
+ }
|
|
|
+
|
|
|
+ UserUtil.assignmentNickName(
|
|
|
+ recordList,
|
|
|
+ ApprovalRecordVo.Record::getProcessedUserId,
|
|
|
+ ApprovalRecordVo.Record::setProcessedUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加进行中记录
|
|
|
+ */
|
|
|
+ private void addInProgress(List<ApprovalRecordVo.Record> recordList, FlowExample flowExample) {
|
|
|
+ Integer status = flowExample.getStatus();
|
|
|
+
|
|
|
+ if (FlowStatusEnum.PASS.getKey().equals(status) || FlowStatusEnum.REJECT.getKey().equals(status)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ApprovalRecordVo.Record record = new ApprovalRecordVo.Record();
|
|
|
+ record.setStatus(2);
|
|
|
+ record.setNodeId(flowExample.getDefinitionNodeId());
|
|
|
+ record.setProcessedUserId(flowExample.getHandleUserId());
|
|
|
+ recordList.add(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加已处理记录
|
|
|
+ */
|
|
|
+ private void addProcessed(List<ApprovalRecordVo.Record> recordList, List<FlowExampleDetail> flowExampleDetailList) {
|
|
|
+ for (FlowExampleDetail flowExampleDetail : flowExampleDetailList) {
|
|
|
+ ApprovalRecordVo.Record record = new ApprovalRecordVo.Record();
|
|
|
+ record.setStatus(1);
|
|
|
+ record.setNodeId(flowExampleDetail.getFlowDefinitionNodeId());
|
|
|
+ record.setProcessedDate(flowExampleDetail.getCreateTime());
|
|
|
+ record.setProcessedUserId(flowExampleDetail.getCreateUser());
|
|
|
+ record.setRemark(flowExampleDetail.getHandleRemark());
|
|
|
+ recordList.add(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行查询流程实例
|
|
|
+ */
|
|
|
+ private Page<FlowExampleVo> doSelectExample(FlowExampleSelectDto dto, IWrapper<FlowExample> wrapper) {
|
|
|
+
|
|
|
+ wrapper.eq("fd", FlowDefinition::getFlowInfoId, dto.getFlowInfoId())
|
|
|
+ .keyword(dto, new SqlField("fe", FlowExample::getTitle))
|
|
|
+ .orderByDesc("fe", FlowExample::getId);
|
|
|
+
|
|
|
+ Page<FlowExampleVo> page = baseMapper.selectExample(dto.getPage(), wrapper);
|
|
|
+ List<FlowExampleVo> records = page.getRecords();
|
|
|
+
|
|
|
+ // 赋值流程发起人名称
|
|
|
+ UserUtil.assignmentNickName(records, BasePo::getCreateUser, FlowExampleVo::setCreateUserName);
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
}
|