ソースを参照

修改同步数据到排课系统

fanxp 3 ヶ月 前
コミット
ae8491de21

+ 70 - 20
src/main/java/com/xjrsoft/module/schedule/util/DataUtil.java

@@ -3,6 +3,7 @@ package com.xjrsoft.module.schedule.util;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.db.Entity;
+import com.alibaba.fastjson.JSON;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
@@ -11,9 +12,11 @@ import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
 import com.xjrsoft.common.utils.SqlRunnerAdapterUtil;
 import com.xjrsoft.module.base.entity.*;
 import com.xjrsoft.module.organization.entity.Department;
+import com.xjrsoft.module.schedule.vo.ScheduleFlowResponseVo;
 import com.xjrsoft.module.schedule.vo.StudentJianyuekbVo;
 import com.xjrsoft.module.teacher.entity.XjrUser;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.apm.toolkit.trace.ActiveSpan;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -44,7 +47,7 @@ public class DataUtil {
             paramJson.addProperty("name", department.getName());
 
             paramJson.addProperty("not", department.getRemark());
-            paramJson.addProperty("sort", department.getSortCode());
+            paramJson.addProperty("sort", department.getSortCode() == null ? 99 : department.getSortCode());
             paramJson.addProperty("shortName", department.getName());
             paramJson.addProperty("extendId", department.getId());
             long timestamp = System.currentTimeMillis();
@@ -53,15 +56,25 @@ public class DataUtil {
             if (ids != null && ids.get(department.getId().toString()) != null) {
                 url = ScheduleUtil.apiUrl + "SchoolDistrict/Update";
                 paramJson.addProperty("id", ids.get(department.getId().toString()));
-                ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                String resultUpdate = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(resultUpdate);
+                if (sfResponse != null && sfResponse.getCode() == -1) {
+                    ActiveSpan.tag("insertSchoolDistrictUpdateRequest", paramJson.toString());
+                    ActiveSpan.tag("insertSchoolDistrictUpdateResponse", resultUpdate);
+                }
                 continue;
             }
             String result = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
             if (result == null) {
                 continue;
             }
-            JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
-            idMap.put(department.getId().toString(), resultJson.get("data").getAsString());
+            ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(result);
+            if (sfResponse != null && sfResponse.getCode() != -1) {
+                idMap.put(department.getId().toString(), sfResponse.getData());
+            } else {
+                ActiveSpan.tag("insertSchoolDistrictInsertRequest", paramJson.toString());
+                ActiveSpan.tag("insertSchoolDistrictInsertResponse", result);
+            }
         }
         //插入记录表
         insertRecord(tableName, idMap);
@@ -119,7 +132,12 @@ public class DataUtil {
                 timestamp = System.currentTimeMillis();
                 //生成签名
                 sign = ScheduleUtil.createSign(timestamp);
-                ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                String resultUpdate = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(resultUpdate);
+                if (sfResponse != null && sfResponse.getCode() == -1) {
+                    ActiveSpan.tag("insertClassUpdateRequest", paramJson.toString());
+                    ActiveSpan.tag("insertClassUpdateResponse", resultUpdate);
+                }
                 continue;
             }
 
@@ -131,9 +149,12 @@ public class DataUtil {
             if (result == null) {
                 continue;
             }
-            JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
-            if (!"".equals(resultJson.get("data").getAsString())) {
-                idMap.put(baseClass.getId().toString(), resultJson.get("data").getAsString());
+            ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(result);
+            if (sfResponse != null && sfResponse.getCode() != -1) {
+                idMap.put(baseClass.getId().toString(), sfResponse.getData());
+            } else {
+                ActiveSpan.tag("insertSchoolDistrictInsertRequest", paramJson.toString());
+                ActiveSpan.tag("insertSchoolDistrictInsertResponse", result);
             }
         }
         //插入记录表
@@ -168,7 +189,12 @@ public class DataUtil {
             if (ids != null && ids.get(classroom.get("extendId").toString()) != null) {
                 url = ScheduleUtil.apiUrl + "classroom/update";
                 paramJson.addProperty("serialNo", ids.get(classroom.get("extendId").toString()));
-                ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                String resultUpdate =ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(resultUpdate);
+                if (sfResponse != null && sfResponse.getCode() == -1) {
+                    ActiveSpan.tag("insertClassRoomUpdateRequest", paramJson.toString());
+                    ActiveSpan.tag("insertClassRoomUpdateResponse", resultUpdate);
+                }
                 continue;
             }
 
@@ -176,8 +202,13 @@ public class DataUtil {
             if (result == null) {
                 continue;
             }
-            JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
-            idMap.put(classroom.get("extendId").toString(), resultJson.get("data").getAsString());
+            ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(result);
+            if (sfResponse != null && sfResponse.getCode() != -1) {
+                idMap.put(classroom.get("extendId").toString(), sfResponse.getData());
+            } else {
+                ActiveSpan.tag("insertSchoolDistrictInsertRequest", paramJson.toString());
+                ActiveSpan.tag("insertSchoolDistrictInsertResponse", result);
+            }
         }
         //插入记录表
         insertRecord(tableName, idMap);
@@ -269,7 +300,12 @@ public class DataUtil {
             if (ids != null && ids.get(user.get("id").toString()) != null) {
                 url = ScheduleUtil.apiUrl + "teacher/update";
                 paramJson.addProperty("serialNo", ids.get(user.get("id").toString()));
-                ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                String resultUpdate = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(resultUpdate);
+                if (sfResponse != null && sfResponse.getCode() == -1) {
+                    ActiveSpan.tag("insertTeacherUpdateRequest", paramJson.toString());
+                    ActiveSpan.tag("insertTeacherUpdateResponse", resultUpdate);
+                }
                 continue;
             }
 
@@ -277,8 +313,13 @@ public class DataUtil {
             if (result == null) {
                 continue;
             }
-            JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
-            idMap.put(user.get("id").toString(), resultJson.get("data").getAsString());
+            ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(result);
+            if (sfResponse != null && sfResponse.getCode() != -1) {
+                idMap.put(user.get("id").toString(), sfResponse.getData());
+            } else {
+                ActiveSpan.tag("insertSchoolDistrictInsertRequest", paramJson.toString());
+                ActiveSpan.tag("insertSchoolDistrictInsertResponse", result);
+            }
         }
         //插入记录表
         insertRecord(tableName, idMap);
@@ -462,15 +503,24 @@ public class DataUtil {
                 if (ids != null && ids.get(gradeId + "_" + baseGrade.getId().toString()) != null) {
                     paramJson.addProperty("serialNo", ids.get(gradeId + "_" + baseGrade.getId().toString()));
                     url = ScheduleUtil.apiUrl + "eduyear/update";
-                    ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                    String resultUpdate = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
+                    ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(resultUpdate);
+                    if (sfResponse != null && sfResponse.getCode() == -1) {
+                        ActiveSpan.tag("insertGradeUpdateRequest", paramJson.toString());
+                        ActiveSpan.tag("insertGradeUpdateResponse", resultUpdate);
+                    }
                     continue;
                 }
 
                 String result = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
 
-                JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
-
-                idMap.put(gradeId + "_" + baseGrade.getId().toString(), resultJson.get("data").getAsString());
+                ScheduleFlowResponseVo sfResponse = ScheduleUtil.ConvertResponse(result);
+                if (sfResponse != null && sfResponse.getCode() != -1) {
+                    idMap.put(gradeId + "_" + baseGrade.getId().toString(), sfResponse.getData());
+                } else {
+                    ActiveSpan.tag("insertGradeInsertRequest", paramJson.toString());
+                    ActiveSpan.tag("insertGradeInsertResponse", result);
+                }
             }
         }
 
@@ -647,7 +697,7 @@ public class DataUtil {
                     + (classroomMap.get(asJsonObject.get("classRoomSerialNo").getAsString()) == null ? 0 : classroomMap.get(asJsonObject.get("classRoomSerialNo").getAsString())) + ","
                     + "'" + asJsonObject.get("classRoomName").getAsString() + "',1,now(),"
                     + "'" + asJsonObject.get("scheduleDate").getAsString() + "',"
-                    + "'" + asJsonObject.get("id").getAsString() + "', '" + asJsonObject.get("startTime").getAsString() + "', '" + asJsonObject.get("endTime").getAsString() +"' FROM DUAL"
+                    + "'" + asJsonObject.get("id").getAsString() + "', '" + asJsonObject.get("startTime").getAsString() + "', '" + asJsonObject.get("endTime").getAsString() + "' FROM DUAL"
                     + " WHERE NOT EXISTS(SELECT 1 FROM course_table WHERE jianyue_id = '" + asJsonObject.get("id").getAsString() + "' and status = 1)";
 //            sqls.add(updateSql);
 //            sqls.add(sql);
@@ -674,7 +724,7 @@ public class DataUtil {
         Set<String> jianyueIds = new HashSet<>();
         for (JsonElement jsonElement : data) {
             JsonObject asJsonObject = jsonElement.getAsJsonObject();
-            if(jianyueIds.contains(asJsonObject.get("id").getAsString())){
+            if (jianyueIds.contains(asJsonObject.get("id").getAsString())) {
                 continue;
             }
             JsonArray teachers = asJsonObject.get("teachers").getAsJsonArray();

+ 10 - 0
src/main/java/com/xjrsoft/module/schedule/util/ScheduleUtil.java

@@ -1,6 +1,11 @@
 package com.xjrsoft.module.schedule.util;
 
 import cn.dev33.satoken.secure.SaSecureUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.xjrsoft.common.utils.SqlRunnerAdapterUtil;
+import com.xjrsoft.module.organization.entity.Department;
+import com.xjrsoft.module.schedule.vo.ScheduleFlowResponseVo;
 import lombok.extern.slf4j.Slf4j;
 
 import javax.crypto.Mac;
@@ -140,6 +145,11 @@ public class ScheduleUtil {
         return result;
     }
 
+    public static ScheduleFlowResponseVo ConvertResponse(String jsonStr) throws JsonProcessingException {
+        ObjectMapper mapper = new ObjectMapper();
+        return mapper.readValue(jsonStr, ScheduleFlowResponseVo.class);
+    }
+
     public static Map<Integer, String> getWeek() {
         Map<Integer, String> weekMap = new HashMap<>();
         weekMap.put(1, "周一");

+ 26 - 0
src/main/java/com/xjrsoft/module/schedule/vo/ScheduleFlowResponseVo.java

@@ -0,0 +1,26 @@
+package com.xjrsoft.module.schedule.vo;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ScheduleFlowResponseVo {
+    private String data;
+    @JsonProperty("isSuccess")   // 映射 JSON 的 isSuccess
+    private boolean success;
+    private int code;
+    private String msg;
+
+    // getter/setter
+    public String getData() { return data; }
+    public void setData(String data) { this.data = data; }
+
+    public boolean isSuccess() { return success; }
+    public void setSuccess(boolean success) { this.success = success; }
+
+    public int getCode() { return code; }
+    public void setCode(int code) { this.code = code; }
+
+    public String getMsg() { return msg; }
+    public void setMsg(String msg) { this.msg = msg; }
+}

+ 6 - 3
src/main/resources/application-dev.yml

@@ -5,9 +5,12 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://10.150.10.136:3308/tl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false&testWhileIdle=true
-    username: data_tl
-    password: qwe123QWE
+#    url: jdbc:mysql://10.150.10.136:3308/tl?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false&testWhileIdle=true
+#    username: data_tl
+#    password: qwe123QWE
+    url: jdbc:mysql://219.153.208.37:53256/smart_campus?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false
+    username: smart_campus
+    password: W2Xk@8QFe3hYR7QZ?-yY
     druid:
       # 验证连接的有效性
       test-while-idle: true

+ 1 - 1
src/main/resources/application-prod.yml

@@ -5,7 +5,7 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://219.153.208.35:3306/smart_campus?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false
+    url: jdbc:mysql://219.153.208.37:53256/smart_campus?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&autoReconnect=true&failOverReadOnly=false
     username: smart_campus
     password: W2Xk@8QFe3hYR7QZ?-yY
 

+ 98 - 0
src/test/java/com/xjrsoft/module/job/JianyuekbBaseDataTaskTest.java

@@ -101,6 +101,104 @@ class JianyuekbBaseDataTaskTest {
         }
     }
 
+    @Test
+    public void RefreshConnectionPoolTeacher() {
+        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
+        try {
+            Db use = Db.use(datasource);
+            String sql = "SELECT distinct table_name FROM jianyue_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 jianyue_data WHERE 0 = 0 and jianyue_id != ''";
+            List<JianyueData> list = use.query(sql, JianyueData.class);
+            Map<String, Map<String, String>> dataMap = new HashMap<>();
+            for (String table : tables) {
+                Map<String, String> tableData = new HashMap<>();
+                for (JianyueData jianyueData : list) {
+                    if(!table.equals(jianyueData.getTableName())){
+                        continue;
+                    }
+                    tableData.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
+                }
+                dataMap.put(table, tableData);
+            }
+            DataUtil dataUtil = new DataUtil();
+            //查询校区
+            String tableName = "xjr_department";
+
+            tableName = "base_teacher";
+            Map<String, String> teacherMap = dataUtil.insertTeacher(tableName, dataMap.get(tableName));
+        } catch (Exception e) {
+        }
+    }
+
+    @Test
+    public void RefreshConnectionPoolClass() {
+        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
+        try {
+            Db use = Db.use(datasource);
+            String sql = "SELECT distinct table_name FROM jianyue_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 jianyue_data WHERE 0 = 0 and jianyue_id != ''";
+            List<JianyueData> list = use.query(sql, JianyueData.class);
+            Map<String, Map<String, String>> dataMap = new HashMap<>();
+            for (String table : tables) {
+                Map<String, String> tableData = new HashMap<>();
+                for (JianyueData jianyueData : list) {
+                    if(!table.equals(jianyueData.getTableName())){
+                        continue;
+                    }
+                    tableData.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
+                }
+                dataMap.put(table, tableData);
+            }
+            DataUtil dataUtil = new DataUtil();
+
+            //查询校区
+            String tableName = "xjr_department";
+            Map<String, String> districtMap = dataUtil.insertSchoolDistrict(tableName, dataMap.get(tableName));
+            if (districtMap.isEmpty() && dataMap.get(tableName) != null) {
+                districtMap = dataMap.get(tableName);
+            }
+
+            //推送年级
+            JsonArray schoolDistrictData = dataUtil.getSchoolDistrictData();
+            tableName = "base_grade";
+            Map<String, String> grade = dataUtil.insertGrade(tableName, districtMap, dataMap.get(tableName));
+            if (grade.isEmpty() && dataMap.get(tableName) != null) {
+                grade = dataMap.get(tableName);
+            }
+
+            //推送教职工
+            tableName = "base_teacher";
+            Map<String, String> teacherMap = dataUtil.insertTeacher(tableName, dataMap.get(tableName));
+            if (teacherMap.isEmpty() && dataMap.get(tableName) != null) {
+                teacherMap = dataMap.get(tableName);
+            }
+
+            //推送教室
+            tableName = "base_classroom";
+            Map<String, String> classroomMap = dataUtil.insertClassRoom(tableName, schoolDistrictData.get(0).getAsString(), dataMap.get(tableName));
+            if (classroomMap.isEmpty() && dataMap.get(tableName) != null) {
+                classroomMap = dataMap.get(tableName);
+            }
+
+            //推送行政班,先查询当前学期id
+            String currenSemeter = dataUtil.getCurrenSemeter();
+            tableName = "base_class";
+            Map<String, String> classMap = dataUtil.insertClass(tableName, grade, teacherMap, currenSemeter, dataMap.get(tableName), classroomMap);;
+        } catch (Exception e) {
+            throw  new RuntimeException(e);
+        }
+    }
+
     @Test
     void test3() throws Exception {
         DataUtil dataUtil = new DataUtil();