Parcourir la source

Merge remote-tracking branch 'origin/test' into test

# Conflicts:
#	device-api-service/src/main/java/com/xy/config/DeviceThreadPoolConfig.java
李进 il y a 1 an
Parent
commit
b3ad2065c1

+ 20 - 0
device-api-service/src/main/java/com/xy/config/DeviceThreadPoolConfig.java

@@ -19,6 +19,8 @@ public class DeviceThreadPoolConfig {
 
     public static final String DEVICE_STATUS_UP = "deviceStatusUp";
 
+    public static final String TY_DEVICE_STATUS = "tyDeviceStatus";
+
     /**
      * 公用线程池
      */
@@ -83,6 +85,24 @@ public class DeviceThreadPoolConfig {
                 .builder();
     }
 
+    /**
+     * 拓元设备状态
+     *
+     * @return {@link ThreadPoolTaskExecutor}
+     */
+    @DynamicTp
+    @Bean(TY_DEVICE_STATUS)
+    public ThreadPoolTaskExecutor tyDeviceStatus() {
+        int coreSize = 1;
+        return ThreadPoolUtils.newPoll()
+                .name(TY_DEVICE_STATUS)
+                .coreSize(coreSize)
+                .maxSize(coreSize * 10)
+                .keepAlive(30)
+                .queueSize(coreSize)
+                .builder();
+    }
+
     /**
      * 设备状态上报线程池
      */

+ 9 - 7
device-api-service/src/main/java/com/xy/service/DeviceInfoServiceImpl.java

@@ -235,8 +235,9 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
         IPage<DeviceInfo> iPage = page(toIPage(pageBean), lqw);
         List<DeviceInfo> records = iPage.getRecords();
         if (CollUtil.isNotEmpty(records)) {
-            records.forEach(r -> {
-                Long deviceId = r.getDeviceId();
+            ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(DeviceThreadPoolConfig.TY_DEVICE_STATUS, records.size());
+            records.forEach(deviceInfo -> execute.execute(() -> {
+                Long deviceId = deviceInfo.getDeviceId();
                 /**
                  * 请求状态码。
                  * 1000: 未知的设备CPUID
@@ -245,19 +246,20 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
                  * 4000: 设备登记成功
                  * 5000: 设备已禁⽤
                  */
-                String tyStatus = r.getThirdStatus();
+                String tyStatus = deviceInfo.getThirdStatus();
                 if (!"4000".equals(tyStatus)) {
                     //未登记成功的需要实时查询
                     //查询登记设备
                     DeviceQueryVO deviceQueryVO = tyApiService.deviceQuery(new DeviceQueryDTO().setCpuId(String.valueOf(deviceId)));
                     Integer status = deviceQueryVO.getStatus();
                     String message = deviceQueryVO.getMessage();
-                    r.setThirdStatus(String.valueOf(status));
-                    r.setThirdResult(message);
-                    updateById(r);
+                    deviceInfo.setThirdStatus(String.valueOf(status));
+                    deviceInfo.setThirdResult(message);
+                    updateById(deviceInfo);
                 }
+            }));
+            execute.end();
 
-            });
         }
         PageBean<DeviceInfoDto.Vo> voPageBean = toPageBean(DeviceInfoDto.Vo.class, iPage);