|
@@ -2,6 +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 com.ruoyi.common.core.domain.R;
|
|
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
import com.ruoyi.common.redis.service.RedisService;
|
|
@@ -42,7 +44,7 @@ public class ExchangeController {
|
|
|
public R<?> getRemoteSecretKey() {
|
|
|
R<?> result = remoteAuthBaseService.getRemoteSecretKey();
|
|
|
if (result.getCode() == 200) {
|
|
|
- return R.ok(result.getData().toString(),"操作成功");
|
|
|
+ return R.ok(result.getData().toString(), "操作成功");
|
|
|
} else {
|
|
|
return R.fail("操作失败");
|
|
|
}
|
|
@@ -57,19 +59,17 @@ public class ExchangeController {
|
|
|
R<?> result = remoteAuthBaseService.loginRemote(form);
|
|
|
if (result.getCode() == 200) {
|
|
|
Map<String, Object> json = (Map<String, Object>) result.getData();
|
|
|
- return R.ok(json.get("access_token").toString(),"操作成功");
|
|
|
+ return R.ok(json.get("access_token").toString(), "操作成功");
|
|
|
} else {
|
|
|
return R.fail("操作失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // TODO: 2024/1/6 0006 数据业务校验
|
|
|
@PostMapping("/straightPushData")
|
|
|
@ResponseBody
|
|
|
- public R<?> dataCheck(@RequestBody List<DataExchangeEntity> list) {
|
|
|
+ public R<?> dataCheck(@RequestBody DataExchangeEntity dataExchangeEntity) {
|
|
|
if (StringUtils.isNotEmpty(SecurityUtils.getToken())) {
|
|
|
- // TODO: 2024/1/6 0006 推送数据 调用event保存
|
|
|
- R<?> result = remoteEventBaseService.saveDataExchangeEntity(list);
|
|
|
+ R<?> result = remoteEventBaseService.saveDataExchangeEntity(dataExchangeEntity);
|
|
|
// if (result.getCode() == 200) {
|
|
|
return R.ok("操作成功");
|
|
|
// } else {
|
|
@@ -81,11 +81,11 @@ public class ExchangeController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // TODO: 2024/1/6 0006 订阅 被119调用 掉用event 更新redis缓存
|
|
|
+ // TODO: 2024/1/6 0006 事件订阅 待完善
|
|
|
@PostMapping("/subscribeTo")
|
|
|
@ResponseBody
|
|
|
- public R<?> dataSubscribeTo(@RequestBody List<String> list) {
|
|
|
- R<?> result = remoteEventBaseService.subscribeTo(list);
|
|
|
+ public R<?> dataSubscribeTo(@RequestBody String str) {
|
|
|
+ R<?> result = remoteEventBaseService.subscribeTo(str);
|
|
|
if (result.getCode() == 200) {
|
|
|
redisService.deleteObject("eventKey");
|
|
|
return R.ok("操作成功");
|
|
@@ -94,34 +94,34 @@ public class ExchangeController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // TODO: 2024/1/6 0006 查询订阅 存redis中 推送119
|
|
|
+ // TODO: 2024/1/6 0006 事件推送 Map
|
|
|
@PostMapping("/pushData")
|
|
|
@ResponseBody
|
|
|
- public R<?> pushData(@RequestBody List<DataExchangeEntity> list) {
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("list", list);
|
|
|
+ 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")) {
|
|
|
- List<String> urlList = redisService.getCacheObject("eventKey");
|
|
|
+ String url = redisService.getCacheObject("eventKey").toString();
|
|
|
try {
|
|
|
- for (String var : urlList) {
|
|
|
- RestUtil.post(var, json);
|
|
|
- }
|
|
|
+ // TODO: 2024/1/9 0009 待修改
|
|
|
+ RestUtil.post(url, jsonObject);
|
|
|
} catch (Exception e) {
|
|
|
log.info("远程调用119报错");
|
|
|
}
|
|
|
return R.ok("操作成功");
|
|
|
} else {
|
|
|
R<?> result = remoteEventBaseService.getDataSubscribeTo();
|
|
|
- List<String> urlList = (List<String>) result.getData();
|
|
|
+ String url = result.getData().toString();
|
|
|
if (result.getCode() == 200) {
|
|
|
try {
|
|
|
- for (String var : urlList) {
|
|
|
- RestUtil.post(var, json);
|
|
|
- }
|
|
|
+ // TODO: 2024/1/9 0009 待修改
|
|
|
+ RestUtil.post(url, jsonObject);
|
|
|
} catch (Exception e) {
|
|
|
log.info("远程调用119报错");
|
|
|
}
|
|
|
- redisService.setCacheList("eventKey", urlList);
|
|
|
+ redisService.setCacheObject("eventKey", url);
|
|
|
return R.ok("操作成功");
|
|
|
} else {
|
|
|
return R.fail("操作失败");
|