Browse Source

机构类型

TRX 1 năm trước cách đây
mục cha
commit
34b8509e33

+ 1 - 1
src/main/java/com/zswl/dataservice/controller/free/FixDataController.java

@@ -26,7 +26,7 @@ public class FixDataController {
     @Autowired
     private FixDataService fixDataService;
 
-    @Operation(summary = "同步全部设备")
+    @Operation(summary = "同步全部设备-网关")
     @RequestMapping(value = "fixSyncDevice", method = {RequestMethod.GET})
     public ResultContent fixSyncDevice() {
         return fixDataService.fixSyncDevice();

+ 4 - 0
src/main/java/com/zswl/dataservice/dao/mqtt/GateWayInfoDao.java

@@ -6,6 +6,8 @@ import com.zswl.dataservice.dao.mqtt.extend.GateWayInfoDaoExtend;
 import com.zswl.dataservice.domain.mqtt.GateWayInfo;
 import com.zswl.dataservice.domain.mqtt.GateWayUserInfo;
 
+import java.util.List;
+
 /**
  * @author TRX
  * @date 2024/3/21
@@ -15,4 +17,6 @@ public interface GateWayInfoDao extends MongoDao<GateWayInfo>, GateWayInfoDaoExt
     GateWayInfo findTopById(String id);
 
     GateWayInfo findTopByGateWayId(String gateWayId);
+
+    List<GateWayInfo> findByGateWayIdIn(List<String> gateWayIds);
 }

+ 5 - 3
src/main/java/com/zswl/dataservice/event/GateWaySyncEvent.java

@@ -3,6 +3,8 @@ package com.zswl.dataservice.event;
 import lombok.Getter;
 import org.springframework.context.ApplicationEvent;
 
+import java.util.List;
+
 /**
  * @author TRX
  * @date 2024/6/26
@@ -10,10 +12,10 @@ import org.springframework.context.ApplicationEvent;
 public class GateWaySyncEvent extends ApplicationEvent {
 
     @Getter
-    private String gateWayId;
+    private List<String> gateWayIds;
 
-    public GateWaySyncEvent(Object source, String gateWayId) {
+    public GateWaySyncEvent(Object source, List<String> gateWayIds) {
         super(source);
-        this.gateWayId = gateWayId;
+        this.gateWayIds = gateWayIds;
     }
 }

+ 3 - 0
src/main/java/com/zswl/dataservice/httpRequest/conf/FullCardAPIConfig.java

@@ -31,6 +31,8 @@ public class FullCardAPIConfig {
     // 全卡业务平台 start -----------------
     // 同步设备
     public static final String deviceSync = api + "/deviceSync/syncDevices";
+    public static final String syncGateWays = api + "/deviceSync/syncGateWays";
+
 
     public static final HashMap<String, ApiConfParam> map = new HashMap<>();
 
@@ -52,6 +54,7 @@ public class FullCardAPIConfig {
 
         // ----------------------------全卡项目 start -----------------
         map.put(deviceSync, ApiConfParam.builder().apiName(deviceSync).methodType(MethodType.Json).build());
+        map.put(syncGateWays, ApiConfParam.builder().apiName(syncGateWays).methodType(MethodType.Json).build());
 
     }
 

+ 17 - 3
src/main/java/com/zswl/dataservice/service/fix/FixDataService.java

@@ -1,7 +1,9 @@
 package com.zswl.dataservice.service.fix;
 
 import com.zswl.dataservice.dao.mqtt.DeviceInfoDao;
+import com.zswl.dataservice.dao.mqtt.GateWayInfoDao;
 import com.zswl.dataservice.domain.mqtt.DeviceInfo;
+import com.zswl.dataservice.domain.mqtt.GateWayInfo;
 import com.zswl.dataservice.service.sync.DeviceSyncFullCardService;
 import com.zswl.dataservice.utils.result.ResultContent;
 import lombok.extern.slf4j.Slf4j;
@@ -9,6 +11,7 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -22,6 +25,9 @@ public class FixDataService {
     @Autowired
     DeviceInfoDao deviceInfoDao;
 
+    @Autowired
+    GateWayInfoDao gateWayInfoDao;
+
     @Autowired
     private DeviceSyncFullCardService deviceSyncFullCardService;
 
@@ -31,13 +37,21 @@ public class FixDataService {
      * @return
      */
     public ResultContent fixSyncDevice() {
-        int count = 0;
+        List<String> strs = new ArrayList<>();
+
+        List<GateWayInfo> gateWayInfos = gateWayInfoDao.findAll();
+        if (ObjectUtils.isNotEmpty(gateWayInfos)) {
+            deviceSyncFullCardService.noticeSyncGateWay(gateWayInfos);
+            strs.add(String.format("同步网关数量:%d", gateWayInfos.size()));
+        }
+        
         List<DeviceInfo> deviceInfoList = deviceInfoDao.findAll();
         if (ObjectUtils.isNotEmpty(deviceInfoList)) {
-            count = deviceInfoList.size();
             deviceSyncFullCardService.noticeSyncDevice(deviceInfoList);
+            strs.add(String.format("同步设备数量:%d", deviceInfoList.size()));
         }
-        return ResultContent.buildSuccess(String.format("同步设备数量:%d", count));
+
+        return ResultContent.buildSuccess(strs);
     }
 
 }

+ 5 - 0
src/main/java/com/zswl/dataservice/service/mqtt/GateWayInfoService.java

@@ -70,6 +70,7 @@ public class GateWayInfoService extends SuperService {
     @Autowired
     DeviceSyncFullCardService deviceSyncFullCardService;
 
+
     /**
      * 添加网关
      *
@@ -182,6 +183,10 @@ public class GateWayInfoService extends SuperService {
 
         // 绑定用户设备权限
         bindUserDevicesPermissions(MqttTopicUtils.getUserRoleName(gateWayUserInfo), deviceInfos);
+
+        // 同步设备
+        deviceSyncFullCardService.noticeSyncDevice(deviceInfos);
+
         return ResultContent.buildSuccess();
     }
 

+ 26 - 6
src/main/java/com/zswl/dataservice/service/sync/DeviceSyncFullCardService.java

@@ -2,6 +2,7 @@ package com.zswl.dataservice.service.sync;
 
 import com.github.microservice.models.device.DeviceInfoSyncParam;
 import com.github.microservice.models.device.DeviceSyncListParam;
+import com.github.microservice.models.device.GateWaySyncParam;
 import com.zswl.dataservice.dao.mqtt.DeviceInfoDao;
 import com.zswl.dataservice.dao.mqtt.GateWay2DeviceDao;
 import com.zswl.dataservice.dao.mqtt.GateWayInfoDao;
@@ -133,8 +134,8 @@ public class DeviceSyncFullCardService extends SuperService {
             }).collect(Collectors.toList());
         }
         param.setList(deviceInfos);
-//        APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.deviceSync, param);
-//        log.info("同步设备情况:{} {}", api.isSuccess(), api.getMsg());
+        APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.deviceSync, param);
+        log.info("同步设备情况:{} {}", api.isSuccess(), api.getMsg());
     }
 
     /**
@@ -145,7 +146,15 @@ public class DeviceSyncFullCardService extends SuperService {
      */
     public ResultContent noticeSyncGateWay(GateWayInfo gateWayInfo) {
         if (ObjectUtils.isNotEmpty(gateWayInfo)) {
-            GateWaySyncEvent event = new GateWaySyncEvent(this, gateWayInfo.getGateWayId());
+            GateWaySyncEvent event = new GateWaySyncEvent(this, List.of(gateWayInfo.getGateWayId()));
+            applicationContext.publishEvent(event);
+        }
+        return ResultContent.buildSuccess();
+    }
+
+    public ResultContent noticeSyncGateWay(List<GateWayInfo> gateWayInfos) {
+        if (ObjectUtils.isNotEmpty(gateWayInfos)) {
+            GateWaySyncEvent event = new GateWaySyncEvent(this, gateWayInfos.stream().map(it -> it.getGateWayId()).collect(Collectors.toList()));
             applicationContext.publishEvent(event);
         }
         return ResultContent.buildSuccess();
@@ -160,8 +169,19 @@ public class DeviceSyncFullCardService extends SuperService {
     @Async
     @SneakyThrows
     public void syncGateWayInfo(GateWaySyncEvent event) {
-        String gatewayId = event.getGateWayId();
-        log.info("event syncGateWayInfo: {}", gatewayId);
-
+        List<String> gatewayIds = event.getGateWayIds();
+        log.info("event syncGateWayInfo: {}", gatewayIds);
+        List<GateWayInfo> gateWayInfos = gateWayInfoDao.findByGateWayIdIn(gatewayIds);
+        if (ObjectUtils.isNotEmpty(gateWayInfos)) {
+            GateWaySyncParam syncParam = new GateWaySyncParam();
+            List<GateWaySyncParam.GateWaySyncInfo> list = gateWayInfos.stream().map(it -> {
+                GateWaySyncParam.GateWaySyncInfo syncInfo = new GateWaySyncParam.GateWaySyncInfo();
+                BeanUtils.copyProperties(it, syncInfo);
+                return syncInfo;
+            }).collect(Collectors.toList());
+            syncParam.setList(list);
+            APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.syncGateWays, syncParam);
+            log.info("同步网关情况:{} {}", api.isSuccess(), api.getMsg());
+        }
     }
 }

+ 6 - 5
src/main/resources/application-dev.yml

@@ -15,16 +15,16 @@ spring:
 
   data:
     mongodb:
-#      uri: mongodb://admin:admin123@192.168.0.104:37047,192.168.0.104:47037,192.168.0.104:37027/iotCenter?replicaSet=rs
+      #      uri: mongodb://admin:admin123@192.168.0.104:37047,192.168.0.104:47037,192.168.0.104:37027/iotCenter?replicaSet=rs
       uri: mongodb://root:8756mongo2024@172.24.50.53:27017,172.24.50.53:27018,172.24.50.53:27019/iotCenter?authSource=admin
       auto-index-creation: true
     redis:
       host: 172.24.50.53
       port: 6379
       password: 8756redis2024
-#      host: 127.0.0.1
-#      port: 6378
-#      password: 8756redis2024
+      #      host: 127.0.0.1
+      #      port: 6378
+      #      password: 8756redis2024
       database: 7
       timeout: 5000
       lettuce:
@@ -40,7 +40,8 @@ artemis:
 
 # 全卡业务平台请求地址配置
 fullcard:
-  url: http://192.168.0.104:9100
+  #  url: http://8.137.120.225:8080/fullcardserver   # 外网
+  url: http://172.24.50.53:8080/fullcardserver-trx
   cardServerName:  # 全卡业务平台服务名
 
 # mqtt 消息存储时间

+ 1 - 1
src/main/resources/application.yml

@@ -5,7 +5,7 @@ debug: true
 
 spring:
   application:
-    name: dataService
+    name: itocenter
   profiles:
     active: dev
   # 允许beans循环引用