From cd264145f9b4107f1430da46269dd306d26f3116 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Mon, 16 Nov 2020 13:16:30 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- src/main/java/com/moral/service/impl/DeviceAdjustValueTimingServiceImpl.java | 45 + src/main/java/com/moral/service/DeviceAdjustValueTimingService.java | 16 src/main/java/com/moral/service/HistoryMinutelyService.java | 1 src/main/resources/mapper/DeviceMapper.xml | 22 src/main/java/com/moral/entity/DeviceAdjustValueTiming.java | 23 src/main/resources/mapper/DeviceAdjustValueTimingMapper.xml | 39 + src/main/java/com/moral/mapper/HistoryMapper.java | 2 src/main/webapp/img/ico005.png | 0 src/main/webapp/js/newmoralmap.js | 10 src/main/java/com/moral/service/impl/DeviceServiceImpl.java | 542 ++++++++++-------- src/main/java/com/moral/mapper/DeviceAdjustValueTimingMapper.java | 21 src/main/java/com/moral/service/DeviceService.java | 8 src/main/java/com/moral/controller/WebController.java | 64 ++ src/main/java/com/moral/mapper/HistoryHourlyMapper.java | 8 src/main/java/com/moral/mapper/DeviceMapper.java | 13 src/main/java/com/moral/util/AQICalculation2.java | 332 +++++++++++ src/main/resources/mapper/HistoryMapper.xml | 6 src/main/webapp/img/ico006.png | 0 src/main/java/com/moral/service/HistoryHourlyService.java | 2 src/main/resources/mapper/HistoryHourlyMapper.xml | 10 src/main/java/com/moral/controller/ScreenController.java | 181 ++++++ src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java | 141 ++++ src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java | 93 +-- src/main/java/com/moral/service/impl/WeatherServiceImpl.java | 47 + 24 files changed, 1,281 insertions(+), 345 deletions(-) diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java index beb5867..3fde66f 100644 --- a/src/main/java/com/moral/controller/ScreenController.java +++ b/src/main/java/com/moral/controller/ScreenController.java @@ -2,6 +2,7 @@ import java.io.*; import java.lang.reflect.Array; +import java.net.URLEncoder; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseException; @@ -40,6 +41,7 @@ import com.rabbitmq.client.*; import com.rabbitmq.client.Channel; + import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -47,6 +49,7 @@ import io.swagger.models.auth.In; import jdk.nashorn.internal.runtime.regexp.joni.Regex; import net.sf.json.JSONString; + import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.net.ftp.FTPClient; @@ -71,6 +74,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import org.xml.sax.InputSource; + import static com.moral.common.util.ResourceUtil.getValue; import static com.moral.common.util.WebUtils.getParametersStartingWith; import static java.util.Calendar.*; @@ -166,6 +170,9 @@ @Resource private ScreenVersionService screenVersionService; + + @Resource + private DeviceAdjustValueTimingService deviceAdjustValueTimingService; /** * Screen login. ������������ @@ -1079,7 +1086,34 @@ public ResultBean<List<MonitorPoint>> getMonitorPointsAndDevicesByRegion(HttpServletRequest request) throws Exception { Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); + String regionCode = parameters.get("regionCode").toString(); List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsAndDevicesByRegion(parameters); + + //������������������������������ + if (regionCode.startsWith("1309")) { + List<Integer> orgIds = new ArrayList<>(); + Collections.addAll(orgIds, 60, 65, 159, 165, 166); + Iterator<MonitorPoint> iter = monitorPoints.iterator(); + while (iter.hasNext()) { + MonitorPoint next = iter.next(); + Integer mpId = next.getId(); + Integer orgId = next.getOrganizationId(); + if (!orgIds.contains(orgId)) { + iter.remove(); + } else { + if (orgId == 60) { + if (mpId != 56) { + iter.remove(); + } + } else if (orgId == 65) { + if (mpId != 83 && mpId != 84) { + iter.remove(); + } + } + } + } + } + //������������monitorPoint������������������device.getName()������������ for (MonitorPoint monitorPoint : monitorPoints) { List<Device> deviceList = monitorPoint.getDevices(); @@ -2015,7 +2049,7 @@ Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MINUTE, (calendar.get(Calendar.MINUTE) - 2)); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - String time = df.format(calendar.getTime()) + ":00"; + //String time = df.format(calendar.getTime()) + ":00"; int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; String mon; @@ -2025,7 +2059,7 @@ mon = "" + month; } String table = "history_minutely_" + year + mon; - List list = deviceService.byMonitorIdGetDeviceAndWind(monitorPointId, time, table); + List list = deviceService.byMonitorIdGetDeviceAndWind(monitorPointId, table); return list; } @@ -2046,7 +2080,7 @@ mon = "" + month; } String table = "history_minutely_" + year + mon; - List list = deviceService.byMonitorIdGetDeviceAndWindSpecial(monitorPointId, time, table); + List list = deviceService.byMonitorIdGetDeviceAndWindSpecial(monitorPointId, table); return list; } @@ -2170,7 +2204,7 @@ for (Map<String, Object> dataMap : dataList) { JSONObject dataJson = JSONObject.parseObject(dataMap.get("json").toString()); if (dataMap.get("time").toString().equals(day + " 00:00:00.0")) { - oneSensorMap.put(dataMap.get("time").toString().substring(0, 10), dataJson.getJSONArray(key).get(2)); + oneSensorMap.put(dataMap.get("time").toString().substring(0, 10), dataJson.getJSONArray(key).get(0)); break; } else { continue; @@ -2186,7 +2220,7 @@ for (Map sameDayHourlyMap : sameDayHourlyList) { List<Double> arr = new ArrayList<>(); JSONObject hourlyJson = JSONObject.parseObject(sameDayHourlyMap.get("json").toString()); - arr.add(Double.parseDouble(hourlyJson.getJSONArray(key).get(2).toString())); + arr.add(Double.parseDouble(hourlyJson.getJSONArray(key).get(0).toString())); Double sum = 0.0; for (int i = 0; i < arr.size(); i++) { sum += arr.get(i); @@ -2222,8 +2256,10 @@ for (Map<String, Object> hourlyMap : hourlyList) { JSONObject dataJson = JSONObject.parseObject(hourlyMap.get("json").toString()); if (hourlyMap.get("time").toString().equals(hour + ".0")) { - oneSensorMap.put(hourlyMap.get("time").toString().substring(0, 19), dataJson.getJSONArray(key).get(2)); - break; + if (dataJson.getJSONArray(key) != null) { + oneSensorMap.put(hourlyMap.get("time").toString().substring(0, 19), dataJson.getJSONArray(key).get(0)); + break; + } } else { continue; } @@ -2539,8 +2575,135 @@ @ApiImplicitParam(name = "endTime", value = "������������(���������2020-08-04)", required = false, paramType = "query", dataType = "String")}) public ResultBean<List<Map<String, Object>>> getAllDeviceDataToExcel(HttpServletRequest request) throws Exception { Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); - ParameterUtils.getTimeType4Time(parameters); List<Map<String, Object>> list = historyMinutelyService.getAllDeviceDataToExcel(parameters); return new ResultBean<List<Map<String, Object>>>(list); } -} \ No newline at end of file + + /*@PostMapping("insertAdjustValue") + @ApiOperation(value = "���������������������������������", notes = "���������������������������������") + @ApiImplicitParams(value = { + @ApiImplicitParam(name = "id", value = "������id", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "time", value = "���������������08:30:00���", required = true, paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "dataArray", value = "������", required = false, paramType = "query", dataType = "String")}) + public void insertAdjustValue(HttpServletRequest request) throws Exception { + Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); + int device_id = Integer.parseInt(parameters.get("id").toString()); + String hour_minute_second = parameters.get("time").toString(); + String[] arr = hour_minute_second.split(":"); + int seconds = Integer.parseInt(arr[0])*3600+Integer.parseInt(arr[1])*60+Integer.parseInt(arr[2]); + String value = parameters.get("dataArray").toString(); + deviceAdjustValueTimingService.insertData(device_id,seconds,value);; + }*/ + + @PostMapping("insertAdjustValue") + public int insertAdjustValue(@RequestBody HashMap map){ + try{ + int device_id = Integer.parseInt(map.get("id").toString()); + String time = map.get("time").toString(); + String[] arr = time.split(":"); + int seconds = Integer.parseInt(arr[0])*3600+Integer.parseInt(arr[1])*60+Integer.parseInt(arr[2]); + //String t = URLEncoder.encode(������,"UTF-8") + List list = (List) map.get("dataArray"); + String val=""; + for (int i = 0; i <list.size() ; i++) { + if (i==0){ + val=val+list.get(i); + }else { + val=val+","+list.get(i); + } + } + String value = "{"+val+"}"; + deviceAdjustValueTimingService.insertData(device_id,seconds,value); + return 1; + }catch (Exception e){ + log.warn(e); + } + return 0; + } + + @RequestMapping("/biaozhun") + @ResponseBody + public List<Device> queryDevice(String macOrName){ + List<Device> deviceList = new ArrayList<>(); + if (!macOrName.equals("")){ + deviceList= deviceService.getDevice(macOrName); + } + return deviceList; + } + + @RequestMapping("/getBiaoZhun") + @ResponseBody + public List<DeviceAdjustValueTiming> getBiaoZhun(String id){ + List<DeviceAdjustValueTiming> dataByDeviceid = deviceAdjustValueTimingService.getDataByDeviceid(Integer.parseInt(id)); + for (DeviceAdjustValueTiming deviceAdjustValueTiming : dataByDeviceid) { + int seconds = Integer.parseInt(deviceAdjustValueTiming.getSeconds()); + String hour = String.valueOf(seconds/3600); + int millAndSeconds = seconds%3600; + String mill = String.valueOf(millAndSeconds/60); + String second = String.valueOf(millAndSeconds%60); + if (hour.length()<2){ + hour="0"+hour; + } + if (mill.length()<2){ + mill="0"+mill; + } + if (second.length()<2){ + second="0"+second; + } + String time = hour+":"+mill+":"+second; + Map<String, String> value = deviceAdjustValueTiming.getValue(); + Collection<String> values = value.values(); + deviceAdjustValueTiming.setSeconds(time); + } + return dataByDeviceid; + } + + + @RequestMapping("/getSensor") + @ResponseBody + public List<Map<String, Object>> getSensor(String id){ + List<Map<String, Object>> allSensors = sensorService.getSensorByDeviceId(id); + return allSensors; + } + + @RequestMapping("/deleteBiaoZhun") + @ResponseBody + public int deleteBiaoZhun(String id){ + int i= deviceAdjustValueTimingService.delete(id); + return i; + } + + + @GetMapping("/monitorAVGData") + @ApiOperation(value = "monitor������������������", notes = "monitor������������������") + @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 List<List<Map>> monitorAVGData(HttpServletRequest request) throws Exception { + Map<String, Object> parameters = getParametersStartingWith(request, null); + String monitorPointIds = (String) parameters.get("monitorPointIds"); + String time = (String) parameters.get("time"); + time = time+" 00:00:00"; + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd mm:HH:ss");//���������������MM + Date date = simpleDateFormat.parse(time); + Calendar calendar = new GregorianCalendar(); + calendar.setTime(date); + calendar.add(calendar.DATE,+1); + String date1= simpleDateFormat.format(date); + String date2= simpleDateFormat.format(calendar.getTime()); + String[] mIds = monitorPointIds.split(","); + List<List<Map>> lists = new ArrayList<>(); + if (mIds.length==1 && mIds.length!=0){ + String mId = mIds[0]; + List<Map> dataAvbByMIdAndTime = historyHourlyService.getDataAvbByMIdAndTime(mId, date1, date2); + 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); + lists.add(dataAvbByMIdAndTime); + } + } + return lists; + } +} diff --git a/src/main/java/com/moral/controller/WebController.java b/src/main/java/com/moral/controller/WebController.java index 2bd5e3c..f88d02e 100644 --- a/src/main/java/com/moral/controller/WebController.java +++ b/src/main/java/com/moral/controller/WebController.java @@ -305,6 +305,70 @@ return new ResultBean<Map<String,Object>>(datasMap); } + @GetMapping("cangzhouMIdGetAllDevice") + public ResultBean<Map<String,Object>> cangzhouMIdGetAllDevice(HttpServletRequest request) { + //���������������������������monitorpointId + Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); + if ((!parameters.containsKey("sensorKey")) || (!parameters.containsKey("monitorPointId"))) + return ResultBean.fail("���������null"); + String sensorKey = (String) parameters.get("sensorKey"); + Integer monitorPointId = Integer.parseInt((String) parameters.get("monitorPointId")); + MonitorPoint mPoint = monitorPointService.queryMonitorPointById(monitorPointId); + Integer code = mPoint.getCityCode(); + List<Device> devices = null; + if (code == 130900){ + devices = deviceService.getDeviceByCode(); + }else { + devices = deviceService.getDevicesByMonitorPointId(monitorPointId); + } + //������monitorpointId������������������������������mac������ + if (ObjectUtils.isEmpty(devices)) + return ResultBean.fail("���������������������monitorPointId������"); + List<String> macs = new ArrayList<>(); + devices.forEach(p -> { + macs.add(p.getMac()); + }); + + //���������������mac��������������������������������������������������������� + Map<String, Object> timeAndYearMonth = getTimeAndYearMonthForFiveMinuteData(); + String time = (String) timeAndYearMonth.get("time"); + String yearAndMonth = (String) timeAndYearMonth.get("yearAndMonth"); + parameters.put("time", time); + parameters.put("yearAndMonth", yearAndMonth); + parameters.put("macs", macs); + List<Map<String, Object>> datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + + //������������������������������������������������������������������������������ + if (ObjectUtils.isEmpty(datas)) { + time = getFiveMinuteAgoTime(time); + parameters.put("time", time); + datas = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTime(parameters); + } + datas = insertDeviceInfo(datas, devices); + + //������monitorPointId��������������������� + List<Map<String,Object>> coordinate = new ArrayList<>(); + MonitorPoint monitorPoint = monitorPointService.queryMonitorPointById(monitorPointId); + Integer orgId = monitorPoint.getOrganizationId(); + List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(orgId); + monitorPoints.forEach(value->{ + if("���������".equals(value.getDescription())) { + List list = LatLngTransformation.Convert_BD09_To_GCJ02(value.getLatitude(), value.getLongitude()); + Map<String,Object> controlStation = new HashMap<>(); + controlStation.put("name",value.getName()); + controlStation.put("longitude", list.get(0)); + controlStation.put("latitude", list.get(1)); + coordinate.add(controlStation); + } + }); + + Map<String,Object> datasMap = new HashMap<>(); + datasMap.put("coordinate",coordinate); + datasMap.put("device",datas); + + return new ResultBean<Map<String,Object>>(datasMap); + } + /** * @Description: ������mac��������������������������������������������������������������������������������� * @Param: [request] diff --git a/src/main/java/com/moral/entity/DeviceAdjustValueTiming.java b/src/main/java/com/moral/entity/DeviceAdjustValueTiming.java new file mode 100644 index 0000000..6580d46 --- /dev/null +++ b/src/main/java/com/moral/entity/DeviceAdjustValueTiming.java @@ -0,0 +1,23 @@ +package com.moral.entity; + +import lombok.Data; + +import javax.persistence.Id; +import java.util.Date; +import java.util.Map; + +@Data +public class DeviceAdjustValueTiming { + @Id + private Integer id; + + private Integer deviceId; + + private String seconds; + + private Map<String,String> value; + + private Date createTime; + + private Date updateTime; +} \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/DeviceAdjustValueTimingMapper.java b/src/main/java/com/moral/mapper/DeviceAdjustValueTimingMapper.java new file mode 100644 index 0000000..9113f78 --- /dev/null +++ b/src/main/java/com/moral/mapper/DeviceAdjustValueTimingMapper.java @@ -0,0 +1,21 @@ +package com.moral.mapper; + + +import com.moral.common.mapper.BaseMapper; +import com.moral.entity.DeviceAdjustValueTiming; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +public interface DeviceAdjustValueTimingMapper{ + List<DeviceAdjustValueTiming> selectAllByDeviceid(@Param("device_id")Integer device_id); + + Map<String, Object> selectAllByDeviceidAndSeconds(@Param("device_id")Integer device_id,@Param("seconds")Integer seconds); + + void insertData(@Param("device_id")Integer device_id,@Param("seconds")Integer seconds,@Param("value")String value,@Param("create_time")String create_time); + + void upDataByDeviceid(@Param("value")String value,@Param("update_time")String update_time,@Param("device_id")Integer device_id); + + int delete(@Param("id")String id); +} \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/DeviceMapper.java b/src/main/java/com/moral/mapper/DeviceMapper.java index 00b8fbc..a30d2e1 100644 --- a/src/main/java/com/moral/mapper/DeviceMapper.java +++ b/src/main/java/com/moral/mapper/DeviceMapper.java @@ -71,12 +71,12 @@ Device byMacGetDevice(@Param("mac") String mac); - DeviceAndWind getDeviceAndWindByMac(@Param("mac") String mac, @Param("time") String time, + DeviceAndWind getDeviceAndWindByMac(@Param("mac") String mac, @Param("table") String table); - List<DeviceAndWind> byMonitorIdGetDeviceAndWind(@Param("id") int id, @Param("time") String time, @Param("table") String table); + List<DeviceAndWind> byMonitorIdGetDeviceAndWind(@Param("id") int id, @Param("table") String table); - DeviceAndWind byMacGetDeviceAndWind(@Param("mac") String mac, @Param("time") String time, @Param("table") String table); + DeviceAndWind byMacGetDeviceAndWind(@Param("mac") String mac, @Param("table") String table); List<String> getMacsByMonitorPointIds(List<Integer> list); @@ -89,4 +89,11 @@ List<Map<String, Object>> getDevicesByMpId(int mpId); String byMacGetOrgId(String mac); + + List<Device> getDevice(String macOrName); + + + List<Device> getDeviceByCityCode(); + + } \ No newline at end of file diff --git a/src/main/java/com/moral/mapper/HistoryHourlyMapper.java b/src/main/java/com/moral/mapper/HistoryHourlyMapper.java index a7f3c4c..b81c969 100644 --- a/src/main/java/com/moral/mapper/HistoryHourlyMapper.java +++ b/src/main/java/com/moral/mapper/HistoryHourlyMapper.java @@ -30,4 +30,12 @@ @Param("sensor") String sensor, @Param("startTime") String startTime, @Param("endTime") String endTime); + List<Map> getDataByMacAndTime1(@Param("mac") String mac, + @Param("sensor") String sensor, + @Param("startTime") String startTime, + @Param("endTime") String endTime); + + List<Map<String,Object>> getDataAvbByMIdAndTime( @Param("mId")String mId, + @Param("startTime")String startTime, + @Param("endTime")String endTime); } diff --git a/src/main/java/com/moral/mapper/HistoryMapper.java b/src/main/java/com/moral/mapper/HistoryMapper.java index 5ab081a..74c339e 100644 --- a/src/main/java/com/moral/mapper/HistoryMapper.java +++ b/src/main/java/com/moral/mapper/HistoryMapper.java @@ -43,4 +43,6 @@ String getJsonData(@Param("mac") String mac, @Param("time") String time, @Param("table") String table); + + Map<String,Object> getDailyAvgData(@Param("mId")String mId,@Param("time")String time); } \ No newline at end of file diff --git a/src/main/java/com/moral/service/DeviceAdjustValueTimingService.java b/src/main/java/com/moral/service/DeviceAdjustValueTimingService.java new file mode 100644 index 0000000..7bba4a3 --- /dev/null +++ b/src/main/java/com/moral/service/DeviceAdjustValueTimingService.java @@ -0,0 +1,16 @@ +package com.moral.service; + +import com.moral.common.bean.PageBean; +import com.moral.entity.DeviceAdjustValue; +import com.moral.entity.DeviceAdjustValueTiming; + +import java.util.List; +import java.util.Map; + +public interface DeviceAdjustValueTimingService { + List<DeviceAdjustValueTiming> getDataByDeviceid(Integer device_id); + + void insertData(int device_id,int seconds,String value); + + int delete(String id); +} diff --git a/src/main/java/com/moral/service/DeviceService.java b/src/main/java/com/moral/service/DeviceService.java index ca06f17..0789f53 100644 --- a/src/main/java/com/moral/service/DeviceService.java +++ b/src/main/java/com/moral/service/DeviceService.java @@ -80,10 +80,14 @@ Device byMacGetDevice(String mac); - List<DeviceAndWind> byMonitorIdGetDeviceAndWind(String id,String time,String tab); - List<DeviceAndWind> byMonitorIdGetDeviceAndWindSpecial(String id,String time,String tab); + List<DeviceAndWind> byMonitorIdGetDeviceAndWind(String id,String tab); + List<DeviceAndWind> byMonitorIdGetDeviceAndWindSpecial(String id,String tab); List<Device> getDeviceByCodeAndId(String code,String id); String byMacGetOrgId(String mac); + //������mac������������������������������������ + List<Device> getDevice(String macOrName); + + List<Device> getDeviceByCode(); } diff --git a/src/main/java/com/moral/service/HistoryHourlyService.java b/src/main/java/com/moral/service/HistoryHourlyService.java index ded5838..0e99fea 100644 --- a/src/main/java/com/moral/service/HistoryHourlyService.java +++ b/src/main/java/com/moral/service/HistoryHourlyService.java @@ -26,4 +26,6 @@ List<Map<String, Object>> getDataByTimeSlot(String mac, String startTime, String endTime) throws Exception; List<Map> getDataByMacAndTime(Map param); + + List<Map> getDataAvbByMIdAndTime(String mId,String startTime,String endTime); } diff --git a/src/main/java/com/moral/service/HistoryMinutelyService.java b/src/main/java/com/moral/service/HistoryMinutelyService.java index fe65a54..35be96b 100644 --- a/src/main/java/com/moral/service/HistoryMinutelyService.java +++ b/src/main/java/com/moral/service/HistoryMinutelyService.java @@ -38,7 +38,6 @@ List<Map<String, Object>> getMultiDeviceSensorData(Map<String, Object> parameters) throws Exception; - List<Map<String, Object>> getAllDeviceDataToExcel(Map<String, Object> parameters) throws Exception; } diff --git a/src/main/java/com/moral/service/impl/DeviceAdjustValueTimingServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceAdjustValueTimingServiceImpl.java new file mode 100644 index 0000000..0573bb1 --- /dev/null +++ b/src/main/java/com/moral/service/impl/DeviceAdjustValueTimingServiceImpl.java @@ -0,0 +1,45 @@ +package com.moral.service.impl; + +import com.moral.entity.DeviceAdjustValueTiming; +import com.moral.mapper.DeviceAdjustValueTimingMapper; +import com.moral.service.DeviceAdjustValueTimingService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Map; +@Service +public class DeviceAdjustValueTimingServiceImpl implements DeviceAdjustValueTimingService { + + @Resource + private DeviceAdjustValueTimingMapper deviceAdjustValueTimingMapper; + + @Override + public List<DeviceAdjustValueTiming> getDataByDeviceid(Integer device_id) { + List<DeviceAdjustValueTiming> result = deviceAdjustValueTimingMapper.selectAllByDeviceid(device_id); + return result; + } + + @Override + public void insertData(int device_id, int seconds, String value) { + //������������������������������������ + DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime time = LocalDateTime.now(); + String nowTime = df.format(time); + //���������device_id������������������������������������������������������������������������ + Map<String,Object> deviceAdjustValueTimingMap = deviceAdjustValueTimingMapper.selectAllByDeviceidAndSeconds(device_id,seconds); + //��������������������������������������������������������������������������������� + if (deviceAdjustValueTimingMap == null){ + deviceAdjustValueTimingMapper.insertData(device_id,seconds,value,nowTime); + }else { + deviceAdjustValueTimingMapper.upDataByDeviceid(value,nowTime,device_id); + } + } + + @Override + public int delete(String id) { + return deviceAdjustValueTimingMapper.delete(id); + } +} diff --git a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java index 6fbd69f..03df587 100644 --- a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java @@ -29,6 +29,7 @@ import com.moral.mapper.OrganizationMapper; import com.moral.service.AccountService; import com.moral.service.DeviceService; +import com.moral.service.MonitorPointService; import com.moral.util.LatLngTransformation; import com.moral.util.TkMybatisUtils; @@ -39,6 +40,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; + import tk.mybatis.mapper.entity.Example; @Service @@ -78,6 +80,8 @@ OrganizationMapper organizationMapper; @Resource DictionaryDataMapper dictionaryDataMapper; + @Resource + private MonitorPointService monitorPointService ; @Override public Map<String, Object> getDeviceStatesByAccount(Map<String, Object> parameters) { @@ -207,13 +211,39 @@ public List<Device> query(Map<String, Object> params) { List<Integer> dv = deviceMapper.getHasWindDirAndWindSpeedDeviceVersion(); Object orgIdObj = params.get("orgId"); + String regionCode = params.get("regionCode").toString(); List<Device> deviceList = null; if (orgIdObj != null) { Integer orgId = Integer.parseInt(orgIdObj.toString()); List<Integer> orgIds = orgMapper.selectLowerOrgIds(orgId); - params.put("orgIds", orgIds); - System.out.println(params); - deviceList = deviceMapper.selectByMap(params); + //��������������������������������������������� + if (regionCode.startsWith("1309")&&orgIdObj.toString().equals("5")) { + orgIds = new ArrayList<>(); + Collections.addAll(orgIds, 60, 65, 159, 165, 166); + deviceList = deviceMapper.selectByMap(params); + Iterator<Device> iter = deviceList.iterator(); + while (iter.hasNext()) { + Device device = iter.next(); + Integer mpId = device.getMonitorPointId(); + Integer oid = monitorPointService.byIdGetMonitorPoint(mpId).getOrganizationId(); + if (!orgIds.contains(oid)) { + iter.remove(); + } else { + if (orgId == 60) { + if (mpId != 56) { + iter.remove(); + } + } else if (orgId == 65) { + if (mpId != 83 && mpId != 84) { + iter.remove(); + } + } + } + } + }else { + params.put("orgIds", orgIds); + deviceList = deviceMapper.selectByMap(params); + } // loadDeviceState(deviceList); } Example deviceExample = new Example(Device.class);//��������� @@ -688,7 +718,7 @@ params.put("orgIds", orgIds); deviceList = deviceMapper.selectDevicesAll(params); } - List<Device> deviceListHasWind=new ArrayList<>(); + List<Device> deviceListHasWind = new ArrayList<>(); for (Device d : deviceList) { if (dv.contains(d.getDeviceVersionId())) { deviceListHasWind.add(d); @@ -719,49 +749,49 @@ } @Override - public List byMonitorIdGetDeviceAndWind(String id,String time,String tab) { - List<DeviceAndWind> deviceAndWinds=deviceMapper.byMonitorIdGetDeviceAndWind(Integer.parseInt(id),time,tab); - List loList=new ArrayList(); - List laList=new ArrayList(); - Double U=0.0; - Double V=0.0; - List list=new ArrayList(); + public List byMonitorIdGetDeviceAndWind(String id, String tab) { + List<DeviceAndWind> deviceAndWinds = deviceMapper.byMonitorIdGetDeviceAndWind(Integer.parseInt(id), tab); + List loList = new ArrayList(); + List laList = new ArrayList(); + Double U = 0.0; + Double V = 0.0; + List list = new ArrayList(); for (DeviceAndWind andWind : deviceAndWinds) { - Double lo=andWind.getLongitude(); - Double la=andWind.getLatitude(); - List tranlist= LatLngTransformation.Convert_BD09_To_GCJ02(la,lo); - Double transLo=(Double) tranlist.get(0); - Double transLa=(Double) tranlist.get(1); + Double lo = andWind.getLongitude(); + Double la = andWind.getLatitude(); + List tranlist = LatLngTransformation.Convert_BD09_To_GCJ02(la, lo); + Double transLo = (Double) tranlist.get(0); + Double transLa = (Double) tranlist.get(1); loList.add(transLo); laList.add(transLa); } - Double loma= 0.0; - Double lomi= 0.0; - Double lama= 0.0; - Double lami= 0.0; - if (loList.size()>0){ - loma= (Double) Collections.max(loList); - lomi= (Double) Collections.min(loList); + Double loma = 0.0; + Double lomi = 0.0; + Double lama = 0.0; + Double lami = 0.0; + if (loList.size() > 0) { + loma = (Double) Collections.max(loList); + lomi = (Double) Collections.min(loList); } - if (laList.size()>0){ - lama= (Double) Collections.max(laList); - lami= (Double) Collections.min(laList); + if (laList.size() > 0) { + lama = (Double) Collections.max(laList); + lami = (Double) Collections.min(laList); } - Map laLaMap=new HashMap(); - laLaMap.put("maxLo",loma); - laLaMap.put("minLo",lomi); - laLaMap.put("maxLa",lama); - laLaMap.put("minLa",lami); + Map laLaMap = new HashMap(); + laLaMap.put("maxLo", loma); + laLaMap.put("minLo", lomi); + laLaMap.put("maxLa", lama); + laLaMap.put("minLa", lami); - Double lo1=lomi-250*0.00001141; - Double lo2=loma+250*0.00001141; - Double la2=lami-250*0.00000899; - Double la1=lama+250*0.00000899; + Double lo1 = lomi - 250 * 0.00001141; + Double lo2 = loma + 250 * 0.00001141; + Double la2 = lami - 250 * 0.00000899; + Double la1 = lama + 250 * 0.00000899; - Double dx=0.00001141*20; - Double dy=0.00000899*20; - int nx=(int) Math.floor((lo2-lo1)/dx); - int ny=(int) Math.floor((la1-la2)/dy); + Double dx = 0.00001141 * 20; + Double dy = 0.00000899 * 20; + int nx = (int) Math.floor((lo2 - lo1) / dx); + int ny = (int) Math.floor((la1 - la2) / dy); String header1 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 2 + ", " + "\"" + "dx" + "\"" + ": " + dx + ", " + "\"" + "dy" + "\"" + ": " + dy + ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + la1 + ", " + "\"" + "la2" + "\"" + ": " + la2 + @@ -774,86 +804,86 @@ ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + lo1 + ", " + "\"" + "lo2" + "\"" + ": " + lo2 + ", " + "\"" + "nx" + "\"" + ": " + nx + ", " + "\"" + "ny" + "\"" + ": " + ny + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; - List<Double> uList=new ArrayList<Double> (); - List<Double> vList=new ArrayList<Double> (); - int x=0; - int y=0; - List<Map> mapList=new ArrayList<Map>(); + List<Double> uList = new ArrayList<Double>(); + List<Double> vList = new ArrayList<Double>(); + int x = 0; + int y = 0; + List<Map> mapList = new ArrayList<Map>(); - for (int j = 0; j <deviceAndWinds.size() ; j++) { - Map<String,Double> map=new HashMap<String,Double> (); - Double windDir= deviceAndWinds.get(j).getWindDir(); + for (int j = 0; j < deviceAndWinds.size(); j++) { + Map<String, Double> map = new HashMap<String, Double>(); + Double windDir = deviceAndWinds.get(j).getWindDir(); - Double windSpeed=deviceAndWinds.get(j).getWindSpeed(); - if (windDir==null){ - windDir=0.0; - windSpeed=0.0; + Double windSpeed = deviceAndWinds.get(j).getWindSpeed(); + if (windDir == null) { + windDir = 0.0; + windSpeed = 0.0; } - Double tvoc=deviceAndWinds.get(j).getTVoc(); + Double tvoc = deviceAndWinds.get(j).getTVoc(); - List tranlist= LatLngTransformation.Convert_BD09_To_GCJ02(deviceAndWinds.get(j).getLatitude(),deviceAndWinds.get(j).getLongitude()); - Double transLo=(Double) tranlist.get(0); - Double transLa=(Double) tranlist.get(1); - if (tvoc==null){ - tvoc=0.0; + List tranlist = LatLngTransformation.Convert_BD09_To_GCJ02(deviceAndWinds.get(j).getLatitude(), deviceAndWinds.get(j).getLongitude()); + Double transLo = (Double) tranlist.get(0); + Double transLa = (Double) tranlist.get(1); + if (tvoc == null) { + tvoc = 0.0; } Double dir = (270.0 - windDir * Math.PI / 180.0); U = windSpeed * Math.cos(dir); V = windSpeed * Math.sin(dir); - map.put("lo",transLo); - map.put("la",transLa); - map.put("U",U); - map.put("V",V); + map.put("lo", transLo); + map.put("la", transLa); + map.put("U", U); + map.put("V", V); mapList.add(map); } - 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)); + 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)); //y=Math.floor(Math.abs(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++) { + 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); } } - for (int j = 0; j <nx*ny ; j++) { - if (i==0){ - if ((y>=2 && j==(y)*nx+x)){ + 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); + 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){ + } 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; + 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); + uList.set(j, U); + vList.set(j, V); } } } @@ -862,12 +892,12 @@ String vData = "\"" + "data" + "\"" + ": " + vList; String s1 = "[" + "{" + header1 + ", " + uData + "}" + ", " + "{" + header2 + ", " + vData + "}" + "]"; JSONArray jsonArray = JSONArray.parseArray(s1); - MonitorPoint monitorPoint=monitorPointMapper.byIdGetMonitorPoint(Integer.parseInt(id)); - Double monitorLo=monitorPoint.getLongitude(); - Double monitorLa=monitorPoint.getLatitude(); - List transList= LatLngTransformation.Convert_BD09_To_GCJ02(monitorLa,monitorLo); - Double transLo=(Double) transList.get(0); - Double transLa=(Double) transList.get(1); + MonitorPoint monitorPoint = monitorPointMapper.byIdGetMonitorPoint(Integer.parseInt(id)); + Double monitorLo = monitorPoint.getLongitude(); + Double monitorLa = monitorPoint.getLatitude(); + List transList = LatLngTransformation.Convert_BD09_To_GCJ02(monitorLa, monitorLo); + Double transLo = (Double) transList.get(0); + Double transLa = (Double) transList.get(1); list.add(jsonArray); list.add(transLo); list.add(transLa); @@ -876,95 +906,95 @@ } @Override - public List byMonitorIdGetDeviceAndWindSpecial(String id, String time, String tab) { - MonitorPoint monitorPoint=monitorPointMapper.byIdGetMonitorPoint(Integer.parseInt(id)); - Integer areaCode=monitorPoint.getAreaCode(); - String townCode= monitorPoint.getTownCode()+""; - int monitorPointId=monitorPoint.getId(); - Map<String, Object> parm=new HashMap<>(); - List<DeviceAndWind> deviceAndWinds=new ArrayList<>(); - Double loma= 0.0; - Double lomi= 0.0; - Double lama= 0.0; - Double lami= 0.0; + public List byMonitorIdGetDeviceAndWindSpecial(String id, String tab) { + MonitorPoint monitorPoint = monitorPointMapper.byIdGetMonitorPoint(Integer.parseInt(id)); + Integer areaCode = monitorPoint.getAreaCode(); + String townCode = monitorPoint.getTownCode() + ""; + int monitorPointId = monitorPoint.getId(); + Map<String, Object> parm = new HashMap<>(); + List<DeviceAndWind> deviceAndWinds = new ArrayList<>(); + Double loma = 0.0; + Double lomi = 0.0; + Double lama = 0.0; + Double lami = 0.0; - int length=1; - int perdlen=1; - if (areaCode==320581){ - parm.put("areaCode",areaCode); - List<Device> deviceList=deviceMapper.getDeviceByCode(parm); + int length = 1; + int perdlen = 1; + if (areaCode == 320581) { + parm.put("areaCode", areaCode); + List<Device> deviceList = deviceMapper.getDeviceByCode(parm); for (Device d : deviceList) { - String mac=d.getMac(); - DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac,time,tab); - if (deviceAndWind!=null){ - deviceAndWinds.add(deviceAndWind); - } - } - length=8000; - perdlen=2200; - }else if ((areaCode == 320583) && (townCode.equals("320583108000"))){ - parm.put("townCode",townCode); - List<Device> deviceList=deviceMapper.getDeviceByCode(parm); - for (Device d : deviceList) { - String mac=d.getMac(); - DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac,time,tab); - if (deviceAndWind!=null){ + String mac = d.getMac(); + DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac, tab); + if (deviceAndWind != null) { deviceAndWinds.add(deviceAndWind); } } - length=2000; - perdlen=280; - }else if(monitorPointId==35){ - DeviceAndWind deviceAndWind=deviceMapper.getDeviceAndWindByMac("898607b0101730392253",time,tab); - DeviceAndWind deviceAndWind1=deviceMapper.getDeviceAndWindByMac("p5dnd7a0392083",time,tab); - deviceAndWinds.add(deviceAndWind); - deviceAndWinds.add(deviceAndWind1); - length=2000; - perdlen=50; + length = 8000; + perdlen = 2200; + } else if ((areaCode == 320583) && (townCode.equals("320583108000"))) { + parm.put("townCode", townCode); + List<Device> deviceList = deviceMapper.getDeviceByCode(parm); + for (Device d : deviceList) { + String mac = d.getMac(); + DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac, tab); + if (deviceAndWind != null) { + deviceAndWinds.add(deviceAndWind); + } + } + length = 2000; + perdlen = 280; + } else if (monitorPointId == 35) { + DeviceAndWind deviceAndWind = deviceMapper.getDeviceAndWindByMac("898607b0101730392253", tab); + DeviceAndWind deviceAndWind1 = deviceMapper.getDeviceAndWindByMac("p5dnd7a0392083", tab); + deviceAndWinds.add(deviceAndWind); + deviceAndWinds.add(deviceAndWind1); + length = 2000; + perdlen = 50; - }else { - deviceAndWinds=deviceMapper.byMonitorIdGetDeviceAndWind(Integer.parseInt(id),time,tab); - length=2000; - perdlen=80; + } else { + deviceAndWinds = deviceMapper.byMonitorIdGetDeviceAndWind(Integer.parseInt(id), tab); + length = 2000; + perdlen = 80; } - List loList=new ArrayList(); - List laList=new ArrayList(); - Double U=0.0; - Double V=0.0; - List list=new ArrayList(); + List loList = new ArrayList(); + List laList = new ArrayList(); + Double U = 0.0; + Double V = 0.0; + List list = new ArrayList(); for (DeviceAndWind andWind : deviceAndWinds) { - Double lo=andWind.getLongitude(); - Double la=andWind.getLatitude(); - List tranlist= LatLngTransformation.Convert_BD09_To_GCJ02(la,lo); - Double transLo=(Double) tranlist.get(0); - Double transLa=(Double) tranlist.get(1); - loList.add(transLo); - laList.add(transLa); + Double lo = andWind.getLongitude(); + Double la = andWind.getLatitude(); + List tranlist = LatLngTransformation.Convert_BD09_To_GCJ02(la, lo); + Double transLo = (Double) tranlist.get(0); + Double transLa = (Double) tranlist.get(1); + loList.add(transLo); + laList.add(transLa); } - if (loList.size()>0){ - loma= (Double) Collections.max(loList); - lomi= (Double) Collections.min(loList); + if (loList.size() > 0) { + loma = (Double) Collections.max(loList); + lomi = (Double) Collections.min(loList); } - if (laList.size()>0){ - lama= (Double) Collections.max(laList); - lami= (Double) Collections.min(laList); + if (laList.size() > 0) { + lama = (Double) Collections.max(laList); + lami = (Double) Collections.min(laList); } - Map laLaMap=new HashMap(); - laLaMap.put("maxLo",loma); - laLaMap.put("minLo",lomi); - laLaMap.put("maxLa",lama); - laLaMap.put("minLa",lami); + Map laLaMap = new HashMap(); + laLaMap.put("maxLo", loma); + laLaMap.put("minLo", lomi); + laLaMap.put("maxLa", lama); + laLaMap.put("minLa", lami); - 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 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); + 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); String header1 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 2 + ", " + "\"" + "dx" + "\"" + ": " + dx + ", " + "\"" + "dy" + "\"" + ": " + dy + ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + la1 + ", " + "\"" + "la2" + "\"" + ": " + la2 + @@ -974,88 +1004,88 @@ String header2 = "\"" + "header" + "\"" + ": " + "{" + "\"" + "parameterUnit" + "\"" + ": " + "\"" + "m/s" + "\"" + ", " + "\"" + "parameterNumber" + "\"" + ": " + 3 + ", " + "\"" + "dx" + "\"" + ": " + dx + ", " + "\"" + "dy" + "\"" + ": " + dy + ", " + "\"" + "parameterNumberName" + "\"" + ": " + "\"" + "eastward_wind" + "\"" + ", " + "\"" + "la1" + "\"" + ": " + la1 + ", " + "\"" + "la2" + "\"" + ": " + la2 + - ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + lo1 + ", " + "\"" + "lo2" + "\"" + ": " + lo2 + + ", " + "\"" + "parameterCategory" + "\"" + ": " + 2 + ", " + "\"" + "lo1" + "\"" + ": " + lo1 + ", " + "\"" + "lo2" + "\"" + ": " + lo2 + ", " + "\"" + "nx" + "\"" + ": " + nx + ", " + "\"" + "ny" + "\"" + ": " + ny + ", " + "\"" + "refTime" + "\"" + ": " + "\"" + "2020-07-22 23:00:00" + "\"" + "}"; - List<Double> uList=new ArrayList<Double> (); - List<Double> vList=new ArrayList<Double> (); - int x=0; - int y=0; - List<Map> mapList=new ArrayList<Map>(); + List<Double> uList = new ArrayList<Double>(); + List<Double> vList = new ArrayList<Double>(); + int x = 0; + int y = 0; + List<Map> mapList = new ArrayList<Map>(); - for (int j = 0; j <deviceAndWinds.size() ; j++) { - Map<String,Double> map=new HashMap<String,Double> (); - Double windDir= deviceAndWinds.get(j).getWindDir(); - Double windSpeed=deviceAndWinds.get(j).getWindSpeed(); - if (windDir==null){ - windDir=0.0; - windSpeed=0.0; - } - Double tvoc=deviceAndWinds.get(j).getTVoc(); + for (int j = 0; j < deviceAndWinds.size(); j++) { + Map<String, Double> map = new HashMap<String, Double>(); + Double windDir = deviceAndWinds.get(j).getWindDir(); + Double windSpeed = deviceAndWinds.get(j).getWindSpeed(); + if (windDir == null) { + windDir = 0.0; + windSpeed = 0.0; + } + Double tvoc = deviceAndWinds.get(j).getTVoc(); - List tranlist= LatLngTransformation.Convert_BD09_To_GCJ02(deviceAndWinds.get(j).getLatitude(),deviceAndWinds.get(j).getLongitude()); - Double transLo=(Double) tranlist.get(0); - Double transLa=(Double) tranlist.get(1); - if (tvoc==null){ - tvoc=0.0; - } - Double dir = (270.0 + windDir * Math.PI / 180.0); + List tranlist = LatLngTransformation.Convert_BD09_To_GCJ02(deviceAndWinds.get(j).getLatitude(), deviceAndWinds.get(j).getLongitude()); + Double transLo = (Double) tranlist.get(0); + Double transLa = (Double) tranlist.get(1); + if (tvoc == null) { + tvoc = 0.0; + } + Double dir = (270.0 - windDir * Math.PI / 180.0); - U = windSpeed * Math.cos(dir); - V = windSpeed * Math.sin(dir); - map.put("lo",transLo); - map.put("la",transLa); - map.put("U",U); - map.put("V",V); - mapList.add(map); + U = windSpeed * Math.cos(dir); + V = windSpeed * Math.sin(dir); + map.put("lo", transLo); + map.put("la", transLa); + map.put("U", U); + map.put("V", V); + mapList.add(map); } - 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)); + 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)); //y=Math.floor(Math.abs(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++) { + 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); } } - for (int j = 0; j <nx*ny ; j++) { - if (i==0){ - if ((y>=2 && j==(y)*nx+x)){ + 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); + 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){ + } 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; + 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); + uList.set(j, U); + vList.set(j, V); } } } @@ -1065,11 +1095,11 @@ String s1 = "[" + "{" + header1 + ", " + uData + "}" + ", " + "{" + header2 + ", " + vData + "}" + "]"; JSONArray jsonArray = JSONArray.parseArray(s1); - Double monitorLo=monitorPoint.getLongitude(); - Double monitorLa=monitorPoint.getLatitude(); - List transList= LatLngTransformation.Convert_BD09_To_GCJ02(monitorLa,monitorLo); - Double transLo=(Double) transList.get(0); - Double transLa=(Double) transList.get(1); + Double monitorLo = monitorPoint.getLongitude(); + Double monitorLa = monitorPoint.getLatitude(); + List transList = LatLngTransformation.Convert_BD09_To_GCJ02(monitorLa, monitorLo); + Double transLo = (Double) transList.get(0); + Double transLa = (Double) transList.get(1); list.add(jsonArray); list.add(transLo); @@ -1080,7 +1110,7 @@ @Override public List<Device> getDeviceByCodeAndId(String code, String id) { - return deviceMapper.getDeviceByCodeAndId(code,id); + return deviceMapper.getDeviceByCodeAndId(code, id); } @Override @@ -1088,4 +1118,14 @@ return deviceMapper.byMacGetOrgId(mac); } + @Override + public List<Device> getDevice(String macOrName) { + return deviceMapper.getDevice(macOrName); + } + + @Override + public List<Device> getDeviceByCode() { + return deviceMapper.getDeviceByCityCode(); + } + } diff --git a/src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java index 45ae468..d6942ce 100644 --- a/src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java +++ b/src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java @@ -1,10 +1,16 @@ package com.moral.service.impl; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +import com.moral.entity.MachineActivate; +import com.moral.mapper.HistoryMapper; +import com.moral.util.AQICalculation; +import com.moral.util.AQICalculation2; +import io.swagger.models.auth.In; import org.apache.commons.collections.MapUtils; import org.springframework.stereotype.Service; @@ -23,6 +29,9 @@ public class HistoryHourlyServiceImpl implements HistoryHourlyService { @Resource private HistoryHourlyMapper historyHourlyMapper; + + @Resource + private HistoryMapper historyMapper; @Resource private DeviceService deviceService; @@ -146,7 +155,6 @@ String date2 = simpleDateFormat.format(date1); List<Map> list = historyHourlyMapper.getDataByMacAndTime(mac, sensor, perTime, date2); List<Map> newList = new ArrayList<Map>(); - //System.out.println(list); for (int i = 0; i < 24; i++) { Map map=new HashMap(); if (i < 10) { @@ -159,7 +167,6 @@ newList.add(map); } } - //System.out.println(newList); if (list.size() <= 24 && list.size() >= 0) { for (int i = 0; i <list.size() ; i++) { String timeS = list.get(i).get("time").toString().substring(11, 13); @@ -216,6 +223,136 @@ } @Override + public List<Map> getDataAvbByMIdAndTime(String mId, String startTime, String endTime) { + List<Device> devicesByMonitorPointId = deviceService.getDevicesByMonitorPointId(Integer.valueOf(mId)); + List<List> lists = new ArrayList<>(); + List<List<Map<String,String>>> listArrayList = new ArrayList<>(); + List<Map<String, Object>> dataAvbByMIdAndTime = historyHourlyMapper.getDataAvbByMIdAndTime(mId, startTime, endTime); + List<Map> mapList = new ArrayList<>(); + for (Map<String, Object> stringStringMap : dataAvbByMIdAndTime) { + Map<String,String> map = new HashMap(); + String s = stringStringMap.get("O3").toString(); + Object time = stringStringMap.get("time"); + map.put("O3",s); + map.put("time",time.toString()); + mapList.add(map); + } + 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 <dataAvbByMIdAndTime.size() ; i++) { + dataAvbByMIdAndTime.get(i).put("O3-8h",null); + 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()); + } + } + } + } + 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); + } + 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 { + 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){ + 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"); + timeAndDate.put("time",time); + timeAndDate.put("data",dataAvbByMIdAndTime.get(i)); + finalList.add(timeAndDate); + } + } + return finalList; + } + + @Override public Point getDirPoint(Map<String, Object> parameters) throws Exception { Map<String, Object> pollutionSourceData = getPollutionSourceDataByHour(parameters); if (MapUtils.isEmpty(pollutionSourceData)) { diff --git a/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java index b3056f9..66aed92 100644 --- a/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java +++ b/src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java @@ -1001,6 +1001,8 @@ @Override public List<Map<String, Object>> getAllDeviceDataToExcel(Map<String, Object> parameters) throws Exception { + Calendar cal = Calendar.getInstance(); + int length = ((String) parameters.get("startTime")).split("-").length; String time = parameters.remove("startTime").toString(); String timeb; if (parameters.get("endTime") == null) { @@ -1008,65 +1010,44 @@ } else { timeb = parameters.remove("endTime").toString(); } + String dateFormat = ""; + String typeFormat = ""; + String timeUnits = "daily"; + int i = 0; + if (length == 1) { + dateFormat = "yyyy"; + typeFormat = "%Y"; + i = Calendar.YEAR; + } else if (length == 2) { + dateFormat = "yyyy-MM"; + typeFormat = "%Y-%m"; + i = Calendar.MONTH; + } else if (length == 3) { + dateFormat = "yyyy-MM-dd"; + typeFormat = "%Y-%m-%d"; + i = Calendar.DAY_OF_MONTH; + } else if (length == 4) { + dateFormat = "yyyy-MM-dd HH"; + typeFormat = "%Y-%m-%d %H"; + timeUnits = "hourly"; + i = Calendar.HOUR_OF_DAY; + time = time.substring(0, 10) + " " + time.substring(11, 13); + timeb = timeb.substring(0, 10) + " " + timeb.substring(11, 13); + } parameters.put("time", time); parameters.put("timeb", timeb); - Calendar cal = Calendar.getInstance(); - int length = time.length(); - String type = ""; - if (length == 10) { - type = "day"; - } else if (length == 7) { - type = "month"; - } else if (length == 4) { - type = "year"; - } else if (length == 13) { - type = "hour"; - } - parameters.put("type", type); - String[] endTimes = timeb.split("-"); - String dateFormat = ""; - String beginTime = ""; - String endTime = ""; - Integer year = Integer.valueOf(endTimes[0]); - int i = 0; - if (type.equals("year")) { - dateFormat = "yyyy-MM"; - beginTime = time + "-01"; - timeb = Integer.valueOf(timeb) + 1 + ""; - endTime = timeb + "-01"; - i = Calendar.MONTH; - } else if (type.equals("month")) { - dateFormat = "yyyy-MM-dd"; - beginTime = time + "-01"; - i = Calendar.DAY_OF_MONTH; - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); - cal.setTime(sdf.parse(timeb)); - cal.add(Calendar.MONTH, 1); - timeb = sdf.format(cal.getTime()); - endTime = timeb + "-01"; - } else if (type.equals("day")) { - dateFormat = "yyyy-MM-dd HH"; - beginTime = time + " 00"; - i = Calendar.HOUR_OF_DAY; - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - cal.setTime(sdf.parse(timeb)); - cal.add(Calendar.DAY_OF_MONTH, 1); - timeb = sdf.format(cal.getTime()); - endTime = timeb + " 00"; - } else if (type.equals("hour")) { - dateFormat = "yyyy-MM-dd HH:mm"; - beginTime = time + ":00:00"; - i = Calendar.MINUTE; - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH"); - cal.setTime(sdf.parse(timeb)); - cal.add(Calendar.HOUR_OF_DAY, 1); - timeb = sdf.format(cal.getTime()); - endTime = timeb + ":00:00"; - } + SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); - cal.setTime(sdf.parse(beginTime)); + cal.setTime(sdf.parse(timeb)); + cal.add(i, 1); + Date endTime = cal.getTime(); + parameters.put("format", dateFormat); + parameters.put("typeFormat", typeFormat); + parameters.put("timeUnits", timeUnits); + parameters.put("field", i); + cal.setTime(sdf.parse(time)); List<String> times = new ArrayList<>(); - for (long d = cal.getTimeInMillis(); d < sdf.parse(endTime).getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) { + for (long d = cal.getTimeInMillis(); d < endTime.getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) { String format = sdf.format(d); times.add(format); } @@ -1074,7 +1055,7 @@ List<String> keys = Arrays.asList(sensorKeys); parameters.put("sensors", keys); parameters.put("sensorKeys", keys); - parameters.put("timeb", timeb); + parameters.put("timeb", sdf.format(endTime)); int mpId = Integer.valueOf(parameters.get("monitorPoint").toString()); String monitorPointName = monitorPointMapper.getMonitorName(mpId); List<Map<String, Object>> devices = deviceMapper.getDevicesByMpId(mpId); diff --git a/src/main/java/com/moral/service/impl/WeatherServiceImpl.java b/src/main/java/com/moral/service/impl/WeatherServiceImpl.java index 8c83b3b..0991b8c 100644 --- a/src/main/java/com/moral/service/impl/WeatherServiceImpl.java +++ b/src/main/java/com/moral/service/impl/WeatherServiceImpl.java @@ -569,6 +569,7 @@ //������������ int x = 0; + parameters.put("cityCode", code); List<Map<String, Object>> realList = realWeatherMapper.getRealWeather(parameters); if (realList.size() == 0) { //1-23��������������������������������������������������������������������� @@ -670,7 +671,7 @@ listMap.put("city", name); String time1 = listMap.get("time").toString(); for (Map<String, Object> aqiMap : realAqilist) { - if(time1.equals(aqiMap.get("time"))){ + if (time1.equals(aqiMap.get("time"))) { listMap.putAll(aqiMap); } } @@ -826,19 +827,39 @@ //������������ Map<String, Object> geographyMap = shAreaMapper.getGeography(name); - for (Map<String, Object> map : resultList) { - double longitude = Double.valueOf(geographyMap.get("lng").toString()); - double latitude = Double.valueOf(geographyMap.get("lat").toString()); - map.put("longitude", df.format(longitude)); - map.put("latitude", df.format(latitude)); - if (geographyMap.get("altitude") != null) { - map.put("altitude", geographyMap.get("altitude").toString()); + if (geographyMap != null) { + for (Map<String, Object> map : resultList) { + if (geographyMap.get("lng") != null) { + double longitude = Double.valueOf(geographyMap.get("lng").toString()); + map.put("longitude", df.format(longitude)); + } + if (geographyMap.get("lat") != null) { + double latitude = Double.valueOf(geographyMap.get("lat").toString()); + map.put("latitude", df.format(latitude)); + } + if (geographyMap.get("altitude") != null) { + map.put("altitude", geographyMap.get("altitude").toString()); + } + if (geographyMap.get("vegetation") != null) { + map.put("vegetation", geographyMap.get("vegetation").toString()); + } + if (geographyMap.get("river") != null) { + map.put("river", geographyMap.get("river").toString()); + } } - if (geographyMap.get("vegetation") != null) { - map.put("vegetation", geographyMap.get("vegetation").toString()); - } - if (geographyMap.get("river") != null) { - map.put("river", geographyMap.get("river").toString()); + } + + for (int i = 0; i < resultList.size(); i = i + 2) { + Map<String, Object> foreMap = resultList.get(i); + Map<String, Object> realMap = resultList.get(i + 1); + if (foreMap.get("O3C") != null && realMap.get("O3C") != null) { + Double foreO3 = Double.valueOf(foreMap.get("O3C").toString()); + Double realO3 = Double.valueOf(realMap.get("O3C").toString()); + int round = (int) Math.round((realO3 - foreO3) / realO3 * 100); + if (round < 0) { + round = -round; + } + realMap.put("errorRate", round + "%"); } } return resultList; diff --git a/src/main/java/com/moral/util/AQICalculation2.java b/src/main/java/com/moral/util/AQICalculation2.java new file mode 100644 index 0000000..92d435c --- /dev/null +++ b/src/main/java/com/moral/util/AQICalculation2.java @@ -0,0 +1,332 @@ +package com.moral.util; + +import java.util.*; + +public class AQICalculation2 { + + public static Map<String, Object> hourlyAQI(Map<String, Object> map){ + List<Double> AQIList = new ArrayList<>(); + Map maxMap = new HashMap(); + for (Map.Entry<String, Object> entry : map.entrySet()) { + String key = entry.getKey(); + if (entry.getValue() instanceof Double){ + Double value = Double.parseDouble(entry.getValue().toString()); + if (key!="O3-8h"){ + maxMap.put(key,value); + } + Double PM2_5AQI; + Double PM10AQI; + Double SO2AQI; + Double NO2AQI; + Double COAQI; + Double O3AQI; + switch (key) { + case "PM2_5":PM2_5AQI = PM2_5AQI(value); + AQIList.add(PM2_5AQI); + break; + case "PM10":PM10AQI = PM10AQI(value); + AQIList.add(PM10AQI); + break; + case "SO2":SO2AQI = SO2AQI(value); + AQIList.add(SO2AQI); + break; + case "e16":NO2AQI = NO2AQI(value); + AQIList.add(NO2AQI); + break; + case "CO":COAQI = COAQI(value); + AQIList.add(COAQI); + break; + case "O3":O3AQI = O3AQI(value); + AQIList.add(O3AQI); + break; + + default: + break; + } + }else { + continue; + } + } + + 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); + return returnMap; + } + public static Map<String, Object> dayAQI(Map<String, Object> map){ + List<Double> AQIList = new ArrayList<>(); + Map maxMap = new HashMap(); + for (Map.Entry<String, Object> entry : map.entrySet()) { + String key = entry.getKey(); + if (entry.getValue() instanceof Double){ + Double value = Double.parseDouble(entry.getValue().toString()); + if (key!="O3-day"){ + maxMap.put(key,value); + } + Double PM2_5AQI; + Double PM10AQI; + Double SO2AQI; + Double NO2AQI; + Double COAQI; + Double maxO38hAQI; + switch (key) { + case "PM2_5":PM2_5AQI = PM2_5AQI(value); + AQIList.add(PM2_5AQI); + break; + case "PM10":PM10AQI = PM10AQI(value); + AQIList.add(PM10AQI); + break; + case "SO2":SO2AQI = SO2DayAQI(value); + AQIList.add(SO2AQI); + break; + case "e16":NO2AQI = NO2DayAQI(value); + AQIList.add(NO2AQI); + break; + case "CO":COAQI = CODayAQI(value); + AQIList.add(COAQI); + break; + case "O3":maxO38hAQI = O3DayAQI(value); + AQIList.add(maxO38hAQI); + break; + default: + break; + } + }else { + continue; + } + } + + 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); + return returnMap; + } + static double PM2_5AQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=35) { + result = 50/35*(value-0)+0; + }else if (value<=75) { + result = 50/40*(value-35)+50; + }else if (value<=115) { + result = 50/40*(value-75)+100; + }else if (value<=150) { + result = 50/35*(value-115)+150; + }else if (value<=250) { + result = 100/100*(value-150)+200; + }else if (value<=350) { + result = 100/100*(value-250)+300; + }else { + result = 100/150*(value-350)+400; + } + return result; + } + + static double PM10AQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=50) { + result = 50/50*(value-0)+0; + }else if (value<=150) { + result = 50/100*(value-50)+50; + }else if (value<=250) { + result = 50/100*(value-150)+100; + }else if (value<=350) { + result = 50/100*(value-250)+150; + }else if (value<=420) { + result = 100/70*(value-350)+200; + }else if (value<=500) { + result = 100/80*(value-420)+300; + }else { + result = 100/100*(value-500)+400; + } + return result; + } + + static double SO2AQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=150) { + result = 50/150*(value-0)+0; + }else if (value<=500) { + result = 50/350*(value-150)+50; + }else if (value<=650) { + result = 50/150*(value-500)+100; + }else { + result = 50/150*(value-650)+150; + } + return result; + } + + static double NO2AQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=100) { + result = 50/100*(value-0)+0; + }else if (value<=200) { + result = 50/100*(value-100)+50; + }else if (value<=700) { + result = 50/500*(value-200)+100; + }else if (value<=1200) { + result = 50/500*(value-700)+150; + }else if (value<=2340) { + result = 100/1140*(value-1200)+200; + }else if (value<=3090) { + result = 100/750*(value-2340)+300; + }else { + result = 100/750*(value-3090)+400; + } + return result; + } + + static double COAQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=5) { + result = 50/5*(value-0)+0; + }else if (value<=10) { + result = 50/5*(value-5)+50; + }else if (value<=35) { + result = 50/25*(value-10)+100; + }else if (value<=60) { + result = 50/25*(value-35)+150; + }else if (value<=90) { + result = 100/30*(value-60)+200; + }else if (value<=120) { + result = 100/30*(value-90)+300; + }else { + result = 100/30*(value-120)+400; + } + return result; + } + + static double O3AQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=100) { + result = 50/160*(value-0)+0; + }else if (value<=160) { + result = 50/40*(value-160)+50; + }else if (value<=215) { + result = 50/100*(value-200)+100; + }else if (value<=265) { + result = 50/100*(value-300)+150; + }else if (value<=800) { + result = 100/400*(value-400)+200; + }else if (value<=2100) { + result = 100/200*(value-800)+300; + }else { + result = 100/200*(value-1000)+400; + } + return result; + } + + static double O3DayAQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=100) { + result = 50/100*(value-0)+0; + }else if (value<=160) { + result = 50/60*(value-100)+50; + }else if (value<=215) { + result = 50/55*(value-160)+100; + }else if (value<=265) { + result = 50/150*(value-215)+150; + }else if (value<=800) { + result = 100/535*(value-265)+200; + }else if (value<=2100) { + result = 100/12*(value-800)+300; + }else { + result = 100/12*(value-48)+400; + } + return result; + } + + static double SO2DayAQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=50) { + result = 50/50*(value-0)+0; + }else if (value<=150) { + result = 50/100*(value-50)+50; + }else if (value<=475) { + result = 50/325*(value-150)+100; + }else if (value<=800) { + result = 50/325*(value-475)+150; + }else if (value<=1600) { + result = 100/800*(value-800)+200; + }else if (value<=2100) { + result = 100/500*(value-1600)+300; + }else { + result = 100/520*(value-2100)+400; + } + return result; + } + static double NO2DayAQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=40) { + result = 50/40*(value-0)+0; + }else if (value<=80) { + result = 50/40*(value-40)+50; + }else if (value<=180) { + result = 50/100*(value-80)+100; + }else if (value<=280) { + result = 50/100*(value-180)+150; + }else if (value<=565) { + result = 100/285*(value-280)+200; + }else if (value<=750) { + result = 100/185*(value-565)+300; + }else { + result = 100/190*(value-750)+400; + } + return result; + } + + static double CODayAQI(Double value) { + Double result = (double) 0; + if(value<=0) { + result=(double) 0; + }else if (value<=5) { + result = 50/2*(value-0)+0; + }else if (value<=10) { + result = 50/2*(value-2)+50; + }else if (value<=35) { + result = 50/10*(value-4)+100; + }else if (value<=60) { + result = 50/10*(value-14)+150; + }else if (value<=90) { + result = 100/12*(value-24)+200; + }else if (value<=120) { + result = 100/12*(value-36)+300; + }else { + result = 100/12*(value-48)+400; + } + return result; + } + + +} diff --git a/src/main/resources/mapper/DeviceAdjustValueTimingMapper.xml b/src/main/resources/mapper/DeviceAdjustValueTimingMapper.xml new file mode 100644 index 0000000..da6f285 --- /dev/null +++ b/src/main/resources/mapper/DeviceAdjustValueTimingMapper.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.moral.mapper.DeviceAdjustValueTimingMapper"> + <resultMap id="BaseResultMap" type="com.moral.entity.DeviceAdjustValueTiming" > + <id column="id" property="id" jdbcType="INTEGER" /> + <result column="device_id" property="deviceId" jdbcType="INTEGER" /> + <result column="value" jdbcType="OTHER" property="value" javaType="java.util.Map" typeHandler="AdjustValueTypeHandle" /> + <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> + <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> + </resultMap> + <delete id="delete"> + delete from device_adjust_value_timing where id=#{id} + </delete> + <select id="selectAllByDeviceid" resultType="com.moral.entity.DeviceAdjustValueTiming" resultMap="BaseResultMap"> + SELECT * FROM device_adjust_value_timing + WHERE device_id = #{device_id} + </select> + + <!--������device_id���seconds������--> + <select id="selectAllByDeviceidAndSeconds" resultType="java.util.Map"> + SELECT * FROM device_adjust_value_timing + WHERE device_id = #{device_id} + AND seconds = #{seconds} + </select> + + <!--������������--> + <insert id="insertData"> + INSERT INTO device_adjust_value_timing (device_id,seconds,value,create_time) + VALUES(#{device_id},#{seconds},#{value},#{create_time}) + </insert> + + <!--������������--> + <update id="upDataByDeviceid"> + UPDATE device_adjust_value_timing + SET value = #{value},update_time = #{update_time} + WHERE device_id = #{device_id} + </update> + +</mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/DeviceMapper.xml b/src/main/resources/mapper/DeviceMapper.xml index 84e4e42..cbdd370 100644 --- a/src/main/resources/mapper/DeviceMapper.xml +++ b/src/main/resources/mapper/DeviceMapper.xml @@ -378,7 +378,7 @@ as windSpeed, h.json->"$.e23[0]" as windDir, h.json->"$.e17[0]" as tVoc from ${table} h ,`device` as d - where d.mac=h.mac and d.mac=#{mac} and h.time=#{time} + where d.mac=h.mac and d.mac=#{mac} and h.time=(select max(time) from ${table}) </select> <select id="byMonitorIdGetDeviceAndWind" resultType="com.moral.entity.DeviceAndWind"> select d.longitude as longitude,d.latitude as latitude, @@ -386,7 +386,7 @@ as windSpeed, h.json->"$.e23[0]" as windDir, h.json->"$.e17[0]" as tVoc from ${table} as h ,`device` as d - where d.mac=h.mac and h.time=#{time} + where d.mac=h.mac and h.time=(select max(time) from ${table}) and d.mac in (select d.mac from device , monitor_point as m where d.monitor_point_id=m.id and m.id=#{id}) </select> @@ -457,8 +457,13 @@ <select id="getDeviceById1" resultType="com.moral.entity.Device"> SELECT d.* FROM `device` as d,monitor_point as mp,device_property as dp where d.monitor_point_id=mp.id and d.id=dp.id and dp.device_tech=1 and d.monitor_point_id=#{id} </select> - <select id="getDeviceById2" resultType="com.moral.entity.Device"> - SELECT d.* FROM `device` as d,monitor_point as mp,device_property as dp where d.monitor_point_id=mp.id and d.id=dp.id and dp.device_tech=2 and d.monitor_point_id=#{id} + <select id="getDeviceById2" resultType="com.moral.entity.Device"> + SELECT d.* + FROM `device` as d,monitor_point as mp,device_property as dp + where d.monitor_point_id=mp.id + and d.id=dp.id + and dp.device_tech=2 + and d.monitor_point_id=#{id} </select> <select id="getDeviceById3" resultType="com.moral.entity.Device"> SELECT d.* FROM `device` as d,monitor_point as mp,device_property as dp where d.monitor_point_id=mp.id and d.id=dp.id and dp.device_tech=3 and d.monitor_point_id=#{id} @@ -547,7 +552,7 @@ as windSpeed, h.json->"$.e23[0]" as windDir, h.json->"$.e17[0]" as tVoc from ${table} as h ,`device` as d - where d.mac=h.mac and h.time=#{time} + where d.mac=h.mac and h.time=(select max(time) from ${table}) and d.mac=#{mac} </select> <select id="getDeviceByCodeAndId" resultType="com.moral.entity.Device" resultMap="BaseResultMap"> @@ -565,4 +570,11 @@ <select id="getDevicesByMpId" resultType="java.util.Map"> select name,mac from device where monitor_point_id=#{mpId} and is_delete=0 </select> + <select id="getDevice" resultType="com.moral.entity.Device"> + select * from device + where mac like concat('%',#{macOrName},'%') + </select> + <select id="getDeviceByCityCode" resultType="com.moral.entity.Device"> + SELECT d.* FROM `monitor_point` mt,device d where d.monitor_point_id=mt.id and d.state!=4 and mt.city_code=130900 + </select> </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/HistoryHourlyMapper.xml b/src/main/resources/mapper/HistoryHourlyMapper.xml index ceee292..8e819ef 100644 --- a/src/main/resources/mapper/HistoryHourlyMapper.xml +++ b/src/main/resources/mapper/HistoryHourlyMapper.xml @@ -102,4 +102,14 @@ <select id="getDataByMacAndTime" resultType="java.util.Map"> SELECT DATE_FORMAT(`time`,'%Y-%m-%d %H:%i:%s') as `time`,json->'$.${sensor}[0]' as ${sensor} FROM `history_hourly` where `mac`=#{mac} and `time`>=#{startTime} and `time`<#{endTime} </select> + <select id="getDataByMacAndTime1" resultType="java.util.Map"> + SELECT DATE_FORMAT(`time`,'%Y-%m-%d %H:%i:%s') as `time`,json->'$.${sensor}[0]' as ${sensor} FROM `history_hourly` where `mac`=#{mac} and `time`>=#{startTime} and `time`<![CDATA[<]]>#{endTime} + </select> + <select id="getDataAvbByMIdAndTime" 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=#{mId} and hh.time>#{startTime} and hh.time<![CDATA[<=]]>#{endTime} GROUP BY hh.time; + </select> </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml index 8af3236..47b11ab 100644 --- a/src/main/resources/mapper/HistoryMapper.xml +++ b/src/main/resources/mapper/HistoryMapper.xml @@ -297,5 +297,11 @@ where mac = #{mac} and time >= #{time1} and time <=#{time} limit 0,1 </select> + <select id="getDailyAvgData" 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=#{mId} and time=#{time} + </select> </mapper> \ No newline at end of file diff --git a/src/main/webapp/img/ico005.png b/src/main/webapp/img/ico005.png new file mode 100644 index 0000000..6650f40 --- /dev/null +++ b/src/main/webapp/img/ico005.png Binary files differ diff --git a/src/main/webapp/img/ico006.png b/src/main/webapp/img/ico006.png new file mode 100644 index 0000000..56c50b4 --- /dev/null +++ b/src/main/webapp/img/ico006.png Binary files differ diff --git a/src/main/webapp/js/newmoralmap.js b/src/main/webapp/js/newmoralmap.js index 1c68869..9cdac74 100644 --- a/src/main/webapp/js/newmoralmap.js +++ b/src/main/webapp/js/newmoralmap.js @@ -657,7 +657,11 @@ state = state == null ? 0 : state; var icon = _option["icon"]; //var url = icon["stateIcons"][state]; - var url = icon["url"] + state + ".png"; + if (state==5 || state==6){ + var url = icon["url"] + "0"+state + ".png"; + }else { + var url = icon["url"] + state + ".png"; + } return new BMap.Icon(url, new BMap.Size(icon["width"], icon["height"]), { imageSize: new BMap.Size(icon["width"], icon["height"]) }); @@ -782,7 +786,7 @@ } } var icon = {}; - icon["stateIcons"] = ["/img/ico00.png", "/img/ico01.png", "/img/ico02.png", "/img/ico03.png", "/img/ico04.png"]; + icon["stateIcons"] = ["/img/ico00.png", "/img/ico01.png", "/img/ico02.png", "/img/ico03.png", "/img/ico04.png","/img/ico05.png", "/img/ico06.png"]; icon["url"] = "/img/ico0"; icon["width"] = 50; icon["height"] = 50; @@ -907,7 +911,7 @@ } } var icon = {}; - icon["stateIcons"] = ["/img/ico00.png", "/img/ico01.png", "/img/ico02.png", "/img/ico03.png", "/img/ico04.png"]; + icon["stateIcons"] = ["/img/ico00.png", "/img/ico01.png", "/img/ico02.png", "/img/ico03.png", "/img/ico04.png","/img/ico005.png", "/img/ico006.png"]; icon["url"] = "/img/ico0"; icon["width"] = 50; icon["height"] = 50; -- Gitblit v1.8.0