diff --git a/nex-be/pom.xml b/nex-be/pom.xml index 339e524..a712c52 100644 --- a/nex-be/pom.xml +++ b/nex-be/pom.xml @@ -22,6 +22,7 @@ 1.8 + 3.23.4 @@ -101,10 +102,64 @@ 1.5 + + com.google.protobuf + protobuf-java + ${protobuf.version} + + + + net.devh + grpc-server-spring-boot-starter + 2.14.0.RELEASE + + + + junit + junit + test + + + org.springframework.boot + spring-boot-starter-test + test + + + + kr.motd.maven + os-maven-plugin + 1.6.2 + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:3.19.2:exe:${os.detected.classifier} + grpc-java + io.grpc:protoc-gen-grpc-java:1.50.0:exe:${os.detected.classifier} + + + ${project.basedir}/src/main/java/com/unisinsight/project/grpc/proto + + ${project.basedir}/src/main/java + false + + + + + + compile + compile-custom + + + + org.springframework.boot spring-boot-maven-plugin diff --git a/nex-be/src/main/java/com/unisinsight/project/config/ThreadConfig.java b/nex-be/src/main/java/com/unisinsight/project/config/ThreadConfig.java new file mode 100644 index 0000000..dcbc27b --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/config/ThreadConfig.java @@ -0,0 +1,67 @@ +package com.unisinsight.project.config; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author : ch + * @version : 1.0 + * @ClassName : ThreadConfig + * @Description : + * @DATE : Created in 16:22 2025/8/21 + *
       Copyright: Copyright(c) 2025     
+ *
       Company :   	紫光汇智信息技术有限公司		           
+ * Modification History: + * Date Author Version Discription + * -------------------------------------------------------------------------- + * 2025/08/21 ch 1.0 Why & What is modified: <修改原因描述> * + */ +@Configuration +public class ThreadConfig { + /** + * 创建用于gRPC连接监听的线程池 + * 用于处理客户端连接/断开连接等事件 + */ + @Bean("grpcConnectionListenerExecutor") + public ExecutorService grpcConnectionListenerExecutor() { + // 获取系统可用处理器核心数 + int corePoolSize =1; + int maximumPoolSize = corePoolSize * 2; + + // 设置线程空闲时间 + long keepAliveTime = 60L; + + // 设置队列大小 + int queueCapacity = 1000; + + // 创建线程池 + return new ThreadPoolExecutor( + // 核心线程数 + corePoolSize, + // 最大线程数 + maximumPoolSize, + // 空闲线程存活时间 + keepAliveTime, + // 时间单位 + TimeUnit.SECONDS, + // 任务队列 + new LinkedBlockingQueue<>(queueCapacity), + new ThreadFactory() { + private final AtomicInteger threadNumber = new AtomicInteger(1); + + @Override + public Thread newThread(Runnable runable) { + Thread thread = new Thread(runable, "grpc-connection-listener-" + threadNumber.getAndIncrement()); + thread.setDaemon(false); // 设置为非守护线程 + return thread; + } + }, + // 拒绝策略:由调用线程执行任务 + new ThreadPoolExecutor.CallerRunsPolicy() + ); + } +} diff --git a/nex-be/src/main/java/com/unisinsight/project/controller/DeviceController.java b/nex-be/src/main/java/com/unisinsight/project/controller/DeviceController.java index 64a56f3..746cf19 100644 --- a/nex-be/src/main/java/com/unisinsight/project/controller/DeviceController.java +++ b/nex-be/src/main/java/com/unisinsight/project/controller/DeviceController.java @@ -7,10 +7,12 @@ import com.unisinsight.project.entity.res.DeviceRes; import com.unisinsight.project.entity.res.PageResult; import com.unisinsight.project.exception.BaseErrorCode; import com.unisinsight.project.exception.Result; +import com.unisinsight.project.service.ClientOperateService; import com.unisinsight.project.service.DeviceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -33,6 +35,8 @@ public class DeviceController { @Resource private DeviceService deviceService; + @Autowired + private ClientOperateService clientOperateService; @ApiOperation(value = "终端新增") @PostMapping("/add") public Result insertUser(@RequestBody DeviceReq deviceReq) { @@ -82,4 +86,25 @@ public class DeviceController { return deviceService.selectPageUser(deviceReq); } + @ApiOperation(value = "开机") + @PostMapping("/terminal/start") + public Result terminalStart(@RequestBody DeviceReq deviceReq) { + if (Objects.isNull(deviceReq)) { + return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR); + } + log.info("终端开机请求参数为:{}", JSONUtil.toJsonStr(deviceReq)); + return clientOperateService.terminalStart(deviceReq); + } + + @ApiOperation(value = "关机") + @PostMapping("/terminal/end") + public Result terminalEnd(@RequestBody DeviceReq deviceReq) { + if (Objects.isNull(deviceReq)) { + return Result.errorResult(BaseErrorCode.PARAMS_CHK_ERROR); + } + log.info("终端关机请求参数为:{}", JSONUtil.toJsonStr(deviceReq)); + return clientOperateService.terminalEnd(deviceReq); + } + + } diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dao/Device.java b/nex-be/src/main/java/com/unisinsight/project/entity/dao/Device.java index 1029cf9..8216b99 100644 --- a/nex-be/src/main/java/com/unisinsight/project/entity/dao/Device.java +++ b/nex-be/src/main/java/com/unisinsight/project/entity/dao/Device.java @@ -102,6 +102,11 @@ public class Device implements Serializable { */ @TableField(value = "description") private String description; + /** + * 设备状态 0:离线 1:在线 + */ + @TableField(value = "device_status") + private Integer deviceStatus; @TableField(exist = false) private static final long serialVersionUID = 1L; diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/req/DeviceReq.java b/nex-be/src/main/java/com/unisinsight/project/entity/req/DeviceReq.java index d4da562..4ad56a7 100644 --- a/nex-be/src/main/java/com/unisinsight/project/entity/req/DeviceReq.java +++ b/nex-be/src/main/java/com/unisinsight/project/entity/req/DeviceReq.java @@ -84,6 +84,12 @@ public class DeviceReq implements Serializable { @ApiModelProperty("描述") @JsonProperty("description") private String description; + /** + * 设备状态 0:离线 1:在线 + */ + @ApiModelProperty("设备状态") + @JsonProperty("device_status") + private String deviceStatus; /** * 查询页 diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/MsgResponse.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/MsgResponse.java new file mode 100644 index 0000000..b3b4ddc --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/MsgResponse.java @@ -0,0 +1,622 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: message.proto + +package com.unisinsight.project.grpc.generate; + +/** + * Protobuf type {@code MsgResponse} + */ +public final class MsgResponse extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:MsgResponse) + MsgResponseOrBuilder { +private static final long serialVersionUID = 0L; + // Use MsgResponse.newBuilder() to construct. + private MsgResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private MsgResponse() { + message_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new MsgResponse(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private MsgResponse( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 8: { + + success_ = input.readBool(); + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + message_ = s; + break; + } + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.unisinsight.project.grpc.generate.MsgResponse.class, com.unisinsight.project.grpc.generate.MsgResponse.Builder.class); + } + + public static final int SUCCESS_FIELD_NUMBER = 1; + private boolean success_; + /** + * bool success = 1; + * @return The success. + */ + @java.lang.Override + public boolean getSuccess() { + return success_; + } + + public static final int MESSAGE_FIELD_NUMBER = 2; + private volatile java.lang.Object message_; + /** + * string message = 2; + * @return The message. + */ + @java.lang.Override + public java.lang.String getMessage() { + java.lang.Object ref = message_; + 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(); + message_ = s; + return s; + } + } + /** + * string message = 2; + * @return The bytes for message. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getMessageBytes() { + java.lang.Object ref = message_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + message_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (success_ != false) { + output.writeBool(1, success_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, message_); + } + unknownFields.writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (success_ != false) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(1, success_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, message_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.unisinsight.project.grpc.generate.MsgResponse)) { + return super.equals(obj); + } + com.unisinsight.project.grpc.generate.MsgResponse other = (com.unisinsight.project.grpc.generate.MsgResponse) obj; + + if (getSuccess() + != other.getSuccess()) return false; + if (!getMessage() + .equals(other.getMessage())) return false; + if (!unknownFields.equals(other.unknownFields)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + SUCCESS_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean( + getSuccess()); + hash = (37 * hash) + MESSAGE_FIELD_NUMBER; + hash = (53 * hash) + getMessage().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.MsgResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.unisinsight.project.grpc.generate.MsgResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code MsgResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:MsgResponse) + com.unisinsight.project.grpc.generate.MsgResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.unisinsight.project.grpc.generate.MsgResponse.class, com.unisinsight.project.grpc.generate.MsgResponse.Builder.class); + } + + // Construct using com.unisinsight.project.grpc.generate.MsgResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + @java.lang.Override + public Builder clear() { + super.clear(); + success_ = false; + + message_ = ""; + + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_MsgResponse_descriptor; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.MsgResponse getDefaultInstanceForType() { + return com.unisinsight.project.grpc.generate.MsgResponse.getDefaultInstance(); + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.MsgResponse build() { + com.unisinsight.project.grpc.generate.MsgResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.MsgResponse buildPartial() { + com.unisinsight.project.grpc.generate.MsgResponse result = new com.unisinsight.project.grpc.generate.MsgResponse(this); + result.success_ = success_; + result.message_ = message_; + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.unisinsight.project.grpc.generate.MsgResponse) { + return mergeFrom((com.unisinsight.project.grpc.generate.MsgResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.unisinsight.project.grpc.generate.MsgResponse other) { + if (other == com.unisinsight.project.grpc.generate.MsgResponse.getDefaultInstance()) return this; + if (other.getSuccess() != false) { + setSuccess(other.getSuccess()); + } + if (!other.getMessage().isEmpty()) { + message_ = other.message_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.unisinsight.project.grpc.generate.MsgResponse parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.unisinsight.project.grpc.generate.MsgResponse) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private boolean success_ ; + /** + * bool success = 1; + * @return The success. + */ + @java.lang.Override + public boolean getSuccess() { + return success_; + } + /** + * bool success = 1; + * @param value The success to set. + * @return This builder for chaining. + */ + public Builder setSuccess(boolean value) { + + success_ = value; + onChanged(); + return this; + } + /** + * bool success = 1; + * @return This builder for chaining. + */ + public Builder clearSuccess() { + + success_ = false; + onChanged(); + return this; + } + + private java.lang.Object message_ = ""; + /** + * string message = 2; + * @return The message. + */ + public java.lang.String getMessage() { + java.lang.Object ref = message_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + message_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string message = 2; + * @return The bytes for message. + */ + public com.google.protobuf.ByteString + getMessageBytes() { + java.lang.Object ref = message_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + message_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string message = 2; + * @param value The message to set. + * @return This builder for chaining. + */ + public Builder setMessage( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + message_ = value; + onChanged(); + return this; + } + /** + * string message = 2; + * @return This builder for chaining. + */ + public Builder clearMessage() { + + message_ = getDefaultInstance().getMessage(); + onChanged(); + return this; + } + /** + * string message = 2; + * @param value The bytes for message to set. + * @return This builder for chaining. + */ + public Builder setMessageBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + message_ = value; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:MsgResponse) + } + + // @@protoc_insertion_point(class_scope:MsgResponse) + private static final com.unisinsight.project.grpc.generate.MsgResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.unisinsight.project.grpc.generate.MsgResponse(); + } + + public static com.unisinsight.project.grpc.generate.MsgResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public MsgResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new MsgResponse(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.MsgResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/MsgResponseOrBuilder.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/MsgResponseOrBuilder.java new file mode 100644 index 0000000..3dab6c6 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/MsgResponseOrBuilder.java @@ -0,0 +1,27 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: message.proto + +package com.unisinsight.project.grpc.generate; + +public interface MsgResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:MsgResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * bool success = 1; + * @return The success. + */ + boolean getSuccess(); + + /** + * string message = 2; + * @return The message. + */ + java.lang.String getMessage(); + /** + * string message = 2; + * @return The bytes for message. + */ + com.google.protobuf.ByteString + getMessageBytes(); +} diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationMessage.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationMessage.java new file mode 100644 index 0000000..299c044 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationMessage.java @@ -0,0 +1,962 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: message.proto + +package com.unisinsight.project.grpc.generate; + +/** + * Protobuf type {@code NotificationMessage} + */ +public final class NotificationMessage extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:NotificationMessage) + NotificationMessageOrBuilder { +private static final long serialVersionUID = 0L; + // Use NotificationMessage.newBuilder() to construct. + private NotificationMessage(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private NotificationMessage() { + type_ = ""; + content_ = ""; + msg_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new NotificationMessage(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private NotificationMessage( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + type_ = s; + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + content_ = s; + break; + } + case 24: { + + timestamp_ = input.readInt64(); + break; + } + case 32: { + + code_ = input.readInt32(); + break; + } + case 42: { + java.lang.String s = input.readStringRequireUtf8(); + + msg_ = s; + break; + } + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.unisinsight.project.grpc.generate.NotificationMessage.class, com.unisinsight.project.grpc.generate.NotificationMessage.Builder.class); + } + + public static final int TYPE_FIELD_NUMBER = 1; + private volatile java.lang.Object type_; + /** + * string type = 1; + * @return The type. + */ + @java.lang.Override + public java.lang.String getType() { + java.lang.Object ref = type_; + 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(); + type_ = s; + return s; + } + } + /** + * string type = 1; + * @return The bytes for type. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getTypeBytes() { + java.lang.Object ref = type_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + type_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CONTENT_FIELD_NUMBER = 2; + private volatile java.lang.Object content_; + /** + * string content = 2; + * @return The content. + */ + @java.lang.Override + public java.lang.String getContent() { + java.lang.Object ref = content_; + 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(); + content_ = s; + return s; + } + } + /** + * string content = 2; + * @return The bytes for content. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getContentBytes() { + java.lang.Object ref = content_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + content_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TIMESTAMP_FIELD_NUMBER = 3; + private long timestamp_; + /** + * int64 timestamp = 3; + * @return The timestamp. + */ + @java.lang.Override + public long getTimestamp() { + return timestamp_; + } + + public static final int CODE_FIELD_NUMBER = 4; + private int code_; + /** + * int32 code = 4; + * @return The code. + */ + @java.lang.Override + public int getCode() { + return code_; + } + + public static final int MSG_FIELD_NUMBER = 5; + private volatile java.lang.Object msg_; + /** + * string msg = 5; + * @return The msg. + */ + @java.lang.Override + public java.lang.String getMsg() { + java.lang.Object ref = msg_; + 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(); + msg_ = s; + return s; + } + } + /** + * string msg = 5; + * @return The bytes for msg. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getMsgBytes() { + java.lang.Object ref = msg_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + msg_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(type_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, type_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(content_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, content_); + } + if (timestamp_ != 0L) { + output.writeInt64(3, timestamp_); + } + if (code_ != 0) { + output.writeInt32(4, code_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msg_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 5, msg_); + } + unknownFields.writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(type_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, type_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(content_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, content_); + } + if (timestamp_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(3, timestamp_); + } + if (code_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(4, code_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(msg_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, msg_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.unisinsight.project.grpc.generate.NotificationMessage)) { + return super.equals(obj); + } + com.unisinsight.project.grpc.generate.NotificationMessage other = (com.unisinsight.project.grpc.generate.NotificationMessage) obj; + + if (!getType() + .equals(other.getType())) return false; + if (!getContent() + .equals(other.getContent())) return false; + if (getTimestamp() + != other.getTimestamp()) return false; + if (getCode() + != other.getCode()) return false; + if (!getMsg() + .equals(other.getMsg())) return false; + if (!unknownFields.equals(other.unknownFields)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + TYPE_FIELD_NUMBER; + hash = (53 * hash) + getType().hashCode(); + hash = (37 * hash) + CONTENT_FIELD_NUMBER; + hash = (53 * hash) + getContent().hashCode(); + hash = (37 * hash) + TIMESTAMP_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getTimestamp()); + hash = (37 * hash) + CODE_FIELD_NUMBER; + hash = (53 * hash) + getCode(); + hash = (37 * hash) + MSG_FIELD_NUMBER; + hash = (53 * hash) + getMsg().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.NotificationMessage parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.unisinsight.project.grpc.generate.NotificationMessage prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code NotificationMessage} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:NotificationMessage) + com.unisinsight.project.grpc.generate.NotificationMessageOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.unisinsight.project.grpc.generate.NotificationMessage.class, com.unisinsight.project.grpc.generate.NotificationMessage.Builder.class); + } + + // Construct using com.unisinsight.project.grpc.generate.NotificationMessage.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + @java.lang.Override + public Builder clear() { + super.clear(); + type_ = ""; + + content_ = ""; + + timestamp_ = 0L; + + code_ = 0; + + msg_ = ""; + + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_NotificationMessage_descriptor; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.NotificationMessage getDefaultInstanceForType() { + return com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance(); + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.NotificationMessage build() { + com.unisinsight.project.grpc.generate.NotificationMessage result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.NotificationMessage buildPartial() { + com.unisinsight.project.grpc.generate.NotificationMessage result = new com.unisinsight.project.grpc.generate.NotificationMessage(this); + result.type_ = type_; + result.content_ = content_; + result.timestamp_ = timestamp_; + result.code_ = code_; + result.msg_ = msg_; + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.unisinsight.project.grpc.generate.NotificationMessage) { + return mergeFrom((com.unisinsight.project.grpc.generate.NotificationMessage)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.unisinsight.project.grpc.generate.NotificationMessage other) { + if (other == com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance()) return this; + if (!other.getType().isEmpty()) { + type_ = other.type_; + onChanged(); + } + if (!other.getContent().isEmpty()) { + content_ = other.content_; + onChanged(); + } + if (other.getTimestamp() != 0L) { + setTimestamp(other.getTimestamp()); + } + if (other.getCode() != 0) { + setCode(other.getCode()); + } + if (!other.getMsg().isEmpty()) { + msg_ = other.msg_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.unisinsight.project.grpc.generate.NotificationMessage parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.unisinsight.project.grpc.generate.NotificationMessage) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object type_ = ""; + /** + * string type = 1; + * @return The type. + */ + public java.lang.String getType() { + java.lang.Object ref = type_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + type_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string type = 1; + * @return The bytes for type. + */ + public com.google.protobuf.ByteString + getTypeBytes() { + java.lang.Object ref = type_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + type_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string type = 1; + * @param value The type to set. + * @return This builder for chaining. + */ + public Builder setType( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + type_ = value; + onChanged(); + return this; + } + /** + * string type = 1; + * @return This builder for chaining. + */ + public Builder clearType() { + + type_ = getDefaultInstance().getType(); + onChanged(); + return this; + } + /** + * string type = 1; + * @param value The bytes for type to set. + * @return This builder for chaining. + */ + public Builder setTypeBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + type_ = value; + onChanged(); + return this; + } + + private java.lang.Object content_ = ""; + /** + * string content = 2; + * @return The content. + */ + public java.lang.String getContent() { + java.lang.Object ref = content_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + content_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string content = 2; + * @return The bytes for content. + */ + public com.google.protobuf.ByteString + getContentBytes() { + java.lang.Object ref = content_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + content_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string content = 2; + * @param value The content to set. + * @return This builder for chaining. + */ + public Builder setContent( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + content_ = value; + onChanged(); + return this; + } + /** + * string content = 2; + * @return This builder for chaining. + */ + public Builder clearContent() { + + content_ = getDefaultInstance().getContent(); + onChanged(); + return this; + } + /** + * string content = 2; + * @param value The bytes for content to set. + * @return This builder for chaining. + */ + public Builder setContentBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + content_ = value; + onChanged(); + return this; + } + + private long timestamp_ ; + /** + * int64 timestamp = 3; + * @return The timestamp. + */ + @java.lang.Override + public long getTimestamp() { + return timestamp_; + } + /** + * int64 timestamp = 3; + * @param value The timestamp to set. + * @return This builder for chaining. + */ + public Builder setTimestamp(long value) { + + timestamp_ = value; + onChanged(); + return this; + } + /** + * int64 timestamp = 3; + * @return This builder for chaining. + */ + public Builder clearTimestamp() { + + timestamp_ = 0L; + onChanged(); + return this; + } + + private int code_ ; + /** + * int32 code = 4; + * @return The code. + */ + @java.lang.Override + public int getCode() { + return code_; + } + /** + * int32 code = 4; + * @param value The code to set. + * @return This builder for chaining. + */ + public Builder setCode(int value) { + + code_ = value; + onChanged(); + return this; + } + /** + * int32 code = 4; + * @return This builder for chaining. + */ + public Builder clearCode() { + + code_ = 0; + onChanged(); + return this; + } + + private java.lang.Object msg_ = ""; + /** + * string msg = 5; + * @return The msg. + */ + public java.lang.String getMsg() { + java.lang.Object ref = msg_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + msg_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string msg = 5; + * @return The bytes for msg. + */ + public com.google.protobuf.ByteString + getMsgBytes() { + java.lang.Object ref = msg_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + msg_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string msg = 5; + * @param value The msg to set. + * @return This builder for chaining. + */ + public Builder setMsg( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + msg_ = value; + onChanged(); + return this; + } + /** + * string msg = 5; + * @return This builder for chaining. + */ + public Builder clearMsg() { + + msg_ = getDefaultInstance().getMsg(); + onChanged(); + return this; + } + /** + * string msg = 5; + * @param value The bytes for msg to set. + * @return This builder for chaining. + */ + public Builder setMsgBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + msg_ = value; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:NotificationMessage) + } + + // @@protoc_insertion_point(class_scope:NotificationMessage) + private static final com.unisinsight.project.grpc.generate.NotificationMessage DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.unisinsight.project.grpc.generate.NotificationMessage(); + } + + public static com.unisinsight.project.grpc.generate.NotificationMessage getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public NotificationMessage parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new NotificationMessage(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.NotificationMessage getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationMessageOrBuilder.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationMessageOrBuilder.java new file mode 100644 index 0000000..f10c1d9 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationMessageOrBuilder.java @@ -0,0 +1,57 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: message.proto + +package com.unisinsight.project.grpc.generate; + +public interface NotificationMessageOrBuilder extends + // @@protoc_insertion_point(interface_extends:NotificationMessage) + com.google.protobuf.MessageOrBuilder { + + /** + * string type = 1; + * @return The type. + */ + java.lang.String getType(); + /** + * string type = 1; + * @return The bytes for type. + */ + com.google.protobuf.ByteString + getTypeBytes(); + + /** + * string content = 2; + * @return The content. + */ + java.lang.String getContent(); + /** + * string content = 2; + * @return The bytes for content. + */ + com.google.protobuf.ByteString + getContentBytes(); + + /** + * int64 timestamp = 3; + * @return The timestamp. + */ + long getTimestamp(); + + /** + * int32 code = 4; + * @return The code. + */ + int getCode(); + + /** + * string msg = 5; + * @return The msg. + */ + java.lang.String getMsg(); + /** + * string msg = 5; + * @return The bytes for msg. + */ + com.google.protobuf.ByteString + getMsgBytes(); +} diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationProto.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationProto.java new file mode 100644 index 0000000..5e3f656 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationProto.java @@ -0,0 +1,78 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: message.proto + +package com.unisinsight.project.grpc.generate; + +public final class NotificationProto { + private NotificationProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + static final com.google.protobuf.Descriptors.Descriptor + internal_static_RegisterRequest_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_RegisterRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_NotificationMessage_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_NotificationMessage_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_MsgResponse_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_MsgResponse_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\rmessage.proto\"8\n\017RegisterRequest\022\021\n\tcl" + + "ient_sn\030\001 \001(\t\022\022\n\nclient_mac\030\002 \001(\t\"b\n\023Not" + + "ificationMessage\022\014\n\004type\030\001 \001(\t\022\017\n\007conten" + + "t\030\002 \001(\t\022\021\n\ttimestamp\030\003 \001(\003\022\014\n\004code\030\004 \001(\005" + + "\022\013\n\003msg\030\005 \001(\t\"/\n\013MsgResponse\022\017\n\007success\030" + + "\001 \001(\010\022\017\n\007message\030\002 \001(\t2\213\001\n\023NotificationS" + + "ervice\022:\n\016RegisterStream\022\020.RegisterReque" + + "st\032\024.NotificationMessage0\001\0228\n\016shutdownCl" + + "ient\022\020.RegisterRequest\032\024.NotificationMes" + + "sageB<\n%com.unisinsight.project.grpc.gen" + + "erateB\021NotificationProtoP\001b\006proto3" + }; + descriptor = com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }); + internal_static_RegisterRequest_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_RegisterRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_RegisterRequest_descriptor, + new java.lang.String[] { "ClientSn", "ClientMac", }); + internal_static_NotificationMessage_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_NotificationMessage_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_NotificationMessage_descriptor, + new java.lang.String[] { "Type", "Content", "Timestamp", "Code", "Msg", }); + internal_static_MsgResponse_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_MsgResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_MsgResponse_descriptor, + new java.lang.String[] { "Success", "Message", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationServiceGrpc.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationServiceGrpc.java new file mode 100644 index 0000000..22b08d5 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/NotificationServiceGrpc.java @@ -0,0 +1,364 @@ +package com.unisinsight.project.grpc.generate; + +import static io.grpc.MethodDescriptor.generateFullMethodName; + +/** + */ +@javax.annotation.Generated( + value = "by gRPC proto compiler (version 1.50.0)", + comments = "Source: message.proto") +@io.grpc.stub.annotations.GrpcGenerated +public final class NotificationServiceGrpc { + + private NotificationServiceGrpc() {} + + public static final String SERVICE_NAME = "NotificationService"; + + // Static method descriptors that strictly reflect the proto. + private static volatile io.grpc.MethodDescriptor getRegisterStreamMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "RegisterStream", + requestType = com.unisinsight.project.grpc.generate.RegisterRequest.class, + responseType = com.unisinsight.project.grpc.generate.NotificationMessage.class, + methodType = io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) + public static io.grpc.MethodDescriptor getRegisterStreamMethod() { + io.grpc.MethodDescriptor getRegisterStreamMethod; + if ((getRegisterStreamMethod = NotificationServiceGrpc.getRegisterStreamMethod) == null) { + synchronized (NotificationServiceGrpc.class) { + if ((getRegisterStreamMethod = NotificationServiceGrpc.getRegisterStreamMethod) == null) { + NotificationServiceGrpc.getRegisterStreamMethod = getRegisterStreamMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "RegisterStream")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance())) + .setSchemaDescriptor(new NotificationServiceMethodDescriptorSupplier("RegisterStream")) + .build(); + } + } + } + return getRegisterStreamMethod; + } + + private static volatile io.grpc.MethodDescriptor getShutdownClientMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "shutdownClient", + requestType = com.unisinsight.project.grpc.generate.RegisterRequest.class, + responseType = com.unisinsight.project.grpc.generate.NotificationMessage.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor getShutdownClientMethod() { + io.grpc.MethodDescriptor getShutdownClientMethod; + if ((getShutdownClientMethod = NotificationServiceGrpc.getShutdownClientMethod) == null) { + synchronized (NotificationServiceGrpc.class) { + if ((getShutdownClientMethod = NotificationServiceGrpc.getShutdownClientMethod) == null) { + NotificationServiceGrpc.getShutdownClientMethod = getShutdownClientMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "shutdownClient")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + com.unisinsight.project.grpc.generate.NotificationMessage.getDefaultInstance())) + .setSchemaDescriptor(new NotificationServiceMethodDescriptorSupplier("shutdownClient")) + .build(); + } + } + } + return getShutdownClientMethod; + } + + /** + * Creates a new async stub that supports all call types for the service + */ + public static NotificationServiceStub newStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public NotificationServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new NotificationServiceStub(channel, callOptions); + } + }; + return NotificationServiceStub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static NotificationServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public NotificationServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new NotificationServiceBlockingStub(channel, callOptions); + } + }; + return NotificationServiceBlockingStub.newStub(factory, channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary calls on the service + */ + public static NotificationServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public NotificationServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new NotificationServiceFutureStub(channel, callOptions); + } + }; + return NotificationServiceFutureStub.newStub(factory, channel); + } + + /** + */ + public static abstract class NotificationServiceImplBase implements io.grpc.BindableService { + + /** + *
+     * 客户端注册长连接
+     * 
+ */ + public void registerStream(com.unisinsight.project.grpc.generate.RegisterRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRegisterStreamMethod(), responseObserver); + } + + /** + *
+     * 客户端关闭连接
+     * 
+ */ + public void shutdownClient(com.unisinsight.project.grpc.generate.RegisterRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getShutdownClientMethod(), responseObserver); + } + + @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getRegisterStreamMethod(), + io.grpc.stub.ServerCalls.asyncServerStreamingCall( + new MethodHandlers< + com.unisinsight.project.grpc.generate.RegisterRequest, + com.unisinsight.project.grpc.generate.NotificationMessage>( + this, METHODID_REGISTER_STREAM))) + .addMethod( + getShutdownClientMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.unisinsight.project.grpc.generate.RegisterRequest, + com.unisinsight.project.grpc.generate.NotificationMessage>( + this, METHODID_SHUTDOWN_CLIENT))) + .build(); + } + } + + /** + */ + public static final class NotificationServiceStub extends io.grpc.stub.AbstractAsyncStub { + private NotificationServiceStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected NotificationServiceStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new NotificationServiceStub(channel, callOptions); + } + + /** + *
+     * 客户端注册长连接
+     * 
+ */ + public void registerStream(com.unisinsight.project.grpc.generate.RegisterRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncServerStreamingCall( + getChannel().newCall(getRegisterStreamMethod(), getCallOptions()), request, responseObserver); + } + + /** + *
+     * 客户端关闭连接
+     * 
+ */ + public void shutdownClient(com.unisinsight.project.grpc.generate.RegisterRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getShutdownClientMethod(), getCallOptions()), request, responseObserver); + } + } + + /** + */ + public static final class NotificationServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub { + private NotificationServiceBlockingStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected NotificationServiceBlockingStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new NotificationServiceBlockingStub(channel, callOptions); + } + + /** + *
+     * 客户端注册长连接
+     * 
+ */ + public java.util.Iterator registerStream( + com.unisinsight.project.grpc.generate.RegisterRequest request) { + return io.grpc.stub.ClientCalls.blockingServerStreamingCall( + getChannel(), getRegisterStreamMethod(), getCallOptions(), request); + } + + /** + *
+     * 客户端关闭连接
+     * 
+ */ + public com.unisinsight.project.grpc.generate.NotificationMessage shutdownClient(com.unisinsight.project.grpc.generate.RegisterRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getShutdownClientMethod(), getCallOptions(), request); + } + } + + /** + */ + public static final class NotificationServiceFutureStub extends io.grpc.stub.AbstractFutureStub { + private NotificationServiceFutureStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected NotificationServiceFutureStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new NotificationServiceFutureStub(channel, callOptions); + } + + /** + *
+     * 客户端关闭连接
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture shutdownClient( + com.unisinsight.project.grpc.generate.RegisterRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getShutdownClientMethod(), getCallOptions()), request); + } + } + + private static final int METHODID_REGISTER_STREAM = 0; + private static final int METHODID_SHUTDOWN_CLIENT = 1; + + private static final class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final NotificationServiceImplBase serviceImpl; + private final int methodId; + + MethodHandlers(NotificationServiceImplBase serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_REGISTER_STREAM: + serviceImpl.registerStream((com.unisinsight.project.grpc.generate.RegisterRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + case METHODID_SHUTDOWN_CLIENT: + serviceImpl.shutdownClient((com.unisinsight.project.grpc.generate.RegisterRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + private static abstract class NotificationServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { + NotificationServiceBaseDescriptorSupplier() {} + + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return com.unisinsight.project.grpc.generate.NotificationProto.getDescriptor(); + } + + @java.lang.Override + public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { + return getFileDescriptor().findServiceByName("NotificationService"); + } + } + + private static final class NotificationServiceFileDescriptorSupplier + extends NotificationServiceBaseDescriptorSupplier { + NotificationServiceFileDescriptorSupplier() {} + } + + private static final class NotificationServiceMethodDescriptorSupplier + extends NotificationServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { + private final String methodName; + + NotificationServiceMethodDescriptorSupplier(String methodName) { + this.methodName = methodName; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { + return getServiceDescriptor().findMethodByName(methodName); + } + } + + private static volatile io.grpc.ServiceDescriptor serviceDescriptor; + + public static io.grpc.ServiceDescriptor getServiceDescriptor() { + io.grpc.ServiceDescriptor result = serviceDescriptor; + if (result == null) { + synchronized (NotificationServiceGrpc.class) { + result = serviceDescriptor; + if (result == null) { + serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) + .setSchemaDescriptor(new NotificationServiceFileDescriptorSupplier()) + .addMethod(getRegisterStreamMethod()) + .addMethod(getShutdownClientMethod()) + .build(); + } + } + } + return result; + } +} diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/RegisterRequest.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/RegisterRequest.java new file mode 100644 index 0000000..ede0027 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/RegisterRequest.java @@ -0,0 +1,695 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: message.proto + +package com.unisinsight.project.grpc.generate; + +/** + * Protobuf type {@code RegisterRequest} + */ +public final class RegisterRequest extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:RegisterRequest) + RegisterRequestOrBuilder { +private static final long serialVersionUID = 0L; + // Use RegisterRequest.newBuilder() to construct. + private RegisterRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private RegisterRequest() { + clientSn_ = ""; + clientMac_ = ""; + } + + @java.lang.Override + @SuppressWarnings({"unused"}) + protected java.lang.Object newInstance( + UnusedPrivateParameter unused) { + return new RegisterRequest(); + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private RegisterRequest( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + clientSn_ = s; + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + clientMac_ = s; + break; + } + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.unisinsight.project.grpc.generate.RegisterRequest.class, com.unisinsight.project.grpc.generate.RegisterRequest.Builder.class); + } + + public static final int CLIENT_SN_FIELD_NUMBER = 1; + private volatile java.lang.Object clientSn_; + /** + * string client_sn = 1; + * @return The clientSn. + */ + @java.lang.Override + public java.lang.String getClientSn() { + java.lang.Object ref = clientSn_; + 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(); + clientSn_ = s; + return s; + } + } + /** + * string client_sn = 1; + * @return The bytes for clientSn. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getClientSnBytes() { + java.lang.Object ref = clientSn_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientSn_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CLIENT_MAC_FIELD_NUMBER = 2; + private volatile java.lang.Object clientMac_; + /** + * string client_mac = 2; + * @return The clientMac. + */ + @java.lang.Override + public java.lang.String getClientMac() { + java.lang.Object ref = clientMac_; + 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(); + clientMac_ = s; + return s; + } + } + /** + * string client_mac = 2; + * @return The bytes for clientMac. + */ + @java.lang.Override + public com.google.protobuf.ByteString + getClientMacBytes() { + java.lang.Object ref = clientMac_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientMac_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + @java.lang.Override + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + @java.lang.Override + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientSn_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, clientSn_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientMac_)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, clientMac_); + } + unknownFields.writeTo(output); + } + + @java.lang.Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientSn_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, clientSn_); + } + if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(clientMac_)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, clientMac_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof com.unisinsight.project.grpc.generate.RegisterRequest)) { + return super.equals(obj); + } + com.unisinsight.project.grpc.generate.RegisterRequest other = (com.unisinsight.project.grpc.generate.RegisterRequest) obj; + + if (!getClientSn() + .equals(other.getClientSn())) return false; + if (!getClientMac() + .equals(other.getClientMac())) return false; + if (!unknownFields.equals(other.unknownFields)) return false; + return true; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + CLIENT_SN_FIELD_NUMBER; + hash = (53 * hash) + getClientSn().hashCode(); + hash = (37 * hash) + CLIENT_MAC_FIELD_NUMBER; + hash = (53 * hash) + getClientMac().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static com.unisinsight.project.grpc.generate.RegisterRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + @java.lang.Override + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(com.unisinsight.project.grpc.generate.RegisterRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + @java.lang.Override + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code RegisterRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:RegisterRequest) + com.unisinsight.project.grpc.generate.RegisterRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_descriptor; + } + + @java.lang.Override + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + com.unisinsight.project.grpc.generate.RegisterRequest.class, com.unisinsight.project.grpc.generate.RegisterRequest.Builder.class); + } + + // Construct using com.unisinsight.project.grpc.generate.RegisterRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + @java.lang.Override + public Builder clear() { + super.clear(); + clientSn_ = ""; + + clientMac_ = ""; + + return this; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return com.unisinsight.project.grpc.generate.NotificationProto.internal_static_RegisterRequest_descriptor; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.RegisterRequest getDefaultInstanceForType() { + return com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance(); + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.RegisterRequest build() { + com.unisinsight.project.grpc.generate.RegisterRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.RegisterRequest buildPartial() { + com.unisinsight.project.grpc.generate.RegisterRequest result = new com.unisinsight.project.grpc.generate.RegisterRequest(this); + result.clientSn_ = clientSn_; + result.clientMac_ = clientMac_; + onBuilt(); + return result; + } + + @java.lang.Override + public Builder clone() { + return super.clone(); + } + @java.lang.Override + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.setField(field, value); + } + @java.lang.Override + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return super.clearField(field); + } + @java.lang.Override + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return super.clearOneof(oneof); + } + @java.lang.Override + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return super.setRepeatedField(field, index, value); + } + @java.lang.Override + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return super.addRepeatedField(field, value); + } + @java.lang.Override + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof com.unisinsight.project.grpc.generate.RegisterRequest) { + return mergeFrom((com.unisinsight.project.grpc.generate.RegisterRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(com.unisinsight.project.grpc.generate.RegisterRequest other) { + if (other == com.unisinsight.project.grpc.generate.RegisterRequest.getDefaultInstance()) return this; + if (!other.getClientSn().isEmpty()) { + clientSn_ = other.clientSn_; + onChanged(); + } + if (!other.getClientMac().isEmpty()) { + clientMac_ = other.clientMac_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + @java.lang.Override + public final boolean isInitialized() { + return true; + } + + @java.lang.Override + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.unisinsight.project.grpc.generate.RegisterRequest parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (com.unisinsight.project.grpc.generate.RegisterRequest) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object clientSn_ = ""; + /** + * string client_sn = 1; + * @return The clientSn. + */ + public java.lang.String getClientSn() { + java.lang.Object ref = clientSn_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + clientSn_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string client_sn = 1; + * @return The bytes for clientSn. + */ + public com.google.protobuf.ByteString + getClientSnBytes() { + java.lang.Object ref = clientSn_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientSn_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string client_sn = 1; + * @param value The clientSn to set. + * @return This builder for chaining. + */ + public Builder setClientSn( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + clientSn_ = value; + onChanged(); + return this; + } + /** + * string client_sn = 1; + * @return This builder for chaining. + */ + public Builder clearClientSn() { + + clientSn_ = getDefaultInstance().getClientSn(); + onChanged(); + return this; + } + /** + * string client_sn = 1; + * @param value The bytes for clientSn to set. + * @return This builder for chaining. + */ + public Builder setClientSnBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + clientSn_ = value; + onChanged(); + return this; + } + + private java.lang.Object clientMac_ = ""; + /** + * string client_mac = 2; + * @return The clientMac. + */ + public java.lang.String getClientMac() { + java.lang.Object ref = clientMac_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + clientMac_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string client_mac = 2; + * @return The bytes for clientMac. + */ + public com.google.protobuf.ByteString + getClientMacBytes() { + java.lang.Object ref = clientMac_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + clientMac_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string client_mac = 2; + * @param value The clientMac to set. + * @return This builder for chaining. + */ + public Builder setClientMac( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + clientMac_ = value; + onChanged(); + return this; + } + /** + * string client_mac = 2; + * @return This builder for chaining. + */ + public Builder clearClientMac() { + + clientMac_ = getDefaultInstance().getClientMac(); + onChanged(); + return this; + } + /** + * string client_mac = 2; + * @param value The bytes for clientMac to set. + * @return This builder for chaining. + */ + public Builder setClientMacBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + clientMac_ = value; + onChanged(); + return this; + } + @java.lang.Override + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + @java.lang.Override + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:RegisterRequest) + } + + // @@protoc_insertion_point(class_scope:RegisterRequest) + private static final com.unisinsight.project.grpc.generate.RegisterRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new com.unisinsight.project.grpc.generate.RegisterRequest(); + } + + public static com.unisinsight.project.grpc.generate.RegisterRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + @java.lang.Override + public RegisterRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new RegisterRequest(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + @java.lang.Override + public com.unisinsight.project.grpc.generate.RegisterRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/generate/RegisterRequestOrBuilder.java b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/RegisterRequestOrBuilder.java new file mode 100644 index 0000000..185ca8d --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/generate/RegisterRequestOrBuilder.java @@ -0,0 +1,33 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: message.proto + +package com.unisinsight.project.grpc.generate; + +public interface RegisterRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:RegisterRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * string client_sn = 1; + * @return The clientSn. + */ + java.lang.String getClientSn(); + /** + * string client_sn = 1; + * @return The bytes for clientSn. + */ + com.google.protobuf.ByteString + getClientSnBytes(); + + /** + * string client_mac = 2; + * @return The clientMac. + */ + java.lang.String getClientMac(); + /** + * string client_mac = 2; + * @return The bytes for clientMac. + */ + com.google.protobuf.ByteString + getClientMacBytes(); +} diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/proto/message.proto b/nex-be/src/main/java/com/unisinsight/project/grpc/proto/message.proto new file mode 100644 index 0000000..016e612 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/proto/message.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "com.unisinsight.project.grpc.generate"; +option java_outer_classname = "NotificationProto"; + +service NotificationService { + // 客户端注册长连接 + rpc RegisterStream (RegisterRequest) returns (stream NotificationMessage); + // 客户端关闭连接 + rpc shutdownClient (RegisterRequest) returns (NotificationMessage); +} + +message RegisterRequest { + string client_sn = 1; + string client_mac = 2; +} + +message NotificationMessage { + + string type = 1; + string content = 2; + int64 timestamp = 3; + int32 code=4; + string msg=5; +} + +message MsgResponse { + bool success = 1; + string message = 2; +} \ No newline at end of file diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/service/ClientNotificationServiceImpl.java b/nex-be/src/main/java/com/unisinsight/project/grpc/service/ClientNotificationServiceImpl.java new file mode 100644 index 0000000..b12d811 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/service/ClientNotificationServiceImpl.java @@ -0,0 +1,213 @@ + +package com.unisinsight.project.grpc.service; + +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.unisinsight.project.entity.dao.Device; +import com.unisinsight.project.exception.BaseErrorCode; +import com.unisinsight.project.exception.Result; +import com.unisinsight.project.grpc.generate.NotificationMessage; +import com.unisinsight.project.grpc.generate.NotificationServiceGrpc; +import com.unisinsight.project.grpc.generate.RegisterRequest; +import com.unisinsight.project.service.DeviceService; +import com.unisinsight.project.util.StringUtil; +import io.grpc.stub.StreamObserver; +import lombok.extern.slf4j.Slf4j; +import net.devh.boot.grpc.server.service.GrpcService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; + +/** + * @author : ch + * @version : 1.0 + * @ClassName : ClientNotificationServiceImpl + * @Description : + * @DATE : Created in 9:17 2025/8/21 + *
       Copyright: Copyright(c) 2025     
+ *
       Company :   	紫光汇智信息技术有限公司		           
+ * Modification History: + * Date Author Version Discription + * -------------------------------------------------------------------------- + * 2025/08/21 ch 1.0 Why & What is modified: <修改原因描述> * + */ +@GrpcService +@Slf4j +public class ClientNotificationServiceImpl extends NotificationServiceGrpc.NotificationServiceImplBase implements SendNotificationService { + // 保存客户端连接的映射表 + private final ConcurrentHashMap> clientStreamMap = + new ConcurrentHashMap<>(); + private final static int MAX_CLIENT_COUNT = 1000; + + + @Autowired + @Qualifier("grpcConnectionListenerExecutor") + private ExecutorService executorService; + + @Autowired + private DeviceService deviceService; + + @Override + public void registerStream(RegisterRequest request, StreamObserver responseObserver) { + String clientSn = request.getClientSn(); + String clientMac = request.getClientMac(); + + if (StringUtil.isEmpty(clientSn)) { + NotificationMessage errMsg = NotificationMessage.newBuilder() + .setCode(HttpStatus.BAD_REQUEST.value()) + .setMsg("client_id不能为空") + .build(); + responseObserver.onNext(errMsg); + responseObserver.onCompleted(); + return; // 避免继续执行后续逻辑 + } + + if (StringUtil.isEmpty(clientMac)) { + NotificationMessage errMsg = NotificationMessage.newBuilder() + .setCode(HttpStatus.BAD_REQUEST.value()) + .setMsg("client_mac不能为空") + .build(); + responseObserver.onNext(errMsg); + responseObserver.onCompleted(); + return; // 避免继续执行后续逻辑 + } + + log.info("客户端连接:client_sn:[{}],client_mac: [{}]", clientSn, clientMac); + + addClientConnection(responseObserver, clientSn, clientMac); + + + responseObserver.onNext(NotificationMessage.newBuilder() + .setCode(HttpStatus.OK.value()) + .setMsg("连接成功") + .build()); + // 获取当前的 ServerCall + final io.grpc.Context context = io.grpc.Context.current(); + + // 注册一个取消监听器来监听客户端断开连接 + context.addListener(context1 -> { + // 客户端断开连接时的处理逻辑 + log.info("通过Context监听到客户端断开连接: {}", clientSn); + removeClientConnection(clientSn); + log.info("清理客户端连接: {}, 剩余客户端数: {}", clientSn, clientStreamMap.size()); + }, executorService); + } + + + private StreamObserver removeClientConnection(String clientId) { + StreamObserver remove = clientStreamMap.remove(clientId); + //更新设备状态 + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + //离线 + updateWrapper.set(Device::getDeviceStatus, 0); + updateWrapper.eq(Device::getDeviceId, clientId); + deviceService.update(updateWrapper); + return remove; + } + + private void addClientConnection(StreamObserver responseObserver, String clientId, String clientMac) { + if (clientStreamMap.size() >= MAX_CLIENT_COUNT) { + NotificationMessage errMsg = NotificationMessage.newBuilder() + .setCode(HttpStatus.TOO_MANY_REQUESTS.value()) + .setMsg("服务器连接数已达上限") + .build(); + responseObserver.onNext(errMsg); + responseObserver.onCompleted(); + return; + } + // 使用 putIfAbsent 确保线程安全的注册 + StreamObserver previousObserver = clientStreamMap.putIfAbsent(clientId, responseObserver); + + if (previousObserver != null) { + // 如果已经存在连接,关闭旧连接 + try { + previousObserver.onNext(NotificationMessage.newBuilder() + .setCode(HttpStatus.CONFLICT.value()) + .setMsg("重复连接,已断开旧连接") + .build()); + previousObserver.onCompleted(); + } catch (Exception e) { + log.warn("关闭旧连接时出错: {}", e.getMessage()); + } + // 更新为新的连接 + clientStreamMap.put(clientId, responseObserver); + } + + log.info("客户端注册: {}, 总客户端: {}", clientId, clientStreamMap.size()); + // 连接成功后更新设备状态 + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + //在线 + updateWrapper.set(Device::getDeviceStatus, 1); + updateWrapper.set(Device::getMacAddr, clientMac); + updateWrapper.eq(Device::getDeviceId, clientId); + deviceService.update(updateWrapper); + } + + @Override + public void shutdownClient(RegisterRequest request, StreamObserver responseObserver) { + String clientSn = request.getClientSn(); + String clientMac = request.getClientMac(); + + if (StringUtil.isEmpty(clientSn)) { + NotificationMessage errMsg = NotificationMessage.newBuilder() + .setCode(HttpStatus.BAD_REQUEST.value()) + .setMsg("client_id不能为空") + .build(); + responseObserver.onNext(errMsg); + responseObserver.onCompleted(); + return; // 避免继续执行后续逻辑 + } + + if (StringUtil.isEmpty(clientMac)) { + NotificationMessage errMsg = NotificationMessage.newBuilder() + .setCode(HttpStatus.BAD_REQUEST.value()) + .setMsg("client_mac不能为空") + .build(); + responseObserver.onNext(errMsg); + responseObserver.onCompleted(); + return; // 避免继续执行后续逻辑 + } + log.info("客户端注销:client_sn:[{}],client_mac: [{}]", clientSn, clientMac); + + // 安全地移除并关闭连接 + StreamObserver notificationStream = removeClientConnection(clientSn); + if (notificationStream != null) { + try { + notificationStream.onNext(NotificationMessage.newBuilder() + .setCode(HttpStatus.OK.value()) + .setMsg("注销成功") + .build()); + notificationStream.onCompleted(); + } catch (Exception e) { + log.warn("关闭连接时出错: {}", e.getMessage()); + } + } else { + // 客户端不存在时也返回成功,避免信息泄露 + responseObserver.onNext(NotificationMessage.newBuilder() + .setCode(HttpStatus.OK.value()) + .setMsg("注销成功") + .build()); + } + responseObserver.onCompleted(); + } + + @Override + public Result sendNotification(String clientId, NotificationMessage notification) { + StreamObserver notificationStream = clientStreamMap.get(clientId); + if (notificationStream == null) { + return Result.errorResult(BaseErrorCode.CONNECTION_FAILURE, "未找到对应的客户端连接"); + } + try { + notificationStream.onNext(notification); + } catch (Exception e) { + log.error("发送消息失败,错误信息:{},错误详情:{}", e.getMessage(), e.getStackTrace()); + removeClientConnection(clientId); + return Result.errorResult(BaseErrorCode.CONNECTION_FAILURE, "对应的客户端连接失效"); + } + return Result.successResult(); + } + + +} \ No newline at end of file diff --git a/nex-be/src/main/java/com/unisinsight/project/grpc/service/SendNotificationService.java b/nex-be/src/main/java/com/unisinsight/project/grpc/service/SendNotificationService.java new file mode 100644 index 0000000..dbda60a --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/grpc/service/SendNotificationService.java @@ -0,0 +1,22 @@ +package com.unisinsight.project.grpc.service; + + +import com.unisinsight.project.exception.Result; +import com.unisinsight.project.grpc.generate.NotificationMessage; + +/** + * @author : ch + * @version : 1.0 + * @ClassName : SendNotificationService + * @Description : + * @DATE : Created in 11:45 2025/8/21 + *
       Copyright: Copyright(c) 2025     
+ *
       Company :   	紫光汇智信息技术有限公司		           
+ * Modification History: + * Date Author Version Discription + * -------------------------------------------------------------------------- + * 2025/08/21 ch 1.0 Why & What is modified: <修改原因描述> * + */ +public interface SendNotificationService { + Result sendNotification(String clientId, NotificationMessage notification); +} diff --git a/nex-be/src/main/java/com/unisinsight/project/service/ClientOperateService.java b/nex-be/src/main/java/com/unisinsight/project/service/ClientOperateService.java new file mode 100644 index 0000000..6bcf794 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/service/ClientOperateService.java @@ -0,0 +1,25 @@ +package com.unisinsight.project.service; + + +import com.unisinsight.project.entity.req.DeviceReq; +import com.unisinsight.project.exception.Result; + +/** + * @author : ch + * @version : 1.0 + * @ClassName : ClientOperateService + * @Description : + * @DATE : Created in 17:06 2025/8/21 + *
       Copyright: Copyright(c) 2025     
+ *
       Company :   	紫光汇智信息技术有限公司		           
+ * Modification History: + * Date Author Version Discription + * -------------------------------------------------------------------------- + * 2025/08/21 ch 1.0 Why & What is modified: <修改原因描述> * + */ +public interface ClientOperateService { + + Result terminalStart(DeviceReq deviceReq); + + Result terminalEnd(DeviceReq deviceReq); +} diff --git a/nex-be/src/main/java/com/unisinsight/project/service/impl/ClientOperateServiceImpl.java b/nex-be/src/main/java/com/unisinsight/project/service/impl/ClientOperateServiceImpl.java new file mode 100644 index 0000000..b4defb5 --- /dev/null +++ b/nex-be/src/main/java/com/unisinsight/project/service/impl/ClientOperateServiceImpl.java @@ -0,0 +1,41 @@ +package com.unisinsight.project.service.impl; + + +import com.unisinsight.project.entity.req.DeviceReq; +import com.unisinsight.project.exception.Result; +import com.unisinsight.project.grpc.generate.NotificationMessage; +import com.unisinsight.project.grpc.service.SendNotificationService; +import com.unisinsight.project.service.ClientOperateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author : ch + * @version : 1.0 + * @ClassName : ClientOperateServiceImpl + * @Description : + * @DATE : Created in 17:07 2025/8/21 + *
       Copyright: Copyright(c) 2025     
+ *
       Company :   	紫光汇智信息技术有限公司		           
+ * Modification History: + * Date Author Version Discription + * -------------------------------------------------------------------------- + * 2025/08/21 ch 1.0 Why & What is modified: <修改原因描述> * + */ +@Service +public class ClientOperateServiceImpl implements ClientOperateService { + + @Autowired + private SendNotificationService notificationService; + @Override + public Result terminalStart(DeviceReq deviceReq) { + //todo 待客户端确认消息内容后完善 + return notificationService.sendNotification(deviceReq.getDeviceId(), NotificationMessage.newBuilder().setContent("终端开机").build()); + } + + @Override + public Result terminalEnd(DeviceReq deviceReq) { + //todo 待客户端确认消息内容后完善 + return notificationService.sendNotification(deviceReq.getDeviceId(), NotificationMessage.newBuilder().setContent("终端关机").build()); + } +} diff --git a/nex-be/src/main/java/com/unisinsight/project/service/impl/DeviceServiceImpl.java b/nex-be/src/main/java/com/unisinsight/project/service/impl/DeviceServiceImpl.java index b92bc78..4440733 100644 --- a/nex-be/src/main/java/com/unisinsight/project/service/impl/DeviceServiceImpl.java +++ b/nex-be/src/main/java/com/unisinsight/project/service/impl/DeviceServiceImpl.java @@ -99,6 +99,7 @@ public class DeviceServiceImpl extends ServiceImpl queryWrapper.eq(ObjectUtils.isNotEmpty(deviceReq.getDeviceGroupId()), Device::getDeviceGroupId, deviceReq.getDeviceGroupId()); queryWrapper.eq(StringUtils.isNotBlank(deviceReq.getIpAddr()), Device::getIpAddr, deviceReq.getIpAddr()); queryWrapper.eq(ObjectUtils.isNotEmpty(deviceReq.getDeviceType()), Device::getDeviceType, deviceReq.getDeviceType()); + queryWrapper.eq(ObjectUtils.isNotEmpty(deviceReq.getDeviceStatus()), Device::getDeviceStatus, deviceReq.getDeviceStatus()); queryWrapper.orderByAsc(Device::getId); IPage userPage = deviceMapper.selectPage(page, queryWrapper); diff --git a/nex-be/src/main/resources/application.yml b/nex-be/src/main/resources/application.yml index 97fd951..06e97cb 100644 --- a/nex-be/src/main/resources/application.yml +++ b/nex-be/src/main/resources/application.yml @@ -44,3 +44,7 @@ mybatis-plus: map-underscore-to-camel-case: true cache-enabled: false log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +grpc: + server: + # 指定Grpc暴露的端口,后续客户端通过这个端口访问 + port: 50051 \ No newline at end of file