DeviceService.java
3.17 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
package cn.com.glsx.modules.service;
import cn.com.glsx.modules.model.param.DeviceInfo;
import cn.com.glsx.modules.model.param.Function;
import cn.com.glsx.modules.model.param.ResponseBody;
import cn.com.glsx.modules.service.abs.BaseDeviceService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author zhouhaibao
* @date 2021/3/5 10:17
*/
@Service
@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;
@Autowired
private SendRequestService sendRequestService;
@Override
public List<DeviceInfo> getAllDevicesByUser(String uid) {
List<DeviceInfo> userInfo = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getAllDevicesByUserUrl.replace("{uid}", uid));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
userInfo = JSONObject.parseArray(result, DeviceInfo.class);
} else {
log.info("调用涂鸦获取用户设备接口失败");
}
return userInfo;
}
@Override
public DeviceInfo getDevicesById(String device_id) {
DeviceInfo deviceInfo = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getDevicesByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
deviceInfo = JSONObject.parseObject(result, DeviceInfo.class);
} else {
log.info("调用涂鸦获取设备接口失败");
}
return deviceInfo;
}
@Override
public Function getFunctionsById(String device_id) {
Function function = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByIdUrl.replace("{device_id}", device_id));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
function = JSONObject.parseObject(result, Function.class);
} else {
log.info("调用涂鸦获取用户设备接口失败");
}
return function;
}
@Override
public Function getFunctionsByCat(String category) {
Function function = null;
ResponseBody responseBody = sendRequestService.sendRequestGet(getFunctionsByCatUrl.replace("{category}", category));
if (responseBody != null && responseBody.isSuccess()) {
String result = responseBody.getResult();
function = JSONObject.parseObject(result, Function.class);
} else {
log.info("调用涂鸦获取用户设备接口失败");
}
return function;
}
}