From 69eed1fc964477d60757cfacaf7614d344196795 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Wed, 23 Oct 2024 14:47:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/alert/AlertListenerJob.java | 27 ++- .../ats/message/OccMessageManage.java | 37 +--- .../ats/message/XianOccMessagingClient.java | 5 +- .../configuration/protos/OccServerProto.java | 48 +++++ .../AlertTipTimeConfigController.java | 10 +- .../controller/RoleAuthController.java | 8 + .../xiannccda/dto/auth/AuthRoleDTO.java | 1 + .../dto/protos/NccAlertInfoMessageProto.java | 196 +++++++++++++++++- .../repository/IAuthRoleRepository.java | 2 + .../repository/impl/AuthRoleRepository.java | 10 + .../xiannccda/service/AlertRecordService.java | 21 +- .../xiannccda/service/AlertTipService.java | 1 + .../joylink/xiannccda/ws/IMessageServer.java | 6 + .../xiannccda/ws/NccAlertMessageServer.java | 34 +-- src/main/resources/application-dev.yml | 3 + src/main/resources/application-local-test.yml | 3 + src/main/resources/application-local.yml | 3 + src/main/resources/application-master.yml | 3 + src/main/resources/application-prod.yml | 3 + src/main/resources/application-test.yml | 3 + .../resources/mybatis/mapper/AuthRole.xml | 2 +- xian-ncc-da-message | 2 +- 22 files changed, 352 insertions(+), 76 deletions(-) create mode 100644 src/main/java/club/joylink/xiannccda/configuration/protos/OccServerProto.java diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java index 05b11c8..30c7db8 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java @@ -2,12 +2,16 @@ package club.joylink.xiannccda.alert; import club.joylink.xiannccda.alert.NccAlertInfo.AlertStatus; import club.joylink.xiannccda.alert.core.AlertManager; +import club.joylink.xiannccda.configuration.protos.OccServerProto; +import club.joylink.xiannccda.configuration.protos.OccServerProto.OccClientMessage; +import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.entity.AlertRecord; import club.joylink.xiannccda.event.Listener; import club.joylink.xiannccda.repository.IAlertRecordRepository; import club.joylink.xiannccda.ws.NccAlertMessageServer; import club.joylink.xiannccda.ws.WsMessageServerManager; import java.util.concurrent.atomic.AtomicInteger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; @@ -19,6 +23,8 @@ public class AlertListenerJob implements ApplicationRunner { private final WsMessageServerManager wsMessageServerManager; private final IAlertRecordRepository alertRecordRepository; + @Autowired + private OccServerProto serverProto; public AlertListenerJob(WsMessageServerManager wsMessageServerManager, IAlertRecordRepository alertRecordRepository) { @@ -31,13 +37,14 @@ public class AlertListenerJob implements ApplicationRunner { //添加报警事件监听器 addAlertListeners(); //注册西安NCC的报警ws消息发送服务 - wsMessageServerManager.registerMessageServer(NccAlertMessageServer.getDefault()); + wsMessageServerManager.registerMessageServer(NccAlertMessageServer.getInstance(LineTypeEnum.NCC)); + wsMessageServerManager.registerMessageServer(NccAlertMessageServer.getInstance(LineTypeEnum.OCC)); //启动报警源事件监测任务 AlertManager.getDefault().taskStart(); } private void addAlertListeners() { - NccAlertMessageServer nccAlertMessageServer = NccAlertMessageServer.getDefault(); + AlertManager alertManager = AlertManager.getDefault(); //添加消息 alertManager.on(new Listener() { @@ -51,10 +58,18 @@ public class AlertListenerJob implements ApplicationRunner { alertInfo.setId(idGenerator.decrementAndGet()); }*/ //不论是否mock 都保存数据库 - AlertRecord record = convertToRecord(alertInfo); - alertRecordRepository.save(record); - alertInfo.setId(record.getId()); - nccAlertMessageServer.addMsg(alertInfo); + + OccClientMessage clientMessage = serverProto.getClientMessage(alertInfo.getLineId()); + for (LineTypeEnum lineType : clientMessage.getLineTypes()) { + + NccAlertMessageServer nccAlertMessageServer = NccAlertMessageServer.getInstance(lineType); + alertInfo.setLineType(lineType); + AlertRecord record = convertToRecord(alertInfo); + + alertRecordRepository.save(record); + alertInfo.setId(record.getId()); + nccAlertMessageServer.addMsg(alertInfo); + } } }); } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java index ca8a372..961704b 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/OccMessageManage.java @@ -2,6 +2,8 @@ package club.joylink.xiannccda.ats.message; import club.joylink.xiannccda.ats.message.changer.DeviceNameChangerManage; import club.joylink.xiannccda.ats.message.changer.NameChangerEnum; +import club.joylink.xiannccda.configuration.protos.OccServerProto; +import club.joylink.xiannccda.configuration.protos.OccServerProto.OccClientMessage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import java.util.HashMap; import java.util.List; @@ -10,6 +12,7 @@ import java.util.Objects; import lombok.Data; import lombok.Setter; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -21,11 +24,10 @@ import org.springframework.stereotype.Component; @Slf4j @Component @Setter -@ConfigurationProperties(prefix = "occ-client") public class OccMessageManage implements ApplicationRunner { - - private Map clientInfoMap; + @Autowired + private OccServerProto occServerProto; Map clientMap = new HashMap<>(); public void sendMsg(Integer lineId, MessageData md, boolean isRealTime) { @@ -37,14 +39,14 @@ public class OccMessageManage implements ApplicationRunner { } public boolean notMatchHandle(Integer lineId, Integer rtuId) { - OccClientMessage clientMessage = this.clientInfoMap.get(lineId); + OccClientMessage clientMessage = this.occServerProto.getClientMessage(lineId); if (Objects.isNull(clientMessage)) { return true; } - if (CollectionUtils.isEmpty(clientMessage.filterRtuIds)) { + if (CollectionUtils.isEmpty(clientMessage.getFilterRtuIds())) { return true; } - if (clientMessage.filterRtuIds.contains(rtuId)) { + if (clientMessage.rtuIdExists(rtuId)) { return false; } return true; @@ -66,33 +68,16 @@ public class OccMessageManage implements ApplicationRunner { DeviceNameChangerManage.init(); - this.clientInfoMap.forEach((k, v) -> { - log.info("初始化 occ tcp连接.... 是否监控cpu,lineId:{} 内存信息:{}", k, v.monitorHandwareChange); + this.occServerProto.getClientInfoMap().forEach((k, v) -> { + log.info("初始化 occ tcp连接.... 是否监控cpu,lineId:{} 内存信息:{}", k, v.isMonitorHandwareChange()); DeviceNameChangerManage.initLineIdNameCHanger(k, v.getNameChanger()); XianOccMessagingClient client = new XianOccMessagingClient(k, v); this.registerClient(client); - client.connect(v.monitorHandwareChange); + client.connect(v.isMonitorHandwareChange()); }); } - @Data - public static class OccClientMessage { - private String serverHost; - - private Integer realPort; - - private Integer unRealPort; - - private Boolean collectorData; - - private Integer receiveMsgTimeout; - - private boolean monitorHandwareChange; - - private List filterRtuIds; - private NameChangerEnum nameChanger; - } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java index 7341c04..082d4f8 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/XianOccMessagingClient.java @@ -1,15 +1,14 @@ package club.joylink.xiannccda.ats.message; -import club.joylink.xiannccda.ats.message.OccMessageManage.OccClientMessage; + import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest; import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum; +import club.joylink.xiannccda.configuration.protos.OccServerProto.OccClientMessage; import java.time.LocalDateTime; import java.util.LinkedList; -import java.util.List; import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import lombok.Getter; diff --git a/src/main/java/club/joylink/xiannccda/configuration/protos/OccServerProto.java b/src/main/java/club/joylink/xiannccda/configuration/protos/OccServerProto.java new file mode 100644 index 0000000..ff2a4cb --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/configuration/protos/OccServerProto.java @@ -0,0 +1,48 @@ +package club.joylink.xiannccda.configuration.protos; + +import club.joylink.xiannccda.ats.message.changer.NameChangerEnum; +import club.joylink.xiannccda.constants.common.LineTypeEnum; +import java.util.List; +import java.util.Map; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@Data +@ConfigurationProperties(prefix = "occ-client") +public class OccServerProto { + + private Map clientInfoMap; + + public OccClientMessage getClientMessage(Integer lineId) { + return this.clientInfoMap.get(lineId); + } + + + @Data + public static class OccClientMessage { + + private String serverHost; + + private Integer realPort; + + private Integer unRealPort; + + private Boolean collectorData; + + private Integer receiveMsgTimeout; + + private boolean monitorHandwareChange; + + private List filterRtuIds; + private NameChangerEnum nameChanger; + + private List lineTypes; + + public boolean rtuIdExists(Integer rtiud) { + return this.filterRtuIds.contains(rtiud); + } + + } +} diff --git a/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java b/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java index 29903f3..a89684a 100644 --- a/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java +++ b/src/main/java/club/joylink/xiannccda/controller/AlertTipTimeConfigController.java @@ -52,15 +52,7 @@ public class AlertTipTimeConfigController { @Operation(summary = "保存修改") @PostMapping("page") @CommonLogAnno(name = "决策信息时间-分页查询", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) - public IPage page(Principal user, AlertTipTimeQueryDTO dto) { - JwtAuthenticationToken authToken = (JwtAuthenticationToken) user; - System.out.println(authToken.getPrincipal()); - System.out.println(authToken.getTokenAttributes()); - Object exp = authToken.getTokenAttributes().get(JwtClaimNames.EXP); - Instant time = (Instant) exp; - System.out.println(time.getEpochSecond()); - System.out.println(authToken.getCredentials()); - System.out.println(authToken.getAuthorities()); + public IPage page(AlertTipTimeQueryDTO dto) { return this.configRepository.page(dto, Wrappers.lambdaQuery(AlertTipTimeConfig.class).eq(AlertTipTimeConfig::getListShower, 1)); } diff --git a/src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java b/src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java index 9722d88..f92bad0 100644 --- a/src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java +++ b/src/main/java/club/joylink/xiannccda/controller/RoleAuthController.java @@ -72,6 +72,7 @@ public class RoleAuthController { this.authPathRepository.removeById(id); } + @GetMapping("/role/page") @SecurityRequirement(name = "jwt") @Operation(summary = "角色分页") @@ -88,4 +89,11 @@ public class RoleAuthController { this.authService.saveOrUpdate(dto); } + @PostMapping("/config/{id}") + @Operation(summary = "角色配置") + @ApiResponse(description = "角色配置") + public void roleConfig(@PathVariable("id") Long id, AuthRoleDTO configStr) { + this.authRoleRepository.roleConfig(id, configStr); + } + } diff --git a/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java b/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java index 34570ab..98d09bf 100644 --- a/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java +++ b/src/main/java/club/joylink/xiannccda/dto/auth/AuthRoleDTO.java @@ -14,4 +14,5 @@ public class AuthRoleDTO { private List resList; @JsonIgnore private String apiIds; + private String roleConfigStr; } diff --git a/src/main/java/club/joylink/xiannccda/dto/protos/NccAlertInfoMessageProto.java b/src/main/java/club/joylink/xiannccda/dto/protos/NccAlertInfoMessageProto.java index 4b4ba60..0c49c71 100644 --- a/src/main/java/club/joylink/xiannccda/dto/protos/NccAlertInfoMessageProto.java +++ b/src/main/java/club/joylink/xiannccda/dto/protos/NccAlertInfoMessageProto.java @@ -180,6 +180,26 @@ public final class NccAlertInfoMessageProto { * @return The mock. */ boolean getMock(); + + /** + *
+       *线路类型 occ/ncc
+       * 
+ * + * string line_type = 11; + * @return The lineType. + */ + java.lang.String getLineType(); + /** + *
+       *线路类型 occ/ncc
+       * 
+ * + * string line_type = 11; + * @return The bytes for lineType. + */ + com.google.protobuf.ByteString + getLineTypeBytes(); } /** * Protobuf type {@code alert.NccAlertInfoMessage.Message} @@ -200,6 +220,7 @@ public final class NccAlertInfoMessageProto { alertObject_ = ""; alertType_ = 0; locatorDeviceId_ = ""; + lineType_ = ""; } @java.lang.Override @@ -483,6 +504,53 @@ public final class NccAlertInfoMessageProto { return mock_; } + public static final int LINE_TYPE_FIELD_NUMBER = 11; + @SuppressWarnings("serial") + private volatile java.lang.Object lineType_ = ""; + /** + *
+       *线路类型 occ/ncc
+       * 
+ * + * string line_type = 11; + * @return The lineType. + */ + @java.lang.Override + public java.lang.String getLineType() { + java.lang.Object ref = lineType_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lineType_ = s; + return s; + } + } + /** + *
+       *线路类型 occ/ncc
+       * 
+ * + * string line_type = 11; + * @return The bytes for lineType. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getLineTypeBytes() { + java.lang.Object ref = lineType_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + lineType_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + private byte memoizedIsInitialized = -1; @java.lang.Override public final boolean isInitialized() { @@ -527,6 +595,9 @@ public final class NccAlertInfoMessageProto { if (mock_ != false) { output.writeBool(10, mock_); } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(lineType_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 11, lineType_); + } getUnknownFields().writeTo(output); } @@ -571,6 +642,9 @@ public final class NccAlertInfoMessageProto { size += com.google.protobuf.CodedOutputStream .computeBoolSize(10, mock_); } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(lineType_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(11, lineType_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -605,6 +679,8 @@ public final class NccAlertInfoMessageProto { != other.getAlertLocationId()) return false; if (getMock() != other.getMock()) return false; + if (!getLineType() + .equals(other.getLineType())) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -638,6 +714,8 @@ public final class NccAlertInfoMessageProto { hash = (37 * hash) + MOCK_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean( getMock()); + hash = (37 * hash) + LINE_TYPE_FIELD_NUMBER; + hash = (53 * hash) + getLineType().hashCode(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -779,6 +857,7 @@ public final class NccAlertInfoMessageProto { locatorDeviceId_ = ""; alertLocationId_ = 0L; mock_ = false; + lineType_ = ""; return this; } @@ -842,6 +921,9 @@ public final class NccAlertInfoMessageProto { if (((from_bitField0_ & 0x00000200) != 0)) { result.mock_ = mock_; } + if (((from_bitField0_ & 0x00000400) != 0)) { + result.lineType_ = lineType_; + } } @java.lang.Override @@ -896,6 +978,11 @@ public final class NccAlertInfoMessageProto { if (other.getMock() != false) { setMock(other.getMock()); } + if (!other.getLineType().isEmpty()) { + lineType_ = other.lineType_; + bitField0_ |= 0x00000400; + onChanged(); + } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -972,6 +1059,11 @@ public final class NccAlertInfoMessageProto { bitField0_ |= 0x00000200; break; } // case 80 + case 90: { + lineType_ = input.readStringRequireUtf8(); + bitField0_ |= 0x00000400; + break; + } // case 90 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { done = true; // was an endgroup tag @@ -1541,6 +1633,98 @@ public final class NccAlertInfoMessageProto { onChanged(); return this; } + + private java.lang.Object lineType_ = ""; + /** + *
+         *线路类型 occ/ncc
+         * 
+ * + * string line_type = 11; + * @return The lineType. + */ + public java.lang.String getLineType() { + java.lang.Object ref = lineType_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lineType_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + *
+         *线路类型 occ/ncc
+         * 
+ * + * string line_type = 11; + * @return The bytes for lineType. + */ + public com.google.protobuf.ByteString + getLineTypeBytes() { + java.lang.Object ref = lineType_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + lineType_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + *
+         *线路类型 occ/ncc
+         * 
+ * + * string line_type = 11; + * @param value The lineType to set. + * @return This builder for chaining. + */ + public Builder setLineType( + java.lang.String value) { + if (value == null) { throw new NullPointerException(); } + lineType_ = value; + bitField0_ |= 0x00000400; + onChanged(); + return this; + } + /** + *
+         *线路类型 occ/ncc
+         * 
+ * + * string line_type = 11; + * @return This builder for chaining. + */ + public Builder clearLineType() { + lineType_ = getDefaultInstance().getLineType(); + bitField0_ = (bitField0_ & ~0x00000400); + onChanged(); + return this; + } + /** + *
+         *线路类型 occ/ncc
+         * 
+ * + * string line_type = 11; + * @param value The bytes for lineType to set. + * @return This builder for chaining. + */ + public Builder setLineTypeBytes( + com.google.protobuf.ByteString value) { + if (value == null) { throw new NullPointerException(); } + checkByteStringIsUtf8(value); + lineType_ = value; + bitField0_ |= 0x00000400; + onChanged(); + return this; + } @java.lang.Override public final Builder setUnknownFields( final com.google.protobuf.UnknownFieldSet unknownFields) { @@ -2311,16 +2495,16 @@ public final class NccAlertInfoMessageProto { static { java.lang.String[] descriptorData = { "\n\017alertInfo.proto\022\005alert\032\020alertConst.pro" + - "to\"\255\002\n\023NccAlertInfoMessage\0224\n\010messages\030\001" + + "to\"\300\002\n\023NccAlertInfoMessage\0224\n\010messages\030\001" + " \003(\0132\".alert.NccAlertInfoMessage.Message" + - "\032\337\001\n\007Message\022\n\n\002id\030\001 \001(\t\022\r\n\005level\030\002 \001(\t\022" + + "\032\362\001\n\007Message\022\n\n\002id\030\001 \001(\t\022\r\n\005level\030\002 \001(\t\022" + "\022\n\nalert_time\030\003 \001(\t\022\024\n\014alert_tip_id\030\004 \001(" + "\005\022\017\n\007line_id\030\005 \001(\005\022\024\n\014alert_object\030\006 \001(\t" + "\022$\n\nalert_type\030\007 \001(\0162\020.alert.AlertType\022\031" + "\n\021locator_device_id\030\010 \001(\t\022\031\n\021alert_locat" + - "ion_id\030\t \001(\003\022\014\n\004mock\030\n \001(\010B=\n!club.joyli" + - "nk.xiannccda.dto.protosB\030NccAlertInfoMes" + - "sageProtob\006proto3" + "ion_id\030\t \001(\003\022\014\n\004mock\030\n \001(\010\022\021\n\tline_type\030" + + "\013 \001(\tB=\n!club.joylink.xiannccda.dto.prot" + + "osB\030NccAlertInfoMessageProtob\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, @@ -2338,7 +2522,7 @@ public final class NccAlertInfoMessageProto { internal_static_alert_NccAlertInfoMessage_Message_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_alert_NccAlertInfoMessage_Message_descriptor, - new java.lang.String[] { "Id", "Level", "AlertTime", "AlertTipId", "LineId", "AlertObject", "AlertType", "LocatorDeviceId", "AlertLocationId", "Mock", }); + new java.lang.String[] { "Id", "Level", "AlertTime", "AlertTipId", "LineId", "AlertObject", "AlertType", "LocatorDeviceId", "AlertLocationId", "Mock", "LineType", }); club.joylink.xiannccda.dto.protos.AlertConstProto.getDescriptor(); } diff --git a/src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java index 4fe8792..e9d1c1f 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IAuthRoleRepository.java @@ -22,4 +22,6 @@ public interface IAuthRoleRepository extends IService { Page roleApiPage(AuthRoleQueryDTO role); List getAuthRoleByUserId(String userId); + + void roleConfig(Long id, AuthRoleDTO configStr); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java index 79c3e42..b06147f 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/AuthRoleRepository.java @@ -5,6 +5,7 @@ import club.joylink.xiannccda.dto.auth.AuthRoleQueryDTO; import club.joylink.xiannccda.entity.AuthRole; import club.joylink.xiannccda.mapper.AuthRoleMapper; import club.joylink.xiannccda.repository.IAuthRoleRepository; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.util.Arrays; @@ -40,4 +41,13 @@ public class AuthRoleRepository extends ServiceImpl im public List getAuthRoleByUserId(String userId) { return this.baseMapper.getAuthRoleByUserId(userId); } + + @Override + public void roleConfig(Long id, AuthRoleDTO configStr) { + UpdateWrapper uw = new UpdateWrapper<>(); + uw.lambda().eq(AuthRole::getId, id).set(AuthRole::getRoleConfigStr, configStr.getRoleConfigStr()); + + this.update(uw); + + } } diff --git a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java index c1eed20..c7c4bf0 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertRecordService.java @@ -3,6 +3,7 @@ package club.joylink.xiannccda.service; import club.joylink.xiannccda.alert.NccAlertInfo; import club.joylink.xiannccda.alert.NccAlertInfo.AlertStatus; import club.joylink.xiannccda.alert.core.AlertDeviceType; +import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.dto.CommonPage; import club.joylink.xiannccda.dto.CommonPageRequest; import club.joylink.xiannccda.dto.protos.AlertConstProto.AlertType; @@ -91,14 +92,14 @@ public class AlertRecordService { private static final List FILTER_LIST = List.of(TipTimeConfig.EVENING_PEARK.name(), TipTimeConfig.MORN_PEAK.name()/*, TipTimeConfig.NORMAL_UNPEARK.name()*/); private AlertTip findTipFromAlertTime(AlertRecord ar, String tipType, Long areaConfigId, boolean hasAreaConfigId) { - if (Objects.isNull(ar)) { - return this.findAlertTip(tipType, areaConfigId, Optional.empty(), hasAreaConfigId); - } +/* if (Objects.isNull(ar)) { + return this.findAlertTip(ar.getLineId(), ar.getLineType(), tipType, areaConfigId, Optional.empty(), hasAreaConfigId); + }*/ Collection collection = this.timeConfigService.getCache(); if (CollectionUtils.isEmpty(collection)) { log.info("高低峰配置数据为空,返回默认的辅助消息"); - return this.findAlertTip(tipType, areaConfigId, Optional.empty(), hasAreaConfigId); + return this.findAlertTip(ar.getLineId(), ar.getLineType(), tipType, areaConfigId, Optional.empty(), hasAreaConfigId); } else { int hour = LocalDateTime.now().getHour(); if (Objects.nonNull(ar.getAlertTime())) { @@ -111,20 +112,21 @@ public class AlertRecordService { if (tipTimeConfigOptional.isEmpty() && normalOptional.isEmpty()) { //高低峰都没有找到 log.info("高低峰均未匹配,告警时间(小时) {}", hour); - return this.findAlertTip(tipType, areaConfigId, Optional.empty(), hasAreaConfigId); + return this.findAlertTip(ar.getLineId(), ar.getLineType(), tipType, areaConfigId, Optional.empty(), hasAreaConfigId); } else if (tipTimeConfigOptional.isPresent()) { //匹配上高峰 - return this.findAlertTip(tipType, areaConfigId, tipTimeConfigOptional, hasAreaConfigId); + return this.findAlertTip(ar.getLineId(), ar.getLineType(), tipType, areaConfigId, tipTimeConfigOptional, hasAreaConfigId); } else { //匹配上低峰 - return this.findAlertTip(tipType, areaConfigId, normalOptional, hasAreaConfigId); + return this.findAlertTip(ar.getLineId(), ar.getLineType(), tipType, areaConfigId, normalOptional, hasAreaConfigId); } } } - private AlertTip findAlertTip(String tipType, Long areaConfigId, Optional tipTimeConfigOptional, boolean hasAreaConfigId) { + private AlertTip findAlertTip(Integer lineId, LineTypeEnum lineType, String tipType, Long areaConfigId, Optional tipTimeConfigOptional, boolean hasAreaConfigId) { - LambdaQueryWrapper qw = Wrappers.lambdaQuery(AlertTip.class).eq(AlertTip::getAlertType, tipType); + LambdaQueryWrapper qw = Wrappers.lambdaQuery(AlertTip.class) + .eq(AlertTip::getLineId, lineId).eq(AlertTip::getLineType, lineType).eq(AlertTip::getAlertType, tipType); qw.eq(hasAreaConfigId, AlertTip::getAreaConfigId, areaConfigId); Long id = tipTimeConfigOptional.map(AlertTipTimeConfig::getId).orElse(null); List alertTips = this.alertTipRepository.list(qw); @@ -145,6 +147,7 @@ public class AlertRecordService { public AlertTip confirm(Long recordId, String tipType, Long areaConfigId) { AlertRecord ar = this.alertRecordRepository.getById(recordId); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(ar), "未找到对应的告警记录"); Long newAreaConfigId = null; if (Objects.nonNull(ar)) { newAreaConfigId = this.findAreaConfig(ar, tipType); diff --git a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java index bcfb7c1..40940ff 100644 --- a/src/main/java/club/joylink/xiannccda/service/AlertTipService.java +++ b/src/main/java/club/joylink/xiannccda/service/AlertTipService.java @@ -38,6 +38,7 @@ public class AlertTipService { AlertTip saveEntity = convertToEntity(saveDTO); LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(AlertTip.class); queryWrapper.eq(AlertTip::getAlertType, saveEntity.getAlertType()) + .eq(AlertTip::getLineId, saveEntity.getLineId()).eq(AlertTip::getLineType, saveEntity.getLineType()) .eq(AlertTip::getAreaConfigId, saveEntity.getAreaConfigId()); if (CollectionUtils.isNotEmpty(saveDTO.getTipTimeIds())) { String tipTimeCond = saveDTO.getTipTimeIds().stream().map(d -> String.format(" find_in_set('%s',%s) > 0 ", d, AlertTip.TIP_TIME_REF)).collect(Collectors.joining(" OR ")); diff --git a/src/main/java/club/joylink/xiannccda/ws/IMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/IMessageServer.java index 613a308..924f239 100644 --- a/src/main/java/club/joylink/xiannccda/ws/IMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/IMessageServer.java @@ -28,6 +28,12 @@ public interface IMessageServer { return PLACEHOLDER_HELPER.replacePlaceholders(this.getDestinationPattern(), properties); } + default String createPlace(Map properMap) { + Properties properties = new Properties(); + properMap.forEach((k, v) -> properties.put(k, v)); + return PLACEHOLDER_HELPER.replacePlaceholders(this.getDestinationPattern(), properties); + } + /** * 服务路径pattern * diff --git a/src/main/java/club/joylink/xiannccda/ws/NccAlertMessageServer.java b/src/main/java/club/joylink/xiannccda/ws/NccAlertMessageServer.java index 5107be4..22b04d3 100644 --- a/src/main/java/club/joylink/xiannccda/ws/NccAlertMessageServer.java +++ b/src/main/java/club/joylink/xiannccda/ws/NccAlertMessageServer.java @@ -1,15 +1,18 @@ package club.joylink.xiannccda.ws; import club.joylink.xiannccda.alert.NccAlertInfo; +import club.joylink.xiannccda.constants.common.LineTypeEnum; import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage; import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.Builder; import club.joylink.xiannccda.dto.protos.NccAlertInfoMessageProto.NccAlertInfoMessage.Message; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Queue; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -18,20 +21,25 @@ import java.util.concurrent.ConcurrentLinkedQueue; */ public class NccAlertMessageServer implements IMessageServer { - private static final Map SERVER_MAP = new ConcurrentHashMap<>(); + private static final Map SERVER_MAP = new ConcurrentHashMap<>(); - private String id; - private final String Destination = "/queue/xian/ncc/alert"; + private LineTypeEnum lineType; + + private Set lineIdSet = Sets.newHashSet(); + + private final String DestinationOcc = "/queue/xian/{lineType}/{lineId}/alert"; Queue pendingMsgQueue = new ConcurrentLinkedQueue<>(); @Override public String getDestinationPattern() { - return Destination; + return DestinationOcc; } @Override public Object onSubscription(String destination, Map paramMap) { + String lineId = paramMap.get("lineId"); + this.lineIdSet.add(lineId); return null; } @@ -51,26 +59,22 @@ public class NccAlertMessageServer implements IMessageServer { builder.addMessages(message); byte[] bytes = builder.build().toByteArray(); if (bytes != null && bytes.length != 0) { - list.add(new TopicMessage(getDestinationPattern(), bytes)); + String dest = this.createPlace(Map.of("lineType", this.lineType.name(), "lineId", alertInfo.getLineId().toString())); + list.add(new TopicMessage(dest, bytes)); } } else { break; } } - return list; } - private NccAlertMessageServer(String id) { - this.id = id; + private NccAlertMessageServer(LineTypeEnum lineType) { + this.lineType = lineType; } - public static NccAlertMessageServer getDefault() { - return getInstance("default"); - } - - public static NccAlertMessageServer getInstance(String id) { - return SERVER_MAP.computeIfAbsent(id, k -> new NccAlertMessageServer(id)); + public static NccAlertMessageServer getInstance(LineTypeEnum lineType) { + return SERVER_MAP.computeIfAbsent(lineType, k -> new NccAlertMessageServer(lineType)); } public static NccAlertMessageServer removeInstance(String id) { @@ -88,7 +92,7 @@ public class NccAlertMessageServer implements IMessageServer { .setAlertTime(alertInfo.getAlertTime().toString()) .setLineId(alertInfo.getLineId()) .setAlertObject(alertInfo.getAlertObject()) - .setAlertType(alertInfo.getAlertType()); + .setAlertType(alertInfo.getAlertType()).setLineType(alertInfo.getLineType().name()); if (Objects.nonNull(alertInfo.getAlertLocationId())) { builder.setAlertLocationId(alertInfo.getAlertLocationId()); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f42d42b..09223fa 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -29,6 +29,9 @@ occ-client: - 81 - 82 nameChanger: UNIVERSAL + lineTypes: + - OCC + - NCC #故障测试 mock-alert-test: false diff --git a/src/main/resources/application-local-test.yml b/src/main/resources/application-local-test.yml index 2179723..1535829 100644 --- a/src/main/resources/application-local-test.yml +++ b/src/main/resources/application-local-test.yml @@ -26,6 +26,9 @@ occ-client: filterRtuIds: - 81 - 82 + lineTypes: + - OCC + - NCC #故障测试 mock-alert-test: true #加载历史模拟数据 diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 07e0386..0ca32a1 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -29,6 +29,9 @@ occ-client: - 81 - 82 nameChanger: UNIVERSAL + lineTypes: + - OCC + - NCC mock-alert-test: true diff --git a/src/main/resources/application-master.yml b/src/main/resources/application-master.yml index b8a138f..b1a3ebf 100644 --- a/src/main/resources/application-master.yml +++ b/src/main/resources/application-master.yml @@ -32,6 +32,9 @@ occ-client: filterRtuIds: - 81 - 82 + lineTypes: + - OCC + - NCC mock-alert-test: false load-mock-history-data: false diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index ae03e08..b99ee4a 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -29,6 +29,9 @@ occ-client: filterRtuIds: - 81 - 82 + lineTypes: + - OCC + - NCC mock-alert-test: false load-mock-history-data: false diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index b58ae67..dd40c1b 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -35,6 +35,9 @@ occ-client: filterRtuIds: - 81 - 82 + lineTypes: + - OCC + - NCC mock-alert-test: true load-mock-history-data: false #延时加载告警处理 diff --git a/src/main/resources/mybatis/mapper/AuthRole.xml b/src/main/resources/mybatis/mapper/AuthRole.xml index 725a85f..1739d4c 100644 --- a/src/main/resources/mybatis/mapper/AuthRole.xml +++ b/src/main/resources/mybatis/mapper/AuthRole.xml @@ -13,7 +13,7 @@ , name