ソースを参照

设备同步代码提交

jingyuanchao 11 ヶ月 前
コミット
2839599b9c

+ 0 - 22
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/event/DeviceSyncEvent.java

@@ -1,22 +0,0 @@
-package com.xunmei.common.core.event;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Getter;
-import lombok.Setter;
-import org.springframework.context.ApplicationEvent;
-
-
-@Getter
-@Setter
-public class DeviceSyncEvent extends ApplicationEvent {
-
-    @ApiModelProperty(value = "设备id")
-    private Long deviceId;
-
-
-
-    public DeviceSyncEvent(Object source, Long deviceId) {
-        super(source);
-        this.deviceId = deviceId;
-    }
-}

+ 3 - 3
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/IotDeviceInfoController.java

@@ -92,9 +92,9 @@ public class IotDeviceInfoController {
     }
 
     @ApiOperation("同步设备")
-    @GetMapping({"/reSyncDevice/{id}"})
-    AjaxResult reSyncDevice(@PathVariable Long id) {
-        deviceInfoService.reSyncDevice(id);
+    @GetMapping({"/syncDevice/{id}"})
+    AjaxResult syncDevice(@PathVariable Long id) {
+        deviceInfoService.syncDevice(id);
         return AjaxResult.success();
     }
 }

+ 0 - 25
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/listener/DeviceSyncEventListener.java

@@ -1,25 +0,0 @@
-package com.xunmei.iot.listener;
-
-import com.xunmei.common.core.event.DeviceSyncEvent;
-import com.xunmei.system.api.RemoteHostService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.event.EventListener;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.event.TransactionPhase;
-import org.springframework.transaction.event.TransactionalEventListener;
-
-@Component
-@Slf4j
-public class DeviceSyncEventListener implements ApplicationListener<DeviceSyncEvent> {
-    @Autowired
-    RemoteHostService hostService;
-
-    @Override
-    @EventListener(DeviceSyncEvent.class)
-    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, fallbackExecution = false)
-    public void onApplicationEvent(DeviceSyncEvent event) {
-        hostService.syncDeviceToHost(event.getDeviceId());
-    }
-}

+ 1 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IIotDeviceInfoService.java

@@ -46,6 +46,6 @@ public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
 
     NetHostDeviceInfoVo netHostDeviceInfo(Long id);
 
-    Integer reSyncDevice(Long id);
+    Integer syncDevice(Long id);
 
 }

+ 2 - 9
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -15,7 +15,6 @@ import com.xunmei.common.core.domain.iot.domain.IotAlarmDefenceArea;
 import com.xunmei.common.core.domain.iot.domain.IotAlarmSubsystem;
 import com.xunmei.common.core.domain.iot.domain.IotServerProduct;
 import com.xunmei.common.core.enums.iot.BaseDeviceTypeEnum;
-import com.xunmei.common.core.event.DeviceSyncEvent;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.utils.StringUtils;
 import com.xunmei.common.core.web.page.TableDataInfo;
@@ -41,7 +40,6 @@ import com.xunmei.system.api.domain.iot.IotDeviceInfoExtend;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.BeanUtils;
-import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -67,8 +65,6 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
     private IotServerProductMapper productMapper;
     @Resource
     private IotDeviceInfoExtendService extendService;
-    @Resource
-    private ApplicationEventPublisher eventPublisher;
 
     @Override
     public TableDataInfo<IotDeviceInfoPageVo> deviceInfoPage(IotDeviceInfoPageDto request) {
@@ -223,7 +219,6 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         }
 
         extendService.updateByDeviceId(deviceId, req);
-        eventPublisher.publishEvent(new DeviceSyncEvent(this, deviceId));
         return effect;
     }
 
@@ -313,7 +308,6 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         }
 
         updateAddAlarmHostDevice(req);
-        eventPublisher.publishEvent(new DeviceSyncEvent(this, deviceId));
         return 1;
     }
 
@@ -530,7 +524,6 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         deviceInfo.setDeleted(0);
         saveOrUpdate(deviceInfo);
         extendService.updateNetHostExtendByDeviceId(deviceInfo.getId(), req);
-        eventPublisher.publishEvent(new DeviceSyncEvent(this, deviceInfo.getId()));
         return 1;
     }
 
@@ -552,8 +545,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Integer reSyncDevice(Long id) {
-        eventPublisher.publishEvent(new DeviceSyncEvent(this, id));
+    public Integer syncDevice(Long id) {
+        remoteHostService.syncDeviceToHost(id);
         return 1;
     }
 }

+ 5 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/deviceInfo/IotDeviceInfoPageVo.java

@@ -1,9 +1,11 @@
 package com.xunmei.iot.vo.deviceInfo;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.util.Date;
 
 @Data
 public class IotDeviceInfoPageVo implements Serializable {
@@ -50,4 +52,7 @@ public class IotDeviceInfoPageVo implements Serializable {
 
     @ApiModelProperty(value = "同步状态")
     private Integer syncStatus;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date updateTime;
 }

+ 1 - 1
soc-modules/soc-modules-iot/src/main/resources/mapper/IotDeviceInfoMapper.xml

@@ -34,7 +34,7 @@
                     and d.org_path like concat(#{req.orgPath},'%')
                 </otherwise>
             </choose>
-        order by d.device_type asc,d.id desc
+        order by d.device_type,d.update_time desc
 
     </select>
     <select id="getDetailById" resultType="com.xunmei.iot.vo.deviceInfo.DeviceDetailInfoVo">