P3-1/2: 新建 flowable-service 独立工作流服务 + 移植 3 个表达式 handler

- 新模块 flowable-service(单客户交付四进程之一,可执行 jar,端口 8089):
  Flowable 6.8.1 引擎(连 eip4flow.eip3,databaseSchemaUpdate=false 严禁自动改表)
  + v5 兼容层 + 双数据源(ACT_ 本地 + 业务组织库客户库只读)
- 3 个 handler 按原包名移植经 cfg.setBeans 注册:CandidateUsersHandler(4761 处)/
  MultiInstanceUsersHandler(33 处会签)/WfContextService(175 处)
- 组织服务全闭包裁剪为 OrgDirectory 窄接口 + OrgDirectoryJdbc 直查业务组织库 SQL
  (逐条对齐 framework AssignmentHandlerImpl/UserFindServiceImpl/OrganizationServiceImpl),
  不拖入保真层元数据引擎;OSGi 取 bean → WfBeanRegistry(§3.1/§5.17 替换类策略);
  com.dsasp.* 零反向依赖 com.eip4(ArchUnit 纪律保持)
- REST 薄封装:待办/已办/发起/办理/挂起激活/委托 + OpenAPI;挂起拒办映射 409
- 26 单测绿;全反应堆 mvn test + ArchUnit 绿
- 实测验证(6.8.1.0 真实迁移数据):1509 定义加载、3 个真实 position 表达式解析
  与客户库组织 SQL 一致、待办口径双向对账(4=4/12=12)、挂起拒办回归、委托语义、会签解析;
  写测试全部可逆还原(act_ru_task 总数 9321 不变)
- 5 个 scriptTask 静态核对:全为 Activiti Explorer demo/report 残留,只读零写库
- 报告 flowable-service/P3流程服务实测报告.md;手册新增 §6.5/§6.6/§6.7 坑位

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 14:40:51 +08:00
parent 3b59e90504
commit 6ced9b15f2
26 changed files with 2161 additions and 1 deletions

View File

@@ -0,0 +1,74 @@
package com.dsasp.server.wf.bean;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
/**
* 候选人表达式 JSON 解析器。移植自 framework com.dsasp.server.wf.bean.BasePropertiesConverter,
* <b>仅保留引擎运行期候选人解析所用的两个方法</b>({@link #readTree} / {@link #convertToUserProperties})
* 与相关常量,逐字节一致。
*
* <p>原版另含 {@code updateTaskPropToBpmnModel/parserUserPropertiesExpress/...} 等
* <b>设计期</b> BPMN 模型编辑方法,依赖 {@code org.activiti.bpmn.model.*}(设计器侧类,
* 不在 Flowable 引擎运行时 classpath 上),且独立工作流服务只负责<b>执行</b>已部署定义、
* 不在服务内重编辑 BPMN——故移植时省略,不影响候选人解析行为(该半段从不在 getCandidateUsers 链路调用)。
* 省略事实登记于 P3 报告「handler 依赖闭包」一节。</p>
*/
public class BasePropertiesConverter {
public static final String TYPE = "type";
public static final String ITEMES = "items";
public static final String CONTENT = "content";
public static final String ISSENDMAIL = "isSendMail";
public static final String ISSENDPHONE = "isSendPhone";
public static final String ISSENDMESSAGE = "isSendMessage";
public static final String ISCANDIDATE = "isCandidate";
public static final String ISSKIPINITIATOR = "isSkipInitiator";
public static final String ISSKIPBEFORETASK = "isSkipBeforeTask";
public static final String ISNOUSERSKIP = "isNoUserSkip";
public static final String MESSAGETEMPLATE = "messageTemplate";//消息模板
public static final String TASKSUCCESSSERVICE = "taskSuccessService";//任务完成后执行的服务
public static final String CANDIDATESERVICE = "${candidateUsersHandler.getCandidateUsers(execution,'";
public static final String MULTIINSTANCESERVICE = "${multiInstanceUsersHandler.getUsers(execution,'";
public static final String DUEDATESERVICE = "${dueDateService.getDueDate(execution,";
public static JsonNode readTree(String content) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readTree(content);
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
public static List<UserProperty> convertToUserProperties(JsonNode node){
// JsonNode node = readTree(expression);
ArrayList<UserProperty> list = new ArrayList<UserProperty>();
if(node == null)
return list;
JsonNode jsonArray = node.get(ITEMES);
for(JsonNode userNode : jsonArray){
JsonNode type = userNode.get(TYPE);
JsonNode content = userNode.get(CONTENT);
JsonNode isSendMail = userNode.get(ISSENDMAIL);
JsonNode isSendPhone = userNode.get(ISSENDPHONE);
JsonNode isSendMessage = userNode.get(ISSENDMESSAGE);
JsonNode isCandidate = userNode.get(ISCANDIDATE);
UserProperty userProperty = new UserProperty();
userProperty.setCandidate(isCandidate.asBoolean());
if(isSendMessage != null){
userProperty.setSendMessage(isSendMessage.asBoolean());
}
userProperty.setSendMail(isSendMail.asBoolean());
userProperty.setSendPhone(isSendPhone.asBoolean());
userProperty.setContent(content.asText());
userProperty.setType(type.asText());
list.add(userProperty);
}
return list;
}
}

View File

@@ -0,0 +1,54 @@
package com.dsasp.server.wf.bean;
/**
* 候选人配置项 bean。原样移植自 framework com.dsasp.server.wf.bean.UserProperty
* (com.dsasp.server.wf 模块),一字段不增删,保证候选人表达式解析行为逐字节一致。
*/
public class UserProperty {
private String type;
private String content;
private boolean isCandidate;
private boolean isSendMail;
private boolean isSendPhone;
private boolean isSendMessage;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getContent() {
return content;
}
public void setContent(String content) {
if("null".equals(content)){
content = null;
}
this.content = content;
}
public boolean isCandidate() {
return isCandidate;
}
public void setCandidate(boolean isCandidate) {
this.isCandidate = isCandidate;
}
public boolean isSendMail() {
return isSendMail;
}
public void setSendMail(boolean isSendMail) {
this.isSendMail = isSendMail;
}
public boolean isSendPhone() {
return isSendPhone;
}
public void setSendPhone(boolean isSendPhone) {
this.isSendPhone = isSendPhone;
}
public boolean isSendMessage() {
return isSendMessage;
}
public void setSendMessage(boolean isSendMessage) {
this.isSendMessage = isSendMessage;
}
}

View File

@@ -0,0 +1,69 @@
package com.dsasp.server.wf.service;
import com.dsasp.server.wf.support.WfBeanRegistry;
/**
* 流程上下文服务,BPMN 表达式 {@code ${wfContextService.xxx(...)}} 入口。
*
* <p>移植自 framework {@code com.dsasp.server.wf.service.WfContextService}
* (com.dsasp.server.wf 模块,被 175 处引用,手册 §6.3)。
* 经 {@code ProcessEngineConfiguration.setBeans} 以 bean 名 {@code wfContextService} 注册。</p>
*
* <p><b>独立服务边界(行为登记于 P3 报告):</b></p>
* <ul>
* <li>{@link #getOrgByDepartId}:经 {@link com.dsasp.server.wf.support.OrgDirectory}
* 直查业务组织库(view_depart_tree),与原版 OrganizationService 同 SQL,<b>已实现</b>。</li>
* <li>{@link #getValue}/{@link #getDisplayValue}/{@link #excuteServiceFlow}:原版依赖保真层
* {@code POJOCRUDService}(业务表 CRUD)与 {@code FlowExcuteService}(服务流引擎),
* 两者都在 <b>eip4-platform.jar</b>(保真层引擎所在进程),不在本独立服务内
* (架构第三节:引擎在独立服务、保真层在平台进程,职责分离)。本服务内 WARN 降级返回 null;
* 生产形态由 platform-flow-gateway/platform 经回调或同进程装配补齐(P3-4 聚合任务),报告登记。</li>
* </ul>
*/
public class WfContextService {
/**
* 根据部门ID获取组织ID。
*/
public String getOrgByDepartId(String departId){
return WfBeanRegistry.orgDirectory().getOrgIdByDepartId(departId);
}
/**
* 获取指定记录属性值。原版经 POJOCRUDService.loadPOJO 取保真层业务表记录;
* 该引擎在 eip4-platform.jar,独立工作流服务不内置,WARN 降级。
*/
public Object getValue(String businessKey,String tableName,String columnName){
System.out.println("[WARN] wfContextService.getValue 依赖保真层 POJOCRUDService(在 eip4-platform.jar),"
+ "独立工作流服务未内置,返回 null。businessKey=" + businessKey + " table=" + tableName + " col=" + columnName);
return null;
}
/**
* 获取指定记录属性显示值。同 {@link #getValue},WARN 降级。
*/
public Object getDisplayValue(String businessKey,String tableName,String columnName){
System.out.println("[WARN] wfContextService.getDisplayValue 依赖保真层 POJOCRUDService(在 eip4-platform.jar),"
+ "独立工作流服务未内置,返回 null。businessKey=" + businessKey + " table=" + tableName + " col=" + columnName);
return null;
}
/**
* 执行指定服务流。原版经 FlowExcuteService.excute 调保真层服务流引擎;
* 该引擎在 eip4-platform.jar,独立工作流服务不内置,WARN 降级。
*/
public Object excuteServiceFlow(String businessKey,String tableName,String flowId){
System.out.println("[WARN] wfContextService.excuteServiceFlow 依赖保真层服务流引擎(在 eip4-platform.jar),"
+ "独立工作流服务未内置,返回 null。flowId=" + flowId);
return null;
}
/**
* 执行指定服务流(带 execution)。同上,WARN 降级。
*/
public Object excuteServiceFlow(Object execution,String businessKey,String tableName,String flowId){
System.out.println("[WARN] wfContextService.excuteServiceFlow(execution) 依赖保真层服务流引擎(在 eip4-platform.jar),"
+ "独立工作流服务未内置,返回 null。flowId=" + flowId);
return null;
}
}

View File

@@ -0,0 +1,53 @@
package com.dsasp.server.wf.support;
import java.util.List;
/**
* 候选人解析所需的「业务组织目录」窄接口。
*
* <p>这是独立 Flowable 服务对 framework 保真层
* {@code com.dsasp.server.common.user.service.AssignmentHandler} +
* {@code UserFindService} + {@code OrganizationService} 三件套的<b>裁剪替身</b>:
* 只暴露候选人/会签解析真正用到的方法,实现走直查业务组织库的 SQL
* (见 {@code com.eip4.flowservice.org.OrgDirectoryJdbc}),
* <b>不把整个 com.dsasp.server.organize 引擎(POJOCRUDService/GeneralPOJO/元数据层)
* 拖进独立进程</b>(任务纪律:优先直查业务 schema,避免组织服务全闭包)。</p>
*
* <p>放在 com.dsasp 包下,使移植的 handler 仅依赖本接口、不反向 import com.eip4
* (ArchUnit「保真层禁止依赖现代层」纪律)。运行期实例由
* {@code cfg.setBeans} 注册并经 {@link WfBeanRegistry} 取用,
* 等价 framework 原版的 {@code SpringBeanOsgiServices.getBeanByName} 间接(手册 §3.1 替换类策略)。</p>
*/
public interface OrgDirectory {
/**
* 解析单条候选人配置项为用户 id 列表。
*
* <p>对齐 framework {@code AssignmentHandlerImpl.assignmentUser(type, content, initiatorId, initiatorDepartId)}
* 的分派语义(见手册 §6.3 candidateUsersHandler 引用 4,761 处)。</p>
*
* @param type 配置类型(user/roles/depart/position/initiator/...,
* 见 framework ProcessDefinitionService 常量)
* @param content 配置内容(逗号分隔的 id 串,或脚本/维度等)
* @param initiatorId 发起人 id(部分类型需要),可为 null
* @param initiatorDepart 发起人所属部门 id(部分类型需要),可为 null
* @return 用户 id 列表,永不为 null
*/
List<String> assignmentUser(String type, String content, String initiatorId, String initiatorDepart);
/**
* 项目角色("八大员"等项目内角色)候选人解析。
*
* <p>对齐 framework {@code ProjectRoleUser.getUserByProjectRole}。
* framework 内无通用实现(项目定制扩展),本服务默认返回空并 WARN,
* 客户私有化时按其 ProjectRoleUser 实现接入。</p>
*/
List<String> getUsersByProjectRole(String projectId, String roleContent);
/**
* 部门 id → 组织(公司)id。对齐 framework
* {@code OrganizationService.getOrgIdByDepartId}(经 view_depart_tree 查)。
* 供 {@code wfContextService.getOrgByDepartId} 使用。
*/
String getOrgIdByDepartId(String departId);
}

View File

@@ -0,0 +1,36 @@
package com.dsasp.server.wf.support;
/**
* 移植 handler 取协作 bean 的入口。
*
* <p>framework 原版 {@code CandidateUsersHandler} 经
* {@code SpringBeanOsgiServices.getInstance().getBeanByName("assignmentHandler")} 取依赖
* (手册 §5.17:OSGi 服务注册/发现);独立服务无 OSGi 容器,本类是其等价替换
* (手册 §3.1「替换类清单」同款策略):由现代层装配时 {@link #setOrgDirectory} 注入,
* handler 侧 {@link #orgDirectory()} 取用,handler 因此不反向依赖 com.eip4。</p>
*/
public final class WfBeanRegistry {
private static volatile OrgDirectory orgDirectory;
private WfBeanRegistry() {
}
public static void setOrgDirectory(OrgDirectory directory) {
orgDirectory = directory;
}
/**
* @return 组织目录实现;未注入时抛错(暴露装配遗漏,等价原版 getBeanByName 取空 NPE,
* 但信息更明确)。
*/
public static OrgDirectory orgDirectory() {
OrgDirectory d = orgDirectory;
if (d == null) {
throw new IllegalStateException(
"OrgDirectory 未注册:flowable-service 装配阶段须 WfBeanRegistry.setOrgDirectory(...) "
+ "(等价 framework SpringBeanOsgiServices 注册 assignmentHandler/userFindService)");
}
return d;
}
}

View File

@@ -0,0 +1,39 @@
package com.dsasp.server.wf.support;
/**
* 候选人配置类型常量 + 流程变量名常量。
*
* <p>逐字节移植自 framework
* {@code com.dsasp.server.common.workflow.service.ProcessDefinitionService}(配置类型)
* 与 {@code ProcessCoreService}(流程变量名),使移植 handler 的分派语义与原版一致;
* 集中到本类避免再拖入 framework workflow 服务模块的接口闭包。</p>
*/
public final class WfTypes {
private WfTypes() {
}
// ===== 配置类型(ProcessDefinitionService) =====
public static final String USER = "user";
public static final String ROLES = "roles";
public static final String DEPART = "depart";
public static final String POSITION = "position";
public static final String INITIATOR = "initiator";
public static final String INITIATORDEPARTMANAGER = "initiatorDepartManager";
public static final String INITIATORLEADER = "initiatorLeader";
public static final String INITIATORSUBORDINATE = "initiatorSubordinate";
public static final String INITIATORDEPART = "initiatorDepart";
public static final String SAMETOTASK = "sameToTask";
public static final String BEFORETASKLEADER = "beforeTaskLeader";
public static final String BEFORETASKDEPARTMANAGER = "beforeTaskDepartManager";
public static final String FIXEDDIMENSION = "fixedDimension";
public static final String FORMSPECIFIEDDIMENSION = "formSpecifiedDimension";
public static final String PROJECTROLETYPE = "projectRoleType";
public static final String SCRIPTUSER = "scriptUser";
// ===== 流程变量名(ProcessCoreService) =====
public static final String INITIATORUSERID = "WFINITIATORUSERID";
public static final String INITIATORDEPARTID = "WFINITIATORDEPARTID";
public static final String PROCESSTITLE = "PROCESSTITLE";
public static final String PROJECTID = "PROJECTID";
}

View File

@@ -0,0 +1,157 @@
package com.dsasp.server.wf.user.assignee;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.JsonNode;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.RuntimeService;
import com.dsasp.server.wf.bean.BasePropertiesConverter;
import com.dsasp.server.wf.bean.UserProperty;
import com.dsasp.server.wf.support.OrgDirectory;
import com.dsasp.server.wf.support.WfBeanRegistry;
import com.dsasp.server.wf.support.WfTypes;
/**
* 候选人表达式 handler。
*
* <p>移植自 framework {@code com.dsasp.server.wf.user.assignee.CandidateUsersHandler}
* (com.dsasp.server.wf 模块,被 1,509 个 BPMN 里 4,761 处
* {@code ${candidateUsersHandler.getCandidateUsers(execution,'...')}} 引用,手册 §6.3)。
* 经 {@code ProcessEngineConfiguration.setBeans} 以 bean 名 {@code candidateUsersHandler} 注册。</p>
*
* <p><b>对 framework 原版的两处工程化适配(行为登记于 P3 报告):</b></p>
* <ol>
* <li>OSGi 解依赖:{@code SpringBeanOsgiServices.getBeanByName("assignmentHandler"/"processCoreService"/...)}
* → {@link WfBeanRegistry#orgDirectory()}(独立服务无 OSGi 容器,手册 §3.1/§5.17 替换类策略);
* 候选人解析的真实 SQL 改直查业务组织库,不拖入 com.dsasp.server.organize 引擎全闭包。</li>
* <li>activiti API → Flowable API:{@code ProcessEngines.getDefaultProcessEngine()} 取流程变量;
* {@code execution} 形参放宽为 {@code Object}(v5 兼容层与 v6 的 Execution 类型不同,
* 仅用其 processInstanceId,经引擎运行时反查,避免对实现类的硬转型,与 PoC 桩同口径)。</li>
* </ol>
*
* <p><b>当前未接入的分支(WARN 降级,报告登记):</b>{@code scriptUser}(JUEL 脚本,26 处,
* 需服务流脚本引擎,超独立服务精简边界)、{@code agentService} 代理人替换后处理(项目定制扩展)。
* 占主导的 user/position/depart/formSpecifiedDimension/initiator 等类型(实测分布见报告)全部覆盖。</p>
*/
public class CandidateUsersHandler {
public List<String> getCandidateUsers(Object execution, String expression){
String processInstanceId = resolveProcessInstanceId(execution);
//FIXME: json text(原版注释保留)
JsonNode node = BasePropertiesConverter.readTree(expression.replace("【", "{").replace("】", "}"));
List<UserProperty> userProperties = BasePropertiesConverter
.convertToUserProperties(node);
List<String> list = new ArrayList<String>();
List<String> phoneList = new ArrayList<String>();
List<String> emailList = new ArrayList<String>();
List<String> messageList = new ArrayList<String>();
String initiatorId = null;
String initiatorDepartId = null;
RuntimeService runtimeService = resolveRuntimeService();
String projectId = (String) getVariable(runtimeService, processInstanceId, WfTypes.PROJECTID);
OrgDirectory directory = WfBeanRegistry.orgDirectory();
if(userProperties != null){
for(UserProperty userProperty : userProperties){
List<String> users = null;
if(WfTypes.SAMETOTASK.equals(userProperty.getType())
|| WfTypes.BEFORETASKLEADER.equals(userProperty.getType())
|| WfTypes.BEFORETASKDEPARTMANAGER.equals(userProperty.getType())){
// 原版经 processCoreService.getSpecialActivityProcessor(前一活动处理者)解析;
// 该解析依赖历史活动栈遍历(framework ProcessCoreServiceImpl),
// 独立服务暂不接入(WARN 降级),报告登记。占比小(sameTo­Task 5 处)。
System.out.println("[WARN] candidateUsersHandler: 类型 " + userProperty.getType()
+ " 依赖前序活动处理者解析,独立服务暂未接入,跳过该项");
users = new ArrayList<String>();
}else if(WfTypes.SCRIPTUSER.equals(userProperty.getType())){
// 原版经 ScriptingEngines.evaluate(content,"juel",execution) 求值;
// 独立服务不内置服务流脚本引擎(精简边界),WARN 降级,报告登记。
System.out.println("[WARN] candidateUsersHandler: scriptUser(JUEL 脚本)分支独立服务暂未接入,跳过该项");
users = new ArrayList<String>();
}else if(WfTypes.PROJECTROLETYPE.equals(userProperty.getType())){
users = directory.getUsersByProjectRole(projectId, userProperty.getContent());
}
else{
if(isEmpty(initiatorId)){
initiatorId = (String) getVariable(runtimeService, processInstanceId, WfTypes.INITIATORUSERID);
}
if(isEmpty(initiatorDepartId)){
initiatorDepartId = (String) getVariable(runtimeService, processInstanceId, WfTypes.INITIATORDEPARTID);
}
users = directory.assignmentUser(userProperty.getType(), userProperty.getContent(), initiatorId, initiatorDepartId);
}
if(users != null && users.size() > 0){
if(userProperty.isCandidate()){
list.addAll(users);
}
if(userProperty.isSendMail()){
emailList.addAll(users);
}
if(userProperty.isSendPhone()){
phoneList.addAll(users);
}
if(userProperty.isSendMessage()){
messageList.addAll(users);
}
}
}
}
// 原版此处经 agentService.agent(list,...) 做代理人(委托/出差代办)替换后处理;
// agentService 是项目定制扩展(framework AgentServiceImpl 依赖代理表),
// 独立服务暂不接入,直接返回原始候选人 list,报告登记。
return list;
}
/** 从 v5/v6 Execution 或字符串 id 中取流程实例 id,不硬转型实现类。 */
protected String resolveProcessInstanceId(Object execution) {
if (execution == null) {
return null;
}
if (execution instanceof String) {
return (String) execution;
}
// v5 org.activiti.engine.runtime.Execution / v6 org.flowable.engine.runtime.Execution
// 均有 getProcessInstanceId();反射调用避免对具体 API 版本的编译期耦合。
try {
Object pid = execution.getClass().getMethod("getProcessInstanceId").invoke(execution);
return pid != null ? pid.toString() : null;
} catch (Exception e) {
return null;
}
}
/** 取默认引擎的 RuntimeService;无默认引擎(如单测)时返回 null,后续按变量缺省处理。 */
protected RuntimeService resolveRuntimeService() {
try {
var engine = ProcessEngines.getDefaultProcessEngine();
return engine != null ? engine.getRuntimeService() : null;
} catch (Exception e) {
return null;
}
}
private Object getVariable(RuntimeService runtimeService, String processInstanceId, String name) {
if (runtimeService == null || processInstanceId == null) {
return null;
}
try {
return runtimeService.getVariable(processInstanceId, name);
} catch (Exception e) {
return null;
}
}
private static boolean isEmpty(String s) {
return s == null || s.trim().isEmpty();
}
/** 取当前发起人(可空),保留以兼容旧 call site;独立服务下经流程变量得到。 */
public static String currentInitiator() {
return Authentication.getAuthenticatedUserId();
}
}

View File

@@ -0,0 +1,21 @@
package com.dsasp.server.wf.user.assignee;
import java.util.List;
/**
* 会签(multiInstance)候选人表达式 handler。
*
* <p>移植自 framework {@code com.dsasp.server.wf.user.assignee.MultiInstanceUsersHandler}
* (extends {@link CandidateUsersHandler},被 33 处
* {@code ${multiInstanceUsersHandler.getUsers(execution,'...')}} 引用,手册 §6.3)。
* 经 {@code ProcessEngineConfiguration.setBeans} 以 bean 名 {@code multiInstanceUsersHandler} 注册。</p>
*
* <p>原版 {@code getUsers} 直接 {@code return super.getCandidateUsers(execution, expression)}
* (会签输入集合 = 候选人集合),逐字保留。execution 形参与父类一致放宽为 Object。</p>
*/
public class MultiInstanceUsersHandler extends CandidateUsersHandler {
public List<String> getUsers(Object execution, String expression){
return super.getCandidateUsers(execution, expression);
}
}

View File

@@ -0,0 +1,31 @@
package com.eip4.flowservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
/**
* Flowable 独立工作流服务启动器(单客户交付四进程之一:flowable-service.jar,端口 8089)。
*
* <p>排除三项自动装配,改手工接管:</p>
* <ul>
* <li>{@link DataSourceAutoConfiguration}:本服务手工装配双数据源
* (flowableDataSource + bizDataSource,见 {@code DataSourceConfig}),无 @Primary 单源;</li>
* <li>{@link DataSourceTransactionManagerAutoConfiguration}:事务由 Flowable 引擎内部管理;</li>
* <li>{@link LiquibaseAutoConfiguration}:Flowable 传递依赖带 liquibase,但本服务
* databaseSchemaUpdate=false、严禁自动改表(任务红线),不跑任何 schema 迁移。</li>
* </ul>
*/
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
LiquibaseAutoConfiguration.class
})
public class FlowableServiceApplication {
public static void main(String[] args) {
SpringApplication.run(FlowableServiceApplication.class, args);
}
}

View File

@@ -0,0 +1,94 @@
package com.eip4.flowservice.api;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dsasp.server.wf.support.OrgDirectory;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
* 候选人解析验证入口。
*
* <p>用于实测对账(P3 报告):给定候选人配置表达式(或挑一个真实待办的处理者来源类型/内容),
* 经移植 handler 同款 {@link OrgDirectory} 解析为用户 id 列表,与客户库组织数据对照 SQL 核对。</p>
*
* <p>这是验证/诊断口,非业务薄封装的一部分;直接解析单条配置项,绕过 BPMN 表达式串拼装,
* 便于对单一 type/content 精确对账。</p>
*/
@RestController
@RequestMapping("/api/flow/candidate")
@Tag(name = "候选人解析(验证)", description = "候选人配置解析为用户 id,与组织库对账")
public class CandidateController {
private final OrgDirectory orgDirectory;
private final TaskService taskService;
private final RuntimeService runtimeService;
private final RepositoryService repositoryService;
public CandidateController(OrgDirectory orgDirectory, TaskService taskService,
RuntimeService runtimeService, RepositoryService repositoryService) {
this.orgDirectory = orgDirectory;
this.taskService = taskService;
this.runtimeService = runtimeService;
this.repositoryService = repositoryService;
}
/** 单条配置项解析入参。 */
public static class ResolveRequest {
public String type;
public String content;
public String initiatorId;
public String initiatorDepart;
}
@PostMapping("/resolve")
@Operation(summary = "解析单条候选人配置", description = "type+content(+发起人/部门)→ 用户 id 列表(直查组织库)")
public List<String> resolve(@RequestBody ResolveRequest req) {
return orgDirectory.assignmentUser(req.type, req.content, req.initiatorId, req.initiatorDepart);
}
@GetMapping("/org-by-depart")
@Operation(summary = "部门→组织", description = "view_depart_tree 查公司 id,对账用")
public ResponseEntity<String> orgByDepart(String departId) {
String org = orgDirectory.getOrgIdByDepartId(departId);
return org != null ? ResponseEntity.ok(org) : ResponseEntity.notFound().build();
}
@GetMapping("/task-context")
@Operation(summary = "任务上下文", description = "给定 taskId,回显其流程实例的发起人/部门/项目变量,辅助候选人对账")
public Map<String, Object> taskContext(String taskId) {
Task t = taskService.createTaskQuery().taskId(taskId).singleResult();
if (t == null) {
return Map.of("error", "task not found: " + taskId);
}
String piId = t.getProcessInstanceId();
List<String> defKey = new ArrayList<>();
var def = repositoryService.createProcessDefinitionQuery()
.processDefinitionId(t.getProcessDefinitionId()).singleResult();
if (def != null) {
defKey.add(def.getKey());
}
Map<String, Object> vars = runtimeService.getVariables(piId);
return Map.of(
"taskId", taskId,
"taskName", t.getName() == null ? "" : t.getName(),
"assignee", t.getAssignee() == null ? "" : t.getAssignee(),
"processInstanceId", piId,
"processDefinitionKey", defKey.isEmpty() ? "" : defKey.get(0),
"variables", vars);
}
}

View File

@@ -0,0 +1,150 @@
package com.eip4.flowservice.api;
import java.util.List;
import java.util.stream.Collectors;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
/**
* 工作流 REST 入口(薄封装 Flowable API,不做语义改写)。
*
* <p>提供:待办列表(按用户/候选组)、已办、发起、办理(complete)、挂起/激活、委托(delegate)。
* 仅转调 Flowable 引擎服务,出参经 DTO 收敛,避免引擎内部类泄漏。</p>
*/
@RestController
@RequestMapping("/api/flow")
@Tag(name = "工作流", description = "Flowable 待办/已办/发起/办理/挂起激活/委托 薄封装")
public class FlowController {
private final TaskService taskService;
private final RuntimeService runtimeService;
private final HistoryService historyService;
private final RepositoryService repositoryService;
public FlowController(TaskService taskService, RuntimeService runtimeService,
HistoryService historyService, RepositoryService repositoryService) {
this.taskService = taskService;
this.runtimeService = runtimeService;
this.historyService = historyService;
this.repositoryService = repositoryService;
}
@GetMapping("/tasks/todo")
@Operation(summary = "待办列表", description = "按 assignee(用户)或 candidateGroup(候选组)查活动待办;不传则查全部活动待办")
public List<TaskDto> todo(
@RequestParam(required = false) String assignee,
@RequestParam(required = false) String candidateGroup,
@RequestParam(required = false) String candidateUser,
@RequestParam(defaultValue = "0") int firstResult,
@RequestParam(defaultValue = "50") int maxResults) {
var q = taskService.createTaskQuery().active();
if (assignee != null && !assignee.isBlank()) {
q = q.taskAssignee(assignee);
}
if (candidateGroup != null && !candidateGroup.isBlank()) {
q = q.taskCandidateGroup(candidateGroup);
}
if (candidateUser != null && !candidateUser.isBlank()) {
q = q.taskCandidateUser(candidateUser);
}
return q.orderByTaskCreateTime().desc()
.listPage(firstResult, maxResults)
.stream().map(TaskDto::of).collect(Collectors.toList());
}
@GetMapping("/tasks/todo/count")
@Operation(summary = "待办计数", description = "与 act_ru_task 直查对账用:按 assignee 计活动待办数")
public long todoCount(@RequestParam(required = false) String assignee) {
var q = taskService.createTaskQuery().active();
if (assignee != null && !assignee.isBlank()) {
q = q.taskAssignee(assignee);
}
return q.count();
}
@GetMapping("/tasks/done")
@Operation(summary = "已办列表", description = "按 assignee 查已完成的历史任务")
public List<TaskDto> done(
@RequestParam(required = false) String assignee,
@RequestParam(defaultValue = "0") int firstResult,
@RequestParam(defaultValue = "50") int maxResults) {
var q = historyService.createHistoricTaskInstanceQuery().finished();
if (assignee != null && !assignee.isBlank()) {
q = q.taskAssignee(assignee);
}
return q.orderByHistoricTaskInstanceEndTime().desc()
.listPage(firstResult, maxResults)
.stream().map(TaskDto::of).collect(Collectors.toList());
}
@PostMapping("/process/start")
@Operation(summary = "发起流程", description = "按 processDefinitionKey 或 processDefinitionId 发起,可带 businessKey 与变量")
public ResponseEntity<ProcessInstanceDto> start(@RequestBody Requests.StartRequest req) {
ProcessInstance pi;
if (req.processDefinitionId != null && !req.processDefinitionId.isBlank()) {
pi = runtimeService.startProcessInstanceById(req.processDefinitionId, req.businessKey, req.variables);
} else if (req.processDefinitionKey != null && !req.processDefinitionKey.isBlank()) {
pi = runtimeService.startProcessInstanceByKey(req.processDefinitionKey, req.businessKey, req.variables);
} else {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(ProcessInstanceDto.of(pi));
}
@PostMapping("/tasks/{taskId}/complete")
@Operation(summary = "办理任务", description = "complete 任务,可带提交变量。挂起实例的任务会被引擎拒绝(语义回归)")
public ResponseEntity<Void> complete(@PathVariable String taskId, @RequestBody(required = false) Requests.CompleteRequest req) {
if (req != null && req.variables != null) {
taskService.complete(taskId, req.variables);
} else {
taskService.complete(taskId);
}
return ResponseEntity.noContent().build();
}
@PostMapping("/process/{processInstanceId}/suspend")
@Operation(summary = "挂起实例", description = "挂起后该实例任务不可办理")
public ResponseEntity<Void> suspend(@PathVariable String processInstanceId) {
runtimeService.suspendProcessInstanceById(processInstanceId);
return ResponseEntity.noContent().build();
}
@PostMapping("/process/{processInstanceId}/activate")
@Operation(summary = "激活实例", description = "解除挂起,恢复可办理")
public ResponseEntity<Void> activate(@PathVariable String processInstanceId) {
runtimeService.activateProcessInstanceById(processInstanceId);
return ResponseEntity.noContent().build();
}
@PostMapping("/tasks/{taskId}/delegate")
@Operation(summary = "委托任务", description = "委托给指定用户:assignee 变为受托人,owner 记原办理人")
public ResponseEntity<TaskDto> delegate(@PathVariable String taskId, @RequestBody Requests.DelegateRequest req) {
if (req == null || req.delegateUserId == null || req.delegateUserId.isBlank()) {
return ResponseEntity.badRequest().build();
}
taskService.delegateTask(taskId, req.delegateUserId);
var t = taskService.createTaskQuery().taskId(taskId).singleResult();
return ResponseEntity.ok(t != null ? TaskDto.of(t) : null);
}
@GetMapping("/process-definitions/count")
@Operation(summary = "流程定义计数", description = "启动后定义加载自检(预期 1,509)")
public long processDefinitionCount() {
return repositoryService.createProcessDefinitionQuery().count();
}
}

View File

@@ -0,0 +1,46 @@
package com.eip4.flowservice.api;
import java.util.Map;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* Flowable 引擎异常 → 干净 HTTP 状态映射(薄层 API 不把引擎栈泄漏给调用方)。
*
* <ul>
* <li>{@link FlowableObjectNotFoundException} → 404;</li>
* <li>"Cannot complete a suspended task" 等非法状态 → 409 Conflict
* (挂起实例拒绝办理的语义,见 P3 报告语义验证);</li>
* <li>其余 {@link FlowableException} → 400(多为入参/定义问题)。</li>
* </ul>
*/
@RestControllerAdvice
public class FlowExceptionHandler {
@ExceptionHandler(FlowableObjectNotFoundException.class)
public ResponseEntity<Map<String, Object>> notFound(FlowableObjectNotFoundException ex) {
return body(HttpStatus.NOT_FOUND, ex.getMessage());
}
@ExceptionHandler(FlowableException.class)
public ResponseEntity<Map<String, Object>> flowable(FlowableException ex) {
String msg = ex.getMessage() == null ? "" : ex.getMessage();
if (msg.contains("suspended")) {
// 挂起实例/任务的写操作:语义上是冲突,非服务端错误
return body(HttpStatus.CONFLICT, msg);
}
return body(HttpStatus.BAD_REQUEST, msg);
}
private ResponseEntity<Map<String, Object>> body(HttpStatus status, String message) {
return ResponseEntity.status(status).body(Map.of(
"status", status.value(),
"error", status.getReasonPhrase(),
"message", message == null ? "" : message));
}
}

View File

@@ -0,0 +1,26 @@
package com.eip4.flowservice.api;
import org.flowable.engine.runtime.ProcessInstance;
/**
* 流程实例 DTO(发起流程出参)。
*/
public class ProcessInstanceDto {
public String id;
public String processDefinitionId;
public String processDefinitionKey;
public String businessKey;
public boolean ended;
public boolean suspended;
public static ProcessInstanceDto of(ProcessInstance pi) {
ProcessInstanceDto d = new ProcessInstanceDto();
d.id = pi.getId();
d.processDefinitionId = pi.getProcessDefinitionId();
d.processDefinitionKey = pi.getProcessDefinitionKey();
d.businessKey = pi.getBusinessKey();
d.ended = pi.isEnded();
d.suspended = pi.isSuspended();
return d;
}
}

View File

@@ -0,0 +1,30 @@
package com.eip4.flowservice.api;
import java.util.Map;
/**
* REST 入参 DTO 集合(发起/办理/委托)。
*/
public final class Requests {
private Requests() {
}
/** 发起流程。processDefinitionKey 或 processDefinitionId 二选一。 */
public static class StartRequest {
public String processDefinitionKey;
public String processDefinitionId;
public String businessKey;
public Map<String, Object> variables;
}
/** 办理(complete)任务。 */
public static class CompleteRequest {
public Map<String, Object> variables;
}
/** 委托(delegate)任务。 */
public static class DelegateRequest {
public String delegateUserId;
}
}

View File

@@ -0,0 +1,48 @@
package com.eip4.flowservice.api;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
/**
* 待办/已办任务 DTO(REST 薄层出参,字段贴 Flowable Task,不做语义改写)。
*/
public class TaskDto {
public String id;
public String name;
public String assignee;
public String owner;
public String processInstanceId;
public String processDefinitionId;
public String taskDefinitionKey;
public Long createTimeMillis;
public Long endTimeMillis;
public boolean suspended;
public static TaskDto of(Task t) {
TaskDto d = new TaskDto();
d.id = t.getId();
d.name = t.getName();
d.assignee = t.getAssignee();
d.owner = t.getOwner();
d.processInstanceId = t.getProcessInstanceId();
d.processDefinitionId = t.getProcessDefinitionId();
d.taskDefinitionKey = t.getTaskDefinitionKey();
d.createTimeMillis = t.getCreateTime() != null ? t.getCreateTime().getTime() : null;
d.suspended = t.isSuspended();
return d;
}
public static TaskDto of(HistoricTaskInstance t) {
TaskDto d = new TaskDto();
d.id = t.getId();
d.name = t.getName();
d.assignee = t.getAssignee();
d.owner = t.getOwner();
d.processInstanceId = t.getProcessInstanceId();
d.processDefinitionId = t.getProcessDefinitionId();
d.taskDefinitionKey = t.getTaskDefinitionKey();
d.createTimeMillis = t.getCreateTime() != null ? t.getCreateTime().getTime() : null;
d.endTimeMillis = t.getEndTime() != null ? t.getEndTime().getTime() : null;
return d;
}
}

View File

@@ -0,0 +1,52 @@
package com.eip4.flowservice.config;
import javax.sql.DataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* 双数据源装配(架构第三节:独立服务连两个数据源)。
*
* <ul>
* <li><b>flowableDataSource</b>(ACT_ 引擎库):本地 eip4flow.eip3,Flowable 6.8.1 引擎用,
* databaseSchemaUpdate=false(严禁自动改表,见 FlowableEngineConfig)。</li>
* <li><b>bizDataSource</b>(业务组织库):客户库只读,候选人解析直查 SYS_* 组织表。
* 本地验证连 192.168.20.68:5435?currentSchema=eip3(ceshi 只读)。</li>
* </ul>
*
* <p>用 {@link DataSourceBuilder} + {@code spring.datasource} 风格属性绑定:
* {@code @ConfigurationProperties} 直接绑到 builder(而非 build 后的 Hikari 实例),
* 这样 {@code url}→{@code jdbcUrl} 的别名归一由 Boot 处理(否则 Hikari 报
* "jdbcUrl is required with driverClassName")。</p>
*
* <p><b>生产单库分 schema 形态</b>:两数据源指向<b>同库不同 schema</b>
* (ACT_ 在 flowable schema、业务表在 business schema),仅 JDBC URL 的 currentSchema 不同;
* 配置示意见 application.yml 注释与 P3 报告。</p>
*/
@Configuration
public class DataSourceConfig {
/** ACT_ 引擎库(Flowable)。前缀 flowable.datasource。 */
@Bean
@ConfigurationProperties(prefix = "flowable.datasource")
public DataSource flowableDataSource() {
return DataSourceBuilder.create().build();
}
/** 业务组织库(客户库只读)。前缀 biz.datasource。 */
@Bean
@ConfigurationProperties(prefix = "biz.datasource")
public DataSource bizDataSource() {
return DataSourceBuilder.create().build();
}
/** 业务组织库 JdbcTemplate(候选人解析直查用)。 */
@Bean
public JdbcTemplate bizJdbcTemplate(DataSource bizDataSource) {
return new JdbcTemplate(bizDataSource);
}
}

View File

@@ -0,0 +1,89 @@
package com.eip4.flowservice.config;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import com.dsasp.server.wf.service.WfContextService;
import com.dsasp.server.wf.support.WfBeanRegistry;
import com.dsasp.server.wf.user.assignee.CandidateUsersHandler;
import com.dsasp.server.wf.user.assignee.MultiInstanceUsersHandler;
import com.eip4.flowservice.org.OrgDirectoryJdbc;
/**
* Flowable 6.8.1 引擎装配(手工接管,不用 flowable-spring-boot-starter)。
*
* <p>三大纪律:</p>
* <ol>
* <li><b>databaseSchemaUpdate=false</b>:严禁引擎自动改表(任务红线,6.8.1.0 真实迁移数据);</li>
* <li><b>v5 兼容层启用</b>:运行 1,509 定义中 engineVersion=v5 的流程(手册 §6.2 两步升级产物);</li>
* <li><b>3 个 handler bean 经 cfg.setBeans 注册</b>(PoC 已验证机制有效,手册 §6.3):
* candidateUsersHandler / multiInstanceUsersHandler / wfContextService,按原包名移植。</li>
* </ol>
*
* <p>候选人解析所需的业务组织目录({@link OrgDirectoryJdbc})经 {@link WfBeanRegistry}
* 注入给 handler(等价 framework SpringBeanOsgiServices 注册,手册 §3.1/§5.17)。</p>
*/
@Configuration
public class FlowableEngineConfig {
@Bean
public OrgDirectoryJdbc orgDirectory(JdbcTemplate bizJdbcTemplate) {
OrgDirectoryJdbc directory = new OrgDirectoryJdbc(bizJdbcTemplate);
// 等价 framework SpringBeanOsgiServices 注册:handler 经 WfBeanRegistry 取用
WfBeanRegistry.setOrgDirectory(directory);
return directory;
}
@Bean(destroyMethod = "close")
public ProcessEngine processEngine(DataSource flowableDataSource, OrgDirectoryJdbc orgDirectory) {
StandaloneProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration();
cfg.setDataSource(flowableDataSource);
// 严禁自动改表:只读取 6.8.1.0 现有 schema,版本不符则 fail-fast(false=校验不改)
cfg.setDatabaseSchemaUpdate("false");
// v5 兼容层:运行 5.x 标记的流程定义
cfg.setFlowable5CompatibilityEnabled(true);
// 独立服务暂不起异步执行器(与 PoC 同口径;定时/边界事件按需在 P3-4 再开)
cfg.setAsyncExecutorActivate(false);
// BPMN 表达式引用的 3 个 handler bean,按原包名移植,cfg.setBeans 注册
Map<Object, Object> beans = new HashMap<>();
beans.put("candidateUsersHandler", new CandidateUsersHandler());
beans.put("multiInstanceUsersHandler", new MultiInstanceUsersHandler());
beans.put("wfContextService", new WfContextService());
cfg.setBeans(beans);
return cfg.buildProcessEngine();
}
@Bean
public RepositoryService repositoryService(ProcessEngine engine) {
return engine.getRepositoryService();
}
@Bean
public RuntimeService runtimeService(ProcessEngine engine) {
return engine.getRuntimeService();
}
@Bean
public TaskService taskService(ProcessEngine engine) {
return engine.getTaskService();
}
@Bean
public HistoryService historyService(ProcessEngine engine) {
return engine.getHistoryService();
}
}

View File

@@ -0,0 +1,235 @@
package com.eip4.flowservice.org;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.springframework.jdbc.core.JdbcTemplate;
import com.dsasp.server.wf.support.OrgDirectory;
import com.dsasp.server.wf.support.WfTypes;
/**
* {@link OrgDirectory} 的直查实现:对<b>业务组织库</b>(客户库 SYS_* 表)跑 SQL 解析候选人,
* 不引入 framework com.dsasp.server.organize 引擎(POJOCRUDService/GeneralPOJO/元数据层)。
*
* <p><b>SQL 来源</b>(逐条对齐 framework,保证候选人解析口径一致):</p>
* <ul>
* <li>{@code AssignmentHandlerImpl.assignmentUser} —— 配置类型分派骨架;</li>
* <li>{@code UserFindServiceImpl} —— findUsersByRoles/Positions/Departs/DirectLeader/Underling 等;</li>
* <li>{@code OrganizationServiceImpl} —— getPositionsByDepartAndPositionTypes/getOrgIdByDepartId 等。</li>
* </ul>
*
* <p>原版 {@code listSelectSpecialCol(param, TABLE, ...)} 是「SELECT col FROM TABLE WHERE k IN (...)」
* 的元数据驱动等价,这里落为直接参数化 SQL(同时收敛原版裸拼注入面,对齐架构第四节安全第 2 层方向)。
* 注:findUsersByRoles 的多表 JOIN SQL 原版即裸拼,此处改 {@code ?} 占位,语义等价。</p>
*
* <p><b>实测分布(本地客户库副本)</b>:position 1949 / user 1683 / formSpecifiedDimension 601
* / projectRoleType 528 / scriptUser 26 / initiatorDepartManager 24 / depart 14
* / fixedDimension 12 / sameToTask 5 / initiator 3。占主导类型全部覆盖。</p>
*
* <p><b>未覆盖类型(报告登记)</b>:initiatorDepartManager/initiatorLeader/initiatorSubordinate/
* initiatorDepart/fixedDimension 依赖 SYS_USER.MASTERDEPART/MASTERPOSITION 等
* <b>元数据虚拟列</b>(客户库 sys_user 无该物理列,引擎经元数据映射),纯直查 SQL 无法复现,
* 需保真层元数据层;本实现对这些类型返回空并由调用侧 WARN。</p>
*/
public class OrgDirectoryJdbc implements OrgDirectory {
private final JdbcTemplate bizJdbc;
/** project-role 解析委托(可空:framework 无通用实现,客户私有化时注入)。 */
private final ProjectRoleResolver projectRoleResolver;
public OrgDirectoryJdbc(JdbcTemplate bizJdbc) {
this(bizJdbc, null);
}
public OrgDirectoryJdbc(JdbcTemplate bizJdbc, ProjectRoleResolver projectRoleResolver) {
this.bizJdbc = bizJdbc;
this.projectRoleResolver = projectRoleResolver;
}
@Override
public List<String> assignmentUser(String type, String content, String initiatorId, String initiatorDepart) {
List<String> rtn = new ArrayList<String>();
List<String> contents = new ArrayList<String>();
if (content != null && !content.trim().isEmpty()) {
contents = Arrays.asList(content.split(","));
}
if (WfTypes.USER.equals(type)) {
return new ArrayList<String>(contents);
} else if (WfTypes.ROLES.equals(type)) {
return findUsersByRoles(contents);
} else if (WfTypes.DEPART.equals(type)) {
return findUsersByDeparts(contents);
} else if (WfTypes.POSITION.equals(type)) {
return findUsersByPositions(contents);
} else if (WfTypes.INITIATOR.equals(type)) {
if (initiatorId != null) {
rtn.add(initiatorId);
}
return rtn;
} else if (WfTypes.INITIATORLEADER.equals(type)) {
return findDirectLeader(initiatorId);
} else if (WfTypes.INITIATORSUBORDINATE.equals(type)) {
return findUnderling(initiatorId);
} else if (WfTypes.INITIATORDEPART.equals(type)) {
return findUsersByDepart(initiatorDepart);
} else if (WfTypes.FORMSPECIFIEDDIMENSION.equals(type)) {
// framework: findUsersByDepartPositionTypes(curDepart, contents)
return findUsersByDepartPositionTypes(initiatorDepart, contents);
}
// initiatorDepartManager/beforeTask*/fixedDimension:依赖 MASTERDEPART 等元数据虚拟列
// 或前序活动栈,纯直查无法复现,返回空(报告登记)。
return rtn;
}
@Override
public List<String> getUsersByProjectRole(String projectId, String roleContent) {
if (projectRoleResolver != null) {
return projectRoleResolver.getUserByProjectRole(projectId, roleContent);
}
System.out.println("[WARN] projectRoleType 候选人:framework 无通用 ProjectRoleUser 实现(项目定制扩展),"
+ "未注入 ProjectRoleResolver,返回空。projectId=" + projectId);
return new ArrayList<String>();
}
@Override
public String getOrgIdByDepartId(String departId) {
if (departId == null || departId.trim().isEmpty()) {
return null;
}
// OrganizationServiceImpl.getOrgIdByDepartId
List<String> orgs = bizJdbc.query(
"SELECT orgid FROM view_depart_tree WHERE view_depart_id = ?",
(rs, n) -> rs.getString("orgid"), departId);
return orgs.isEmpty() ? null : orgs.get(0);
}
// ===== UserFindServiceImpl 等价直查 =====
/** UserFindServiceImpl.findUsersByRoles(List):多表 JOIN(原版裸拼,此处参数化)。 */
List<String> findUsersByRoles(List<String> roleIds) {
List<String> users = new ArrayList<String>();
if (roleIds == null || roleIds.isEmpty()) {
return users;
}
String inClause = placeholders(roleIds.size());
String sql = "SELECT distinct a.sys_user_id as userid FROM sys_user a "
+ "LEFT JOIN sys_usergroupuser b ON a.sys_user_id = b.userid::bpchar "
+ "JOIN sys_usergrouprole c ON b.usergroupid::text = c.usergroupid::text "
+ "where (a.state = 1 or a.state = 2) and c.roleid in (" + inClause + ")";
return bizJdbc.query(sql, (rs, n) -> rs.getString("userid"), roleIds.toArray());
}
/** UserFindServiceImpl.findUsersByPositions:SYS_POSITIONUSER.USERID where POSITIONID in (...)。 */
List<String> findUsersByPositions(List<String> positionIds) {
Set<String> userIds = new LinkedHashSet<String>();
if (positionIds == null || positionIds.isEmpty()) {
return new ArrayList<String>(userIds);
}
String sql = "SELECT distinct userid FROM sys_positionuser WHERE positionid IN (" + placeholders(positionIds.size()) + ")";
List<String> rows = bizJdbc.query(sql, (rs, n) -> rs.getString("userid"), positionIds.toArray());
for (String u : rows) {
if (u != null) {
userIds.add(u.trim());
}
}
return new ArrayList<String>(userIds);
}
/** UserFindServiceImpl.findUsersByDepart → 部门下岗位 → 岗位人员。 */
List<String> findUsersByDepart(String departId) {
if (departId == null || departId.trim().isEmpty()) {
return new ArrayList<String>();
}
List<String> positionIds = bizJdbc.query(
"SELECT sys_position_id FROM sys_position WHERE parentdepartid = ?",
(rs, n) -> rs.getString("sys_position_id"), departId);
return findUsersByPositions(positionIds);
}
/** UserFindServiceImpl.findUsersByDeparts。 */
List<String> findUsersByDeparts(List<String> departIds) {
if (departIds == null || departIds.isEmpty()) {
return new ArrayList<String>();
}
String sql = "SELECT sys_position_id FROM sys_position WHERE parentdepartid IN (" + placeholders(departIds.size()) + ")";
List<String> positionIds = bizJdbc.query(sql, (rs, n) -> rs.getString("sys_position_id"), departIds.toArray());
return findUsersByPositions(positionIds);
}
/** UserFindServiceImpl.findDirectLeader:SYS_USERLEADER.LEADERID where USERID = ?。 */
List<String> findDirectLeader(String userId) {
if (userId == null) {
return new ArrayList<String>();
}
return bizJdbc.query("SELECT leaderid FROM sys_userleader WHERE userid = ?",
(rs, n) -> rs.getString("leaderid"), userId);
}
/** UserFindServiceImpl.findUnderling:SYS_USERLEADER.USERID where LEADERID = ?。 */
List<String> findUnderling(String leaderId) {
if (leaderId == null) {
return new ArrayList<String>();
}
return bizJdbc.query("SELECT userid FROM sys_userleader WHERE leaderid = ?",
(rs, n) -> rs.getString("userid"), leaderId);
}
/**
* UserFindServiceImpl.findUsersByDepartPositionTypes:
* 部门下指定岗位类别的岗位 → 人员;部门内无则回退到部门所属公司。
*/
List<String> findUsersByDepartPositionTypes(String departId, List<String> positionTypes) {
if (departId == null || departId.trim().isEmpty() || positionTypes == null || positionTypes.isEmpty()) {
return new ArrayList<String>();
}
// OrganizationServiceImpl.getPositionsByDepartAndPositionTypes
String sql = "SELECT sys_position_id FROM sys_position WHERE parentdepartid = ? AND positiontype IN (" + placeholders(positionTypes.size()) + ")";
Object[] args = new Object[positionTypes.size() + 1];
args[0] = departId;
for (int i = 0; i < positionTypes.size(); i++) {
args[i + 1] = positionTypes.get(i);
}
List<String> positionIds = bizJdbc.query(sql, (rs, n) -> rs.getString("sys_position_id"), args);
if (!positionIds.isEmpty()) {
return findUsersByPositions(positionIds);
}
// 回退:部门所属公司下的岗位类别岗位(OrganizationServiceImpl.getPositionsByOrgAndPositionTypes)
String orgId = getOrgIdByDepartId(departId);
if (orgId != null) {
String orgSql = "SELECT a.sys_position_id FROM sys_position a "
+ "INNER JOIN view_depart_tree b ON a.parentdepartid = b.view_depart_id "
+ "WHERE b.orgid = ? AND a.positiontype IN (" + placeholders(positionTypes.size()) + ")";
Object[] orgArgs = new Object[positionTypes.size() + 1];
orgArgs[0] = orgId;
for (int i = 0; i < positionTypes.size(); i++) {
orgArgs[i + 1] = positionTypes.get(i);
}
List<String> orgPositionIds = bizJdbc.query(orgSql, (rs, n) -> rs.getString("sys_position_id"), orgArgs);
if (!orgPositionIds.isEmpty()) {
return findUsersByPositions(orgPositionIds);
}
}
return new ArrayList<String>();
}
private static String placeholders(int n) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i > 0) {
sb.append(',');
}
sb.append('?');
}
return sb.toString();
}
/** 项目角色解析钩子(framework ProjectRoleUser 的对齐位,客户私有化注入)。 */
public interface ProjectRoleResolver {
List<String> getUserByProjectRole(String projectId, String roleContent);
}
}

View File

@@ -0,0 +1,46 @@
server:
port: 8089
spring:
application:
name: flowable-service
# ===== 双数据源(架构第三节:独立服务连两个数据源)=====
# flowable.datasource:ACT_ 引擎库(本地 eip4flow.eip3,6.8.1.0 真实迁移数据)
# databaseSchemaUpdate=false 在 FlowableEngineConfig 写死,严禁自动改表。
# biz.datasource:业务组织库(客户库只读,候选人解析直查 SYS_* 组织表)
#
# 本地验证默认值经环境变量覆盖(见下 ${...:默认}),不把口令写死进仓库。
flowable:
datasource:
# Hikari 原生属性名 jdbc-url(@ConfigurationProperties 绑到已 build 的 HikariDataSource,
# 须用 jdbc-url 而非 url,否则报 "jdbcUrl is required with driverClassName")
jdbc-url: ${FLOWABLE_JDBC_URL:jdbc:postgresql://localhost:5433/eip4flow?currentSchema=eip3}
username: ${FLOWABLE_JDBC_USER:zhengwr}
password: ${FLOWABLE_JDBC_PASS:}
driver-class-name: org.postgresql.Driver
biz:
datasource:
# 本地验证:客户库副本 192.168.20.68:5435,schema eip3,ceshi 只读
jdbc-url: ${BIZ_JDBC_URL:jdbc:postgresql://192.168.20.68:5435/postgres?currentSchema=eip3}
username: ${BIZ_JDBC_USER:ceshi}
password: ${BIZ_JDBC_PASS:ceshi}
driver-class-name: org.postgresql.Driver
# 业务库只读纪律:Hikari 只读连接
read-only: true
# ===== 生产单库分 schema 形态(架构第三节,配置示意)=====
# 生产为同一 PG 库、不同 schema:ACT_ 表在 flowable schema、业务表在 business schema。
# 仅 URL 的 currentSchema 不同、其余装配不变:
# flowable.datasource.url: jdbc:postgresql://<生产PG>:5432/eip4?currentSchema=flowable
# biz.datasource.url: jdbc:postgresql://<生产PG>:5432/eip4?currentSchema=business
# 业务库只读连接走最小权限账户(架构第四节安全第 3 层),DDL 不经本服务。
springdoc:
swagger-ui:
path: /swagger-ui.html
logging:
level:
org.flowable: INFO