UserDeviceController.java
4.34 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
package cn.com.glsx.smart.modules.controller;
import cn.com.glsx.smart.common.exception.BusinessException;
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 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;
/**
* <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 结果
*/
@RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
public List<SmartUserDevice> getList(SmartUserDevice req) {
log.info("$$$$ /userDevice/getList param: {}", JSON.toJSONString(req));
if (req.getUserId() == null) {
throw BusinessException.create(ResultEnum.PARAM_EMPTY, "userId");
}
return userDeviceService.getList(req);
}
/**
* 根据 deviceId 查询设备详情
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/getByDeviceId", method = {RequestMethod.GET, RequestMethod.POST})
public SmartUserDevice getByDeviceId(SmartUserDevice req) {
log.info("$$$$ /userDevice/getByDeviceId param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId())) {
throw BusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId");
}
return userDeviceService.getByDeviceId(req);
}
/**
* 保存用户设备
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/save", method = {RequestMethod.POST})
public boolean save(@RequestBody SmartUserDevice req) {
log.info("$$$$ /userDevice/save param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
throw BusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
}
return userDeviceService.save(req) > 0;
}
/**
* 删除用户设备
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/deleteDevice", method = {RequestMethod.POST})
public boolean deleteDevice(@RequestBody SmartUserDevice req) {
log.info("$$$$ /userDevice/deleteDevice param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
throw BusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
}
return userDeviceService.deleteDevice(req) > 0;
}
/**
* 获取用户 bindKey
*
* @param token 用户 token
* @return 结果
*/
@RequestMapping(value = "/getUserBindKey", method = {RequestMethod.GET, RequestMethod.POST})
public String getUserBindKey(String token) {
log.info("$$$$ /userDevice/getUserBindKey param: {}", token);
if (StringUtils.isBlank(token)) {
throw BusinessException.create(ResultEnum.PARAM_EMPTY, "token");
}
return userDeviceService.getUserBindKey(token);
}
/**
* 下发指令
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/sendCommand", method = {RequestMethod.POST})
public String sendCommand(@RequestBody JSONObject req) {
log.info("$$$$ /userDevice/sendCommand param: {}", req.toJSONString());
return userDeviceService.sendCommand(req);
}
/**
* 设备解绑
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/unbind", method = {RequestMethod.POST})
public String unbind(@RequestBody JSONObject req) {
log.info("$$$$ /userDevice/unbind param: {}", req.toJSONString());
return userDeviceService.unbind(req);
}
}