yzc 1 год назад
Родитель
Сommit
b0dc3b0f40

+ 1 - 1
hx-flow/src/main/java/com/fjhx/flow/enums/HandleObjectTypeEnum.java

@@ -17,7 +17,7 @@ public enum HandleObjectTypeEnum {
     POST(4, "岗位"),
     ROLE(5, "角色"),
     PARALLEL(6, "动态用户"),
-    DEPT_MANAGER(8, "部门主管"),
+    DEPT_MANAGER(8, "职级"),
     BUSINESS_USER(9, "用户表达式"),
     ;
 

+ 5 - 0
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowDefinitionServiceImpl.java

@@ -15,6 +15,7 @@ import com.fjhx.flow.entity.flow.po.FlowInfo;
 import com.fjhx.flow.entity.flow.vo.FlowDefinitionPageVo;
 import com.fjhx.flow.entity.flow.vo.FlowDefinitionVo;
 import com.fjhx.flow.enums.HandleTypeEnum;
+import com.fjhx.flow.enums.NodeHandleTypeEnum;
 import com.fjhx.flow.enums.NodeTypeEnum;
 import com.fjhx.flow.mapper.flow.FlowDefinitionMapper;
 import com.fjhx.flow.service.flow.FlowDefinitionLineService;
@@ -147,6 +148,10 @@ public class FlowDefinitionServiceImpl extends ServiceImpl<FlowDefinitionMapper,
         List<FlowDefinitionLine> flowDefinitionLineList = dto.getFlowDefinitionLineList();
 
         for (FlowDefinitionNode flowDefinitionNode : flowDefinitionNodeList) {
+            if(ObjectUtil.isEmpty(flowDefinitionNode.getNodeHandleType())){
+                //默认为常规节点
+                flowDefinitionNode.setNodeHandleType(NodeHandleTypeEnum.ORDINARY.getKey());
+            }
             flowDefinitionNode.setFlowDefinitionId(dto.getId());
 
             Long oldId = flowDefinitionNode.getId();

+ 49 - 7
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowProcessServiceImpl.java

@@ -34,7 +34,6 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysUserIdentityService;
 import com.ruoyi.system.service.ISysUserService;
-import com.ruoyi.system.utils.UserUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -81,7 +80,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
     @DSTransactional
     @Override
     public FlowResult initiate(InitiateDto dto) {
-        dto.getData().put("createUser",SecurityUtils.getUserId());
+        dto.getData().put("createUser", SecurityUtils.getUserId());
 
         // 获取流程委托对象
         FlowDelegate flowDelegate = FlowBean.getBean(dto.getFlowKey());
@@ -981,13 +980,56 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 flowResult.setUserId(dynamicUserIdsStr);
                 return flowResult;
             case DEPT_MANAGER:
-                SysUser createUser = sysUserService.getById(FlowThreadLocalUtil.getFlowCreateUser());
+                Long deptId ;
+                if(ObjectUtil.isEmpty(node.getJumpCondition())){
+                    //没表达式取发起人部门
+                    SysUser createUser = sysUserService.getById(FlowThreadLocalUtil.getFlowCreateUser());
+                    deptId = createUser.getDeptId();
+                }else {
+                    //有表达式取表达式部门
+                    Expression exp = AviatorEvaluator.compile(node.getJumpCondition());
+                    Object execute = exp.execute(FlowThreadLocalUtil.getTemplateData());
+                    if (ObjectUtil.isEmpty(execute)) {
+                        throw new ServiceException("节点用户表达式结果为空!");
+                    }
+                    deptId = Long.valueOf(execute.toString());
+                }
+                //递归查询部门
+                SysDept sysDept1 = sysDeptService.getById(deptId);
+                while (sysDept1 != null && ObjectUtil.notEqual(sysDept1.getType(), 2)) {
+                    Long deptParentId = sysDept1.getParentId();
+                    if (ObjectUtil.isEmpty(deptParentId)) {
+                        sysDept1 = null;
+                        break;
+                    }
+                    sysDept1 = sysDeptService.getById(deptParentId);
+                }
+                if (sysDept1 == null) {
+                    throw new ServiceException("无法找到节点部门信息!");
+                }
                 List<SysUserIdentity> identityList = sysUserIdentityService.list(Wrappers.<SysUserIdentity>lambdaQuery()
-                        .eq(SysUserIdentity::getDeptId, createUser.getDeptId())
-                        .eq(SysUserIdentity::getIdentity, 20)
+                        .eq(SysUserIdentity::getDeptId, sysDept1.getDeptId())
+                        .eq(SysUserIdentity::getIdentity, node.getHandleObjectId())
                 );
+                String identityName ;
+                switch (node.getHandleObjectId()){
+                    case  "10":
+                       identityName =  "员工";
+                    break;
+                    case  "20":
+                        identityName =  "主管";
+                        break;
+                    case  "30":
+                        identityName =  "经理";
+                        break;
+                    case  "40":
+                        identityName =  "总监";
+                        break;
+                    default:
+                        identityName = "未知职级";
+                }
                 if (identityList.size() == 0) {
-                    throw new ServiceException("流程节点处理人异常:当前所在部门无部门主管!");
+                    throw new ServiceException(StrUtil.format("流程节点处理人异常:部门无部门{}!",identityName));
                 }
                 List<Long> userIds = identityList.stream().map(SysUserIdentity::getUserId).collect(Collectors.toList());
                 List<SysUser> identityUserList = sysUserService.list(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds));
@@ -1003,7 +1045,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 Expression exp = AviatorEvaluator.compile(node.getJumpCondition());
                 Object execute = exp.execute(FlowThreadLocalUtil.getTemplateData());
                 if (ObjectUtil.isEmpty(execute)) {
-                    throw new ServiceException("节点用户表达式结果不能为空!");
+                    throw new ServiceException("节点用户表达式结果为空!");
                 }
                 String userId = String.valueOf(execute);
                 SysUser sysUser = sysUserService.getById(Long.valueOf(userId));