|
@@ -9,6 +9,7 @@ import com.xjrsoft.common.enums.OutInStatusEnum;
|
|
|
import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
import com.xjrsoft.common.utils.SqlRunnerAdapterUtil;
|
|
|
import com.xjrsoft.module.attendance.entity.AttendanceRuleDetails;
|
|
|
+import com.xjrsoft.module.attendance.vo.AttendanceRuleDetailsUserVo;
|
|
|
import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -19,10 +20,10 @@ import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
@@ -38,12 +39,12 @@ public class OutInRecordUtil {
|
|
|
" WHERE NOT EXISTS (SELECT 1 FROM teacher_out_in_record WHERE eventId = '" + eventId + "')";
|
|
|
SqlRunnerAdapter.db().insert(sql);
|
|
|
|
|
|
- String updSql = "UPDATE attendance_user_relation SET " +
|
|
|
- "attendance_status = '" + attendanceStatus + "', " +
|
|
|
- "attendance_time = '" + recordTime + "', " +
|
|
|
- "attendance_mode = '人脸' " +
|
|
|
- "WHERE user_id = '" + userId + "' AND delete_mark = 0";
|
|
|
- SqlRunnerAdapter.db().update(updSql);
|
|
|
+// String updSql = "UPDATE attendance_user_relation SET " +
|
|
|
+// "attendance_status = '" + attendanceStatus + "', " +
|
|
|
+// "attendance_time = '" + recordTime + "', " +
|
|
|
+// "attendance_mode = '人脸' " +
|
|
|
+// "WHERE user_id = '" + userId + "' AND delete_mark = 0";
|
|
|
+// SqlRunnerAdapter.db().update(updSql);
|
|
|
}
|
|
|
|
|
|
private void studentInsertRecord(Long userId, Long teacherId, Long classId, String facePhoto, String recordTime, int status, String eventId, String attendanceStatus){
|
|
@@ -438,8 +439,6 @@ public class OutInRecordUtil {
|
|
|
|
|
|
if (visit_id_list.contains(eventId)) continue;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
visitInsertRecord(Long.parseLong(reservationSchoolId), eventTime, picUri, status + "", eventId);
|
|
|
}
|
|
|
|
|
@@ -578,6 +577,7 @@ public class OutInRecordUtil {
|
|
|
JsonObject paramsObject = data.getAsJsonObject("params");
|
|
|
JsonArray eventsArray = paramsObject.getAsJsonArray("events");
|
|
|
|
|
|
+ List<Long> teacherUserIds = faceImportMapper.getTeacherUserIds();
|
|
|
for (JsonElement eventElement : eventsArray) {
|
|
|
JsonObject eventObject = eventElement.getAsJsonObject();
|
|
|
JsonObject dataObject = eventObject.getAsJsonObject("data");
|
|
@@ -606,7 +606,7 @@ public class OutInRecordUtil {
|
|
|
|
|
|
if (idNum == null) continue;
|
|
|
|
|
|
- if (!Objects.equals(faceImportMapper.IsStudentTypeByPersonId(Long.valueOf(idNum)), "学生")) {
|
|
|
+ if (teacherUserIds.contains(Long.valueOf(idNum))) {
|
|
|
// 老师记录
|
|
|
LocalDateTime recordTimeDate = LocalDateTime.parse(recordTimeStr, formatter);
|
|
|
String attendanceStatus = discernTeacherStatus(recordTimeDate, status, Long.valueOf(idNum));
|
|
@@ -812,4 +812,202 @@ public class OutInRecordUtil {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void getTeacherRecords(FaceImportMapper faceImportMapper, LocalDateTime startDateTime, LocalDateTime endDateTime,
|
|
|
+ Map<Long, AttendanceRuleDetailsUserVo> teacherRules) throws ParseException {
|
|
|
+ JsonArray responseBuilder = new JsonArray();
|
|
|
+
|
|
|
+ AtomicInteger pageNo = new AtomicInteger(1);
|
|
|
+ int pageSize = 1000;
|
|
|
+ boolean hasMorePages = true;
|
|
|
+
|
|
|
+ while (hasMorePages) {
|
|
|
+ String response = GetDoorEvent(pageNo, pageSize, startDateTime, endDateTime);
|
|
|
+
|
|
|
+ JsonElement responseElement = new Gson().fromJson(response, JsonElement.class);
|
|
|
+ JsonArray dataList = responseElement.getAsJsonObject().getAsJsonObject("data").getAsJsonArray("list");
|
|
|
+ responseBuilder.addAll(dataList);
|
|
|
+ JsonObject responseJson = new Gson().fromJson(response, JsonObject.class);
|
|
|
+ int totalCount = responseJson.getAsJsonObject("data").get("totalPage").getAsInt();
|
|
|
+ hasMorePages = pageNo.getAndIncrement() < totalCount;
|
|
|
+ }
|
|
|
+ //存数据
|
|
|
+ if(responseBuilder.size() > 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ InsertTeacherStudentRecords(responseBuilder, faceImportMapper);
|
|
|
+
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<Long> teacherUserIds = faceImportMapper.getTeacherUserIds();
|
|
|
+ List<String> insertSqls = new ArrayList<>();
|
|
|
+ for (JsonElement element : responseBuilder) {
|
|
|
+ JsonObject item = element.getAsJsonObject();
|
|
|
+
|
|
|
+ Long personId;
|
|
|
+ try {
|
|
|
+ personId = item.get("personId").isJsonNull() ? null : item.get("personId").getAsLong();
|
|
|
+ }catch (Exception e){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (personId == null) continue;
|
|
|
+
|
|
|
+ int statusInt = item.get("inAndOutType").getAsInt();
|
|
|
+ int status = 1;
|
|
|
+ switch (statusInt){
|
|
|
+ case 0:
|
|
|
+ status = 1;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ status = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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();
|
|
|
+ String recordTimeStr = ChangeTime(recordTime);
|
|
|
+ if (teacherUserIds.contains(personId)) {
|
|
|
+ // 老师记录
|
|
|
+ LocalDateTime recordTimeDate = LocalDateTime.parse(recordTimeStr, formatter);
|
|
|
+ String attendanceStatus = discernTeacherStatus(recordTimeDate, status, teacherRules.get(personId));
|
|
|
+ String insSql = "INSERT INTO teacher_out_in_record(create_date, user_id, record_time, face_photo, eventId, status,delete_mark,enabled_mark, attendance_status) "
|
|
|
+ + "select now(), '" + personId + "', '" + recordTimeStr + "', '" +
|
|
|
+ ApiUtil.GetRedirectURL(uri) + "', '" + eventId + "', '" +status + "',0,1,'" + attendanceStatus + "'" +
|
|
|
+ " WHERE NOT EXISTS (SELECT 1 FROM teacher_out_in_record WHERE eventId = '" + eventId + "')";
|
|
|
+ insertSqls.add(insSql);
|
|
|
+ }
|
|
|
+ if(!insertSqls.isEmpty()){
|
|
|
+ for (String insertSql : insertSqls) {
|
|
|
+ SqlRunnerAdapter.db().insert(insertSql);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String discernTeacherStatus(LocalDateTime recordTime, int status, AttendanceRuleDetailsUserVo ruleDetails){
|
|
|
+ String attendanceStatus = "";
|
|
|
+ if (ruleDetails != null) {
|
|
|
+ if (ruleDetails.getIsAttendance() != null && ruleDetails.getIsAttendance() == 0) {
|
|
|
+ attendanceStatus = "不考勤";
|
|
|
+ } else {
|
|
|
+ LocalDateTime amStartTime = null, amEndTime = null, pmStartTime = null, pmEndTime = null, eveningStartTime = null, eveningEndTime = null;
|
|
|
+ if (ruleDetails.getAmStatus() != null && ruleDetails.getAmStatus() == 1
|
|
|
+ && ruleDetails.getAmStartTime() != null && ruleDetails.getAmEndTime() != null) {
|
|
|
+ amStartTime = recordTime.withHour(ruleDetails.getAmStartTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getAmStartTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getAmStartTime().getSecond());
|
|
|
+ amEndTime = recordTime.withHour(ruleDetails.getAmEndTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getAmEndTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getAmEndTime().getSecond());
|
|
|
+ }
|
|
|
+ if (ruleDetails.getPmStatus() != null && ruleDetails.getPmStatus() == 1
|
|
|
+ && ruleDetails.getPmEndTime() != null && ruleDetails.getPmStartTime() != null) {
|
|
|
+ pmStartTime = recordTime.withHour(ruleDetails.getPmStartTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getPmStartTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getPmStartTime().getSecond());
|
|
|
+ pmEndTime = recordTime.withHour(ruleDetails.getPmEndTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getPmEndTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getPmEndTime().getSecond());
|
|
|
+ }
|
|
|
+ if (status == OutInStatusEnum.goOut.getCode()) {//出
|
|
|
+ if (recordTime.isBefore(amEndTime) && recordTime.isAfter(amStartTime)) {
|
|
|
+ attendanceStatus = "早退";
|
|
|
+ } else if (recordTime.isBefore(pmEndTime) && recordTime.isAfter(pmStartTime)) {
|
|
|
+ attendanceStatus = "早退";
|
|
|
+ } else {
|
|
|
+ attendanceStatus = "离校";
|
|
|
+ }
|
|
|
+ } else {//进
|
|
|
+ if (recordTime.isBefore(amEndTime) && recordTime.isAfter(amStartTime)) {
|
|
|
+ attendanceStatus = "迟到";
|
|
|
+ } else if (recordTime.isBefore(pmEndTime) && recordTime.isAfter(pmStartTime)) {
|
|
|
+ attendanceStatus = "迟到";
|
|
|
+ } else {
|
|
|
+ attendanceStatus = "到校";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return attendanceStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ String discernStudentStatus(LocalDateTime recordTime, int status, AttendanceRuleDetailsUserVo ruleDetails){
|
|
|
+ String attendanceStatus = "";
|
|
|
+ if(ruleDetails.getIsAllowInOutSchool() != null && ruleDetails.getIsAllowInOutSchool() == 0){
|
|
|
+ attendanceStatus = "不考勤";
|
|
|
+ }else{
|
|
|
+ LocalDateTime amStartTime = null, amEndTime = null, pmStartTime = null, pmEndTime = null, eveningStartTime = null, eveningEndTime = null;
|
|
|
+ if(ruleDetails.getAmStatus() != null && ruleDetails.getAmStatus() == 1 && ruleDetails.getAmStartTime() != null
|
|
|
+ && ruleDetails.getAmEndTime() != null){
|
|
|
+ amStartTime = recordTime.withHour(ruleDetails.getAmStartTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getAmStartTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getAmStartTime().getSecond());
|
|
|
+ amEndTime = recordTime.withHour(ruleDetails.getAmEndTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getAmEndTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getAmEndTime().getSecond());
|
|
|
+ }
|
|
|
+ if(ruleDetails.getPmStatus() != null && ruleDetails.getPmStatus() == 1 && ruleDetails.getPmStartTime() != null
|
|
|
+ && ruleDetails.getPmEndTime() != null){
|
|
|
+ pmStartTime = recordTime.withHour(ruleDetails.getPmStartTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getPmStartTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getPmStartTime().getSecond());
|
|
|
+ pmEndTime = recordTime.withHour(ruleDetails.getPmEndTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getPmEndTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getPmEndTime().getSecond());
|
|
|
+ }
|
|
|
+ if(ruleDetails.getEveningStatus() != null && ruleDetails.getEveningStatus() == 1
|
|
|
+ && ruleDetails.getEveningStartTime() != null
|
|
|
+ && ruleDetails.getEveningEndTime() != null){
|
|
|
+ eveningStartTime = recordTime.withHour(ruleDetails.getEveningStartTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getEveningStartTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getEveningStartTime().getSecond());
|
|
|
+ eveningEndTime = recordTime.withHour(ruleDetails.getEveningEndTime().getHour())
|
|
|
+ .withMinute(ruleDetails.getEveningEndTime().getMinute())
|
|
|
+ .withSecond(ruleDetails.getEveningEndTime().getSecond());
|
|
|
+ }
|
|
|
+ if(status == OutInStatusEnum.goOut.getCode()){//出
|
|
|
+ if(amEndTime != null && amStartTime != null && recordTime.isBefore(amEndTime) && recordTime.isAfter(amStartTime)){
|
|
|
+ attendanceStatus = "早退";
|
|
|
+ }else if(pmEndTime != null && pmStartTime != null && recordTime.isBefore(pmEndTime) && recordTime.isAfter(pmStartTime)){
|
|
|
+ attendanceStatus = "早退";
|
|
|
+ }else if(eveningEndTime != null && recordTime.isBefore(eveningEndTime) && recordTime.isAfter(eveningStartTime)){
|
|
|
+ attendanceStatus = "早退";
|
|
|
+ }else{
|
|
|
+ attendanceStatus = "离校";
|
|
|
+ }
|
|
|
+ }else{//进
|
|
|
+ if(amEndTime != null && amStartTime != null && recordTime.isBefore(amEndTime) && recordTime.isAfter(amStartTime)){
|
|
|
+ attendanceStatus = "迟到";
|
|
|
+ LocalDateTime localDateTime = amStartTime;
|
|
|
+ if(ruleDetails.getOverMinutes() != null){
|
|
|
+ localDateTime = amStartTime.plusMinutes(ruleDetails.getOverMinutes());
|
|
|
+ }
|
|
|
+ if(recordTime.isAfter(localDateTime)){
|
|
|
+ attendanceStatus = "旷课";
|
|
|
+ }
|
|
|
+ }else if(pmEndTime != null && pmStartTime != null && recordTime.isBefore(pmEndTime) && recordTime.isAfter(pmStartTime)){
|
|
|
+ attendanceStatus = "迟到";
|
|
|
+ LocalDateTime localDateTime = pmStartTime;
|
|
|
+ if(ruleDetails.getOverMinutes() != null){
|
|
|
+ localDateTime = pmStartTime.plusMinutes(ruleDetails.getOverMinutes());
|
|
|
+ }
|
|
|
+ if(recordTime.isAfter(localDateTime)){
|
|
|
+ attendanceStatus = "旷课";
|
|
|
+ }
|
|
|
+ }else if(eveningEndTime != null && recordTime.isBefore(eveningEndTime) && recordTime.isAfter(eveningStartTime)){
|
|
|
+ attendanceStatus = "迟到";
|
|
|
+ LocalDateTime localDateTime = eveningStartTime;
|
|
|
+ if(ruleDetails.getOverMinutes() != null){
|
|
|
+ localDateTime = eveningStartTime.plusMinutes(ruleDetails.getOverMinutes());
|
|
|
+ }
|
|
|
+ if(recordTime.isAfter(localDateTime)){
|
|
|
+ attendanceStatus = "旷课";
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ attendanceStatus = "到校";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return attendanceStatus;
|
|
|
+ }
|
|
|
}
|