Merge branch 'master' of http://blit.7drlb.com:8888/r/screen_api_v2
| | |
| | | |
| | | import java.io.*; |
| | | import java.lang.reflect.Array; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.text.DateFormat; |
| | | import java.text.DecimalFormat; |
| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.googlecode.aviator.AviatorEvaluator; |
| | | import com.googlecode.aviator.Expression; |
| | | import com.moral.common.bean.Constants; |
| | |
| | | import com.moral.entity.alarm.AlarmSensorLevel; |
| | | import com.moral.entity.charts.DataSortCondition; |
| | | import com.moral.entity.layout.RealTimeDeviceLayout; |
| | | import com.moral.mapper.HistoryMapper; |
| | | import com.moral.service.*; |
| | | import com.moral.util.*; |
| | | |
| | |
| | | @Api(tags = "Screen", description = "大屏接口") |
| | | public class ScreenController { |
| | | public static Logger log = Logger.getLogger(ScreenController.class); |
| | | |
| | | @Resource |
| | | private HistoryMapper historyMapper; |
| | | @Resource |
| | | AlarmConfigService alarmConfigService; |
| | | @Resource |
| | |
| | | @ApiOperation(value = "预测和实际臭氧对比", notes = "预测和实际臭氧对比") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "monitorPointId", defaultValue = "1", value = "监控站id", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "time", value = "时6间(格式:2020-03-19)", required = true, paramType = "query", dataType = "String")}) |
| | | @ApiImplicitParam(name = "time", value = "时间(格式:2020-03-19)", required = true, paramType = "query", dataType = "String")}) |
| | | public ResultBean<List<Map<String, Object>>> getWeatherNextDayDataByRegion(HttpServletRequest request) throws Exception { |
| | | Map<String, Object> parameters = getParametersStartingWith(request, null); |
| | | List<String> sensorKeys=new ArrayList<>(); |
| | | sensorKeys.add("e15"); |
| | | parameters.put("sensorKeys",sensorKeys); |
| | | List<Map<String, Object>> resultList = weatherService.getForecastAndReal(parameters); |
| | | return new ResultBean<List<Map<String, Object>>>(resultList); |
| | | } |
| | | |
| | | |
| | | @GetMapping("forecastPM") |
| | | @ApiOperation(value = "预测和实测颗粒物对比", notes = "预测和实测颗粒物对比") |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "monitorPointId", defaultValue = "1", value = "监控站id", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "time", value = "时间(格式:2020-03-19)", required = true, paramType = "query", dataType = "String")}) |
| | | public ResultBean<List<Map<String, Object>>> getForecastAndRealPM(HttpServletRequest request) throws Exception { |
| | | Map<String, Object> parameters = getParametersStartingWith(request, null); |
| | | List<String> sensorKeys=new ArrayList<>(); |
| | | sensorKeys.add("e1"); |
| | | sensorKeys.add("e2"); |
| | | parameters.put("sensorKeys",sensorKeys); |
| | | List<Map<String, Object>> resultList = weatherService.getForecastAndReal(parameters); |
| | | return new ResultBean<List<Map<String, Object>>>(resultList); |
| | | } |
| | |
| | | @ApiImplicitParams(value = { |
| | | @ApiImplicitParam(name = "monitorPointIds", value = "多个monitorid", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "time", value = "时间(格式:2020-03-19)", required = true, paramType = "query", dataType = "String")}) |
| | | public ResultBean<List<List<Map>>> monitorAVGData(HttpServletRequest request) throws Exception { |
| | | public ResultBean<List<List<Map<String,Object>>>> monitorAVGData(HttpServletRequest request) throws Exception { |
| | | Map<String, Object> parameters = getParametersStartingWith(request, null); |
| | | String monitorPointIds = (String) parameters.get("monitorPointIds"); |
| | | String time = (String) parameters.get("time"); |
| | |
| | | String date1= simpleDateFormat.format(date); |
| | | String date2= simpleDateFormat.format(calendar.getTime()); |
| | | String[] mIds = monitorPointIds.split(","); |
| | | List<List<Map>> lists = new ArrayList<>(); |
| | | List<List<Map<String,Object>>> lists = new ArrayList<>(); |
| | | if (mIds.length==1 && mIds.length!=0){ |
| | | String mId = mIds[0]; |
| | | List<Map> dataAvbByMIdAndTime = historyHourlyService.getDataAvbByMIdAndTime(mId, date1, date2); |
| | | List<Map<String,Object>> dataAvbByMIdAndTime = historyHourlyService.getDataAvbByMIdAndTime(mId, date1, date2); |
| | | Double maxO3 = Double.parseDouble(dataAvbByMIdAndTime.get(dataAvbByMIdAndTime.size() - 1).get("maxO3").toString()); |
| | | Map<String,Object> dailyAvgData =new HashMap<>(); |
| | | if (dataAvbByMIdAndTime.get(dataAvbByMIdAndTime.size() - 2).get("data")!=""){ |
| | | dailyAvgData = (Map<String, Object>) dataAvbByMIdAndTime.get(dataAvbByMIdAndTime.size() - 2).get("data"); |
| | | dailyAvgData.put("maxO3_8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | }else { |
| | | dailyAvgData= historyHourlyService.getAvgDataByMId(mId, date1, date2); |
| | | dailyAvgData.put("maxO3_8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | } |
| | | dataAvbByMIdAndTime.remove(dataAvbByMIdAndTime.size() - 1); |
| | | dataAvbByMIdAndTime.remove(dataAvbByMIdAndTime.size() - 1); |
| | | Map<String,Object> dayMap = new HashMap<>(); |
| | | dayMap.put("data",dailyAvgData); |
| | | dayMap.put("time",date1.substring(0,11)); |
| | | dataAvbByMIdAndTime.add(dayMap); |
| | | for (int i = 0; i <dataAvbByMIdAndTime.size() ; i++) { |
| | | if (i!=dataAvbByMIdAndTime.size()-1){ |
| | | Map<String, Object> map1 = AQICalculation2.hourlyAQI((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")); |
| | | if (Double.parseDouble(map1.get("AQI").toString())>=50.0){ |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("primary_pollutants",map1.get("maxSensor")); |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | }else { |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("primary_pollutants","-"); |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | } |
| | | }else { |
| | | Map<String, Object> map1 = AQICalculation2.dayAQI((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")); |
| | | if (Double.parseDouble(map1.get("AQI").toString())>=50.0){ |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("primary_pollutants",map1.get("maxSensor")); |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | }else { |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("primary_pollutants","-"); |
| | | ((Map<String, Object>) dataAvbByMIdAndTime.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | } |
| | | } |
| | | } |
| | | lists.add(dataAvbByMIdAndTime); |
| | | //List<Device> devicesByMonitorPointId = deviceService.getDevicesByMonitorPointId(Integer.valueOf(mId)); |
| | | }else { |
| | | for (int i = 0; i <mIds.length ; i++) { |
| | | List<Map> dataAvbByMIdAndTime = historyHourlyService.getDataAvbByMIdAndTime(mIds[i], date1, date2); |
| | | List<Map<String,Object>> dataAvbByMIdAndTime = historyHourlyService.getDataAvbByMIdAndTime(mIds[i], date1, date2); |
| | | Double maxO3 = Double.parseDouble(dataAvbByMIdAndTime.get(dataAvbByMIdAndTime.size() - 1).get("maxO3").toString()); |
| | | Map<String,Object> dailyAvgData =new HashMap<>(); |
| | | if (dataAvbByMIdAndTime.get(dataAvbByMIdAndTime.size() - 2).get("data")!=""){ |
| | | dailyAvgData = (Map<String, Object>) dataAvbByMIdAndTime.get(dataAvbByMIdAndTime.size() - 2).get("data"); |
| | | dailyAvgData.put("maxO3_8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | }else { |
| | | dailyAvgData= historyHourlyService.getAvgDataByMId(mIds[i], date1, date2); |
| | | dailyAvgData.put("maxO3_8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | } |
| | | dataAvbByMIdAndTime.remove(dataAvbByMIdAndTime.size() - 1); |
| | | dataAvbByMIdAndTime.remove(dataAvbByMIdAndTime.size() - 1); |
| | | Map<String,Object> dayMap = new HashMap<>(); |
| | | dayMap.put("data",dailyAvgData); |
| | | dayMap.put("time",date1.substring(0,11)); |
| | | dataAvbByMIdAndTime.add(dayMap); |
| | | lists.add(dataAvbByMIdAndTime); |
| | | } |
| | | List<Map<String, Object>> dataByMonitorPoints = historyHourlyService.getDataByMonitorPoints(mIds, date1, date2); |
| | | lists.add(dataByMonitorPoints); |
| | | } |
| | | return new ResultBean<List<List<Map>>>(lists); |
| | | return new ResultBean<List<List<Map<String,Object>>>>(lists); |
| | | } |
| | | } |
| | |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.security.access.method.P; |
| | | |
| | | import java.lang.reflect.Array; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | List<Map<String,Object>> getDataAvbByMIdAndTime( @Param("mId")String mId, |
| | | @Param("startTime")String startTime, |
| | | @Param("endTime")String endTime); |
| | | |
| | | List<Map<String,Object>> getDataByMonitorPoints(@Param("mIds") String[] mIds, |
| | | @Param("startTime")String startTime, |
| | | @Param("endTime")String endTime); |
| | | |
| | | |
| | | Map<String,Object> getAvgDataByMId(@Param("mId")String mId, |
| | | @Param("startTime")String startTime, |
| | | @Param("endTime")String endTime); |
| | | |
| | | Map<String,Object> getAvgDataByMIds(@Param("mIds")String[] mIds, |
| | | @Param("startTime")String startTime, |
| | | @Param("endTime")String endTime); |
| | | } |
| | |
| | | @Param("table") String table);
|
| | |
|
| | | Map<String,Object> getDailyAvgData(@Param("mId")String mId,@Param("time")String time);
|
| | | Map<String,Object> getDailyAvgDataByMIds(@Param("mIds")String[] mIds,@Param("time")String time);
|
| | |
|
| | | } |
| | |
| | | package com.moral.service; |
| | | |
| | | import java.lang.reflect.Array; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | |
| | | List<Map> getDataByMacAndTime(Map param); |
| | | |
| | | List<Map> getDataAvbByMIdAndTime(String mId,String startTime,String endTime); |
| | | List<Map<String,Object>> getDataAvbByMIdAndTime(String mId,String startTime,String endTime); |
| | | List<Map<String,Object>> getDataByMonitorPoints(String[] mIds, String startTime, String endTime); |
| | | Map<String,Object> getAvgDataByMId(String mId,String startTime,String endTime); |
| | | } |
| | |
| | | package com.moral.service.impl; |
| | | |
| | | import java.lang.reflect.Array; |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map> getDataAvbByMIdAndTime(String mId, String startTime, String endTime) { |
| | | List<Device> devicesByMonitorPointId = deviceService.getDevicesByMonitorPointId(Integer.valueOf(mId)); |
| | | List<List> lists = new ArrayList<>(); |
| | | public List<Map<String,Object>> getDataAvbByMIdAndTime(String mId, String startTime, String endTime) { |
| | | List<List<Map<String,String>>> listArrayList = new ArrayList<>(); |
| | | List<Map<String, Object>> dataAvbByMIdAndTime = historyHourlyMapper.getDataAvbByMIdAndTime(mId, startTime, endTime); |
| | | List<Map> mapList = new ArrayList<>(); |
| | |
| | | timeOfHour=timeOfHour+1; |
| | | } |
| | | O3_8.put("time", String.valueOf(timeOfHour)); |
| | | O3_8.put("O3-8h", String.valueOf(avg1)); |
| | | O3_8.put("O3_8h", String.valueOf(avg1)); |
| | | mapList1.add(O3_8); |
| | | }else { |
| | | continue; |
| | |
| | | List<Map<String, String>> mapList1 = listArrayList.get(0); |
| | | List<Double> O3List = new ArrayList(); |
| | | for (Map<String, String> stringStringMap : mapList1) { |
| | | O3List.add(Double.parseDouble(stringStringMap.get("O3-8h"))); |
| | | O3List.add(Double.parseDouble(stringStringMap.get("O3_8h"))); |
| | | } |
| | | |
| | | maxO3 = Collections.max(O3List); |
| | | for (int i = 0; i <dataAvbByMIdAndTime.size() ; i++) { |
| | | dataAvbByMIdAndTime.get(i).put("O3-8h",null); |
| | | dataAvbByMIdAndTime.get(i).put("O3_8h",""); |
| | | int time = Integer.parseInt(((Object)dataAvbByMIdAndTime.get(i).get("time")).toString().substring(11,13)) ; |
| | | for (int j = 0; j <mapList1.size() ; j++) { |
| | | int time1 = Integer.parseInt(mapList1.get(j).get("time").toString()) ; |
| | | if (time==time1){ |
| | | Double O3_8h = Double.parseDouble(mapList1.get(j).get("O3-8h").toString()); |
| | | dataAvbByMIdAndTime.get(i).put("O3-8h",new BigDecimal(O3_8h).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | Double O3_8h = Double.parseDouble(mapList1.get(j).get("O3_8h").toString()); |
| | | dataAvbByMIdAndTime.get(i).put("O3_8h",new BigDecimal(O3_8h).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | Map<String, Object> dailyAvgData = historyMapper.getDailyAvgData(mId, startTime); |
| | | if (dailyAvgData!=null){ |
| | | dailyAvgData.put("maxO3-8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | dailyAvgData.put("time",startTime); |
| | | dailyAvgData.put("maxO3_8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | } |
| | | if (dataAvbByMIdAndTime.size()>24){ |
| | | for (int i = 0; i <dataAvbByMIdAndTime.size()-1 ; i++) { |
| | | Map<String, Object> map =dataAvbByMIdAndTime.get(i); |
| | | Map<String, Object> map1 = AQICalculation2.hourlyAQI(map); |
| | | dataAvbByMIdAndTime.get(i).put("AQI",Double.parseDouble(map1.get("AQI").toString())); |
| | | if (Double.parseDouble(map1.get("AQI").toString())>=50){ |
| | | String name = map1.get("maxSensor").toString(); |
| | | dataAvbByMIdAndTime.get(i).put("首要污染物",name); |
| | | }else { |
| | | dataAvbByMIdAndTime.get(i).put("首要污染物","-"); |
| | | } |
| | | } |
| | | }else { |
| | | List<Map<String,Object>> finalList = new ArrayList<>(); |
| | | for (int i = 0; i <dataAvbByMIdAndTime.size() ; i++) { |
| | | Map<String, Object> map =dataAvbByMIdAndTime.get(i); |
| | | Map<String, Object> map1 = AQICalculation2.hourlyAQI(map); |
| | | dataAvbByMIdAndTime.get(i).put("AQI",Double.parseDouble(map1.get("AQI").toString())); |
| | | if (Double.parseDouble(map1.get("AQI").toString())>=50){ |
| | | String name = map1.get("maxSensor").toString(); |
| | | dataAvbByMIdAndTime.get(i).put("首要污染物",name); |
| | | }else { |
| | | dataAvbByMIdAndTime.get(i).put("首要污染物","-"); |
| | | } |
| | | } |
| | | } |
| | | Map<String, Object> dayAQI = AQICalculation2.dayAQI(dailyAvgData); |
| | | dailyAvgData.put("首要污染物",dayAQI.get("maxSensor")); |
| | | dailyAvgData.put("AQI",dayAQI.get("AQI")); |
| | | dataAvbByMIdAndTime.add(dataAvbByMIdAndTime.size(),dailyAvgData); |
| | | |
| | | List<Map> finalList = new ArrayList<>(); |
| | | for (int i = 0; i <dataAvbByMIdAndTime.size() ; i++) { |
| | | Map timeAndDate = new HashMap(); |
| | | if (i!=dataAvbByMIdAndTime.size()-1){ |
| | | Map<String,Object> timeAndDate = new HashMap(); |
| | | String time = dataAvbByMIdAndTime.get(i).get("time").toString().substring(11,13); |
| | | dataAvbByMIdAndTime.get(i).remove("time"); |
| | | timeAndDate.put("time",time); |
| | | timeAndDate.put("data",dataAvbByMIdAndTime.get(i)); |
| | | finalList.add(timeAndDate); |
| | | }else { |
| | | String time = dataAvbByMIdAndTime.get(i).get("time").toString().substring(0,11); |
| | | dataAvbByMIdAndTime.get(i).remove("time"); |
| | | } |
| | | Map<String,Object> timeAndDate = new HashMap(); |
| | | String time = startTime.substring(0,11); |
| | | timeAndDate.put("time",time); |
| | | timeAndDate.put("data",dataAvbByMIdAndTime.get(i)); |
| | | if (dailyAvgData==null){ |
| | | //List<Map<String, Object>> dailyData = historyHourlyMapper.getDataAvbByMIdAndT; |
| | | timeAndDate.put("data",""); |
| | | }else { |
| | | timeAndDate.put("data",dailyAvgData); |
| | | } |
| | | |
| | | finalList.add(timeAndDate); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("maxO3",maxO3); |
| | | finalList.add(map); |
| | | return finalList; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getDataByMonitorPoints(String[] mIds, String startTime, String endTime) { |
| | | List<Map<String, Object>> dataByMonitorPoints = historyHourlyMapper.getDataByMonitorPoints(mIds, startTime, endTime); |
| | | List<Map> mapList = new ArrayList<>(); |
| | | for (Map<String, Object> dataByMonitorPoint : dataByMonitorPoints) { |
| | | Map<String,String> map = new HashMap(); |
| | | String s = dataByMonitorPoint.get("O3").toString(); |
| | | Object time = dataByMonitorPoint.get("time"); |
| | | map.put("O3",s); |
| | | map.put("time",time.toString()); |
| | | mapList.add(map); |
| | | } |
| | | List<List<Map<String,String>>> listArrayList = new ArrayList<>(); |
| | | if (mapList.size()>=8){ |
| | | List<Map<String,String>> mapList1 = new ArrayList<>(); |
| | | for (int i = 7; i <=mapList.size()-1 ; i++) { |
| | | if (mapList.get(i).get("O3")!=null){ |
| | | List<Integer> numList = new ArrayList(); |
| | | Map<String,String> O3_8 = new HashMap<>(); |
| | | for (int j =i; j<= mapList.size(); j--) { |
| | | if (j<0){ |
| | | break; |
| | | } |
| | | numList.add(j); |
| | | if (numList.size()==8){ |
| | | List e15 = new ArrayList(); |
| | | for (int k = 0; k <numList.size() ; k++) { |
| | | String value = mapList.get(Integer.valueOf(numList.get(k))).get("O3").toString(); |
| | | e15.add(value); |
| | | } |
| | | double sum =0; |
| | | for (Object o : e15) { |
| | | sum=sum+Double.parseDouble(o.toString()); |
| | | } |
| | | Double avg1 = sum/e15.size(); |
| | | int timeOfHour = numList.get(0); |
| | | if (timeOfHour==23){ |
| | | timeOfHour=0; |
| | | }else { |
| | | timeOfHour=timeOfHour+1; |
| | | } |
| | | O3_8.put("time", String.valueOf(timeOfHour)); |
| | | O3_8.put("O3_8h", String.valueOf(avg1)); |
| | | mapList1.add(O3_8); |
| | | }else { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | listArrayList.add(mapList1); |
| | | } |
| | | } |
| | | Double maxO3=0.0; |
| | | if(listArrayList.size()>0){ |
| | | List<Map<String, String>> mapList1 = listArrayList.get(0); |
| | | List<Double> O3List = new ArrayList(); |
| | | for (Map<String, String> stringStringMap : mapList1) { |
| | | O3List.add(Double.parseDouble(stringStringMap.get("O3_8h"))); |
| | | } |
| | | maxO3 = Collections.max(O3List); |
| | | for (int i = 0; i <dataByMonitorPoints.size() ; i++) { |
| | | dataByMonitorPoints.get(i).put("O3_8h",""); |
| | | int time = Integer.parseInt(((Object)dataByMonitorPoints.get(i).get("time")).toString().substring(11,13)) ; |
| | | for (int j = 0; j <mapList1.size() ; j++) { |
| | | int time1 = Integer.parseInt(mapList1.get(j).get("time").toString()) ; |
| | | if (time==time1){ |
| | | Double O3_8h = Double.parseDouble(mapList1.get(j).get("O3_8h").toString()); |
| | | dataByMonitorPoints.get(i).put("O3_8h",new BigDecimal(O3_8h).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<Map<String,Object>> finalList = new ArrayList<>(); |
| | | for (int i = 0; i <dataByMonitorPoints.size() ; i++) { |
| | | Map<String,Object> timeAndDate = new HashMap(); |
| | | String time = dataByMonitorPoints.get(i).get("time").toString().substring(11,13); |
| | | dataByMonitorPoints.get(i).remove("time"); |
| | | timeAndDate.put("time",time); |
| | | timeAndDate.put("data",dataByMonitorPoints.get(i)); |
| | | finalList.add(timeAndDate); |
| | | } |
| | | Map<String, Object> dailyAvgData = historyMapper.getDailyAvgDataByMIds(mIds, startTime); |
| | | if (dailyAvgData!=null){ |
| | | Map<String,Object> timeAndDate = new HashMap(); |
| | | dailyAvgData.put("maxO3_8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | timeAndDate.put("data",dailyAvgData); |
| | | timeAndDate.put("time",startTime.substring(0,11)); |
| | | finalList.add(timeAndDate); |
| | | }else { |
| | | Map<String, Object> avgDataByMIds = historyHourlyMapper.getAvgDataByMIds(mIds, startTime, endTime); |
| | | Map<String,Object> timeAndDate = new HashMap(); |
| | | avgDataByMIds.put("maxO3_8h",new BigDecimal(maxO3).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue()); |
| | | timeAndDate.put("data",avgDataByMIds); |
| | | timeAndDate.put("time",startTime.substring(0,11)); |
| | | finalList.add(timeAndDate); |
| | | } |
| | | for (int i=0;i<finalList.size();i++) { |
| | | if (i!=finalList.size()-1){ |
| | | Map<String, Object> map1 = AQICalculation2.hourlyAQI((Map<String, Object>) finalList.get(i).get("data")); |
| | | if (Double.parseDouble(map1.get("AQI").toString())>=50.0){ |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("primary_pollutants",map1.get("maxSensor")); |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | }else { |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("primary_pollutants","-"); |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | } |
| | | }else { |
| | | Map<String, Object> map1 = AQICalculation2.dayAQI((Map<String, Object>) finalList.get(i).get("data")); |
| | | if (Double.parseDouble(map1.get("AQI").toString())>=50.0){ |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("primary_pollutants",map1.get("maxSensor")); |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | }else { |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("primary_pollutants","-"); |
| | | ((Map<String, Object>) finalList.get(i).get("data")).put("AQI",map1.get("AQI")); |
| | | } |
| | | } |
| | | } |
| | | Map<String,Object> timeAndDate = new HashMap(); |
| | | String time = startTime.substring(0,11); |
| | | timeAndDate.put("time",time); |
| | | if (dailyAvgData==null){ |
| | | timeAndDate.put("data",""); |
| | | }else { |
| | | timeAndDate.put("data",dailyAvgData); |
| | | } |
| | | return finalList; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getAvgDataByMId(String mId, String startTime, String endTime) { |
| | | return historyHourlyMapper.getAvgDataByMId(mId,startTime,endTime); |
| | | } |
| | | |
| | | @Override |
| | | public Point getDirPoint(Map<String, Object> parameters) throws Exception { |
| | | Map<String, Object> pollutionSourceData = getPollutionSourceDataByHour(parameters); |
| | | if (MapUtils.isEmpty(pollutionSourceData)) { |
| | |
| | |
|
| | | @Override
|
| | | public List<Map<String, Object>> getForecastAndReal(Map<String, Object> parameters) throws ParseException {
|
| | | ArrayList<String> sensorKeys = (ArrayList<String>) parameters.get("sensorKeys");
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | | for (int i = 0; i < 24; i++) {
|
| | | Map<String, Object> map = new HashMap<>();
|
| | | List<String> arrayList = new ArrayList<>();
|
| | | map.put("values", arrayList);
|
| | | map.put("time", i + 1);
|
| | | resultList.add(map);
|
| | | }
|
| | |
|
| | | for (String sensorKey : sensorKeys) {
|
| | | parameters.put("sensorKey", sensorKey);
|
| | | List<Map<String, Object>> list = forecastAndReal(parameters);
|
| | | for (Map<String, Object> map : list) {
|
| | | Object time = map.get("time");
|
| | | ArrayList<String> values = (ArrayList<String>) map.get("values");
|
| | | for (Map<String, Object> resultMap : resultList) {
|
| | | if (time.equals(resultMap.get("time"))) {
|
| | | ArrayList<String> resultValues = (ArrayList<String>) resultMap.get("values");
|
| | | resultValues.addAll(values);
|
| | | resultMap.put("values", resultValues);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return resultList;
|
| | | }
|
| | |
|
| | | public List<Map<String, Object>> forecastAndReal(Map<String, Object> parameters) throws ParseException {
|
| | | Object sensorKey = parameters.remove("sensorKey");
|
| | | String sensor1;
|
| | | String sensor2;
|
| | | if ("e1".equals(sensorKey)) {
|
| | | sensor1 = "PM25C";
|
| | | sensor2 = "PM2_5";
|
| | | } else if ("e2".equals(sensorKey)) {
|
| | | sensor1 = "PM10C";
|
| | | sensor2 = "PM10";
|
| | | } else {
|
| | | sensor1 = "O3C";
|
| | | sensor2 = "O3";
|
| | | }
|
| | | parameters.put("sensor1", sensor1);
|
| | | parameters.put("sensor2", sensor2);
|
| | | parameters.put("typeFormat", "%Y-%m-%d %H:%i:%s");
|
| | | String monitorPointId = parameters.get("monitorPointId").toString();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| | |
| | | parameters.put("start", sdf.parse(time));
|
| | | parameters.put("end", sdf.parse(nextDay));
|
| | | MonitorPoint monitorPoint = monitorPointMapper.selectByPrimaryKey(Integer.valueOf(monitorPointId));
|
| | | int cityCode;
|
| | | int parentCode;
|
| | | if (monitorPoint.getAreaCode() == null) {
|
| | | parameters.put("cityCode", monitorPoint.getCityCode());
|
| | | cityCode = monitorPoint.getCityCode();
|
| | | parentCode = monitorPoint.getProvinceCode();
|
| | | } else {
|
| | | parameters.put("cityCode", monitorPoint.getAreaCode());
|
| | | cityCode = monitorPoint.getAreaCode();
|
| | | parentCode = monitorPoint.getCityCode();
|
| | | }
|
| | | parameters.put("cityCode", cityCode);
|
| | | //实测O3
|
| | | List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
|
| | | List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecastHour(parameters);
|
| | |
|
| | | String timeUnits = time.substring(5, 7);
|
| | | String timeUnits = time.substring(0, 4);
|
| | | if (aqiList.size() == 0) {
|
| | | parameters.put("timeUnits", timeUnits);
|
| | | aqiList = hangzhouAqiMapper.getHistoryO3(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | parameters.put("cityCode", monitorPoint.getCityCode());
|
| | | parameters.put("cityCode", parentCode);
|
| | | aqiList = hangzhouAqiMapper.getAqiDataByAreaCode(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | parameters.put("cityCode", monitorPoint.getAreaCode());
|
| | | aqiList = hangzhouAqiMapper.getHistoryO3(parameters);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //预测O3
|
| | | parameters.put("cityCode", cityCode);
|
| | | List<Map<String, Object>> forecastList = forecastWeatherMapper.getForecastHour(parameters);
|
| | | if (forecastList.size() == 0) {
|
| | | parameters.put("cityCode", parentCode);
|
| | | forecastList = forecastWeatherMapper.getForecastHour(parameters);
|
| | | }
|
| | | for (Map<String, Object> map : aqiList) {
|
| | | String O3 = map.get("O3").toString().replace("\"", "");
|
| | | map.put("O3", O3);
|
| | | int s = (int) Double.parseDouble(map.get(sensor2).toString().replace("\"", ""));
|
| | | map.put(sensor2, String.valueOf(s));
|
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | |
| | | }
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | values.add("");
|
| | | values.add(aqiMap.get("O3").toString());
|
| | | values.add(aqiMap.get(sensor2).toString());
|
| | | map.put("values", values);
|
| | | resultList.add(map);
|
| | | }
|
| | |
| | | hour = "24";
|
| | | }
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | if (forecastMap.get("O3") != null) {
|
| | | values.add(forecastMap.get("O3").toString().replace("\"", ""));
|
| | | if (forecastMap.get(sensor2) != null) {
|
| | | values.add(forecastMap.get(sensor2).toString().replace("\"", ""));
|
| | | } else {
|
| | | values.add("");
|
| | | }
|
| | |
| | | hour = "24";
|
| | | }
|
| | | map.put("time", Integer.valueOf(hour));
|
| | | if (forecastMap.get("O3") != null) {
|
| | | values.add(forecastMap.get("O3").toString().replace("\"", ""));
|
| | | if (forecastMap.get(sensor2) != null) {
|
| | | values.add(forecastMap.get(sensor2).toString().replace("\"", ""));
|
| | | } else {
|
| | | values.add("");
|
| | | }
|
| | | for (Map<String, Object> aqiMap : aqiList) {
|
| | | if (forecastMap.get("time").equals(aqiMap.get("time"))) {
|
| | | values.add(aqiMap.get("O3").toString());
|
| | | values.add(aqiMap.get(sensor2).toString());
|
| | | }
|
| | | }
|
| | | map.put("values", values);
|
| | |
| | | City city = cityMapper.getCityByName(cityName);
|
| | | if (city == null) {
|
| | | Province province = provinceMapper.getProvinceByName(cityName);
|
| | | if (province == null) {
|
| | | return new ArrayList<>();
|
| | | }
|
| | | code = province.getProvinceCode();
|
| | | name = province.getProvinceName();
|
| | | parentCode = 0;
|
| | |
| | | Date end = cal.getTime();
|
| | | cal.setTime(sdf.parse(time));
|
| | | cal.add(Calendar.DAY_OF_MONTH, -1);
|
| | | //获取前天时间,作为预测时的时间,提前一天预测
|
| | | String beforeDay = sdf.format(cal.getTime());
|
| | | parameters.put("start", selectTime);
|
| | | parameters.put("end", end);
|
| | |
| | | if (!String.valueOf(code).endsWith("0000")) {
|
| | | parameters.put("cityCode", parentCode);
|
| | | forecastList = forecastWeatherMapper.getForecast(parameters);
|
| | | } else {
|
| | | return new ArrayList<>();
|
| | | }
|
| | | }
|
| | |
|
| | | //添加预测时间,每天07,15点预测一次
|
| | | List<Map<String, Object>> foreList = new ArrayList<>();
|
| | | //添加预测时间,每天07,15点各预测一次
|
| | | for (Map<String, Object> forecastMap : forecastList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", forecastMap.get("time").toString());
|
| | | hashMap.put("type", "预测");
|
| | | hashMap.put("city", name);
|
| | | forecastMap.put("type", "预测");
|
| | | forecastMap.put("city", name);
|
| | | if (sdf.parse(time).getTime() <= now.getTime()) {
|
| | | hashMap.put("fxTime", (beforeDay + " 15:00").substring(5, 16));
|
| | | forecastMap.put("fxTime", (beforeDay + " 15:00").substring(5, 16));
|
| | | } else {
|
| | | String format = sdf1.format(now).split(" ")[0];
|
| | | Date date1 = sdf1.parse(format + " 07:00:00");
|
| | | Date date2 = sdf1.parse(format + " 15:00:00");
|
| | | if (now.getTime() > date2.getTime()) {
|
| | | hashMap.put("fxTime", (beforeDay + " 15:00").substring(5, 16));
|
| | | forecastMap.put("fxTime", (beforeDay + " 15:00").substring(5, 16));
|
| | | } else if (now.getTime() > date1.getTime()) {
|
| | | hashMap.put("fxTime", (beforeDay + " 07:00").substring(5, 16));
|
| | | forecastMap.put("fxTime", (beforeDay + " 07:00").substring(5, 16));
|
| | | }
|
| | | }
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(forecastMap.get("json").toString());
|
| | | hashMap.putAll(jsonMap);
|
| | | foreList.add(hashMap);
|
| | | }
|
| | |
|
| | | for (Map<String, Object> foreMap : foreList) {
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(forecastMap.remove("json").toString());
|
| | | forecastMap.putAll(jsonMap);
|
| | | //预测中的过去6小时降水总量
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("cityCode", parameters.get("cityCode").toString());
|
| | | Date endTime = sdf1.parse(foreMap.get("time").toString());
|
| | | Date endTime = sdf1.parse(forecastMap.get("time").toString());
|
| | | hashMap.put("end", endTime);
|
| | | //过去6小时总降水量(预测)
|
| | | cal.setTime(endTime);
|
| | | cal.add(Calendar.HOUR, -6);
|
| | | Date startTime = cal.getTime();
|
| | | hashMap.put("start", startTime);
|
| | | Map<String, Object> precip6HourMap = forecastWeatherMapper.getPrecip6Hour(hashMap);
|
| | | if (precip6HourMap != null) {
|
| | | foreMap.put("precip6", precip6HourMap.get("precip6").toString());
|
| | | forecastMap.put("precip6", precip6HourMap.get("precip6").toString());
|
| | | }
|
| | | //过去8小时O3平均值(预测)
|
| | | cal.setTime(endTime);
|
| | |
| | | hashMap.put("start", startTime);
|
| | | Map<String, Object> O3Map = forecastWeatherMapper.getO38Hours(hashMap);
|
| | | if (O3Map != null) {
|
| | | foreMap.put("O3C_8H", O3Map.get("O3_8H").toString());
|
| | | forecastMap.put("O3C_8H", O3Map.get("O3_8H").toString());
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | //获取实测aqi
|
| | | parameters.put("cityCode", code);
|
| | | //从hangzhou_aqi获取,没有再从history_aqi_月分表获取
|
| | | //从hangzhou_aqi获取,没有再从history_aqi年分表获取
|
| | | int p = 0;
|
| | | String timeUnits1 = time.substring(5, 7);
|
| | | String timeUnits2 = sdf1.format(end).substring(5, 7);
|
| | | String timeUnits1 = time.substring(0, 4);
|
| | | String timeUnits2 = sdf1.format(end).substring(0, 4);
|
| | | List<Map<String, Object>> aqiList = hangzhouAqiMapper.getAqi(parameters);
|
| | | if (aqiList.size() == 0) {
|
| | | p = 1;
|
| | | //1-23点数据必然是同一个月份,最后一个可能是下一个月
|
| | | //1-23点数据必然是同年,00点可能是明年
|
| | | parameters.put("timeUnits", timeUnits1);
|
| | | List<Map<String, Object>> aqiList1 = hangzhouAqiMapper.getHistoryAqi(parameters);
|
| | | parameters.put("timeUnits", timeUnits2);
|
| | |
| | | }
|
| | | DecimalFormat df = new DecimalFormat(".####");
|
| | | DecimalFormat df1 = new DecimalFormat("#.#");
|
| | | List<Map<String, Object>> realAqilist = new ArrayList<>();
|
| | | for (Map<String, Object> aqiMap : aqiList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", aqiMap.get("time"));
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(aqiMap.get("json").toString());
|
| | | aqiMap.put("type", "实测");
|
| | | aqiMap.put("city", name);
|
| | | Map<String, Object> jsonMap = (Map<String, Object>) JSONObject.parse(aqiMap.remove("json").toString());
|
| | | for (String key : jsonMap.keySet()) {
|
| | | if ("NO2".equals(key) || "NO2C".equals(key) || "O3".equals(key) || "O3C".equals(key) ||
|
| | | "SO2".equals(key) || "SO2C".equals(key) || "PM2_5".equals(key) || "PM25C".equals(key) || "PM10".equals(key) || "PM10C".equals(key)) {
|
| | |
| | | long AQI = Math.round(Double.valueOf(jsonMap.get(key).toString()));
|
| | | jsonMap.put(key, String.valueOf(AQI));
|
| | | }
|
| | |
|
| | | }
|
| | | hashMap.putAll(jsonMap);
|
| | | hashMap.put("city", name);
|
| | | realAqilist.add(hashMap);
|
| | | }
|
| | | aqiMap.putAll(jsonMap);
|
| | |
|
| | | //计算o3_8H(实测)
|
| | | for (Map<String, Object> map : realAqilist) {
|
| | | String s = map.get("time").toString();
|
| | | //计算O3_8H(实测)
|
| | | String s = aqiMap.get("time").toString();
|
| | | Date endTime = sdf1.parse(s);
|
| | | cal.setTime(endTime);
|
| | | cal.add(Calendar.HOUR, -8);
|
| | |
| | | hashMap.put("cityCode", parameters.get("cityCode").toString());
|
| | | hashMap.put("start", startTime);
|
| | | hashMap.put("end", endTime);
|
| | | Map<String, Object> O3Map = new HashMap<>();
|
| | | Map<String, Object> O3Map;
|
| | | if (p == 0) {
|
| | | O3Map = hangzhouAqiMapper.getAvgO3EightHours(hashMap);
|
| | | } else {
|
| | | hashMap.put("time", endTime);
|
| | | hashMap.put("timeUnits", s.substring(5, 7));
|
| | | hashMap.put("timeUnits", s.substring(0, 4));
|
| | | O3Map = hangzhouAqiMapper.getHistoryO3EightHours(hashMap);
|
| | | }
|
| | | map.put("O3C_8H", O3Map.get("O3_8H").toString().replace("\"", ""));
|
| | | aqiMap.put("O3C_8H", O3Map.get("O3_8H").toString().replace("\"", ""));
|
| | |
|
| | | }
|
| | | //光照,该城市下所有设备光照平均值以及tvoc
|
| | | Map<String, Object> params = new HashMap<>();
|
| | |
| | | parameters.put("cityCode", code);
|
| | | List<Map<String, Object>> realList = realWeatherMapper.getRealWeather(parameters);
|
| | | if (realList.size() == 0) {
|
| | | //1-23点数据必然是同一个月份,最后一个可能是下一个月
|
| | | //1-23点数据必然是同年,00点可能是明年
|
| | | x = 1;
|
| | | timeUnits1 = time.substring(5, 7);
|
| | | timeUnits2 = sdf1.format(end).substring(5, 7);
|
| | | timeUnits1 = time.substring(0, 4);
|
| | | timeUnits2 = sdf1.format(end).substring(0, 4);
|
| | | parameters.put("timeUnits", timeUnits1);
|
| | | List<Map<String, Object>> realList1 = realWeatherMapper.getHistoryWeather(parameters);
|
| | | parameters.put("timeUnits", timeUnits2);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | List<Map<String, Object>> realWeatherList = new ArrayList<>();
|
| | | for (Map<String, Object> realMap : realList) {
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", realMap.get("time"));
|
| | | Map<String, Object> jsonMap;
|
| | | if (x == 0) {
|
| | | jsonMap = (Map<String, Object>) JSONObject.parse(realMap.get("json").toString());
|
| | | jsonMap = (Map<String, Object>) JSONObject.parse(realMap.remove("json").toString());
|
| | | } else {
|
| | | jsonMap = (Map<String, Object>) JSONObject.parse(realMap.get("value").toString());
|
| | | jsonMap = (Map<String, Object>) JSONObject.parse(realMap.remove("value").toString());
|
| | | }
|
| | | hashMap.putAll(jsonMap);
|
| | | hashMap.put("city", name);
|
| | | realWeatherList.add(hashMap);
|
| | | realMap.putAll(jsonMap);
|
| | | realMap.put("city", name);
|
| | | realMap.put("type", "实测");
|
| | | }
|
| | |
|
| | | //Tvoc,光照合并
|
| | | //TVOC,光照合并
|
| | | for (Map<String, Object> beamMap : beamList) {
|
| | | for (Map<String, Object> tvocMap : tvocList) {
|
| | | Object bTime = beamMap.get("time");
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | for (Map<String, Object> realMap : realWeatherList) {
|
| | | for (Map<String, Object> realMap : realList) {
|
| | | if (time1.equals(realMap.get("time"))) {
|
| | | map1.putAll(realMap);
|
| | | }
|
| | |
| | | listMap.put("type", "实测");
|
| | | listMap.put("city", name);
|
| | | String time1 = listMap.get("time").toString();
|
| | | for (Map<String, Object> aqiMap : realAqilist) {
|
| | | for (Map<String, Object> aqiMap : aqiList) {
|
| | | if (time1.equals(aqiMap.get("time"))) {
|
| | | listMap.putAll(aqiMap);
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | List<Map<String, Object>> resultList = new ArrayList<>();
|
| | | if (foreList.size() == 0) {
|
| | | if (forecastList.size() == 0) {
|
| | | cal.setTime(selectTime);
|
| | | for (long d = cal.getTimeInMillis(); d < end.getTime();
|
| | | cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + 1),
|
| | |
| | | hashMap.put("type", "预测");
|
| | | hashMap.put("city", name);
|
| | | hashMap.put("time", sdf1.format(d));
|
| | | foreList.add(hashMap);
|
| | | forecastList.add(hashMap);
|
| | | }
|
| | | }
|
| | |
|
| | | for (Map<String, Object> foreMap : foreList) {
|
| | | for (Map<String, Object> foreMap : forecastList) {
|
| | | for (Map<String, Object> realMap : list) {
|
| | | if (foreMap.get("time").equals(realMap.get("time"))) {
|
| | | resultList.add(foreMap);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | for (int i = list.size(); i < foreList.size(); i++) {
|
| | | Map<String, Object> map = foreList.get(i);
|
| | | for (int i = list.size(); i < forecastList.size(); i++) {
|
| | | Map<String, Object> map = forecastList.get(i);
|
| | | resultList.add(map);
|
| | | Map<String, Object> hashMap = new HashMap<>();
|
| | | hashMap.put("time", map.get("time").toString());
|
| | |
| | | String key = entry.getKey(); |
| | | if (entry.getValue() instanceof Double){ |
| | | Double value = Double.parseDouble(entry.getValue().toString()); |
| | | if (key!="O3-8h"){ |
| | | if (key!="O3_8h"){ |
| | | maxMap.put(key,value); |
| | | } |
| | | Double PM2_5AQI; |
| | |
| | | case "SO2":SO2AQI = SO2AQI(value); |
| | | AQIList.add(SO2AQI); |
| | | break; |
| | | case "e16":NO2AQI = NO2AQI(value); |
| | | case "NO2":NO2AQI = NO2AQI(value); |
| | | AQIList.add(NO2AQI); |
| | | break; |
| | | case "CO":COAQI = COAQI(value); |
| | | AQIList.add(COAQI); |
| | | break; |
| | | case "O3":O3AQI = O3AQI(value); |
| | | case "maxO3_8h":O3AQI = O3AQI(value); |
| | | AQIList.add(O3AQI); |
| | | break; |
| | | |
| | |
| | | |
| | | Double AQIMAX = Collections.max(AQIList); |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | //System.out.println("-------"+maxMap); |
| | | |
| | | Optional<Map.Entry<String, Integer>> max0 = maxMap.entrySet() |
| | | .stream() |
| | | .max(Map.Entry.comparingByValue()); |
| | | //System.out.println("-------"+max0.get().getKey()); |
| | | |
| | | returnMap.put("maxSensor",max0.get().getKey()); |
| | | returnMap.put("AQI", AQIMAX); |
| | |
| | | String key = entry.getKey(); |
| | | if (entry.getValue() instanceof Double){ |
| | | Double value = Double.parseDouble(entry.getValue().toString()); |
| | | if (key!="O3-day"){ |
| | | if (key!="O3_day"){ |
| | | maxMap.put(key,value); |
| | | } |
| | | Double PM2_5AQI; |
| | |
| | | case "SO2":SO2AQI = SO2DayAQI(value); |
| | | AQIList.add(SO2AQI); |
| | | break; |
| | | case "e16":NO2AQI = NO2DayAQI(value); |
| | | case "NO2":NO2AQI = NO2DayAQI(value); |
| | | AQIList.add(NO2AQI); |
| | | break; |
| | | case "CO":COAQI = CODayAQI(value); |
| | | AQIList.add(COAQI); |
| | | break; |
| | | case "O3":maxO38hAQI = O3DayAQI(value); |
| | | case "maxO3_8h":maxO38hAQI = O3DayAQI(value); |
| | | AQIList.add(maxO38hAQI); |
| | | break; |
| | | default: |
| | |
| | | |
| | | Double AQIMAX = Collections.max(AQIList); |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | System.out.println("-------"+maxMap); |
| | | Optional<Map.Entry<String, Integer>> max0 = maxMap.entrySet() |
| | | .stream() |
| | | .max(Map.Entry.comparingByValue()); |
| | | //System.out.println("-------"+max0.get().getKey()); |
| | | |
| | | returnMap.put("maxSensor",max0.get().getKey()); |
| | | returnMap.put("AQI", AQIMAX); |
| | |
| | | <select id="getForecastHour" resultType="java.util.Map"> |
| | | SELECT |
| | | DATE_FORMAT(time, #{typeFormat}) time, |
| | | json->'$.O3C' 'O3' |
| | | json->'$.${sensor1}' '${sensor2}' |
| | | from forecast_weather |
| | | where time >= #{start} |
| | | AND time <![CDATA[<]]> #{end} |
| | |
| | | <select id="getAqiDataByAreaCode" resultType="java.util.Map"> |
| | | SELECT |
| | | DATE_FORMAT(time, #{typeFormat}) time, |
| | | ifnull(aqi_json->'$.O3C',aqi_json->'$.O3') as 'O3' |
| | | ifnull(aqi_json->'$.${sensor1}',aqi_json->'$.${sensor2}') as '${sensor2}' |
| | | FROM |
| | | hangzhou_aqi |
| | | WHERE |
| | |
| | | <select id="getHistoryO3" resultType="java.util.Map"> |
| | | SELECT |
| | | DATE_FORMAT(time, #{typeFormat}) time, |
| | | value->'$.O3' as 'O3' |
| | | value->'$.${sensor2}' as '${sensor2}' |
| | | FROM |
| | | history_aqi_${timeUnits} |
| | | WHERE |
| | |
| | | from monitor_point mt,device d,history_hourly hh |
| | | where mt.id=d.monitor_point_id and d.mac=hh.mac and mt.id=#{mId} and hh.time>#{startTime} and hh.time<![CDATA[<=]]>#{endTime} GROUP BY hh.time; |
| | | </select> |
| | | <select id="getDataByMonitorPoints" resultType="java.util.Map"> |
| | | select hh.time as `time`, |
| | | AVG(hh.json->"$.e1[0]") as `PM2_5`,AVG(hh.json->"$.e2[0]") as 'PM10',AVG(hh.json->"$.e10[0]") as 'CO', |
| | | AVG(hh.json->"$.e11[0]") as 'SO2',AVG(hh.json->"$.e16[0]") as 'NO2',AVG(hh.json->"$.e15[0]") as 'O3' |
| | | from monitor_point mt,device d,history_hourly hh |
| | | where mt.id=d.monitor_point_id and d.mac=hh.mac and mt.id in |
| | | <foreach collection="mIds" item="id" index="index" open="(" close=")" separator=","> |
| | | #{id} |
| | | </foreach> |
| | | and hh.time>#{startTime} and hh.time<![CDATA[<=]]>#{endTime} GROUP BY hh.time; |
| | | </select> |
| | | <select id="getAvgDataByMId" resultType="java.util.Map"> |
| | | SELECT AVG(hh.json->"$.e1[0]") as `PM2_5`,AVG(hh.json->"$.e2[0]") as 'PM10',AVG(hh.json->"$.e10[0]") as 'CO', |
| | | AVG(hh.json->"$.e11[0]") as 'SO2',AVG(hh.json->"$.e16[0]") as 'NO2',AVG(hh.json->"$.e15[0]") as 'O3_day' |
| | | from monitor_point mt,device d,history_hourly hh where mt.id=d.monitor_point_id |
| | | and d.mac=hh.mac and mt.id =#{mId} and hh.time<![CDATA[<=]]>#{endTime} and hh.time>#{startTime} |
| | | </select> |
| | | <select id="getAvgDataByMIds" resultType="java.util.Map"> |
| | | SELECT AVG(hh.json->"$.e1[0]") as `PM2_5`,AVG(hh.json->"$.e2[0]") as 'PM10',AVG(hh.json->"$.e10[0]") as 'CO', |
| | | AVG(hh.json->"$.e11[0]") as 'SO2',AVG(hh.json->"$.e16[0]") as 'NO2',AVG(hh.json->"$.e15[0]") as 'O3_day' |
| | | from monitor_point mt,device d,history_hourly hh where mt.id=d.monitor_point_id |
| | | and d.mac=hh.mac and mt.id in |
| | | <foreach collection="mIds" item="id" index="index" open="(" close=")" separator=","> |
| | | #{id} |
| | | </foreach> |
| | | and hh.time<![CDATA[<=]]>#{endTime} and hh.time>#{startTime} |
| | | |
| | | </select> |
| | | </mapper> |
| | |
| | | FROM `history_daily` hd,monitor_point mt,device d where mt.id=d.monitor_point_id
|
| | | and d.mac=hd.mac and mt.id=#{mId} and time=#{time}
|
| | | </select>
|
| | |
|
| | | <select id="getDailyAvgDataByMIds" resultType="java.util.Map">
|
| | | SELECT AVG(hd.json->"$.e1[0]") as `PM2_5`,AVG(hd.json->"$.e2[0]") as 'PM10',AVG(hd.json->"$.e10[0]") as 'CO',
|
| | | AVG(hd.json->"$.e11[0]") as 'SO2',AVG(hd.json->"$.e16[0]") as 'NO2',AVG(hd.json->"$.e15[0]") as 'O3_day'
|
| | | FROM `history_daily` hd,monitor_point mt,device d where mt.id=d.monitor_point_id
|
| | | and d.mac=hd.mac and mt.id in
|
| | | <foreach collection="mIds" item="id" index="index" open="(" close=")" separator=",">
|
| | | #{id}
|
| | | </foreach>
|
| | | and time=#{time}
|
| | | </select>
|
| | | </mapper> |