houzhongjian
2024-12-27 12db859ea1485e676b6e11927946cb50f79e27a8
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.vto;
H 2
3 import com.sun.jna.Callback;
4 import com.sun.jna.Pointer;
5 import com.iailab.netsdk.common.PaintPanel;
6 import com.iailab.netsdk.common.Res;
7 import com.iailab.netsdk.common.SavePath;
8 import com.iailab.netsdk.lib.NetSDKLib;
9 import com.iailab.netsdk.lib.ToolKits;
10
11 import javax.imageio.ImageIO;
12 import javax.swing.*;
13 import javax.swing.table.DefaultTableModel;
14
15 import java.awt.image.BufferedImage;
16 import java.io.ByteArrayInputStream;
17 import java.io.File;
18 import java.io.IOException;
19
7412dd 20 import static com.iailab.netsdk.lib.NetSDKLib.EVENT_IVS_ACCESS_CTL;
149dd0 21
H 22 /**
23  * @author 47081
24  * @version 1.0
25  * @description vto智能分析的回调函数, 建议写成单例模式
26  * 对应接口 {@link NetSDKLib#CLIENT_RealLoadPictureEx(NetSDKLib.LLong, int, int, int, Callback, Pointer, Pointer)}
27  * @date 2020/8/15
28  */
29 public class VTOAnalyzerCallBack implements NetSDKLib.fAnalyzerDataCallBack {
30     private static VTOAnalyzerCallBack INSTANCE;
31     private JTable table;
32     private PaintPanel paintPanel;
33     private BufferedImage bufferedImage;
34
35     private VTOAnalyzerCallBack(JTable table,PaintPanel panel) {
36         this.table = table;
37         this.paintPanel=panel;
38     }
39
40     public static VTOAnalyzerCallBack getINSTANCE(JTable table,PaintPanel paintPanel) {
41         if (INSTANCE == null) {
42             INSTANCE = new VTOAnalyzerCallBack(table,paintPanel);
43         }
44         return INSTANCE;
45     }
46
47     @Override
48     public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, Pointer dwUser, int nSequence, Pointer reserved) {
49         //门禁事件
50         if (dwAlarmType == EVENT_IVS_ACCESS_CTL) {
51             NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO info = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO();
52             ToolKits.GetPointerDataToStruct(pAlarmInfo, 0, info);
53             //更新列表
54             if(table!=null){
55                 DefaultTableModel model= (DefaultTableModel) table.getModel();
56                 NetSDKLib.NET_TIME_EX time=info.UTC;
57                 if(info.UTC.dwYear==0&&info.UTC.dwMonth==0&&info.UTC.dwDay==0){
58                     time=info.stuFileInfo.stuFileTime;
59                 }
60                 model.addRow(new Object[]{new String(info.szUserID).trim(),new String(info.szCardNo).trim(),time.toString().trim(),getEventInfo(info).trim()});
61             }
62             if(pBuffer != null && dwBufSize > 0) {
63                 String strFileName = SavePath.getSavePath().getSaveCapturePath();
64                 byte[] buf = pBuffer.getByteArray(0, dwBufSize);
65                 ByteArrayInputStream byteArrInput = new ByteArrayInputStream(buf);
66                 try {
67                     bufferedImage = ImageIO.read(byteArrInput);
68                     if (bufferedImage == null) {
69                         return 0;
70                     }
71                     ImageIO.write(bufferedImage, "jpg", new File(strFileName));
72                 } catch (IOException e) {
73                     e.printStackTrace();
74                 }
75
76                 // 界面显示抓图
77                 SwingUtilities.invokeLater(new Runnable() {
78                     @Override
79                     public void run() {
80                         paintPanel.setOpaque(false);
81                         paintPanel.setImage(bufferedImage);
82                         paintPanel.repaint();
83                     }
84                 });
85             }
86         }
87         return 1;
88     }
89
90     /**
91      * 获取事件信息
92      * @param info
93      * @return
94      */
95     private String getEventInfo(NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO info){
96         StringBuilder builder=new StringBuilder();
97         builder.append(Res.string().getChannel()).append(info.nChannelID).append(",")
98                 .append(Res.string().getOpenMethod()).append(openDoorMethod(info.emOpenMethod)).append(",")
99                 .append(Res.string().getOpenStatus()).append(info.bStatus==1?Res.string().getSucceed():Res.string().getFailed());
100         return builder.toString();
101     }
102     /**
103      * 开门方式
104      * @param emOpenMethod
105      * @return
106      */
107     private String openDoorMethod(int emOpenMethod) {
108         String method;
109         switch (emOpenMethod) {
110             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_CARD:
111                 method = Res.string().getCard();
112                 break;
113             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FACE_RECOGNITION:
114                 method = Res.string().getTargetRecognition();
115                 break;
116             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_FINGERPRINT:
117                 method = Res.string().getFingerPrint();
118                 break;
119             case NetSDKLib.NET_ACCESS_DOOROPEN_METHOD.NET_ACCESS_DOOROPEN_METHOD_REMOTE:
120                 method = Res.string().getRemoteCapture();
121                 break;
122             default:
123                 method = Res.string().getUnKnow();
124                 break;
125         }
126         return method;
127     }
128 }