wxr
2022-10-28 bab36f8002d92e7125dfc40023f566266e3fdb38
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
package com.common.openapi;
 
import android.os.Message;
 
import com.common.openapi.entity.CloudRecordsData;
import com.common.openapi.entity.ControlMovePTZData;
import com.common.openapi.entity.DeleteCloudRecordsData;
import com.common.openapi.entity.LocalRecordsData;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessException;
import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.BusinessRunnable;
import com.mm.android.deviceaddmodule.mobilecommon.base.LCBusinessHandler;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.BusinessErrorTip;
import com.mm.android.deviceaddmodule.mobilecommon.businesstip.HandleMessageCode;
 
public class DeviceRecordService {
 
    /**
     * 倒序查询设备云录像片段
     *
     * @param cloudRecordsData
     * @param cloudRecordCallBack
     */
    public void getCloudRecords(final CloudRecordsData cloudRecordsData, final IGetDeviceInfoCallBack.IDeviceCloudRecordCallBack cloudRecordCallBack) {
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (cloudRecordCallBack == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    cloudRecordCallBack.deviceCloudRecord((CloudRecordsData.Response) msg.obj);
                } else {
                    //失败
                    cloudRecordCallBack.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    CloudRecordsData.Response response = DeviceInfoOpenApiManager.getCloudRecords(cloudRecordsData);
                    handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    /**
     * 查询设备设备录像片段
     *
     * @param localRecordsData
     * @param deviceLocalRecordCallBack
     */
    public void queryLocalRecords(final LocalRecordsData localRecordsData, final IGetDeviceInfoCallBack.IDeviceLocalRecordCallBack deviceLocalRecordCallBack) {
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (deviceLocalRecordCallBack == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    deviceLocalRecordCallBack.deviceLocalRecord((LocalRecordsData.Response) msg.obj);
                } else {
                    //失败
                    deviceLocalRecordCallBack.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    LocalRecordsData.Response response = DeviceInfoOpenApiManager.queryLocalRecords(localRecordsData);
                    handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    public void queryCloudUse(final String deviceId, final String channelId, final IGetDeviceInfoCallBack.ICommon iCommon){
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (iCommon == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    iCommon.onCommonBack(msg.obj);
                } else {
                    //失败
                    iCommon.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    int response = DeviceInfoOpenApiManager.queryCloudUse(deviceId,channelId);
                    handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    public void querySDUse(final String deviceId, final IGetDeviceInfoCallBack.ICommon iCommon){
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (iCommon == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    iCommon.onCommonBack(msg.obj);
                } else {
                    //失败
                    iCommon.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    String response = DeviceInfoOpenApiManager.querySDState(deviceId);
                    handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, response).sendToTarget();
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    /**
     * 云台移动控制接口(V2版本)
     *
     * @param controlMovePTZData
     */
    public void controlMovePTZ(final ControlMovePTZData controlMovePTZData) {
        new BusinessRunnable(new LCBusinessHandler() {
 
            @Override
            public void handleBusiness(Message msg) {
            }
        }) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    DeviceInfoOpenApiManager.controlMovePTZ(controlMovePTZData);
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
 
    /**
     * 删除设备云录像片段
     *
     * @param deleteCloudRecordsData
     * @param deviceDeleteRecordCallBack
     */
    public void deleteCloudRecords(final DeleteCloudRecordsData deleteCloudRecordsData, final IGetDeviceInfoCallBack.IDeviceDeleteRecordCallBack deviceDeleteRecordCallBack) {
        final LCBusinessHandler handler = new LCBusinessHandler() {
            @Override
            public void handleBusiness(Message msg) {
                if (deviceDeleteRecordCallBack == null) {
                    return;
                }
                if (msg.what == HandleMessageCode.HMC_SUCCESS) {
                    //成功
                    deviceDeleteRecordCallBack.deleteDeviceRecord();
                } else {
                    //失败
                    deviceDeleteRecordCallBack.onError(BusinessErrorTip.throwError(msg));
                }
            }
        };
        new BusinessRunnable(handler) {
            @Override
            public void doBusiness() throws BusinessException {
                try {
                    for (String id : deleteCloudRecordsData.data.recordRegionIds) {
                        DeviceInfoOpenApiManager.deleteCloudRecords(id);
                    }
                    handler.obtainMessage(HandleMessageCode.HMC_SUCCESS, null).sendToTarget();
                } catch (BusinessException e) {
                    throw e;
                }
            }
        };
    }
}