UserDeviceController.java
4.14 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
package com.glsx.smart.controller;
import java.util.List;
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 com.glsx.smart.dao.entity.SmartUserDevice;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.service.SmartUserDeviceService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* <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 R getList(SmartUserDevice req) {
log.info("$$$$ /userDevice/getList param: {}", JSON.toJSONString(req));
if (req.getUserId() == null) {
throw BusinessException.create(ResultEnum.PARAM_ERROR);
}
List<SmartUserDevice> userDeviceList = userDeviceService.getList(req);
return R.ok().data(userDeviceList);
}
/**
* 根据 deviceId 查询设备详情
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/getByDeviceId", method = {RequestMethod.GET, RequestMethod.POST})
public R getByDeviceId(SmartUserDevice req) {
log.info("$$$$ /userDevice/getByDeviceId param: {}", JSON.toJSONString(req));
if (StringUtils.isBlank(req.getDeviceId())) {
throw BusinessException.create(ResultEnum.PARAM_ERROR);
}
SmartUserDevice userDevice = userDeviceService.getByDeviceId(req);
return R.ok().data(userDevice);
}
/**
* 保存用户设备
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/save", method = {RequestMethod.POST})
public R 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_ERROR);
}
boolean success = userDeviceService.save(req) > 0;
return R.ok().data(success);
}
/**
* 删除用户设备
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/deleteDevice", method = {RequestMethod.POST})
public R 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_ERROR);
}
boolean success = userDeviceService.deleteDevice(req) > 0;
return R.ok().data(success);
}
/**
* 获取用户 bindKey
*
* @param username 用户名
* @return 结果
*/
@RequestMapping(value = "/getUserBindKey", method = {RequestMethod.GET, RequestMethod.POST})
public R getUserBindKey(@RequestParam String username) {
log.info("$$$$ /userDevice/getUserBindKey param: {}", username);
String userBindKey = userDeviceService.getUserBindKey(username);
return R.ok().data(userBindKey);
}
/**
* 下发指令
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/sendCommand", method = {RequestMethod.POST})
public R sendCommand(JSONObject req) {
log.info("$$$$ /userDevice/sendCommand param: {}", req.toJSONString());
String result = userDeviceService.sendCommand(req);
return R.ok().data(result);
}
}