|
|
@@ -0,0 +1,116 @@
|
|
|
+package com.xjrsoft.module.job;
|
|
|
+
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.google.gson.JsonArray;
|
|
|
+import com.xjrsoft.XjrSoftApplication;
|
|
|
+import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
+import com.xjrsoft.module.schedule.entity.CourseReceiveMsg;
|
|
|
+import com.xjrsoft.module.schedule.util.DataUtil;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author dzx
|
|
|
+ * @date 2024/8/7
|
|
|
+ */
|
|
|
+
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = XjrSoftApplication.class)
|
|
|
+class JianyuekbScheduleTaskTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void RefreshConnectionPool() throws SQLException, InterruptedException {
|
|
|
+ String active = SpringUtil.getActiveProfile();
|
|
|
+ if(!"prod".equals(active)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String sql = "SELECT * FROM course_receive_msg WHERE delete_mark = 0 AND is_callback IS NULL";
|
|
|
+ List<Map<String, Object>> receiveMsgs = SqlRunnerAdapter.db().selectList(sql, CourseReceiveMsg.class);
|
|
|
+ for (Map<String, Object> receiveMsg : receiveMsgs) {
|
|
|
+ String updSql = "update course_receive_msg set is_callback = 0 where id = " + receiveMsg.get("id").toString();
|
|
|
+ SqlRunnerAdapter.db().update(updSql);
|
|
|
+
|
|
|
+ doExecute(receiveMsg.get("edu_year_serial_no").toString(), receiveMsg.get("start_date").toString(), receiveMsg.get("end_date").toString());
|
|
|
+
|
|
|
+ updSql = "update course_receive_msg set is_callback = 1 where id = " + receiveMsg.get("id").toString();
|
|
|
+ SqlRunnerAdapter.db().update(updSql);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void doExecute(String eduYearSerialNo, String startDateStr, String endDateStr){
|
|
|
+ try {
|
|
|
+ String sql = "SELECT distinct table_name FROM jianyue_data WHERE 1 = 1";
|
|
|
+ List<Map<String, Object>> query = SqlRunnerAdapter.db().selectList(sql);
|
|
|
+ Set<String> tables = new HashSet<>();
|
|
|
+ for (Map<String, Object> jianyueData : query) {
|
|
|
+ tables.add(jianyueData.get("table_name").toString());
|
|
|
+ }
|
|
|
+ sql = "SELECT * FROM jianyue_data WHERE 0 = 0";
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
|
|
|
+ Map<String, Map<String, String>> dataMap = new HashMap<>();
|
|
|
+ for (String table : tables) {
|
|
|
+ Map<String, String> tableData = new HashMap<>();
|
|
|
+ for (Map<String, Object> jianyueData : list) {
|
|
|
+ if(!table.equals(jianyueData.get("table_name").toString())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ tableData.put(jianyueData.get("jianyue_id").toString(), jianyueData.get("source_id").toString());
|
|
|
+ }
|
|
|
+ dataMap.put(table, tableData);
|
|
|
+ }
|
|
|
+ DataUtil dataUtil = new DataUtil();
|
|
|
+ //获取年级
|
|
|
+ String tableName = "base_grade";
|
|
|
+// Map<String, Long> gradeMap = dataMap.get(tableName);
|
|
|
+ //获取学期
|
|
|
+ tableName = "base_semester";
|
|
|
+ Map<String, String> semesterMap = dataMap.get(tableName);
|
|
|
+ //获取课程
|
|
|
+ tableName = "base_course_subject";
|
|
|
+ Map<String, String> courseMap = dataMap.get(tableName);
|
|
|
+ //获取教职工
|
|
|
+ tableName = "base_teacher";
|
|
|
+ Map<String, String> teacherMap = dataMap.get(tableName);
|
|
|
+ //获取行政班
|
|
|
+ tableName = "base_class";
|
|
|
+ Map<String, String> classMap = dataMap.get(tableName);
|
|
|
+
|
|
|
+ tableName = "base_classroom";
|
|
|
+ Map<String, String> classroomMap = dataMap.get(tableName);
|
|
|
+ LocalDate startDateObj = LocalDate.parse(startDateStr);
|
|
|
+ LocalDate endDateObj = LocalDate.parse(endDateStr);
|
|
|
+ long between = ChronoUnit.DAYS.between(startDateObj, endDateObj);
|
|
|
+ long times = (between / 7) + 1;
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ for (int i = 0; i < times; i ++) {
|
|
|
+ LocalDate statrTime = startDateObj.plusDays(i * 7L);
|
|
|
+ String startDate = statrTime.format(formatter);
|
|
|
+ LocalDate endTime = statrTime.plusDays(6L);
|
|
|
+ if(endTime.isAfter(endDateObj)){
|
|
|
+ endTime = endDateObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ String endDate = endTime.format(formatter);
|
|
|
+ //获取课表并存到数据库
|
|
|
+ JsonArray scheduleInfo = dataUtil.getScheduleInfoByGrade(eduYearSerialNo, startDate, endDate);
|
|
|
+ dataUtil.insertCourseTableEntiy(scheduleInfo, classroomMap, courseMap, semesterMap, teacherMap, classMap);
|
|
|
+ dataUtil.insertClassTime(scheduleInfo);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|