24282 2 年之前
父节点
当前提交
a5ed5a2e8f

+ 3 - 0
hx-flow/src/main/java/com/fjhx/flow/controller/flow/FlowProcessController.java

@@ -28,6 +28,9 @@ public class FlowProcessController {
         flowProcessService.initiate(dto);
     }
 
+    /**
+     * 流程跳转
+     */
     @PostMapping("/jump")
     public void jump(@Validated @RequestBody JumpDto dto) {
         flowProcessService.jump(dto);

+ 28 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/FlowResult.java

@@ -0,0 +1,28 @@
+package com.fjhx.flow.entity.flow.dto;
+
+import com.ruoyi.common.core.domain.entity.SysUser;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+@Getter
+@Setter
+public class FlowResult {
+
+    /**
+     * 1成功 0失败
+     */
+    private Integer status;
+
+    /**
+     * 处理用户
+     */
+    private List<SysUser> userList;
+
+    /**
+     * 用户id
+     */
+    private Long userId;
+
+}

+ 20 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/GetHandleUserDto.java

@@ -0,0 +1,20 @@
+package com.fjhx.flow.entity.flow.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class GetHandleUserDto {
+
+    /**
+     * 流程id
+     */
+    private Long flowId;
+
+    /**
+     * 流程标识
+     */
+    private String flowKey;
+
+}

+ 5 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/InitiateDto.java

@@ -22,6 +22,11 @@ public class InitiateDto {
     private String remark;
 
     /**
+     * 下级节点审批人
+     */
+    private Long handleUserId;
+
+    /**
      * 提交数据
      */
     private JSONObject data;

+ 5 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/dto/JumpDto.java

@@ -29,6 +29,11 @@ public class JumpDto {
     private Integer version;
 
     /**
+     * 下级节点审批人
+     */
+    private Long handleUserId;
+
+    /**
      * 处理备注
      */
     private String remark;

+ 2 - 2
hx-flow/src/main/java/com/fjhx/flow/entity/flow/po/FlowDefinitionNode.java

@@ -51,11 +51,11 @@ public class FlowDefinitionNode extends BaseIdPo {
     /**
      * 发起 / 处理对象类型(1用户 2角色 3部门)
      */
-    private Byte handleObjectType;
+    private Integer handleObjectType;
 
     /**
      * 指定对象id集合
      */
-    private String handleObjectIdSet;
+    private Long handleObjectId;
 
 }

+ 5 - 0
hx-flow/src/main/java/com/fjhx/flow/entity/flow/po/FlowExample.java

@@ -41,6 +41,11 @@ public class FlowExample extends BasePo {
     private Long definitionNodeId;
 
     /**
+     * 节点处理人id
+     */
+    private Long handleUserId;
+
+    /**
      * 业务id
      */
     private Long businessId;

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

@@ -0,0 +1,40 @@
+package com.fjhx.flow.enums;
+
+import com.ruoyi.common.exception.ServiceException;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Getter
+@AllArgsConstructor
+public enum HandleObjectTypeEnum {
+
+    USER(1, "用户"),
+    DETP_LEADER(2, "部门负责人"),
+    DEPT_DIRECTOR(3, "部门总监"),
+    POST(4, "岗位"),
+    ;
+
+    private final Integer key;
+
+    private final String value;
+
+    private static final Map<Integer, HandleObjectTypeEnum> map = new HashMap<>();
+
+    static {
+        for (HandleObjectTypeEnum value : HandleObjectTypeEnum.values()) {
+            map.put(value.getKey(), value);
+        }
+    }
+
+    public static HandleObjectTypeEnum getEnum(Integer key) {
+        HandleObjectTypeEnum handleObjectTypeEnum = map.get(key);
+        if (handleObjectTypeEnum == null) {
+            throw new ServiceException("未知处理人类型");
+        }
+        return handleObjectTypeEnum;
+    }
+
+}

+ 3 - 2
hx-flow/src/main/java/com/fjhx/flow/service/flow/FlowProcessService.java

@@ -1,12 +1,13 @@
 package com.fjhx.flow.service.flow;
 
+import com.fjhx.flow.entity.flow.dto.FlowResult;
 import com.fjhx.flow.entity.flow.dto.InitiateDto;
 import com.fjhx.flow.entity.flow.dto.JumpDto;
 
 public interface FlowProcessService {
 
-    void initiate(InitiateDto dto);
+    FlowResult initiate(InitiateDto dto);
 
-    void jump(JumpDto dto);
+    FlowResult jump(JumpDto dto);
 
 }

+ 103 - 4
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowProcessServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.fjhx.flow.core.FlowBean;
 import com.fjhx.flow.core.FlowDelegate;
 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.JumpDto;
 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.FlowExampleDetail;
 import com.fjhx.flow.enums.FlowStatusEnum;
+import com.fjhx.flow.enums.HandleObjectTypeEnum;
 import com.fjhx.flow.enums.HandleTypeEnum;
 import com.fjhx.flow.enums.NodeTypeEnum;
 import com.fjhx.flow.service.flow.*;
@@ -21,7 +23,11 @@ import com.googlecode.aviator.AviatorEvaluator;
 import com.googlecode.aviator.Expression;
 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.SysUser;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.system.service.ISysDeptService;
+import com.ruoyi.system.service.ISysUserService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -49,8 +55,14 @@ public class FlowProcessServiceImpl implements FlowProcessService {
     @Autowired
     private FlowExampleDetailService flowExampleDetailService;
 
+    @Autowired
+    private ISysDeptService sysDeptService;
+
+    @Autowired
+    private ISysUserService sysUserService;
+
     @Override
-    public void initiate(InitiateDto dto) {
+    public FlowResult initiate(InitiateDto dto) {
 
         // 找到代码定义的流程bean
         Class<? extends FlowDelegate> flowDelegateCls = FlowBean.getBean(dto.getFlowKey());
@@ -59,8 +71,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
         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));
 
         if (flowDefinition == null) {
@@ -97,6 +108,19 @@ public class FlowProcessServiceImpl implements FlowProcessService {
         // 寻找下一节点
         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;
         try {
@@ -119,6 +143,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
         }
         flowExample.setStartData(dto.getData().toJSONString());
+        flowExample.setHandleUserId(userId);
 
         FlowExampleDetail startExampleDetail = new FlowExampleDetail();
         startExampleDetail.setFlowExampleId(flowId);
@@ -137,10 +162,13 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             endFlow(flowId, dto, nextUserNode, flowDelegateCls, flowDelegate);
         }
 
+        FlowResult flowResult = new FlowResult();
+        flowResult.setStatus(1);
+        return flowResult;
     }
 
     @Override
-    public void jump(JumpDto dto) {
+    public FlowResult jump(JumpDto dto) {
         Long flowId = dto.getFlowId();
 
         FlowExample flowExample = flowExampleService.getById(flowId);
@@ -239,6 +267,20 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 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();
         if (StrUtil.isNotBlank(handlingMethod)) {
@@ -251,6 +293,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
         }
 
         flowExample.setStatus(flowStatusEnum.getKey());
+        flowExample.setHandleUserId(userId);
 
         // 节点处理
         FlowExampleDetail nodeExampleDetail = new FlowExampleDetail();
@@ -269,6 +312,9 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             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));
     }
 
+    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;
+    }
+
 }

+ 10 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CaptchaController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.web.controller.common;
 
 import com.baomidou.dynamic.datasource.annotation.DS;
+import com.fjhx.flow.core.FlowBean;
 import com.google.code.kaptcha.Producer;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.constant.CacheConstants;
@@ -11,11 +12,13 @@ import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.sign.Base64;
 import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.system.service.ISysConfigService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.FastByteArrayOutputStream;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
@@ -27,6 +30,7 @@ import java.util.concurrent.TimeUnit;
  *
  * @author ruoyi
  */
+@Slf4j
 @DS(DatasourceConstant.BASE)
 @RestController
 public class CaptchaController {
@@ -42,6 +46,12 @@ public class CaptchaController {
     @Autowired
     private ISysConfigService configService;
 
+    @PostConstruct
+    public void initFlow() {
+        log.info("流程bean注册");
+        FlowBean.addBean("test_flow", TestFlow.class);
+    }
+
     /**
      * 生成验证码
      */

+ 63 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/TestFlow.java

@@ -0,0 +1,63 @@
+package com.ruoyi.web.controller.common;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.fjhx.flow.core.FlowDelegate;
+import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.system.service.ISysConfigService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Slf4j
+@Service
+public class TestFlow extends FlowDelegate {
+
+    @Autowired
+    private ISysConfigService sysConfigService;
+
+    @DS("iot")
+    @Transactional
+    @Override
+    public Long start(Long flowId, JSONObject data) {
+
+        long id = IdWorker.getId();
+
+        System.err.println(flowId);
+        System.err.println(data);
+        System.err.println(id);
+
+        List<SysConfig> list = sysConfigService.list();
+        SysConfig sysConfig = new SysConfig();
+        sysConfig.setRemark("备注");
+        sysConfigService.save(sysConfig);
+
+        return id;
+    }
+
+    @Override
+    public void end() {
+        log.error("默认结束方法");
+    }
+
+    public void testEnd() {
+        log.error("测试结束方法");
+    }
+
+    public void type1() {
+        log.error("type1");
+    }
+
+    public void type2() {
+        log.error("type2");
+    }
+
+    public void type3() {
+        log.error("type2");
+    }
+
+}

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java

@@ -127,4 +127,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
      * @return 结果
      */
     public SysUser checkEmailUnique(String email);
+
+    List<SysUser> getListByPostId(Long postId);
+
 }

+ 8 - 4
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@@ -1,11 +1,7 @@
 package com.ruoyi.system.service;
 
-import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.ruoyi.common.constant.DatasourceConstant;
 import com.ruoyi.common.core.domain.entity.SysUser;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -211,9 +207,17 @@ public interface ISysUserService extends IService<SysUser> {
 
     /**
      * 通过userId列表获取uis对象list
+     *
      * @param userIdList 用户id list
      * @return 用户list
      */
     List<SysUser> getListByUserId(List<Long> userIdList);
 
+    /**
+     * 根据岗位id获取用户列表
+     *
+     * @param postId
+     */
+    List<SysUser> getListByPostId(Long postId);
+
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -491,4 +491,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         return listByIds(userIdList);
     }
 
+    @Override
+    public List<SysUser> getListByPostId(Long postId) {
+        return baseMapper.getListByPostId(postId);
+    }
+
 }

+ 23 - 1
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -197,7 +197,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
 		select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
 	</select>
-	
+	<select id="getListByPostId" resultType="com.ruoyi.common.core.domain.entity.SysUser">
+        select u.user_id,
+               u.dept_id,
+               u.user_name,
+               u.nick_name,
+               u.email,
+               u.avatar,
+               u.phonenumber,
+               u.password,
+               u.sex,
+               u.status,
+               u.del_flag,
+               u.login_ip,
+               u.login_date,
+               u.create_by,
+               u.create_time,
+               u.remark,
+               u.tenant_id
+        from sys_user_post sup
+                 inner join sys_user u on sup.user_id = u.id
+        where sup.post_id = #{postId}
+    </select>
+
 	<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
  		insert into sys_user(
  			<if test="userId != null and userId != 0">user_id,</if>