AutoWarningClosureService.java 1.3 KB

123456789101112131415161718192021222324252627
  1. package com.zksy.api.service;
  2. import com.zksy.api.mapper.AutoWarningClosureMapper;
  3. import com.zksy.api.domain.EarlyWarning;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import java.time.LocalDateTime;
  8. import java.util.UUID;
  9. /** 状态和解除轨迹同事务提交;只关闭未发布的自动草稿,不覆盖人工流程。 */
  10. @Service
  11. public class AutoWarningClosureService {
  12. @Autowired private AutoWarningClosureMapper mapper;
  13. @Transactional(rollbackFor = Exception.class)
  14. public void close(String deviceCode, String marker, String reason) {
  15. EarlyWarning warning = mapper.lockDraft(deviceCode, marker);
  16. if (warning == null) return;
  17. LocalDateTime now = LocalDateTime.now();
  18. if (mapper.closeDraft(warning.getWarningId(), now) != 1)
  19. throw new IllegalStateException("自动预警状态更新失败");
  20. if (mapper.insertClosure(UUID.randomUUID().toString().replace("-", ""), warning.getWarningId(),
  21. reason == null || reason.trim().isEmpty() ? "监测值已恢复,系统自动解除" : reason, now) != 1)
  22. throw new IllegalStateException("自动解除处置记录保存失败");
  23. }
  24. }