zhangqian 1 年之前
父节点
当前提交
ddfd51d103

+ 8 - 0
pom.xml

@@ -93,6 +93,14 @@
                     </dependency>
                 </dependencies>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>8</source>
+                    <target>8</target>
+                </configuration>
+            </plugin>
         </plugins>
         <!--扫描指定的配置文件 如果mapper的xml文件没有放在resources目录下,而是放在了和接口类在一起的包,这里就必须配置-->
         <resources>

+ 77 - 1
src/main/java/com/greentech/gateservice/task/GateLogService.java

@@ -1,12 +1,88 @@
 package com.greentech.gateservice.task;
 
+import com.greentech.gateservice.util.LoginModule;
+import com.netsdk.common.Res;
+import com.netsdk.lib.NetSDKLib;
+import com.netsdk.lib.ToolKits;
+import com.sun.jna.Memory;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
+import java.util.Calendar;
+
 @Service
 public class GateLogService {
     @Scheduled(cron = "0 * * * * *")
     public void syncLog() {
-        System.out.println("hello");
+        System.out.println("--开始执行日志查询同步任务--");
+        //获取前一小时
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime startTime = now.minusHours(1);
+        NetSDKLib.NET_TIME s = new NetSDKLib.NET_TIME();
+        s.setTime(startTime.getYear(),startTime.getMonthValue(),startTime.getDayOfMonth(),0,0,0);
+        NetSDKLib.NET_TIME e = new NetSDKLib.NET_TIME();
+        e.setTime(startTime.getYear(),startTime.getMonthValue(),startTime.getDayOfMonth(),23,59,59);
+
+        synchronized(LoginModule.lock){
+            for (NetSDKLib.LLong key : LoginModule.m_stDeviceInfo.keySet()) {
+                //获取handle句柄和设备信息
+                NetSDKLib.NET_DEVICEINFO_Ex value = LoginModule.m_stDeviceInfo.get(key);
+                System.out.println("Key: " + key + ", Value: " + value);
+
+                //查询逻辑
+                NetSDKLib.NET_IN_FIND_RECORD_PARAM inParam = new NetSDKLib.NET_IN_FIND_RECORD_PARAM();
+                inParam.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_ACCESSCTLCARDREC_EX;
+                //查询条件
+                NetSDKLib.FIND_RECORD_ACCESSCTLCARDREC_CONDITION_EX condition = new NetSDKLib.FIND_RECORD_ACCESSCTLCARDREC_CONDITION_EX();
+                condition.bTimeEnable = 1;
+                condition.stStartTime = s;
+                condition.stEndTime = e;
+                inParam.pQueryCondition = new Memory(condition.size());
+                ToolKits.SetStructDataToPointer(condition, inParam.pQueryCondition, 0);
+                NetSDKLib.NET_OUT_FIND_RECORD_PARAM outParam = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM();
+                boolean f = LoginModule.netsdk.CLIENT_FindRecord(key,inParam,outParam,5000);
+                if (!f) {
+                    System.err.println("查询日志失败1!");
+                    return;
+                }
+                System.out.println("CLIENT_FindRecord success!");
+
+                int max = 100;
+                NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM inNextParam = new NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM();
+                inNextParam.lFindeHandle = outParam.lFindeHandle;
+                inNextParam.nFileCount = max;
+
+                NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM outNextParam = new NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM();
+                outNextParam.nMaxRecordNum = max;
+
+                NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARDREC[] rets = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARDREC[max];
+                for (int i = 0; i < max; i++) {
+                    rets[i] = new NetSDKLib.NET_RECORDSET_ACCESS_CTL_CARDREC();
+                }
+                outNextParam.pRecordList = new Memory(rets[0].size() * max);
+                ToolKits.SetStructArrToPointerData(rets, outNextParam.pRecordList);
+                boolean f2 = LoginModule.netsdk.CLIENT_FindNextRecord(inNextParam, outNextParam, 5000);
+                if (!f2) {
+                    System.err.println("查询日志失败2!");
+                    return;
+                }
+                System.out.println("CLIENT_FindNextRecord success!");
+                ToolKits.GetPointerDataToStructArr(outNextParam.pRecordList, rets);
+
+                System.out.println("查询到的结果数量:"+outNextParam.nRetRecordNum+"最大数量:"+outNextParam.nMaxRecordNum);
+                for (int i = 0; i < outNextParam.nRetRecordNum; i++) {
+                    String szCardName = new String(rets[i].szCardName);
+                    String openMethod = Res.string().getOpenMethods(rets[i].emMethod);
+                    System.out.println("人名:" + szCardName + "时间:" + rets[i].stuTime.toStringTime() + "开门方式" + openMethod);
+                    System.out.println("开门方向:"+rets[i].emDirection);
+                    //bStatus 开门结果
+                }
+
+                LoginModule.netsdk.CLIENT_FindRecordClose(outParam.lFindeHandle);
+                System.out.println("查询结束");
+            }
+        }
+        System.out.println("--结束执行日志查询同步任务--");
     }
 }

+ 2 - 0
src/main/java/com/greentech/gateservice/util/LoginModule.java

@@ -20,6 +20,8 @@ public class LoginModule {
     //登录句柄 设备 map k:登录句柄 v:设备信息
     public static HashMap<LLong, NetSDKLib.NET_DEVICEINFO_Ex> m_stDeviceInfo = new HashMap<>();
 
+    public static final Object lock = new Object();
+
     private static boolean bInit    = false;
     private static boolean bLogopen = false;