Browse Source

车辆导入修改

brealinxx 9 months ago
parent
commit
242c83cb14

+ 4 - 0
src/main/java/com/xjrsoft/module/hikvision/util/Car_OutInRecordUtil.java

@@ -0,0 +1,4 @@
+package com.xjrsoft.module.hikvision.util;
+
+public class Car_OutInRecordUtil {
+}

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

@@ -7,19 +7,17 @@ import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.xjrsoft.module.base.entity.BaseClass;
 import com.xjrsoft.module.base.entity.BaseGrade;
+import com.xjrsoft.module.hikvision.entity.HikvisionData;
 import com.xjrsoft.module.organization.entity.Department;
 import com.xjrsoft.module.personnel.entity.CarMessageApply;
+import com.xjrsoft.module.personnel.mapper.TeacherFaceProcessMapper;
 import com.xjrsoft.module.system.entity.DictionaryDetail;
+import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
 import lombok.extern.slf4j.Slf4j;
 import lombok.var;
 
 import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.ThreadLocalRandom;
 
 /**
@@ -32,6 +30,8 @@ public class DataUtil {
      * 同步组织数据
      * 只有批量添加接口,需要一个层级一个层级的添加
      */
+    private static FaceImportMapper faceImportMapper;
+
     public Map<String, String> insertDepartment(Db db, String tableName, Map<String, String> tableData) throws Exception {
         String sql = "SELECT DISTINCT LENGTH(hierarchy) FROM " + tableName + " WHERE delete_mark = 0";
         List<Integer[]> list = db.query(sql, Integer[].class);
@@ -453,29 +453,30 @@ public class DataUtil {
     }
 
     /*同步车辆数据*/
-    public Map<String, String> insertCar(Db db, String tableName, Map<Long, String> tableData) throws Exception {
+    public Map<Long, String> insertCar(Db db, String tableName, Map<Long, String> tableData) throws Exception {
         String sql = "SELECT * FROM " + tableName + " WHERE delete_mark = 0 and status = 1";
         List<CarMessageApply> dataList = db.query(sql, CarMessageApply.class);
         String apiPath = "/api/resource/v1/vehicle/batch/add";
-        Map<String, String> idMap = new HashMap<>();
+        Map<Long, String> idMap = new HashMap<>();
         JsonParser jsonParser = new JsonParser();
         ApiUtil apiUtil = new ApiUtil();
 
-        Map<String, String> idCodeMap = new HashMap<>();
-        idCodeMap.put("tagId", "frs");
+        Map<Integer, Long> clientMap = new HashMap<>();
+        Map<String, String> tagMap = new HashMap<>();
+        tagMap.put("tagId", "frs");
+
+        String sqlHik = "SELECT * FROM " + "hikvision_data" + " WHERE delete_mark = 0 and status = 1";
+        List<HikvisionData> HikList =  db.query(sqlHik, HikvisionData.class);
 
         JsonArray dataArray = new JsonArray();
         String result = null;
+        int clientId = 1;
         for (CarMessageApply carMessageApply : dataList) {
-            long currentTimestamp = System.currentTimeMillis();
-            int randomSuffix = ThreadLocalRandom.current().nextInt(10000);
-            String uniqueClientIdStr = String.format("%03d%04d", currentTimestamp % 1000, randomSuffix);
-            long uniqueClientId = Long.parseLong(uniqueClientIdStr);
 
             JsonObject paramJson = new JsonObject();
-            paramJson.addProperty("clientId", uniqueClientId);
+            paramJson.addProperty("clientId", clientId);
             paramJson.addProperty("plateNo", carMessageApply.getCarNumber());
-            paramJson.addProperty("PersonId",carMessageApply.getUserId());
+            paramJson.addProperty("PersonId", faceImportMapper.GetHikvisonPersonId(carMessageApply.getId()));
 
             int vehicleTypeNum;
             switch (carMessageApply.getVehicleType()) {
@@ -493,10 +494,11 @@ public class DataUtil {
                     break;
             }
             paramJson.addProperty("vehicleType", vehicleTypeNum);
-
+            clientMap.put(clientId, carMessageApply.getId());
             dataArray.add(paramJson);
+            clientId++;
         }
-        result = apiUtil.doPost(apiPath, dataArray.toString(), idCodeMap, null);
+        result = apiUtil.doPost(apiPath, dataArray.toString(), tagMap, null);
 
         JsonElement parse = jsonParser.parse(result);
 
@@ -505,7 +507,7 @@ public class DataUtil {
             JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
             for (JsonElement jsonElement : array) {
                 JsonObject jsonObject = jsonElement.getAsJsonObject();
-                idMap.put(jsonObject.get("clientId").getAsString(), jsonObject.get("vehicleId").getAsString());
+                idMap.put(clientMap.get(jsonObject.get("clientId")), jsonObject.get("vehicleId").getAsString());
             }
         } else {
             System.err.println("API call failed: " + resultJson.get("msg").getAsString());

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

@@ -0,0 +1,143 @@
+package com.xjrsoft.module.hikvision.util;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.hutool.db.Db;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import io.swagger.annotations.ApiOperation;
+import lombok.var;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class Teacher_Student_OutIn_RecordUtil {
+//    void tearcherInsertRecord(Db db, Long userId, String recordTime, Long facePhoto,int status) throws SQLException {
+//
+//        String sql = "INSERT INTO teacher_out_in_record(create_date, ...) " +
+//                "VALUES(now(), '"  + userId + "', '" + teacherId + "', '" +
+//                classId + "', '" + recordTime + "', '" + facePhoto + "', '" + status + "', '" + entry.getValue() + "')";
+//        db.execute(sql);
+//    }
+
+    public void studentInsertRecord(Db db, Long userId, Long teacherId, Long classId, String recordTime,Long facePhoto, int status) throws SQLException {
+        String sql = "INSERT INTO teacher_out_in_record(create_date, ...) " +
+                "VALUES(now(), '"  + userId + "', '" + teacherId + "', '" +
+                classId + "', '" + recordTime + "', '" + facePhoto + "', '" + status + "', '" + "')";
+        db.execute(sql);
+    }
+
+    public void visitInsertRecord(Db db, Long reservation_school_people_id, String recordTime,Long facePhoto, int status) throws SQLException {
+        String sql = "INSERT INTO visitor_out_in_record(create_date, ...) " +
+                "VALUES(now(), '"  + reservation_school_people_id + "', '" +
+                 recordTime + "', '" + facePhoto + "', '" + status + "', '" + "')";
+        db.execute(sql);
+    }
+
+
+    @GetMapping(value = "/adada")
+    @ApiOperation(value = "新www价项")
+    @SaCheckPermission("evaluateitem:add")
+    public String GetAccessConsole(){
+        ApiUtil apiUtil = new ApiUtil();
+        JsonObject paramJson = new JsonObject();
+        paramJson.addProperty("pageNo", 1);
+        paramJson.addProperty("pageSize", 100);
+
+        Map<String, String> querys = new HashMap<>();
+        querys.put("tagId", "frs");
+
+        String apiPath = "/api/resource/v2/acsDevice/search";
+        String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
+
+        return GetDoorEvents(response);
+    }
+
+    public String GetDoorEvents(String accessPointResponse){
+        ApiUtil apiUtil = new ApiUtil();
+
+        JsonObject accessPointJson = new Gson().fromJson(accessPointResponse, JsonObject.class);
+        JsonArray dataList = accessPointJson.getAsJsonObject("data").getAsJsonArray("list");
+        String apiPath = "/api/acs/v2/door/events";
+        String response = null;
+        for(JsonElement element : dataList){
+            JsonObject item = element.getAsJsonObject();
+            JsonObject paramJson = new JsonObject();
+            JsonArray doorIndexCodes = new JsonArray();
+            paramJson.addProperty("pageNo", 1);
+            paramJson.addProperty("pageSize", 10);
+            doorIndexCodes.add(item.get("indexCode"));
+            paramJson.add("doorIndexCodes", doorIndexCodes);
+            response = apiUtil.doPost(apiPath, String.valueOf(paramJson), null);
+            // 执行四中人员的导入
+            stProcessRecords(response);
+
+//            doorIndexCodes.add(item.get("indexCode").getAsString());
+            System.out.println(response);
+        }
+
+        return response;
+    }
+
+    public void stProcessRecords(String doorEventsResponse) {
+        JsonObject doorEventsJson = new Gson().fromJson(doorEventsResponse, JsonObject.class);
+        JsonArray dataList = doorEventsJson.getAsJsonObject("data").getAsJsonArray("list");
+
+        for (JsonElement element : dataList) {
+            JsonObject item = element.getAsJsonObject();
+            if (item.get("studentId").isJsonNull()) {
+                // 老师记录
+                String personId = item.get("personId").isJsonNull() ? null : item.get("personId").getAsString();
+                int inAndOutType = item.get("inAndOutType").getAsInt();
+
+            } else {
+                // 学生记录
+                String studentId = item.get("studentId").getAsString();
+                String personId = item.get("personId").isJsonNull() ? null : item.get("personId").getAsString();
+                int status = item.get("inAndOutType").getAsInt();
+                String receiveTime = item.get("receiveTime").getAsString();
+
+                // 执行mapper获取例如班主任等数据 然后执行
+//                Teacher_Student_OutIn_RecordUtil teacherStudentOutInRecordUtil = new Teacher_Student_OutIn_RecordUtil();
+//                teacherStudentOutInRecordUtil.studentInsertRecord(db...);
+            }
+        }
+    }
+
+    void GetVisitRecord(){
+        ApiUtil apiUtil = new ApiUtil();
+        JsonObject paramJson = new JsonObject();
+        paramJson.addProperty("pageNo", 1);
+        paramJson.addProperty("pageSize", 100);
+
+        Map<String, String> querys = new HashMap<>();
+        querys.put("tagId", "frs");
+
+        String apiPath = "/api/visitor/v2/visiting/records\n";
+        String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
+
+        JsonObject doorEventsJson = new Gson().fromJson(response, JsonObject.class);
+        JsonArray dataList = doorEventsJson.getAsJsonObject("data").getAsJsonArray("list");
+
+        for (JsonElement element : dataList) {
+            JsonObject item = element.getAsJsonObject();
+            if (item.get("orderId").isJsonNull()) {
+                // 访客记录
+                Long orderId = item.get("orderId").getAsLong();
+                String picUri = item.get("picUri").getAsString();
+                String visitStartTime = item.get("visitStartTime").getAsString();
+                // int status?
+
+                // mapper
+
+//                Teacher_Student_OutIn_RecordUtil teacherStudentOutInRecordUtil = new Teacher_Student_OutIn_RecordUtil();
+//                teacherStudentOutInRecordUtil.visitInsertRecord();db...);
+            }
+        }
+    }
+
+}

+ 2 - 0
src/main/java/com/xjrsoft/module/teacher/mapper/FaceImportMapper.java

@@ -11,5 +11,7 @@ public interface FaceImportMapper {
 
     String GetStudentUserIdById(@Param("id") Long id);
     String GetStudentHikvisionImgById(@Param("id") Long id);
+
+    Long GetHikvisonPersonId(@Param("id") Long id);
 }
 

+ 10 - 0
src/main/resources/mapper/teacher/TeacherFaceImportMapper.xml

@@ -40,4 +40,14 @@
         </if>
         and t.status = 1
     </select>
+
+    <select id="GetHikvisonPersonId" parameterType="long" resultType="java.lang.Long">
+        select t.hikvision_id
+        from hikvision_data t
+        left join car_message_apply t1 on t1.user_id = t.source_id
+        <if test="id != null">
+            where t1.id = #{id}
+        </if>
+        and t1.status = 1
+    </select>
 </mapper>