From 010f4ba252db180fc7fea4d7cb1b84a0bca7479f Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Fri, 11 Aug 2023 16:37:43 +0800 Subject: [PATCH] Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into wb --- screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java | 207 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 178 insertions(+), 29 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java index da4cbef..c7379dc 100644 --- a/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java +++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java @@ -2,28 +2,27 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.conditions.ISqlSegment; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; -import com.baomidou.mybatisplus.core.conditions.segments.NormalSegmentList; import com.moral.api.config.mybatis.MybatisPlusConfig; -import com.moral.api.entity.Device; -import com.moral.api.entity.HistoryFiveMinutely; -import com.moral.api.entity.HistoryHourly; -import com.moral.api.entity.MonitorPoint; +import com.moral.api.entity.*; import com.moral.api.mapper.HistoryFiveMinutelyMapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.moral.api.mapper.HistoryHourlyMapper; import com.moral.api.pojo.dto.Wind.WindData; import com.moral.api.pojo.dto.historyFiveMinutely.DeviceAndFiveMinuteDataDTO; import com.moral.api.pojo.form.device.MonitorPointQueryForm; import com.moral.api.pojo.form.historyFiveMinutely.QueryDeviceAndFiveMinuteDataForm; +import com.moral.api.service.DeviceService; import com.moral.api.service.HistoryFiveMinutelyService; import com.moral.api.service.MonitorPointService; +import com.moral.api.utils.UnitConvertUtils; +import com.moral.constant.Constants; import com.moral.constant.RedisConstants; import com.moral.constant.SeparateTableType; import com.moral.util.DateUtils; import com.moral.util.MybatisPLUSUtils; import io.lettuce.core.GeoCoordinates; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -40,6 +39,7 @@ * @since 2021-07-15 */ @Service +@Slf4j public class HistoryFiveMinutelyServiceImpl extends ServiceImpl<HistoryFiveMinutelyMapper, HistoryFiveMinutely> implements HistoryFiveMinutelyService { @Autowired @@ -48,6 +48,11 @@ RedisTemplate redisTemplate; @Autowired HistoryFiveMinutelyMapper historyFiveMinutelyMapper; + + @Autowired + HistoryHourlyMapper historyHourlyMapper; + @Autowired + DeviceService deviceService; @Override public List<DeviceAndFiveMinuteDataDTO> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) { @@ -60,24 +65,41 @@ List<Device> devices = new ArrayList<>(); for (MonitorPoint monitorPoint : monitorPoints) { List<Device> monitorPointDevices = monitorPoint.getDevices(); - if (!ObjectUtils.isEmpty(monitorPointDevices)) - devices.addAll(monitorPointDevices); + if (!ObjectUtils.isEmpty(monitorPointDevices)) { + //������������������ + for (Device device : monitorPointDevices) { + if (!device.getState().equals(Constants.DEVICE_STATE_OFFLINE)) + devices.add(device); + } + } + } //��������������������������������� List<DeviceAndFiveMinuteDataDTO> dtos = new ArrayList<>(); + if (form.getChooseTime().equals("true")) { + String time = form.getTime(); + String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN); + for (Device device : devices) { + DeviceAndFiveMinuteDataDTO dto = new DeviceAndFiveMinuteDataDTO(); + String mac = device.getMac(); + String dbDataStr = historyHourlyMapper.queryLastHourlyMac(mac, time, timeUnits); +// String dbDataStr = historyFiveMinutelyMapper.queryLastFiveMinutely(mac, time, timeUnits); + HashMap sensorValues = JSON.parseObject(dbDataStr, HashMap.class); + Map<String, Object> sensorValue = new HashMap<>(); + if (sensorValues != null && sensorValues.get(sensorCode) != null) + sensorValue.put(sensorCode, sensorValues.get(sensorCode)); + else + sensorValue.put(sensorCode, null); + dto.setDevice(device); + dto.setSensorValue(sensorValue); + dtos.add(dto); + } + return dtos; + } for (Device device : devices) { DeviceAndFiveMinuteDataDTO dto = new DeviceAndFiveMinuteDataDTO(); String mac = device.getMac(); - //������������������ - Map<String, Object> sensorValues = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DATA_FIVE_MINUTES, mac); - //������������������������������������ - if (ObjectUtils.isEmpty(sensorValues)) { - HistoryFiveMinutely dbHistoryFiveMinutely = queryLastDataByMac(mac); - if (ObjectUtils.isEmpty(dbHistoryFiveMinutely)) - continue; - else - sensorValues = JSON.parseObject(dbHistoryFiveMinutely.getValue(),Map.class); - } + Map<String, Object> sensorValues = queryLastDataByMac(mac); String dbDataStr = JSON.toJSONString(sensorValues); sensorValues = JSON.parseObject(dbDataStr, HashMap.class); Map<String, Object> sensorValue = new HashMap<>(); @@ -93,7 +115,12 @@ } @Override - public HistoryFiveMinutely queryLastDataByMac(String mac) { + public Map<String, Object> queryLastDataByMac(String mac) { + //������������������ + Map<String, Object> sensorValues = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DATA_FIVE_MINUTES, mac); + //������������������������������������ + if (sensorValues != null) + return sensorValues; QueryWrapper<HistoryFiveMinutely> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("mac", mac); queryWrapper.orderByDesc("time"); @@ -104,17 +131,125 @@ List<HistoryFiveMinutely> datas = multiTableQuery(queryWrapper, tableNames); if (ObjectUtils.isEmpty(datas)) return null; - return datas.get(0); + HistoryFiveMinutely historyFiveMinutely = datas.get(0); + sensorValues = JSON.parseObject(historyFiveMinutely.getValue(), Map.class); + sensorValues.put("dataTime", DateUtils.dateToDateString(historyFiveMinutely.getTime(), "yyyy-MM-dd HH:mm:ss")); + return sensorValues; } @Override public List<Object> getAreaWindData(Map<String, Object> params) { - String timeUnits = DateUtils.dateToDateString(new Date(), DateUtils.yyyyMM_EN); - params.put("timeUnits", timeUnits); - //������������ - List<WindData> windData = historyFiveMinutelyMapper.getAreaWindData(params); +// String timeUnits = DateUtils.dateToDateString(new Date(), DateUtils.yyyyMM_EN); +// params.put("timeUnits", timeUnits); +// //������������ +// List<WindData> windData = historyFiveMinutelyMapper.getAreaWindData(params); +// return getWindData(windData); + String chooseTime = params.get("chooseTime").toString(); + List<WindData> windData = null; + if (chooseTime.equals("true")) { + String time = params.get("time").toString(); + String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN); + params.put("timeUnits", timeUnits); + windData = historyHourlyMapper.getArea(params); + } else { + String timeUnits = DateUtils.dateToDateString(new Date(), DateUtils.yyyyMM_EN); + params.put("timeUnits", timeUnits); + //������������ + windData = historyFiveMinutelyMapper.getAreaWindData(params); + } return getWindData(windData); + } + + + //��������������������������� + @Override + public Map<String, Object> getPopDataByMac(Map<String, Object> params) { +// Map<String, Object> datas = queryLastDataByMac(mac); + String chooseTime = params.get("chooseTime").toString(); + String mac = params.get("mac").toString(); + Map<String, Object> datas = null; + if (chooseTime.equals("true")) { + String time = params.get("time").toString(); + String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN); + String dbDataStr = historyHourlyMapper.queryLastHourlyMac(mac, time, timeUnits); + if (dbDataStr == null) { + return null; + } +// String dbDataStr = historyFiveMinutelyMapper.queryLastFiveMinutely(mac, time, timeUnits); + datas = JSON.parseObject(dbDataStr, HashMap.class); + datas.put("dataTime", time); + } else { + datas = queryLastDataByMac(mac); + if (ObjectUtils.isEmpty(datas)){ + return null; + } + } + //������������������ + Map<String, Object> result = new HashMap<>(); + //������������������code������ + List<String> sensorCodes = Arrays.asList("a34004", "a34002", "a21005", "a21004", "a21026", "a05024", "a99054", "a01008", "a01007"); + //������������������ + Device device = deviceService.getDeviceUnitAlramInforByMac(mac); + //��������������������������� + for (Sensor sensor : device.getVersion().getSensors()) { + if (!sensorCodes.contains(sensor.getCode())) + continue; + Object dataO = datas.get(sensor.getCode()); + if (dataO != null) { + String data = String.valueOf(dataO); + //������������ + if (!sensor.getShowUnitKey().equals(sensor.getUnitKey())) + data = UnitConvertUtils.calculate(data, sensor.getFormula()); + //������������ + data = data + " " + sensor.getShowUnit(); + result.put(sensor.getCode(), data); + } else { + result.put(sensor.getCode(), "-"); + } + } + //������������������ + result.put("name", device.getName()); + //������������ + result.put("dataTime", datas.get("dataTime")); + //������ + return orderSixParam(result); + } + + //��������������������������������� + private Map<String, Object> orderSixParam(Map<String, Object> data) { + LinkedHashMap result = new LinkedHashMap(); + Object PM2_5 = data.get("a34004"); + Object PM10 = data.get("a34002"); + Object SO2 = data.get("a21026"); + Object NO2 = data.get("a21004"); + Object CO = data.get("a21005"); + Object O3 = data.get("a05024"); + Object a01008 = data.get("a01008"); + Object a01007 = data.get("a01007"); + Object name = data.get("name"); + Object time = data.get("dataTime"); + if (name != null) + result.put("������", name); + if (PM2_5 != null) + result.put("PM2.5", PM2_5); + if (PM10 != null) + result.put("PM10", PM10); + if (SO2 != null) + result.put("���������������SO������", SO2); + if (NO2 != null) + result.put("���������������NO������", NO2); + if (CO != null) + result.put("���������������CO���", CO); + if (O3 != null) + result.put("���������O������", O3); + if (time != null) + result.put("������", time); + if (a01008 != null) + result.put("������", a01008); + if (a01007 != null) + result.put("������", a01007); + return result; } @@ -168,7 +303,9 @@ List<Object> list = new ArrayList<>(); List<Map<String, Object>> mapList = new ArrayList<>(); for (WindData data : windData) { + //������ Double longitude = data.getLongitude(); + //������ Double latitude = data.getLatitude(); GeoCoordinates geoCoordinates = GeoCoordinates.create(longitude, latitude); points.add(geoCoordinates); @@ -176,14 +313,18 @@ laList.add(latitude); Map<String, Object> map = new HashMap<>(); + //������ Double windDir = data.getWindDir(); + //������ Double windSpeed = data.getWindSpeed(); if (windDir == null) { windDir = 0d; windSpeed = 0d; } double dir = (360.0 - (windDir + 180.0) * Math.PI / 180.0); + //��������� U = windSpeed * Math.cos(dir); + //��������������� V = windSpeed * Math.sin(dir); map.put("lo", longitude); map.put("la", latitude); @@ -208,17 +349,23 @@ laLaMap.put("minLo", lomi); laLaMap.put("maxLa", lama); laLaMap.put("minLa", lami); - Double lo1 = lomi - length * 0.00001141; + //Double lo1 = lomi - length * 0.000001141 * 2; Double lo2 = loma + length * 0.00001141; + //Double lo2 = loma + length * 0.000001141 * 2; + //Double la2 = lami - length * 0.000000899 * 2; Double la2 = lami - length * 0.00000899; + //Double la1 = lama + length * 0.000000899 * 2; Double la1 = lama + length * 0.00000899; double dx = 0.00001141 * perdlen; double dy = 0.00000899 * perdlen; + + //double dx = 0.000001141 * perdlen * 2; + //double dy = 0.000000899 * perdlen * 2; + int nx = (int) Math.floor((lo2 - lo1) / dx); int ny = (int) Math.floor((la1 - la2) / dy); - List<Double> uList = new ArrayList<>(); List<Double> vList = new ArrayList<>(); @@ -226,6 +373,7 @@ int y; for (int i = 0; i < mapList.size(); i++) { + Double lo = (Double) mapList.get(i).get("lo"); Double la = (Double) mapList.get(i).get("la"); x = (int) Math.floor((lo - lo1) / dx); @@ -275,6 +423,8 @@ } } } + + String uData = "\"" + "data" + "\"" + ": " + uList; String vData = "\"" + "data" + "\"" + ": " + vList; @@ -292,6 +442,7 @@ String s1 = "[" + "{" + header1 + ", " + uData + "}" + ", " + "{" + header2 + ", " + vData + "}" + "]"; + //System.out.println(s1); JSONArray jsonArray = JSONArray.parseArray(s1); list.add(jsonArray); @@ -335,6 +486,4 @@ MybatisPlusConfig.tableName.remove(); return result; } - - } -- Gitblit v1.8.0