Bladeren bron

更新!

TRX 1 jaar geleden
bovenliggende
commit
a4287d0d84

+ 10 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/config/OpenAPIConfig.java

@@ -0,0 +1,10 @@
+package com.zhongshu.iot.server.core.config;
+
+import com.zhongshu.gateway.client.config.OpenApiGatewayClientConfiguration;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+@Configuration
+@Import(OpenApiGatewayClientConfiguration.class)
+public class OpenAPIConfig {
+}

+ 42 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/openAPi/IotSendApiController.java

@@ -0,0 +1,42 @@
+package com.zhongshu.iot.server.core.controller.openAPi;
+
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.helper.AuthHelper;
+import com.github.microservice.auth.security.type.AuthType;
+import com.github.microservice.models.iot.IotSendParam;
+import com.zhongshu.iot.server.core.service.iot.IotSendMessageService;
+import com.zhongshu.iot.server.core.util.result.ResultContent;
+import io.swagger.v3.oas.annotations.Hidden;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.validation.Valid;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 物模型下发数据
+ *
+ * @author TRX
+ * @date 2024/3/21
+ */
+@RequestMapping("/openAPI/manager/sendMessage")
+@RestController
+@Validated
+@Tag(name = "物模型-调用服务")
+public class IotSendApiController {
+
+    @Autowired
+    IotSendMessageService iotSendMessageService;
+
+    @Operation(summary = "下发消息")
+    @RequestMapping(value = "/sendIotMessage", method = {RequestMethod.POST})
+    @Hidden
+    public ResultContent sendIotMessageFree(@RequestBody @Valid IotSendParam param) {
+        return iotSendMessageService.sendIotMessage(param);
+    }
+
+}

+ 36 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/init/OpenApiInit.java

@@ -0,0 +1,36 @@
+package com.zhongshu.iot.server.core.init;
+
+import com.zhongshu.iot.server.core.service.openApi.OpenAPIRegisterService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 平台用户的初始化
+ *
+ * @author TRX
+ * @date 2024/6/3
+ */
+@Component
+@Slf4j
+public class OpenApiInit implements CommandLineRunner {
+
+    @Autowired
+    OpenAPIRegisterService openAPIRegisterService;
+
+    @Override
+    public void run(String... args) throws Exception {
+        CompletableFuture.runAsync(() -> {
+            try {
+                TimeUnit.SECONDS.sleep(30);
+                openAPIRegisterService.initRegisterPAIS();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        });
+    }
+}

+ 2 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/OperationMessageService.java

@@ -3,7 +3,7 @@ package com.zhongshu.iot.server.core.service.artemis;
 import cn.hutool.core.date.StopWatch;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
-import com.github.microservice.models.hxz.base.HxzBaseResult;
+import com.github.microservice.models.hxz.base.IotBaseResult;
 import com.google.gson.JsonObject;
 import com.zhongshu.iot.client.model.artemis.OperationMessageModel;
 import com.zhongshu.iot.client.model.artemis.OperationMessageResultModel;
@@ -467,7 +467,7 @@ public class OperationMessageService {
             String handleMsg = "处理成功";
 
             Long handlerTime = System.currentTimeMillis();
-            HxzBaseResult handleError = new HxzBaseResult();
+            IotBaseResult handleError = new IotBaseResult();
             // 是否需要返回
             Boolean isNeedReplay = Boolean.TRUE;
             String remoteUrl = iotMain.getRemoteUrl();

+ 2 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotSendMessageService.java

@@ -125,7 +125,9 @@ public class IotSendMessageService extends SuperService {
 
                 OperationMessageResult messageResult = new OperationMessageResult();
                 messageResult.setOperationMessage(entity);
+                // 物模型信息
                 messageResult.setIotMain(iotMain);
+
                 // 设备ID
                 messageResult.setDeviceId(iotMain.getDeviceId());
                 // 分组code

+ 54 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/openApi/OpenAPIRegisterService.java

@@ -0,0 +1,54 @@
+package com.zhongshu.iot.server.core.service.openApi;
+
+import com.github.microservice.models.openAPI.OpenApiInfo;
+import com.github.microservice.models.openAPI.RefreshApiParam;
+import com.github.microservice.net.ResultContent;
+import com.github.microservice.utils.OpenAPIScan;
+import com.zhongshu.gateway.client.type.ApiType;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
+
+/**
+ * 注册平台所有的API
+ *
+ * @author TRX
+ * @date 2024/9/29
+ */
+@Slf4j
+@Service
+public class OpenAPIRegisterService {
+
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @Value("${spring.application.name}")
+    private String serviceId;
+
+    public ResultContent initRegisterPAIS() {
+        String str = restTemplate.getForObject("http://" + serviceId + "/v3/api-docs", String.class);
+        List<OpenApiInfo> openAPIS = OpenAPIScan.scanAPI(str, "物联网");
+        RefreshApiParam param = new RefreshApiParam();
+        param.setServerName(serviceId.toLowerCase());
+        param.setPredicateArgs("/openAPI/**");
+        param.setOpenApiInfo(openAPIS);
+        param.setApiType(ApiType.IOT.name());
+
+        ResultContent content = restTemplate.postForObject("http://openapiserver/openapi/manager/api/refresh", param, ResultContent.class);
+        if (content == null) {
+            content = ResultContent.buildSuccess();
+        }
+        if (content.isFailed()) {
+            log.info("openApi注册错误: {}", content.getMsg());
+        } else {
+            log.info("openApi注册成功");
+        }
+        str = null;
+        return ResultContent.buildSuccess();
+    }
+
+}

+ 2 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/other/RequestInfoService.java

@@ -1,6 +1,6 @@
 package com.zhongshu.iot.server.core.service.other;
 
-import com.github.microservice.models.hxz.base.HxzBaseResult;
+import com.github.microservice.models.hxz.base.IotBaseResult;
 import com.zhongshu.iot.client.type.RequestType;
 import com.zhongshu.iot.server.core.dao.payment.RequestInfoDao;
 import com.zhongshu.iot.server.core.domain.payment.RequestInfo;
@@ -30,7 +30,7 @@ public class RequestInfoService {
      * @param response
      * @return
      */
-    public boolean addHXZRequestInfo(Object param, HxzBaseResult response) {
+    public boolean addHXZRequestInfo(Object param, IotBaseResult response) {
         RequestInfo requestInfo = new RequestInfo();
         requestInfo.setParam(param);
         requestInfo.setResponse(response);

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/payment/HxzService.java

@@ -2,7 +2,7 @@ package com.zhongshu.iot.server.core.service.payment;
 
 import cn.hutool.json.JSONUtil;
 import com.github.microservice.models.hxz.*;
-import com.github.microservice.models.type.PaymentType;
+import com.github.microservice.types.payment.PaymentType;
 import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;