From 2ac80d588a68f60084d8bcc02aabd18c91100267 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Tue, 29 May 2018 14:50:37 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java |   38 +++++++++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
index 3274397..200db4e 100644
--- a/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -95,9 +95,17 @@
                 monitorPoint.setIsDelete(Constants.IS_DELETE_FALSE);
                 monitorPointMapper.insertSelective(monitorPoint);
             }else{
+                MonitorPoint queryMonitorPoint = new MonitorPoint();
+                queryMonitorPoint.setId(monitorPoint.getId());
+                queryMonitorPoint.setOrganizationId(monitorPoint.getOrganizationId());
+                // num = 1,���������������,������������������������
+                Integer num =  monitorPointMapper.selectCount(queryMonitorPoint);
+                boolean needRefreshCach = (num!=1);
                 monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);
-                // ������������������������������ ���redis���������������
-                refreshDevicesInRedis(monitorPoint.getId());
+                if(needRefreshCach){
+                    // ������������������������������ ���redis���������������
+                    refreshDevicesInRedis(monitorPoint.getId());
+                }
             }
         }
         catch (Exception ex){
@@ -108,24 +116,24 @@
       ������������������������������ ���redis���������������
      */
     private void  refreshDevicesInRedis(int monitorPointId){
-        Device device = new Device();
-        device.setMonitorPointId(monitorPointId);
-        List<Device> deviceList = deviceMapper.select(device);
+        Device queryDevice = new Device();
+        queryDevice.setMonitorPointId(monitorPointId);
+        List<Device> deviceList = deviceMapper.select(queryDevice);
         if (!CollectionUtils.isEmpty(deviceList)){
             List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(monitorPointId);
             if (!CollectionUtils.isEmpty(orgIds)){
                 deviceList.stream().forEach(dev ->{
                     if(!StringUtils.isNullOrEmpty(dev.getMac())){
                         String key = "device_"+dev.getMac();
-                        // ��������������������� ������������redis
-                        Device simpleDevice = new Device();
-                        simpleDevice.setId(dev.getId());
-                        simpleDevice.setDeviceVersion(dev.getDeviceVersion());
-                        simpleDevice.setMac(dev.getMac());
-                        simpleDevice.setMonitorPointId(dev.getMonitorPointId());
+//                        // ��������������������� ������������redis
+//                        Device simpleDevice = new Device();
+//                        simpleDevice.setId(dev.getId());
+//                        simpleDevice.setDeviceVersion(dev.getDeviceVersion());
+//                        simpleDevice.setMac(dev.getMac());
+//                        simpleDevice.setMonitorPointId(dev.getMonitorPointId());
                         // ������������������������������������������������������������������
-                        simpleDevice.setOrganizationIds(orgIds);
-                        redisUtils.set(key,simpleDevice);
+                        dev.setOrganizationIds(orgIds);
+                        redisUtils.set(key,dev);
                     }
                 });
             }
@@ -214,4 +222,8 @@
 		criteria.andEqualTo(parameters.get("name").toString(), parameters.get("value"));
 		return monitorPointMapper.selectByExample(example);
 	}
+	@Override
+    public List<Integer> queryVersionsById(Integer id){
+        return  monitorPointMapper.selectVersionsById(id);
+    }
 }

--
Gitblit v1.8.0