From d41a47bf4c02d0ada7b2e2e4dad7a50efab24e8c Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Tue, 12 Sep 2023 17:06:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AlertRecordController.java | 6 +++--- .../xiannccda/service/AlertRecordService.java | 21 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java b/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java index 8e9731d..3baf1f4 100644 --- a/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java +++ b/src/main/java/club/joylink/xiannccda/controller/AlertRecordController.java @@ -42,12 +42,12 @@ public class AlertRecordController { this.alertRecordService = alertRecordService; } - @GetMapping("/confirm/{recordId}") + @GetMapping("/confirm/{recordId}/{tipType}") @SecurityRequirement(name = "jwt") @Operation(summary = "报警信息确认") @ApiResponse(description = "报警信息确认") - public AlertTip confirm(@PathVariable("recordId") Long recordId, @RequestParam(value = "alertLocationId", required = false) Long locationId) { - return this.alertRecordService.confirm(recordId, locationId); + public AlertTip confirm(@PathVariable("recordId") Long recordId, @PathVariable("tipType") String tipType, @RequestParam(value = "alertLocationId", required = false) Long locationId) { + return this.alertRecordService.confirm(recordId, tipType, locationId); } @GetMapping("/fail/{recordId}") diff --git a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java index 5bee539..b7890db 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java @@ -44,17 +44,17 @@ public class AlertRecordService { this.areaConfigService = areaConfigService; } - private Long findAreaConfig(AlertRecord ar) { + private Long findAreaConfig(AlertRecord ar, String tipType) { String deviceId = ar.getAlertDeviceId(); if (StringUtils.isEmpty(deviceId)) { log.info("告警数据确认,数据中未找到对应的设备id线路[{}] 记录id[{}] ", ar.getLineId(), ar.getId()); return null; } - AlertType alertType = AlertType.valueOf(ar.getAlertType()); + AlertType alertType = AlertType.valueOf(tipType); switch (alertType) { case AXLE_LED_RED, AXLE_LED_ORANGE, SWITCH_All_LOST, SWITCH_DW_LOST, SWITCH_FW_LOST -> { List areaConfigList = this.areaConfigService.getCache(ar.getLineId(), AlertDeviceType.valueOf(ar.getAlertDeviceType())); - List findList = areaConfigList.stream().filter(d -> StringUtils.contains(d.getAlertTypes(), ar.getAlertType())).filter(d -> { + List findList = areaConfigList.stream().filter(d -> StringUtils.contains(d.getAlertTypes(), tipType)).filter(d -> { String[] datas = d.getData().split(","); return Arrays.binarySearch(datas, deviceId) >= 0; }).toList(); @@ -71,22 +71,21 @@ public class AlertRecordService { } } - public AlertTip confirm(Long recordId, Long areaConfigId) { + public AlertTip confirm(Long recordId, String tipType, Long areaConfigId) { AlertRecord ar = this.alertRecordRepository.getById(recordId); - Long newAreaConfigId = this.findAreaConfig(ar); + Long newAreaConfigId = this.findAreaConfig(ar, tipType); if (Objects.isNull(newAreaConfigId)) { newAreaConfigId = areaConfigId; } - LambdaQueryWrapper qw = Wrappers.lambdaQuery(AlertTip.class).eq(AlertTip::getAlertType, ar.getAlertType()); - if (Objects.nonNull(newAreaConfigId) && newAreaConfigId > 0L) { - qw.eq(AlertTip::getAreaConfigId, newAreaConfigId); - } - AlertTip tip = alertTipRepository.getOne(qw, false); + boolean hasAreaConfigId = Objects.nonNull(newAreaConfigId) && newAreaConfigId > 0L; + LambdaQueryWrapper qw = Wrappers.lambdaQuery(AlertTip.class).eq(AlertTip::getAlertType, tipType); + qw.eq(hasAreaConfigId, AlertTip::getAreaConfigId, newAreaConfigId); + AlertTip tip = alertTipRepository.getOne(qw, false); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(tip), "未找到对应的决策辅助信息"); this.alertRecordRepository.update(Wrappers.lambdaUpdate(AlertRecord.class) .set(AlertRecord::getAlertTipId, tip.getId()).set(AlertRecord::getAlarmStatus, 1) - .set(Objects.nonNull(newAreaConfigId), AlertRecord::getAlertLocationId, newAreaConfigId) + .set(hasAreaConfigId, AlertRecord::getAlertLocationId, newAreaConfigId) .eq(AlertRecord::getId, recordId).isNull(AlertRecord::getAlarmStatus)); return tip; }