|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.fjhx.flow.core.FlowBean;
|
|
import com.fjhx.flow.core.FlowBean;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
import com.fjhx.flow.core.FlowThreadLocalUtil;
|
|
import com.fjhx.flow.core.FlowThreadLocalUtil;
|
|
|
|
+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.FlowDefinition;
|
|
@@ -14,6 +15,7 @@ import com.fjhx.flow.entity.flow.po.FlowDefinitionNode;
|
|
import com.fjhx.flow.entity.flow.po.FlowExample;
|
|
import com.fjhx.flow.entity.flow.po.FlowExample;
|
|
import com.fjhx.flow.entity.flow.po.FlowExampleDetail;
|
|
import com.fjhx.flow.entity.flow.po.FlowExampleDetail;
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
|
+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.*;
|
|
@@ -21,7 +23,11 @@ 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.BaseIdPo;
|
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
+import com.ruoyi.system.service.ISysDeptService;
|
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -49,8 +55,14 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
@Autowired
|
|
@Autowired
|
|
private FlowExampleDetailService flowExampleDetailService;
|
|
private FlowExampleDetailService flowExampleDetailService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysDeptService sysDeptService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysUserService sysUserService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public void initiate(InitiateDto dto) {
|
|
|
|
|
|
+ public FlowResult initiate(InitiateDto dto) {
|
|
|
|
|
|
// 找到代码定义的流程bean
|
|
// 找到代码定义的流程bean
|
|
Class<? extends FlowDelegate> flowDelegateCls = FlowBean.getBean(dto.getFlowKey());
|
|
Class<? extends FlowDelegate> flowDelegateCls = FlowBean.getBean(dto.getFlowKey());
|
|
@@ -59,8 +71,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
FlowDelegate flowDelegate = getFlowDelegate(flowDelegateCls);
|
|
FlowDelegate flowDelegate = getFlowDelegate(flowDelegateCls);
|
|
|
|
|
|
// 查找可用流程
|
|
// 查找可用流程
|
|
- FlowDefinition flowDefinition = flowDefinitionService.getOne(q -> q
|
|
|
|
- .eq(FlowDefinition::getFlowKey, dto.getFlowKey())
|
|
|
|
|
|
+ FlowDefinition flowDefinition = flowDefinitionService.getOne(q -> q.eq(FlowDefinition::getFlowKey, dto.getFlowKey())
|
|
.eq(FlowDefinition::getCurrentVersion, StatusConstant.YES));
|
|
.eq(FlowDefinition::getCurrentVersion, StatusConstant.YES));
|
|
|
|
|
|
if (flowDefinition == null) {
|
|
if (flowDefinition == null) {
|
|
@@ -97,6 +108,19 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
// 寻找下一节点
|
|
// 寻找下一节点
|
|
FlowDefinitionNode nextUserNode = getNextUserNode(startNode, parentNodeMap);
|
|
FlowDefinitionNode nextUserNode = getNextUserNode(startNode, parentNodeMap);
|
|
|
|
|
|
|
|
+ // 处理用户
|
|
|
|
+ Long userId;
|
|
|
|
+
|
|
|
|
+ if (dto.getHandleUserId() == null) {
|
|
|
|
+ FlowResult handleUser = getHandleUser(nextUserNode);
|
|
|
|
+ if (handleUser.getStatus() == 0) {
|
|
|
|
+ return handleUser;
|
|
|
|
+ }
|
|
|
|
+ userId = handleUser.getUserId();
|
|
|
|
+ } else {
|
|
|
|
+ userId = dto.getHandleUserId();
|
|
|
|
+ }
|
|
|
|
+
|
|
// 执行开始流程方法
|
|
// 执行开始流程方法
|
|
Long businessId;
|
|
Long businessId;
|
|
try {
|
|
try {
|
|
@@ -119,6 +143,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
|
|
}
|
|
}
|
|
flowExample.setStartData(dto.getData().toJSONString());
|
|
flowExample.setStartData(dto.getData().toJSONString());
|
|
|
|
+ flowExample.setHandleUserId(userId);
|
|
|
|
|
|
FlowExampleDetail startExampleDetail = new FlowExampleDetail();
|
|
FlowExampleDetail startExampleDetail = new FlowExampleDetail();
|
|
startExampleDetail.setFlowExampleId(flowId);
|
|
startExampleDetail.setFlowExampleId(flowId);
|
|
@@ -137,10 +162,13 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
endFlow(flowId, dto, nextUserNode, flowDelegateCls, flowDelegate);
|
|
endFlow(flowId, dto, nextUserNode, flowDelegateCls, flowDelegate);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ FlowResult flowResult = new FlowResult();
|
|
|
|
+ flowResult.setStatus(1);
|
|
|
|
+ return flowResult;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void jump(JumpDto dto) {
|
|
|
|
|
|
+ public FlowResult jump(JumpDto dto) {
|
|
Long flowId = dto.getFlowId();
|
|
Long flowId = dto.getFlowId();
|
|
|
|
|
|
FlowExample flowExample = flowExampleService.getById(flowId);
|
|
FlowExample flowExample = flowExampleService.getById(flowId);
|
|
@@ -239,6 +267,20 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
throw new ServiceException("未知节点处理类型");
|
|
throw new ServiceException("未知节点处理类型");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 处理用户
|
|
|
|
+ Long userId = null;
|
|
|
|
+ if (jumpUserNode != null) {
|
|
|
|
+ if (dto.getHandleUserId() == null) {
|
|
|
|
+ FlowResult handleUser = getHandleUser(jumpUserNode);
|
|
|
|
+ if (handleUser.getStatus() == 0) {
|
|
|
|
+ return handleUser;
|
|
|
|
+ }
|
|
|
|
+ userId = handleUser.getUserId();
|
|
|
|
+ } else {
|
|
|
|
+ userId = dto.getHandleUserId();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// 执行当前节点方法
|
|
// 执行当前节点方法
|
|
String handlingMethod = currentNode.getHandlingMethod();
|
|
String handlingMethod = currentNode.getHandlingMethod();
|
|
if (StrUtil.isNotBlank(handlingMethod)) {
|
|
if (StrUtil.isNotBlank(handlingMethod)) {
|
|
@@ -251,6 +293,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
}
|
|
}
|
|
|
|
|
|
flowExample.setStatus(flowStatusEnum.getKey());
|
|
flowExample.setStatus(flowStatusEnum.getKey());
|
|
|
|
+ flowExample.setHandleUserId(userId);
|
|
|
|
|
|
// 节点处理
|
|
// 节点处理
|
|
FlowExampleDetail nodeExampleDetail = new FlowExampleDetail();
|
|
FlowExampleDetail nodeExampleDetail = new FlowExampleDetail();
|
|
@@ -269,6 +312,9 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
endFlow(flowId, dto, jumpUserNode, flowDelegateCls, flowDelegate);
|
|
endFlow(flowId, dto, jumpUserNode, flowDelegateCls, flowDelegate);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ FlowResult flowResult = new FlowResult();
|
|
|
|
+ flowResult.setStatus(1);
|
|
|
|
+ return flowResult;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -408,4 +454,57 @@ public class FlowProcessServiceImpl implements FlowProcessService {
|
|
return Boolean.parseBoolean(String.valueOf(execute));
|
|
return Boolean.parseBoolean(String.valueOf(execute));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private FlowResult getHandleUser(FlowDefinitionNode node) {
|
|
|
|
+ FlowResult flowResult = new FlowResult();
|
|
|
|
+
|
|
|
|
+ Integer handleObjectType = node.getHandleObjectType();
|
|
|
|
+ Long handleObjectId = node.getHandleObjectId();
|
|
|
|
+
|
|
|
|
+ HandleObjectTypeEnum handleObjectTypeEnum = HandleObjectTypeEnum.getEnum(handleObjectType);
|
|
|
|
+
|
|
|
|
+ switch (handleObjectTypeEnum) {
|
|
|
|
+ case USER:
|
|
|
|
+ flowResult.setStatus(1);
|
|
|
|
+ flowResult.setUserId(handleObjectId);
|
|
|
|
+ return flowResult;
|
|
|
|
+ case DETP_LEADER:
|
|
|
|
+ case DEPT_DIRECTOR:
|
|
|
|
+ SysDept sysDept = sysDeptService.getById(handleObjectId);
|
|
|
|
+ if (sysDept == null) {
|
|
|
|
+ throw new ServiceException("部门为空");
|
|
|
|
+ }
|
|
|
|
+ if (HandleObjectTypeEnum.DETP_LEADER.equals(handleObjectTypeEnum)) {
|
|
|
|
+ Long leaderId = sysDept.getLeaderId();
|
|
|
|
+ if (leaderId == null) {
|
|
|
|
+ throw new ServiceException("部门负责人为空");
|
|
|
|
+ }
|
|
|
|
+ flowResult.setUserId(leaderId);
|
|
|
|
+ } else {
|
|
|
|
+ Long directorId = sysDept.getDirectorId();
|
|
|
|
+ if (directorId == null) {
|
|
|
|
+ throw new ServiceException("部门总监为空");
|
|
|
|
+ }
|
|
|
|
+ flowResult.setUserId(directorId);
|
|
|
|
+ }
|
|
|
|
+ flowResult.setStatus(1);
|
|
|
|
+ return flowResult;
|
|
|
|
+ case POST:
|
|
|
|
+ List<SysUser> userList = sysUserService.getListByPostId(handleObjectId);
|
|
|
|
+ if (userList.size() == 0) {
|
|
|
|
+ throw new ServiceException("岗位无用户");
|
|
|
|
+ }
|
|
|
|
+ if (userList.size() == 1) {
|
|
|
|
+ flowResult.setStatus(1);
|
|
|
|
+ flowResult.setUserId(userList.get(0).getUserId());
|
|
|
|
+ return flowResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ flowResult.setStatus(0);
|
|
|
|
+ flowResult.setUserList(userList);
|
|
|
|
+ return flowResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return flowResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|