From 9169cc4846799cf149c92f76b8b3cb6994c80f84 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 13 Dec 2022 16:45:09 +0800
Subject: [PATCH] 测试sql
---
screen-manage/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java | 89 ++++++++++++++++++++++++++++++++++----------
1 files changed, 69 insertions(+), 20 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 aa34315..9ae3b93 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,5 +1,6 @@
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;
@@ -21,6 +22,7 @@
import com.moral.constant.RedisConstants;
import com.moral.util.ConvertUtils;
import com.moral.util.DateUtils;
+import com.sun.javafx.collections.MappingChange;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,11 +37,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;
@@ -348,6 +348,9 @@
//������������
deviceInfo.put("extend", device.getExtend());
+ //������������������
+ deviceInfo.put("town", device.getTown());
+
//������
deviceInfo.put("professions", device.getProfessions());
@@ -441,8 +444,10 @@
return deviceInfo;
}
+ @Autowired
+ private HistoryHourlyMapper historyHourlyMapper;
@Override
- public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData) {
+ public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData,String code) {
String mac = deviceData.remove("mac").toString();
//���redis������������������
Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac);
@@ -453,6 +458,26 @@
Map<String, Object> aqiMap = null;
if (govMpInfo.get("guid") != null) {
aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString());
+ }
+ if (code.equals("2")){
+ if (ObjectUtils.isEmpty(aqiMap.get("a21005")) || ObjectUtils.isEmpty(aqiMap.get("a21026"))
+ || ObjectUtils.isEmpty(aqiMap.get("a21004")) || ObjectUtils.isEmpty(aqiMap.get("a34002"))
+ || ObjectUtils.isEmpty(aqiMap.get("a34004")) || ObjectUtils.isEmpty(aqiMap.get("a05024"))
+ || ObjectUtils.isEmpty(aqiMap)){
+ HashMap<String, Object> result = new HashMap<>();
+ String dataTime = deviceData.get("DataTime").toString();
+ Date time = DateUtils.getDate(dataTime, DateUtils.yyyyMMddHHmmss_EN);
+ String yearAndMonth = DateUtils.dateToDateString(DateUtils.addHours(time, -2), DateUtils.yyyyMM_EN);
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+ String format = simpleDateFormat.format(DateUtils.addHours(time, -2));
+ result.put("timeUnits",yearAndMonth);
+ result.put("mac",mac);
+ result.put("time",format);
+ Map<String, Object> map = historyHourlyMapper.selectHistoryHourly(result);
+ if (!ObjectUtils.isEmpty(map)){
+ return JSON.parseObject(map.get("value").toString(), Map.class);
+ }
+ }
}
return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap);
}
@@ -498,19 +523,21 @@
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;
+ }
}
}
//������������������
@@ -519,13 +546,35 @@
deviceMapper.update(null, updateWrapper);
}
+ @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;
+ }
+
//���������������������������
private int judgeState(List<Object> levels, Double data) {
int state = 1;
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;
}
}
--
Gitblit v1.8.0