|
|
@@ -145,10 +145,14 @@ class JianyuekbScheduleTaskTest {
|
|
|
@Autowired
|
|
|
private ICourseReceiveMsgService receiveMsgService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private JianyuekbScheduleTask jianyuekbScheduleTask;
|
|
|
+
|
|
|
@Test
|
|
|
public void execute(){
|
|
|
doExecute();
|
|
|
}
|
|
|
+
|
|
|
public void doExecute() {
|
|
|
String active = SpringUtil.getActiveProfile();
|
|
|
// if(!"prod".equals(active)){
|
|
|
@@ -160,104 +164,7 @@ class JianyuekbScheduleTaskTest {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- //查询出传入排课系统的年级和班级
|
|
|
- List<String> eduYearSerialNo1 = receiveMsgs.stream().map(x -> "'" + x.get("edu_year_serial_no").toString() + "'").collect(Collectors.toList());
|
|
|
-
|
|
|
- //查询出传入排课系统的年级和班级
|
|
|
- sql = "SELECT * FROM jianyue_data WHERE source_id IS NOT NULL AND jianyue_id != ''" +
|
|
|
- " and table_name = 'base_grade'" +
|
|
|
- " and jianyue_id in (" + eduYearSerialNo1.toString().replace("[","").replace("]","") + ")";
|
|
|
- List<Map<String, Object>> jianyueData = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- Map<String, List<Long>> gradeClassMaps = new HashMap<>();//存入对应年级的所有班级id
|
|
|
- for (Map<String, Object> el : jianyueData) {
|
|
|
-
|
|
|
- String clasSql = "select source_id from jianyue_data where extend_data = '" + el.get("jianyue_id").toString() + "'";
|
|
|
- List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(clasSql);
|
|
|
-
|
|
|
- List<Long> classList = new ArrayList<>();
|
|
|
- for (Map<String, Object> objectMap : list) {
|
|
|
- classList.add(Long.parseLong(objectMap.get("source_id").toString()));
|
|
|
- }
|
|
|
-
|
|
|
- gradeClassMaps.put(el.get("jianyue_id").toString(), classList);
|
|
|
- }
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
-
|
|
|
- DataUtil dataUtil = new DataUtil();
|
|
|
- Set<String> ongoing = redisUtil.get(taskKey, new TypeReference<Set<String>>() {});//正在进行中的
|
|
|
- if(ongoing == null){
|
|
|
- ongoing = new HashSet<>();
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Map<String, String>> dataMap = initDataMap();
|
|
|
- for (Map<String, Object> receiveMsg : receiveMsgs) {
|
|
|
- String eduYearSerialNo = receiveMsg.get("edu_year_serial_no").toString();
|
|
|
- Long courseReceiveMsgId = Long.parseLong(receiveMsg.get("id").toString());
|
|
|
- if(ongoing.contains(eduYearSerialNo)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- ongoing.add(eduYearSerialNo);
|
|
|
- redisUtil.set(taskKey, ongoing);
|
|
|
-
|
|
|
- try {
|
|
|
- String updSql = "update course_receive_msg set is_callback = 0 where id = " + receiveMsg.get("id").toString();
|
|
|
- SqlRunnerAdapter.db().update(updSql);
|
|
|
-
|
|
|
- JsonArray allScheduleInfo = new JsonArray();
|
|
|
- String startDateStr = receiveMsg.get("start_date").toString();
|
|
|
- LocalDate startDateObj = LocalDate.parse(startDateStr);
|
|
|
- String endDateStr = receiveMsg.get("end_date").toString();
|
|
|
- LocalDate endDateObj = LocalDate.parse(endDateStr);
|
|
|
-// if(today.isAfter(startDateObj)){
|
|
|
-// startDateStr = today.format(formatter);
|
|
|
-// }
|
|
|
-
|
|
|
- //删除课表信息;
|
|
|
- List<Long> classIdList = gradeClassMaps.get(eduYearSerialNo);
|
|
|
- String classIds = classIdList.toString().replace("[", "").replace("]", "");
|
|
|
- String delSql = "delete from course_table where schedule_date between '" + startDateStr + "'" +
|
|
|
- " and '" + endDateStr +
|
|
|
- "' and class_id in (" + classIds + ")";
|
|
|
- SqlRunnerAdapter.db().delete(delSql);
|
|
|
-
|
|
|
- startDateStr = receiveMsg.get("start_date").toString();
|
|
|
- List<String> processIds = suspendedCourseAdjust(classIdList, startDateStr, endDateStr);
|
|
|
-
|
|
|
- long between = ChronoUnit.DAYS.between(startDateObj, endDateObj);
|
|
|
- int times = Integer.parseInt(((between / 7) + 1) + "");
|
|
|
-
|
|
|
- for (int index = 0; index < times; index ++) {
|
|
|
- LocalDate statrTime = startDateObj.plusDays(index * 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);
|
|
|
- allScheduleInfo.addAll(scheduleInfo);
|
|
|
- }
|
|
|
-
|
|
|
- updSql = "update course_receive_msg set is_callback = 1 where id = " + receiveMsg.get("id").toString();
|
|
|
- SqlRunnerAdapter.db().update(updSql);
|
|
|
-
|
|
|
- ongoing.remove(eduYearSerialNo);
|
|
|
- redisUtil.set(taskKey, ongoing);
|
|
|
- insertCourse(allScheduleInfo, dataMap, dataUtil, courseReceiveMsgId, startDateStr, endDateStr);
|
|
|
- //恢复挂起的流程
|
|
|
- restoreCourseAdjust(processIds);
|
|
|
- //处理该日期内已经审批通过的调课和顶课申请
|
|
|
- handleCourseAdjust(classIdList, startDateStr, endDateStr);
|
|
|
- }catch (Exception e){
|
|
|
- Log.error(e.getMessage(), e);
|
|
|
- }finally {
|
|
|
- ongoing.remove(eduYearSerialNo);
|
|
|
- redisUtil.set(taskKey, ongoing);
|
|
|
- }
|
|
|
- }
|
|
|
+ jianyuekbScheduleTask.syncCourseTable(receiveMsgs);
|
|
|
}
|
|
|
|
|
|
void insertCourse(JsonArray scheduleInfo, Map<String, Map<String, String>> dataMap, DataUtil dataUtil, Long courseReceiveMsgId, String startDate, String endDate){
|