From 4319627cf67d19093a18ff724c21782e34fc7a26 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Tue, 10 Oct 2023 15:44:27 +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 | 72 +++++++++++++++++++++++++---------- 1 files changed, 51 insertions(+), 21 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 1328f06..cd1b80c 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 @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.config.mybatis.MybatisPlusConfig; import com.moral.api.entity.*; +import com.moral.api.mapper.DeviceMapper; import com.moral.api.mapper.HistoryFiveMinutelyMapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.api.mapper.HistoryHourlyMapper; @@ -21,6 +22,7 @@ import com.moral.constant.SeparateTableType; import com.moral.util.DateUtils; import com.moral.util.MybatisPLUSUtils; +import com.moral.util.RegionCodeUtils; import io.lettuce.core.GeoCoordinates; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -53,15 +55,30 @@ HistoryHourlyMapper historyHourlyMapper; @Autowired DeviceService deviceService; + @Autowired + DeviceMapper deviceMapper; @Override - public List<DeviceAndFiveMinuteDataDTO> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) { + public List<Map<String, Object>> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) { //������ + String times = DateUtils.dateToDateString(new Date(),DateUtils.yyyyMM_EN); Integer organizationId = form.getOrganizationId(); Integer regionCode = form.getRegionCode(); String sensorCode = form.getSensorCode(); + String type = "$."+ sensorCode; + String region = null; + String endHourlyTime = null; + if (regionCode != null && organizationId!=24) { + region = RegionCodeUtils.regionCodeConvertToName(regionCode); + } + if (form.getChooseTime().equals("true")) { + endHourlyTime = form.getTime(); + Date time = DateUtils.convertDate(endHourlyTime); + times = DateUtils.dateToDateString(time,DateUtils.yyyyMM_EN); + } + List<Map<String, Object>> listAll = deviceMapper.deviceList(organizationId,regionCode,region,type,sensorCode,times,endHourlyTime); //��������������������������������������������������� - List<MonitorPoint> monitorPoints = monitorPointService.queryByOrgIdAndRegionCode(new MonitorPointQueryForm(organizationId, regionCode)); + /*List<MonitorPoint> monitorPoints = monitorPointService.queryByOrgIdAndRegionCode(new MonitorPointQueryForm(organizationId, regionCode)); List<Device> devices = new ArrayList<>(); for (MonitorPoint monitorPoint : monitorPoints) { List<Device> monitorPointDevices = monitorPoint.getDevices(); @@ -73,8 +90,9 @@ } } - } + }*/ //��������������������������������� + /*List<Device> devices = new ArrayList<>(); List<DeviceAndFiveMinuteDataDTO> dtos = new ArrayList<>(); if (form.getChooseTime().equals("true")) { String time = form.getTime(); @@ -96,10 +114,12 @@ } return dtos; } + //List<Map<String, Object>> sensorValuess = (List<Map<String, Object>>) redisTemplate.opsForValue().multiGet(Arrays.asList("data_five_minutes:p5dnd7a0245400","data_five_minutes:p5dnd7a0245412")); for (Device device : devices) { DeviceAndFiveMinuteDataDTO dto = new DeviceAndFiveMinuteDataDTO(); String mac = device.getMac(); Map<String, Object> sensorValues = queryLastDataByMac(mac); + String dbDataStr = JSON.toJSONString(sensorValues); sensorValues = JSON.parseObject(dbDataStr, HashMap.class); Map<String, Object> sensorValue = new HashMap<>(); @@ -110,8 +130,8 @@ dto.setDevice(device); dto.setSensorValue(sensorValue); dtos.add(dto); - } - return dtos; + }*/ + return listAll; } @Override @@ -121,14 +141,12 @@ //������������������������������������ if (sensorValues != null) return sensorValues; - QueryWrapper<HistoryFiveMinutely> queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("mac", mac); - queryWrapper.orderByDesc("time"); - queryWrapper.last("limit 0,1"); + Map<String, Object> mapParams = new HashMap<>(); + mapParams.put("mac",mac); //��������������������� Date date = new Date(); List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date, date, SeparateTableType.MONTH); - List<HistoryFiveMinutely> datas = multiTableQuery(queryWrapper, tableNames); + List<HistoryFiveMinutely> datas = multiTableQuery(mapParams, tableNames); if (ObjectUtils.isEmpty(datas)) return null; HistoryFiveMinutely historyFiveMinutely = datas.get(0); @@ -181,6 +199,9 @@ datas.put("dataTime", time); } else { datas = queryLastDataByMac(mac); + if (ObjectUtils.isEmpty(datas)){ + return null; + } } //������������������ Map<String, Object> result = new HashMap<>(); @@ -363,9 +384,9 @@ 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<>(); + int nums = Objects.nonNull(nx*ny)?nx*ny+100:100; + List<Double> uList = new ArrayList<>(nums); + List<Double> vList = new ArrayList<>(nums); int x; int y; @@ -457,11 +478,12 @@ * @Date: 2021/9/23 */ public List<HistoryFiveMinutely> getValueByMacAndTime(String mac, Date startDate, Date endDate) { - QueryWrapper<HistoryFiveMinutely> wrapper = new QueryWrapper<>(); - wrapper.eq("mac", mac); - wrapper.between("time", startDate, endDate); + Map<String, Object> mapParams = new HashMap<>(); + mapParams.put("startDate",startDate); + mapParams.put("endDate",endDate); + mapParams.put("mac",mac); List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH); - List<HistoryFiveMinutely> datas = multiTableQuery(wrapper, tableNames); + List<HistoryFiveMinutely> datas = multiTableQueryResult(mapParams, tableNames); return datas; } @@ -473,14 +495,22 @@ * @Author: ��������� * @Date: 2021/9/23 */ - private List<HistoryFiveMinutely> multiTableQuery(QueryWrapper<HistoryFiveMinutely> wrapper, List<String> tableNames) { + private List<HistoryFiveMinutely> multiTableQuery(Map<String, Object> params, List<String> tableNames) { List<HistoryFiveMinutely> result = new ArrayList<>(); for (String tableName : tableNames) { - MybatisPlusConfig.tableName.set(tableName); - List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.selectList(wrapper); + params.put("table",tableName); + List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.listResultOne(params); result.addAll(datas); } - MybatisPlusConfig.tableName.remove(); + return result; + } + private List<HistoryFiveMinutely> multiTableQueryResult(Map<String, Object> params, List<String> tableNames) { + List<HistoryFiveMinutely> result = new ArrayList<>(); + for (String tableName : tableNames) { + params.put("table",tableName); + List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.listResult(params); + result.addAll(datas); + } return result; } } -- Gitblit v1.8.0