hxb
2022-11-24 535d69817e83737f3da6250fc6fb70da25fc1a4c
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package com.common.openapi;
 
import com.common.openapi.entity.CloudRecordsData;
import com.common.openapi.entity.ControlMovePTZData;
import com.common.openapi.entity.DeviceAlarmStatusData;
import com.common.openapi.entity.DeviceChannelInfoData;
import com.common.openapi.entity.DeviceDetailListData;
import com.common.openapi.entity.DeviceListData;
import com.common.openapi.entity.DeviceModifyNameData;
import com.common.openapi.entity.DeviceUnBindData;
import com.common.openapi.entity.DeviceVersionListData;
import com.common.openapi.entity.LocalRecordsData;
import com.common.openapi.entity.SubAccountDeviceData;
import com.google.gson.JsonObject;
import com.mm.android.deviceaddmodule.LCDeviceEngine;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
import com.mm.android.deviceaddmodule.openapi.HttpSend;
 
import java.util.HashMap;
 
public class DeviceInfoOpenApiManager {
 
    private static int TIME_OUT = 10 * 1000;
    private static int DMS_TIME_OUT = 45 * 1000;
 
    /**
     * 分页获取乐橙app添加或分享的设备通道基本信息
     *
     * @param deviceListData
     * @return
     * @throws BusinessException
     */
    public static DeviceListData.Response deviceBaseList(DeviceListData deviceListData) throws BusinessException {
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("bindId", deviceListData.data.baseBindId);
        paramsMap.put("limit", deviceListData.data.limit);
        paramsMap.put("type", deviceListData.data.type);
        paramsMap.put("needApInfo", deviceListData.data.needApInfo);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_BASE_LIST,TIME_OUT);
        DeviceListData.Response response = new DeviceListData.Response();
        response.parseData(json);
        return response;
    }
 
    /**
     * 分页获取开放平台添加设备的通道基本信息
     *
     * @param deviceListData
     * @return
     * @throws BusinessException
     */
    public static DeviceListData.Response deviceOpenList(DeviceListData deviceListData) throws BusinessException {
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("bindId", deviceListData.data.openBindId);
        paramsMap.put("limit", deviceListData.data.limit);
        paramsMap.put("type", deviceListData.data.type);
        paramsMap.put("needApInfo", deviceListData.data.needApInfo);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_OPEN_LIST,TIME_OUT);
        DeviceListData.Response response = new DeviceListData.Response();
        response.parseData(json);
        return response;
    }
 
    /**
     * 批量根据设备序列号、通道号列表和配件号列表,获取设备的详细信息
     *
     * @param deviceDetailListData
     * @return
     * @throws BusinessException
     */
    public static DeviceDetailListData.Response deviceOpenDetailList(DeviceDetailListData deviceDetailListData) throws BusinessException {
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceList", deviceDetailListData.data.deviceList);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_OPEN_DETAIL_LIST,TIME_OUT);
        DeviceDetailListData.Response response = new DeviceDetailListData.Response();
        response.parseData(json);
        return response;
    }
 
    /**
     * 批量根据设备序列号、通道号列表和配件号列表,获取乐橙app添加或分享的设备的详细信息
     *
     * @param deviceDetailListData
     * @return
     * @throws BusinessException
     */
    public static DeviceDetailListData.Response deviceBaseDetailList(DeviceDetailListData deviceDetailListData) throws BusinessException {
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceList", deviceDetailListData.data.deviceList);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_BASE_DETAIL_LIST,TIME_OUT);
        DeviceDetailListData.Response response = new DeviceDetailListData.Response();
        response.parseData(json);
        return response;
    }
 
    /**
     * 解绑设备
     *
     * @param deviceUnBindData
     * @return
     * @throws BusinessException
     */
    public static boolean unBindDevice(DeviceUnBindData deviceUnBindData) throws BusinessException {
        // 解绑设备
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
        paramsMap.put("deviceId", deviceUnBindData.data.deviceId);
        HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_UN_BIND,TIME_OUT);
        return true;
    }
 
    public static boolean deletePermission(String deviceId,String channelId) throws BusinessException{
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("openid", LCDeviceEngine.newInstance().openid);
        paramsMap.put("channelId", channelId);
        paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
        paramsMap.put("deviceId", deviceId);
        HttpSend.execute(paramsMap, MethodConst.DELETE_DEVICE_PERMISSION,TIME_OUT);
        return true;
    }
 
    public static boolean recoverSDCard(String deviceId) throws BusinessException{
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
        paramsMap.put("deviceId", deviceId);
        HttpSend.execute(paramsMap, MethodConst.RECOVER_SDCARD,TIME_OUT);
        return true;
    }
 
    /**
     * 获取设备版本和可升级信息
     *
     * @param deviceVersionListData
     * @return
     * @throws BusinessException
     */
    public static DeviceVersionListData.Response deviceVersionList(DeviceVersionListData deviceVersionListData) throws BusinessException {
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceIds", deviceVersionListData.data.deviceIds);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_VERSION_LIST,TIME_OUT);
        DeviceVersionListData.Response response = new DeviceVersionListData.Response();
        response.parseData(json);
        return response;
    }
 
    /**
     * 修改设备或通道名称
     *
     * @param deviceModifyNameData
     * @return
     * @throws BusinessException
     */
    public static boolean modifyDeviceName(DeviceModifyNameData deviceModifyNameData) throws BusinessException {
        // 解绑设备
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", deviceModifyNameData.data.deviceId);
        paramsMap.put("channelId", deviceModifyNameData.data.channelId);
        paramsMap.put("name", deviceModifyNameData.data.name);
        HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_MODIFY_NAME,TIME_OUT);
        return true;
    }
 
    /**
     * 单个设备通道的详细信息获取
     *
     * @param deviceChannelInfoData
     * @return
     * @throws BusinessException
     */
    public static DeviceChannelInfoData.Response bindDeviceChannelInfo(DeviceChannelInfoData deviceChannelInfoData) throws BusinessException {
        // 单个设备通道的详细信息获取
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", deviceChannelInfoData.data.deviceId);
        paramsMap.put("channelId", deviceChannelInfoData.data.channelId);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_CHANNEL_INFO, DMS_TIME_OUT);
        DeviceChannelInfoData.Response response = new DeviceChannelInfoData.Response();
        response.parseData(json);
        return response;
    }
 
    /**
     * 设置动检开关
     *
     * @param deviceAlarmStatusData
     * @return
     * @throws BusinessException
     */
    public static boolean modifyDeviceAlarmStatus(DeviceAlarmStatusData deviceAlarmStatusData) throws BusinessException {
        // 解绑设备
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", deviceAlarmStatusData.data.deviceId);
        paramsMap.put("channelId", deviceAlarmStatusData.data.channelId);
        paramsMap.put("enable", deviceAlarmStatusData.data.enable);
        HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_MODIFY_ALARM_STATUS, DMS_TIME_OUT);
        return true;
    }
 
    /**
     * 设备升级
     *
     * @param deviceId
     * @return
     * @throws BusinessException
     */
    public static boolean upgradeDevice(String deviceId) throws BusinessException {
        // 解绑设备
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", deviceId);
        try{
            JsonObject execute = HttpSend.execute(paramsMap, MethodConst.METHOD_DEVICE_UPDATE, DMS_TIME_OUT);
            if(execute!=null){
                return true;
            }else{
                return false;
            }
        }catch (Exception e){
            return false;
        }
 
 
    }
 
    /**
     * 倒序查询设备云录像片段
     *
     * @param cloudRecordsData
     * @return
     * @throws BusinessException
     */
    public static CloudRecordsData.Response getCloudRecords(CloudRecordsData cloudRecordsData) throws BusinessException {
        // 倒序查询设备云录像片段
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", cloudRecordsData.data.deviceId);
        paramsMap.put("channelId", cloudRecordsData.data.channelId);
        paramsMap.put("beginTime", cloudRecordsData.data.beginTime);
        paramsMap.put("endTime", cloudRecordsData.data.endTime);
//        paramsMap.put("nextRecordId", cloudRecordsData.data.nextRecordId);
        paramsMap.put("count", cloudRecordsData.data.count);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_GET_CLOUND_RECORDS,TIME_OUT);
        CloudRecordsData.Response response = new CloudRecordsData.Response();
        response.parseData(json);
        return response;
    }
 
    /**
     * 查询设备设备录像片段
     *
     * @param localRecordsData
     * @return
     * @throws BusinessException
     */
    public static LocalRecordsData.Response queryLocalRecords(LocalRecordsData localRecordsData) throws BusinessException {
        // 查询设备设备录像片段
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", localRecordsData.data.deviceId);
        paramsMap.put("channelId", localRecordsData.data.channelId);
        paramsMap.put("beginTime", localRecordsData.data.beginTime);
        paramsMap.put("endTime", localRecordsData.data.endTime);
        paramsMap.put("type", localRecordsData.data.type);
        paramsMap.put("queryRange", localRecordsData.data.queryRange);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.METHOD_QUERY_LOCAL_RECORD, DMS_TIME_OUT);
        LocalRecordsData.Response response = new LocalRecordsData.Response();
        response.parseData(json);
        return response;
    }
 
    public static int queryCloudUse(String deviceId,String channelId) throws BusinessException{
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", deviceId);
        paramsMap.put("channelId", channelId);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.GET_DEVICE_CLOUD, DMS_TIME_OUT);
        Integer state = json.get("strategyStatus").getAsInt();
        return state;
    }
 
    public static String  querySDState(String deviceId) throws BusinessException{
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", deviceId);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.SD_STATUE_QUERY, DMS_TIME_OUT);
        String state = json.get("status").getAsString();
        return state;
    }
 
    /**
     * 云台移动控制接口(V2版本)
     *
     * @param controlMovePTZData
     * @return
     * @throws BusinessException
     */
    public static void controlMovePTZ(ControlMovePTZData controlMovePTZData) throws BusinessException {
        // 云台移动控制接口(V2版本)
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("deviceId", controlMovePTZData.data.deviceId);
        paramsMap.put("channelId", controlMovePTZData.data.channelId);
        paramsMap.put("operation", controlMovePTZData.data.operation);
        paramsMap.put("duration", controlMovePTZData.data.duration);
        HttpSend.execute(paramsMap, MethodConst.METHOD_CONTROL_MOVE_PTZ, DMS_TIME_OUT);
    }
 
    /**
     * 删除设备云录像片段
     *
     * @param recordRegionId
     * @return
     * @throws BusinessException
     */
    public static boolean deleteCloudRecords(String recordRegionId) throws BusinessException {
        // 删除设备云录像片段
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("recordRegionId", recordRegionId);
        HttpSend.execute(paramsMap, MethodConst.METHOD_DELETE_CLOUND_RECORDS,TIME_OUT);
        return true;
    }
 
    //V7.12新增
    public static SubAccountDeviceData.Response getSubAccountDeviceListLight(int pageNo, int pageSize, String openid)throws BusinessException{
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().accessToken);
        paramsMap.put("pageNo", pageNo);
        paramsMap.put("pageSize",pageSize);
        paramsMap.put("openid",openid);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.LIST_SUB_ACCOUNT_DEVICE,TIME_OUT);
        SubAccountDeviceData.Response response = new SubAccountDeviceData.Response();
        response.parseData(json);
        return  response;
    }
 
    public static DeviceDetailListData.Response getSubAccountDeviceList(int pageNo, int pageSize)throws BusinessException{
        HashMap<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("token", LCDeviceEngine.newInstance().subAccessToken);
        paramsMap.put("page", pageNo);
        paramsMap.put("pageSize",pageSize);
        JsonObject json = HttpSend.execute(paramsMap, MethodConst.SUB_ACCOUNT_DEVICE_LIST,TIME_OUT);
        DeviceDetailListData.Response response = new DeviceDetailListData.Response();
        response.parseData(json);
        return  response;
    }
 
}