DeviceService.java
5.37 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
package cn.com.glsx.modules.service;
import cn.com.glsx.common.DeviceErrorEnum;
import cn.com.glsx.modules.model.param.OrderRequest;
import cn.com.glsx.modules.model.param.RemoteRequest;
import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.service.abs.BaseDeviceService;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @author zhouhaibao
* @date 2021/3/5 10:17
*/
@Service("deviceService")
@Slf4j
public class DeviceService extends BaseDeviceService {
@Value("${tuya.getAllDevicesByUserUrl}")
private String getAllDevicesByUserUrl;
@Value("${tuya.getFunctionsByIdUrl}")
private String getFunctionsByIdUrl;
@Value("${tuya.getDevicesByIdUrl}")
private String getDevicesByIdUrl;
@Value("${tuya.getFunctionsByCatUrl}")
private String getFunctionsByCatUrl;
@Value("${tuya.instructionIssue}")
private String instructionIssue;
@Value("${tuya.findRemotes}")
private String findRemotes;
@Value("${tuya.instructionInfIssue}")
private String instructionInfIssue;
@Autowired
private SendRequestService sendRequestService;
public R getAllDevicesByUser(String uid) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getAllDevicesByUserUrl.replace("{uid}", uid));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
return R.ok(result);
}
Integer code = responseBody == null ? 500 : responseBody.getCode();
String errorMessage=responseBody == null ? "调用涂鸦失败" : DeviceErrorEnum.searchValue(code+"");
return R.error(errorMessage);
}
public R getDevicesById(String device_id) {
log.info("开始查询{}",device_id);
ResponseBody responseBody = sendRequestService.sendRequestGet(getDevicesByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
return R.ok(result);
}
Integer code = responseBody == null ? 500 : responseBody.getCode();
String errorMessage=responseBody == null ? "调用涂鸦失败" : DeviceErrorEnum.searchValue(code+"");
return R.error(errorMessage);
}
public R getFunctionsById(String device_id) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
return R.ok(result);
}
Integer code = responseBody == null ? 500 : responseBody.getCode();
String errorMessage=responseBody == null ? "调用涂鸦失败" : DeviceErrorEnum.searchValue(code+"");
return R.error(errorMessage);
}
public R getFunctionsByCat(String category) {
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByCatUrl.replace("{category}", category));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
return R.ok(result);
}
Integer code = responseBody == null ? 500 : responseBody.getCode();
String errorMessage=responseBody == null ? "调用涂鸦失败" : DeviceErrorEnum.searchValue(code+"");
return R.error(errorMessage);
}
@Override
public R instructionIssue(OrderRequest orderRequest) {
ResponseBody responseBody = sendRequestService.sendRequestPost(instructionIssue.replace("{device_id}", orderRequest.getDeviceId()), orderRequest.getData());
if (responseBody != null && responseBody.isSuccess()) {
return R.ok();
}
Integer code = responseBody == null ? 500 : responseBody.getCode();
String errorMessage=responseBody == null ? "调用涂鸦失败" : DeviceErrorEnum.searchValue(code+"");
return R.error(code,errorMessage);
}
public R findRemotes(String infrared_id) {
ResponseBody responseBody = sendRequestService.sendRequestGet(findRemotes.replace("{infrared_id}", infrared_id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
return R.ok(result);
}
Integer code = responseBody == null ? 500 : responseBody.getCode();
String errorMessage=responseBody == null ? "调用涂鸦失败" : DeviceErrorEnum.searchValue(code+"");
return R.error(errorMessage);
}
/**
* 下发红外指令
*
* @param remoteRequest 请求参数
* @return
*/
@Override
public R instructionInfIssue(RemoteRequest remoteRequest) {
ResponseBody responseBody = sendRequestService.sendRequestPost(instructionInfIssue.replace("{remote_id}", remoteRequest.getRemoteId()).replace("{infrared_id}", remoteRequest.getDeviceId()), remoteRequest.getData());
if (responseBody != null && responseBody.isSuccess()) {
return R.ok();
}
Integer code = responseBody == null ? 500 : responseBody.getCode();
String errorMessage=responseBody == null ? "调用涂鸦失败" : DeviceErrorEnum.searchValue(code+"");
return R.error(errorMessage);
}
}