DeviceController.java
3.31 KB
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
package cn.com.glsx.modules.controller;
import cn.com.glsx.common.BussinessFactory.BussinessFactory;
import cn.com.glsx.modules.model.param.DeviceInfo;
import cn.com.glsx.modules.model.param.Function;
import cn.com.glsx.modules.service.DeviceService;
import cn.com.glsx.modules.service.abs.BaseDeviceService;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
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.ResponseBody;
import java.util.List;
/**
* @author zhouhaibao
* @date 2021/3/4 17:05
*/
@Controller
@RequestMapping("/device")
@Api(value = "设备管理", tags = {"设备管理"})
public class DeviceController {
@Autowired
private DeviceService deviceService;
/**
* 获取用户下的设备列表
*
* @return
*/
@RequestMapping(value = "/{uid}/devices", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取用户下的设备列表")
public R getAllDevicesByUser(@PathVariable String uid) {
List<DeviceInfo> list = deviceService.getAllDevicesByUser(uid);
return R.ok(JSONObject.toJSONString(list));
}
/**
* 获取用户下的设备列表
*
* @return
*/
@RequestMapping(value = "/devices/{device_id}", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据id获取设备")
public R getDevicesById(@PathVariable String device_id) {
DeviceInfo deviceInfo = deviceService.getDevicesById(device_id);
return R.ok(JSONObject.toJSONString(deviceInfo));
}
/**
* 获取用户下的设备列表
*
* @return
*/
@RequestMapping(value = "/devices/{device_id}/functions", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据id获取指令集")
public R getFunctionsById(@PathVariable String device_id) {
Function function = deviceService.getFunctionsById(device_id);
return R.ok(JSONObject.toJSONString(function));
}
/**
* 获取用户下的设备列表
*
* @return
*/
@RequestMapping(value = "/functions/{category}", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据品类获取指令集")
public R getFunctionsByCat(@PathVariable String category) {
Function function = deviceService.getFunctionsByCat(category);
return R.ok(JSONObject.toJSONString(function));
}
/**
* 根据设备下发指令
*
* @return
*/
@RequestMapping(value = "/devices/{device_id}/commands", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "根据设备下发指令")
public R instructionIssue(@PathVariable String device_id, @RequestBody String insjson) {
String message = deviceService.instructionIssue(device_id, insjson);
if (("下发成功").equals(message)) {
return R.ok(message);
}
return R.error(message);
}
}