Ver código fonte

报警功能

Askin 2 anos atrás
pai
commit
1abdb51a7d

+ 1 - 1
sources/server/vrv/run/application.pid

@@ -1 +1 @@
-18384
+16216

+ 1 - 1
sources/server/vrv/vrv-core-api/src/main/java/com/kuyuntech/vrv/coreapi/service/core/DeviceAlarmConfigService.java

@@ -92,6 +92,6 @@ public interface DeviceAlarmConfigService  {
      */
     void batchDeleteByCodes(List<String> codes);
 
-    
 
+    DeviceAlarmConfigBean findByName(String name);
 }

+ 2 - 0
sources/server/vrv/vrv-core-api/src/main/java/com/kuyuntech/vrv/coreapi/service/core/DeviceAlarmRecordService.java

@@ -26,6 +26,8 @@ public interface DeviceAlarmRecordService  {
      */
      DeviceAlarmRecordBean update(DeviceAlarmRecordBean deviceAlarmRecordBean);
 
+    String updateParam(String alarmCode);
+
     /**
      * 删除记录
      * @param deviceAlarmRecordBean 删除参数

+ 1 - 1
sources/server/vrv/vrv-core-service/src/main/java/com/kuyuntech/vrv/coreservice/dao/core/DeviceAlarmConfigDao.java

@@ -18,5 +18,5 @@ public interface DeviceAlarmConfigDao extends FastbootRepository<DeviceAlarmConf
    DeviceAlarmConfig findByCodeAndValid(String code,Short valid);
 
 
-    DeviceAlarmConfig findByVariableIdAndValid(String variableId, short valid);
+    DeviceAlarmConfig findByVariableIdAndValid(String variableId, Short valid);
 }

+ 6 - 8
sources/server/vrv/vrv-core-service/src/main/java/com/kuyuntech/vrv/coreservice/dao/core/DeviceAlarmRecordDao.java

@@ -2,23 +2,21 @@ package com.kuyuntech.vrv.coreservice.dao.core;
 
 import com.kuyuntech.vrv.coreservice.domain.core.DeviceAlarmRecord;
 import com.wbspool.fastboot.core.jpa.repository.FastbootRepository;
+import org.hibernate.type.ShortType;
 
-
+import java.util.List;
 
 
 /**
  * DeviceAlarmRecordDao
- *
  */
-public interface DeviceAlarmRecordDao extends FastbootRepository<DeviceAlarmRecord,Long> {
+public interface DeviceAlarmRecordDao extends FastbootRepository<DeviceAlarmRecord, Long> {
+
 
-    
+    DeviceAlarmRecord findByCodeAndValid(String code, Short valid);
 
-   
-   DeviceAlarmRecord findByCodeAndValid(String code,Short valid);
-   
 
-   
+    List<DeviceAlarmRecord> findAllByAlarmConfigCodeAndValid(String code, Short valid);
 
 
 }

+ 71 - 63
sources/server/vrv/vrv-core-service/src/main/java/com/kuyuntech/vrv/coreservice/service/core/impl/DeviceAlarmConfigServiceImpl.java

@@ -4,11 +4,14 @@ package com.kuyuntech.vrv.coreservice.service.core.impl;
 import com.kuyuntech.vrv.coreapi.service.core.DeviceAlarmConfigService;
 import com.kuyuntech.vrv.coreservice.dao.core.*;
 import com.kuyuntech.vrv.coreservice.domain.core.*;
+import org.apache.commons.lang3.Validate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import com.kuyuntech.vrv.coreapi.bean.core.DeviceAlarmConfigBean;
 import com.wbspool.fastboot.core.common.bean.PagerBean;
+
 import java.util.List;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,23 +19,22 @@ import org.springframework.beans.BeanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.hibernate.criterion.DetachedCriteria;
 import org.hibernate.criterion.Restrictions;
+
 import java.util.ArrayList;
+
 import org.hibernate.criterion.Order;
 import com.wbspool.fastboot.core.jpa.service.AbstractFastbootService;
 import org.springframework.util.Assert;
-import static com.wbspool.fastboot.core.jpa.constant.DataValidTypes.*;
-
-
 
+import static com.wbspool.fastboot.core.jpa.constant.DataValidTypes.*;
 
 
 /**
-* DeviceAlarmConfigService
-*
-*/
+ * DeviceAlarmConfigService
+ */
 @Service("deviceAlarmConfigService")
-@Transactional(rollbackFor = Exception.class,transactionManager = "vrvCoreServiceTransactionManager")
-public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<DeviceAlarmConfig,DeviceAlarmConfigBean> implements DeviceAlarmConfigService {
+@Transactional(rollbackFor = Exception.class, transactionManager = "vrvCoreServiceTransactionManager")
+public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<DeviceAlarmConfig, DeviceAlarmConfigBean> implements DeviceAlarmConfigService {
 
     private static final Logger logger = LoggerFactory.getLogger(DeviceAlarmConfigServiceImpl.class);
 
@@ -52,7 +54,7 @@ public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<Device
     public DeviceAlarmConfigBean add(DeviceAlarmConfigBean deviceAlarmConfigBean) {
 
         DeviceAlarmConfig deviceAlarmConfig = new DeviceAlarmConfig();
-        beanToDomain(deviceAlarmConfigBean,deviceAlarmConfig,"id");
+        beanToDomain(deviceAlarmConfigBean, deviceAlarmConfig, "id");
 
 
         String operatorNumber = deviceAlarmConfigBean.getOperatorNumber();
@@ -75,7 +77,7 @@ public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<Device
         Operator operator = operatorDao.findByNumberAndValid(operatorNumber, VALID);
         Project project = projectDao.findByNumberAndValid(projectNumber, VALID);
         Gateway gateway = gatewayDao.findByNumberAndValid(gatewayNumber, VALID);
-        Device device = deviceDao.findBySnAndValid(sn,VALID);
+        Device device = deviceDao.findBySnAndValid(sn, VALID);
 
         deviceAlarmConfig.setOperatorCode(operator.getCode());
         deviceAlarmConfig.setProjectCode(project.getCode());
@@ -93,23 +95,23 @@ public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<Device
     @Override
     public DeviceAlarmConfigBean update(DeviceAlarmConfigBean deviceAlarmConfigBean) {
 
-        if(deviceAlarmConfigBean == null ){
-            return null ;
+        if (deviceAlarmConfigBean == null) {
+            return null;
         }
 
-        
-        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByCodeAndValid(deviceAlarmConfigBean.getCode(),VALID);
-        
 
-        if(deviceAlarmConfig == null){
+        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByCodeAndValid(deviceAlarmConfigBean.getCode(), VALID);
+
+
+        if (deviceAlarmConfig == null) {
             return null;
         }
 
-        beanToDomain(deviceAlarmConfigBean,deviceAlarmConfig,"id","code","version","createTime","updateTime","valid");
+        beanToDomain(deviceAlarmConfigBean, deviceAlarmConfig, "id", "code", "version", "createTime", "updateTime", "valid");
 
         deviceAlarmConfigDao.save(deviceAlarmConfig);
 
-        domainToBean(deviceAlarmConfig,deviceAlarmConfigBean);
+        domainToBean(deviceAlarmConfig, deviceAlarmConfigBean);
 
         return deviceAlarmConfigBean;
     }
@@ -117,60 +119,58 @@ public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<Device
     @Override
     public DeviceAlarmConfigBean delete(DeviceAlarmConfigBean deviceAlarmConfigBean) {
 
-        if(deviceAlarmConfigBean == null){
-            return null ;
+        if (deviceAlarmConfigBean == null) {
+            return null;
         }
 
-        
-        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByCodeAndValid(deviceAlarmConfigBean.getCode(),VALID);
-        
+
+        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByCodeAndValid(deviceAlarmConfigBean.getCode(), VALID);
 
 
-        if(deviceAlarmConfig == null){
+        if (deviceAlarmConfig == null) {
             return null;
         }
 
-        
+
         deviceAlarmConfig.setValid(INVALID);
         deviceAlarmConfigDao.save(deviceAlarmConfig);
-        
 
-        domainToBean(deviceAlarmConfig,deviceAlarmConfigBean);
+
+        domainToBean(deviceAlarmConfig, deviceAlarmConfigBean);
 
         return deviceAlarmConfigBean;
     }
 
     @Override
     public DeviceAlarmConfigBean find(DeviceAlarmConfigBean deviceAlarmConfigBean) {
-        if(deviceAlarmConfigBean == null){
-            return null ;
+        if (deviceAlarmConfigBean == null) {
+            return null;
         }
 
-        
-        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByCodeAndValid(deviceAlarmConfigBean.getCode(),VALID);
-        
+
+        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByCodeAndValid(deviceAlarmConfigBean.getCode(), VALID);
 
 
-        if(deviceAlarmConfig == null){
-            return null ;
+        if (deviceAlarmConfig == null) {
+            return null;
         }
-        BeanUtils.copyProperties(deviceAlarmConfig,deviceAlarmConfigBean);
+        BeanUtils.copyProperties(deviceAlarmConfig, deviceAlarmConfigBean);
         return deviceAlarmConfigBean;
     }
 
     @Override
     public DeviceAlarmConfigBean find(String code) {
-        return  this.find(DeviceAlarmConfigBean.builder().code(code).build());
+        return this.find(DeviceAlarmConfigBean.builder().code(code).build());
     }
 
     @Override
     public List<DeviceAlarmConfigBean> findAll(DeviceAlarmConfigBean deviceAlarmConfigBean, PagerBean pagerBean) {
         List<DeviceAlarmConfigBean> deviceAlarmConfigBeans = new ArrayList<>();
         DetachedCriteria detachedCriteria = createListCriteria(deviceAlarmConfigBean);
-        List<DeviceAlarmConfig> deviceAlarmConfigs = deviceAlarmConfigDao.findAll(detachedCriteria,pagerBean);
+        List<DeviceAlarmConfig> deviceAlarmConfigs = deviceAlarmConfigDao.findAll(detachedCriteria, pagerBean);
         for (DeviceAlarmConfig deviceAlarmConfig : deviceAlarmConfigs) {
             DeviceAlarmConfigBean deviceAlarmConfigBeanTemp = new DeviceAlarmConfigBean();
-            domainToBean(deviceAlarmConfig,deviceAlarmConfigBeanTemp);
+            domainToBean(deviceAlarmConfig, deviceAlarmConfigBeanTemp);
             deviceAlarmConfigBeans.add(deviceAlarmConfigBeanTemp);
         }
         return deviceAlarmConfigBeans;
@@ -178,17 +178,17 @@ public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<Device
 
     @Override
     public List<DeviceAlarmConfigBean> findAll(DeviceAlarmConfigBean deviceAlarmConfigBean) {
-       return  this.findAll(deviceAlarmConfigBean,null);
+        return this.findAll(deviceAlarmConfigBean, null);
     }
 
     @Override
-     public Long countAll(DeviceAlarmConfigBean deviceAlarmConfigBean) {
+    public Long countAll(DeviceAlarmConfigBean deviceAlarmConfigBean) {
         DetachedCriteria detachedCriteria = createListCriteria(deviceAlarmConfigBean);
         return deviceAlarmConfigDao.countAll(detachedCriteria);
     }
 
-     @Override
-     public PagerBean<DeviceAlarmConfigBean> findPager(DeviceAlarmConfigBean deviceAlarmConfigBean, PagerBean pagerBean) {
+    @Override
+    public PagerBean<DeviceAlarmConfigBean> findPager(DeviceAlarmConfigBean deviceAlarmConfigBean, PagerBean pagerBean) {
         List<DeviceAlarmConfigBean> deviceAlarmConfigBeans = this.findAll(deviceAlarmConfigBean, pagerBean);
         Long count = this.countAll(deviceAlarmConfigBean);
         PagerBean<DeviceAlarmConfigBean> deviceAlarmConfigPageBean = new PagerBean<>();
@@ -196,30 +196,30 @@ public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<Device
         deviceAlarmConfigPageBean.setItemCount(count.intValue());
         deviceAlarmConfigPageBean.init();
         deviceAlarmConfigPageBean.setItems(deviceAlarmConfigBeans);
-        return  deviceAlarmConfigPageBean ;
-     }
-
-     /**
-      * 创建列表查询条件
-      * @param deviceAlarmConfigBean 查询参数
-      * @return
-      */
-     private static DetachedCriteria createListCriteria(DeviceAlarmConfigBean deviceAlarmConfigBean){
-         DetachedCriteria detachedCriteria = DetachedCriteria.forClass(DeviceAlarmConfig.class);
-         detachedCriteria.add(Restrictions.eq("valid",VALID));
-         return  detachedCriteria;
-     }
+        return deviceAlarmConfigPageBean;
+    }
 
+    /**
+     * 创建列表查询条件
+     *
+     * @param deviceAlarmConfigBean 查询参数
+     * @return
+     */
+    private static DetachedCriteria createListCriteria(DeviceAlarmConfigBean deviceAlarmConfigBean) {
+        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(DeviceAlarmConfig.class);
+        detachedCriteria.add(Restrictions.eq("valid", VALID));
+        return detachedCriteria;
+    }
 
 
     @Override
     public void batchDelete(List<DeviceAlarmConfigBean> deviceAlarmConfigBean) {
-        if(deviceAlarmConfigBean.isEmpty()){
-            return ;
+        if (deviceAlarmConfigBean.isEmpty()) {
+            return;
         }
         List<String> codes = new ArrayList<>();
-       deviceAlarmConfigBean.forEach((e) ->{
-          codes.add(e.getCode());
+        deviceAlarmConfigBean.forEach((e) -> {
+            codes.add(e.getCode());
         });
         batchDeleteByCodes(codes);
 
@@ -229,17 +229,25 @@ public class DeviceAlarmConfigServiceImpl extends AbstractFastbootService<Device
     @Override
     public void batchDeleteByCodes(List<String> codes) {
 
-        if(codes.isEmpty()){
-        return ;
+        if (codes.isEmpty()) {
+            return;
         }
 
         for (String code : codes) {
-            Assert.notNull(this.delete(DeviceAlarmConfigBean.builder().code(code).build()),"batch delete by codes error! ");
+            Assert.notNull(this.delete(DeviceAlarmConfigBean.builder().code(code).build()), "batch delete by codes error! ");
         }
 
     }
 
-    
+    @Override
+    public DeviceAlarmConfigBean findByName(String name) {
+        DeviceAlarmConfigBean deviceAlarmConfigBean = new DeviceAlarmConfigBean();
+        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByVariableIdAndValid(name, VALID);
+
+        domainToBean(deviceAlarmConfig, deviceAlarmConfigBean);
+
+        return deviceAlarmConfigBean;
+    }
 
 
 }

+ 24 - 45
sources/server/vrv/vrv-core-service/src/main/java/com/kuyuntech/vrv/coreservice/service/core/impl/DeviceAlarmRecordServiceImpl.java

@@ -23,7 +23,6 @@ import org.hibernate.criterion.Restrictions;
 
 import java.util.ArrayList;
 
-import org.hibernate.criterion.Order;
 import com.wbspool.fastboot.core.jpa.service.AbstractFastbootService;
 import org.springframework.util.Assert;
 
@@ -56,48 +55,32 @@ public class DeviceAlarmRecordServiceImpl extends AbstractFastbootService<Device
     public DeviceAlarmRecordBean add(DeviceAlarmRecordBean deviceAlarmRecordBean) {
 
         DeviceAlarmRecord deviceAlarmRecord = new DeviceAlarmRecord();
-        beanToDomain(deviceAlarmRecordBean, deviceAlarmRecord, "id");
 
-        String operatorNumber = deviceAlarmRecordBean.getOperatorNumber();
-        String projectNumber = deviceAlarmRecordBean.getProjectNumber();
-        String gatewayNumber = deviceAlarmRecordBean.getGatewayNumber();
-        String sn = deviceAlarmRecordBean.getSn();
+        beanToDomain(deviceAlarmRecordBean, deviceAlarmRecord, "id");
 
-        String variableId = deviceAlarmRecordBean.getVariableId();
+        deviceAlarmRecordDao.save(deviceAlarmRecord);
 
-        if ((operatorNumber == null || operatorNumber == "")
-                && (projectNumber == null || projectNumber == "")
-                && (gatewayNumber == null || gatewayNumber == "")
-                && (sn == null || sn == "")
-                && (variableId == null || variableId == "")) {
+        domainToBean(deviceAlarmRecord, deviceAlarmRecordBean);
 
-            deviceAlarmRecordDao.save(deviceAlarmRecord);
+        return deviceAlarmRecordBean;
+    }
 
-            domainToBean(deviceAlarmRecord, deviceAlarmRecordBean);
+    @Override
+    public DeviceAlarmRecordBean update(DeviceAlarmRecordBean deviceAlarmRecordBean) {
 
-            return deviceAlarmRecordBean;
+        if (deviceAlarmRecordBean == null) {
+            return null;
         }
 
-        Operator operator = operatorDao.findByNumberAndValid(operatorNumber, VALID);
-        Project project = projectDao.findByNumberAndValid(projectNumber, VALID);
-        Gateway gateway = gatewayDao.findByNumberAndValid(gatewayNumber, VALID);
-        Device device = deviceDao.findBySnAndValid(sn, VALID);
-        DeviceAlarmConfig deviceAlarmConfig = deviceAlarmConfigDao.findByVariableIdAndValid(variableId, VALID);
+        List<DeviceAlarmRecord> deviceAlarmRecords = deviceAlarmRecordDao.findAllByAlarmConfigCodeAndValid(deviceAlarmRecordBean.getAlarmConfigCode(), VALID);
 
-        deviceAlarmRecord.setOperatorCode(operator.getCode());
-        deviceAlarmRecord.setProjectCode(project.getCode());
-        deviceAlarmRecord.setGatewayCode(gateway.getCode());
-        deviceAlarmRecord.setDeviceCode(device.getCode());
-
-        deviceAlarmRecord.setAlarmConfigCode(deviceAlarmConfig.getCode());
-        deviceAlarmRecord.setAlarmName(deviceAlarmConfig.getAlarmName());
-        deviceAlarmRecord.setAlarmType(deviceAlarmConfig.getAlarmType());
-        deviceAlarmRecord.setRecordCondition(deviceAlarmConfig.getConfigCondition());
-
-        Date startTime = new Date();
-        deviceAlarmRecord.setStartTime(startTime);
+        DeviceAlarmRecord deviceAlarmRecord = new DeviceAlarmRecord();
+        for (DeviceAlarmRecord alarmRecord : deviceAlarmRecords) {
+            alarmRecord.setEndTime(new Date());
+            alarmRecord.setStatus("0");
 
-        deviceAlarmRecordDao.save(deviceAlarmRecord);
+            deviceAlarmRecordDao.save(alarmRecord);
+        }
 
         domainToBean(deviceAlarmRecord, deviceAlarmRecordBean);
 
@@ -105,27 +88,23 @@ public class DeviceAlarmRecordServiceImpl extends AbstractFastbootService<Device
     }
 
     @Override
-    public DeviceAlarmRecordBean update(DeviceAlarmRecordBean deviceAlarmRecordBean) {
+    public String updateParam(String alarmCode) {
 
-        if (deviceAlarmRecordBean == null) {
+        if (alarmCode == null) {
             return null;
         }
 
+        List<DeviceAlarmRecord> deviceAlarmRecords = deviceAlarmRecordDao.findAllByAlarmConfigCodeAndValid(alarmCode, VALID);
 
-        DeviceAlarmRecord deviceAlarmRecord = deviceAlarmRecordDao.findByCodeAndValid(deviceAlarmRecordBean.getCode(), VALID);
-
+        for (DeviceAlarmRecord alarmRecord : deviceAlarmRecords) {
+            alarmRecord.setEndTime(new Date());
+            alarmRecord.setStatus("0");
 
-        if (deviceAlarmRecord == null) {
-            return null;
+            deviceAlarmRecordDao.save(alarmRecord);
         }
 
-        beanToDomain(deviceAlarmRecordBean, deviceAlarmRecord, "id", "code", "version", "createTime", "updateTime", "valid");
-
-        deviceAlarmRecordDao.save(deviceAlarmRecord);
-
-        domainToBean(deviceAlarmRecord, deviceAlarmRecordBean);
 
-        return deviceAlarmRecordBean;
+        return "成功!";
     }
 
     @Override

+ 135 - 143
sources/server/vrv/vrv-platform/src/main/java/com/kuyuntech/vrv/platform/configuration/core/MqttConfiguration.java

@@ -1,9 +1,14 @@
 package com.kuyuntech.vrv.platform.configuration.core;
 
 import com.alibaba.fastjson.JSONObject;
+import com.kuyuntech.vrv.coreapi.bean.core.DeviceAlarmConfigBean;
+import com.kuyuntech.vrv.coreapi.bean.core.DeviceAlarmRecordBean;
 import com.kuyuntech.vrv.coreapi.bean.core.DeviceParamBean;
 import com.kuyuntech.vrv.coreapi.bean.mqtt.DeviceParam;
+import com.kuyuntech.vrv.coreapi.service.core.DeviceAlarmConfigService;
+import com.kuyuntech.vrv.coreapi.service.core.DeviceAlarmRecordService;
 import com.kuyuntech.vrv.coreapi.service.core.DeviceParamService;
+import org.apache.commons.lang3.StringUtils;
 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
@@ -20,17 +25,22 @@ import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
 import org.springframework.messaging.MessageChannel;
 import org.springframework.messaging.MessageHandler;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 @Configuration
 public class MqttConfiguration {
-    @Autowired
-    private RedisTemplate redisTemplate;
+
 
     @Autowired
     private DeviceParamService deviceParamService;
+    @Autowired
+    DeviceAlarmRecordService deviceAlarmRecordService;
+    @Autowired
+    DeviceAlarmConfigService deviceAlarmConfigService;
+
 
     // 消费消息
 
@@ -65,7 +75,7 @@ public class MqttConfiguration {
     @Bean
     public MessageProducer inbound() {
         // Paho客户端消息驱动通道适配器,主要用来订阅主题
-        MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("askin-paho",
+        MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("A-paho",
                 mqttClientFactory(), "mqtt/335102012203A500/data", "mqtt/335102012203A500/cmd", "battery", "+/sensor");
         adapter.setCompletionTimeout(5000);
 
@@ -98,6 +108,7 @@ public class MqttConfiguration {
             } else if (topic.equals("collector")) {
                 System.out.println("采集器的消息:" + payload);
             } else {
+                //设备传入
                 System.out.println("丢弃消息:主题[" + topic + "],负载:" + payload);
 
                 //String转Json
@@ -108,152 +119,133 @@ public class MqttConfiguration {
                 //取里面
                 List<DeviceParam> list = JSONObject.parseArray(devices, DeviceParam.class);
 
-                //CK1
-                String deviceId = list.get(0).getDeviceId();
-                //CK2
-                String deviceId2 = list.get(1).getDeviceId();
-
-                //取deviceData
-                HashMap<String, String> deviceData = list.get(0).getDeviceData();
-                //CK2的deviceData
-                HashMap<String, String> deviceData2 = list.get(1).getDeviceData();
-
-                //存入数据库的新增方法,将第一次读取到的数据存入数据库
-
-                //先将数据存入redis,检验所有数据,如果出现数据改变,就执行update更新数据库,并更新redis
-
-                //用长度做判断
-//                Long size = redisTemplate.opsForHash().size("paramKeyValue");
-//                Long size2 = redisTemplate.opsForHash().size("paramKeyValueCK2");
-//                System.out.println(size);
-//                System.out.println(size2);
-
-//                if (size == 0) {
-//                    //遍历CK1数据
-//                    for (Map.Entry<String, String> entry : deviceData.entrySet()) {
-//
-//                        String name = entry.getKey();
-//                        String value = entry.getValue();
-//
-//                        //存入hash
-//                        redisTemplate.opsForHash().put("paramKeyValue", name, value);
-//
-//                        System.out.println("CK1存入redis成功!");
-//                    }
-//                }
-//
-//                if (size2 == 0) {
-//                    //遍历CK2数据
-//                    for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
-//
-//                        String name = entry.getKey();
-//                        String value = entry.getValue();
-//
-//                        //存入hash
-//                        redisTemplate.opsForHash().put("paramKeyValueCK2", name, value);
-//
-//                        System.out.println("CK2存入redis成功!");
-//                    }
-//                }
-
-                //遍历redis中hash的每一个键值对和mqtt传过来的数据进行比较
-
-                //获取paramKeyValue键值对
-//                HashMap<String, String> paramKeyValue = (HashMap<String, String>) redisTemplate.opsForHash().entries("paramKeyValue");
-//                HashMap<String, String> paramKeyValueCK2 = (HashMap<String, String>) redisTemplate.opsForHash().entries("paramKeyValueCK2");
-
-//                System.out.println("----------------------------");
-//                System.out.println(deviceData);
-//                System.out.println(paramKeyValue);
-//                System.out.println("----------------------------");
-//                System.out.println(deviceData2);
-//                System.out.println(paramKeyValueCK2);
-//                System.out.println("----------------------------");
-
-//                boolean result = CompareParamValue.CompareParamValue(paramKeyValue, deviceData);
-//                boolean result2 = CompareParamValue.CompareParamValue(paramKeyValueCK2, deviceData2);
-
-//                System.out.println("CK1比较的结果:" + result);
-//                System.out.println("CK2比较的结果:" + result2);
-
-                //如果不相等,清除缓存,重新加入,并更新数据库
-//                if (result == false) {
-                //清除redis缓存
-//                    redisTemplate.delete("paramKeyValue");
-
-                //重新存入redis
-//                    for (Map.Entry<String, String> entry : deviceData.entrySet()) {
-//
-//                        String name = entry.getKey();
-//                        String value = entry.getValue();
-//
-//                        //存入hash
-//                        redisTemplate.opsForHash().put("paramKeyValue", name, value);
-//
-//                        System.out.println("重新存入redis成功!");
-//                    }
-
-                long id = 199;
-
-                //更新数据库
-                for (Map.Entry<String, String> entry : deviceData.entrySet()) {
-                    DeviceParamBean deviceParamBean = new DeviceParamBean();
-
-                    deviceParamBean.setSn(deviceId);
-
-                    String name = entry.getKey();
-                    String value = entry.getValue();
-
-
-                    deviceParamBean.setId(id);
-
-                    id = id + 1;
-
-                    deviceParamBean.setName(name);
-                    deviceParamBean.setValue(value);
-
-                    deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
-
-                    System.out.println("id为:" + id  + "-- 更新后的数据:" + deviceParamBean);
+                //判断是否单个
+                if (list.size() == 1) {
+                    System.out.println("这是单个数据的处理");
+
+                    //取deviceData
+                    HashMap<String, String> deviceData = list.get(0).getDeviceData();
+                    System.out.println(deviceData + "=======");
+
+                    //判断传来的是不是报警
+                    for (Map.Entry<String, String> entry : deviceData.entrySet()) {
+
+                        String name = entry.getKey();
+                        String value = entry.getValue();
+
+                        System.out.println(name == "WD_GBJ");
+                        int var = Integer.parseInt(value);
+
+                        if ((name == "WD_GBJ" && var == 1)
+                                || (name == "WD_DBJ" && var == 1)
+                                || (name == "SD_GBJ" && var == 1)
+                                || (name == "SD_DBJ" && var == 1)
+                                || (name == "SFJ_GZ" && var == 1)
+                                || (name == "PFJ_GZ" && var == 1)
+                                || (name == "FLZJ_GZ" && var == 1)
+                                || (name == "GW_BJ" && var == 1)
+                                || (name == "LWDS_CX" && var == 1)
+                                || (name == "LWDS_ZX" && var == 1)
+                                || (name == "JZ_GZ" && var == 1)
+                                || (name == "QFYC_BJ" && var == 1)
+                                || (name == "JZ_JT" && var == 1)) {
+                            System.out.println("这是一个报警!!");
+                            //找到对应的报警设置
+                            DeviceAlarmConfigBean deviceAlarmConfigBean = deviceAlarmConfigService.findByName(name);
+                            //添加一个报警记录
+                            DeviceAlarmRecordBean deviceAlarmRecordBean = new DeviceAlarmRecordBean();
+                            deviceAlarmRecordBean.setAlarmName(deviceAlarmConfigBean.getAlarmName());
+                            deviceAlarmRecordBean.setAlarmType(deviceAlarmConfigBean.getAlarmType());
+                            deviceAlarmRecordBean.setSn("CK1");
+                            deviceAlarmRecordBean.setContent(deviceAlarmConfigBean.getAlarmName());
+                            deviceAlarmRecordBean.setAlarmConfigCode(deviceAlarmConfigBean.getCode());
+                            deviceAlarmRecordBean.setStartTime(new Date());
+                            //状态:1表示未处理,0表示已处理
+                            deviceAlarmRecordBean.setStatus(value);
+                            deviceAlarmRecordService.add(deviceAlarmRecordBean);
+                        }
+
+                        if ((name == "WD_GBJ" && var == 0)
+                                || (name == "WD_DBJ" && var == 0)
+                                || (name == "SD_GBJ" && var == 0)
+                                || (name == "SD_DBJ" && var == 0)
+                                || (name == "SFJ_GZ" && var == 0)
+                                || (name == "PFJ_GZ" && var == 0)
+                                || (name == "FLZJ_GZ" && var == 0)
+                                || (name == "GW_BJ" && var == 0)
+                                || (name == "LWDS_CX" && var == 0)
+                                || (name == "LWDS_ZX" && var == 0)
+                                || (name == "JZ_GZ" && var == 0)
+                                || (name == "QFYC_BJ" && var == 0)
+                                || (name == "JZ_JT" && var == 0)) {
+                            System.out.println("这是一个报警处理,更新为已处理和结束时间!!");
+                            //找到对应的报警设置
+                            DeviceAlarmConfigBean deviceAlarmConfigBean = deviceAlarmConfigService.findByName(name);
+
+                            //状态:1表示未处理,0表示已处理
+                            deviceAlarmRecordService.updateParam(deviceAlarmConfigBean.getCode());
+                        }
+
+
+                    }
+
+
+                } else {
+                    System.out.println("这是所有数据的处理");
+
+                    //CK1
+                    String deviceId = list.get(0).getDeviceId();
+                    //CK2
+                    String deviceId2 = list.get(1).getDeviceId();
+
+                    //取deviceData
+                    HashMap<String, String> deviceData = list.get(0).getDeviceData();
+                    //CK2的deviceData
+                    HashMap<String, String> deviceData2 = list.get(1).getDeviceData();
+
+                    long id = 199;
+
+                    //更新数据库
+                    for (Map.Entry<String, String> entry : deviceData.entrySet()) {
+                        DeviceParamBean deviceParamBean = new DeviceParamBean();
+
+                        deviceParamBean.setSn(deviceId);
+
+                        String name = entry.getKey();
+                        String value = entry.getValue();
+
+
+                        deviceParamBean.setId(id);
+
+                        id = id + 1;
+
+                        deviceParamBean.setName(name);
+                        deviceParamBean.setValue(value);
+
+                        deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
+
+                        System.out.println("id为:" + id + "-- 更新后的数据:" + deviceParamBean);
 
-                }
-//                }
-
-                //如果不相等,清除缓存,重新加入,并更新数据库
-//                if (result2 == false) {
-                //清除redis缓存
-//                    redisTemplate.delete("paramKeyValueCK2");
-
-                //重新存入redis
-//                    for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
-//
-//                        String name = entry.getKey();
-//                        String value = entry.getValue();
-//
-//                        //存入hash
-//                        redisTemplate.opsForHash().put("paramKeyValueCK2", name, value);
-//
-//                        System.out.println("重新存入redis成功!");
-//                    }
-
-                //更新数据库
-                for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
-                    DeviceParamBean deviceParamBean = new DeviceParamBean();
-                    deviceParamBean.setSn(deviceId2);
-
-                    for (long i = 298; i < 300; i++) {
-                        deviceParamBean.setId(i);
                     }
 
-                    String name = entry.getKey();
-                    String value = entry.getValue();
+                    //更新数据库
+                    for (Map.Entry<String, String> entry : deviceData2.entrySet()) {
+                        DeviceParamBean deviceParamBean = new DeviceParamBean();
+                        deviceParamBean.setSn(deviceId2);
 
-                    deviceParamBean.setName(name);
-                    deviceParamBean.setValue(value);
+                        for (long i = 308; i < 310; i++) {
+                            deviceParamBean.setId(i);
+                        }
 
-                    deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
+                        String name = entry.getKey();
+                        String value = entry.getValue();
+
+                        deviceParamBean.setName(name);
+                        deviceParamBean.setValue(value);
+
+                        deviceParamBean = this.deviceParamService.updateParam(deviceParamBean);
+                    }
                 }
-//                }
             }
 
         };