jinpengyong
2024-03-07 36844dfeea0914de1138be9ebdf27c92d745d73a
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
package com.moral.api.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import javax.validation.Valid;
import com.moral.api.dto.OnlineRatePageCond;
import com.moral.api.service.DeviceService;
import com.moral.api.vo.OnlineRateVo;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
 
/**
 * Description //todo
 *
 * @author swb
 * @ClassName DeviceOnlineRateController
 * @date 2024.01.26 10:02
 */
@RestController
@RequestMapping("/onlineRate")
@Api(tags = {"设备在线率"})
public class DeviceOnlineRateController {
 
    @Autowired
    private DeviceService deviceService;
 
    @PostMapping("/page")
    @ApiOperation("分页")
    public ResultMessage page(@Valid @RequestBody OnlineRatePageCond onlineRatePageCond) {
        List<OnlineRateVo> rsList = deviceService.getPage(onlineRatePageCond);
//        PageResult<OnlineRateVo> result = new PageResult<>(page);
//        result.setList(page.getRecords());
        return ResultMessage.ok(rsList);
    }
 
    @GetMapping("/detail")
    @ApiOperation("详情")
    public ResultMessage get(@RequestParam @ApiParam(value = "mac",name = "mac")String mac,
                             @RequestParam @ApiParam(value = "startTime",name = "开始时间") String startTime,
                             @RequestParam @ApiParam(value = "endTime",name = "结束时间") String endTime,
                             @RequestParam @ApiParam(value = "type",name = "时间类型") String type){
        Map<String, Object> detail = deviceService.detail(mac, startTime, endTime, type);
        return ResultMessage.ok(detail);
    }
 
 
 
    @PostMapping("state")
    @ApiOperation("当前在线率")
    public ResultMessage state(@RequestBody Map<String, Object> params){
        if (!params.containsKey("macs")) {
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        List<String> macs = (List<String>) params.get("macs");
        Map<String, Object> start = deviceService.getStart(macs);
        return  ResultMessage.ok(start);
    }
}