From 6f12948893fcc846dfb32aa861c473a842edcd56 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 23 Jun 2021 14:46:15 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev_

---
 screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java |   79 ++++++++++++++++++++-------------------
 1 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
index c1b48df..4af7aef 100644
--- a/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
+++ b/screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -12,6 +12,7 @@
 import com.moral.api.service.DeviceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import com.moral.api.util.CacheUtils;
 import com.moral.api.util.AdjustDataUtils;
 import com.moral.api.util.LogUtils;
 import com.moral.constant.Constants;
@@ -91,8 +92,7 @@
      * ���redis������������������
      * */
     private Map<String, Object> getDeviceInfoFromRedis(String mac) {
-        Map<String, Object> deviceInfo = (Map<String, Object>) redisTemplate.opsForValue().get(getDeviceKey(mac));
-        return deviceInfo;
+        return (Map<String, Object>) redisTemplate.opsForValue().get(getDeviceKey(mac));
     }
 
     /*
@@ -116,13 +116,6 @@
         return keysConnect(RedisConstants.DEVICE, mac);
     }
 
-    /*
-     * ���redis������������������
-     * */
-    private Map<String, Object> getOrgAlarmConfigFromRedis(String orId) {
-        return null;
-    }
-
     //redis key������
     private String keysConnect(String... keys) {
         StringBuilder key = new StringBuilder(keys[0]);
@@ -141,13 +134,15 @@
         deviceMapper.insert(device);
         Map<String, Object> deviceInfo = selectDeviceInfoById(device.getId());
         //���������������������������
-        insertOrganizationUnitAlarm(orgId, device.getDeviceVersionId());
+        insertOrganizationUnitAlarm(orgId,device.getDeviceVersionId());
         //������������������������redis
         String mac = device.getMac();
         //���redis���������������������
         delDeviceInfoFromRedis(mac);
         //������������������redis
         setDeviceInfoToRedis(mac, deviceInfo);
+        //������deviceInfo������
+        CacheUtils.flushDeviceAlarmInfo();
         //������������������
         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         StringBuilder content = new StringBuilder();
@@ -165,6 +160,12 @@
         String mac = device.getMac();
         //���redis���������������������
         delDeviceInfoFromRedis(mac);
+        //���������������������������
+        Integer versionId = device.getDeviceVersionId();
+        Integer orgId = device.getOrganizationId();
+        deleteOrganizationUnitAlarm(orgId,versionId);
+        //������deviceInfo������
+        CacheUtils.flushDeviceAlarmInfo();
         //������������������
         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         StringBuilder content = new StringBuilder();
@@ -178,7 +179,7 @@
         Integer deviceId = device.getId();
         Device oldDevice = deviceMapper.selectById(deviceId);
         //���������������������������������������������������������������������������������id������������
-        if (!ObjectUtils.isEmpty(device.getMonitorPointId())) {
+        if(!ObjectUtils.isEmpty(device.getMonitorPointId())){
             MonitorPoint monitorPoint = monitorPointMapper.selectById(device.getMonitorPointId());
             device.setOrganizationId(monitorPoint.getOrganizationId());
         }
@@ -186,19 +187,21 @@
         Device updateDevice = deviceMapper.selectById(deviceId);
         String mac = updateDevice.getMac();
         //���������������������������
-        Integer oldOrgId = oldDevice.getOrganizationId();
-        Integer newOrgId = updateDevice.getOrganizationId();
-        Integer oldVersionId = oldDevice.getDeviceVersionId();
-        Integer newVersionId = updateDevice.getDeviceVersionId();
-        if (!oldOrgId.equals(newOrgId) || !oldVersionId.equals(newVersionId)) {
-            deleteOrganizationUnitAlarm(oldOrgId, oldVersionId);
-            insertOrganizationUnitAlarm(newOrgId, newVersionId);
-        }
+       Integer oldOrgId = oldDevice.getOrganizationId();
+       Integer newOrgId = updateDevice.getOrganizationId();
+       Integer oldVersionId = oldDevice.getDeviceVersionId();
+       Integer newVersionId = updateDevice.getDeviceVersionId();
+       if(!oldOrgId.equals(newOrgId)||!oldVersionId.equals(newVersionId)){
+           deleteOrganizationUnitAlarm(oldOrgId,oldVersionId);
+           insertOrganizationUnitAlarm(newOrgId,newVersionId);
+       }
         //���redis���������������������
         delDeviceInfoFromRedis(mac);
         Map<String, Object> deviceInfo = selectDeviceInfoById(deviceId);
         //������������������redis
         setDeviceInfoToRedis(mac, deviceInfo);
+        //������deviceInfo������
+        CacheUtils.flushDeviceAlarmInfo();
         //������������������
         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         StringBuilder content = new StringBuilder();
@@ -490,18 +493,18 @@
         return state;
     }
 
-    private void insertOrganizationUnitAlarm(Integer orgId, Integer versionId) {
+    private void insertOrganizationUnitAlarm(Integer orgId,Integer versionId){
         QueryWrapper<OrganizationUnitAlarm> queryOrganizationVersionWrapper = new QueryWrapper<>();
-        queryOrganizationVersionWrapper.eq("organization_id", orgId);
-        queryOrganizationVersionWrapper.eq("version_id", versionId);
-        queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE);
+        queryOrganizationVersionWrapper.eq("organization_id",orgId);
+        queryOrganizationVersionWrapper.eq("version_id",versionId);
+        queryOrganizationVersionWrapper.eq("is_delete",Constants.NOT_DELETE);
         List<OrganizationUnitAlarm> organizationUnitAlarms = organizationUnitAlarmMapper.selectList(queryOrganizationVersionWrapper);
-        if (ObjectUtils.isEmpty(organizationUnitAlarms)) {
-            QueryWrapper<VersionSensorUnit> queryVersionSensorUnitWrapper = new QueryWrapper<>();
-            queryVersionSensorUnitWrapper.eq("version_id", versionId);
-            queryVersionSensorUnitWrapper.eq("is_delete", Constants.NOT_DELETE);
+        if(ObjectUtils.isEmpty(organizationUnitAlarms)){
+            QueryWrapper<VersionSensorUnit> queryVersionSensorUnitWrapper =new QueryWrapper<>();
+            queryVersionSensorUnitWrapper.eq("version_id",versionId);
+            queryVersionSensorUnitWrapper.eq("is_delete",Constants.NOT_DELETE);
             List<VersionSensorUnit> versionSensorUnits = versionSensorUnitMapper.selectList(queryVersionSensorUnitWrapper);
-            if (!ObjectUtils.isEmpty(versionSensorUnits)) {
+            if(!ObjectUtils.isEmpty(versionSensorUnits)){
                 for (VersionSensorUnit versionSensorUnit : versionSensorUnits) {
                     OrganizationUnitAlarm organizationUnitAlarm = new OrganizationUnitAlarm();
                     organizationUnitAlarm.setOrganizationId(orgId);
@@ -515,19 +518,19 @@
         }
     }
 
-    private void deleteOrganizationUnitAlarm(Integer orgId, Integer versionId) {
+    private void deleteOrganizationUnitAlarm(Integer orgId,Integer versionId){
         QueryWrapper<Device> queryOrganizationVersionWrapper = new QueryWrapper<>();
-        queryOrganizationVersionWrapper.eq("organization_id", orgId);
-        queryOrganizationVersionWrapper.eq("device_version_id", versionId);
-        queryOrganizationVersionWrapper.eq("is_delete", Constants.NOT_DELETE);
+        queryOrganizationVersionWrapper.eq("organization_id",orgId);
+        queryOrganizationVersionWrapper.eq("device_version_id",versionId);
+        queryOrganizationVersionWrapper.eq("is_delete",Constants.NOT_DELETE);
         List<Device> devices = deviceMapper.selectList(queryOrganizationVersionWrapper);
-        if (ObjectUtils.isEmpty(devices)) {//������������������������������������������������������
+        if(ObjectUtils.isEmpty(devices)){//������������������������������������������������������
             UpdateWrapper deleteWrapper = new UpdateWrapper();
-            deleteWrapper.eq("organization_id", orgId);
-            deleteWrapper.eq("version_id", versionId);
-            deleteWrapper.eq("is_delete", Constants.NOT_DELETE);
-            deleteWrapper.set("is_delete", Constants.DELETE);
-            organizationUnitAlarmMapper.update(null, deleteWrapper);
+            deleteWrapper.eq("organization_id",orgId);
+            deleteWrapper.eq("version_id",versionId);
+            deleteWrapper.eq("is_delete",Constants.NOT_DELETE);
+            deleteWrapper.set("is_delete",Constants.DELETE);
+            organizationUnitAlarmMapper.update(null,deleteWrapper);
         }
     }
 }

--
Gitblit v1.8.0