chen_xi
2023-06-29 123181df72f846957a5b05cf45b323f8762fe9b8
screen-api/src/main/java/com/moral/api/controller/CruiserController.java
@@ -1,11 +1,13 @@
package com.moral.api.controller;
import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@@ -16,6 +18,7 @@
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -77,17 +80,49 @@
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String")
            @ApiImplicitParam(name = "time1", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time2", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage carTrajectory(HttpServletRequest request) {
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("time2")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<Map<String, Object>> response = specialDeviceService.carTrajectory(params);
        List<Map<String, Object>> response = specialDeviceService.carTrajectory(params,true);
        return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response);
    }
    @GetMapping("carTrajectoryNewAvg")
    @ApiOperation(value = "走航车轨迹", notes = "走航车轨迹")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time1", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "time2", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "采集因子", required = true, paramType = "query", dataType = "String")
    })
    public ResultMessage carTrajectoryNewAvg(HttpServletRequest request) {
        long stime = System.currentTimeMillis();
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("type")|| !params.containsKey("time2")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<HistorySecondCruiserResultDTO> response = specialDeviceService.carTrajectoryNewAvg(params);
        if(CollectionUtils.isEmpty(response)){
            return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response);
        }
        long etime = System.currentTimeMillis();
        Map<Integer,HistorySecondCruiserResultDTO> map = new HashMap<>();
        for(int i = 0 ;i<response.size();i++){
            map.put(i,response.get(i));
        }
        //计算执行时间
        System.out.printf("执行时长:%d 毫秒.", (etime - stime));
        return ResultMessage.ok(map);
    }
    /**
     * 走航车日报