Browse Source

代码优化

dzx 8 months ago
parent
commit
ca13252ff5

+ 4 - 5
src/main/java/com/xjrsoft/module/hikvision/controller/EventController.java

@@ -31,7 +31,6 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.sql.SQLException;
 import java.text.ParseException;
 import java.util.List;
 import java.util.Objects;
@@ -58,8 +57,8 @@ public class EventController {
         new Thread(() -> {
             try {
                 outInRecordUtil.GetVehicleRecordTest(faceImportMapper, eventData);
-            } catch (SQLException | ParseException e) {
-                log.error("Error processing event data", e);
+            } catch (ParseException e) {
+                throw new RuntimeException(e);
             }
         }).start();
 
@@ -140,7 +139,7 @@ public class EventController {
                         weChatService.sendTemplateMessage(weChatSendMessageDto);
                     }
                 }
-            } catch (SQLException | ParseException e) {
+            } catch (ParseException e) {
                 log.error("Error processing event data", e);
             }
         }).start();
@@ -155,7 +154,7 @@ public class EventController {
         new Thread(() -> {
             try {
                 outInRecordUtil.GetVisitRecordsTest(faceImportMapper, eventData);
-            } catch (SQLException | ParseException e) {
+            } catch (ParseException e) {
                 log.error("Error processing event data", e);
             }
         }).start();

+ 15 - 16
src/main/java/com/xjrsoft/module/hikvision/util/OutInRecordUtil.java

@@ -12,7 +12,6 @@ import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.sql.SQLException;
 import java.sql.Types;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -28,7 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 public class OutInRecordUtil {
     private static final Logger log = LoggerFactory.getLogger(OutInRecordUtil.class);
 
-    private void teacherInsertRecord(Long userId, String recordTime, String facePhoto, int status, String eventId, String attendanceStatus) throws SQLException {
+    private void teacherInsertRecord(Long userId, String recordTime, String facePhoto, int status, String eventId, String attendanceStatus){
         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) " +
@@ -37,7 +36,7 @@ public class OutInRecordUtil {
         SqlRunnerAdapter.db().insert(sql);
     }
 
-    private void studentInsertRecord(Long userId, Long teacherId, Long classId, String facePhoto, String recordTime, int status, String eventId, String attendanceStatus) throws SQLException {
+    private void studentInsertRecord(Long userId, Long teacherId, Long classId, String facePhoto, String recordTime, int status, String eventId, String attendanceStatus){
         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) " +
@@ -47,7 +46,7 @@ public class OutInRecordUtil {
     }
 
 
-    public void visitInsertRecord(Long reservation_school_people_id, String recordTime,String facePhoto, String status, String eventId) throws SQLException {
+    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)";
@@ -55,7 +54,7 @@ public class OutInRecordUtil {
     }
 
     private void vehicleInsertRecord(Long carMessageApplyId, String recordTime, int releaseReason, int category, String facePhoto, int status, String planNo, String crossRecordSyscode,
-                                     int releaseResult, int releaseWay, int vehicleType, String phone, String name) throws SQLException {
+                                     int releaseResult, int releaseWay, int vehicleType, String phone, String name){
         String phoneValue = (phone != null && !phone.equals("null")) ? phone : "";
         String nameValue = (name != null && !name.equals("null")) ? name : "";
         String photoValue = (facePhoto != null && !facePhoto.equals("null")) ? facePhoto : "";
@@ -83,7 +82,7 @@ public class OutInRecordUtil {
 
     }
 
-    public void GetTeacherAndStudentRecords(FaceImportMapper faceImportMapper) throws SQLException, ParseException {
+    public void GetTeacherAndStudentRecords(FaceImportMapper faceImportMapper) throws ParseException {
         JsonArray responseBuilder = new JsonArray();
 
         AtomicInteger pageNo = new AtomicInteger(1);
@@ -108,7 +107,7 @@ public class OutInRecordUtil {
         InsertTeacherStudentRecords(responseBuilder, faceImportMapper);
     }
 
-    private void InsertTeacherStudentRecords(JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws SQLException, ParseException {
+    private void InsertTeacherStudentRecords(JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws ParseException {
         List<String> teacherEventIdList = faceImportMapper.GetTeacherUrlList();
         List<String> studentEventIdList = faceImportMapper.GetStudentUrlList();
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -159,7 +158,7 @@ public class OutInRecordUtil {
         }
     }
 
-    String discernTeacherStatus(LocalDateTime recordTime, int status, Long userId) throws SQLException {
+    String discernTeacherStatus(LocalDateTime recordTime, int status, Long userId){
         String attendanceStatus = "";
         String dayOfWeek = recordTime.getDayOfWeek().name();
         String sql = "SELECT t2.* FROM attendance_rule_category t1" +
@@ -214,7 +213,7 @@ public class OutInRecordUtil {
         return attendanceStatus;
     }
 
-    String discernStudentStatus(LocalDateTime recordTime, int status, Long studentUserId) throws SQLException {
+    String discernStudentStatus(LocalDateTime recordTime, int status, Long studentUserId){
         String attendanceStatus = "";
         String dayOfWeek = recordTime.getDayOfWeek().name();
         String sql = "SELECT t2.* FROM attendance_rule_category t1" +
@@ -288,7 +287,7 @@ public class OutInRecordUtil {
         return attendanceStatus;
     }
 
-    public void GetVisitRecord(FaceImportMapper faceImportMapper) throws SQLException, ParseException {
+    public void GetVisitRecord(FaceImportMapper faceImportMapper) throws ParseException {
         ApiUtil apiUtil = new ApiUtil();
 
         AtomicInteger pageNo = new AtomicInteger(1);
@@ -329,7 +328,7 @@ public class OutInRecordUtil {
         InsertVisitRecords(responseBuilder,responseDoorBuilder,faceImportMapper);
     }
 
-    private void InsertVisitRecords(JsonArray eventsResponse, JsonArray doorEventsResponse,FaceImportMapper faceImportMapper) throws SQLException, ParseException {
+    private void InsertVisitRecords(JsonArray eventsResponse, JsonArray doorEventsResponse,FaceImportMapper faceImportMapper) throws ParseException {
 
         for (JsonElement element : eventsResponse) {
             List<String> visit_id_list = faceImportMapper.GetReservationSchoolIdList();
@@ -358,7 +357,7 @@ public class OutInRecordUtil {
 
     }
 
-    public void GetVehicleRecord(FaceImportMapper faceImportMapper) throws SQLException, ParseException {
+    public void GetVehicleRecord(FaceImportMapper faceImportMapper) throws ParseException {
         ApiUtil apiUtil = new ApiUtil();
 
         AtomicInteger pageNo = new AtomicInteger(1);
@@ -389,7 +388,7 @@ public class OutInRecordUtil {
         InsertVehicleRecords(responseBuilder,faceImportMapper);
     }
 
-    private void InsertVehicleRecords(JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws SQLException, ParseException {
+    private void InsertVehicleRecords(JsonArray doorEventsResponse, FaceImportMapper faceImportMapper) throws ParseException {
         List<String> vehicle_id_list = faceImportMapper.GetVehicleIdList();
 
         for (JsonElement element : doorEventsResponse) {
@@ -479,7 +478,7 @@ public class OutInRecordUtil {
         return mysqlFormat.format(date);
     }
 
-    public void GetTeacherAndStudentRecordsTest(FaceImportMapper faceImportMapper, JsonObject data) throws SQLException, ParseException {
+    public void GetTeacherAndStudentRecordsTest(FaceImportMapper faceImportMapper, JsonObject data) throws ParseException {
         try {
             List<String> teacherEventIdList = faceImportMapper.GetTeacherUrlList();
             List<String> studentEventIdList = faceImportMapper.GetStudentUrlList();
@@ -541,7 +540,7 @@ public class OutInRecordUtil {
     }
 
 
-    public void GetVehicleRecordTest(FaceImportMapper faceImportMapper, String data) throws SQLException, ParseException {
+    public void GetVehicleRecordTest(FaceImportMapper faceImportMapper, String data) throws ParseException {
         if (data != null) {
             List<String> vehicle_id_list = faceImportMapper.GetVehicleIdList();
             try {
@@ -613,7 +612,7 @@ public class OutInRecordUtil {
         }
     }
 
-    public void GetVisitRecordsTest(FaceImportMapper faceImportMapper, String data) throws SQLException, ParseException {
+    public void GetVisitRecordsTest(FaceImportMapper faceImportMapper, String data) throws ParseException {
         if (data != null) {
             List<String> visit_id_list = faceImportMapper.GetVisitIdList();