Quellcode durchsuchen

车辆考勤报错修改

brealinxx vor 5 Monaten
Ursprung
Commit
f6ae56b230

+ 14 - 7
src/main/java/com/xjrsoft/common/mybatis/SqlRunnerAdapter.java

@@ -25,10 +25,7 @@ import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 
 public class SqlRunnerAdapter implements ISqlRunner, Closeable {
 
@@ -367,12 +364,21 @@ public class SqlRunnerAdapter implements ISqlRunner, Closeable {
      * @return
      */
     public Map<String, Object> dynamicSelectOne(String tableName, Entity where) {
+        if (where == null) {
+            throw new IllegalArgumentException("Where entity cannot be null");
+        }
+
         SQL sql = new SQL().FROM(tableName);
         List<String> args = new ArrayList<>();
         int i = 0;
-        // 查询列
-        for (String field : where.getFieldNames()) {
-            sql.SELECT(field);
+
+        Set<String> fieldNames = where.getFieldNames();
+        if (fieldNames != null && !fieldNames.isEmpty()) {
+            for (String field : fieldNames) {
+                sql.SELECT(field);
+            }
+        } else {
+            sql.SELECT("*"); // 如果没有指定字段,选择所有字段
         }
 
         // 循环where条件
@@ -386,6 +392,7 @@ public class SqlRunnerAdapter implements ISqlRunner, Closeable {
             args.add(strValue);
             i++;
         }
+
         return this.selectOne(sql.toString(), args.toArray());
     }
 

+ 10 - 11
src/main/java/com/xjrsoft/module/hikvision/util/OutInRecordUtil.java

@@ -12,16 +12,14 @@ import com.xjrsoft.module.attendance.entity.AttendanceRuleDetails;
 import com.xjrsoft.module.teacher.mapper.FaceImportMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.sql.Types;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
 
@@ -65,7 +63,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){
+                                    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 : "";
@@ -95,16 +93,17 @@ public class OutInRecordUtil {
         if(carMessageApplyId != 0){
             String selectTable = "car_message_apply";
             Entity selectWhere = Entity.create(selectTable);
-            selectWhere.set("car_message_apply_id", carMessageApplyId);
-            selectWhere.set("plan_no", planNo);
+            selectWhere.set("id", carMessageApplyId);
+            selectWhere.set("car_number", planNo);
             Map<String, Object> objectMap = SqlRunnerAdapter.db().dynamicSelectOne(selectTable, selectWhere);
             Long userId = Long.parseLong(objectMap.get("user_id").toString());
-            LocalDateTime recordTimeDate = LocalDateTime.parse(recordTime);
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            LocalDateTime recordTimeDate = LocalDateTime.parse(recordTime, formatter);
             String attendanceStatus = discernTeacherStatus(recordTimeDate, status, userId);
 
             String updSql = "UPDATE attendance_user_relation SET " +
                     "attendance_status = '" + attendanceStatus + "', attendance_time = '" + recordTime + "' " +
-                    "WHERE user_id = '" + userId + "', attendance_mode = '车辆', car_number = '" + planNo + "' AND delete_mark = 0";
+                    "WHERE user_id = '" + userId + "' AND attendance_mode = '车辆' AND car_number = '" + planNo + "' AND delete_mark = 0";
             SqlRunnerAdapter.db().update(updSql);
         }
     }
@@ -430,8 +429,8 @@ public class OutInRecordUtil {
             JsonObject paramJson = new JsonObject();
             paramJson.addProperty("pageNo", pageNo.getAndIncrement());
             paramJson.addProperty("pageSize", pageSize);
-//            paramJson.addProperty("startTime", "2024-06-18T00:00:00+08:00");
-//            paramJson.addProperty("endTime", "2024-06-19T16:00:00+08:00");
+//            paramJson.addProperty("startTime", "2024-06-20T00:00:00+08:00");
+//            paramJson.addProperty("endTime", "2024-06-21T16:00:00+08:00");
 
             String response = apiUtil.doPost(apiPath, String.valueOf(paramJson), null);
             JsonElement responseElement = new Gson().fromJson(response, JsonElement.class);

+ 5 - 0
src/test/java/com/xjrsoft/module/job/HikvisionBaseDataTaskTest.java

@@ -138,6 +138,11 @@ class HikvisionBaseDataTaskTest {
 //        selectResource(use);
     }
 
+    @Test
+    void testCarInsert() throws Exception {
+        outInRecordUtil.GetVehicleRecord(faceImportMapper);
+    }
+
     public static void selectCar(Db db, String tableName) throws SQLException {
         String sql = "SELECT * FROM " + tableName + " WHERE delete_mark = 0";
         List<Department> dataList = db.query(sql, Department.class);