whyclxw
2024-03-11 525166acab2b1219417f1e3953c0b7836995bc2c
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
package com.whyc.peopleCamera.Acs;
 
import com.sun.jna.Pointer;
import com.whyc.peopleCamera.NetSDKDemo.HCNetSDK;
import com.whyc.pojo.PeopleCarmera;
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
 
/**
 * 事件查询模块
 */
public final class EventSearch {
 
    public static void searchAllEvent(int lUserID) throws UnsupportedEncodingException, InterruptedException {
        int i = 0; //事件条数
        HCNetSDK.NET_DVR_ACS_EVENT_COND struAcsEventCond = new HCNetSDK.NET_DVR_ACS_EVENT_COND();
        struAcsEventCond.read();
        struAcsEventCond.dwSize = struAcsEventCond.size();
        //查询全部主次类型的报警
        struAcsEventCond.dwMajor = 0; // 主次事件类型设为0,代表查询所有事件
        struAcsEventCond.dwMinor = 0; //
        //开始时间
        struAcsEventCond.struStartTime.dwYear = 2022;
        struAcsEventCond.struStartTime.dwMonth = 4;
        struAcsEventCond.struStartTime.dwDay = 27;
        struAcsEventCond.struStartTime.dwHour = 9;
        struAcsEventCond.struStartTime.dwMinute = 0;
        struAcsEventCond.struStartTime.dwSecond = 0;
        //结束时间
        struAcsEventCond.struEndTime.dwYear = 2022;
        struAcsEventCond.struEndTime.dwMonth = 4;
        struAcsEventCond.struEndTime.dwDay = 30;
        struAcsEventCond.struEndTime.dwHour = 16;
        struAcsEventCond.struEndTime.dwMinute = 0;
        struAcsEventCond.struEndTime.dwSecond = 0;
        struAcsEventCond.wInductiveEventType = 1;
        struAcsEventCond.byPicEnable = 1; //是否带图片,0-不带图片,1-带图片
        struAcsEventCond.write();
        Pointer ptrStruEventCond = struAcsEventCond.getPointer();
        int m_lSearchEventHandle = AcsMain.hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_GET_ACS_EVENT, ptrStruEventCond, struAcsEventCond.size(), null, null);
        if (m_lSearchEventHandle<=-1)
        {
            System.out.println("NET_DVR_StartRemoteConfig调用失败,错误码:" + AcsMain.hCNetSDK.NET_DVR_GetLastError());
        }
        HCNetSDK.NET_DVR_ACS_EVENT_CFG struAcsEventCfg = new HCNetSDK.NET_DVR_ACS_EVENT_CFG();
        struAcsEventCfg.read();
        struAcsEventCfg.dwSize = struAcsEventCfg.size();
        struAcsEventCfg.write();
        Pointer ptrStruEventCfg = struAcsEventCfg.getPointer();
        while (true) {
            System.out.println("i=" + i);
            int dwEventSearch = AcsMain.hCNetSDK.NET_DVR_GetNextRemoteConfig(m_lSearchEventHandle, ptrStruEventCfg, struAcsEventCfg.size());
            if (dwEventSearch <= -1) {
                System.out.println("NET_DVR_GetNextRemoteConfig接口调用失败,错误码:" + AcsMain.hCNetSDK.NET_DVR_GetLastError());
            }
            if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT) {
                System.out.println("配置等待....");
                Thread.sleep(10);
                continue;
            } else if (dwEventSearch == HCNetSDK.NET_SDK_NEXT_STATUS__FINISH) {
                System.out.println("获取事件完成");
                break;
            } else if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED) {
                System.out.println("获取事件出现异常");
                break;
            } else if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS) {
                struAcsEventCfg.read();
                //获取的事件信息通过struAcsEventCfg结构体进行解析,
                System.out.println(i + "获取事件成功, 报警主类型:" + Integer.toHexString(struAcsEventCfg.dwMajor) + "报警次类型:" + Integer.toHexString(struAcsEventCfg.dwMinor) + "卡号:" + new String(struAcsEventCfg.struAcsEventInfo.byCardNo).trim());
                /**
                 * 工号有两个字段,dwEmployeeNo表示工号,当值为0时,表示无效,解析byEmployeeNo参数
                 */
                System.out.println("工号1:"+struAcsEventCfg.struAcsEventInfo.dwEmployeeNo);
                System.out.println("工号2:"+new String(struAcsEventCfg.struAcsEventInfo.byEmployeeNo));
                //人脸温度数据,需要设备和支持测温功能
                System.out.println("人脸温度:" + struAcsEventCfg.struAcsEventInfo.fCurrTemperature + "是否异常:" + struAcsEventCfg.struAcsEventInfo.byIsAbnomalTemperature);
                //口罩功能,需要设备支持此功能 0-保留,1-未知,2-不戴口罩,3-戴口罩
                System.out.println("是否带口罩:"+struAcsEventCfg.struAcsEventInfo.byMask);
                //人脸图片保存
                if (struAcsEventCfg.dwPicDataLen>0 || struAcsEventCfg.pPicData != null )
                {
                    FileOutputStream fout;
                    try {
                        /**
                         * 人脸图片保存路径
                         */
                        String filename = "..\\pic\\"+i+"_event.jpg";
                        fout = new FileOutputStream(filename);
                        //将字节写入文件
                        long offset = 0;
                        ByteBuffer buffers = struAcsEventCfg.pPicData.getByteBuffer(offset, struAcsEventCfg.dwPicDataLen);
                        byte[] bytes = new byte[struAcsEventCfg.dwPicDataLen];
                        buffers.rewind();
                        buffers.get(bytes);
                        fout.write(bytes);
                        fout.close();
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                i++;
                continue;
            }
        }
        i = 0;
        if (!AcsMain.hCNetSDK.NET_DVR_StopRemoteConfig(m_lSearchEventHandle)) {
            System.out.println("NET_DVR_StopRemoteConfig接口调用失败,错误码:" + AcsMain.hCNetSDK.NET_DVR_GetLastError());
        } else {
            System.out.println("NET_DVR_StopRemoteConfig接口成功");
        }
        return;
    }
    //获取一年内(推一年)的事件
    public static List<PeopleCarmera> getCarCameraHis_people(int lUserID) throws UnsupportedEncodingException, InterruptedException {
        //1.获取当前系统时间
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
 
        int i = 0; //事件条数
        HCNetSDK.NET_DVR_ACS_EVENT_COND struAcsEventCond = new HCNetSDK.NET_DVR_ACS_EVENT_COND();
        struAcsEventCond.read();
        struAcsEventCond.dwSize = struAcsEventCond.size();
        //查询全部主次类型的报警
        struAcsEventCond.dwMajor = 0; // 主次事件类型设为0,代表查询所有事件
        struAcsEventCond.dwMinor = 0; //
        //开始时间
        struAcsEventCond.struStartTime.dwYear = year-1;
        struAcsEventCond.struStartTime.dwMonth = month;
        struAcsEventCond.struStartTime.dwDay = day;
        struAcsEventCond.struStartTime.dwHour = 0;
        struAcsEventCond.struStartTime.dwMinute = 0;
        struAcsEventCond.struStartTime.dwSecond = 0;
        //结束时间
        struAcsEventCond.struEndTime.dwYear = year;
        struAcsEventCond.struEndTime.dwMonth = month;
        struAcsEventCond.struEndTime.dwDay = day;
        struAcsEventCond.struEndTime.dwHour = 23;
        struAcsEventCond.struEndTime.dwMinute = 59;
        struAcsEventCond.struEndTime.dwSecond = 59;
        struAcsEventCond.wInductiveEventType = 1;
        struAcsEventCond.byPicEnable = 0; //是否带图片,0-不带图片,1-带图片
        struAcsEventCond.write();
        Pointer ptrStruEventCond = struAcsEventCond.getPointer();
        int m_lSearchEventHandle = AcsMain.hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_GET_ACS_EVENT, ptrStruEventCond, struAcsEventCond.size(), null, null);
        if (m_lSearchEventHandle<=-1)
        {
            System.out.println("NET_DVR_StartRemoteConfig调用失败,错误码:" + AcsMain.hCNetSDK.NET_DVR_GetLastError());
            return null;
        }
        HCNetSDK.NET_DVR_ACS_EVENT_CFG struAcsEventCfg = new HCNetSDK.NET_DVR_ACS_EVENT_CFG();
        struAcsEventCfg.read();
        struAcsEventCfg.dwSize = struAcsEventCfg.size();
        struAcsEventCfg.write();
        Pointer ptrStruEventCfg = struAcsEventCfg.getPointer();
        List<PeopleCarmera> list=new ArrayList<>();
        while (true) {
            System.out.println("i=" + i);
            int dwEventSearch = AcsMain.hCNetSDK.NET_DVR_GetNextRemoteConfig(m_lSearchEventHandle, ptrStruEventCfg, struAcsEventCfg.size());
            if (dwEventSearch <= -1) {
                System.out.println("NET_DVR_GetNextRemoteConfig接口调用失败,错误码:" + AcsMain.hCNetSDK.NET_DVR_GetLastError());
                return null;
            }
            if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_NEED_WAIT) {
                System.out.println("配置等待....");
                Thread.sleep(10);
                continue;
            } else if (dwEventSearch == HCNetSDK.NET_SDK_NEXT_STATUS__FINISH) {
                System.out.println("获取事件完成");
                break;
            } else if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_FAILED) {
                System.out.println("获取事件出现异常");
                break;
            } else if (dwEventSearch == HCNetSDK.NET_SDK_GET_NEXT_STATUS_SUCCESS) {
                struAcsEventCfg.read();
                //获取的事件信息通过struAcsEventCfg结构体进行解析,
                /*System.out.println(i + "获取事件成功, 报警主类型:" + Integer.toHexString(struAcsEventCfg.dwMajor) + "报警次类型:" + Integer.toHexString(struAcsEventCfg.dwMinor) + "卡号:" + new String(struAcsEventCfg.struAcsEventInfo.byCardNo).trim());
                *//**
                 * 工号有两个字段,dwEmployeeNo表示工号,当值为0时,表示无效,解析byEmployeeNo参数
                 *//*
                System.out.println("工号1:"+struAcsEventCfg.struAcsEventInfo.dwEmployeeNo);
                System.out.println("工号2:"+new String(struAcsEventCfg.struAcsEventInfo.byEmployeeNo));
                //人脸温度数据,需要设备和支持测温功能
                System.out.println("人脸温度:" + struAcsEventCfg.struAcsEventInfo.fCurrTemperature + "是否异常:" + struAcsEventCfg.struAcsEventInfo.byIsAbnomalTemperature);
                //口罩功能,需要设备支持此功能 0-保留,1-未知,2-不戴口罩,3-戴口罩
                System.out.println("是否带口罩:"+struAcsEventCfg.struAcsEventInfo.byMask);*/
                PeopleCarmera pc=new PeopleCarmera();
                pc.setCarId(new String(struAcsEventCfg.struAcsEventInfo.byCardNo).trim());
                pc.setEventType(struAcsEventCfg.dwMajor);
                if(struAcsEventCfg.struAcsEventInfo.dwEmployeeNo==0){
                    pc.setEmployeeNo(new String(struAcsEventCfg.struAcsEventInfo.byEmployeeNo));
                }else{
                    pc.setEmployeeNo(String.valueOf(struAcsEventCfg.struAcsEventInfo.dwEmployeeNo));
                }
                pc.setFCurrTemperature(struAcsEventCfg.struAcsEventInfo.fCurrTemperature);
                pc.setByIsAbnomalTemperature(struAcsEventCfg.struAcsEventInfo.byIsAbnomalTemperature);
                pc.setByMask(struAcsEventCfg.struAcsEventInfo.byMask);
                list.add(pc);
                //人脸图片保存
                if (struAcsEventCfg.dwPicDataLen>0 || struAcsEventCfg.pPicData != null )
                {
                    FileOutputStream fout;
                    try {
                        /**
                         * 人脸图片保存路径
                         */
                        String filename = "..\\pic\\"+i+"_event.jpg";
                        fout = new FileOutputStream(filename);
                        //将字节写入文件
                        long offset = 0;
                        ByteBuffer buffers = struAcsEventCfg.pPicData.getByteBuffer(offset, struAcsEventCfg.dwPicDataLen);
                        byte[] bytes = new byte[struAcsEventCfg.dwPicDataLen];
                        buffers.rewind();
                        buffers.get(bytes);
                        fout.write(bytes);
                        fout.close();
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                i++;
                continue;
            }
        }
        i = 0;
        if (!AcsMain.hCNetSDK.NET_DVR_StopRemoteConfig(m_lSearchEventHandle)) {
            System.out.println("NET_DVR_StopRemoteConfig接口调用失败,错误码:" + AcsMain.hCNetSDK.NET_DVR_GetLastError());
            return null;
        } else {
            System.out.println("NET_DVR_StopRemoteConfig接口成功");
        }
        return list;
    }
 
}