|
@@ -1,10 +1,13 @@
|
|
package com.fjhx.flow.service.flow.impl;
|
|
package com.fjhx.flow.service.flow.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.flow.core.FlowBean;
|
|
import com.fjhx.flow.core.FlowBean;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
@@ -12,21 +15,22 @@ import com.fjhx.flow.core.FlowThreadLocalUtil;
|
|
import com.fjhx.flow.entity.flow.dto.FlowResult;
|
|
import com.fjhx.flow.entity.flow.dto.FlowResult;
|
|
import com.fjhx.flow.entity.flow.dto.InitiateDto;
|
|
import com.fjhx.flow.entity.flow.dto.InitiateDto;
|
|
import com.fjhx.flow.entity.flow.dto.JumpDto;
|
|
import com.fjhx.flow.entity.flow.dto.JumpDto;
|
|
-import com.fjhx.flow.entity.flow.po.FlowDefinition;
|
|
|
|
-import com.fjhx.flow.entity.flow.po.FlowDefinitionNode;
|
|
|
|
-import com.fjhx.flow.entity.flow.po.FlowExample;
|
|
|
|
-import com.fjhx.flow.entity.flow.po.FlowExampleDetail;
|
|
|
|
|
|
+import com.fjhx.flow.entity.flow.po.*;
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
import com.fjhx.flow.enums.HandleObjectTypeEnum;
|
|
import com.fjhx.flow.enums.HandleObjectTypeEnum;
|
|
import com.fjhx.flow.enums.HandleTypeEnum;
|
|
import com.fjhx.flow.enums.HandleTypeEnum;
|
|
import com.fjhx.flow.enums.NodeTypeEnum;
|
|
import com.fjhx.flow.enums.NodeTypeEnum;
|
|
import com.fjhx.flow.service.flow.*;
|
|
import com.fjhx.flow.service.flow.*;
|
|
|
|
+import com.fjhx.socket.core.PushTypeEnum;
|
|
|
|
+import com.fjhx.socket.core.WebSocketPush;
|
|
import com.googlecode.aviator.AviatorEvaluator;
|
|
import com.googlecode.aviator.AviatorEvaluator;
|
|
import com.googlecode.aviator.Expression;
|
|
import com.googlecode.aviator.Expression;
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
import com.ruoyi.common.constant.StatusConstant;
|
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -35,9 +39,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -65,6 +67,9 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
@Autowired
|
|
@Autowired
|
|
private ISysUserService sysUserService;
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FlowInfoService flowInfoService;
|
|
|
|
+
|
|
@DSTransactional
|
|
@DSTransactional
|
|
@Override
|
|
@Override
|
|
public FlowResult initiate(InitiateDto dto) {
|
|
public FlowResult initiate(InitiateDto dto) {
|
|
@@ -184,6 +189,9 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
// 保存节点附件
|
|
// 保存节点附件
|
|
ObsFileUtil.saveFile(dto.getFileList(), startExampleDetail.getId());
|
|
ObsFileUtil.saveFile(dto.getFileList(), startExampleDetail.getId());
|
|
|
|
|
|
|
|
+ // 推送
|
|
|
|
+ pushInitiate(flowId, flowDefinition, nextNodeType, flowExample);
|
|
|
|
+
|
|
FlowResult flowResult = new FlowResult();
|
|
FlowResult flowResult = new FlowResult();
|
|
flowResult.setSuccess(true);
|
|
flowResult.setSuccess(true);
|
|
return flowResult;
|
|
return flowResult;
|
|
@@ -384,6 +392,9 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
// 保存节点附件
|
|
// 保存节点附件
|
|
ObsFileUtil.saveFile(dto.getFileList(), nodeExampleDetail.getId());
|
|
ObsFileUtil.saveFile(dto.getFileList(), nodeExampleDetail.getId());
|
|
|
|
|
|
|
|
+ // 消息推送
|
|
|
|
+ pushJump(handleTypeEnum, nextUserNode, flowExample, currentNode);
|
|
|
|
+
|
|
FlowResult flowResult = new FlowResult();
|
|
FlowResult flowResult = new FlowResult();
|
|
flowResult.setSuccess(true);
|
|
flowResult.setSuccess(true);
|
|
return flowResult;
|
|
return flowResult;
|
|
@@ -616,6 +627,96 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 开始节点消息推送
|
|
|
|
+ */
|
|
|
|
+ private void pushInitiate(long flowId, FlowDefinition flowDefinition, NodeTypeEnum nextNodeType, FlowExample flowExample) {
|
|
|
|
+ Map<String, Object> businessData = new HashMap<>();
|
|
|
|
+ businessData.put("flowId", flowId);
|
|
|
|
+ businessData.put("flowKey", flowDefinition.getFlowKey());
|
|
|
|
+
|
|
|
|
+ Long pushUserId;
|
|
|
|
+ String title;
|
|
|
|
+ if (NodeTypeEnum.END.equals(nextNodeType)) {
|
|
|
|
+ FlowInfo flowInfo = flowInfoService.getById(flowDefinition.getFlowInfoId());
|
|
|
|
+ String flowName = flowInfo == null ? StringPool.EMPTY : flowInfo.getFlowName();
|
|
|
|
+
|
|
|
|
+ pushUserId = flowExample.getHandleUserId();
|
|
|
|
+ title = StrUtil.format("您于【{}】发起的【{}}】已经审批通过。", DateUtil.formatDateTime(new Date()), flowName);
|
|
|
|
+ } else {
|
|
|
|
+ pushUserId = SecurityUtils.getUserId();
|
|
|
|
+ title = "您有一条新的待审批事项,请及时处理。";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ WebSocketPush.byUser(PushTypeEnum.MESSAGE, pushUserId, title, 0, businessData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 跳转节点消息推送
|
|
|
|
+ */
|
|
|
|
+ private void pushJump(HandleTypeEnum handleTypeEnum, FlowDefinitionNode nextUserNode, FlowExample flowExample, FlowDefinitionNode currentNode) {
|
|
|
|
+ Map<String, Object> businessData = new HashMap<>();
|
|
|
|
+ businessData.put("flowId", flowExample.getId());
|
|
|
|
+ businessData.put("flowKey", flowExample.getFlowKey());
|
|
|
|
+
|
|
|
|
+ FlowInfo flowInfo = flowInfoService.getOne(q -> q.eq(FlowInfo::getFlowKey, flowExample.getFlowKey()));
|
|
|
|
+ String flowName = flowInfo == null ? StringPool.EMPTY : flowInfo.getFlowName();
|
|
|
|
+
|
|
|
|
+ String title;
|
|
|
|
+ Long pushUserId;
|
|
|
|
+
|
|
|
|
+ switch (handleTypeEnum) {
|
|
|
|
+ // 跳转下一节点
|
|
|
|
+ case SKIP_TO_NEXT:
|
|
|
|
+ // 如果下一节点为结束节点
|
|
|
|
+ if (NodeTypeEnum.END.equals(NodeTypeEnum.getEnum(nextUserNode.getNodeType()))) {
|
|
|
|
+ title = StrUtil.format("您于【{}】发起的【{}}】已经审批通过。",
|
|
|
|
+ DateUtil.formatDateTime(flowExample.getCreateTime()),
|
|
|
|
+ flowName);
|
|
|
|
+ pushUserId = flowExample.getCreateUser();
|
|
|
|
+ }
|
|
|
|
+ // 如果下一节点不为结束节点
|
|
|
|
+ else {
|
|
|
|
+ title = "您有一条新的待审批事项,请及时处理。";
|
|
|
|
+ pushUserId = flowExample.getHandleUserId();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ // 驳回流程
|
|
|
|
+ case REJECT:
|
|
|
|
+ title = StrUtil.format("您于【{}】发起的【{}】在【{}】被驳回。",
|
|
|
|
+ DateUtil.formatDateTime(flowExample.getCreateTime()),
|
|
|
|
+ flowName,
|
|
|
|
+ currentNode.getNodeName());
|
|
|
|
+ pushUserId = flowExample.getCreateUser();
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ // 退回上一节点,退回到发起人
|
|
|
|
+ case RETURN_TO_PREVIOUS:
|
|
|
|
+ case RETURN_TO_SUBMITTER:
|
|
|
|
+
|
|
|
|
+ // 查找上次审批节点
|
|
|
|
+ FlowExampleDetail flowExampleDetail = flowExampleDetailService.getOne(
|
|
|
|
+ Wrappers.<FlowExampleDetail>lambdaQuery()
|
|
|
|
+ .eq(FlowExampleDetail::getFlowExampleId, flowExample.getId())
|
|
|
|
+ .orderByDesc(BaseIdPo::getId)
|
|
|
|
+ .last("limit 1,1")
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ title = StrUtil.format("您于【{}】提交的【{}】被退回,请及时处理。",
|
|
|
|
+ DateUtil.formatDateTime(flowExampleDetail.getCreateTime()),
|
|
|
|
+ flowName);
|
|
|
|
+
|
|
|
|
+ pushUserId = flowExampleDetail.getCreateUser();
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ throw new ServiceException("未知处理方法");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ WebSocketPush.byUser(PushTypeEnum.MESSAGE, pushUserId, title, 0, businessData);
|
|
|
|
+ }
|
|
|
|
+
|
|
// public static void main(String[] args) {
|
|
// public static void main(String[] args) {
|
|
// HashMap<String, Object> map = new HashMap<>();
|
|
// HashMap<String, Object> map = new HashMap<>();
|
|
//
|
|
//
|