|
@@ -1,113 +1,117 @@
|
|
|
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 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.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
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 + "', '" + "')";
|
|
|
+ public void teacherInsertRecord(Db db, Long userId, String recordTime, String facePhoto,int status, String eventId) throws SQLException {
|
|
|
+
|
|
|
+ String sql = "INSERT INTO teacher_out_in_record(create_date, user_id, record_time, face_photo, eventId, status) " +
|
|
|
+ "VALUES(now(), '" + userId + "', '" + recordTime + "', '" +
|
|
|
+ facePhoto + "', '" + eventId + "', '" +status + "')";
|
|
|
db.execute(sql);
|
|
|
}
|
|
|
|
|
|
+ public void studentInsertRecord(Db db, Long userId, Long teacherId, Long classId, String facePhoto, String recordTime, int status, String eventId) throws SQLException {
|
|
|
+ String sql = "INSERT INTO student_out_in_record(create_date, user_id, teacher_id, class_id, face_photo, record_time , eventId,status) " +
|
|
|
+ "VALUES(now(), '" + userId + "', '" + teacherId + "', '" +
|
|
|
+ classId + "', '" + facePhoto + "', '" + recordTime + "', '" + eventId + "', '" + 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, ...) " +
|
|
|
+ String sql = "INSERT INTO visitor_out_in_record(create_date, reservation_school_people_id, record_time, face_photo, status) " +
|
|
|
"VALUES(now(), '" + reservation_school_people_id + "', '" +
|
|
|
- recordTime + "', '" + facePhoto + "', '" + status + "', '" + "')";
|
|
|
+ recordTime + "', '" + facePhoto + "', '" + status + "')";
|
|
|
db.execute(sql);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @GetMapping(value = "/adada")
|
|
|
- @ApiOperation(value = "新www价项")
|
|
|
- @SaCheckPermission("evaluateitem:add")
|
|
|
- public String GetAccessConsole(){
|
|
|
+ public String GetDoorEvents(Db use, FaceImportMapper faceImportMapper) throws SQLException {
|
|
|
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/acs/v2/door/events";
|
|
|
+ JsonArray responseBuilder = new JsonArray();
|
|
|
|
|
|
- String apiPath = "/api/resource/v2/acsDevice/search";
|
|
|
- String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), querys);
|
|
|
+ AtomicInteger pageNo = new AtomicInteger(1);
|
|
|
+ int pageSize = 100;
|
|
|
+ boolean hasMorePages = true;
|
|
|
|
|
|
- return GetDoorEvents(response);
|
|
|
- }
|
|
|
+ while (hasMorePages) {
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.addProperty("pageNo", pageNo.get());
|
|
|
+ paramJson.addProperty("pageSize", pageSize);
|
|
|
|
|
|
- public String GetDoorEvents(String accessPointResponse){
|
|
|
- ApiUtil apiUtil = new ApiUtil();
|
|
|
+ String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), null);
|
|
|
+ JsonElement responseElement = new Gson().fromJson(response, JsonElement.class);
|
|
|
+ JsonArray dataList = responseElement.getAsJsonObject().getAsJsonObject("data").getAsJsonArray("list");
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
+ for (JsonElement item : dataList) {
|
|
|
+ responseBuilder.add(item);
|
|
|
+ }
|
|
|
|
|
|
- return response;
|
|
|
+ JsonObject responseJson = new Gson().fromJson(response, JsonObject.class);
|
|
|
+ int totalCount = responseJson.getAsJsonObject("data").get("totalPage").getAsInt();
|
|
|
+ hasMorePages = pageNo.getAndIncrement() < totalCount;
|
|
|
+ }
|
|
|
+ // Process the records
|
|
|
+ InsertTeacherStudentRecords(use, responseBuilder, faceImportMapper);
|
|
|
+ return responseBuilder.toString();
|
|
|
}
|
|
|
|
|
|
- public void stProcessRecords(String doorEventsResponse) {
|
|
|
- JsonObject doorEventsJson = new Gson().fromJson(doorEventsResponse, JsonObject.class);
|
|
|
- JsonArray dataList = doorEventsJson.getAsJsonObject("data").getAsJsonArray("list");
|
|
|
|
|
|
- for (JsonElement element : dataList) {
|
|
|
+ public void InsertTeacherStudentRecords(Db use, JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws SQLException {
|
|
|
+// for (JsonElement e : doorEventsResponse){
|
|
|
+ Teacher_Student_OutIn_RecordUtil teacherStudentOutInRecordUtil = new Teacher_Student_OutIn_RecordUtil();
|
|
|
+ List<String> teacherEventIdList = faceImportMapper.GetTeacherUrlList();
|
|
|
+ List<String> studentEventIdList = faceImportMapper.GetStudentUrlList();
|
|
|
+
|
|
|
+ for (JsonElement element : doorEventsResponse) {
|
|
|
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();
|
|
|
|
|
|
+ Long personId;
|
|
|
+ try {
|
|
|
+ personId = item.get("personId").isJsonNull() ? null : item.get("personId").getAsLong();
|
|
|
+ }catch (Exception e){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (personId == null) continue;
|
|
|
+
|
|
|
+ int status = item.get("inAndOutType").getAsInt();
|
|
|
+ String photo = 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);
|
|
|
} 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...);
|
|
|
+ if (studentEventIdList.contains(item.get("eventId").getAsString())) continue;
|
|
|
+ teacherStudentOutInRecordUtil.studentInsertRecord(use, personId, faceImportMapper.GetTeacherIdByPersonId(personId), faceImportMapper.GetClassIdByPersonId(personId), photo, recordTime, status,eventId);
|
|
|
}
|
|
|
}
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
void GetVisitRecord(){
|
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
|
JsonObject paramJson = new JsonObject();
|