OpenApiHTTPServiceImpl.java
3.86 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
package com.glsx.service.impl;
import com.glsx.base.aop.SysLog;
import com.glsx.base.controller.BaseService;
import com.glsx.constant.OpenAPIConstant;
import com.glsx.exception.ApiException;
import com.glsx.model.BO.CommandsBo;
import com.glsx.model.BO.DeviceDateBo;
import com.glsx.model.BO.DeviceSdeviceDateBo;
import com.glsx.model.BO.DeviceStatusBo;
import com.glsx.service.IOpenApiHTTPService;
import com.glsx.service.component.OpenApiInvoker;
import com.glsx.utils.SystemProperty;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @author fengzhi
* @version V1.0
* @Description: http协议接口实现类
*/
@Service
public class OpenApiHTTPServiceImpl extends BaseService implements IOpenApiHTTPService {
@Autowired
OpenApiInvoker apiInvoker;
@SysLog
@Override
public void postCommands(CommandsBo commandsBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_POST_COMMANDS);
Map<String, Object> params = new HashMap<>();
params.put("sn", commandsBo.getSn());
params.put("device_type", commandsBo.getDevice_type());
params.put("commandid", commandsBo.getCommandid());
params.put("command", commandsBo.getCommand());
String jsonRes = apiInvoker.invokCommandOrDeviceStatus(methodName, params);
JSONObject jsonObj = JSONObject.fromObject(jsonRes);
boolean isSuccess= jsonObj.getBoolean("success");
if(!isSuccess){
String msg = jsonObj.getString("msg");
logi("postCommands=====Failed====msg:"+msg);
throw new ApiException(msg);
}
}
@SysLog
@Override
public Map<String, Integer> getDeviceStatus(DeviceStatusBo deviceStatusBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_DEVICE_STATUS);
Map<String, Object> params = new HashMap<>();
params.put("sn", deviceStatusBo.getSn());
params.put("device_type", deviceStatusBo.getDevice_type());
String jsonRes = apiInvoker.invokCommandOrDeviceStatus(methodName, params);
JSONObject jsonObj = JSONObject.fromObject(jsonRes);
boolean isSuccess= jsonObj.getBoolean("success");
if(!isSuccess){
String msg = jsonObj.getString("msg");
logi("getDeviceStatus=====Failed====msg:"+msg);
throw new ApiException(msg);
}
JSONObject result = jsonObj.getJSONObject("result");
Integer status = result.getInt("status");
Map<String, Integer> map = new HashMap<>();
map.put("status", status);
return map;
}
@Override
public String getFenceTriggerRecords(DeviceDateBo deviceDateBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_FENCE_RECORD);
Map<String, Object> params = new HashMap<>();
params.put("sn", deviceDateBo.getSn());
params.put("device_type", deviceDateBo.getDevice_type());
params.put("start_date", deviceDateBo.getStart_date());
params.put("end_date", deviceDateBo.getEnd_date());
return apiInvoker.invokeFenceOrRescue(methodName, params);
}
@Override
public String getRescueEventRecords(DeviceSdeviceDateBo deviceDateBo) {
String methodName = SystemProperty.getProperty(OpenAPIConstant.METHOD_RESCUE_RECORD);
Map<String, Object> params = new HashMap<>();
params.put("sn", deviceDateBo.getSn());
//这里的type为string(SOS:紧急救援,COLLIDE:碰撞,CUSTOMER_SUBMIT 客服提交)
params.put("device_type", deviceDateBo.getDevice_type());
params.put("start_date", deviceDateBo.getStart_date());
params.put("end_date", deviceDateBo.getEnd_date());
return apiInvoker.invokeFenceOrRescue(methodName, params);
}
}