jinpengyong
2021-05-13 943a2364c76db4c4e570e0d0219a81b6caa9bffc
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
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.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Map;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.Device;
import com.moral.api.entity.ManageAccount;
import com.moral.api.entity.Organization;
import com.moral.api.entity.User;
import com.moral.api.pojo.vo.device.DeviceVO;
import com.moral.api.service.DeviceService;
import com.moral.api.service.OrganizationService;
import com.moral.constant.ResultMessage;
import com.moral.util.PageResult;
 
@Slf4j
@Api(tags = {"设备管理"})
@RestController
@RequestMapping(value = "/device")
public class DeviceController {
 
    @Autowired
    private DeviceService deviceService;
 
    @Autowired
    private OrganizationService organizationService;
 
    @ApiOperation(value = "添加设备", notes = "添加设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public ResultMessage insert(@RequestBody Device device) {
        deviceService.insert(device);
        return ResultMessage.ok();
    }
 
    @ApiOperation(value = "维护人列表", notes = "维护人列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "operators", method = RequestMethod.GET)
    public ResultMessage selectOperators() {
        List<ManageAccount> operators = deviceService.selectAllOperator();
        return ResultMessage.ok(operators);
    }
 
    @ApiOperation(value = "型号列表", notes = "型号列表")
    @RequestMapping(value = "versions", method = RequestMethod.GET)
    public ResultMessage selectVersions() {
        return null;
    }
 
    @ApiOperation(value = "组织列表", notes = "组织列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "organizations", method = RequestMethod.GET)
    public ResultMessage selectOrganizations() {
        List<Organization> organizations = deviceService.selectAllOrganization();
        return ResultMessage.ok(organizations);
    }
 
    @ApiOperation(value = "分页设备列表", notes = "分页设备列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "order", value = "排序字段", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orderType", value = "排序类型,升序:0,降序:1", defaultValue = "0", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
            @ApiImplicitParam(name = "organizationName", value = "组织模糊查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "monitorPointName", value = "站点模糊查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deviceName", value = "设备名称模糊查询", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "mac", value = "mac模糊查询", required = false, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "select", method = RequestMethod.POST)
    public ResultMessage select(@RequestBody Map<String, Object> parameters) {
        Page<DeviceVO> userPage = deviceService.selectDevices(parameters);
        PageResult<DeviceVO> pageResult = new PageResult<>(
                userPage.getTotal(), userPage.getPages(), userPage.getRecords()
        );
        return ResultMessage.ok(pageResult);
    }
}