kaiyu
2020-11-16 cd264145f9b4107f1430da46269dd306d26f3116
Merge remote-tracking branch 'origin/master'
8 files added
16 files modified
1114 ■■■■■ changed files
src/main/java/com/moral/controller/ScreenController.java 177 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/WebController.java 64 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/entity/DeviceAdjustValueTiming.java 23 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/DeviceAdjustValueTimingMapper.java 21 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/DeviceMapper.java 13 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/HistoryHourlyMapper.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/HistoryMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/DeviceAdjustValueTimingService.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/DeviceService.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/HistoryHourlyService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/HistoryMinutelyService.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/DeviceAdjustValueTimingServiceImpl.java 45 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/DeviceServiceImpl.java 62 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java 141 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryMinutelyServiceImpl.java 93 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/WeatherServiceImpl.java 23 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/util/AQICalculation2.java 332 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/DeviceAdjustValueTimingMapper.xml 39 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/DeviceMapper.xml 20 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryHourlyMapper.xml 10 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryMapper.xml 6 ●●●●● patch | view | raw | blame | history
src/main/webapp/img/ico005.png patch | view | raw | blame | history
src/main/webapp/img/ico006.png patch | view | raw | blame | history
src/main/webapp/js/newmoralmap.js 8 ●●●● patch | view | raw | blame | history
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));
                            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);
    }
    /*@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;
    }
}
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]
src/main/java/com/moral/entity/DeviceAdjustValueTiming.java
New file
@@ -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;
}
src/main/java/com/moral/mapper/DeviceAdjustValueTimingMapper.java
New file
@@ -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);
}
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();
}
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);
}
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);
}
src/main/java/com/moral/service/DeviceAdjustValueTimingService.java
New file
@@ -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);
}
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();
}
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);
}
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;
}
src/main/java/com/moral/service/impl/DeviceAdjustValueTimingServiceImpl.java
New file
@@ -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);
    }
}
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);
            //剔除沧州地图页面非公司设备图标
            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);//实例化
@@ -719,8 +749,8 @@
    }
    @Override
    public List byMonitorIdGetDeviceAndWind(String id,String time,String tab) {
        List<DeviceAndWind> deviceAndWinds=deviceMapper.byMonitorIdGetDeviceAndWind(Integer.parseInt(id),time,tab);
    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;
@@ -876,7 +906,7 @@
    }
    @Override
    public List byMonitorIdGetDeviceAndWindSpecial(String id, String time, String tab) {
    public List byMonitorIdGetDeviceAndWindSpecial(String id, String tab) {
        MonitorPoint monitorPoint=monitorPointMapper.byIdGetMonitorPoint(Integer.parseInt(id));
        Integer areaCode=monitorPoint.getAreaCode();
        String townCode= monitorPoint.getTownCode()+"";
@@ -895,7 +925,7 @@
            List<Device> deviceList=deviceMapper.getDeviceByCode(parm);
            for (Device d : deviceList) {
                String mac=d.getMac();
                 DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac,time,tab);
                DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac, tab);
                 if (deviceAndWind!=null){
                     deviceAndWinds.add(deviceAndWind);
                 }
@@ -907,7 +937,7 @@
            List<Device> deviceList=deviceMapper.getDeviceByCode(parm);
            for (Device d : deviceList) {
                String mac=d.getMac();
                DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac,time,tab);
                DeviceAndWind deviceAndWind = deviceMapper.byMacGetDeviceAndWind(mac, tab);
                if (deviceAndWind!=null){
                    deviceAndWinds.add(deviceAndWind);
                }
@@ -915,15 +945,15 @@
            length=2000;
            perdlen=280;
        }else if(monitorPointId==35){
         DeviceAndWind deviceAndWind=deviceMapper.getDeviceAndWindByMac("898607b0101730392253",time,tab);
         DeviceAndWind deviceAndWind1=deviceMapper.getDeviceAndWindByMac("p5dnd7a0392083",time,tab);
            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);
            deviceAndWinds = deviceMapper.byMonitorIdGetDeviceAndWind(Integer.parseInt(id), tab);
            length=2000;
            perdlen=80;
        }
@@ -999,7 +1029,7 @@
                if (tvoc==null){
                    tvoc=0.0;
                }
                Double dir = (270.0 + windDir * Math.PI / 180.0);
            Double dir = (270.0 - windDir * Math.PI / 180.0);
                U = windSpeed * Math.cos(dir);
                V = windSpeed * Math.sin(dir);
@@ -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();
    }
}
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)) {
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);
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点数据必然是同一个月份,最后一个可能是下一个月
@@ -826,11 +827,16 @@
        //地理特征
        Map<String, Object> geographyMap = shAreaMapper.getGeography(name);
        if (geographyMap != null) {
        for (Map<String, Object> map : resultList) {
                if (geographyMap.get("lng") != null) {
            double longitude = Double.valueOf(geographyMap.get("lng").toString());
            double latitude = Double.valueOf(geographyMap.get("lat").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());
            }
@@ -841,6 +847,21 @@
                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;
    }
}
src/main/java/com/moral/util/AQICalculation2.java
New file
@@ -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;
    }
}
src/main/resources/mapper/DeviceAdjustValueTimingMapper.xml
New file
@@ -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>
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>
@@ -458,7 +458,12 @@
        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 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>
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`&gt;=#{startTime} and `time`&lt;#{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`&gt;=#{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>
src/main/resources/mapper/HistoryMapper.xml
@@ -297,5 +297,11 @@
        where  mac = #{mac} and time &gt;= #{time1} and time &lt;=#{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>
src/main/webapp/img/ico005.png
src/main/webapp/img/ico006.png
src/main/webapp/js/newmoralmap.js
@@ -657,7 +657,11 @@
            state = state == null ? 0 : state;
            var icon = _option["icon"];
            //var url = icon["stateIcons"][state];
            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;