|
@@ -1,19 +1,62 @@
|
|
|
package com.xjrsoft.module.job;
|
|
|
|
|
|
-import cn.hutool.db.Entity;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.google.gson.JsonArray;
|
|
|
-import com.google.gson.JsonElement;
|
|
|
-import com.google.gson.JsonObject;
|
|
|
-import com.google.gson.JsonParser;
|
|
|
import com.xjrsoft.XjrSoftApplication;
|
|
|
+import com.xjrsoft.common.enums.CourseAdjustTypeEnum;
|
|
|
+import com.xjrsoft.common.enums.EnabledMark;
|
|
|
+import com.xjrsoft.common.enums.WorkflowApproveType;
|
|
|
+import com.xjrsoft.common.enums.WorkflowMultiInstanceType;
|
|
|
import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
+import com.xjrsoft.common.utils.RedisUtil;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
+import com.xjrsoft.config.CommonPropertiesConfig;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
+import com.xjrsoft.module.courseTable.dto.ClassTeacherDto;
|
|
|
+import com.xjrsoft.module.courseTable.entity.CourseTable;
|
|
|
+import com.xjrsoft.module.courseTable.service.ICourseTableService;
|
|
|
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
|
|
|
+import com.xjrsoft.module.organization.entity.Department;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
+import com.xjrsoft.module.organization.service.IDepartmentService;
|
|
|
+import com.xjrsoft.module.organization.service.IUserService;
|
|
|
+import com.xjrsoft.module.organization.service.IWeChatService;
|
|
|
import com.xjrsoft.module.schedule.entity.CourseReceiveMsg;
|
|
|
+import com.xjrsoft.module.schedule.entity.CourseTableBak;
|
|
|
+import com.xjrsoft.module.schedule.entity.JianyueData;
|
|
|
+import com.xjrsoft.module.schedule.entity.WfCourseAdjust;
|
|
|
+import com.xjrsoft.module.schedule.service.ICourseReceiveMsgService;
|
|
|
+import com.xjrsoft.module.schedule.service.ICourseTableBakService;
|
|
|
+import com.xjrsoft.module.schedule.service.IJianyueDataService;
|
|
|
+import com.xjrsoft.module.schedule.service.IWfCourseAdjustService;
|
|
|
import com.xjrsoft.module.schedule.util.DataUtil;
|
|
|
-import com.xjrsoft.module.schedule.util.ScheduleUtil;
|
|
|
+import com.xjrsoft.module.teacher.entity.BaseTeacher;
|
|
|
+import com.xjrsoft.module.workflow.constant.WorkflowConstant;
|
|
|
+import com.xjrsoft.module.workflow.entity.WorkflowExtra;
|
|
|
+import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
|
|
|
+import com.xjrsoft.module.workflow.entity.WorkflowRecord;
|
|
|
+import com.xjrsoft.module.workflow.entity.XjrWorkflowOperateRecord;
|
|
|
+import com.xjrsoft.module.workflow.mapper.XjrWorkflowOperateRecordMapper;
|
|
|
+import com.xjrsoft.module.workflow.service.IWorkflowExecuteService;
|
|
|
+import com.xjrsoft.module.workflow.service.IWorkflowExtraService;
|
|
|
+import com.xjrsoft.module.workflow.service.IWorkflowFormRelationService;
|
|
|
+import com.xjrsoft.module.workflow.service.IWorkflowRecordService;
|
|
|
+import me.zhyd.oauth.log.Log;
|
|
|
+import org.camunda.bpm.engine.RuntimeService;
|
|
|
+import org.camunda.bpm.engine.TaskService;
|
|
|
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
|
|
|
+import org.camunda.bpm.engine.impl.persistence.entity.TaskEntity;
|
|
|
+import org.camunda.bpm.engine.runtime.ActivityInstance;
|
|
|
+import org.camunda.bpm.engine.runtime.ProcessInstance;
|
|
|
+import org.camunda.bpm.engine.task.Task;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -22,15 +65,16 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -44,16 +88,79 @@ import java.util.stream.Collectors;
|
|
|
class JianyuekbScheduleTaskTest {
|
|
|
@Autowired
|
|
|
private IBaseClassService classService;
|
|
|
+
|
|
|
+ private final static String taskKey = "jianyuekbScheduleTask";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWfCourseAdjustService adjustService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseTableService courseTableService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseTableBakService courseTableBakService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RuntimeService runtimeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWorkflowFormRelationService formRelationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaskService taskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWorkflowExecuteService workflowExecuteService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWorkflowRecordService workflowRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private XjrWorkflowOperateRecordMapper xjrWorkflowOperateRecordMapper;
|
|
|
+
|
|
|
+ private final static String wechatTemplate = "OO5Ryu9_6Hh5LQW0aKG7qu3g5uV8VxvBusq1i5UFesk";
|
|
|
+ private final static String noticeTeacherTemplate = "sHsmz7LRj7HLd7GSTS3r2jCLvK-4Wp19iGzEvYK8n_I";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWeChatService weChatService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonPropertiesConfig commonPropertiesConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWorkflowExtraService workflowExtraService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IJianyueDataService jianyueDataService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDepartmentService departmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICourseReceiveMsgService receiveMsgService;
|
|
|
+
|
|
|
@Test
|
|
|
- public void RefreshConnectionPool() throws Exception {
|
|
|
+ public void execute(){
|
|
|
+ doExecute();
|
|
|
+ }
|
|
|
+ public void doExecute() {
|
|
|
+ String active = SpringUtil.getActiveProfile();
|
|
|
+ if(!"prod".equals(active)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
String sql = "SELECT * FROM course_receive_msg WHERE delete_mark = 0 AND is_callback = -1";
|
|
|
List<Map<String, Object>> receiveMsgs = SqlRunnerAdapter.db().selectList(sql);
|
|
|
if(receiveMsgs.isEmpty()){
|
|
|
return;
|
|
|
}
|
|
|
- JsonArray allScheduleInfo = new JsonArray();
|
|
|
+
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- DataUtil dataUtil = new DataUtil();
|
|
|
|
|
|
List<String> eduYearSerialNo1 = receiveMsgs.stream().map(x -> "'" + x.get("edu_year_serial_no").toString() + "'").collect(Collectors.toList());
|
|
|
|
|
@@ -62,7 +169,7 @@ class JianyuekbScheduleTaskTest {
|
|
|
" 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<>();
|
|
|
+ Map<String, List<BaseClass>> gradeClassMaps = new HashMap<>();
|
|
|
for (Map<String, Object> el : jianyueData) {
|
|
|
String gradeId = el.get("source_id").toString();
|
|
|
String orgId = null;
|
|
@@ -76,78 +183,88 @@ class JianyuekbScheduleTaskTest {
|
|
|
.eq(BaseClass::getGradeId, gradeId)
|
|
|
.eq(BaseClass::getOrgId, orgId)
|
|
|
);
|
|
|
- List<Long> classIds = classList.stream().map(BaseClass::getId).collect(Collectors.toList());
|
|
|
-
|
|
|
- gradeClassMaps.put(el.get("jianyue_id").toString(), classIds);
|
|
|
+ gradeClassMaps.put(el.get("jianyue_id").toString(), classList);
|
|
|
}
|
|
|
LocalDate today = LocalDate.now();
|
|
|
- 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);
|
|
|
|
|
|
+ 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();
|
|
|
- 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);
|
|
|
+ Long courseReceiveMsgId = Long.parseLong(receiveMsg.get("id").toString());
|
|
|
+ if(ongoing.contains(eduYearSerialNo)){
|
|
|
+ continue;
|
|
|
}
|
|
|
-
|
|
|
- String classIds = gradeClassMaps.get(eduYearSerialNo).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);
|
|
|
-
|
|
|
- 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;
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
- String endDate = endTime.format(formatter);
|
|
|
-
|
|
|
- JsonArray scheduleInfo = dataUtil.getScheduleInfoByClass(eduYearSerialNo, startDate, endDate);
|
|
|
- allScheduleInfo.addAll(scheduleInfo);
|
|
|
- }
|
|
|
+
|
|
|
+ List<BaseClass> classList = gradeClassMaps.get(eduYearSerialNo);
|
|
|
+ List<Long> classIdList = classList.stream().map(BaseClass::getId).collect(Collectors.toList());
|
|
|
+ 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(classList, 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);
|
|
|
-
|
|
|
- updSql = "UPDATE wf_course_adjust SET enabled_mark = 0 WHERE adjust_type BETWEEN '" + startDateStr + "'" +
|
|
|
- " and '" + endDateStr + "' and class_id in (" + classIds + ")";
|
|
|
- SqlRunnerAdapter.db().update(updSql);
|
|
|
+ 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(classList, startDateStr, endDateStr);
|
|
|
+ }catch (Exception e){
|
|
|
+ Log.error(e.getMessage(), e);
|
|
|
+ }finally {
|
|
|
+ ongoing.remove(eduYearSerialNo);
|
|
|
+ redisUtil.set(taskKey, ongoing);
|
|
|
+ }
|
|
|
}
|
|
|
- doExecute(allScheduleInfo);
|
|
|
}
|
|
|
|
|
|
- void doExecute(JsonArray scheduleInfo){
|
|
|
- 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();
|
|
|
+ void insertCourse(JsonArray scheduleInfo, Map<String, Map<String, String>> dataMap, DataUtil dataUtil, Long courseReceiveMsgId, String startDate, String endDate){
|
|
|
|
|
|
String tableName = "base_grade";
|
|
|
|
|
@@ -167,168 +284,465 @@ class JianyuekbScheduleTaskTest {
|
|
|
tableName = "base_classroom";
|
|
|
Map<String, String> classroomMap = dataMap.get(tableName);
|
|
|
|
|
|
- dataUtil.insertCourseTableEntiy(scheduleInfo, classroomMap, courseMap, semesterMap, teacherMap, classMap, null, null, null);
|
|
|
+ Set<String> techerIds = dataUtil.insertCourseTableEntiy(scheduleInfo, classroomMap, courseMap, semesterMap,
|
|
|
+ teacherMap, classMap, courseReceiveMsgId, startDate, endDate);
|
|
|
+ sendMsg(techerIds, courseReceiveMsgId);
|
|
|
dataUtil.insertClassTime(scheduleInfo);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Test
|
|
|
- void updateClass() throws Exception {
|
|
|
- String url = ScheduleUtil.apiUrl + "Class/page";
|
|
|
- JsonObject pageJson = new JsonObject();
|
|
|
- pageJson.addProperty("pageSize", 200);
|
|
|
- pageJson.addProperty("pageIndex", 1);
|
|
|
- JsonParser parser = new JsonParser();
|
|
|
-
|
|
|
- long timestamp = System.currentTimeMillis();
|
|
|
- String sign = ScheduleUtil.createSign(timestamp);
|
|
|
-
|
|
|
- String doPost = ScheduleUtil.doPost(url, pageJson.toString(), sign, timestamp);
|
|
|
- System.out.println(doPost);
|
|
|
- JsonArray dataList = parser.parse(doPost).getAsJsonObject().get("data").getAsJsonObject().get("dataList").getAsJsonArray();
|
|
|
- String sql = "select * from base_class where delete_mark = 0";
|
|
|
- List<Map<String, Object>> classList = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- Map<String, Long> classMap = new HashMap<>();
|
|
|
- for (Map<String, Object> objectMap : classList) {
|
|
|
- classMap.put(objectMap.get("name").toString(), (Long)objectMap.get("id"));
|
|
|
+ void sendMsg(Set<String> techerIds, Long courseReceiveMsgId){
|
|
|
+ try {
|
|
|
+ CourseReceiveMsg receiveMsg = receiveMsgService.getById(courseReceiveMsgId);
|
|
|
+ JianyueData jianyueData = jianyueDataService.getOne(
|
|
|
+ new QueryWrapper<JianyueData>().lambda()
|
|
|
+ .eq(JianyueData::getJianyueId, receiveMsg.getEduYearSerialNo())
|
|
|
+ );
|
|
|
+ String[] sourceId = jianyueData.getSourceId().split("_");
|
|
|
+ Department department = departmentService.getById(sourceId[0]);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ List<User> userList = userService.listByIds(new ArrayList<>(techerIds));
|
|
|
+ for (User user : userList) {
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setTemplateId(noticeTeacherTemplate);
|
|
|
+ JSONObject paramJson = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject thing8 = new JSONObject();
|
|
|
+ thing8.put("value", "课表更新");
|
|
|
+ paramJson.put("thing8", thing8);
|
|
|
+
|
|
|
+ JSONObject thing2 = new JSONObject();
|
|
|
+ thing2.put("value", department.getName());
|
|
|
+ paramJson.put("thing2", thing2);
|
|
|
+
|
|
|
+ JSONObject thing6 = new JSONObject();
|
|
|
+ thing6.put("value", "教务处");
|
|
|
+ paramJson.put("thing6", thing6);
|
|
|
+
|
|
|
+ JSONObject time3 = new JSONObject();
|
|
|
+ time3.put("value", sdf.format(receiveMsg.getCreateDate()));
|
|
|
+ paramJson.put("time3", time3);
|
|
|
+
|
|
|
+ weChatSendMessageDto.setContent(paramJson);
|
|
|
+ weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
|
|
|
+
|
|
|
+ String openId = user.getOpenId();
|
|
|
+ if(openId != null && !"".equals(openId)){
|
|
|
+ weChatSendMessageDto.setUserId(openId);
|
|
|
+ weChatService.sendTemplateMessage(weChatSendMessageDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ Log.error(e.getMessage(), e);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- sql = "select * from jianyue_data where table_name = 'base_class'";
|
|
|
- List<Map<String, Object>> classList2 = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- Set<String> sourceIds = new HashSet<>();
|
|
|
- for (Map<String, Object> objectMap : classList2) {
|
|
|
- sourceIds.add(objectMap.get("jianyue_id").toString());
|
|
|
+ Map<String, Map<String, String>> initDataMap(){
|
|
|
+ Map<String, Map<String, String>> dataMap = new HashMap<>();
|
|
|
+ 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 source_id IS NOT NULL AND jianyue_id != ''";
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
|
|
|
|
|
|
- String tableName = "jianyue_data";
|
|
|
- List<Entity> insertList = new ArrayList<>();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- for (JsonElement jsonElement : dataList) {
|
|
|
- JsonObject object = jsonElement.getAsJsonObject();
|
|
|
- String serialNo = object.get("serialNo").getAsString();
|
|
|
- if(sourceIds.contains(serialNo)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- if(classMap.get(object.get("name").getAsString()) == null){
|
|
|
- continue;
|
|
|
+ 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());
|
|
|
}
|
|
|
- Entity entity = Entity.create(tableName);
|
|
|
- entity.set("create_date", sdf.format(new Date()));
|
|
|
- entity.set("table_name", "base_class");
|
|
|
- entity.set("source_id", classMap.get(object.get("name").getAsString()));
|
|
|
- entity.set("jianyue_id", serialNo);
|
|
|
- insertList.add(entity);
|
|
|
+ dataMap.put(table, tableData);
|
|
|
}
|
|
|
- SqlRunnerAdapter.db().dynamicInsertBatch(tableName, insertList);
|
|
|
-
|
|
|
+ return dataMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
- @Test
|
|
|
- void updateClass2() throws Exception {
|
|
|
- String url = ScheduleUtil.apiUrl + "Class/page";
|
|
|
- JsonObject pageJson = new JsonObject();
|
|
|
- pageJson.addProperty("pageSize", 200);
|
|
|
- pageJson.addProperty("pageIndex", 1);
|
|
|
- JsonParser parser = new JsonParser();
|
|
|
-
|
|
|
- long timestamp = System.currentTimeMillis();
|
|
|
- String sign = ScheduleUtil.createSign(timestamp);
|
|
|
-
|
|
|
- String doPost = ScheduleUtil.doPost(url, pageJson.toString(), sign, timestamp);
|
|
|
- System.out.println(doPost);
|
|
|
- JsonArray dataList = parser.parse(doPost).getAsJsonObject().get("data").getAsJsonObject().get("dataList").getAsJsonArray();
|
|
|
- String sql = "select * from base_class where delete_mark = 0";
|
|
|
- List<Map<String, Object>> classList = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- Map<String, Long> classMap = new HashMap<>();
|
|
|
- for (Map<String, Object> objectMap : classList) {
|
|
|
- classMap.put(objectMap.get("name").toString(), (Long)objectMap.get("id"));
|
|
|
+
|
|
|
+ * 课程数据同步完之后,处理调课和顶课申请
|
|
|
+ * 1、课程数据入库后,将新课表日期之后的的调课顶课数据再次更新到课表中
|
|
|
+ * 2、筛选出课表变化了的调课和顶课申请,通知发起人
|
|
|
+ * 3、顶课数据,如果顶课日期那天那个老师没有课,但是新发布的课表又有课了,需要把原来的顶课数据作废
|
|
|
+ */
|
|
|
+ public void handleCourseAdjust(List<BaseClass> classList, String startDate, String endDate){
|
|
|
+ List<Long> classIds = classList.stream().map(BaseClass::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, String> classMap = classList.stream().collect(Collectors.toMap(BaseClass::getId, BaseClass::getName));
|
|
|
+ List<CourseTableBak> bakList = courseTableBakService.list(
|
|
|
+ new QueryWrapper<CourseTableBak>().lambda()
|
|
|
+ .in(CourseTableBak::getClassId, classIds)
|
|
|
+ .between(CourseTableBak::getScheduleDate, startDate, endDate)
|
|
|
+ );
|
|
|
+ Set<Long> courseAdjustIdSet = bakList.stream().map(CourseTableBak::getWfCourseAdjustId).collect(Collectors.toSet());
|
|
|
+ List<Long> courseAdjustIds = new ArrayList<>(courseAdjustIdSet);
|
|
|
+ List<WfCourseAdjust> list = adjustService.list(
|
|
|
+ new MPJLambdaWrapper<WfCourseAdjust>()
|
|
|
+ .select(WfCourseAdjust::getId)
|
|
|
+ .select(WfCourseAdjust.class, x -> VoToColumnUtil.fieldsToColumns(WfCourseAdjust.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(WorkflowFormRelation.class, WorkflowFormRelation::getFormKeyValue, WfCourseAdjust::getId)
|
|
|
+ .in(!courseAdjustIds.isEmpty(), WfCourseAdjust::getId, courseAdjustIds)
|
|
|
+ .and(wq -> wq.between(WfCourseAdjust::getAdjustDate, startDate, endDate).or().between(WfCourseAdjust::getExchangeDate, startDate, endDate))
|
|
|
+ .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_COMPLETED)
|
|
|
+ );
|
|
|
+ List<WfCourseAdjust> cancelList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<Long> userIds = list.stream().map(WfCourseAdjust::getUserId).collect(Collectors.toList());
|
|
|
+ List<User> userList = userService.list(
|
|
|
+ new MPJLambdaWrapper<User>()
|
|
|
+ .select(User::getId)
|
|
|
+ .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(BaseTeacher.class, BaseTeacher::getUserId, User::getId)
|
|
|
+ .in(!userIds.isEmpty(), User::getId, userIds)
|
|
|
+ );
|
|
|
+ Map<Long, String> userOpenIdMap = new HashMap<>();
|
|
|
+ for (User user : userList) {
|
|
|
+ userOpenIdMap.put(user.getId(), user.getOpenId());
|
|
|
}
|
|
|
|
|
|
- sql = "select * from jianyue_data where table_name = 'base_class'";
|
|
|
- List<Map<String, Object>> classList2 = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- Set<String> sourceIds = new HashSet<>();
|
|
|
- for (Map<String, Object> objectMap : classList2) {
|
|
|
- sourceIds.add(objectMap.get("jianyue_id").toString());
|
|
|
- }
|
|
|
+ for (WfCourseAdjust courseAdjust : list) {
|
|
|
+ List<CourseTable> courseList = courseTableService.list(
|
|
|
+ new MPJLambdaWrapper<CourseTable>()
|
|
|
+ .select(CourseTable::getId)
|
|
|
+ .select(CourseTable.class, x -> VoToColumnUtil.fieldsToColumns(CourseTable.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(CourseTableBak.class, CourseTableBak::getKeyInfo, CourseTable::getKeyInfo)
|
|
|
+ .eq(CourseTableBak::getWfCourseAdjustId, courseAdjust.getId())
|
|
|
+ );
|
|
|
|
|
|
- String tableName = "jianyue_data";
|
|
|
- List<Entity> insertList = new ArrayList<>();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- for (JsonElement jsonElement : dataList) {
|
|
|
- JsonObject object = jsonElement.getAsJsonObject();
|
|
|
- String serialNo = object.get("serialNo").getAsString();
|
|
|
- if(sourceIds.contains(serialNo)){
|
|
|
- continue;
|
|
|
+ String[] courseIds = courseAdjust.getCourseId().split(",");
|
|
|
+ String[] exchangeCourseIds = null;
|
|
|
+ int courseCount = courseIds.length;
|
|
|
+ if (CourseAdjustTypeEnum.courseExchange.getCode().equals(courseAdjust.getAdjustType())) {
|
|
|
+ exchangeCourseIds = courseAdjust.getExchangeCourseId().split(",");
|
|
|
+ courseCount += exchangeCourseIds.length;
|
|
|
}
|
|
|
- if(classMap.get(object.get("name").getAsString()) == null){
|
|
|
+
|
|
|
+ Integer substituteTeacherCourseCount = courseTableService.getSubstituteTeacherCourseCountByParams(new ClassTeacherDto() {{
|
|
|
+ setWfCourseAdjustId(courseAdjust.getId());
|
|
|
+ setTeacherId(Long.parseLong(courseAdjust.getExchangeTeacherId()));
|
|
|
+ }});
|
|
|
+ if(courseList.size() != courseCount || substituteTeacherCourseCount > 0){
|
|
|
+
|
|
|
+ courseAdjust.setEnabledMark(EnabledMark.DISABLED.getCode());
|
|
|
+ courseAdjust.setModifyDate(new Date());
|
|
|
+ courseAdjust.setCancelReason("由于课表更新,当前调/顶课课程发生变化,该调顶课已失效,请重新发起调顶课");
|
|
|
+ cancelList.add(courseAdjust);
|
|
|
+ List<String> thing16Str = new ArrayList<>();
|
|
|
+ List<String> thing2Str = new ArrayList<>();
|
|
|
+ for (CourseTableBak tableBak : bakList) {
|
|
|
+ if(!tableBak.getWfCourseAdjustId().equals(courseAdjust.getId())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ thing16Str.add(classMap.get(tableBak.getId()));
|
|
|
+ thing2Str.add(tableBak.getClassName());
|
|
|
+ }
|
|
|
+
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setTemplateId(wechatTemplate);
|
|
|
+ JSONObject paramJson = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject thing16 = new JSONObject();
|
|
|
+ thing16.put("value", thing16Str.toString().replace(" ", "").replace("[", "").replace("]", ""));
|
|
|
+ paramJson.put("thing16", thing16);
|
|
|
+
|
|
|
+ JSONObject thing2 = new JSONObject();
|
|
|
+ thing2.put("value", thing2Str.toString().replace(" ", "").replace("[", "").replace("]", ""));
|
|
|
+ paramJson.put("thing2", thing2);
|
|
|
+
|
|
|
+ String const12Str = "";
|
|
|
+ if (CourseAdjustTypeEnum.courseExchange.getCode().equals(courseAdjust.getAdjustType())) {
|
|
|
+ const12Str = "调课失败";
|
|
|
+ } else if (CourseAdjustTypeEnum.courseSubstitute.getCode().equals(courseAdjust.getAdjustType())) {
|
|
|
+ const12Str = "顶课失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject const12 = new JSONObject();
|
|
|
+ const12.put("value", const12Str);
|
|
|
+ paramJson.put("const23", const12);
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject thing5 = new JSONObject();
|
|
|
+ thing5.put("value", "由于课表更新,该调顶课已失效");
|
|
|
+ paramJson.put("thing5", thing5);
|
|
|
+
|
|
|
+ String url = StrUtil.format(
|
|
|
+ "{}/xjrsoft/pages/workflow/look?processId={}&type=my",
|
|
|
+ commonPropertiesConfig.getDomainApp(),
|
|
|
+ "relation.getProcessId()"
|
|
|
+ );
|
|
|
+ weChatSendMessageDto.setContent(paramJson);
|
|
|
+ weChatSendMessageDto.setUrl(url);
|
|
|
+ weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
|
|
|
+ String openId = userOpenIdMap.get(courseAdjust.getUserId());
|
|
|
+ if(openId != null && !"".equals(openId)){
|
|
|
+ weChatSendMessageDto.setUserId(openId);
|
|
|
+ weChatService.sendTemplateMessage(weChatSendMessageDto);
|
|
|
+ }
|
|
|
continue;
|
|
|
}
|
|
|
- Entity entity = Entity.create(tableName);
|
|
|
- entity.set("create_date", sdf.format(new Date()));
|
|
|
- entity.set("table_name", "base_class");
|
|
|
- entity.set("source_id", classMap.get(object.get("name").getAsString()));
|
|
|
- entity.set("jianyue_id", serialNo);
|
|
|
- insertList.add(entity);
|
|
|
+ courseTableService.adjustCourse(courseAdjust);
|
|
|
+ }
|
|
|
+ if(!cancelList.isEmpty()){
|
|
|
+ adjustService.updateBatchById(cancelList);
|
|
|
}
|
|
|
- SqlRunnerAdapter.db().dynamicInsertBatch(tableName, insertList);
|
|
|
|
|
|
- }
|
|
|
+ List<WorkflowFormRelation> activeList = formRelationService.list(
|
|
|
+ new MPJLambdaWrapper<WorkflowFormRelation>()
|
|
|
+ .select(WorkflowFormRelation::getId)
|
|
|
+ .select(WorkflowFormRelation.class, x -> VoToColumnUtil.fieldsToColumns(WorkflowFormRelation.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(WfCourseAdjust.class, WfCourseAdjust::getId, WorkflowFormRelation::getFormKeyValue)
|
|
|
+ .in(!courseAdjustIds.isEmpty(), WfCourseAdjust::getId, courseAdjustIds)
|
|
|
+ .and(wq -> wq.between(WfCourseAdjust::getAdjustDate, startDate, endDate).or().between(WfCourseAdjust::getExchangeDate, startDate, endDate))
|
|
|
+ .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_ACTIVE)
|
|
|
+ );
|
|
|
+ for (WorkflowFormRelation relation : activeList) {
|
|
|
+ List<CourseTable> courseList = courseTableService.list(
|
|
|
+ new MPJLambdaWrapper<CourseTable>()
|
|
|
+ .select(CourseTable::getId)
|
|
|
+ .select(CourseTable.class, x -> VoToColumnUtil.fieldsToColumns(CourseTable.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(CourseTableBak.class, CourseTableBak::getKeyInfo, CourseTable::getKeyInfo)
|
|
|
+ .eq(CourseTableBak::getWfCourseAdjustId, relation.getFormKeyValue())
|
|
|
+ );
|
|
|
+ List<CourseTableBak> thisbakList = courseTableBakService.list(
|
|
|
+ new QueryWrapper<CourseTableBak>().lambda()
|
|
|
+ .eq(CourseTableBak::getWfCourseAdjustId, relation.getFormKeyValue())
|
|
|
+ );
|
|
|
+ if(courseList.size() == thisbakList.size()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ WfCourseAdjust courseAdjust = adjustService.getById(relation.getFormKeyValue());
|
|
|
+
|
|
|
+ List<String> thing16Str = new ArrayList<>();
|
|
|
+ List<String> thing2Str = new ArrayList<>();
|
|
|
+ for (CourseTableBak tableBak : bakList) {
|
|
|
+ if(!tableBak.getWfCourseAdjustId().equals(courseAdjust.getId())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- @Test
|
|
|
- void test2(){
|
|
|
- String sql = "SELECT schedule_date,weeks,time_period,time_number,teacher_id,class_id,COUNT(*) FROM course_table WHERE 1 = 1" +
|
|
|
- " GROUP BY schedule_date,weeks,time_period,time_number,teacher_id,class_id HAVING COUNT(*) > 1";
|
|
|
- List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- for (Map<String, Object> objectMap : list) {
|
|
|
- sql = "SELECT * FROM course_table WHERE schedule_date = '" + objectMap.get("schedule_date").toString() +"'" +
|
|
|
- " AND weeks = " + objectMap.get("weeks").toString() +
|
|
|
- " AND time_period = " + objectMap.get("time_period").toString() +
|
|
|
- " AND time_number = " + objectMap.get("time_number").toString() +
|
|
|
- " AND teacher_id = " + objectMap.get("teacher_id").toString() +
|
|
|
- " AND class_id = " + objectMap.get("class_id").toString();
|
|
|
- List<Map<String, Object>> list2 = SqlRunnerAdapter.db().selectList(sql);
|
|
|
-
|
|
|
- String delSql = "delete from course_table where id = " + list2.get(0).get("id").toString();
|
|
|
- SqlRunnerAdapter.db().delete(delSql);
|
|
|
+ thing16Str.add(classMap.get(tableBak.getId()));
|
|
|
+ thing2Str.add(tableBak.getClassName());
|
|
|
+ }
|
|
|
+
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setTemplateId(wechatTemplate);
|
|
|
+ JSONObject paramJson = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject thing16 = new JSONObject();
|
|
|
+ thing16.put("value", thing16Str.toString().replace(" ", "").replace("[", "").replace("]", ""));
|
|
|
+ paramJson.put("thing16", classMap);
|
|
|
+
|
|
|
+ JSONObject thing2 = new JSONObject();
|
|
|
+ thing2.put("value", thing2Str.toString().replace(" ", "").replace("[", "").replace("]", ""));
|
|
|
+ paramJson.put("thing2", thing2);
|
|
|
+
|
|
|
+ String const12Str = "";
|
|
|
+ if (CourseAdjustTypeEnum.courseExchange.getCode().equals(courseAdjust.getAdjustType())) {
|
|
|
+ const12Str = "调课失败";
|
|
|
+ } else if (CourseAdjustTypeEnum.courseSubstitute.getCode().equals(courseAdjust.getAdjustType())) {
|
|
|
+ const12Str = "顶课失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject const12 = new JSONObject();
|
|
|
+ const12.put("value", const12Str);
|
|
|
+ paramJson.put("const23", const12);
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject thing5 = new JSONObject();
|
|
|
+ thing5.put("value", "由于课表更新,该调顶课已失效");
|
|
|
+ paramJson.put("thing5", thing5);
|
|
|
+
|
|
|
+ weChatSendMessageDto.setContent(paramJson);
|
|
|
+ List<WorkflowExtra> extraList = workflowExtraService.list(
|
|
|
+ new QueryWrapper<WorkflowExtra>().lambda()
|
|
|
+ .eq(WorkflowExtra::getProcessId, relation.getProcessId())
|
|
|
+ .orderByDesc(WorkflowExtra::getStartTime)
|
|
|
+ );
|
|
|
+
|
|
|
+ if(!extraList.isEmpty()){
|
|
|
+ String url = StrUtil.format(
|
|
|
+ "{}/xjrsoft/pages/workflow/approval?taskId={}&processId={}&type=todo",
|
|
|
+ commonPropertiesConfig.getDomainApp(),
|
|
|
+ extraList.get(0).getTaskId(),
|
|
|
+ relation.getProcessId()
|
|
|
+ );
|
|
|
+ weChatSendMessageDto.setUrl(url);
|
|
|
+
|
|
|
+ weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
|
|
|
+ String openId = userOpenIdMap.get(courseAdjust.getExchangeTeacherId());
|
|
|
+ if(openId != null && !"".equals(openId)){
|
|
|
+ weChatSendMessageDto.setUserId(openId);
|
|
|
+ weChatService.sendTemplateMessage(weChatSendMessageDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String url = StrUtil.format(
|
|
|
+ "{}/xjrsoft/pages/workflow/look?processId={}&type=my",
|
|
|
+ commonPropertiesConfig.getDomainApp(),
|
|
|
+ relation.getProcessId()
|
|
|
+ );
|
|
|
+ weChatSendMessageDto.setUrl(url);
|
|
|
+ weChatSendMessageDto.setMsgId(IdUtil.getSnowflakeNextId() + "");
|
|
|
+ String openId = userOpenIdMap.get(courseAdjust.getUserId());
|
|
|
+ if(openId != null && !"".equals(openId)){
|
|
|
+ weChatSendMessageDto.setUserId(openId);
|
|
|
+ weChatService.sendTemplateMessage(weChatSendMessageDto);
|
|
|
+ }
|
|
|
+ String processId = relation.getProcessId();
|
|
|
+
|
|
|
+ List<Task> taskList = taskService.createTaskQuery().processInstanceId(processId).list();
|
|
|
+ Task task = taskList.stream().filter(x -> x.getProcessInstanceId().equals(processId)).findFirst().orElse(new TaskEntity());
|
|
|
+ Long schemaId = Convert.toLong(taskService.getVariable(task.getId(), WorkflowConstant.PROCESS_SCHEMA_ID_KEY));
|
|
|
+
|
|
|
+ ActivityInstance activityInstance = runtimeService.getActivityInstance(task.getProcessInstanceId());
|
|
|
+
|
|
|
+ String message = " 因课表更新之后当前课程已发生变更,该流程已内部终止,如还需调/顶课,请重新发起调/顶课流程";
|
|
|
+
|
|
|
+ runtimeService.createProcessInstanceModification(task.getProcessInstanceId())
|
|
|
+ .cancelActivityInstance(activityInstance.getId())
|
|
|
+ .cancelAllForActivity(activityInstance.getId())
|
|
|
+ .setAnnotation("因课表更新之后当前课程已发生变更,该流程已内部终止")
|
|
|
+ .execute();
|
|
|
+
|
|
|
+
|
|
|
+ WorkflowRecord record = new WorkflowRecord();
|
|
|
+ record.setNodeId(task.getId());
|
|
|
+ record.setNodeName(task.getName());
|
|
|
+ record.setNodeType(WorkflowConstant.USER_TASK_TYPE_NAME);
|
|
|
+ record.setProcessId(task.getProcessInstanceId());
|
|
|
+ record.setSchemaId(schemaId);
|
|
|
+ record.setNodeMultiType(WorkflowMultiInstanceType.NONE.getCode());
|
|
|
+ record.setRecordTime(LocalDateTime.now());
|
|
|
+ record.setWorkflowApproveType(WorkflowApproveType.FINISH.getCode());
|
|
|
+
|
|
|
+ record.setMessage(message);
|
|
|
+
|
|
|
+ workflowRecordService.save(record);
|
|
|
+
|
|
|
+
|
|
|
+ XjrWorkflowOperateRecord xjrWorkflowOperateRecord = new XjrWorkflowOperateRecord();
|
|
|
+ xjrWorkflowOperateRecord.setNodeId(task.getId());
|
|
|
+ xjrWorkflowOperateRecord.setNodeName(task.getName());
|
|
|
+ xjrWorkflowOperateRecord.setNodeType(WorkflowConstant.USER_TASK_TYPE_NAME);
|
|
|
+ xjrWorkflowOperateRecord.setProcessId(task.getProcessInstanceId());
|
|
|
+ xjrWorkflowOperateRecord.setSchemaId(schemaId);
|
|
|
+ xjrWorkflowOperateRecord.setNodeMultiType(WorkflowMultiInstanceType.NONE.getCode());
|
|
|
+ xjrWorkflowOperateRecord.setRecordTime(LocalDateTime.now());
|
|
|
+ xjrWorkflowOperateRecord.setUsageScenario(1);
|
|
|
+
|
|
|
+
|
|
|
+ xjrWorkflowOperateRecord.setOperateInfo(message);
|
|
|
+ xjrWorkflowOperateRecordMapper.insert(xjrWorkflowOperateRecord);
|
|
|
+
|
|
|
+
|
|
|
+ Optional<HistoricProcessInstance> historicProcessInstance = workflowExecuteService.getHistoricProcessInstance(processId);
|
|
|
+ historicProcessInstance.ifPresent(item -> {
|
|
|
+ formRelationService.updateCurrentState(new WorkflowFormRelation() {{
|
|
|
+ setProcessId(processId);
|
|
|
+ setCurrentState(item.getState());
|
|
|
+ setStartTime(item.getStartTime());
|
|
|
+ setEndTime(item.getEndTime());
|
|
|
+ }});
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- void test3(){
|
|
|
- String sql = "SELECT * FROM wf_course_adjust t1" +
|
|
|
- " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
|
|
|
- " WHERE adjust_type = 'course_substitute' AND t1.delete_mark = 0 AND t2.current_state = 'COMPLETED'";
|
|
|
- List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- for (Map<String, Object> objectMap : list) {
|
|
|
- List<String> split = Arrays.asList(objectMap.get("course_id").toString().split(","));
|
|
|
- sql = "update course_table set teacher_id = '" + objectMap.get("exchange_teacher_id").toString() + "' WHERE id in (" + split.toString().replace("[", "").replace("]", "") + ")";
|
|
|
|
|
|
- SqlRunnerAdapter.db().update(sql);
|
|
|
+
|
|
|
+ * 挂起未通过的流程
|
|
|
+ */
|
|
|
+ List<String> suspendedCourseAdjust(List<BaseClass> classList, String startDate, String endDate) {
|
|
|
+ List<Long> classIds = classList.stream().map(BaseClass::getId).collect(Collectors.toList());
|
|
|
+ List<CourseTableBak> bakList = courseTableBakService.list(
|
|
|
+ new QueryWrapper<CourseTableBak>().lambda()
|
|
|
+ .in(CourseTableBak::getClassId, classIds)
|
|
|
+ .between(CourseTableBak::getScheduleDate, startDate, endDate)
|
|
|
+ );
|
|
|
+ Set<Long> courseAdjustIdSet = bakList.stream().map(CourseTableBak::getWfCourseAdjustId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<Long> courseAdjustIds = new ArrayList<>(courseAdjustIdSet);
|
|
|
+ List<WorkflowFormRelation> list = formRelationService.list(
|
|
|
+ new MPJLambdaWrapper<WorkflowFormRelation>()
|
|
|
+ .select(WorkflowFormRelation::getId)
|
|
|
+ .select(WorkflowFormRelation.class, x -> VoToColumnUtil.fieldsToColumns(WorkflowFormRelation.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(WfCourseAdjust.class, WfCourseAdjust::getId, WorkflowFormRelation::getFormKeyValue)
|
|
|
+ .between(WfCourseAdjust::getAdjustDate, startDate, endDate)
|
|
|
+ .in(!courseAdjustIds.isEmpty(), WfCourseAdjust::getId, courseAdjustIds)
|
|
|
+ .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_ACTIVE)
|
|
|
+ );
|
|
|
+ List<String> processIds = new ArrayList<>();
|
|
|
+ for (WorkflowFormRelation relation : list) {
|
|
|
+ String processId = relation.getProcessId();
|
|
|
+ ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
|
|
|
+ List<Task> taskList = taskService.createTaskQuery().processInstanceId(processId).list();
|
|
|
+ Task task = taskList.stream().filter(x -> x.getProcessInstanceId().equals(processId)).findFirst().orElse(new TaskEntity());
|
|
|
+ Long schemaId = Convert.toLong(taskService.getVariable(task.getId(), WorkflowConstant.PROCESS_SCHEMA_ID_KEY));
|
|
|
+
|
|
|
+ WorkflowRecord record = new WorkflowRecord();
|
|
|
+ record.setNodeId(task.getId());
|
|
|
+ record.setNodeName(task.getName());
|
|
|
+ record.setNodeType(WorkflowConstant.USER_TASK_TYPE_NAME);
|
|
|
+ record.setProcessId(task.getProcessInstanceId());
|
|
|
+ record.setSchemaId(schemaId);
|
|
|
+ record.setNodeMultiType(WorkflowMultiInstanceType.NONE.getCode());
|
|
|
+ record.setRecordTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ if (processInstance.isSuspended()) {
|
|
|
+ runtimeService.activateProcessInstanceById(relation.getProcessId());
|
|
|
+
|
|
|
+ record.setMessage("课表同步成功,流程恢复");
|
|
|
+ } else {
|
|
|
+ runtimeService.suspendProcessInstanceById(relation.getProcessId());
|
|
|
+
|
|
|
+ record.setMessage("课表更新中,暂停流程审核,请等待课表更新完成之后进行审核");
|
|
|
+ }
|
|
|
+ workflowRecordService.save(record);
|
|
|
+ Optional<HistoricProcessInstance> historicProcessInstance = workflowExecuteService.getHistoricProcessInstance(processId);
|
|
|
+ historicProcessInstance.ifPresent(item -> {
|
|
|
+ formRelationService.updateCurrentState(new WorkflowFormRelation() {{
|
|
|
+ setProcessId(processId);
|
|
|
+ setCurrentState(item.getState());
|
|
|
+ setStartTime(item.getStartTime());
|
|
|
+ setEndTime(item.getEndTime());
|
|
|
+ }});
|
|
|
+ });
|
|
|
+
|
|
|
+ processIds.add(relation.getProcessId());
|
|
|
}
|
|
|
+ return processIds;
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- void test4(){
|
|
|
- String sql = "SELECT t1.* FROM wf_course_adjust t1" +
|
|
|
- " INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value" +
|
|
|
- " LEFT JOIN course_table_bak t3 ON t1.id = t3.wf_course_adjust_id" +
|
|
|
- " WHERE t1.adjust_type = 'course_substitute' " +
|
|
|
- " AND t2.current_state = 'COMPLETED'" +
|
|
|
- " AND t1.delete_mark = 0 " +
|
|
|
- " AND t3.wf_course_adjust_id IS NULL";
|
|
|
- List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
|
|
|
- String tableName = "course_table_bak";
|
|
|
- for (Map<String, Object> objectMap : list) {
|
|
|
- List<String> split = Arrays.asList(objectMap.get("course_id").toString().split(","));
|
|
|
- String insertSql = "INSERT INTO course_table_bak(id,base_semester_id,teacher_id,teacher_name,course_id,course_name,class_id,class_name,WEEK,weeks," +
|
|
|
- " weeks_cn,time_period,time_number,site_id,site_name,STATUS,err_msg,create_date,modify_date,jianyue_id,source_data,schedule_date,teacher_serial_no," +
|
|
|
- " wf_course_adjust_id,adjust_type)" +
|
|
|
- " SELECT id,base_semester_id,teacher_id,teacher_name,course_id,course_name,class_id,class_name,WEEK,weeks," +
|
|
|
- " weeks_cn,time_period,time_number,site_id,site_name,STATUS,err_msg,create_date,modify_date,jianyue_id,source_data,schedule_date,teacher_serial_no," +
|
|
|
- " " + objectMap.get("id").toString() + ",'course_substitute' FROM course_table " +
|
|
|
- " WHERE id IN (" + split.toString().replace("[", "").replace("]", "") + ")";
|
|
|
- SqlRunnerAdapter.db().insert(insertSql);
|
|
|
+
|
|
|
+ * 将挂起的流程恢复
|
|
|
+ */
|
|
|
+ void restoreCourseAdjust(List<String> processIds){
|
|
|
+ for (String processId : processIds) {
|
|
|
+ List<Task> taskList = taskService.createTaskQuery().processInstanceId(processId).list();
|
|
|
+ Task task = taskList.stream().filter(x -> x.getProcessInstanceId().equals(processId)).findFirst().orElse(new TaskEntity());
|
|
|
+ Long schemaId = Convert.toLong(taskService.getVariable(task.getId(), WorkflowConstant.PROCESS_SCHEMA_ID_KEY));
|
|
|
+
|
|
|
+ WorkflowRecord record = new WorkflowRecord();
|
|
|
+ record.setNodeId(task.getId());
|
|
|
+ record.setNodeName(task.getName());
|
|
|
+ record.setNodeType(WorkflowConstant.USER_TASK_TYPE_NAME);
|
|
|
+ record.setProcessId(task.getProcessInstanceId());
|
|
|
+ record.setSchemaId(schemaId);
|
|
|
+ record.setNodeMultiType(WorkflowMultiInstanceType.NONE.getCode());
|
|
|
+ record.setRecordTime(LocalDateTime.now());
|
|
|
+ record.setMessage("课表同步成功,流程恢复");
|
|
|
+ workflowRecordService.save(record);
|
|
|
+ runtimeService.activateProcessInstanceById(processId);
|
|
|
+
|
|
|
+ Optional<HistoricProcessInstance> historicProcessInstance = workflowExecuteService.getHistoricProcessInstance(processId);
|
|
|
+ historicProcessInstance.ifPresent(item -> {
|
|
|
+ formRelationService.updateCurrentState(new WorkflowFormRelation() {{
|
|
|
+ setProcessId(processId);
|
|
|
+ setCurrentState(item.getState());
|
|
|
+ setStartTime(item.getStartTime());
|
|
|
+ setEndTime(item.getEndTime());
|
|
|
+ }});
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|