From fda0e3ff796d82232e2cb9e32ef094a71c0b1628 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 7 Nov 2024 09:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=85=E9=9A=9C=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/alert/AlertListenerJob.java | 12 ++ .../warn/bule/BuleDisplayMonitoringTask.java | 3 + ...Task.java => SwitchLostAndJammedTask.java} | 54 ++++++--- .../warn/platform/PlatformEmergStopTask.java | 7 +- .../constants/common/FaultQueryType.java | 14 +++ .../controller/FaultQueryController.java | 105 +++++++++++++++++ .../xiannccda/controller/UserController.java | 3 - .../xiannccda/dto/fq/FaultQueryReqDTO.java | 12 ++ .../joylink/xiannccda/dto/fq/FaultType.java | 16 +++ .../xiannccda/dto/protos/AlertConstProto.java | 31 +++-- .../xiannccda/mapper/FaultQueryMapper.java | 18 +++ .../repository/IFaultQueryRepository.java | 21 ++++ .../repository/impl/FaultQueryRepository.java | 45 ++++++++ .../xiannccda/service/AlertTipService.java | 13 ++- .../config/DeviceAreaConfigService.java | 21 ++-- .../xiannccda/MybatisPlusGenerator.java | 4 +- .../device/DeviceStatusCheckTest.java | 2 +- .../joylink/xiannccda/util/CollectorData.java | 7 +- .../xiannccda/util/impo/SwitchImportTest.java | 108 ++++++++++++++++-- 19 files changed, 440 insertions(+), 56 deletions(-) rename src/main/java/club/joylink/xiannccda/ats/warn/lost/{SwitchLostTask.java => SwitchLostAndJammedTask.java} (52%) create mode 100644 src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java create mode 100644 src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/fq/FaultQueryReqDTO.java create mode 100644 src/main/java/club/joylink/xiannccda/dto/fq/FaultType.java create mode 100644 src/main/java/club/joylink/xiannccda/mapper/FaultQueryMapper.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java create mode 100644 src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java index 09f0cd7..4f41b6a 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java @@ -65,6 +65,7 @@ public class AlertListenerJob implements ApplicationRunner { //不论是否mock 都保存数据库 OccClientMessage clientMessage = serverProto.getClientMessage(alertInfo.getLineId()); +/* if (alertInfo.getAlertType() == AlertType.PLATFORM_EMERG_STOP) { NccAlertInfo cloned = alertInfo.clone2(); cloned.setLineType(LineTypeEnum.OCC); @@ -84,6 +85,17 @@ public class AlertListenerJob implements ApplicationRunner { nccAlertMessageServer.addMsg(cloned); } } +*/ + + for (LineTypeEnum lineType : clientMessage.getLineTypes()) { + NccAlertInfo cloned = alertInfo.clone2(); + cloned.setLineType(lineType); + AlertRecord record = convertToRecord(cloned); + alertRecordRepository.save(record); + cloned.setId(record.getId()); + NccAlertMessageServer nccAlertMessageServer = NccAlertMessageServer.getInstance(lineType); + nccAlertMessageServer.addMsg(cloned); + } } }); diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/bule/BuleDisplayMonitoringTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/bule/BuleDisplayMonitoringTask.java index 27b7af9..6b25163 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/bule/BuleDisplayMonitoringTask.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/bule/BuleDisplayMonitoringTask.java @@ -88,6 +88,9 @@ public class BuleDisplayMonitoringTask implements AlertMonitoringTask { List collectRtuList = this.findRtuBuild(lineId, builderMap); Map> rtuVOMapList = collectRtuList.stream().collect(Collectors.groupingBy(d -> d.areaConfigVO.getId())); int interLockCount = rtuVOMapList.keySet().size(); + if (interLockCount == 0) { + continue; + } List allShutdownList = rtuVOMapList.values().stream().map(Collection::stream).map(ls -> ls.anyMatch(r -> Objects.nonNull(r.rtu) && r.rtu.getIpRtuStusDown())).toList(); if (allShutdownList.size() == interLockCount && allShutdownList.stream().allMatch(d -> d)) { if (alertDataSource.putAlterDevice(lineId, ALL_BULE_DISPLAY_NAME, "All")) { diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAndJammedTask.java similarity index 52% rename from src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostTask.java rename to src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAndJammedTask.java index 0e18d33..a4ca176 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostTask.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/lost/SwitchLostAndJammedTask.java @@ -25,12 +25,12 @@ import org.springframework.stereotype.Component; @Component @Slf4j -public class SwitchLostTask implements AlertMonitoringTask { +public class SwitchLostAndJammedTask implements AlertMonitoringTask { private DeviceGuardConfigService configService; private AlertInfoService alertInfoService; - public SwitchLostTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) { + public SwitchLostAndJammedTask(DeviceGuardConfigService configService, AlertInfoService alertInfoService) { this.configService = configService; this.alertInfoService = alertInfoService; } @@ -63,23 +63,41 @@ public class SwitchLostTask implements AlertMonitoringTask { private void handle(Builder deviceBuild) { if (deviceBuild instanceof Switch.Builder switchBuild) { - GuardConfig guardConfig = this.configService.getGuardConfig(switchBuild.getLineId()); - boolean isLost = switchBuild.getIpSingleSwitchStusLostIndication(); - if (isLost && this.timeOver(switchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) { - Optional turnoutOpt = LineGraphicDataRepository.getDeviceOptByCode(switchBuild.getLineId(), switchBuild.getId(), Turnout.class); - String layoutId = turnoutOpt.map(d -> String.valueOf(d.getCommon().getId())).orElse(""); - if (alertDataSource.putAlterDevice(switchBuild.getLineId(), this.getName(), switchBuild.getId())) { - log.info("道岔失表超时,准备报警 线路[{}] 设备[{}] 接受时间[{}] 发送时间[{}] 对应地图设备id[{}]" - , switchBuild.getLineId(), switchBuild.getId(), switchBuild.getReceiveTime(), switchBuild.getTimestamp(), layoutId); - String alertMsg = String.format("设备[%s]失表", switchBuild.getId()); - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.SWITCH_LOST, switchBuild, alertMsg, layoutId, - AlertDeviceType.DEVICE_TYPE_SWITCH, false); - alertManager.emit(alertInfo); - } - } else { - alertDataSource.removeAlterDevice(switchBuild.getLineId(), this.getName(), switchBuild.getId()); - } + Optional turnoutOpt = LineGraphicDataRepository.getDeviceOptByCode(switchBuild.getLineId(), switchBuild.getId(), Turnout.class); + String layoutId = turnoutOpt.map(d -> String.valueOf(d.getCommon().getId())).orElse(""); + this.checkLost(switchBuild, layoutId); + this.checkJammed(switchBuild, layoutId); } } + private void checkLost(Switch.Builder switchBuild, String layoutId) { + GuardConfig guardConfig = this.configService.getGuardConfig(switchBuild.getLineId()); + boolean isLost = switchBuild.getIpSingleSwitchStusLostIndication(); + if (isLost && this.timeOver(switchBuild.getReceiveTime(), guardConfig.getSwitchLostTimes())) { + if (alertDataSource.putAlterDevice(switchBuild.getLineId(), this.getName(), switchBuild.getId())) { + log.info("道岔失表超时,准备报警 线路[{}] 设备[{}] 接受时间[{}] 发送时间[{}] 对应地图设备id[{}]" + , switchBuild.getLineId(), switchBuild.getId(), switchBuild.getReceiveTime(), switchBuild.getTimestamp(), layoutId); + String alertMsg = String.format("设备[%s]失表", switchBuild.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.SWITCH_LOST, switchBuild, alertMsg, layoutId, + AlertDeviceType.DEVICE_TYPE_SWITCH, false); + alertManager.emit(alertInfo); + } + } else { + alertDataSource.removeAlterDevice(switchBuild.getLineId(), this.getName(), switchBuild.getId()); + } + } + + + private final static String JAMMED_NAME = "JAMMED"; + + private void checkJammed(Switch.Builder switchBuild, String layoutId) { + if (switchBuild.getIpSingleSwitchStusJammed()) { + String alertMsg = String.format("设备[%s]挤岔", switchBuild.getId()); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.SWITCH_JAMMED, switchBuild, alertMsg, layoutId, + AlertDeviceType.DEVICE_TYPE_SWITCH, false); + alertManager.emit(alertInfo); + } else { + alertDataSource.removeAlterDevice(switchBuild.getLineId(), JAMMED_NAME, switchBuild.getId()); + } + } } diff --git a/src/main/java/club/joylink/xiannccda/ats/warn/platform/PlatformEmergStopTask.java b/src/main/java/club/joylink/xiannccda/ats/warn/platform/PlatformEmergStopTask.java index dfd2c74..364f143 100644 --- a/src/main/java/club/joylink/xiannccda/ats/warn/platform/PlatformEmergStopTask.java +++ b/src/main/java/club/joylink/xiannccda/ats/warn/platform/PlatformEmergStopTask.java @@ -57,9 +57,10 @@ public class PlatformEmergStopTask implements AlertMonitoringTask { if (alertDataSource.putAlterDevice(lineIdInt, this.getName(), platformBuild.getId())) { Integer layOutId = giPlatform.getCommon().getId(); Station station = LineGraphicDataRepository.getDeviceByCode(lineIdInt, giPlatform.getRefStation() + "", Station.class); - - Optional optional = alertInfoService.findAreaDevice(AlertType.PLATFORM_EMERG_STOP, AlertDeviceType.DEVICE_TYPE_PLATFORM, layOutId, lineIdInt); - NccAlertInfo alertInfo = this.alertInfoService.createAlert2(optional, AlertType.PLATFORM_EMERG_STOP, platformBuild, "aaaaa", layOutId.toString(), + String upWay = giPlatform.getUp() ? "上行" : "下行"; + String msg = String.format("%s-%s站台 应急触发", station.getName(), upWay); +// Optional optional = alertInfoService.findAreaDevice(AlertType.PLATFORM_EMERG_STOP, AlertDeviceType.DEVICE_TYPE_PLATFORM, layOutId, lineIdInt); + NccAlertInfo alertInfo = this.alertInfoService.createAlert2(Optional.empty(), AlertType.PLATFORM_EMERG_STOP, platformBuild, msg, layOutId.toString(), AlertDeviceType.DEVICE_TYPE_PLATFORM, false); alertManager.emit(alertInfo); } diff --git a/src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java b/src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java new file mode 100644 index 0000000..3e1c546 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java @@ -0,0 +1,14 @@ +package club.joylink.xiannccda.constants.common; + +public enum FaultQueryType { + // FAULT_EMERGENCY_GUIDE 开头是应急故障,FAULT_EXIT_SERVICE 开头是故障退出服务 +// T 代表车辆,T后面代表车辆型号 + FAULT_EMERGENCY_GUIDE, + FAULT_EXIT_SERVICE, + FAULT_EMERGENCY_GUIDE_T_DK37, + FAULT_EXIT_SERVICE_T_DK37, + + FAULT_EMERGENCY_GUIDE_T_CCD_5037, + FAULT_EXIT_SERVICE_T_CCD_5037, + ; +} diff --git a/src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java b/src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java new file mode 100644 index 0000000..4f32428 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java @@ -0,0 +1,105 @@ +package club.joylink.xiannccda.controller; + +import club.joylink.xiannccda.constants.common.CommonLogAnno; +import club.joylink.xiannccda.constants.common.CommonLogTypeEnum; +import club.joylink.xiannccda.constants.common.CommonLogTypeEnum.SubEventType; +import club.joylink.xiannccda.constants.common.FaultQueryType; +import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto; +import club.joylink.xiannccda.dto.alertTip.AlertTipQueryDTO; +import club.joylink.xiannccda.dto.alertTip.AlertTipSaveDTO; +import club.joylink.xiannccda.dto.fq.FaultQueryReqDTO; +import club.joylink.xiannccda.dto.fq.FaultType; +import club.joylink.xiannccda.entity.AlertTip; +import club.joylink.xiannccda.entity.FaultQuery; +import club.joylink.xiannccda.repository.IFaultQueryRepository; +import com.baomidou.mybatisplus.core.metadata.IPage; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Collections; +import java.util.List; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + *

+ * 前端控制器 + *

+ * + * @author walker-sheng + * @since 2024-11-06 + */ +@RestController +@RequestMapping("/fault/query") +@Tag(name = "故障查询管理") +public class FaultQueryController { + + + private IFaultQueryRepository faultQueryRepository; + + public FaultQueryController(IFaultQueryRepository faultQueryRepository) { + this.faultQueryRepository = faultQueryRepository; + } + + @SecurityRequirement(name = "jwt") + @Operation(summary = "查询故障类型") + @GetMapping("/type/{lineId}") +// @CommonLogAnno(name = "决策信息-查看", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) + public List faultType(@PathVariable("lineId") Integer lineId) { + if (lineId == 3) { + return List.of(new FaultType(FaultQueryType.FAULT_EMERGENCY_GUIDE, "车辆故障应急处置指导关键点"), new FaultType(FaultQueryType.FAULT_EXIT_SERVICE, "车辆故障退出服务地点")); + } else if (lineId == 4) { + return List.of(new FaultType(FaultQueryType.FAULT_EMERGENCY_GUIDE_T_DK37, "车辆故障应急处置指导关键点-DK37车型"), + new FaultType(FaultQueryType.FAULT_EXIT_SERVICE_T_DK37, "车辆故障退出服务地点-DK37车型") + , new FaultType(FaultQueryType.FAULT_EMERGENCY_GUIDE_T_CCD_5037, "车辆故障应急处置指导关键点CCD-5037车型"), + new FaultType(FaultQueryType.FAULT_EXIT_SERVICE_T_CCD_5037, "车辆故障退出服务地点CCD-5037车型") + ); + } + return Collections.emptyList(); + } + + @SecurityRequirement(name = "jwt") + @Operation(summary = "保存故障查询") + @PostMapping() +// @CommonLogAnno(name = "决策信息-保存修改", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.SAVE_OR_UPDATE) + public void save(@RequestBody @Validated FaultQuery fq) { + this.faultQueryRepository.newSaveOrUpdate(fq); + } + + + @SecurityRequirement(name = "jwt") + @Operation(summary = "根据id查询数据") + @GetMapping("/{id}") +// @CommonLogAnno(name = "决策信息-查看", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) + public FaultQuery getById(@PathVariable int id) { + return faultQueryRepository.getById(id); + + } + + @SecurityRequirement(name = "jwt") + @Operation(summary = "分页查询故障信息") + @ApiResponse(description = "分页查询故障信息") + @GetMapping("/page") +// @CommonLogAnno(name = "决策信息-分页列表", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) + public IPage pageAlertTips(FaultQueryReqDTO req) { + return this.faultQueryRepository.page(req); + } + + + @SecurityRequirement(name = "jwt") + @Operation(summary = "根据id删除数据") + @ApiResponse(description = "是否确实删除掉了一条数据") + @DeleteMapping("/id/{id}") +// @CommonLogAnno(name = "决策信息-删除", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.DELETE) + public boolean deleteById(@PathVariable int id) { + return this.faultQueryRepository.removeById(id); + } + +} diff --git a/src/main/java/club/joylink/xiannccda/controller/UserController.java b/src/main/java/club/joylink/xiannccda/controller/UserController.java index 9cf4c18..b9031eb 100644 --- a/src/main/java/club/joylink/xiannccda/controller/UserController.java +++ b/src/main/java/club/joylink/xiannccda/controller/UserController.java @@ -9,8 +9,6 @@ import club.joylink.xiannccda.dto.user.UserEditDTO; import club.joylink.xiannccda.dto.user.UserInfoAuthDTO; import club.joylink.xiannccda.dto.user.UserQueryDTO; import club.joylink.xiannccda.dto.user.UserTokenDTO; -import club.joylink.xiannccda.entity.User; -import club.joylink.xiannccda.entity.User.Register; import club.joylink.xiannccda.repository.IUserRepository; import club.joylink.xiannccda.service.UserService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -20,7 +18,6 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import java.security.Principal; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; diff --git a/src/main/java/club/joylink/xiannccda/dto/fq/FaultQueryReqDTO.java b/src/main/java/club/joylink/xiannccda/dto/fq/FaultQueryReqDTO.java new file mode 100644 index 0000000..196c7bd --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/fq/FaultQueryReqDTO.java @@ -0,0 +1,12 @@ +package club.joylink.xiannccda.dto.fq; + +import club.joylink.xiannccda.constants.common.FaultQueryType; +import club.joylink.xiannccda.dto.CommonPage; +import lombok.Data; + +@Data +public class FaultQueryReqDTO extends CommonPage { + + private Integer lineId; + private FaultQueryType queryType; +} diff --git a/src/main/java/club/joylink/xiannccda/dto/fq/FaultType.java b/src/main/java/club/joylink/xiannccda/dto/fq/FaultType.java new file mode 100644 index 0000000..3745381 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/fq/FaultType.java @@ -0,0 +1,16 @@ +package club.joylink.xiannccda.dto.fq; + +import club.joylink.xiannccda.constants.common.FaultQueryType; +import lombok.Data; + +@Data +public class FaultType { + + private String faultType; + private String typeName; + + public FaultType(FaultQueryType qt, String name) { + this.faultType = qt.name(); + this.typeName = name; + } +} diff --git a/src/main/java/club/joylink/xiannccda/dto/protos/AlertConstProto.java b/src/main/java/club/joylink/xiannccda/dto/protos/AlertConstProto.java index 4f58a6c..56760e9 100644 --- a/src/main/java/club/joylink/xiannccda/dto/protos/AlertConstProto.java +++ b/src/main/java/club/joylink/xiannccda/dto/protos/AlertConstProto.java @@ -383,6 +383,14 @@ public final class AlertConstProto { * PLATFORM_EMERG_STOP = 24; */ PLATFORM_EMERG_STOP(24), + /** + *
+     *  道岔挤岔
+     * 
+ * + * SWITCH_JAMMED = 25; + */ + SWITCH_JAMMED(25), UNRECOGNIZED(-1), ; @@ -566,6 +574,14 @@ public final class AlertConstProto { * PLATFORM_EMERG_STOP = 24; */ public static final int PLATFORM_EMERG_STOP_VALUE = 24; + /** + *
+     *  道岔挤岔
+     * 
+ * + * SWITCH_JAMMED = 25; + */ + public static final int SWITCH_JAMMED_VALUE = 25; public final int getNumber() { @@ -615,6 +631,7 @@ public final class AlertConstProto { case 22: return SWITCH_LOST_INTERLOCK_AREA; case 23: return INTERLOCK_LEVEL_ONE; case 24: return PLATFORM_EMERG_STOP; + case 25: return SWITCH_JAMMED; default: return null; } } @@ -858,7 +875,7 @@ public final class AlertConstProto { "\n\020alertConst.proto\022\005alert*g\n\rAlertLocati" + "on\022\032\n\026ALERT_LOCATION_UNKNOWN\020\000\022\006\n\002QX\020\001\022\013" + "\n\007YHZ_LSQ\020\002\022\013\n\007HJM_LSQ\020\003\022\013\n\007BCT_LSQ\020\004\022\013\n" + - "\007BSQ_LSQ\020\005*\304\004\n\tAlertType\022\026\n\022ALERT_TYPE_U" + + "\007BSQ_LSQ\020\005*\327\004\n\tAlertType\022\026\n\022ALERT_TYPE_U" + "NKNOWN\020\000\022\020\n\014BLUE_DISPLAY\020\001\022\021\n\rTRAIN_DELA" + "Y_2\020\002\022\022\n\016TRAIN_DELAY_10\020\003\022\'\n#PLATFORM_DO" + "OR_WITHOUT_LOCKED_SIGNAL\020\004\022\035\n\031PLATFORM_D" + @@ -872,12 +889,12 @@ public final class AlertConstProto { "\020\023\022\037\n\033AXLE_LED_RED_INTERLOCK_AREA\020\024\022\"\n\036A" + "XLE_LED_ORANGE_INTERLOCK_AREA\020\025\022\036\n\032SWITC" + "H_LOST_INTERLOCK_AREA\020\026\022\027\n\023INTERLOCK_LEV" + - "EL_ONE\020\027\022\027\n\023PLATFORM_EMERG_STOP\020\030*x\n\rTip" + - "TimeConfig\022\026\n\022HOLIDAYS_MORN_PEAK\020\000\022\031\n\025HO" + - "LIDAYS_EVENING_PEAK\020\001\022\r\n\tMORN_PEAK\020\002\022\021\n\r" + - "EVENING_PEARK\020\003\022\022\n\016NORMAL_UNPEARK\020\004B4\n!c" + - "lub.joylink.xiannccda.dto.protosB\017AlertC" + - "onstProtob\006proto3" + "EL_ONE\020\027\022\027\n\023PLATFORM_EMERG_STOP\020\030\022\021\n\rSWI" + + "TCH_JAMMED\020\031*x\n\rTipTimeConfig\022\026\n\022HOLIDAY" + + "S_MORN_PEAK\020\000\022\031\n\025HOLIDAYS_EVENING_PEAK\020\001" + + "\022\r\n\tMORN_PEAK\020\002\022\021\n\rEVENING_PEARK\020\003\022\022\n\016NO" + + "RMAL_UNPEARK\020\004B4\n!club.joylink.xiannccda" + + ".dto.protosB\017AlertConstProtob\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, diff --git a/src/main/java/club/joylink/xiannccda/mapper/FaultQueryMapper.java b/src/main/java/club/joylink/xiannccda/mapper/FaultQueryMapper.java new file mode 100644 index 0000000..b65840f --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/mapper/FaultQueryMapper.java @@ -0,0 +1,18 @@ +package club.joylink.xiannccda.mapper; + +import club.joylink.xiannccda.entity.FaultQuery; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author walker-sheng + * @since 2024-11-06 + */ +@Mapper +public interface FaultQueryMapper extends BaseMapper { + +} diff --git a/src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java b/src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java new file mode 100644 index 0000000..0613e5d --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java @@ -0,0 +1,21 @@ +package club.joylink.xiannccda.repository; + +import club.joylink.xiannccda.dto.fq.FaultQueryReqDTO; +import club.joylink.xiannccda.entity.FaultQuery; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author walker-sheng + * @since 2024-11-06 + */ +public interface IFaultQueryRepository extends IService { + + void newSaveOrUpdate(FaultQuery fq); + + IPage page(FaultQueryReqDTO reqDTO); +} diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java new file mode 100644 index 0000000..e21bcb9 --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java @@ -0,0 +1,45 @@ +package club.joylink.xiannccda.repository.impl; + +import club.joylink.xiannccda.dto.CommonPageRequest; +import club.joylink.xiannccda.dto.fq.FaultQueryReqDTO; +import club.joylink.xiannccda.entity.FaultQuery; +import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; +import club.joylink.xiannccda.mapper.FaultQueryMapper; +import club.joylink.xiannccda.repository.IFaultQueryRepository; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.Objects; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author walker-sheng + * @since 2024-11-06 + */ +@Service +public class FaultQueryRepository extends ServiceImpl implements IFaultQueryRepository { + + @Override + public void newSaveOrUpdate(FaultQuery fq) { + if (fq.getId() == null) { + this.save(fq); + } else { + FaultQuery nfq = this.getById(fq.getId()); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(nfq)); + this.updateById(fq); + } + + } + + @Override + public IPage page(FaultQueryReqDTO reqDTO) { + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(Objects.nonNull(reqDTO.getLineId()), FaultQuery::getLineId, reqDTO.getLineId()) + .eq(Objects.nonNull(reqDTO.getQueryType()), FaultQuery::getFaultType, reqDTO.getQueryType()); + return this.page(CommonPageRequest.defaultPage(), qw); + } +} diff --git a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java index b0dddfd..1e0beb9 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java @@ -18,6 +18,8 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.base.Joiner; import com.google.common.base.Splitter; +import com.google.common.collect.Lists; +import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -85,9 +87,14 @@ public class AlertTipService { entity.setLineId(saveDTO.getLineId()); entity.setLineType(saveDTO.getLineType()); if (CollectionUtils.isNotEmpty(saveDTO.getTipTimeIds())) { - String selectIds = this.timeConfigService.getCache().stream().filter(d -> saveDTO.getTipTimeIds().contains(d.getTimeType())).map(d -> d.getId().toString()) - .collect(Collectors.joining(StringPool.COMMA)); - entity.setTipTimeRef(selectIds); + Collection obj = this.timeConfigService.getCache(); + List refTimeIdList = Lists.newArrayList(); + for (AlertTipTimeConfig timeConfig : obj) { + if (saveDTO.getTipTimeIds().contains(timeConfig.getTimeType())) { + refTimeIdList.add(timeConfig.getId().toString()); + } + } + entity.setTipTimeRef(Joiner.on(",").join(refTimeIdList)); } else { entity.setTipTimeRef(""); } diff --git a/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java b/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java index 55abd2b..e78e3c8 100644 --- a/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java +++ b/src/main/java/club/joylink/xiannccda/service/config/DeviceAreaConfigService.java @@ -78,8 +78,10 @@ public class DeviceAreaConfigService { private void checkDataForSql(DeviceAreaConfigDto dto, boolean isUpdate) { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(DeviceAreaConfig.class); + queryWrapper.eq(DeviceAreaConfig::getLineId, dto.getLineId()); queryWrapper.eq(DeviceAreaConfig::getDeviceType, dto.getDeviceType()); queryWrapper.ne(isUpdate, DeviceAreaConfig::getId, dto.getId()); + List lastSqlList = Lists.newArrayList(); for (String alertType : dto.getAlertTypes()) { lastSqlList.add(String.format(" find_in_set('%s',%s) > 0 ", alertType, DeviceAreaConfig.ALERT_TYPES)); @@ -93,11 +95,14 @@ public class DeviceAreaConfigService { List areaConfigList = this.deviceAreaConfigRepository.list(queryWrapper); for (DeviceAreaConfig areaConfig : areaConfigList) { - List dbDatas = Splitter.on(StringPool.COMMA).splitToList(areaConfig.getData()); - List saveDatas = Lists.newArrayList(dto.getData()); - saveDatas.retainAll(dbDatas); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isEmpty(saveDatas), - String.format("添加重复的设备区域[%s] 设备:%s", areaConfig.getAreaName(), this.findDevice(areaConfig.getLineId(), saveDatas))); + if (StringUtils.isNotEmpty(areaConfig.getData())) { + List dbDatas = Splitter.on(StringPool.COMMA).splitToList(areaConfig.getData()); + List saveDatas = Lists.newArrayList(dto.getData()); + saveDatas.retainAll(dbDatas); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(CollectionUtils.isEmpty(saveDatas), + String.format("添加重复的设备区域[%s] 设备:%s", areaConfig.getAreaName(), this.findDevice(areaConfig.getLineId(), saveDatas))); + } + } } @@ -139,9 +144,11 @@ public class DeviceAreaConfigService { DeviceAreaConfigDto deviceAreaConfig = new DeviceAreaConfigDto(); deviceAreaConfig.setLineId(dto.getLineId()); deviceAreaConfig.setAreaName(dto.getAreaName()); - List datas = Splitter.on(StringPool.COMMA).splitToList(dto.getData()); + if (StringUtils.isNotEmpty(dto.getData())) { + List datas = Splitter.on(StringPool.COMMA).splitToList(dto.getData()); + deviceAreaConfig.setData(datas); + } - deviceAreaConfig.setData(datas); deviceAreaConfig.setDeviceType(dto.getDeviceType()); if (StringUtils.isNotEmpty(dto.getAlertTypes())) { List ll = Splitter.on(StringPool.COMMA).splitToList(dto.getAlertTypes()); diff --git a/src/test/java/club/joylink/xiannccda/MybatisPlusGenerator.java b/src/test/java/club/joylink/xiannccda/MybatisPlusGenerator.java index 871a54a..8e35cd6 100644 --- a/src/test/java/club/joylink/xiannccda/MybatisPlusGenerator.java +++ b/src/test/java/club/joylink/xiannccda/MybatisPlusGenerator.java @@ -29,8 +29,8 @@ public class MybatisPlusGenerator { private static final List includeTableList = new ArrayList<>(); static { - includeTableList.add("relieve_device_shere"); - includeTableList.add("relieve_time_shere"); + includeTableList.add("fault_query"); +// includeTableList.add("relieve_time_shere"); } public static void main(String[] args) { diff --git a/src/test/java/club/joylink/xiannccda/device/DeviceStatusCheckTest.java b/src/test/java/club/joylink/xiannccda/device/DeviceStatusCheckTest.java index b135788..6797136 100644 --- a/src/test/java/club/joylink/xiannccda/device/DeviceStatusCheckTest.java +++ b/src/test/java/club/joylink/xiannccda/device/DeviceStatusCheckTest.java @@ -71,7 +71,7 @@ public class DeviceStatusCheckTest { DeviceStatusProto.Switch.Builder s1 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, 40); System.out.println(s1); System.out.println("-----------------"); - DeviceStatusProto.Switch.Builder s2 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, 134217992); + DeviceStatusProto.Switch.Builder s2 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, 134217728); System.out.println(s2); System.out.println("-----------------"); DeviceStatusProto.Switch.Builder s3 = DeviceStatusConvertor.convert(DeviceStatus.SWITCH.class, 2); diff --git a/src/test/java/club/joylink/xiannccda/util/CollectorData.java b/src/test/java/club/joylink/xiannccda/util/CollectorData.java index 4f6c345..e6852c9 100644 --- a/src/test/java/club/joylink/xiannccda/util/CollectorData.java +++ b/src/test/java/club/joylink/xiannccda/util/CollectorData.java @@ -12,7 +12,6 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Lists; @@ -33,6 +32,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -60,8 +60,11 @@ public class CollectorData { StringBuilder sb = new StringBuilder(); for (String s : v) { String[] ssss = s.split("\u0000"); + String trackName = ssss[0]; + if (StringUtils.startsWith(trackName, "DG")) { + newList.add(ssss[0]); - newList.add(ssss[0]); + } } writer.write("\t\t" + newList.stream().sorted().collect(Collectors.joining(",")) + "\n"); diff --git a/src/test/java/club/joylink/xiannccda/util/impo/SwitchImportTest.java b/src/test/java/club/joylink/xiannccda/util/impo/SwitchImportTest.java index 114a227..5b8d88e 100644 --- a/src/test/java/club/joylink/xiannccda/util/impo/SwitchImportTest.java +++ b/src/test/java/club/joylink/xiannccda/util/impo/SwitchImportTest.java @@ -1,15 +1,20 @@ package club.joylink.xiannccda.util.impo; +import club.joylink.xiannccda.alert.core.AlertDeviceType; import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto; +import club.joylink.xiannccda.dto.protos.LayoutGraphicsProto.Turnout; import club.joylink.xiannccda.entity.AlertTip; import club.joylink.xiannccda.entity.DeviceAreaConfig; +import club.joylink.xiannccda.entity.PublishedGi; +import club.joylink.xiannccda.repository.IPublishedGiRepository; import club.joylink.xiannccda.repository.impl.AlertTipRepository; import club.joylink.xiannccda.repository.impl.DeviceAreaConfigRepository; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -19,7 +24,6 @@ import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -33,6 +37,12 @@ public class SwitchImportTest { @Autowired private AlertTipRepository tipRepository; + @Autowired + private IPublishedGiRepository iPublishedGiRepository; + + private static final Integer lineId = 4; + private static final LineTypeEnum lineType = LineTypeEnum.OCC; + private List findAreaConfig() { QueryWrapper qw = new QueryWrapper<>(); qw.lambda().eq(DeviceAreaConfig::getLineId, lineId).eq(DeviceAreaConfig::getDeviceType, "DEVICE_TYPE_SWITCH"); @@ -40,23 +50,87 @@ public class SwitchImportTest { return list; } - private static final Integer lineId = 3; - private static final LineTypeEnum lineType = LineTypeEnum.OCC; + private PublishedGi findGi() { + return this.iPublishedGiRepository.lambdaQuery().eq(PublishedGi::getLineId, lineId).one(); + } + + @SneakyThrows + private List findAllSwitchFromGI() { + PublishedGi gi = this.findGi(); + LayoutGraphicsProto.RtssGraphicStorage storage = + LayoutGraphicsProto.RtssGraphicStorage.parseFrom(gi.getProto()); + List switcVOS = new ArrayList<>(); + for (Turnout turnout : storage.getTurnoutsList()) { + SwitcVO switcVO = new SwitcVO((long) turnout.getCommon().getId(), turnout.getCode()); + switcVOS.add(switcVO); + } + + String filePath = "g:\\2.xlsx"; + + try (FileInputStream file = new FileInputStream(new File(filePath)); + Workbook workbook = new XSSFWorkbook(file)) { + Sheet sheet = workbook.getSheetAt(2); + String station = ""; + String deviceCode = ""; + for (int i = 2; i < sheet.getPhysicalNumberOfRows(); i++) { + Row row = sheet.getRow(i); + Cell cell3 = row.getCell(2); + Cell cell4 = row.getCell(3); + String ts = cell3.getStringCellValue(); + String c = cell4.getStringCellValue(); + if (StringUtils.isNotEmpty(ts)) { + station = ts; + } + if (StringUtils.isNotEmpty(c)) { + deviceCode = c; + } + String finalDeviceCode = deviceCode; + List sw = switcVOS.stream().filter(d -> StringUtils.equals(d.code, finalDeviceCode)).toList(); + + if (CollectionUtils.isEmpty(sw)) { + continue; +// throw new RuntimeException(String.format("%s-%s", station, deviceCode)); + } + sw.get(0).station = station; + System.out.println(String.format("%s-%s", station, deviceCode)); + } + } + + return switcVOS; + } + + + @SneakyThrows + @Test + public void importAreaConfig() { + + List switcVOS = findAllSwitchFromGI(); + for (SwitcVO sw : switcVOS) { + if (StringUtils.isEmpty(sw.station)) { + continue; + } + DeviceAreaConfig ac = new DeviceAreaConfig(); + ac.setAreaName(String.format("%s-%s", sw.station, sw.code)); + ac.setLineId(lineId); + ac.setDeviceType(AlertDeviceType.DEVICE_TYPE_SWITCH); + ac.setAlertTypes(String.format("%s,%s,%s", AlertType.SWITCH_All_LOST.name(), AlertType.SWITCH_DW_LOST.name(), AlertType.SWITCH_FW_LOST.name())); + ac.setData(sw.layoutId.toString()); + this.configRepository.save(ac); + } + } + @SneakyThrows @Test public void testRead() { - String filePath = "g:\\1.xlsx"; + String filePath = "g:\\3.xlsx"; List areaConfigList = this.findAreaConfig(); List saveList = new ArrayList<>(); try (FileInputStream file = new FileInputStream(new File(filePath)); Workbook workbook = new XSSFWorkbook(file)) { -/* for (int i = 0; i < workbook.getNumberOfSheets(); i++) { - Sheet sheet = workbook.getSheetAt(i); - System.out.println(sheet.getSheetName()); - }*/ + Sheet sheet = workbook.getSheetAt(2); String newDeviceName = ""; for (int i = 2; i < sheet.getPhysicalNumberOfRows(); i++) { @@ -89,14 +163,28 @@ public class SwitchImportTest { msg2 = "\"" + msg2 + "\""; saveList.add(TestObj.create(lineId, lineType, funType, msg, msg2, config.getId())); } else { - throw new RuntimeException(""); + System.out.println(finalNewDeviceName); +// throw new RuntimeException(finalNewDeviceName); } } } + System.out.println(saveList); this.tipRepository.saveBatch(saveList); } + private static class SwitcVO { + + public SwitcVO(Long layoutId, String code) { + this.layoutId = layoutId; + this.code = code; + } + + private Long layoutId; + private String code; + + private String station; + } }