From 6992aaf0587c09f7c511c1afd12e1519d91363d3 Mon Sep 17 00:00:00 2001 From: cjl <276999030@qq.com> Date: Thu, 14 Dec 2023 15:38:45 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/cjl' into qa --- screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java | 374 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 340 insertions(+), 34 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 130fa2e..8d56568 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 @@ -3,6 +3,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.moral.api.config.Interceptor.UserHelper; import com.moral.api.config.mybatis.MybatisPlusConfig; import com.moral.api.entity.*; import com.moral.api.mapper.DeviceMapper; @@ -11,11 +13,16 @@ 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.enums.SysDictTypeEnum; +import com.moral.api.pojo.ext.wind.WindListExt; import com.moral.api.pojo.form.device.MonitorPointQueryForm; import com.moral.api.pojo.form.historyFiveMinutely.QueryDeviceAndFiveMinuteDataForm; +import com.moral.api.pojo.vo.historyFiveMinutely.QueryFiveDataByMacVO; +import com.moral.api.pojo.vo.user.QxUser; import com.moral.api.service.DeviceService; import com.moral.api.service.HistoryFiveMinutelyService; import com.moral.api.service.MonitorPointService; +import com.moral.api.service.SysDictTypeService; import com.moral.api.utils.UnitConvertUtils; import com.moral.constant.Constants; import com.moral.constant.RedisConstants; @@ -25,12 +32,16 @@ import com.moral.util.RegionCodeUtils; import io.lettuce.core.GeoCoordinates; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import java.text.DecimalFormat; import java.util.*; +import java.util.stream.Collectors; /** * <p> @@ -57,6 +68,8 @@ DeviceService deviceService; @Autowired DeviceMapper deviceMapper; + @Autowired + private SysDictTypeService sysDictTypeService; @Override public List<Map<String, Object>> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) { @@ -73,6 +86,8 @@ } 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); //��������������������������������������������������� @@ -139,14 +154,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); @@ -176,9 +189,23 @@ //������������ windData = historyFiveMinutelyMapper.getAreaWindData(params); } - return getWindData(windData); + return getWindData(windData,params); } + @Override + public List<Object> getAreaWindDataCenter(Map<String, Object> params) { +// String timeUnits = DateUtils.dateToDateString(new Date(), DateUtils.yyyyMM_EN); +// params.put("timeUnits", timeUnits); +// //������������ +// List<WindData> windData = historyFiveMinutelyMapper.getAreaWindData(params); +// return getWindData(windData); + params.put("timeUnits","202311"); + params.put("time","2023-11-05 09:00"); + params.put("macs",Arrays.asList("p5dnd7a0245472","p5dnd7a0245400","p5dnd7a0245385","p5dnd7a0245374")); + List<WindData> windData = historyHourlyMapper.getArea(params); + params.put("perdlen",50); + return getWindData(windData,params); + } //��������������������������� @Override @@ -223,7 +250,12 @@ data = data + " " + sensor.getShowUnit(); result.put(sensor.getCode(), data); } else { - result.put(sensor.getCode(), "-"); + if (sensor.getCode().equals("a01008") ||sensor.getCode().equals("a01007")){ + result.put(sensor.getCode(), "-"); + }else { + result.put(sensor.getCode(), "0"+" "+sensor.getShowUnit()); + } + } } //������������������ @@ -232,6 +264,64 @@ result.put("dataTime", datas.get("dataTime")); //������ return orderSixParam(result); + } + + @Override + public QueryFiveDataByMacVO queryFiveDataByMac(String mac, String chooseTime, String time) { + Map<String, Object> datas = null; + if (chooseTime.equals("true")) { + 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; + } + 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); + result.put(sensor.getCode(), data); + } else { + if (sensor.getCode().equals("a01008") ||sensor.getCode().equals("a01007")){ + result.put(sensor.getCode(), "-"); + }else { + result.put(sensor.getCode(), "0"); + } + + } + } + String str = new DecimalFormat("#.######").format(Double.parseDouble(result.get("a21005").toString())); + QueryFiveDataByMacVO queryFiveDataByMacVO = new QueryFiveDataByMacVO(); + queryFiveDataByMacVO.setName(device.getName()); + queryFiveDataByMacVO.setDataTime(datas.get("dataTime").toString()); + queryFiveDataByMacVO.setA34004(result.get("a34004").toString()); + queryFiveDataByMacVO.setA34002(result.get("a34002").toString()); + queryFiveDataByMacVO.setA21026(result.get("a21026").toString()); + queryFiveDataByMacVO.setA21004(result.get("a21004").toString()); + queryFiveDataByMacVO.setA21005(str); + queryFiveDataByMacVO.setA05024(result.get("a05024").toString()); + queryFiveDataByMacVO.setA01008(result.get("a01008").toString()); + queryFiveDataByMacVO.setA01007(result.get("a01007").toString()); + queryFiveDataByMacVO.setA99054(result.get("a99054").toString()); + + return queryFiveDataByMacVO; } //��������������������������������� @@ -304,22 +394,38 @@ map.put("lat", Lat * 180 / Math.PI); return map; } + private int windDate(String ids){ + int num = 200; + if(StringUtils.isEmpty(ids)){ + return num; + } + List<Integer> list = Arrays.asList(ids.split(",")).stream().map(s->Integer.parseInt(s.trim())).collect(Collectors.toList()); + LambdaQueryChainWrapper<MonitorPoint> wrapper = monitorPointService.lambdaQuery(); + wrapper.in(MonitorPoint::getId,list); + List<MonitorPoint> resultList = wrapper.list(); + if(CollectionUtils.isEmpty(resultList)){ + return num; + } + List<String> integerList = resultList.stream().map(s->s.getOrganizationId().toString()).collect(Collectors.toList()); + List<SysDictData> sysDictList = sysDictTypeService.listWindAll(SysDictTypeEnum.WIND_FARM_SCOPE.value,integerList); + if(CollectionUtils.isEmpty(sysDictList)){ + return num; + } + num = sysDictList.stream().mapToInt(s->Integer.parseInt(s.getDataValue())).max().getAsInt(); + return num; + } - public List<Object> getWindData(List<WindData> windData) { + public List<Object> getWindData(List<WindData> windData,Map<String, Object> params) { List<GeoCoordinates> points = new ArrayList<>(); - int length = 2000; - int perdlen = 200; Double loma = 0d; Double lomi = 0d; Double lama = 0d; Double lami = 0d; List<Double> loList = new ArrayList<>(); List<Double> laList = new ArrayList<>(); + List<Map<String, Object>> mapList = new ArrayList<>(); Double U; Double V; - //��������� - List<Object> list = new ArrayList<>(); - List<Map<String, Object>> mapList = new ArrayList<>(); for (WindData data : windData) { //������ Double longitude = data.getLongitude(); @@ -348,6 +454,7 @@ map.put("la", latitude); map.put("U", U); map.put("V", V); + map.put("mac", data.getMac()); mapList.add(map); } @@ -367,6 +474,11 @@ laLaMap.put("minLo", lomi); laLaMap.put("maxLa", lama); laLaMap.put("minLa", lami); + + + int perdlen = Objects.nonNull(params.get("perdlen"))?Integer.parseInt(params.get("perdlen").toString()):windDate(Objects.nonNull(params.get("monitorPointList"))?params.get("monitorPointList").toString():null); + int length = perdlen*10; + Double lo1 = lomi - length * 0.00001141; //Double lo1 = lomi - length * 0.000001141 * 2; Double lo2 = loma + length * 0.00001141; @@ -384,26 +496,30 @@ int nx = (int) Math.floor((lo2 - lo1) / dx); int ny = (int) Math.floor((la1 - la2) / dy); + int nums = Objects.nonNull(nx*ny)?nx*ny+100:100; + List<Double> uList = new ArrayList<>(nums); + List<Double> vList = new ArrayList<>(nums); - List<Double> uList = new ArrayList<>(); - List<Double> vList = new ArrayList<>(); + + for (int j = 0; j < nx * ny; j++) { + uList.add(0.0); + vList.add(0.0); + } int x; 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); y = Math.abs((int) Math.floor((la - la1) / dy)); U = (Double) mapList.get(i).get("U"); V = (Double) mapList.get(i).get("V"); - if (i == 0) { - for (int j = 0; j < nx * ny; j++) { - uList.add(0.0); - vList.add(0.0); - } - } + // ������������ + /* WindListExt windListExt = getWindList(mapList.get(i),loList,laList,500,50); + if(Objects.nonNull(windListExt)&&Objects.nonNull(windListExt.getUValue()) ){ + U = windListExt.getUValue(); + V = windListExt.getVValue(); + }*/ for (int j = 0; j < nx * ny; j++) { if (i == 0) { if ((y >= 2 && j == (y) * nx + x)) { @@ -441,8 +557,21 @@ } } } - - + /*WindListExt windList = getWindList(length,perdlen,params); + for(int i =0; i< windList.getUList().size(); i++){ + Double d = windList.getUList().get(i); + if(Objects.nonNull(d)&& (!d.equals(0d))){ + uList.set(i,d); + } + } + for(int i =0; i< windList.getVList().size(); i++){ + Double d = windList.getVList().get(i); + if(Objects.nonNull(d)&& (!d.equals(0d))){ + vList.set(i,d); + } + }*/ + /*//��������� + List<Object> list = new ArrayList<>(); String uData = "\"" + "data" + "\"" + ": " + uList; String vData = "\"" + "data" + "\"" + ": " + vList; @@ -466,7 +595,175 @@ list.add(jsonArray); list.add(centerPoint.get("lng")); list.add(centerPoint.get("lat")); - list.add(laLaMap); + list.add(laLaMap);*/ + + Map<String,Object> map = new HashMap<>(); + map.put("uList",uList); + map.put("vList",vList); + map.put("dx",dx); + map.put("dy",dy); + map.put("nx",nx); + map.put("ny",ny); + map.put("la1",la1); + map.put("la2",la2); + map.put("lo1",lo1); + map.put("lo2",lo2); + map.put("laLaMap",laLaMap); + return getWindData(map,centerPoint); + } + + private WindListExt getWindList(int length,int perdlen,Map<String, Object> params){ + params.put("time","2023-10-16 04:00"); + String time = params.get("time").toString(); + String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN); + params.put("timeUnits", timeUnits); + List<WindData> windData = historyHourlyMapper.getArea(params); + WindListExt windListExt = new WindListExt(); + List<String> stringList = Arrays.asList("p5dnd7a0245400","p5dnd7a0245472","p5dnd7a0245374","p5dnd7a0245385"); + List<GeoCoordinates> points = new ArrayList<>(); + Double loma = 0d; + Double lomi = 0d; + Double lama = 0d; + Double lami = 0d; + List<Double> loList = new ArrayList<>(); + List<Double> laList = new ArrayList<>(); + List<Map<String, Object>> mapList = new ArrayList<>(); + Double U = 0d; + Double V = 0d; + for (WindData data : windData) { + //������ + Double longitude = data.getLongitude(); + //������ + Double latitude = data.getLatitude(); + GeoCoordinates geoCoordinates = GeoCoordinates.create(longitude, latitude); + points.add(geoCoordinates); + loList.add(longitude); + 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); + if(stringList.contains(data.getMac())){ + map.put("lo", longitude); + map.put("la", latitude); + map.put("U", U); + map.put("V", V); + map.put("mac", data.getMac()); + mapList.add(map); + } + } + if (loList.size() > 0) { + loma = Collections.max(loList); + lomi = Collections.min(loList); + } + if (laList.size() > 0) { + lama = Collections.max(laList); + lami = Collections.min(laList); + } + Double lo1 = lomi - length * 0.00001141; + Double lo2 = loma + length * 0.00001141; + Double la2 = lami - length * 0.00000899; + Double la1 = lama + length * 0.00000899; + double dx = 0.00001141 * perdlen; + double dy = 0.00000899 * perdlen; + int nx = (int) Math.floor((lo2 - lo1) / dx); + int ny = (int) Math.floor((la1 - la2) / dy); + int nums = Objects.nonNull(nx*ny)?nx*ny+100:100; + List<Double> uList = new ArrayList<>(nums); + List<Double> vList = new ArrayList<>(nums); + for (int j = 0; j < nx * ny; j++) { + uList.add(0.0); + vList.add(0.0); + } + int x; + 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); + y = Math.abs((int) Math.floor((la - la1) / dy)); + U = (Double) mapList.get(i).get("U"); + V = (Double) mapList.get(i).get("V"); + + for (int j = 0; j < nx * ny; j++) { + if (i == 0) { + if ((y >= 2 && j == (y) * nx + x)) { + int k; + for (k = j - 2 * nx; k <= j + 2 * nx; k = k + nx) { + uList.set(k, U); + uList.set(k - 1, U); + uList.set(k - 2, U); + uList.set(k + 1, U); + uList.set(k + 2, U); + vList.set(k, V); + vList.set(k - 1, V); + vList.set(k - 2, V); + vList.set(k + 1, V); + vList.set(k + 2, V); + } + } + } else { + if (y >= 1 && j == y * nx + x) { + int k; + for (k = j - 2 * nx; k <= j + 2 * nx; ) { + uList.set(k - 1, U); + uList.set(k - 2, U); + uList.set(k + 1, U); + uList.set(k + 2, U); + vList.set(k - 1, V); + vList.set(k - 2, V); + vList.set(k + 1, V); + vList.set(k + 2, V); + k = k + nx; + } + uList.set(j, U); + vList.set(j, V); + } + } + } + } + windListExt.setUList(uList); + windListExt.setVList(vList); + return windListExt; + } + + private List<Object> getWindData(Map<String,Object> map, Map<String, Double> centerPoint){ + List<Object> list = new ArrayList<>(); + String uData = "\"" + "data" + "\"" + ": " + map.get("uList"); + String vData = "\"" + "data" + "\"" + ": " + map.get("vList"); + + String header1 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 2 + + ", " + "\"" + "dx" + "\"" + ": " + map.get("dx") + ", " + "\"" + "dy" + "\"" + ": " + map.get("dy") + + ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + map.get("la1") + ", " + "\"" + "la2" + "\"" + ": " + map.get("la2") + + ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + map.get("lo1") + ", " + "\"" + "lo2" + "\"" + ": " + map.get("lo2") + + ", " + "\"" + "nx" + "\"" + ": " + map.get("nx") + ", " + "\"" + "ny" + "\"" + ": " + map.get("ny") + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; + + String header2 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 3 + + ", " + "\"" + "dx" + "\"" + ": " + map.get("dx") + ", " + "\"" + "dy" + "\"" + ": " + map.get("dy") + + ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + map.get("la1") + ", " + "\"" + "la2" + "\"" + ": " + map.get("la2") + + ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + map.get("lo1") + ", " + "\"" + "lo2" + "\"" + ": " + map.get("lo2") + + ", " + "\"" + "nx" + "\"" + ": " + map.get("nx") + ", " + "\"" + "ny" + "\"" + ": " + map.get("ny") + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; + + + String s1 = "[" + "{" + header1 + ", " + uData + "}" + ", " + "{" + header2 + ", " + vData + "}" + "]"; + //System.out.println(s1); + JSONArray jsonArray = JSONArray.parseArray(s1); + + list.add(jsonArray); + list.add(centerPoint.get("lng")); + list.add(centerPoint.get("lat")); + list.add(map.get("laLaMap")); return list; } @@ -478,11 +775,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; } @@ -494,14 +792,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