代码调整

This commit is contained in:
tiger_zhou 2023-09-12 17:06:58 +08:00
parent 84e79a7b66
commit d41a47bf4c
2 changed files with 13 additions and 14 deletions

View File

@ -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}")

View File

@ -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<DeviceAreaConfig> areaConfigList = this.areaConfigService.getCache(ar.getLineId(), AlertDeviceType.valueOf(ar.getAlertDeviceType()));
List<DeviceAreaConfig> findList = areaConfigList.stream().filter(d -> StringUtils.contains(d.getAlertTypes(), ar.getAlertType())).filter(d -> {
List<DeviceAreaConfig> 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<AlertTip> 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<AlertTip> 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;
}