|
@@ -1,221 +0,0 @@
|
|
|
-/*
|
|
|
- * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
- *
|
|
|
- * Redistribution and use in source and binary forms, with or without
|
|
|
- * modification, are permitted provided that the following conditions are met:
|
|
|
- *
|
|
|
- * Redistributions of source code must retain the above copyright notice,
|
|
|
- * this list of conditions and the following disclaimer.
|
|
|
- * Redistributions in binary form must reproduce the above copyright
|
|
|
- * notice, this list of conditions and the following disclaimer in the
|
|
|
- * documentation and/or other materials provided with the distribution.
|
|
|
- * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
- * contributors may be used to endorse or promote products derived from
|
|
|
- * this software without specific prior written permission.
|
|
|
- * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
- */
|
|
|
-package com.fjhx.flow.service.impl;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fjhx.flow.mapper.FlowMapper;
|
|
|
-import com.fjhx.flow.service.IFlowApplycheckService;
|
|
|
-import com.fjhx.flow.service.IFlowEngineService;
|
|
|
-import com.fjhx.flow.service.IFlowNodeService;
|
|
|
-import com.fjhx.flow.service.IFlowNodelineService;
|
|
|
-import com.fjhx.myapp.application.entity.*;
|
|
|
-import org.springblade.core.log.exception.ServiceException;
|
|
|
-import org.springblade.core.secure.utils.AuthUtil;
|
|
|
-import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
-import org.springblade.core.tool.utils.StringUtil;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-/**
|
|
|
- * 业务附件表 服务实现类
|
|
|
- *
|
|
|
- * @author BladeX
|
|
|
- * @since 2022-07-20
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class FlowEngineServiceImpl extends ServiceImpl<FlowMapper, Flow> implements IFlowEngineService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IFlowNodeService iFlowNodeService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IFlowNodelineService iFlowNodelineService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IFlowApplycheckService iFlowApplycheckService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 发起流程
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @return true 发起成功
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Boolean startFlow(FlowParam param) {
|
|
|
- if (StringUtil.isEmpty(param.getFlowIdentifying())) {
|
|
|
- throw new ServiceException("流程标识不能为空");
|
|
|
- }
|
|
|
- //根据流程标识查询流程模型
|
|
|
- Flow flow = this.getOne(Wrappers.<Flow>query().lambda().eq(Flow::getFlowIdentifying, param.getFlowIdentifying()));
|
|
|
- if (ObjectUtil.isEmpty(flow)) {
|
|
|
- throw new ServiceException("模型不存在");
|
|
|
- }
|
|
|
- //查询出发起节点
|
|
|
- FlowNodeline flowNodeline = iFlowNodelineService.getOne(Wrappers.<FlowNodeline>query().lambda().
|
|
|
- eq(FlowNodeline::getFlowId, flow.getId()).eq(FlowNodeline::getFromNodeId, ""));
|
|
|
- //根据上一个节点查询出下一个节点
|
|
|
- FlowNodeline flowNodelineNext = iFlowNodelineService.getOne(Wrappers.<FlowNodeline>query().lambda().
|
|
|
- eq(FlowNodeline::getFromNodeId, flowNodeline.getToNodeId()));
|
|
|
- //根据发起节点查询下一个节点
|
|
|
- FlowNode flowNode = iFlowNodeService.getOne(Wrappers.<FlowNode>query().lambda().
|
|
|
- eq(FlowNode::getId, flowNodeline.getToNodeId()));
|
|
|
- //生成节点走向数据
|
|
|
- List<FlowApplycheck> saveBatch = new ArrayList<>();
|
|
|
- //生成发起节点走向
|
|
|
- saveBatch.add(setFlowApplyCheck(flowNodeline.getFlowId(), "", "",
|
|
|
- flowNodeline.getToNodeId(), "", 0, new Date(), "",
|
|
|
- param.getBusinessId(), ""));
|
|
|
- //生成审批节点走向
|
|
|
- saveBatch.add(setFlowApplyCheck(flowNode.getFlowId(), flowNode.getId(), flowNode.getBackNodeId(),
|
|
|
- flowNodelineNext.getToNodeId(), "", 1, null, null,
|
|
|
- param.getBusinessId(), param.getTitle()));
|
|
|
- iFlowApplycheckService.saveBatch(saveBatch);
|
|
|
- //消息通知,根据角色查询用户,通知所有拥有这个角色的人
|
|
|
- String roleId = flowNode.getRoleKey();
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 审批
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @return true流程已结束 false还有下一个节点
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean examineFlow(FlowParam param) {
|
|
|
- if (StringUtil.isEmpty(param.getProInstantsId())) {
|
|
|
- throw new ServiceException("流程ID不能为空");
|
|
|
- }
|
|
|
- //通过流程ID查询出走向数据
|
|
|
- FlowApplycheck flowApplycheck = iFlowApplycheckService.getById(param.getProInstantsId());
|
|
|
- if (flowApplycheck.getCheckState() != 1) {
|
|
|
- throw new ServiceException("该流程已处理完毕");
|
|
|
- }
|
|
|
- updateApplyCheck(param, 2);
|
|
|
- //如果下一个节点是空的,流程已结束
|
|
|
- if (StringUtil.isEmpty(flowApplycheck.getNextNodeId())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- //查询出当前节点连接
|
|
|
- FlowNodeline flowNodelineNext = iFlowNodelineService.getOne(Wrappers.<FlowNodeline>query().lambda().
|
|
|
- eq(FlowNodeline::getFromNodeId, flowApplycheck.getNextNodeId()));
|
|
|
- //查询出下一个节点基础信息
|
|
|
- FlowNode flowNode = iFlowNodeService.getOne(Wrappers.<FlowNode>query().lambda().
|
|
|
- eq(FlowNode::getId, flowApplycheck.getNextNodeId()));
|
|
|
- //生成审批节点走向
|
|
|
- iFlowApplycheckService.save(setFlowApplyCheck(flowNodelineNext.getFlowId(), flowApplycheck.getNextNodeId(), flowApplycheck.getNodeId(),
|
|
|
- flowNodelineNext.getToNodeId(), "", 1, null, null,
|
|
|
- param.getBusinessId(), param.getTitle()));
|
|
|
- //消息通知,根据角色查询用户,通知所有拥有这个角色的人
|
|
|
- String roleId = flowNode.getRoleKey();
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 驳回流程
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean rejectFlow(FlowParam param) {
|
|
|
- if (StringUtil.isEmpty(param.getProInstantsId())) {
|
|
|
- throw new ServiceException("流程ID不能为空");
|
|
|
- }
|
|
|
- //通过流程ID查询出走向数据
|
|
|
- FlowApplycheck flowApplycheck = iFlowApplycheckService.getById(param.getProInstantsId());
|
|
|
- updateApplyCheck(param, 3);
|
|
|
- //如果上一个节点是空的或者上一个节点是发起,流程也结束
|
|
|
- FlowNode checkFlowNode = iFlowNodeService.getOne(Wrappers.<FlowNode>query().lambda().
|
|
|
- eq(FlowNode::getId, flowApplycheck.getPreNodeId()));
|
|
|
- if (StringUtil.isEmpty(flowApplycheck.getPreNodeId()) ||
|
|
|
- StringUtil.isEmpty(checkFlowNode.getBackNodeId())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- //查询出当前节点连接
|
|
|
- FlowNodeline flowNodeline = iFlowNodelineService.getOne(Wrappers.<FlowNodeline>query().lambda().
|
|
|
- eq(FlowNodeline::getFromNodeId, flowApplycheck.getPreNodeId()));
|
|
|
- //查询出上一个节点基础信息
|
|
|
- FlowNode flowNode = iFlowNodeService.getOne(Wrappers.<FlowNode>query().lambda().
|
|
|
- eq(FlowNode::getId, flowNodeline.getFromNodeId()));
|
|
|
- //生成审批节点走向
|
|
|
- iFlowApplycheckService.save(setFlowApplyCheck(flowNode.getFlowId(), flowNode.getId(), flowNode.getBackNodeId(),
|
|
|
- flowNodeline.getToNodeId(), "", 1, null, null,
|
|
|
- param.getBusinessId(), param.getTitle()));
|
|
|
- //消息通知,根据角色查询用户,通知所有拥有这个角色的人
|
|
|
- String roleId = flowNode.getRoleKey();
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置属性
|
|
|
- *
|
|
|
- * @param flowId
|
|
|
- * @param nodeId
|
|
|
- * @param preNodeId
|
|
|
- * @param nextNodeId
|
|
|
- * @param checkUserId
|
|
|
- * @param checkState
|
|
|
- * @param checkTime
|
|
|
- * @param suggestions
|
|
|
- * @param linkId
|
|
|
- * @param approvalItem
|
|
|
- * @return
|
|
|
- */
|
|
|
- public FlowApplycheck setFlowApplyCheck(String flowId, String nodeId, String preNodeId, String nextNodeId,
|
|
|
- String checkUserId, int checkState, Date checkTime, String suggestions, String linkId, String approvalItem) {
|
|
|
- FlowApplycheck flowApplycheck = new FlowApplycheck();
|
|
|
- flowApplycheck.setCreatedTime(new Date());
|
|
|
- flowApplycheck.setFlowId(flowId);
|
|
|
- flowApplycheck.setNodeId(nodeId);
|
|
|
- flowApplycheck.setPreNodeId(preNodeId);
|
|
|
- flowApplycheck.setNextNodeId(nextNodeId);
|
|
|
- flowApplycheck.setCheckUserId(checkUserId);
|
|
|
- flowApplycheck.setCheckTime(checkTime);
|
|
|
- flowApplycheck.setCheckState(checkState);
|
|
|
- flowApplycheck.setSuggestions(suggestions);
|
|
|
- flowApplycheck.setLinkId(linkId);
|
|
|
- flowApplycheck.setApprovalItem(approvalItem);
|
|
|
- return flowApplycheck;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @param state
|
|
|
- */
|
|
|
- public void updateApplyCheck(FlowParam param, int state) {
|
|
|
- //修改流程标识为已审批
|
|
|
- FlowApplycheck update = new FlowApplycheck();
|
|
|
- update.setId(param.getProInstantsId());
|
|
|
- update.setUpdatedTime(new Date());
|
|
|
- update.setCheckUserId(AuthUtil.getUserIdStr());
|
|
|
- update.setCheckState(state);
|
|
|
- update.setCheckTime(new Date());
|
|
|
- update.setSuggestions(param.getCommon());
|
|
|
- update.setApprovalItem(param.getTitle());
|
|
|
- iFlowApplycheckService.updateById(update);
|
|
|
- }
|
|
|
-}
|