Browse Source

学生、教师导入

brealinxx 9 months ago
parent
commit
385eca420c

+ 9 - 0
src/main/java/com/xjrsoft/module/hikvision/util/ApiUtil.java

@@ -2,6 +2,7 @@ package com.xjrsoft.module.hikvision.util;
 
 import com.hikvision.artemis.sdk.ArtemisHttpUtil;
 import com.hikvision.artemis.sdk.config.ArtemisConfig;
+import org.apache.http.HttpResponse;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -64,4 +65,12 @@ public class ApiUtil {
     public String doPost(String apiPath, String body, Map<String, String> querys){
         return doPost(apiPath, body, querys, null);
     }
+
+    public static String GetRedirectURL(String uri){
+        if (uri != null)
+            return "https://" + ApiUtil.host + "/" + uri;
+        else
+            return null;
+    }
+
 }

+ 2 - 2
src/main/java/com/xjrsoft/module/hikvision/util/DataUtil.java

@@ -479,8 +479,8 @@ public class DataUtil {
             JsonObject paramJson = new JsonObject();
             paramJson.addProperty("clientId", clientId);
             paramJson.addProperty("plateNo", carMessageApply.getCarNumber());
-            System.out.println(faceImportMapper.GetHikvisonPersonId(carMessageApply.getId().toString()) + "heihei");
-            System.out.println(faceImportMapper.GetHikvisonPersonId(carMessageApply.getId().toString()) + "xixi");
+            System.out.println(faceImportMapper.GetHikvisonPersonId(carMessageApply.getId().toString()));
+            System.out.println(faceImportMapper.GetHikvisonPersonId(carMessageApply.getId().toString()));
             paramJson.addProperty("personId", faceImportMapper.GetHikvisonPersonId(carMessageApply.getId().toString()));
 
             int vehicleTypeNum;

+ 19 - 19
src/main/java/com/xjrsoft/module/hikvision/util/Teacher_Student_OutIn_RecordUtil.java

@@ -5,17 +5,12 @@ import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
-import com.xjrsoft.common.constant.GlobalConstant;
-import com.xjrsoft.common.utils.DatasourceUtil;
 import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
-import org.springframework.beans.factory.annotation.Autowired;
 
-import javax.sql.DataSource;
 import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
 
@@ -43,7 +38,7 @@ public class Teacher_Student_OutIn_RecordUtil {
         db.execute(sql);
     }
 
-    public String GetDoorEvents(Db use, FaceImportMapper faceImportMapper) throws SQLException {
+    public String GetDoorEvents(Db use, FaceImportMapper faceImportMapper) throws SQLException, ParseException {
         ApiUtil apiUtil = new ApiUtil();
 
         String apiPath = "/api/acs/v2/door/events";
@@ -76,8 +71,7 @@ public class Teacher_Student_OutIn_RecordUtil {
     }
 
 
-    public void InsertTeacherStudentRecords(Db use, JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws SQLException {
-//        for (JsonElement e : doorEventsResponse){
+    public void InsertTeacherStudentRecords(Db use, JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws SQLException, ParseException {
         Teacher_Student_OutIn_RecordUtil teacherStudentOutInRecordUtil = new Teacher_Student_OutIn_RecordUtil();
         List<String> teacherEventIdList = faceImportMapper.GetTeacherUrlList();
         List<String> studentEventIdList = faceImportMapper.GetStudentUrlList();
@@ -94,24 +88,23 @@ public class Teacher_Student_OutIn_RecordUtil {
             if (personId == null) continue;
 
             int status = item.get("inAndOutType").getAsInt();
-            String photo = item.get("picUri").isJsonNull() ? null : item.get("picUri").getAsString();
+            String uri = item.get("picUri").isJsonNull() ? null : item.get("picUri").getAsString();
             String recordTime = item.get("eventTime").isJsonNull() ? null : item.get("eventTime").getAsString();
             String eventId = item.get("eventId").isJsonNull() ? null : item.get("eventId").getAsString();
 
             if (!Objects.equals(faceImportMapper.IsStudentTypeByPersonId(personId), "学生")) {
                 // 老师记录
-                if (teacherEventIdList.contains(item.get("eventId").getAsString())) continue;
-                teacherStudentOutInRecordUtil.teacherInsertRecord(use, personId,recordTime,photo,status,eventId);
+                if (teacherEventIdList.contains(eventId)) continue;
+                teacherStudentOutInRecordUtil.teacherInsertRecord(use, personId, ChangeTime(recordTime), ApiUtil.GetRedirectURL(uri),status,eventId);
             } else {
                 // 学生记录
-                if (studentEventIdList.contains(item.get("eventId").getAsString())) continue;
-                teacherStudentOutInRecordUtil.studentInsertRecord(use, personId, faceImportMapper.GetTeacherIdByPersonId(personId), faceImportMapper.GetClassIdByPersonId(personId), photo, recordTime, status,eventId);
+                if (studentEventIdList.contains(eventId)) continue;
+                teacherStudentOutInRecordUtil.studentInsertRecord(use, personId, faceImportMapper.GetTeacherIdByPersonId(personId),
+                        faceImportMapper.GetClassIdByPersonId(personId), ApiUtil.GetRedirectURL(uri), ChangeTime(recordTime), status,eventId);
             }
         }
-//        }
     }
 
-
     void GetVisitRecord(){
         ApiUtil apiUtil = new ApiUtil();
         JsonObject paramJson = new JsonObject();
@@ -121,7 +114,7 @@ public class Teacher_Student_OutIn_RecordUtil {
         Map<String, String> querys = new HashMap<>();
         querys.put("tagId", "frs");
 
-        String apiPath = "/api/visitor/v2/visiting/records\n";
+        String apiPath = "/api/visitor/v2/visiting/records";
         String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
 
         JsonObject doorEventsJson = new Gson().fromJson(response, JsonObject.class);
@@ -144,4 +137,11 @@ public class Teacher_Student_OutIn_RecordUtil {
         }
     }
 
+    private String ChangeTime(String recordTime) throws ParseException {
+        SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+        SimpleDateFormat mysqlFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = isoFormat.parse(recordTime);
+        return mysqlFormat.format(date);
+    }
+
 }

+ 3 - 3
src/test/java/com/xjrsoft/module/job/HikvisionBaseDataTaskTest.java

@@ -45,9 +45,7 @@ class HikvisionBaseDataTaskTest {
     @Autowired
     private FaceImportMapper faceImportMapper;
 
-    @Autowired
-    EvaluateItemController evaluateItemController;
-
+    Teacher_Student_OutIn_RecordUtil teacherStudentOutInRecordUtil = new Teacher_Student_OutIn_RecordUtil();
     @Test
     void test() throws Exception {
         DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
@@ -104,6 +102,8 @@ class HikvisionBaseDataTaskTest {
 //        String carTableName = "car_message_apply";
 //        selectCar(use, carTableName);
 
+        teacherStudentOutInRecordUtil.GetDoorEvents(use,faceImportMapper);
+
 
 //        selecAllPersonById(use);
         selectResource(use);