Explorar o código

流程添加SQL表达式节点

yzc hai 1 ano
pai
achega
fbfaa4c09e

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

@@ -19,6 +19,7 @@ public enum HandleObjectTypeEnum {
     PARALLEL(6, "动态用户"),
     DEPT_MANAGER(8, "职级"),
     BUSINESS_USER(9, "用户表达式"),
+    SQL_EXPRESSION(10,"SQL表达式")
     ;
 
     private final Integer key;

+ 25 - 0
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowProcessServiceImpl.java

@@ -35,6 +35,9 @@ import com.ruoyi.system.service.ISysDeptService;
 import com.ruoyi.system.service.ISysUserIdentityService;
 import com.ruoyi.system.service.ISysUserService;
 import lombok.extern.slf4j.Slf4j;
+import net.sf.jsqlparser.JSQLParserException;
+import net.sf.jsqlparser.parser.CCJSqlParserUtil;
+import net.sf.jsqlparser.statement.select.Select;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -1071,6 +1074,28 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 flowResult.setSuccess(true);
                 flowResult.setUserId(userId);
                 return flowResult;
+            case SQL_EXPRESSION:
+                String jumpCondition = templateParse(node.getJumpCondition(), FlowThreadLocalUtil.getTemplateData());
+                try {
+                    if (!(CCJSqlParserUtil.parse(jumpCondition) instanceof Select)) {
+                        throw new ServiceException("非法表达式");
+                    }
+                } catch (JSQLParserException e) {
+                    log.error("表达式解析异常:" + e.getMessage(), e);
+                    throw new ServiceException("表达式解析失败:" + e.getMessage());
+                }
+                List<SysUser> userList = sysUserService.list(Wrappers.<SysUser>query().apply("user_id in (" + jumpCondition + ")"));
+                if (ObjectUtil.isEmpty(userList)) {
+                    throw new ServiceException("节点表达式结果无用户!");
+                }
+                if (userList.size() == 1) {
+                    flowResult.setSuccess(true);
+                    flowResult.setUserId(String.valueOf(userList.get(0).getUserId()));
+                    return flowResult;
+                }
+                flowResult.setSuccess(false);
+                flowResult.setUserList(userList);
+                return flowResult;
 
             default:
                 throw new ServiceException("未知用户处理类型:" + handleObjectType);