!32 fix(flow): 修复配置前缀错误导致 props 为 null 及流程变量获取失败

* fix(flow): 修复配置前缀错误导致 props 为 null 及流程变量获取失败
* fix(flow): 修复 inspectImproveProps 字段初始化 NPE 问题
* feat(flow): 新增巡视整改流程党群领导审批表达式方法
* feat(dqinspecttask): 新增工作进展反馈子表独立Controller接口
This commit is contained in:
new_new_new
2026-06-04 12:25:18 +00:00
parent 0bc279957f
commit 335890b699
5 changed files with 286 additions and 1 deletions
@@ -0,0 +1,8 @@
package org.jeecg.inspectimprove;
import org.jeecg.modules.demo.dqinspecttask.entity.DqInspectTask;
public class InspectConstant {
public static final String NEED_APPROVE_STR = "1";
public static final String NOT_NEED_APPROVE_STR = "0";
}
@@ -6,7 +6,7 @@ import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "inspect-improve")
@ConfigurationProperties(prefix = "flow-biz")
public class InspectImproveConfig {
private InspectImproveProperties inspectImprove;
@@ -35,5 +35,7 @@ public class InspectImproveConfig {
private String workProgressKey;
/** 完成状态 key */
private String completionStatusKey;
private String dqDeptId;
private String ldRoleId;
}
}
@@ -4,9 +4,14 @@ import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.modules.demo.dqinspecttask.entity.DqInspectTask;
import org.jeecg.modules.demo.dqinspecttask.service.IDqInspectTaskService;
import org.jeecg.modules.dj.inspectimprove.entity.DjInspectImprove;
import org.jeecg.modules.dj.inspectimprove.service.IDjInspectImproveService;
import org.jeecg.modules.extbpm.process.common.expression.FlowNodeExpression;
import org.jeecg.xispeak.XiSpeakConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -21,6 +26,108 @@ public class InspectImproveFlow {
private final InspectImproveConfig inspectImproveConfig;
private final IDjInspectImproveService djInspectImproveService;
private final FlowNodeExpression flowNodeExpression;
private final XiSpeakConfig xiSpeakConfig;
private final ISysBaseAPI iSysBaseAPI;
private final IDqInspectTaskService dqInspectTaskService;
//流程表达式内用法 ${inspectImproveFlow.getDqDeptLdUserIdList()}
public List<String> getDqDeptLdUserIdList() {
InspectImproveConfig.InspectImproveProperties props = inspectImproveConfig.getInspectImprove();
if (props == null || !org.apache.shiro.util.StringUtils.hasText(props.getDqDeptId())) {
log.error("流程配置缺失: [flow-biz.inspect-improve.dq-dept-id] 未在 YAML 中定义");
return Collections.emptyList();
}
log.info("正在查询部门: {} 下的角色: {} 的用户列表", props.getDqDeptId(), props.getLdRoleId());
List<String> userList = iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
props.getDqDeptId(),
props.getLdRoleId()
);
log.info("查询到的用户为: {}", userList);
return userList;
}
//流程表达式内用法 ${inspectImproveFlow.getDqDeptLdUserIdListLength()}
public int getDqDeptLdUserIdListLength() {
List<String> dqDeptLdUserIdList = this.getDqDeptLdUserIdList();
if (dqDeptLdUserIdList != null && !dqDeptLdUserIdList.isEmpty()) {
return dqDeptLdUserIdList.size();
}
log.warn("dq部门ld角色没有对应用户");
return 0;
}
// 流程表达式内用法 ${inspectImproveFlow.getNeedDqLeaderApprove(execution)}
public String getNeedDqLeaderApprove(DelegateExecution execution) {
DqInspectTask temDqInspectTask = this.getDqInspectTask(execution);
// 如果上一步返回了 null(说明数据缺失),为了流程安全,这里直接抛出异常,阻止流程往错误的方向流转
if (temDqInspectTask == null) {
throw new IllegalStateException("无法判定是否需要审批:未找到对应的业务表单数据,流程暂停。");
}
// 字符串比对的优雅写法:把常量放在前面,天然防范 NPE
if (InspectConstant.NOT_NEED_APPROVE_STR.equals(temDqInspectTask.getIsNeedAppro())
|| StringUtils.isBlank(temDqInspectTask.getIsNeedAppro())) {
return InspectConstant.NOT_NEED_APPROVE_STR;
}
return InspectConstant.NEED_APPROVE_STR;
}
// 流程表达式内用法:${inspectImproveFlow.getImplDeptLeaderList(execution)}
public List<String> getImplDeptLeaderList(DelegateExecution execution) {
DqInspectTask temDqInspectTask = this.getDqInspectTask(execution);
if (temDqInspectTask == null) {
throw new IllegalStateException("无法获取审批人:未找到对应的业务表单数据,流程暂停。");
}
String measureDeptId = temDqInspectTask.getMeasureResDept();
if (StringUtils.isBlank(measureDeptId)) {
String errorMsg = String.format("流程流转失败: 业务表单[ID:%s]中的整改责任部门(measureResDept)为空,无法匹配审批人。", temDqInspectTask.getId());
log.error(errorMsg);
throw new IllegalStateException(errorMsg); // 保持严谨,核心数据缺失直接抛异常阻断
}
InspectImproveConfig.InspectImproveProperties props = inspectImproveConfig.getInspectImprove();
log.info("正在查询整改责任部门: {} 下的角色: {} 的领导列表", measureDeptId, props.getLdRoleId());
List<String> leaderList = iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
measureDeptId,
props.getLdRoleId()
);
if (leaderList == null || leaderList.isEmpty()) {
log.warn("【节点预警】整改责任部门: {} 下未配置角色: {} 的用户,审批人列表为空!", measureDeptId, props.getLdRoleId());
return Collections.emptyList();
}
log.info("查询到的整改责任部门领导为:{}", leaderList);
return leaderList;
}
// 流程表达式内用法:${inspectImproveFlow.getImplDeptLeaderListLength(execution)}
public int getImplDeptLeaderListLength(DelegateExecution execution) {
return this.getImplDeptLeaderList(execution).size();
}
private DqInspectTask getDqInspectTask(DelegateExecution execution) {
Object inspectTaskId = execution.getVariable(inspectImproveConfig.getInspectImprove().getBusinessKey());
// 统一校验 null 和空字符串
if (inspectTaskId == null || StringUtils.isBlank(inspectTaskId.toString())) {
log.error("【流程异常】流程实例id为 {} 的流程内未获取到有效的业务表单id", execution.getProcessInstanceId());
return null; // 明确返回 null,不给上游返回空壳对象
}
// 如果 getById 没查到,MyBatis-Plus 也会返回 null
DqInspectTask task = dqInspectTaskService.getById(inspectTaskId.toString());
if (task == null) {
log.error("【数据异常】通过业务表单id {} 未查询到数据库中的任务记录", inspectTaskId);
}
return task;
}
// ===================================================================
// 通用工具方法
@@ -19,6 +19,8 @@ flow-biz:
sdw-leader-list-key: "sdwLeaderList"
is-end-key: "isEnd"
inspect-improve:
dq-dept-id: "2044677628281720834"
ld-role-id: "2044680793306591234"
business-key: "business_id"
json-data-key: "json_data"
form-url: "dj/inspectimprove/components/DjInspectImproveBPMForm"