Browse Source

添加日志更新接口

zhangqian 1 year ago
parent
commit
f8fc7bc359

+ 30 - 2
src/main/java/com/greentech/gateservice/task/GateLogService.java

@@ -1,5 +1,7 @@
 package com.greentech.gateservice.task;
 
+import com.greentech.gateservice.entity.GateOplog;
+import com.greentech.gateservice.mapper.GateOplogMapper;
 import com.greentech.gateservice.util.LoginModule;
 import com.netsdk.common.Res;
 import com.netsdk.lib.NetSDKLib;
@@ -7,15 +9,25 @@ import com.netsdk.lib.ToolKits;
 import com.sun.jna.Memory;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestMapping;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Date;
 
+@RequestMapping("crud")
 @Service
 public class GateLogService {
+    GateOplogMapper gateOplogMapper;
+
     @Scheduled(cron = "0 * * * * *")
     public void syncLog() {
         System.out.println("--开始执行日志查询同步任务--");
+        String format = "yyyy-MM-dd HH:mm:ss";
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
         //获取前一小时
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime startTime = now.minusHours(1);
@@ -74,11 +86,27 @@ public class GateLogService {
                 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("人名:" + szCardName + "时间:" + rets[i].stuTime.toStringTimeEx() + "开门方式" + openMethod);
                     System.out.println("开门方向:"+rets[i].emDirection);
                     //bStatus 开门结果
-                }
+                    GateOplog opLog = new GateOplog();
+                    opLog.setGateName("");
+                    opLog.setProjectId(0);
+                    opLog.setUserName(szCardName);
+                    opLog.setEventType(openMethod);
+                    opLog.setStatus("");
+                    opLog.setSerialNum(new String(value.sSerialNumber));
 
+                    Date d = new Date();
+                    try {
+                        d = sdf.parse(rets[i].stuTime.toStringTimeEx());
+                    }catch (ParseException excep) {
+                        System.err.println("解析时间发生错误: " + excep.getMessage());
+                    }
+                    opLog.setCreatedTime(d);
+                    gateOplogMapper.insert(opLog);
+                }
+                //断开查询句柄
                 LoginModule.netsdk.CLIENT_FindRecordClose(outParam.lFindeHandle);
                 System.out.println("查询结束");
             }

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

@@ -17,7 +17,7 @@ public class LoginModule {
     public static NetSDKLib netsdk 		= NetSDKLib.NETSDK_INSTANCE;
     public static NetSDKLib configsdk 	= NetSDKLib.CONFIG_INSTANCE;
 
-    //登录句柄 设备 map k:登录句柄 v:设备信息
+    //登录句柄 设备 map k:登录句柄 v:设备信息 调用时需加锁
     public static HashMap<LLong, NetSDKLib.NET_DEVICEINFO_Ex> m_stDeviceInfo = new HashMap<>();
 
     public static final Object lock = new Object();
@@ -29,7 +29,7 @@ public class LoginModule {
     public static boolean init(NetSDKLib.fDisConnect disConnect, NetSDKLib.fHaveReConnect haveReConnect) {
         bInit = netsdk.CLIENT_Init(disConnect, null);
         if(!bInit) {
-            System.out.println("Initialize SDK failed");
+            System.err.println("Initialize SDK failed");
             return false;
         }