隐患排查bug
This commit is contained in:
@@ -23,7 +23,7 @@ SET `submit_version` = IFNULL(NULLIF(`submit_version`, 0), 1),
|
||||
`last_reject_by_name` = COALESCE(NULLIF(`last_reject_by_name`, ''), `approver_name`),
|
||||
`flow_status` = 'REJECTED',
|
||||
`instance_id` = NULL,
|
||||
`status` = 1
|
||||
`status` = 10
|
||||
WHERE `is_deleted` = 0;
|
||||
|
||||
-- 2. 将老数据写入驳回历史表
|
||||
@@ -129,7 +129,7 @@ WHERE i.`is_deleted` = 0
|
||||
COMMIT;
|
||||
|
||||
-- 校验SQL
|
||||
-- SELECT COUNT(*) FROM hot_hidden_danger_inspection WHERE is_deleted = 0 AND audit_result = 'REJECT' AND status = 1;
|
||||
-- SELECT COUNT(*) FROM hot_hidden_danger_inspection WHERE is_deleted = 0 AND audit_result = 'REJECT' AND status = 10;
|
||||
-- SELECT COUNT(*) FROM hot_hidden_danger_inspection_audit_history WHERE is_deleted = 0;
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class HiddenDangerCheckCallback implements IFlowCallback {
|
||||
inspection.setStatus(inspection.getAuditHasDanger() != null && inspection.getAuditHasDanger() == 1L ? 6L : 3L);
|
||||
} else {
|
||||
inspection.setFlowStatus("REJECTED");
|
||||
inspection.setStatus(1L);
|
||||
inspection.setStatus(10L);
|
||||
inspection.setInstanceId(null);
|
||||
log.info("隐患排查流程被驳回或非正常结束: {}", businessId);
|
||||
}
|
||||
|
||||
@@ -37,25 +37,53 @@ public class HiddenDangerCheckStrategy implements IFlowStrategy {
|
||||
|
||||
@Override
|
||||
public FlowNextDto next(SysFlowInstance instance, String currentNodeCode) {
|
||||
// 简单流程:只有一级审批,审批通过即结束
|
||||
if ("NODE_CHECK_EDIT".equals(currentNodeCode)) {
|
||||
return buildAuditNode(instance.getBusinessId());
|
||||
}
|
||||
// 审核通过即结束
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowNextDto reject(SysFlowInstance instance, String currentNodeCode) {
|
||||
if (!"NODE_CHECK_AUDIT".equals(currentNodeCode)) {
|
||||
return null;
|
||||
}
|
||||
InspectionNodeMeta meta = getInspectionNodeMeta(instance.getBusinessId());
|
||||
String editApproverId = meta.inspection != null && meta.inspection.getCheckerId() != null
|
||||
? meta.inspection.getCheckerId() : instance.getInitiatorId();
|
||||
return buildEditNode(instance.getBusinessId(), editApproverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowNextDto getInitialNode(String businessId) {
|
||||
return getNextNode(businessId);
|
||||
return buildAuditNode(businessId);
|
||||
}
|
||||
|
||||
private FlowNextDto getNextNode(String id) {
|
||||
private FlowNextDto buildAuditNode(String id) {
|
||||
InspectionNodeMeta meta = getInspectionNodeMeta(id);
|
||||
String approverId = meta.inspection != null && meta.inspection.getApproverId() != null
|
||||
? String.valueOf(meta.inspection.getApproverId()) : null;
|
||||
String nodeName = String.format("(%s)(%s)审核", meta.planName, meta.inspectItemName);
|
||||
return new FlowNextDto("NODE_CHECK_AUDIT", nodeName, approverId);
|
||||
}
|
||||
|
||||
private FlowNextDto buildEditNode(String id, String approverId) {
|
||||
InspectionNodeMeta meta = getInspectionNodeMeta(id);
|
||||
String nodeName = String.format("(%s)(%s)处理", meta.planName, meta.inspectItemName);
|
||||
return new FlowNextDto("NODE_CHECK_EDIT", nodeName, approverId);
|
||||
}
|
||||
|
||||
private InspectionNodeMeta getInspectionNodeMeta(String id) {
|
||||
// 待办名称规则:(排查计划名称)(排查项名称)审核
|
||||
|
||||
String inspectItemName = "未知排查项";
|
||||
String planName = "未知计划";
|
||||
HotHiddenDangerInspection inspection = null;
|
||||
|
||||
try {
|
||||
if (id != null) {
|
||||
HotHiddenDangerInspection inspection = inspectMapper.selectById(id);
|
||||
inspection = inspectMapper.selectById(id);
|
||||
if (inspection != null) {
|
||||
// 处理排查项名称
|
||||
if (inspection.getProjectName() != null) {
|
||||
@@ -80,8 +108,9 @@ public class HiddenDangerCheckStrategy implements IFlowStrategy {
|
||||
} catch (Exception e) {
|
||||
// 忽略异常,使用默认值
|
||||
}
|
||||
return new InspectionNodeMeta(inspection, inspectItemName, planName);
|
||||
}
|
||||
|
||||
String nodeName = String.format("(%s)(%s)审核", planName, inspectItemName);
|
||||
return new FlowNextDto("NODE_CHECK_AUDIT", nodeName, null);
|
||||
private record InspectionNodeMeta(HotHiddenDangerInspection inspection, String inspectItemName, String planName) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +137,15 @@ public interface ISysFlowService {
|
||||
*/
|
||||
String getTaskIdByBusinessId(String flowCode, String businessId, String userId);
|
||||
|
||||
/**
|
||||
* 根据业务ID获取当前活动任务ID(不限定处理人)
|
||||
*
|
||||
* @param flowCode 流程编码
|
||||
* @param businessId 业务ID
|
||||
* @return 当前活动任务ID
|
||||
*/
|
||||
String getCurrentTaskIdByBusinessId(String flowCode, String businessId);
|
||||
|
||||
/**
|
||||
* 根据任务ID获取任务详情
|
||||
*
|
||||
|
||||
@@ -737,6 +737,32 @@ public class SysFlowServiceImpl implements ISysFlowService {
|
||||
return task != null ? task.getTaskId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentTaskIdByBusinessId(String flowCode, String businessId) {
|
||||
List<SysFlowInstance> instances = instanceMapper.selectList(
|
||||
Wrappers.<SysFlowInstance>lambdaQuery()
|
||||
.eq(SysFlowInstance::getFlowCode, flowCode)
|
||||
.eq(SysFlowInstance::getBusinessId, businessId)
|
||||
.eq(SysFlowInstance::getStatus, STATUS_RUNNING)
|
||||
);
|
||||
|
||||
if (instances.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> instanceIds = instances.stream()
|
||||
.map(SysFlowInstance::getInstanceId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
SysFlowTask task = taskMapper.selectOne(
|
||||
Wrappers.<SysFlowTask>lambdaQuery()
|
||||
.in(SysFlowTask::getInstanceId, instanceIds)
|
||||
.orderByDesc(SysFlowTask::getCreateTime)
|
||||
.last("limit 1")
|
||||
);
|
||||
return task != null ? task.getTaskId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPendingTask(String flowCode, String businessId, String userId) {
|
||||
// 1. 查找相关的运行中流程实例
|
||||
|
||||
@@ -221,7 +221,9 @@ public class HotHiddenDangerInspectionServiceImpl implements IHotHiddenDangerIns
|
||||
signatureVerifyService.validateSelfSignature(parseSignatureOssId(signImgUrl), checkerName);
|
||||
}
|
||||
boolean flag = baseMapper.updateById(update) > 0;
|
||||
if (flag && shouldStartAuditFlow(original)) {
|
||||
if (flag && shouldResumeRejectedFlow(original)) {
|
||||
resumeRejectedFlow(original);
|
||||
} else if (flag && shouldStartAuditFlow(original)) {
|
||||
String initiator = String.valueOf(LoginHelper.getBusinessUserId());
|
||||
String approverId = bo.getApproverId() != null ? String.valueOf(bo.getApproverId()) : null;
|
||||
if (StringUtils.isBlank(approverId)) {
|
||||
@@ -337,6 +339,8 @@ public class HotHiddenDangerInspectionServiceImpl implements IHotHiddenDangerIns
|
||||
.eq(HotHiddenDangerInspection::getId, original.getId())
|
||||
.set(HotHiddenDangerInspection::getApproverId, bo.getApproverId())
|
||||
.set(HotHiddenDangerInspection::getApproverName, bo.getApproverName())
|
||||
.set(HotHiddenDangerInspection::getStatus, 10L)
|
||||
.set(HotHiddenDangerInspection::getFlowStatus, "REJECTED")
|
||||
.set(HotHiddenDangerInspection::getAuditDate, auditDate)
|
||||
.set(HotHiddenDangerInspection::getAuditConclusion, auditConclusion)
|
||||
.set(HotHiddenDangerInspection::getApproverSignImgUrl, bo.getApproverSignImgUrl())
|
||||
@@ -365,7 +369,82 @@ public class HotHiddenDangerInspectionServiceImpl implements IHotHiddenDangerIns
|
||||
return false;
|
||||
}
|
||||
Long status = original.getStatus();
|
||||
return status == null || status == 0L || status == 1L || "REJECTED".equalsIgnoreCase(original.getFlowStatus());
|
||||
return status == null || status == 0L || status == 1L || status == 10L || "REJECTED".equalsIgnoreCase(original.getFlowStatus());
|
||||
}
|
||||
|
||||
private boolean shouldResumeRejectedFlow(HotHiddenDangerInspection original) {
|
||||
if (original == null || StringUtils.isBlank(original.getInstanceId())) {
|
||||
return false;
|
||||
}
|
||||
Long status = original.getStatus();
|
||||
return status != null && status == 10L && "REJECTED".equalsIgnoreCase(original.getFlowStatus());
|
||||
}
|
||||
|
||||
private void resumeRejectedFlow(HotHiddenDangerInspection original) {
|
||||
String currentUserId = LoginHelper.getBusinessUserId();
|
||||
String taskId = flowService.getTaskId(original.getInstanceId(), currentUserId);
|
||||
if (StringUtils.isBlank(taskId)) {
|
||||
taskId = flowService.getTaskIdByBusinessId("HIDDEN_DANGER_CHECK", String.valueOf(original.getId()), currentUserId);
|
||||
}
|
||||
if (StringUtils.isBlank(taskId)) {
|
||||
taskId = flowService.getCurrentTaskIdByBusinessId("HIDDEN_DANGER_CHECK", String.valueOf(original.getId()));
|
||||
}
|
||||
if (StringUtils.isBlank(taskId)) {
|
||||
throw new ServiceException("当前记录未找到待处理任务,无法重新提交");
|
||||
}
|
||||
String submitOperatorId = currentUserId;
|
||||
var task = flowService.getTaskById(taskId);
|
||||
if (task == null) {
|
||||
throw new ServiceException("当前记录未找到待处理任务,无法重新提交");
|
||||
}
|
||||
if (!StringUtils.equals(task.getApproverId(), currentUserId)) {
|
||||
if (!DriverLoginContextHelper.isDriverPort() && !canResubmitRejectedRecord(original, currentUserId)) {
|
||||
throw new ServiceException("当前用户无权重新提交该记录");
|
||||
}
|
||||
submitOperatorId = task.getApproverId();
|
||||
}
|
||||
baseMapper.update(
|
||||
null,
|
||||
Wrappers.<HotHiddenDangerInspection>lambdaUpdate()
|
||||
.eq(HotHiddenDangerInspection::getId, original.getId())
|
||||
.set(HotHiddenDangerInspection::getStatus, 2L)
|
||||
.set(HotHiddenDangerInspection::getFlowStatus, "SUBMITTED")
|
||||
.set(HotHiddenDangerInspection::getAuditDate, null)
|
||||
.set(HotHiddenDangerInspection::getAuditConclusion, null)
|
||||
.set(HotHiddenDangerInspection::getApproverSignImgUrl, null)
|
||||
.set(HotHiddenDangerInspection::getAuditHasDanger, null)
|
||||
.set(HotHiddenDangerInspection::getAuditResult, null)
|
||||
.set(HotHiddenDangerInspection::getEvaluatorId, null)
|
||||
.set(HotHiddenDangerInspection::getEvaluatorName, null)
|
||||
);
|
||||
flowService.audit(taskId, true, "重新提交", submitOperatorId);
|
||||
}
|
||||
|
||||
private boolean canResubmitRejectedRecord(HotHiddenDangerInspection original, String currentUserId) {
|
||||
if (original == null || StringUtils.isBlank(currentUserId)) {
|
||||
return false;
|
||||
}
|
||||
if (StringUtils.equals(original.getCheckerId(), currentUserId)) {
|
||||
return true;
|
||||
}
|
||||
if (original.getCreateBy() != null && StringUtils.equals(String.valueOf(original.getCreateBy()), currentUserId)) {
|
||||
return true;
|
||||
}
|
||||
if (DriverLoginContextHelper.isDriverPort()) {
|
||||
try {
|
||||
HotDriver currentDriver = DriverLoginContextHelper.getCurrentDriver();
|
||||
if (currentDriver != null && StringUtils.equals(currentDriver.getId(), original.getCheckerId())) {
|
||||
return true;
|
||||
}
|
||||
if (currentDriver != null && original.getCreateBy() != null
|
||||
&& StringUtils.equals(currentDriver.getId(), String.valueOf(original.getCreateBy()))) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Resolve current driver for hidden danger resubmit failed, inspectionId={}", original.getId(), e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Long buildNextSubmitVersion(HotHiddenDangerInspection original) {
|
||||
@@ -453,6 +532,9 @@ public class HotHiddenDangerInspectionServiceImpl implements IHotHiddenDangerIns
|
||||
if (StringUtils.isBlank(taskId) && vo.getId() != null) {
|
||||
taskId = flowService.getTaskIdByBusinessId("HIDDEN_DANGER_CHECK", String.valueOf(vo.getId()), userId);
|
||||
}
|
||||
if (StringUtils.isBlank(taskId) && vo.getId() != null) {
|
||||
taskId = flowService.getCurrentTaskIdByBusinessId("HIDDEN_DANGER_CHECK", String.valueOf(vo.getId()));
|
||||
}
|
||||
vo.setTaskId(taskId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user