Commit 0c020d16 authored by 鲁鸿波's avatar 鲁鸿波

所有作业3天未完成的,需要重新发起申请。

危险作业到交底环节后按固定时间判断是否超时,超时自动取消
parent ad7f2c82
package com.testor.common.scheduler;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.testor.biz.sys.dict.data.model.domain.SysDictData;
import com.testor.biz.sys.org.model.domain.SysOrg;
import com.testor.common.core.constant.Constants;
import com.testor.module.hazard.dao.THazardWorkPlanDao;
import com.testor.module.hazard.dao.THazardWorkPlanExpiredLogDao;
import com.testor.module.hazard.model.domain.THazardWorkPlan;
import com.testor.module.hazard.model.domain.THazardWorkPlanExpiredLog;
import com.testor.module.hazard.model.enums.WorkPlanStatusEnum;
import com.testor.module.sys.model.domian.NewSysOrg;
import com.testor.module.sys.service.NewSysDictDataService;
import com.testor.common.util.DangerousOperationValidator;
import com.testor.module.sys.service.NewSysOrgService;
import com.tongtech.tfw.backend.common.biz.constants.BizConstants;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
......@@ -63,6 +69,9 @@ public class HazardWorkPlanScheduler {
@Autowired
private HistoryService historyService;
@Autowired
private NewSysOrgService orgService;
// 缓存:key = dictValue, value = SysDictData
private final Map<String, SysDictData> workTypeCache = new ConcurrentHashMap<>();
private final Map<String, SysDictData> workLevelCache = new ConcurrentHashMap<>();
......@@ -75,7 +84,7 @@ public class HazardWorkPlanScheduler {
/**
* 定时刷新字典缓存(每 10 分钟刷新一次,保证字典变更能生效)
*/
@Scheduled(cron = "0 0/10 * * * ?")
//@Scheduled(cron = "0 0/10 * * * ?")
public void refreshDictCacheScheduled() {
refreshDictCache();
}
......@@ -140,43 +149,6 @@ public class HazardWorkPlanScheduler {
log.info("结束---refreshSwitch-----查询所有危险作业已安全许可申请审批通过后未完成的作业");
}
/**
* 每小时检查所有未完成作业
*/
@Scheduled(cron = "0 0 * * * ?")
public void refreshSwitch1() {
if (!isSchedulerEnabled()) {
log.debug("refreshSwitch1: 调度被禁用(字典值非 {})", DICT_ENABLE_VALUE);
return;
}
log.info("开始---refreshSwitch1-------查询所有危险作业未完成的作业");
List<THazardWorkPlan> plans;
try {
plans = hazardWorkPlanDao.selectNotCompleteList();
} catch (Exception e) {
log.error("查询 selectNotCompleteList 失败", e);
return;
}
if (plans == null || plans.isEmpty()) {
log.info("refreshSwitch1: 无需处理的计划");
return;
}
for (THazardWorkPlan plan : plans) {
try {
checkThreeDaysExpiredRelaxed(plan);
} catch (Exception e) {
log.error("宽松检查处理异常,planId={}, code={}", plan == null ? null : plan.getId(),
plan == null ? null : plan.getCode(), e);
}
}
log.info("结束---refreshSwitch1-------查询所有危险作业未完成的作业");
}
/****************************
* 核心处理函数
****************************/
......@@ -217,6 +189,12 @@ public class HazardWorkPlanScheduler {
return;
}
NewSysOrg org = orgService.getOne(new QueryWrapper<NewSysOrg>().eq("org_id", plan.getOrgId()));
if(org.getParentIds().contains(Constants.DBGK_ORG_ID) || org.getOrgId().equals(Constants.DBGK_ORG_ID)){
plan.setBl(true);
}else{
plan.setBl(false);
}
// 计算从审批通过到现在的小时数
double actualHours = calculateHoursBetween(plan.getHazardLicensePassTime());
......@@ -278,57 +256,6 @@ public class HazardWorkPlanScheduler {
}
}
/**
* 检查3天过期逻辑
*/
private void checkThreeDaysExpiredRelaxed(THazardWorkPlan plan) {
if (plan == null) {
return;
}
double hoursSinceCreation = calculateHoursBetween(plan.getHazardLicensePassTime());
if (hoursSinceCreation > 72) {
handleThreeDaysExpired(plan, hoursSinceCreation);
} else {
log.debug("检查通过 - planId={}, hoursSinceCreation={}", plan.getId(), hoursSinceCreation);
}
}
private void handleThreeDaysExpired(THazardWorkPlan plan, double actualHours) {
log.warn("3天过期 - planId={}, code={}, hoursSinceCreation={}",
plan.getId(), plan.getCode(), actualHours);
// 记录日志
try {
THazardWorkPlanExpiredLog expiredLog = new THazardWorkPlanExpiredLog();
expiredLog.setPlanId(plan.getId());
expiredLog.setCode(plan.getCode());
expiredLog.setWorkType(plan.getWorkType());
expiredLog.setDangerLevel(plan.getWorkLevel());
expiredLog.setExpiredReason("作业创建后3天内未完成,需要重新发起申请");
expiredLog.setBeforeExpiration(plan.getWorkStatus());
expiredLog.setHazardLicensePassTime(plan.getHazardLicensePassTime());
expiredLog.setActualDurationHours(BigDecimal.valueOf(actualHours));
expiredLog.setPlanCreateDate(plan.getCreateDate());
expiredLog.setStatus("0");
expiredLog.setCreateBy("system-relaxed");
expiredLog.setCreateDate(new Date());
hazardWorkPlanExpiredLogDao.insert(expiredLog);
} catch (Exception e) {
log.error("记录3天过期日志失败,planId={}", plan.getId(), e);
}
// 停止流程并更新状态
stopFlowableProcess(plan);
try {
// 更新状态
updateOperationStatus(plan, WorkPlanStatusEnum.TIMEOUT_CANCELED.getValue());
} catch (Exception e) {
log.error("3天过期后更新作业状态失败,planId={}", plan.getId(), e);
}
}
/**
* 检查调度是否启用(通过字典开关)
*/
......
......@@ -183,7 +183,13 @@ public class DangerousOperationValidator {
//如果是非北良的熏蒸作业高度为1小时,如果是北良的为7天
if (level == DangerLevel.HIGH){
if(type == OperationType.FUMIGATION){
if(plan.isBl()){
timeLimit = 7 * 24;
}else{
timeLimit = 1;
}
}
}
// 特殊规则:进出仓、进仓、出仓作业的较大危险级别
......
......@@ -38,10 +38,5 @@ public interface THazardWorkPlanDao extends SuperDao<THazardWorkPlan>
*/
List<THazardWorkPlan> selectHazardLicensePassTime();
/**
* 查询所有危险作业未完成的作业
* @return
*/
List<THazardWorkPlan> selectNotCompleteList();
}
......@@ -331,6 +331,10 @@ public class THazardWorkPlan extends SuperModel
@TableField(exist = false)
private String currentTaskName;
@ApiModelProperty(value = "是否北良")
@TableField(exist = false)
private boolean bl;
public static final String ID ="id";
public static final String WORK_TYPE ="work_type";
......
......@@ -88,11 +88,4 @@
where status ='0' and hazard_license_pass_time is not null
and work_status in('4','8','9','10')
</select>
<select id="selectNotCompleteList" resultType="com.testor.module.hazard.model.domain.THazardWorkPlan">
select * from t_hazard_work_plan
where status ='0'
and work_status not in('0','5','6','12')
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment