|
@@ -18,6 +18,7 @@ import java.sql.Types;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
@@ -30,8 +31,9 @@ public class OutInRecordUtil {
|
|
|
String photoValue = (facePhoto != null && !facePhoto.equals("null")) ? facePhoto : "";
|
|
|
|
|
|
String sql = "INSERT INTO teacher_out_in_record(create_date, user_id, record_time, face_photo, eventId, status,delete_mark,enabled_mark, attendance_status) " +
|
|
|
- "VALUES(now(), '" + userId + "', '" + recordTime + "', '" +
|
|
|
- photoValue + "', '" + eventId + "', '" +status + "',0,1,'" + attendanceStatus + "')";
|
|
|
+ "select now(), '" + userId + "', '" + recordTime + "', '" +
|
|
|
+ photoValue + "', '" + eventId + "', '" +status + "',0,1,'" + attendanceStatus + "'" +
|
|
|
+ " WHERE NOT EXISTS (SELECT 1 FROM teacher_out_in_record WHERE eventId = '" + eventId + "')";
|
|
|
SqlRunnerAdapter.db().insert(sql);
|
|
|
|
|
|
String updSql = "UPDATE attendance_user_relation SET " +
|
|
@@ -46,8 +48,9 @@ public class OutInRecordUtil {
|
|
|
String photoValue = (facePhoto != null && !facePhoto.equals("null")) ? facePhoto : "";
|
|
|
|
|
|
String sql = "INSERT INTO student_out_in_record(create_date, user_id, teacher_id, class_id, face_photo, record_time , eventId,status,delete_mark,enabled_mark, attendance_status) " +
|
|
|
- "VALUES(now(), '" + userId + "', '" + teacherId + "', '" +
|
|
|
- classId + "', '" + photoValue + "', '" + recordTime + "', '" + eventId + "', '" + status + "',0,1,'" + attendanceStatus + "')";
|
|
|
+ "select now(), '" + userId + "', '" + teacherId + "', '" +
|
|
|
+ classId + "', '" + photoValue + "', '" + recordTime + "', '" + eventId + "', '" + status + "',0,1,'" + attendanceStatus + "'" +
|
|
|
+ " WHERE NOT EXISTS (SELECT 1 FROM student_out_in_record WHERE eventId = '" + eventId + "')";
|
|
|
SqlRunnerAdapter.db().insert(sql);
|
|
|
|
|
|
String updSql = "UPDATE attendance_user_relation SET " +
|
|
@@ -61,8 +64,9 @@ public class OutInRecordUtil {
|
|
|
|
|
|
public void visitInsertRecord(Long reservation_school_people_id, String recordTime,String facePhoto, String status, String eventId){
|
|
|
String sql = "INSERT INTO visitor_out_in_record(create_date, reservation_school_people_id, record_time, face_photo, event_id, status,delete_mark,enabled_mark) " +
|
|
|
- "VALUES(now(), '" + reservation_school_people_id + "', '" +
|
|
|
- recordTime + "', '" + facePhoto + "', '" + eventId + "', '" + status + "',0,1)";
|
|
|
+ "select now(), '" + reservation_school_people_id + "', '" +
|
|
|
+ recordTime + "', '" + facePhoto + "', '" + eventId + "', '" + status + "',0,1" +
|
|
|
+ " WHERE NOT EXISTS (SELECT 1 FROM visitor_out_in_record WHERE eventId = '" + eventId + "')";
|
|
|
SqlRunnerAdapter.db().insert(sql);
|
|
|
}
|
|
|
|
|
@@ -147,15 +151,15 @@ public class OutInRecordUtil {
|
|
|
SqlRunnerAdapter.db().dynamicUpdate(tableName, params, where);
|
|
|
}
|
|
|
|
|
|
- public void GetTeacherAndStudentRecords(FaceImportMapper faceImportMapper) throws ParseException {
|
|
|
+ public void GetTeacherAndStudentRecords(FaceImportMapper faceImportMapper, LocalDateTime startDateTime, LocalDateTime endDateTime) throws ParseException {
|
|
|
JsonArray responseBuilder = new JsonArray();
|
|
|
|
|
|
AtomicInteger pageNo = new AtomicInteger(1);
|
|
|
- int pageSize = 100;
|
|
|
+ int pageSize = 1000;
|
|
|
boolean hasMorePages = true;
|
|
|
|
|
|
while (hasMorePages) {
|
|
|
- String response = GetDoorEvent(pageNo, pageSize);
|
|
|
+ String response = GetDoorEvent(pageNo, pageSize, startDateTime, endDateTime);
|
|
|
|
|
|
JsonElement responseElement = new Gson().fromJson(response, JsonElement.class);
|
|
|
JsonArray dataList = responseElement.getAsJsonObject().getAsJsonObject("data").getAsJsonArray("list");
|
|
@@ -352,7 +356,7 @@ public class OutInRecordUtil {
|
|
|
return attendanceStatus;
|
|
|
}
|
|
|
|
|
|
- public void GetVisitRecord(FaceImportMapper faceImportMapper) throws ParseException {
|
|
|
+ public void GetVisitRecord(FaceImportMapper faceImportMapper, LocalDateTime startDateTime, LocalDateTime endDateTime) throws ParseException {
|
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
|
|
|
|
AtomicInteger pageNo = new AtomicInteger(1);
|
|
@@ -369,7 +373,7 @@ public class OutInRecordUtil {
|
|
|
paramJson.addProperty("pageSize", pageSize);
|
|
|
|
|
|
String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), null);
|
|
|
- String responseDoor = GetDoorEvent(pageNo,pageSize);
|
|
|
+ String responseDoor = GetDoorEvent(pageNo, pageSize, startDateTime, endDateTime);
|
|
|
|
|
|
JsonElement responseElement = new Gson().fromJson(response, JsonElement.class);
|
|
|
JsonElement responseDoorElement = new Gson().fromJson(responseDoor, JsonElement.class);
|
|
@@ -422,7 +426,7 @@ public class OutInRecordUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void GetVehicleRecord(FaceImportMapper faceImportMapper) throws ParseException {
|
|
|
+ public void GetVehicleRecord(FaceImportMapper faceImportMapper, LocalDateTime startDateTime, LocalDateTime endDateTime) throws ParseException {
|
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
|
|
|
|
AtomicInteger pageNo = new AtomicInteger(1);
|
|
@@ -436,8 +440,8 @@ public class OutInRecordUtil {
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("pageNo", pageNo.getAndIncrement());
|
|
|
paramJson.addProperty("pageSize", pageSize);
|
|
|
-// paramJson.addProperty("startTime", "2024-06-20T00:00:00+08:00");
|
|
|
-// paramJson.addProperty("endTime", "2024-06-21T16:00:00+08:00");
|
|
|
+ paramJson.addProperty("startTime", startDateTime.atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
|
|
|
+ paramJson.addProperty("endTime", endDateTime.atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
|
|
|
|
|
|
String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), null);
|
|
|
JsonElement responseElement = new Gson().fromJson(response, JsonElement.class);
|
|
@@ -452,7 +456,7 @@ public class OutInRecordUtil {
|
|
|
hasMorePages = pageNo.getAndIncrement() * pageSize < totalCount;
|
|
|
}
|
|
|
|
|
|
- InsertVehicleRecords(responseBuilder,faceImportMapper);
|
|
|
+ InsertVehicleRecords(responseBuilder, faceImportMapper);
|
|
|
}
|
|
|
|
|
|
private void InsertVehicleRecords(JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws ParseException {
|
|
@@ -526,7 +530,7 @@ public class OutInRecordUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private String GetDoorEvent(AtomicInteger pageNo, int pageSize){
|
|
|
+ private String GetDoorEvent(AtomicInteger pageNo, int pageSize, LocalDateTime startDateTime, LocalDateTime endDateTime){
|
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
|
String apiPath = "/api/acs/v2/door/events";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
@@ -535,6 +539,8 @@ public class OutInRecordUtil {
|
|
|
paramJson.addProperty("pageNo", pageNo.get());
|
|
|
paramJson.addProperty("pageSize", pageSize);
|
|
|
paramJson.add("eventTypes", eventList);
|
|
|
+ paramJson.addProperty("startTime", startDateTime.atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
|
|
|
+ paramJson.addProperty("endTime", endDateTime.atOffset(ZoneOffset.ofHours(8)).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
|
|
|
|
|
|
return apiUtil.doPost(apiPath, String.valueOf(paramJson), null);
|
|
|
}
|