jpy
2023-05-27 41a8d1d5ff0192baaba3130f3113a6ccfbcf6a33
screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
@@ -1,7 +1,9 @@
package com.moral.api.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.*;
import com.moral.api.mapper.HistoryMonthlyMapper;
import com.moral.api.pojo.dto.dataDisplay.MonitorPointDataDisplayDTO;
import com.moral.api.pojo.dto.dataDisplay.SensorComparisonDisplayDTO;
import com.moral.api.pojo.form.dataDisplay.MonitorPointDataDisplayForm;
@@ -32,6 +34,8 @@
    HistoryDailyService historyDailyService;
    @Autowired
    HistoryHourlyService historyHourlyService;
    @Autowired
    HistoryMonthlyMapper historyMonthlyMapper;
    @Autowired
    HistoryWeeklyService historyWeeklyService;
    @Autowired
@@ -226,8 +230,31 @@
        String mac = params.get("mac").toString();
        String reportType = params.get("reportType").toString();
        Map<String, String> timeValueMap = new LinkedHashMap<>();//key为time,value为数据的json
        //处理月数据
        if (reportType.equals(Constants.MONTHLY_REPORT)) {
            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_EN);
            Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_EN);
            //List<HistoryHourly> hourlies = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate);
            QueryWrapper<HistoryMonthly> historyMonthlyQueryWrapper = new QueryWrapper<>();
            historyMonthlyQueryWrapper.eq("mac",mac);
            historyMonthlyQueryWrapper.between("time",startTime.substring(0,7)+"-01 00:00:00",endTime.substring(0,7)+"-01 00:00:00");
            List<HistoryMonthly> monthlies = historyMonthlyMapper.selectList(historyMonthlyQueryWrapper);
            for (HistoryMonthly historyMonthly : monthlies) {
                Date time = historyMonthly.getTime();
                String dateStr = DateUtils.dateToDateString(time, "yyyy-MM");
                String value = historyMonthly.getValue();
                timeValueMap.put(dateStr, value);
            }
            //补上无数据时间
            Date middleDate = startDate;
            while (DateUtils.compareDateStr(DateUtils.dateToDateString(endDate,DateUtils.yyyy_MM_EN),DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN),DateUtils.yyyy_MM_EN)<=0){
                if (timeValueMap.get(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN)) == null)
                    timeValueMap.put(DateUtils.dateToDateString(middleDate,DateUtils.yyyy_MM_EN), null);
                middleDate = DateUtils.addMonths(middleDate,1);
            }
        }
        //处理小时数据
        if (reportType.equals(Constants.HOURLY_REPORT)) {
        else if (reportType.equals(Constants.HOURLY_REPORT)) {
            Date startDate = DateUtils.getDate(startTime,DateUtils.yyyy_MM_dd_HH_EN);
            Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_EN);
            List<HistoryHourly> hourlies = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate);
@@ -272,6 +299,15 @@
        for (String sensor : sensors) {
            SensorComparisonDisplayDTO dto = new SensorComparisonDisplayDTO();
            List<Map<String, Object>> dtoTimeValueList = new ArrayList<>();
            if(sensor.equals("a00e12") || sensor.equals("a00e03")){
                dto.setCode("1");
            }else if (sensor.equals("a01006")){
                dto.setCode("2");
            }else if (sensor.equals("a99054") || sensor.equals("a21005")){
                dto.setCode("3");
            }else {
                dto.setCode("0");
            }
            dto.setSensorCode(sensor);
            timeValueMap.forEach((time, valueJson) -> {
                Map<String, Object> listMap = new HashMap<>();