DeviceService.java
4.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
package cn.com.glsx.modules.service;
import cn.com.glsx.modules.model.param.ResponseBody;
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
@Slf4j
public class DeviceService {
@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);
}
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMsg();
return R.error(errorMessage);
}
public R getDevicesById(String 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);
}
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMsg();
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);
}
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMsg();
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);
}
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMsg();
return R.error(errorMessage);
}
public R instructionIssue(String device_id, String insjson) {
ResponseBody responseBody = sendRequestService.sendRequestPost(instructionIssue.replace("{device_id}", device_id), insjson);
if (responseBody != null && responseBody.isSuccess()) {
return R.ok();
}
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMsg();
Integer code = responseBody == null ? 500 : responseBody.getCode();
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);
}
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMsg();
return R.error(errorMessage);
}
public R instructionInfIssue(String infrared_id, String remote_id, String insjson) {
ResponseBody responseBody = sendRequestService.sendRequestPost(instructionInfIssue.replace("{remote_id}", remote_id).replace("{infrared_id}", infrared_id), insjson);
if (responseBody != null && responseBody.isSuccess()) {
return R.ok();
}
String errorMessage = responseBody == null ? "调用涂鸦失败" : responseBody.getMsg();
return R.error(errorMessage);
}
}