24282 2 роки тому
батько
коміт
bf50a17a09

+ 0 - 11
hx-flow/src/main/java/com/fjhx/flow/core/FlowThreadLocalUtil.java

@@ -130,17 +130,6 @@ public class FlowThreadLocalUtil {
     }
 
     // ===================================================
-    //  流程状态
-    // ===================================================
-    public static FlowStatusEnum getFlowStatusEnum() {
-        return getData().flowStatusEnum;
-    }
-
-    public static void setFlowStatusEnum(FlowStatusEnum flowStatusEnum) {
-        getData().flowStatusEnum = flowStatusEnum;
-    }
-
-    // ===================================================
     //  下个节点审批用户id
     // ===================================================
     public static Long getNextHandleUserId() {

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

@@ -32,7 +32,7 @@ public class FlowDefinitionNode extends BaseIdPo {
     private String nodeName;
 
     /**
-     * 节点类型 1开始 2审核 3审批 4办理 5分支 99结束
+     * 节点类型 1开始 2办理 3分支 99结束
      */
     @NotNull(message = "流程节点类型不能为空")
     private Integer nodeType;

+ 1 - 3
hx-flow/src/main/java/com/fjhx/flow/entity/flow/po/FlowExampleDetail.java

@@ -1,7 +1,5 @@
 package com.fjhx.flow.entity.flow.po;
 
-import cn.hutool.core.util.ObjectUtil;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
@@ -36,7 +34,7 @@ public class FlowExampleDetail extends BasePo {
     private Integer flowDefinitionNodeType;
 
     /**
-     * 处理类型 1跳转下一节点 2返回上一节点 3结束流程
+     * 处理类型 1、跳转下一节点 2、结束流程 3、返回上一节点 4、退回到发起人
      */
     private Integer handleType;
 

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

@@ -15,6 +15,7 @@ public enum HandleObjectTypeEnum {
     DETP_LEADER(2, "部门负责人"),
     DEPT_DIRECTOR(3, "部门总监"),
     POST(4, "岗位"),
+    ROLE(5, "角色")
     ;
 
     private final Integer key;

+ 8 - 3
hx-flow/src/main/java/com/fjhx/flow/enums/HandleTypeEnum.java

@@ -11,9 +11,14 @@ import java.util.Map;
 @AllArgsConstructor
 public enum HandleTypeEnum {
 
-    NEXT(1, "跳转下一节点"),
-    PREVIOUS(2, "返回上一节点"),
-    OVER(3, "结束流程"),
+    // 跳转下一节点
+    NEXT(1, "通过"),
+    // 结束流程
+    REJECT(2, "驳回"),
+    // 返回上一节点
+    PREVIOUS(3, "返回上一步"),
+    // 退回到发起人
+    RETURN_TO_SPONSOR(4, "退回到发起人"),
     ;
 
     private final Integer key;

+ 2 - 7
hx-flow/src/main/java/com/fjhx/flow/enums/NodeTypeEnum.java

@@ -12,13 +12,8 @@ import java.util.Map;
 public enum NodeTypeEnum {
 
     START(1, "开始"),
-    // 通过/不通过,通过后向下一节点流转,不通过则退回上一节点
-    EXAMINED(2, "审核"),
-    // 同意/驳回,同意后向下一节点流转,驳回则以驳回状态结束本流程
-    APPROVAL(3, "审批"),
-    // 办理,办理后向下一节点流转
-    HANDLE(4, "办理"),
-    BRANCH(5, "分支"),
+    HANDLE(2, "办理"),
+    BRANCH(3, "分支"),
     END(99, "结束");
 
     private final Integer key;

+ 74 - 17
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowProcessServiceImpl.java

@@ -37,6 +37,8 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -122,11 +124,9 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             }
             // 流程进行中
             flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
-            FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.IN_PROGRESS);
         } else {
             // 流程已通过
             flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
-            FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.HAVE_PASSED);
         }
 
         // 执行开始流程方法
@@ -163,11 +163,11 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             endExampleDetail.setFlowExampleId(flowId);
             endExampleDetail.setFlowDefinitionNodeId(nextUserNode.getId());
             endExampleDetail.setFlowDefinitionNodeType(nextUserNode.getNodeType());
-            endExampleDetail.setHandleType(HandleTypeEnum.OVER.getKey());
+            endExampleDetail.setHandleType(HandleTypeEnum.NEXT.getKey());
             flowExampleDetailList.add(endExampleDetail);
         }
 
-        flowExample.setTitle(StrUtil.format(flowDefinition.getTitleTemplate(), templateMap, true));
+        flowExample.setTitle(templateParse(flowDefinition.getTitleTemplate(), templateMap));
         flowExample.setFlowKey(dto.getFlowKey());
         flowExample.setDefinitionId(flowDefinition.getId());
         flowExample.setDefinitionNodeId(nextUserNode.getId());
@@ -234,6 +234,8 @@ public class FlowProcessServiceImpl implements FlowProcessService {
         // 跳转节点
         FlowDefinitionNode nextUserNode = null;
         switch (handleTypeEnum) {
+
+            // 跳转下一节点
             case NEXT:
 
                 // 寻找下一节点
@@ -246,7 +248,6 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 if (NodeTypeEnum.END.equals(NodeTypeEnum.getEnum(nextUserNode.getNodeType()))) {
                     // 流程已通过
                     flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
-                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.HAVE_PASSED);
                 } else {
 
                     FlowResult handleUser = getHandleUser(nextUserNode, dto.getHandleUserId());
@@ -263,10 +264,15 @@ public class FlowProcessServiceImpl implements FlowProcessService {
 
                     // 流程进行中
                     flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
-                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.IN_PROGRESS);
                 }
                 break;
 
+            // 结束流程
+            case REJECT:
+                flowExample.setStatus(FlowStatusEnum.REJECTED.getKey());
+                break;
+
+            // 返回上一节点
             case PREVIOUS:
 
                 // 查找上一个节点
@@ -281,17 +287,23 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 if (NodeTypeEnum.START.getKey().equals(lastOneFlowExampleDetail.getFlowDefinitionNodeType())) {
                     // 流程未发起
                     flowExample.setStatus(FlowStatusEnum.UNINITIATED.getKey());
-                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.UNINITIATED);
                 } else {
                     // 流程进行中
                     flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
-                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.IN_PROGRESS);
                 }
                 break;
 
-            case OVER:
-                flowExample.setStatus(FlowStatusEnum.REJECTED.getKey());
-                FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.REJECTED);
+            // 退回到发起人
+            case RETURN_TO_SPONSOR:
+
+                // 获取第一个用户操作节点
+                FlowExampleDetail exampleDetail = flowExampleDetailService.getOne(q -> q
+                        .eq(FlowExampleDetail::getFlowExampleId, flowId));
+
+                flowExample.setHandleUserId(exampleDetail.getCreateUser());
+                flowExample.setDefinitionNodeId(exampleDetail.getFlowDefinitionNodeId());
+                flowExample.setStatus(FlowStatusEnum.UNINITIATED.getKey());
+                FlowThreadLocalUtil.setNextHandleUserId(exampleDetail.getCreateUser());
                 break;
 
             default:
@@ -332,7 +344,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             endExampleDetail.setFlowExampleId(flowId);
             endExampleDetail.setFlowDefinitionNodeId(nextUserNode.getId());
             endExampleDetail.setFlowDefinitionNodeType(nextUserNode.getNodeType());
-            endExampleDetail.setHandleType(HandleTypeEnum.OVER.getKey());
+            endExampleDetail.setHandleType(HandleTypeEnum.NEXT.getKey());
             flowExampleDetailList.add(endExampleDetail);
 
         }
@@ -474,10 +486,12 @@ public class FlowProcessServiceImpl implements FlowProcessService {
         HandleObjectTypeEnum handleObjectTypeEnum = HandleObjectTypeEnum.getEnum(handleObjectType);
 
         switch (handleObjectTypeEnum) {
+
             case USER:
                 flowResult.setSuccess(true);
                 flowResult.setUserId(handleObjectId);
                 return flowResult;
+
             case DETP_LEADER:
             case DEPT_DIRECTOR:
                 SysDept sysDept = sysDeptService.getById(handleObjectId);
@@ -499,19 +513,35 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 }
                 flowResult.setSuccess(true);
                 return flowResult;
+
             case POST:
-                List<SysUser> userList = sysUserService.getListByPostId(handleObjectId);
-                if (userList.size() == 0) {
+                List<SysUser> postUserList = sysUserService.getListByPostId(handleObjectId);
+                if (postUserList.size() == 0) {
                     throw new ServiceException("岗位无用户");
                 }
-                if (userList.size() == 1) {
+                if (postUserList.size() == 1) {
+                    flowResult.setSuccess(true);
+                    flowResult.setUserId(postUserList.get(0).getUserId());
+                    return flowResult;
+                }
+                flowResult.setSuccess(false);
+                flowResult.setUserList(postUserList);
+                return flowResult;
+
+            case ROLE:
+                List<SysUser> roleUserList = sysUserService.getListByRoleId(handleObjectId);
+                if (roleUserList.size() == 0) {
+                    throw new ServiceException("角色无用户");
+                }
+                if (roleUserList.size() == 1) {
                     flowResult.setSuccess(true);
-                    flowResult.setUserId(userList.get(0).getUserId());
+                    flowResult.setUserId(roleUserList.get(0).getUserId());
                     return flowResult;
                 }
                 flowResult.setSuccess(false);
-                flowResult.setUserList(userList);
+                flowResult.setUserList(roleUserList);
                 return flowResult;
+
             default:
                 throw new ServiceException("未知用户处理类型:" + handleObjectType);
         }
@@ -532,4 +562,31 @@ public class FlowProcessServiceImpl implements FlowProcessService {
         }
     }
 
+    /**
+     * 模板替换
+     *
+     * <p>
+     * templateStr: ${Integer.parseInt(a)+1};  ${a+1};  ${b.tt};  ${b.vv};  ${b.vv[0]};
+     * map:         {a: "1", b: {tt: "t", vv: ["aa", "bb", "cc"] }}
+     * result:      2;  11;  t;  ["aa","bb","cc"];  aa;
+     *
+     * @param templateStr 模板字符串
+     * @param map         替换参数
+     * @return 替换后的字符串
+     */
+    private static String templateParse(String templateStr, Map<String, Object> map) {
+        Pattern pattern = Pattern.compile("\\$\\{(.*?)}");
+        Matcher matcher = pattern.matcher(templateStr);
+        StringBuffer sr = new StringBuffer();
+        while (matcher.find()) {
+            String group = matcher.group().replace("$", "");
+            Object execute = AviatorEvaluator.compile(group).execute(map);
+            if (execute != null) {
+                matcher.appendReplacement(sr, execute.toString());
+            }
+        }
+        matcher.appendTail(sr);
+        return sr.toString();
+    }
+
 }

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

@@ -130,4 +130,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
 
     List<SysUser> getListByPostId(Long postId);
 
+    List<SysUser> getListByRoleId(Long roleId);
+
 }

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

@@ -216,8 +216,15 @@ public interface ISysUserService extends IService<SysUser> {
     /**
      * 根据岗位id获取用户列表
      *
-     * @param postId
+     * @param postId 角色id
      */
     List<SysUser> getListByPostId(Long postId);
 
+    /**
+     * 根据角色id获取用户列表
+     *
+     * @param roleId 用户id
+     */
+    List<SysUser> getListByRoleId(Long roleId);
+
 }

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

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

+ 105 - 74
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -4,20 +4,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.system.mapper.SysUserMapper">
 
-    <resultMap type="SysUser" id="SysUserResult">
-        <id     property="userId"       column="user_id"      />
-        <result property="deptId"       column="dept_id"      />
-        <result property="userName"     column="user_name"    />
-        <result property="nickName"     column="nick_name"    />
-        <result property="email"        column="email"        />
-        <result property="phonenumber"  column="phonenumber"  />
-        <result property="sex"          column="sex"          />
-        <result property="avatar"       column="avatar"       />
-        <result property="password"     column="password"     />
-        <result property="status"       column="status"       />
-        <result property="delFlag"      column="del_flag"     />
-        <result property="loginIp"      column="login_ip"     />
-        <result property="loginDate"    column="login_date"   />
+	<resultMap type="SysUser" id="SysUserResult">
+		<id property="userId" column="user_id"/>
+		<result property="deptId" column="dept_id"/>
+		<result property="userName" column="user_name"/>
+		<result property="nickName" column="nick_name"/>
+		<result property="email" column="email"/>
+		<result property="phonenumber" column="phonenumber"/>
+		<result property="sex" column="sex"/>
+		<result property="avatar" column="avatar"/>
+		<result property="password" column="password"/>
+		<result property="status" column="status"/>
+		<result property="delFlag" column="del_flag"/>
+		<result property="loginIp" column="login_ip"/>
+		<result property="loginDate" column="login_date"/>
         <result property="createBy"     column="create_by"    />
         <result property="createTime"   column="create_time"  />
         <result property="updateBy"     column="update_by"    />
@@ -189,73 +189,104 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         and del_flag = '0'
         limit 1
     </select>
-	
+
 	<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
-		select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
+		select user_id, phonenumber
+		from sys_user
+		where phonenumber = #{phonenumber}
+		  and del_flag = '0'
+		limit 1
 	</select>
-	
+
 	<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
-		select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
+		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>
+		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.user_id
+		where sup.post_id = #{postId}
+	</select>
+
+	<select id="getListByRoleId" 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_role sur
+				 inner join sys_user u on sur.user_id = u.user_id
+		where sur.role_id = #{roleId}
+	</select>
 
 	<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
- 		insert into sys_user(
- 			<if test="userId != null and userId != 0">user_id,</if>
- 			<if test="deptId != null and deptId != 0">dept_id,</if>
- 			<if test="userName != null and userName != ''">user_name,</if>
- 			<if test="nickName != null and nickName != ''">nick_name,</if>
- 			<if test="email != null and email != ''">email,</if>
- 			<if test="avatar != null and avatar != ''">avatar,</if>
- 			<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
- 			<if test="sex != null and sex != ''">sex,</if>
- 			<if test="password != null and password != ''">password,</if>
- 			<if test="status != null and status != ''">status,</if>
- 			<if test="createBy != null and createBy != ''">create_by,</if>
- 			<if test="remark != null and remark != ''">remark,</if>
- 			<if test="tenantId != null and tenantId != ''">tenant_id,</if>
- 			<if test="userType != null and userType != ''">user_type,</if>
- 			<if test="jobNumber != null and jobNumber != ''">job_number,</if>
- 			create_time
- 		)values(
- 			<if test="userId != null and userId != ''">#{userId},</if>
- 			<if test="deptId != null and deptId != ''">#{deptId},</if>
- 			<if test="userName != null and userName != ''">#{userName},</if>
- 			<if test="nickName != null and nickName != ''">#{nickName},</if>
- 			<if test="email != null and email != ''">#{email},</if>
- 			<if test="avatar != null and avatar != ''">#{avatar},</if>
- 			<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
- 			<if test="sex != null and sex != ''">#{sex},</if>
- 			<if test="password != null and password != ''">#{password},</if>
- 			<if test="status != null and status != ''">#{status},</if>
- 			<if test="createBy != null and createBy != ''">#{createBy},</if>
- 			<if test="remark != null and remark != ''">#{remark},</if>
- 			<if test="tenantId != null and tenantId != ''">#{tenantId},</if>
- 			<if test="userType != null and userType != ''">#{userType},</if>
- 			<if test="jobNumber != null and jobNumber != ''">#{jobNumber},</if>
- 			sysdate()
- 		)
+		insert into sys_user(
+		<if test="userId != null and userId != 0">user_id,</if>
+		<if test="deptId != null and deptId != 0">dept_id,</if>
+		<if test="userName != null and userName != ''">user_name,</if>
+		<if test="nickName != null and nickName != ''">nick_name,</if>
+		<if test="email != null and email != ''">email,</if>
+		<if test="avatar != null and avatar != ''">avatar,</if>
+		<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
+		<if test="sex != null and sex != ''">sex,</if>
+		<if test="password != null and password != ''">password,</if>
+		<if test="status != null and status != ''">status,</if>
+		<if test="createBy != null and createBy != ''">create_by,</if>
+		<if test="remark != null and remark != ''">remark,</if>
+		<if test="tenantId != null and tenantId != ''">tenant_id,</if>
+		<if test="userType != null and userType != ''">user_type,</if>
+		<if test="jobNumber != null and jobNumber != ''">job_number,</if>
+		create_time
+		)values(
+		<if test="userId != null and userId != ''">#{userId},</if>
+		<if test="deptId != null and deptId != ''">#{deptId},</if>
+		<if test="userName != null and userName != ''">#{userName},</if>
+		<if test="nickName != null and nickName != ''">#{nickName},</if>
+		<if test="email != null and email != ''">#{email},</if>
+		<if test="avatar != null and avatar != ''">#{avatar},</if>
+		<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
+		<if test="sex != null and sex != ''">#{sex},</if>
+		<if test="password != null and password != ''">#{password},</if>
+		<if test="status != null and status != ''">#{status},</if>
+		<if test="createBy != null and createBy != ''">#{createBy},</if>
+		<if test="remark != null and remark != ''">#{remark},</if>
+		<if test="tenantId != null and tenantId != ''">#{tenantId},</if>
+		<if test="userType != null and userType != ''">#{userType},</if>
+		<if test="jobNumber != null and jobNumber != ''">#{jobNumber},</if>
+		sysdate()
+		)
 	</insert>
 	
 	<update id="updateUser" parameterType="SysUser">