Commit 2b1b4799 authored by 鲁鸿波's avatar 鲁鸿波

危险作业条件确认 bug修改

parent 34921ee4
...@@ -68,6 +68,33 @@ public class THazardConditionConfirmationServiceImpl extends SuperServiceImpl<TH ...@@ -68,6 +68,33 @@ public class THazardConditionConfirmationServiceImpl extends SuperServiceImpl<TH
THazardConditionConfirmation tHazardConditionConfirmation = BeanHelper.beanToBean(tHazardConditionConfirmationDTO, THazardConditionConfirmation.class); THazardConditionConfirmation tHazardConditionConfirmation = BeanHelper.beanToBean(tHazardConditionConfirmationDTO, THazardConditionConfirmation.class);
String id = tHazardConditionConfirmationDTO.getId(); String id = tHazardConditionConfirmationDTO.getId();
// ✅ 跨天保护:如果前端传入了id,先检查该id对应的记录是否属于今天
// 如果不是今天的记录(说明前端带着旧批次的id来提交新一天的数据),强制清空id走新增逻辑
if (StringUtils.isNotBlank(id)) {
THazardConditionConfirmation existingEntityCheck = this.getById(id);
if (existingEntityCheck != null) {
Date existingCreateDate = existingEntityCheck.getCreateDate();
if (existingCreateDate != null) {
LocalDate recordDate = existingCreateDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate today = LocalDate.now();
if (!today.isEqual(recordDate)) {
// 跨天保护触发:该id是历史批次的记录,强制走新增
log.warn("【跨天保护触发】传入id属于历史批次,强制走新增逻辑 - id: {}, recordDate: {}, today: {}",
id, recordDate, today);
id = null;
tHazardConditionConfirmationDTO.setId(null);
tHazardConditionConfirmation.setId(null);
}
}
}else{
log.warn("【无效id保护】传入id在数据库中不存在,强制走新增 - id: {}", id);
id = null;
tHazardConditionConfirmationDTO.setId(null); // ← 补上这两行
tHazardConditionConfirmation.setId(null); // ← 补上这两行
}
}
// 如果是新增操作 // 如果是新增操作
if (StringUtils.isBlank(id)) { if (StringUtils.isBlank(id)) {
log.info("【操作类型】新增操作 - 开始查询最大批次记录"); log.info("【操作类型】新增操作 - 开始查询最大批次记录");
...@@ -112,12 +139,14 @@ public class THazardConditionConfirmationServiceImpl extends SuperServiceImpl<TH ...@@ -112,12 +139,14 @@ public class THazardConditionConfirmationServiceImpl extends SuperServiceImpl<TH
tHazardConditionConfirmation.setBatch(newBatch); tHazardConditionConfirmation.setBatch(newBatch);
log.info("【批次设置】跨天新增 - 原批次: {}, 新批次: {}", maxBatch, newBatch); log.info("【批次设置】跨天新增 - 原批次: {}, 新批次: {}", maxBatch, newBatch);
} else { } else {
// 同一天,不允许新增 // ✅ 保护2:同一天已有记录,幂等处理,复用当天已有记录而不是报错
log.error("【批次设置失败】同一天重复新增 - planId: {}, workTypeId: {}, 已存在批次: {}", // 避免前端重复提交(如先暂存再提交)时用户看到报错
log.warn("【幂等保护】同一天已存在记录,复用当天已有数据 - planId: {}, workTypeId: {}, batch: {}",
tHazardConditionConfirmationDTO.getPlanId(), tHazardConditionConfirmationDTO.getPlanId(),
tHazardConditionConfirmationDTO.getWorkTypeId(), tHazardConditionConfirmationDTO.getWorkTypeId(),
maxRecord.getBatch()); maxRecord.getBatch());
throw new ServiceException("同一天只能新增一次同作业类型的安全条件确认"); tHazardConditionConfirmation.setId(maxRecord.getId());
tHazardConditionConfirmation.setBatch(maxRecord.getBatch());
} }
} else { } else {
// ✅ 关键修复:没有历史记录时,设置初始批次为1 // ✅ 关键修复:没有历史记录时,设置初始批次为1
......
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