bihuisong 1 tahun lalu
induk
melakukan
892318df4d

+ 31 - 53
src/main/java/com/sooka/sponest/dataexchange/exchange/controller/ExchangeController.java

@@ -2,10 +2,8 @@ package com.sooka.sponest.dataexchange.exchange.controller;
 
 
 import com.alibaba.fastjson.JSONObject;
-import com.alibaba.nacos.shaded.com.google.gson.Gson;
-import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
+import org.springframework.beans.factory.annotation.Value;
 import com.ruoyi.common.core.domain.R;
-import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.redis.service.RedisService;
 import com.ruoyi.common.security.utils.SecurityUtils;
 import com.sooka.sponest.dataexchange.exchange.domian.DataExchangeEntity;
@@ -17,7 +15,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
-import springfox.documentation.spring.web.json.Json;
 
 import javax.annotation.Resource;
 import java.util.List;
@@ -35,6 +32,8 @@ public class ExchangeController {
     @Resource
     private RedisService redisService;
 
+    @Value("${}")
+    private String url;
 
     /**
      * 获取秘钥接口
@@ -70,63 +69,42 @@ public class ExchangeController {
     public R<?> dataCheck(@RequestBody DataExchangeEntity dataExchangeEntity) {
         if (StringUtils.isNotEmpty(SecurityUtils.getToken())) {
             R<?> result = remoteEventBaseService.saveDataExchangeEntity(dataExchangeEntity);
-//            if (result.getCode() == 200) {
-            return R.ok("操作成功");
-//            } else {
-//                return R.fail("操作失败");
-//            }
+            if (result.getCode() == 200) {
+                return R.ok("推送成功");
+            } else {
+                return R.fail(result.getMsg());
+            }
         } else {
-            return R.fail("操作失败");
+            return R.fail("推送失败");
         }
     }
 
 
-    // TODO: 2024/1/6 0006 事件订阅 待完善
-    @PostMapping("/subscribeTo")
-    @ResponseBody
-    public R<?> dataSubscribeTo(@RequestBody String str) {
-        R<?> result = remoteEventBaseService.subscribeTo(str);
-        if (result.getCode() == 200) {
-            redisService.deleteObject("eventKey");
-            return R.ok("操作成功");
-        } else {
-            return R.fail("操作失败");
-        }
-    }
+    // 舍弃
+//    @PostMapping("/subscribeTo")
+//    @ResponseBody
+//    public R<?> dataSubscribeTo(@RequestBody String str) {
+//        R<?> result = remoteEventBaseService.subscribeTo(str);
+//        if (result.getCode() == 200) {
+//            redisService.deleteObject("eventKey");
+//            return R.ok("操作成功");
+//        } else {
+//            return R.fail("操作失败");
+//        }
+//    }
 
-    // TODO: 2024/1/6 0006  事件推送 Map
-    @PostMapping("/pushData")
+    @PostMapping("/receiveEventData")
     @ResponseBody
-    public R<?> pushData(@RequestBody Map map) {
-        Gson gson = new Gson();
-        String json = gson.toJson(map);
-        JSONObject jsonObject = gson.fromJson(json, JSONObject.class);
-
-        if (redisService.hasKey("eventKey")) {
-            String url = redisService.getCacheObject("eventKey").toString();
-            try {
-                // TODO: 2024/1/9 0009 待修改
-                RestUtil.post(url, jsonObject);
-            } catch (Exception e) {
-                log.info("远程调用119报错");
-            }
-            return R.ok("操作成功");
-        } else {
-            R<?> result = remoteEventBaseService.getDataSubscribeTo();
-            String url = result.getData().toString();
-            if (result.getCode() == 200) {
-                try {
-                    // TODO: 2024/1/9 0009 待修改
-                    RestUtil.post(url, jsonObject);
-                } catch (Exception e) {
-                    log.info("远程调用119报错");
-                }
-                redisService.setCacheObject("eventKey", url);
-                return R.ok("操作成功");
-            } else {
-                return R.fail("操作失败");
-            }
+    public R<?> pushData(@RequestBody DataExchangeEntity dataExchangeEntity) {
+        // TODO: 2024/1/9 0009 待修改
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("",dataExchangeEntity);
+        try {
+            RestUtil.post(url, jsonObject);
+        } catch (Exception e) {
+            log.info("远程调用119报错");
         }
+        return R.ok("操作成功");
     }
 
 }