From d56ba0ec51cf2b0afa00bbf6ddb0c02ac16393fa Mon Sep 17 00:00:00 2001
From: swb <jpy123456>
Date: Mon, 26 Aug 2024 11:16:55 +0800
Subject: [PATCH] fix:分页查询设备接口修改提交

---
 screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java |  121 +++++++++++++++++++++++++--------------
 1 files changed, 77 insertions(+), 44 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 64eee36..6d10b52 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
@@ -1,8 +1,10 @@
 package com.moral.api.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.googlecode.aviator.AviatorEvaluator;
 import com.googlecode.aviator.Expression;
@@ -21,7 +23,6 @@
 import com.moral.constant.RedisConstants;
 import com.moral.util.ConvertUtils;
 import com.moral.util.DateUtils;
-
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -35,11 +36,9 @@
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.lang.reflect.Type;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import javax.servlet.http.HttpServletRequest;
@@ -77,8 +76,6 @@
     @Autowired
     private SysDictDataService sysDictDataService;
 
-    @Autowired
-    private LogUtils logUtils;
 
     @Autowired
     private RedisTemplate redisTemplate;
@@ -140,7 +137,7 @@
         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         StringBuilder content = new StringBuilder();
         content.append("������������������").append(device.getName()).append(":").append("mac���").append(mac);
-        logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE);
+        LogUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE);
     }
 
     @Override
@@ -163,7 +160,7 @@
         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         StringBuilder content = new StringBuilder();
         content.append("������������������").append(device.getName()).append(";").append("mac���").append(mac);
-        logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE);
+        LogUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE);
     }
 
     @Override
@@ -194,7 +191,7 @@
         //������������������redis
         setDeviceInfoToRedis(mac, deviceInfo);
         //������deviceInfo������
-        CacheUtils.refreshDeviceAlarmInfo();
+        CacheUtils.refreshDeviceAlarmInfo(mac);
         //������������������
         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         StringBuilder content = new StringBuilder();
@@ -223,7 +220,7 @@
             }
 
         }
-        logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE);
+        LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE);
     }
 
     @Override
@@ -294,14 +291,10 @@
             queryWrapper.eq("monitor_point_id", mpId);
         }
 
-        //���������������������
-        if (name != null) {
-            queryWrapper.like("name", name);
-        }
 
-        //mac������������
-        if (mac != null) {
-            queryWrapper.like("mac", mac);
+        //���������������mac������������
+        if (name != null && mac != null) {
+            queryWrapper.eq("is_delete", Constants.NOT_DELETE).like("name", name).or().like("mac", mac);
         }
 
         //������������,������create_time������
@@ -314,7 +307,9 @@
         } else {
             queryWrapper.orderByDesc("create_time");
         }
+        //������������������������
         queryWrapper.eq("is_delete", Constants.NOT_DELETE);
+
         Page<Device> devicePage = new Page<>(page, size);
         deviceMapper.selectPage(devicePage, queryWrapper);
         List<Device> devices = devicePage.getRecords();
@@ -355,9 +350,11 @@
         //������������
         deviceInfo.put("extend", device.getExtend());
 
+        //������������������
+        deviceInfo.put("town", device.getTown());
+
         //������
-        deviceInfo.put("profession", device.getProfession());
-        deviceInfo.put("professionName", device.getProfessionName());
+        deviceInfo.put("professions", device.getProfessions());
 
         //������
         deviceInfo.put("tech", device.getTech());
@@ -450,8 +447,9 @@
     }
 
     @Override
-    public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData) {
-        String mac = deviceData.remove("mac").toString();
+    public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData,String code) {
+//        String mac = deviceData.remove("mac").toString();
+        String mac = deviceData.get("mac").toString();
         //���redis������������������
         Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac);
         if (!ObjectUtils.isEmpty(adjustFormula)) {
@@ -462,7 +460,7 @@
             if (govMpInfo.get("guid") != null) {
                 aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString());
             }
-            return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap);
+            return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap,code);
         }
         deviceData.remove("DataTime");
         return deviceData;
@@ -470,7 +468,8 @@
 
     @Override
     public Map<String, Object> adjustSpecialDeviceData(Map<String, Object> deviceData) {
-        String mac = deviceData.remove("mac").toString();
+//        String mac = deviceData.remove("mac").toString();
+        String mac = deviceData.get("mac").toString();
         //���redis������������������
         Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac);
         if (!ObjectUtils.isEmpty(adjustFormula)) {
@@ -481,14 +480,13 @@
             if (ObjectUtils.isEmpty(aqiMap)) {
                 aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, cityCode);
             }
-            return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap);
+            return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap,"0");
         }
         deviceData.remove("DataTime");
         return deviceData;
     }
 
     @Override
-    @Transactional
     public void judgeDeviceState(Map<String, Object> deviceData) {
         String mac = deviceData.remove("mac").toString();
         Device device = (Device) redisTemplate.opsForHash().get(RedisConstants.DEVICE_INFO, mac);
@@ -506,25 +504,50 @@
             String sensorCode = sensor.getCode();
             //������������
             String formula = sensor.getFormula();
-            //������������������������
-            String sensorValue = (String) deviceData.get(sensorCode);
-            double value = Double.parseDouble(sensorValue);
-            //������������
-            if (formula != null) {
-                //������������������
-                sensorValue = formula.replace("{0}", sensorValue);
-                expression = AviatorEvaluator.compile(sensorValue);
-                value = Double.parseDouble(expression.execute().toString());
-            }
-            int sensorState = judgeState(list, value);
-            if (sensorState > state) {
-                state = sensorState;
+
+            //���������������������������������������������������������������
+            if (deviceData.get(sensorCode) != null) {
+                String sensorValue = String.valueOf(deviceData.get(sensorCode));
+                double value = Double.parseDouble(sensorValue);
+                if (formula != null) {
+                    //������������������
+                    sensorValue = formula.replace("{0}", sensorValue);
+                    expression = AviatorEvaluator.compile(sensorValue);
+                    value = Double.parseDouble(expression.execute().toString());
+                }
+                int sensorState = judgeState(list, value);
+                if (sensorState > state) {
+                    state = sensorState;
+                }
             }
         }
         //������������������
-        UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("id", device.getId()).set("state", String.valueOf(state));
-        deviceMapper.update(null, updateWrapper);
+        Device device1 = new Device();
+        device1.setId(device.getId());
+        device1.setState(String.valueOf(state));
+        deviceMapper.updateById(device1);
+    }
+
+    @Override
+    public List<Map<String, Object>> selectMonitorPiontAndDeviceByOrgId(int orgId) {
+        QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>();
+        monitorPointQueryWrapper.eq("is_delete", Constants.NOT_DELETE);
+        monitorPointQueryWrapper.eq("organization_id", orgId);
+        List<MonitorPoint> monitorPointList = monitorPointMapper.selectList(monitorPointQueryWrapper);
+        List<Map<String, Object>> resultList = new ArrayList<>();
+        for (MonitorPoint monitorPoint : monitorPointList) {
+            Map<String, Object> resultMap = new HashMap<>();
+            resultMap = JSON.parseObject(JSON.toJSONString(monitorPoint), Map.class);
+            int mp_id = monitorPoint.getId();
+            QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
+            deviceQueryWrapper.eq("is_delete", Constants.NOT_DELETE);
+            deviceQueryWrapper.eq("monitor_point_id", mp_id);
+            List<Device> devices = new ArrayList<>();
+            devices = deviceMapper.selectList(deviceQueryWrapper);
+            resultMap.put("devices", devices);
+            resultList.add(resultMap);
+        }
+        return resultList;
     }
 
     //���������������������������
@@ -533,7 +556,7 @@
         for (int i = levels.size() - 1; i >= 0; i--) {
             Double level = Double.parseDouble(levels.get(i).toString());
             if (data >= level) {
-                state = i + 1;
+                state = i + 2;
                 break;
             }
         }
@@ -604,4 +627,14 @@
             organizationUnitAlarmMapper.update(null, deleteWrapper);
         }
     }
+
+    @Override
+    public void setRedisDevice() {
+        List<Device> list = lambdaQuery().eq(Device::getIsDelete,0).list();
+        for(Device d : list){
+            redisTemplate.opsForHash().delete(RedisConstants.DEVICE, d.getMac());
+            Map<String, Object> deviceInfo = selectDeviceInfoById(d.getId());
+            setDeviceInfoToRedis(d.getMac(), deviceInfo);
+        }
+    }
 }

--
Gitblit v1.8.0