Bladeren bron

教师考勤调整

dzx 5 maanden geleden
bovenliggende
commit
6f086a1987

+ 12 - 6
src/main/java/com/xjrsoft/module/attendance/controller/TeacherStatisticsController.java

@@ -168,9 +168,10 @@ public class TeacherStatisticsController {
                     continue;
                 }
                 List<TeacherOutInRecord> outInRecords = teacherOutInRecordService.list(
-                    new QueryWrapper<TeacherOutInRecord>().lambda()
-                            .between(TeacherOutInRecord::getRecordTime, startTime, endTime)
+                    new MPJLambdaWrapper<TeacherOutInRecord>()
+                            .le(TeacherOutInRecord::getRecordTime, startTime)
                             .eq(TeacherOutInRecord::getStatus, 1)
+                            .eq("DATE_FORMAT(record_time, '%Y-%m-%d')", startTime.toLocalDate())
                             .eq(TeacherOutInRecord::getUserId, record.getUserId())
                             .orderByAsc(TeacherOutInRecord::getRecordTime)
                 );
@@ -184,16 +185,21 @@ public class TeacherStatisticsController {
                     //查询该教师是否通过车辆进入
                     List<CarOutInRecord> list = carOutInRecordService.list(
                             new MPJLambdaWrapper<CarOutInRecord>()
-                                    .select(CarMessageApply.class, x -> VoToColumnUtil.fieldsToColumns(CarMessageApply.class).contains(x.getProperty()))
+                                    .select(CarOutInRecord.class, x -> VoToColumnUtil.fieldsToColumns(CarOutInRecord.class).contains(x.getProperty()))
                                     .leftJoin(CarMessageApply.class, CarMessageApply::getId, CarOutInRecord::getCarMessageApplyId)
-                                    .between(CarOutInRecord::getRecordTime, startTime, endTime)
+                                    .le(TeacherOutInRecord::getRecordTime, endTime)
+                                    .eq("DATE_FORMAT(record_time, '%Y-%m-%d')", endTime.toLocalDate())
+                                    .eq(CarMessageApply::getUserId, record.getUserId())
                                     .orderByAsc(CarOutInRecord::getRecordTime)
                     );
                     if(!list.isEmpty()){
                         CarOutInRecord outInRecord = list.get(0);
-                        if(outInRecord != null){
+                        if(outInRecord != null && outInRecord.getRecordTime().isBefore(startTime)){
                             record.setRecordTime(outInRecord.getRecordTime());
-                            record.setStatus(outInRecord.getAttendanceStatus());
+                            record.setStatus("到校");
+                        }else if(outInRecord != null && outInRecord.getRecordTime().isAfter(startTime)){
+                            record.setRecordTime(outInRecord.getRecordTime());
+                            record.setStatus("迟到");
                         }
                     }
                 }

+ 13 - 13
src/main/java/com/xjrsoft/module/hikvision/util/DataUtil.java

@@ -281,9 +281,9 @@ public class DataUtil {
             paramJson.addProperty("personId", objectMap.get("id").toString());
             paramJson.addProperty("personName", objectMap.get("name").toString());
             paramJson.addProperty("orgIndexCode", objectMap.get("orgIndexCode").toString());
-            paramJson.addProperty("phoneNo", objectMap.get("mobile").toString());
+            paramJson.addProperty("phoneNo", objectMap.get("mobile")==null?"":objectMap.get("mobile").toString());
             paramJson.addProperty("jobNo", objectMap.get("user_name").toString());
-            paramJson.addProperty("birthday", objectMap.get("birthday").toString());
+            paramJson.addProperty("birthday", objectMap.get("birthday")==null?"":objectMap.get("birthday").toString());
             paramJson.addProperty("personType", 2);
 
             int gender;
@@ -321,7 +321,7 @@ public class DataUtil {
         return idMap;
     }
 
-    public Map<String, String> insertStudent(String tableName, Map<String, String> tableData) throws Exception {
+    public Map<String, String> insertStudent(String tableName, Map<String, String> tableData) {
         String sql = "SELECT t1.id,t1.name,CONCAT(t3.id,'-',t4.name,'-',t3.class_type,'-',t2.stduy_status)," +
                 " t1.user_name,t1.gender,t1.birth_date,t1.mobile,t1.email,t1.credential_type,t1.credential_number FROM xjr_user t1" +
                 " INNER JOIN base_student_school_roll t2 ON t1.id = t2.user_id" +
@@ -407,22 +407,22 @@ public class DataUtil {
         JsonArray paramArray = new JsonArray();
         Map<Integer, String> clientMap = new HashMap<>();
         for(int i = 0; i < list.size(); i ++){
-            String[] el = SqlRunnerAdapterUtil.convertMapToStringArray(list.get(i));
-            if(tableData != null && tableData.containsKey(el[0])){
+            Map<String, Object> objectMap = list.get(i);
+            if(tableData != null && tableData.containsKey(objectMap.get("id").toString())){
                 continue;
             }
             JsonObject paramJson = new JsonObject();
             paramJson.addProperty("clientId", i);
-            paramJson.addProperty("personId", el[0]);
-            paramJson.addProperty("personName", el[1]);
-            paramJson.addProperty("orgIndexCode", deptMap.get(el[3]));
-            paramJson.addProperty("phoneNo", el[5]);
-            paramJson.addProperty("jobNo", el[9]);
-            paramJson.addProperty("birthday", el[4]);
+            paramJson.addProperty("personId", objectMap.get("id").toString());
+            paramJson.addProperty("personName", objectMap.get("name").toString());
+            paramJson.addProperty("orgIndexCode", objectMap.get("dept_id").toString());
+            paramJson.addProperty("phoneNo", objectMap.get("mobile")==null?"":objectMap.get("mobile").toString());
+            paramJson.addProperty("jobNo", objectMap.get("user_name").toString());
+            paramJson.addProperty("birthday", objectMap.get("birth_date")==null?"":objectMap.get("birth_date").toString());
             paramJson.addProperty("personType", 1);
 
             int gender;
-            switch (el[2]) {
+            switch (objectMap.get("gender").toString()) {
                 case "SB10001":
                     gender = 1;
                     break;
@@ -436,7 +436,7 @@ public class DataUtil {
             paramJson.addProperty("gender", gender);
             paramArray.add(paramJson);
 
-            clientMap.put(i, el[0]);
+            clientMap.put(i, objectMap.get("id").toString());
         }
 
         String apiPath = "/api/resource/v1/person/batch/add";

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

@@ -83,29 +83,29 @@ class HikvisionBaseDataTaskTest {
 
     @Test
     void test() throws Exception {
-//        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
-//        Db use = Db.use(datasource);
-//        String sql = "SELECT distinct table_name FROM hikvision_data WHERE 1 = 1";
-//        List<JianyueData> query = use.query(sql, JianyueData.class);
-//        Set<String> tables = new HashSet<>();
-//        for (JianyueData jianyueData : query) {
-//            tables.add(jianyueData.getTableName());
-//        }
-//        sql = "SELECT * FROM hikvision_data WHERE 0 = 0";
-//        List<HikvisionData> list = use.query(sql, HikvisionData.class);
-//        Map<String, Map<String, String>> dataMap = new HashMap<>();
-//        for (String table : tables) {
-//            Map<String, String> tableData = new HashMap<>();
-//            for (HikvisionData hikvisiondata : list) {
-//                if(!table.equals(hikvisiondata.getTableName())){
-//                    continue;
-//                }
-//                tableData.put(hikvisiondata.getSourceId(), hikvisiondata.getHikvisionId());
-//            }
-//            dataMap.put(table, tableData);
-//        }
+        String sql = "SELECT distinct table_name FROM hikvision_data WHERE 1 = 1";
+        List<Map<String, Object>> maps = SqlRunnerAdapter.db().selectList(sql, HikvisionData.class);
+        Set<String> tables = new HashSet<>();
+        for (Map<String, Object> map : maps) {
+            String[] strings = SqlRunnerAdapterUtil.convertMapToStringArray(map);
+            tables.add(strings[0]);
+        }
+        sql = "SELECT * FROM hikvision_data WHERE 0 = 0";
+        List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, HikvisionData.class);
+        Map<String, Map<String, String>> dataMap = new HashMap<>();
+        for (String table : tables) {
+            Map<String, String> tableData = new HashMap<>();
+            for (Map<String, Object> hikvision : list) {
+
+                if(!table.equals(hikvision.get("table_name").toString())){
+                    continue;
+                }
+                tableData.put(hikvision.get("source_id").toString(), hikvision.get("hikvision_id").toString());
+            }
+            dataMap.put(table, tableData);
+        }
 //        DataUtil dataUtil = new DataUtil();
-//        String tableName = "xjr_department";
+        String tableName = "xjr_department";
 //        Map<String, String> department = dataUtil.insertDepartment(use, tableName, dataMap.get(tableName));
 //        if(department.isEmpty() && dataMap.get(tableName) != null){
 //            department = dataMap.get(tableName);
@@ -127,9 +127,9 @@ class HikvisionBaseDataTaskTest {
 //        Map<String, String> classes = dataUtil.insertClass(use, tableName, baseClass);
 
 
-//        tableName = "base_student";
-//        Map<String, String> baseStudent = dataMap.get(tableName);
-//        Map<String, String> student = dataUtil.insertStudentOne(use, tableName, baseStudent);
+        tableName = "base_student";
+        Map<String, String> baseStudent = dataMap.get(tableName);
+        Map<String, String> student = insertStudentOne(tableName, baseStudent);
 
 //        selectOrg(use, "base_class");
 
@@ -170,43 +170,40 @@ class HikvisionBaseDataTaskTest {
         db.executeBatch(sqls);
     }
 
-    public Map<String, String> insertStudentOne(Db db, String tableName, Map<String, String> tableData) throws Exception {
-        String sql = "SELECT t1.id,t1.name,CONCAT(t3.id,'-',t4.name,'-',t3.class_type,'-',t2.stduy_status)," +
-                " t1.user_name,t1.gender,DATE_FORMAT(t1.birth_date, '%Y-%m-%d'),t1.mobile,t1.email,t1.credential_type,t1.credential_number FROM xjr_user t1" +
+    public Map<String, String> insertStudentOne(String tableName, Map<String, String> tableData) throws Exception {
+        String sql = "SELECT t1.id,t1.name,CONCAT(t3.id,'-',replace(t4.name,'级',''),'-',t3.class_type,'-',t2.stduy_status) as orgIndexCode," +
+                " t1.user_name,t1.gender,DATE_FORMAT(t1.birth_date, '%Y-%m-%d') as birthday,t1.mobile,t1.email,t1.credential_type,t1.credential_number FROM xjr_user t1" +
                 " INNER JOIN base_student_school_roll t2 ON t1.id = t2.user_id" +
                 " INNER JOIN base_class t3 ON t2.class_id = t3.id" +
                 " INNER JOIN base_grade t4 ON t3.grade_id = t4.id" +
                 " WHERE t1.delete_mark = 0 AND t2.delete_mark = 0" +
-                " AND t3.class_type IS NOT NULL" +
-                " AND t1.id NOT IN (SELECT source_id FROM hikvision_data WHERE table_name = 'base_student'\n" +
-                ") AND t4.name NOT IN ('2021级','2020级')";
-        List<String[]> list = db.query(sql, String[].class);
+                " AND t3.class_type IS NOT NULL";
+                //" AND t1.name IN ('宋成男','白江龙','李松阳')";
+        List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, String[].class);
         Map<Integer, String> clientMap = new HashMap<>();
 
-        String apiPath = "/api/resource/v2/person/single/add";
         Map<String, String> idMap = new HashMap<>();
         JsonParser jsonParser = new JsonParser();
         ApiUtil apiUtil = new ApiUtil();
         Map<String, String> header = new HashMap<>();
         header.put("tagId", "insert_student");
 
-        for(int i = 0; i < list.size(); i ++){
-            String[] el = list.get(i);
-            if(tableData != null && tableData.containsKey(el[0])){
-                continue;
-            }
+        for(int i = 1; i < list.size(); i ++){
+            Map<String, Object> objectMap = list.get(i);
+            String apiPath = "/api/resource/v2/person/single/add";
+
             JsonObject paramJson = new JsonObject();
             paramJson.addProperty("clientId", i);
-            paramJson.addProperty("personId", el[0]);
-            paramJson.addProperty("personName", el[1]);
-            paramJson.addProperty("orgIndexCode", el[2]);
-            paramJson.addProperty("phoneNo", el[6]);
-            paramJson.addProperty("jobNo", el[3]);
-            paramJson.addProperty("birthday", el[5]);
+            paramJson.addProperty("personId", objectMap.get("id").toString());
+            paramJson.addProperty("personName", objectMap.get("name").toString());
+            paramJson.addProperty("orgIndexCode", objectMap.get("orgIndexCode").toString());
+            paramJson.addProperty("phoneNo", objectMap.get("mobile")==null?"":objectMap.get("mobile").toString());
+            paramJson.addProperty("jobNo", objectMap.get("user_name").toString());
+            paramJson.addProperty("birthday", objectMap.get("birthday")==null?"":objectMap.get("birthday").toString());
             paramJson.addProperty("personType", 2);
 
             int gender;
-            switch (el[4]) {
+            switch (objectMap.get("gender").toString()) {
                 case "SB10001":
                     gender = 1;
                     break;
@@ -219,18 +216,21 @@ class HikvisionBaseDataTaskTest {
             }
             paramJson.addProperty("gender", gender);
 
-            clientMap.put(i, el[0]);
-            System.out.println("请求参数:" + paramJson.toString());
+            if(tableData != null && tableData.containsKey(objectMap.get("id").toString())){
+                apiPath = "/api/resource/v1/person/single/update";
+                apiUtil.doPost(apiPath, paramJson.toString(), null, header);
+                continue;
+            }
+
+            clientMap.put(i, objectMap.get("id").toString());
             String result = apiUtil.doPost(apiPath, paramJson.toString(), null, header);
-            System.out.println("返回结果:" + result);
             JsonElement parse = jsonParser.parse(result);
             JsonObject resultJson = parse.getAsJsonObject();
             if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
                 JsonObject array = resultJson.get("data").getAsJsonObject();
-                idMap.put(el[0], array.get("personId").getAsString());
+                idMap.put(objectMap.get("id").toString(), array.get("personId").getAsString());
             }
         }
-        insertRecord(db, tableName, idMap);
         //插入记录表
         return idMap;
     }