|  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private DeviceAdjustValueTimingService deviceAdjustValueTimingService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private PollutioSourcePointService pollutioSourcePointService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private HistoryFiveMinutelyService historyFiveMinutelyService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Screen login. 大屏登录 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Device> devicesList = deviceService.getDevicesByAccountId(id); | 
|---|
|  |  |  | return devicesList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("/unorganizedEmissionsFiveMinute") | 
|---|
|  |  |  | @ApiOperation(value = "无组织排放五分钟", notes = "无组织排放五分钟") | 
|---|
|  |  |  | @ApiImplicitParams(value = { | 
|---|
|  |  |  | @ApiImplicitParam(name = "monitorPointId", value = "公司Id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "sensorKey", value = "因子", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "accountId", value = "用户id", required = false, paramType = "query", dataType = "String")}) | 
|---|
|  |  |  | public ModelAndView unorganizedEmissionsBackupsV2(HttpServletRequest request, ModelAndView model) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | String sensorKey = parameters.get("sensorKey").toString(); | 
|---|
|  |  |  | //第一步,获取污染源点 | 
|---|
|  |  |  | PollutionSourcePoint pollutionSourcePoint = pollutioSourcePointService.selectByMonitorPointId(539); | 
|---|
|  |  |  | //获取站点的所有设备 | 
|---|
|  |  |  | List<Device> deviceList = deviceService.getDevicesByMonitorPointId(539); | 
|---|
|  |  |  | //获取五分钟数据 | 
|---|
|  |  |  | Map<String,Object> pa = new HashMap<>(); | 
|---|
|  |  |  | //pa.put("sensorKey","e1"); | 
|---|
|  |  |  | pa.put("yearAndMonth","202012"); | 
|---|
|  |  |  | pa.put("time","2020-12-03 10:10:00"); | 
|---|
|  |  |  | List<String> macs = new ArrayList<>(); | 
|---|
|  |  |  | List<String> sensorKeys = new ArrayList<>(); | 
|---|
|  |  |  | for (Device device:deviceList) { | 
|---|
|  |  |  | macs.add(device.getMac()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | sensorKeys.add(sensorKey); | 
|---|
|  |  |  | sensorKeys.add("e18"); | 
|---|
|  |  |  | sensorKeys.add("e23"); | 
|---|
|  |  |  | pa.put("macs",macs); | 
|---|
|  |  |  | pa.put("sensorKeys",sensorKeys); | 
|---|
|  |  |  | List<Map<String, Object>> fiveMinuteDataList = historyFiveMinutelyService.getFiveMinutesSersorDataByMacsAndTime(pa); | 
|---|
|  |  |  | //声明数组,存放所有设备的数值 | 
|---|
|  |  |  | double[] allDeviceData = new double[fiveMinuteDataList.size()]; | 
|---|
|  |  |  | System.out.println(fiveMinuteDataList); | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | //计算风向 | 
|---|
|  |  |  | List<Map<String,Object>> windList = new ArrayList<>(); | 
|---|
|  |  |  | for (Map map:fiveMinuteDataList) { | 
|---|
|  |  |  | String[] wind_speed = map.get("e18").toString().split(","); | 
|---|
|  |  |  | String[] wind_direction = map.get("e23").toString().split(","); | 
|---|
|  |  |  | Map<String,Object> windMap = new HashMap<>(); | 
|---|
|  |  |  | windMap.put("wind_speed",wind_speed[0].substring(1,wind_speed[0].length())); | 
|---|
|  |  |  | windMap.put("wind_direction",wind_direction[0].substring(1,wind_direction[0].length())); | 
|---|
|  |  |  | windList.add(windMap); | 
|---|
|  |  |  | String[] sensorArr = map.get(sensorKey).toString().split(","); | 
|---|
|  |  |  | double sensorData = Double.parseDouble(sensorArr[0].substring(1,sensorArr[0].length())); | 
|---|
|  |  |  | allDeviceData[i] = sensorData; | 
|---|
|  |  |  | i = i+1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //计算平均风向和风速 | 
|---|
|  |  |  | Map<String,Double> res = WindUtils.getWind_direction_speed(windList); | 
|---|
|  |  |  | //计算该站点的点与污染源点的角度 | 
|---|
|  |  |  | Map<String,Double> angleMap = new HashMap(); | 
|---|
|  |  |  | MyLatLng pollutionSourcePoint_log_lat = new MyLatLng(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude()); | 
|---|
|  |  |  | for (Device device:deviceList) { | 
|---|
|  |  |  | MyLatLng device_log_lat = new MyLatLng(device.getLongitude(),device.getLatitude()); | 
|---|
|  |  |  | //以设备为坐标原点,与污染源连线的角度 | 
|---|
|  |  |  | double angle = mapUtils.getAngle(device_log_lat,pollutionSourcePoint_log_lat); | 
|---|
|  |  |  | angleMap.put(device.getMac(),angle); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Map<String,Double> disparityMap = new HashMap<>(); | 
|---|
|  |  |  | for (String key:angleMap.keySet()) { | 
|---|
|  |  |  | double angleDisparity = Math.abs(angleMap.get(key)-res.get("wind_direction")); | 
|---|
|  |  |  | if (angleDisparity>180){ | 
|---|
|  |  |  | angleDisparity = 360-angleDisparity; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | disparityMap.put(key,angleDisparity); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Optional<Map.Entry<String, Double>> minDisparity = disparityMap.entrySet() | 
|---|
|  |  |  | .stream() | 
|---|
|  |  |  | .min(Map.Entry.comparingByValue()); | 
|---|
|  |  |  | //留下的任务:循环disparityMap,查出与minDisparity相等的值的key,以防出现两个点的角度差一样 | 
|---|
|  |  |  | List<String> minAngleDisparityMacList = new ArrayList<>(); | 
|---|
|  |  |  | for (String key:disparityMap.keySet()) { | 
|---|
|  |  |  | if (disparityMap.get(key) == minDisparity.get().getValue()){ | 
|---|
|  |  |  | minAngleDisparityMacList.add(minDisparity.get().getKey()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //定义一个map,存放设备点 | 
|---|
|  |  |  | Map<String,Object> fiveMinuteDataMap = new HashMap(); | 
|---|
|  |  |  | if (minAngleDisparityMacList.size()<2){//只有一个点 | 
|---|
|  |  |  | for (Map fiveMinuteData:fiveMinuteDataList) { | 
|---|
|  |  |  | if (fiveMinuteData.get("mac").toString().equals(minAngleDisparityMacList.get(0))){ | 
|---|
|  |  |  | fiveMinuteDataMap.putAll(fiveMinuteData); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Device referenceDevice = new Device(); | 
|---|
|  |  |  | for (Device device:deviceList) { | 
|---|
|  |  |  | if (device.getMac().equals(fiveMinuteDataMap.get("mac"))){ | 
|---|
|  |  |  | referenceDevice = device; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //计算污染平均值 | 
|---|
|  |  |  | double sum = 0; | 
|---|
|  |  |  | for (int j=0;j<allDeviceData.length;j++) { | 
|---|
|  |  |  | sum = sum+allDeviceData[j]; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | double deviceDataAvg = sum/allDeviceData.length; | 
|---|
|  |  |  | //计算污染源点与设备点之间的距离 | 
|---|
|  |  |  | double distance = mapUtils.getDistance(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude(),referenceDevice.getLongitude(),referenceDevice.getLatitude()); | 
|---|
|  |  |  | //已知距离,角度,求x,y | 
|---|
|  |  |  | double x = Math.cos(minDisparity.get().getValue())*distance; | 
|---|
|  |  |  | double y = Math.sin(minDisparity.get().getValue())*distance; | 
|---|
|  |  |  | //获取设备的数值 | 
|---|
|  |  |  | String[] fiveMinuteData = fiveMinuteDataMap.get("e21").toString().split(","); | 
|---|
|  |  |  | double c = Double.parseDouble(fiveMinuteData[0].substring(1,fiveMinuteData[0].length()))-deviceDataAvg; | 
|---|
|  |  |  | System.out.println(c); | 
|---|
|  |  |  | //计算源强 | 
|---|
|  |  |  | double pollutionSourceIntensity = EmissionDataUtil.getPollutionSourceIntensity(c,x,y,res.get("wind_speed")); | 
|---|
|  |  |  | System.out.println(pollutionSourceIntensity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存放地图中心点 | 
|---|
|  |  |  | Map<String,Object> center = new HashMap<>(); | 
|---|
|  |  |  | center.put("lng",120.997119); | 
|---|
|  |  |  | center.put("lat",31.451714); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存放各个点位经纬度及数值 | 
|---|
|  |  |  | List<Map<String,Double>> numericalValueList = new ArrayList<>(); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap.put("lng",120.997119); | 
|---|
|  |  |  | numericalValueMap.put("lat",31.451714); | 
|---|
|  |  |  | numericalValueMap.put("count",0.027); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap2 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap2.put("lng",120.99516); | 
|---|
|  |  |  | numericalValueMap2.put("lat",31.448664); | 
|---|
|  |  |  | numericalValueMap2.put("count",0.029); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap2); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap3 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap3.put("lng",120.998538); | 
|---|
|  |  |  | numericalValueMap3.put("lat",31.449289); | 
|---|
|  |  |  | numericalValueMap3.put("count",0.033); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap3); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap4 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap4.put("lng",120.998628); | 
|---|
|  |  |  | numericalValueMap4.put("lat",31.452027); | 
|---|
|  |  |  | numericalValueMap4.put("count",0.025); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap4); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap5 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap5.put("lng",121.000383); | 
|---|
|  |  |  | numericalValueMap5.put("lat",31.451469); | 
|---|
|  |  |  | numericalValueMap5.put("count",0.05); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap5); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap6 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap6.put("lng",120.999908); | 
|---|
|  |  |  | numericalValueMap6.put("lat",31.449389); | 
|---|
|  |  |  | numericalValueMap6.put("count",0.04); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap6); | 
|---|
|  |  |  | Map<String,Double> numericalValueMap7 = new HashMap<>(); | 
|---|
|  |  |  | numericalValueMap7.put("lng",120.998519); | 
|---|
|  |  |  | numericalValueMap7.put("lat",31.450588); | 
|---|
|  |  |  | numericalValueMap7.put("count",0.10); | 
|---|
|  |  |  | numericalValueList.add(numericalValueMap7); | 
|---|
|  |  |  | System.out.println(numericalValueList.toString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | JSONObject params = new JSONObject(); | 
|---|
|  |  |  | params.put("accountId",190); | 
|---|
|  |  |  | params.put("level",17); | 
|---|
|  |  |  | params.put("center",center); | 
|---|
|  |  |  | params.put("points",numericalValueList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取公司信息 | 
|---|
|  |  |  | //JSONObject params=monitorPointService.getMonitorPointById(monitPointId,Time,3,sensor); | 
|---|
|  |  |  | // model.addObject("params",params); | 
|---|
|  |  |  | model.addObject("params", params); | 
|---|
|  |  |  | model.setViewName("unorganizedMapV2"); | 
|---|
|  |  |  | return model; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|