UserDeviceController.java
4.05 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
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
package cn.com.glsx.smart.modules.controller;
import cn.com.glsx.smart.common.exception.ChejiaBusinessException;
import cn.com.glsx.smart.common.exception.ResultEnum;
import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import cn.com.glsx.smart.modules.service.SmartUserDeviceService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>Description: 用户设备业务
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
@Slf4j
@RestController
@RequestMapping("/userDevice")
public class UserDeviceController {
@Autowired
private SmartUserDeviceService userDeviceService;
/**
* 获取用户设备
*
* @param req 请求
* @return 结果
*/
@GetMapping("/getList")
public R getList(SmartUserDevice req) {
log.info("$$$$ /userDevice/getList param: {}", JSON.toJSONString(req));
if (req.getUserId() == null) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "userId");
}
List<SmartUserDevice> userDeviceList = userDeviceService.getList(req);
return R.ok().data(userDeviceList);
}
/**
* 根据 deviceId 查询设备详情
*
* @param req 请求
* @return 结果
*/
@GetMapping("/getByDeviceId")
public R getByDeviceId(SmartUserDevice req) {
log.info("$$$$ /userDevice/getByDeviceId param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId())) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId");
}
SmartUserDevice userDevice = userDeviceService.getByDeviceId(req);
return R.ok().data(userDevice);
}
/**
* 保存用户设备
*
* @param req 请求
* @return 结果
*/
@PostMapping("/save")
public R save(@RequestBody SmartUserDevice req) {
log.info("$$$$ /userDevice/save param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
}
int rows = userDeviceService.save(req);
return R.ok().data(rows > 0);
}
/**
* 删除用户设备
*
* @param req 请求
* @return 结果
*/
@PostMapping("/deleteDevice")
public R deleteDevice(@RequestBody SmartUserDevice req) {
log.info("$$$$ /userDevice/deleteDevice param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
}
int rows = userDeviceService.deleteDevice(req);
return R.ok().data(rows > 0);
}
/**
* 获取用户 bindKey
*
* @param token 用户 token
* @return 结果
*/
@GetMapping("/getUserBindKey")
public R getUserBindKey(@RequestParam String token) {
log.info("$$$$ /userDevice/getUserBindKey param: {}", token);
String userBindKey = userDeviceService.getUserBindKey(token);
return R.ok().data(userBindKey);
}
/**
* 下发指令
*
* @param req 请求
* @return 结果
*/
@PostMapping("/sendCommand")
public R sendCommand(@RequestBody JSONObject req) {
log.info("$$$$ /userDevice/sendCommand param: {}", req.toJSONString());
String result = userDeviceService.sendCommand(req);
return R.ok().data(result);
}
/**
* 设备解绑
*
* @param req 请求
* @return 结果
*/
@PostMapping("/unbind")
public R unbind(@RequestBody JSONObject req) {
log.info("$$$$ /userDevice/unbind param: {}", req.toJSONString());
String result = userDeviceService.unbind(req);
return R.ok().data(result);
}
}