wsm-修改xispeak督办计划流程
This commit is contained in:
+2
-1
@@ -14,7 +14,6 @@ public class XiSpeakConfig {
|
||||
*/
|
||||
private XiSpeakProperties xiSpeak;
|
||||
|
||||
|
||||
@Data
|
||||
public static class XiSpeakProperties {
|
||||
/** 对应 bg-dept-id */
|
||||
@@ -36,5 +35,7 @@ public class XiSpeakConfig {
|
||||
/** 对应impl-dept-key-underscore-key*/
|
||||
private String implDeptKeyUnderscoreKey;
|
||||
private String deptWorkerKey;
|
||||
private String xiSpeakFbFlowCode;
|
||||
private String formUrl;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ public class XiSpeakFlow {
|
||||
private final ISysBaseAPI iSysBaseAPI;
|
||||
private final RuntimeService runtimeService;
|
||||
|
||||
//流程表达式内用法 ${xiSpeakFlow.getBgDeptLdUserIdList()}
|
||||
public List<String> getBgDeptLdUserIdList() {
|
||||
// 1. 安全获取配置,防止 NPE
|
||||
XiSpeakConfig.XiSpeakProperties props = xiSpeakConfig.getXiSpeak();
|
||||
@@ -61,7 +62,7 @@ public class XiSpeakFlow {
|
||||
return this.getSDWLeader().size();
|
||||
}
|
||||
|
||||
|
||||
//流程表达式内用法 ${xiSpeakFlow.getBgDeptLdUserIdListLength()}
|
||||
public int getBgDeptLdUserIdListLength() {
|
||||
return getBgDeptLdUserIdList().size();
|
||||
}
|
||||
|
||||
-55
@@ -37,61 +37,6 @@ public class AfterImplDeptLeaderApproveListener implements TaskListener {
|
||||
private final ITaskTaskService taskTaskService;
|
||||
private final IBgXiSpeakService bgXiSpeakService;
|
||||
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void notify(DelegateTask delegateTask) {
|
||||
//
|
||||
// // 1. 获取审批人
|
||||
// String currentAssignee = delegateTask.getAssignee();
|
||||
// if (StringUtils.isEmpty(currentAssignee)) {
|
||||
// // 使用你给出的正确获取方式:扫描 Execution 树获取局部变量
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 2. 获取业务主键:通常业务 ID 是全局变量,可以直接 getVariable
|
||||
// Object rawTaskTaskId = delegateTask.getVariable(xiSpeakConfig.getXiSpeak().getBusinessKey());
|
||||
//
|
||||
// if (StringUtils.isEmpty(currentAssignee) || rawTaskTaskId == null) {
|
||||
// log.warn("无法获取有效的审批人或业务ID,ExecutionId: {}, TaskId: {}",
|
||||
// delegateTask.getExecutionId(), delegateTask.getId());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 3. 获取业务实体
|
||||
// BgXiSpeak xiSpeak = bgXiSpeakService.getById(rawTaskTaskId.toString());
|
||||
// if (xiSpeak == null) return;
|
||||
//
|
||||
// // 4. 处理数据结构
|
||||
// Map<String, DeptApproveDetail> deptApproveDetailMap = Optional.ofNullable(xiSpeak.getApproveInfo())
|
||||
// .orElse(new HashMap<>());
|
||||
//
|
||||
// // 5. 获取实施部门 ID:同样使用全路径搜索,确保在嵌套会签中能精准定位局部变量
|
||||
// String implDeptKey = xiSpeakConfig.getXiSpeak().getImplDeptCollectionUsedKey();
|
||||
// String rawDeptVar = delegateTask.getVariable(implDeptKey).toString();
|
||||
//
|
||||
// if (StringUtils.isBlank(rawDeptVar)) {
|
||||
// throw new RuntimeException("流程数据异常:未找到实施部门ID变量: " + implDeptKey);
|
||||
// }
|
||||
//
|
||||
// // 清洗字符串(处理 [id1, id2] 格式)
|
||||
// String cleanDeptId = rawDeptVar.replace("[", "").replace("]", "").trim();
|
||||
//
|
||||
// // computeIfAbsent 的特性:如果 key 存在,返回 value;如果不存在,运行 lambda 并存入再返回。
|
||||
// DeptApproveDetail detail = deptApproveDetailMap.computeIfAbsent(cleanDeptId, k -> new DeptApproveDetail());
|
||||
//
|
||||
// // 2. 只有当 approverName 为空时(即该对象是刚新建的,或者之前没存过审批人),才进行赋值
|
||||
// if (StringUtils.isBlank(detail.getApproverName())) {
|
||||
// detail.setApproverName(currentAssignee);
|
||||
//
|
||||
// // 3. 只有发生了赋值,才执行数据库更新(可选,为了性能)
|
||||
// xiSpeak.setApproveInfo(deptApproveDetailMap);
|
||||
// bgXiSpeakService.updateById(xiSpeak);
|
||||
// log.info("部门 {} 首次审批,已记录审批人: {}", cleanDeptId, currentAssignee);
|
||||
// } else {
|
||||
// log.info("部门 {} 已存在审批记录: {},跳过本次回写", cleanDeptId, detail.getApproverName());
|
||||
// }
|
||||
// }
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void notify(DelegateTask delegateTask) {
|
||||
// 1. 获取基础数据
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.jeecg.xispeakfb;
|
||||
|
||||
import lombok.Data;
|
||||
import org.jeecg.xispeak.XiSpeakConfig;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "flow-biz")
|
||||
public class XiSpeakFeedbackConfig {
|
||||
/**
|
||||
* 复用 xi-speak 配置节点
|
||||
* 两个模块共用同一份配置
|
||||
*/
|
||||
private XiSpeakFeedbackConfig.XiSpeakPropertiesFb xiSpeakFb;
|
||||
|
||||
@Data
|
||||
public static class XiSpeakPropertiesFb {
|
||||
String deptId;
|
||||
String businessId;
|
||||
String jjDeptId;
|
||||
String jjWorkerRoleId;
|
||||
String jjLeaderRoleId;
|
||||
}
|
||||
}
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
package org.jeecg.xispeakfb;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.delegate.DelegateExecution;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.jeecg.modules.bg.xispeak.entity.BgXiSpeak;
|
||||
import org.jeecg.modules.bg.xispeak.entity.DeptApproveDetail;
|
||||
import org.jeecg.modules.bg.xispeak.service.IBgXiSpeakService;
|
||||
import org.jeecg.modules.tasktask.entity.TaskTask;
|
||||
import org.jeecg.modules.tasktask.service.ITaskTaskService;
|
||||
import org.jeecg.xispeak.XiSpeakConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Component("XiSpeakFeedbackFlow")
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
public class XiSpeakFeedbackFlow {
|
||||
|
||||
private final XiSpeakFeedbackConfig xiSpeakFeedbackConfig;
|
||||
private final ISysBaseAPI iSysBaseAPI;
|
||||
private final RuntimeService runtimeService;
|
||||
private final IBgXiSpeakService bgXiSpeakService;
|
||||
private final ITaskTaskService taskTaskService;
|
||||
|
||||
|
||||
// 流程表达式内用法 ${XiSpeakFeedbackFlow.getImplDeptList()}
|
||||
public List<String> getImplDeptList(DelegateExecution execution) {
|
||||
String processInstId = execution.getProcessInstanceId();
|
||||
String businessKey = execution.getProcessInstanceBusinessKey();
|
||||
|
||||
if (StringUtils.isAnyBlank(processInstId, businessKey)) {
|
||||
log.warn("流程上下文中业务关键信息缺失![ProcessInstanceId: {}, BusinessKey: {}, ExecutionId: {}, ActivityId: {}]",
|
||||
processInstId, businessKey, execution.getId(), execution.getCurrentActivityId());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
BgXiSpeak xiSpeak = bgXiSpeakService.getById(businessKey);
|
||||
if (xiSpeak == null) {
|
||||
log.warn("根据查询到的业务表单id无法获取业务数据行![BusinessKey: {}]", businessKey);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Map<String, DeptApproveDetail> approveInfoMap = xiSpeak.getApproveInfo();
|
||||
if (approveInfoMap == null || approveInfoMap.isEmpty()) {
|
||||
log.warn("根据查询到的业务表单数据无法获取对应的审批信息![BgXiSpeak: {}]", xiSpeak);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> deptIdList = approveInfoMap.keySet().stream()
|
||||
.filter(StringUtils::isNotBlank) // 可选:过滤掉空的Key
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return deptIdList;
|
||||
}
|
||||
|
||||
// 流程表达式内用法 ${XiSpeakFeedbackFlow.getImplDeptListLength()}
|
||||
public int getImplDeptListLength(DelegateExecution execution) {
|
||||
List<String> implDeptList = this.getImplDeptList(execution);
|
||||
if (implDeptList.isEmpty() || implDeptList == null) {
|
||||
log.warn("当前节点无经办部门{}!", execution);
|
||||
return 0;
|
||||
}
|
||||
return implDeptList.size();
|
||||
}
|
||||
|
||||
public String getImplDeptApprove(DelegateExecution execution) {
|
||||
String businessKey = execution.getProcessInstanceBusinessKey();
|
||||
|
||||
// 1. 基础校验
|
||||
if (StringUtils.isBlank(businessKey)) {
|
||||
log.warn("流程 BusinessKey 缺失,ExecutionId: {}", execution.getId());
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
// 2. 获取任务主表数据
|
||||
TaskTask taskTask = taskTaskService.getById(businessKey);
|
||||
if (taskTask == null || StringUtils.isBlank(taskTask.getBusinessId())) {
|
||||
log.warn("无法获取任务数据或业务关联ID![taskTaskId: {}]", businessKey);
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
// 3. 获取业务表单数据
|
||||
BgXiSpeak xiSpeak = bgXiSpeakService.getById(taskTask.getBusinessId());
|
||||
if (xiSpeak == null || xiSpeak.getApproveInfo() == null) {
|
||||
log.warn("业务表单数据或审批配置缺失![xiBusinessId: {}]", taskTask.getBusinessId());
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
// 4. 获取匹配参数
|
||||
String handlerName = taskTask.getDeptHandlerName();
|
||||
if (StringUtils.isBlank(handlerName)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
// --- 核心修复部分 ---
|
||||
// 从 DB 或缓存取出的 Map,其 Value 在运行时往往是 LinkedHashMap
|
||||
Map<String, ?> approveInfoMap = xiSpeak.getApproveInfo();
|
||||
|
||||
// 建议将 ObjectMapper 定义为静态常量或通过 Spring 注入,此处为演示保持局部定义
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
return approveInfoMap.values().stream()
|
||||
// 重点 1: 强制声明为 Object 接收,跳过隐式的 (DeptApproveDetail) 强转
|
||||
.map((Object obj) -> {
|
||||
try {
|
||||
// 重点 2: 如果已经是对象则直接转,否则进行 Jackson 转换
|
||||
if (obj instanceof DeptApproveDetail) {
|
||||
return (DeptApproveDetail) obj;
|
||||
}
|
||||
return mapper.convertValue(obj, DeptApproveDetail.class);
|
||||
} catch (Exception e) {
|
||||
log.error("审批明细类型转换失败: {}", obj, e);
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(Objects::nonNull) // 过滤掉转换失败的元素
|
||||
.filter(detail -> detail.getImplUserNameList() != null && detail.getImplUserNameList().contains(handlerName))
|
||||
.map(DeptApproveDetail::getApproverName)
|
||||
.findFirst()
|
||||
.orElse("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前流程的经办部门的经办人。
|
||||
* <p>用于流程表达式判断,通过 BusinessKey 关联业务主键,获取当前经办人。</p>
|
||||
*
|
||||
* @param execution 流程执行上下文
|
||||
* @return 经办部门经办人
|
||||
* @example 表达式用法: ${XiSpeakFeedbackFlow.getImplDeptWorker()}
|
||||
*/
|
||||
public List<String> getImplDeptWorker(DelegateExecution execution) {
|
||||
String businessKey = execution.getProcessInstanceBusinessKey();
|
||||
|
||||
// 1. 基础校验
|
||||
if (StringUtils.isBlank(businessKey)) {
|
||||
log.warn("流程 BusinessKey 缺失,ExecutionId: {}", execution.getId());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 2. 获取任务主表数据并判空
|
||||
TaskTask taskTask = taskTaskService.getById(businessKey);
|
||||
if (taskTask == null || StringUtils.isBlank(taskTask.getBusinessId())) {
|
||||
log.warn("无法获取任务数据或业务关联ID![taskTaskId: {}]", businessKey);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String implDeptWorker = taskTask.getDeptHandlerName();
|
||||
if (StringUtils.isBlank(implDeptWorker)) {
|
||||
log.warn("中间表taskTask[id={}]没有经办人数据", businessKey);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 将 "张三, 李四 " 转换为 ["张三", "李四"]
|
||||
return Arrays.stream(implDeptWorker.split(","))
|
||||
.map(String::trim) // 去掉前后空格
|
||||
.filter(StringUtils::isNotBlank) // 过滤掉空字符串(防止出现 "张三,,李四")
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 经办部门经办人数量
|
||||
* <p>经办部门经办人数量</p>
|
||||
*
|
||||
* @param execution 流程执行上下文
|
||||
* @return 经办部门经办人数量
|
||||
* @example 表达式用法: ${XiSpeakFeedbackFlow.getImplDeptWorkerLength()}
|
||||
*/
|
||||
public int getImplDeptWorkerLength(DelegateExecution execution) {
|
||||
List<String> implDeptWorkerList = this.getImplDeptWorker(execution);
|
||||
if (implDeptWorkerList == null || implDeptWorkerList.isEmpty()) {
|
||||
log.warn("{}流程经办部门经办人数量为0",execution.getProcessInstanceId());
|
||||
return 0;
|
||||
}
|
||||
return implDeptWorkerList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jj部门经办人
|
||||
* <p>jj部门经办人</p>
|
||||
*
|
||||
* @return jj部门经办人
|
||||
* @example 表达式用法: ${XiSpeakFeedbackFlow.JJDeptWorkerList()}
|
||||
*/
|
||||
public List<String> getJJDeptWorkerList() {
|
||||
// 1. 安全获取配置对象
|
||||
XiSpeakFeedbackConfig.XiSpeakPropertiesFb config = xiSpeakFeedbackConfig.getXiSpeakFb();
|
||||
if (config == null) {
|
||||
log.error("xiSpeakFb 配置对象加载失败,请检查配置文件!");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String deptId = config.getJjDeptId();
|
||||
String roleId = config.getJjWorkerRoleId();
|
||||
|
||||
// 2. 参数合法性拦截
|
||||
if (StringUtils.isAnyBlank(deptId, roleId)) {
|
||||
log.warn("xiSpeakFb 配置项不完整: deptId={}, roleId={}", deptId, roleId);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 3. 调用接口并处理结果
|
||||
List<String> workerList = iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(deptId, roleId);
|
||||
|
||||
if (CollectionUtils.isEmpty(workerList)) {
|
||||
log.warn("未查找到匹配的部门经办人 [deptId: {}, roleId: {}]", deptId, roleId);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return workerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jj部门经办人列表长度
|
||||
* <p>获取jj部门经办人列表长度</p>
|
||||
*
|
||||
* @return jj部门经办人列表长度
|
||||
* @example 表达式用法: ${XiSpeakFeedbackFlow.getJJDeptWorkerListLength()}
|
||||
*/
|
||||
public int getJJDeptWorkerListLength() {
|
||||
List<String> jjDeptWorkerList = this.getJJDeptWorkerList();
|
||||
if (jjDeptWorkerList == null || jjDeptWorkerList.isEmpty()) {
|
||||
log.warn("获取jj部经办人数量为0");
|
||||
return 0;
|
||||
}
|
||||
return jjDeptWorkerList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jj部门审核人
|
||||
* <p>获取jj部门审核人</p>
|
||||
*
|
||||
* @return jj部门审核人
|
||||
* @example 表达式用法: ${XiSpeakFeedbackFlow.getJjDeptLeaderList()}
|
||||
*/
|
||||
public List<String> getJJDeptLeaderList() {
|
||||
// 1. 安全获取配置对象
|
||||
XiSpeakFeedbackConfig.XiSpeakPropertiesFb config = xiSpeakFeedbackConfig.getXiSpeakFb();
|
||||
if (config == null) {
|
||||
log.error("xiSpeakFb 配置对象加载失败,请检查配置文件!");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
String deptId = config.getJjDeptId();
|
||||
String roleId = config.getJjLeaderRoleId ();
|
||||
|
||||
// 2. 参数合法性拦截
|
||||
if (StringUtils.isAnyBlank(deptId, roleId)) {
|
||||
log.warn("xiSpeakFb 配置项不完整: deptId={}, roleId={}", deptId, roleId);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 3. 调用接口并处理结果
|
||||
List<String> workerList = iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(deptId, roleId);
|
||||
|
||||
if (CollectionUtils.isEmpty(workerList)) {
|
||||
log.warn("未查找到匹配的部门审核人 [deptId: {}, roleId: {}]", deptId, roleId);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return workerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jj部门审核人列表长度
|
||||
* <p>获取jj部门审核人列表长度</p>
|
||||
*
|
||||
* @return jj部门审核人列表长度
|
||||
* @example 表达式用法: ${XiSpeakFeedbackFlow.getJJDeptLeaderListLength()}
|
||||
*/
|
||||
public int getJJDeptLeaderListLength() {
|
||||
List<String> jjDeptWorkerList = this.getJJDeptLeaderList();
|
||||
if (jjDeptWorkerList == null || jjDeptWorkerList.isEmpty()) {
|
||||
log.warn("[获取JJ部审批人数量为0]");
|
||||
return 0;
|
||||
}
|
||||
return jjDeptWorkerList.size();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user