jinpengyong
2022-11-04 a8ec3f0c200b7e3b038c6cc9fb34d99d68775708
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package com.moral.api.controller;
 
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.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import java.text.ParseException;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import com.moral.api.pojo.bo.ExcelBO;
import com.moral.api.pojo.vo.excel.DailyVo;
import com.moral.api.service.SpecialDeviceService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
 
@Slf4j
@Api(tags = {"走航车"})
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/cruiser")
public class CruiserController {
 
    @Autowired
    private SpecialDeviceService specialDeviceService;
 
    /**
     * @return 返回请求成功后的对象信息
     */
    @GetMapping("selectCruisers")
    @ApiOperation(value = "获取当前组织下所有走航车列表", notes = "走航车轨迹")
    public ResultMessage getCarsInfo() {
        List<Map<String, Object>> response = specialDeviceService.selectCruisers();
        return ResultMessage.ok(response);
    }
 
    /**
     * @param mac 设备mac
     * @return 返回请求成功后的对象信息
     */
    @GetMapping("getDates")
    @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")
    })
    public ResultMessage getDates(String mac) {
        if (ObjectUtils.isEmpty(mac)) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<String> response = specialDeviceService.getDatesByMac(mac);
        return ResultMessage.ok(response);
    }
 
    /**
     * @param request 请求信息
     * @return 返回请求成功后的对象信息
     */
    @GetMapping("cruiserTrajectory")
    @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 = "time", 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);
        return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response);
    }
 
 
    /**
     * 走航车日报
     * @param request
     * @return
     */
    @PostMapping("getDaily")
    @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")
    })
    public  ResultMessage getDaily(HttpServletRequest request) throws ParseException {
        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<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
        ExcelBO daily = specialDeviceService.getDaily(params, files);
        if (daily==null){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
        return ObjectUtils.isEmpty(daily) ? ResultMessage.ok() : ResultMessage.ok(daily);
    }
 
    /**
     * 下载走航车日报
     * @param id
     * @return
     */
    @GetMapping("loadDaily")
    public ResultMessage loadDaily(Integer id){
 
        DailyVo dailyVo = specialDeviceService.loadDaily(id);
        if (dailyVo==null){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),dailyVo);
    }
 
    /**
     * 查询日报
     * @param request
     * @return
     */
    @GetMapping("selectDaily")
    public ResultMessage selectDaily(HttpServletRequest request){
        Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
        if ( !params.containsKey("startTime")|| !params.containsKey("endTime")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<ExcelBO> excelBOS = specialDeviceService.selectDaily(params);
        if (excelBOS==null){
            return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg());
        }
        return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),excelBOS);
    }
 
 
}