于紫祥_1901
2020-09-10 5476f8bcf411ce654c02fbd34b9086518adbd917
三天数据对比
5 files modified
124 ■■■■■ changed files
src/main/java/com/moral/controller/ScreenController.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/HistoryHourlyMapper.java 6 ●●●●● 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/impl/HistoryHourlyServiceImpl.java 91 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryHourlyMapper.xml 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java
@@ -86,6 +86,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;
import org.xml.sax.InputSource;
@@ -175,6 +176,9 @@
    @Resource
    private QualityDailyService qualityDailyService;
    @Resource
    private RestTemplate restTemplate;
    /**
     * Screen login. 大屏登录
@@ -1996,6 +2000,8 @@
        List list=deviceService.byMonitorIdGetDeviceAndWind(monitorPointId,time,table);
        return list;
    }
    //局部风场
    @GetMapping("/windAndDeviceDataByArea")
    @ResponseBody
    public List windAndDeviceDataByArea(String monitorPointId) {
@@ -2012,8 +2018,6 @@
            mon=""+month;
        }
        String table="history_minutely_"+year+mon;
        log.info(table);
        log.info(time);
        List list=deviceService.byMonitorIdGetDeviceAndWindSpecial(monitorPointId,time,table);
        return list;
    }
@@ -2213,4 +2217,18 @@
        return new ResultBean<List<Map<String, Object>>>(list);
    }
    @GetMapping("contrastFactor")
    @ApiOperation(value = "因子对比", notes = "因子对比")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sensor", value = "因子", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "时间(格式:2020-03-19、20、21)", required = true, paramType = "query", dataType = "String")})
    public ResultBean<List<Map<String, Object>>> contrastFactor(HttpServletRequest request) throws Exception {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List list=historyHourlyService.getDataByMacAndTime(parameters);
        //System.out.println(list);
        return new ResultBean<List<Map<String, Object>>>(list);
    }
}
src/main/java/com/moral/mapper/HistoryHourlyMapper.java
@@ -1,6 +1,7 @@
package com.moral.mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.method.P;
import java.util.List;
import java.util.Map;
@@ -24,4 +25,9 @@
    List<Map<String, Object>> getDataByTimeSlot(@Param("mac") String mac, @Param("startTime") String startTime, @Param("endTime") String endTime);
    List<Map<String,Object>> getTVOCByMacs(Map<String,Object> params);
    List<Map> getDataByMacAndTime(@Param("mac") String mac,
                                  @Param("sensor") String sensor,
                                  @Param("startTime") String startTime,
                                  @Param("endTime") String endTime);
}
src/main/java/com/moral/service/HistoryHourlyService.java
@@ -24,4 +24,6 @@
    Map<String,Object> getDataByMac(String mac,String time);
    List<Map<String, Object>> getDataByTimeSlot(String mac, String startTime, String endTime) throws Exception;
    List<Map> getDataByMacAndTime(Map param);
}
src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java
@@ -1,9 +1,9 @@
package com.moral.service.impl;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Service;
@@ -121,6 +121,91 @@
    }
    @Override
    public List<Map> getDataByMacAndTime(Map param) {
        String mac = param.get("mac").toString();
        String sensor = param.get("sensor").toString();
        String time = param.get("time").toString();
        String[] times = time.split("、");
        String time1=times[0].substring(0,8);
        for (int i = 0; i <times.length ; i++) {
            if (i!=0){
                times[i]=time1+""+times[i];
            }
        }
        List<List> lists = new ArrayList<List>();
        List<Map> perList = new ArrayList<Map>();
        try {
            for (String perTime : times) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
                Date date = simpleDateFormat.parse(perTime);
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                calendar.add(Calendar.DATE, 1);
                Date date1 = calendar.getTime();
                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) {
                        map.put("time","0"+i);
                        map.put(sensor,"");
                        newList.add(map);
                    }else {
                        map.put("time",""+i);
                        map.put(sensor,"");
                        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);
                        for (Map map : newList) {
                            if (timeS.equals(map.get("time"))){
                                map.replace(sensor,"",list.get(i).get(sensor));
                            }
                        }
                    }
                }
                lists.add(newList);
            }
            for (int i = 0; i < 24; i++) {
                Map<String, Object> map = new HashMap<>();
                List iList = new ArrayList();
                for (List<Map> list : lists) {
                    String timeS = list.get(i).get("time").toString();
                    if (i < 10) {
                        if (timeS.equals("0" + i)) {
                            iList.add(list.get(i).get(sensor));
                        } else {
                            iList.add("");
                        }
                    } else {
                        if (timeS.equals(i + "")) {
                            iList.add(list.get(i).get(sensor));
                        } else {
                            iList.add("");
                        }
                    }
                }
                map.put("value", iList);
                map.put("time", i);
                perList.add(map);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        for (int i = 0; i <perList.size() ; i++) {
            perList.get(i).replace("time",perList.get(i).get("time"),(Integer) perList.get(i).get("time")+1);
        }
        return perList;
    }
    @Override
    public Point getDirPoint(Map<String, Object> parameters) throws Exception {
        Map<String, Object> pollutionSourceData = getPollutionSourceDataByHour(parameters);
        if (MapUtils.isEmpty(pollutionSourceData)) {
src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -98,4 +98,7 @@
        and h.json->'$.e17[0]' is not null
        group by h.time
    </select>
    <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>
</mapper>