kaiyu
2020-10-21 23bdc88d7c2f871711a781ba94b776d629b02702
输出日志 排查问题
1 files modified
33 ■■■■ changed files
src/main/java/com/moral/controller/WebController.java 33 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/WebController.java
@@ -9,23 +9,19 @@
import com.moral.service.*;
import com.moral.util.DateUtil;
import com.moral.util.LatLngTransformation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import static com.moral.common.util.WebUtils.getParametersStartingWith;
import org.apache.log4j.Logger;
@RestController
@RequestMapping("/web")
@@ -33,6 +29,7 @@
@SuppressWarnings({"rawtypes", "unchecked", "unused"})
public class WebController {
    private static Logger log = Logger.getLogger(WebController.class);
    private static Map<String, Sensor> sensors;
    @PostConstruct
@@ -256,6 +253,7 @@
        String sensorKey = (String) parameters.get("sensorKey");
        Integer monitorPointId = Integer.parseInt((String) parameters.get("monitorPointId"));
        //根据monitorpointId获取该站点下所有设备mac集合
        List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
        if (ObjectUtils.isEmpty(devices))
@@ -286,13 +284,16 @@
    }
    @GetMapping("fiveMinuteAvgDataByMac")
    public ResultBean<Map<String, Object>> fiveMinuteAvgDataByMac(HttpServletRequest request) {
    @GetMapping("getFiveMinuteAvgDataByMac")
    public ResultBean<Map<String, Object>> getFiveMinuteAvgDataByMac(HttpServletRequest request) {
        try{
        //获取参数,mac号
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        if ((!parameters.containsKey("mac")))
            return ResultBean.fail("参数为null");
        String mac = (String) parameters.get("mac");
        log.info("获取到mac参数");
        //根据mac获取orgId
        String orgId = monitorPointService.getOrgIdByMac(mac);
@@ -300,6 +301,7 @@
        //判断是否特殊定制客户,如果为特殊定制客户则选取特定参数
        Map<String, Object> specialSensors = organizationSensorsService.getSensorsByOrgId(orgId);
        try {
        if (ObjectUtils.isEmpty(specialSensors)) {
            List<String> sensorKeys = sensorService.getSensorKeys();
            parameters.put("sensorKeys", sensorKeys);
@@ -309,16 +311,23 @@
            sensorKeys = sensorKeys.substring(1, sensorKeys.length() - 1);
            parameters.put("sensorKeys", Arrays.asList(sensorKeys.split(",")));
        }
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        log.info("判断是否特殊客户");
        //设置查询参数
        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("mac", mac);
        log.info("设置查询参数");
        Map<String, Object> datas = historyFiveMinutelyService.getFiveMinutesDataByMac(parameters);
        log.info("查询完毕");
        //如果当前五分钟数据还没有插入,则提取前五分钟数据返回
        if (ObjectUtils.isEmpty(datas)) {
@@ -326,17 +335,20 @@
            parameters.put("time", time);
            datas = historyFiveMinutelyService.getFiveMinutesDataByMac(parameters);
        }
        log.info("查询五分钟前数据");
        //去除无效参数
        datas.values().removeIf((value) -> {
            return ObjectUtils.isEmpty(value) || value.equals("[0, 0, 0]");
        });
        log.info("去除无效参数");
        //添加设备名称
        Map<String, Object> sortDatas = new LinkedHashMap<>();
        Device device = deviceService.getDeviceByMac(mac, true);
        sortDatas.put("名称", device.getName());
        log.info("添加设备名称");
        //参数转换中文
        datas.forEach((key, value) -> {
@@ -349,10 +361,15 @@
                sortDatas.put(sensor.getName(), Arrays.asList(str.split(",")).get(0) + unit);
            }
        });
        log.info("转换中文");
        sortDatas.put("时间", time);
        return new ResultBean<Map<String, Object>>(sortDatas);
        }catch (Exception e){
            log.error(e.getMessage());
            return null;
        }
    }