|
@@ -2,18 +2,22 @@ package com.xjrsoft.module.job;
|
|
|
|
|
|
import cn.hutool.db.Entity;
|
|
import cn.hutool.db.Entity;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonParser;
|
|
import com.google.gson.JsonParser;
|
|
import com.xjrsoft.XjrSoftApplication;
|
|
import com.xjrsoft.XjrSoftApplication;
|
|
import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
|
+import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
|
+import com.xjrsoft.module.base.service.IBaseClassService;
|
|
import com.xjrsoft.module.schedule.entity.CourseReceiveMsg;
|
|
import com.xjrsoft.module.schedule.entity.CourseReceiveMsg;
|
|
import com.xjrsoft.module.schedule.util.DataUtil;
|
|
import com.xjrsoft.module.schedule.util.DataUtil;
|
|
import com.xjrsoft.module.schedule.util.ScheduleUtil;
|
|
import com.xjrsoft.module.schedule.util.ScheduleUtil;
|
|
import org.camunda.bpm.engine.impl.util.JsonUtil;
|
|
import org.camunda.bpm.engine.impl.util.JsonUtil;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
@@ -28,6 +32,7 @@ import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author dzx
|
|
* @author dzx
|
|
@@ -37,26 +42,49 @@ import java.util.Set;
|
|
@RunWith(SpringRunner.class)
|
|
@RunWith(SpringRunner.class)
|
|
@SpringBootTest(classes = XjrSoftApplication.class)
|
|
@SpringBootTest(classes = XjrSoftApplication.class)
|
|
class JianyuekbScheduleTaskTest {
|
|
class JianyuekbScheduleTaskTest {
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IBaseClassService classService;
|
|
@Test
|
|
@Test
|
|
public void RefreshConnectionPool() throws Exception {
|
|
public void RefreshConnectionPool() throws Exception {
|
|
String active = SpringUtil.getActiveProfile();
|
|
String active = SpringUtil.getActiveProfile();
|
|
- if(!"prod".equals(active)){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- String sql = "SELECT * FROM course_receive_msg WHERE delete_mark = 0 AND id in (1821034023531098114,1821034021123567617)";
|
|
|
|
|
|
+ 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);
|
|
List<Map<String, Object>> receiveMsgs = SqlRunnerAdapter.db().selectList(sql, CourseReceiveMsg.class);
|
|
JsonArray allScheduleInfo = new JsonArray();
|
|
JsonArray allScheduleInfo = new JsonArray();
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
DataUtil dataUtil = new DataUtil();
|
|
DataUtil dataUtil = new DataUtil();
|
|
|
|
+
|
|
|
|
+ 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 gradeId = el.get("source_id").toString().split("_")[1];
|
|
|
|
+ List<BaseClass> classList = classService.list(new QueryWrapper<BaseClass>().lambda().eq(BaseClass::getGradeId, gradeId));
|
|
|
|
+ List<Long> classIds = classList.stream().map(BaseClass::getId).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ gradeClassMaps.put(el.get("jianyue_id").toString(), classIds);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
for (Map<String, Object> receiveMsg : receiveMsgs) {
|
|
for (Map<String, Object> receiveMsg : receiveMsgs) {
|
|
String updSql = "update course_receive_msg set is_callback = 0 where id = " + receiveMsg.get("id").toString();
|
|
String updSql = "update course_receive_msg set is_callback = 0 where id = " + receiveMsg.get("id").toString();
|
|
SqlRunnerAdapter.db().update(updSql);
|
|
SqlRunnerAdapter.db().update(updSql);
|
|
|
|
|
|
String eduYearSerialNo = receiveMsg.get("edu_year_serial_no").toString();
|
|
String eduYearSerialNo = receiveMsg.get("edu_year_serial_no").toString();
|
|
|
|
+ String startDateStr = receiveMsg.get("start_date").toString();
|
|
|
|
+ String endDateStr = receiveMsg.get("end_date").toString();
|
|
|
|
+ //删除课表信息
|
|
|
|
+ String delSql = "delete from course_table where schedule_date between '" + startDateStr + "'" +
|
|
|
|
+ " and '" + endDateStr + "'" +
|
|
|
|
+ " and class_id in (" + gradeClassMaps.get(eduYearSerialNo).toString().replace("[","").replace("]","")+ ")";
|
|
|
|
+ SqlRunnerAdapter.db().delete(delSql);
|
|
|
|
|
|
- LocalDate startDateObj = LocalDate.parse(receiveMsg.get("start_date").toString());
|
|
|
|
- LocalDate endDateObj = LocalDate.parse(receiveMsg.get("end_date").toString());
|
|
|
|
|
|
+ LocalDate startDateObj = LocalDate.parse(startDateStr);
|
|
|
|
+ LocalDate endDateObj = LocalDate.parse(endDateStr);
|
|
long between = ChronoUnit.DAYS.between(startDateObj, endDateObj);
|
|
long between = ChronoUnit.DAYS.between(startDateObj, endDateObj);
|
|
int times = Integer.parseInt(((between / 7) + 1) + "");
|
|
int times = Integer.parseInt(((between / 7) + 1) + "");
|
|
|
|
|
|
@@ -77,21 +105,7 @@ class JianyuekbScheduleTaskTest {
|
|
updSql = "update course_receive_msg set is_callback = 1 where id = " + receiveMsg.get("id").toString();
|
|
updSql = "update course_receive_msg set is_callback = 1 where id = " + receiveMsg.get("id").toString();
|
|
SqlRunnerAdapter.db().update(updSql);
|
|
SqlRunnerAdapter.db().update(updSql);
|
|
}
|
|
}
|
|
- doExecute(allScheduleInfo);
|
|
|
|
-// Map<String, JsonObject> infoMap = new HashMap<>();
|
|
|
|
-// Map<Integer, Integer> tmePeriod = ScheduleUtil.getTmePeriod();
|
|
|
|
-// for (JsonElement jsonElement : allScheduleInfo) {
|
|
|
|
-// JsonObject asJsonObject = jsonElement.getAsJsonObject();
|
|
|
|
-// String numberOfDayName = asJsonObject.get("numberOfDayName").getAsString();
|
|
|
|
-// JsonObject json = new JsonObject();
|
|
|
|
-// json.add("startTime", asJsonObject.get("startTime"));
|
|
|
|
-// json.add("endTime", asJsonObject.get("endTime"));
|
|
|
|
-// json.addProperty("tmePeriod", tmePeriod.get(asJsonObject.get("timeOption").getAsInt()));
|
|
|
|
-// json.add("numberOfDay", asJsonObject.get("numberOfDay"));
|
|
|
|
-// infoMap.put(numberOfDayName, json);
|
|
|
|
-// }
|
|
|
|
-// System.out.println(JsonUtil.asString(infoMap));
|
|
|
|
-
|
|
|
|
|
|
+// doExecute(allScheduleInfo);
|
|
}
|
|
}
|
|
|
|
|
|
void doExecute(JsonArray scheduleInfo){
|
|
void doExecute(JsonArray scheduleInfo){
|
|
@@ -189,4 +203,56 @@ class JianyuekbScheduleTaskTest {
|
|
SqlRunnerAdapter.db().dynamicInsertBatch(tableName, insertList);
|
|
SqlRunnerAdapter.db().dynamicInsertBatch(tableName, insertList);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @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"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ SqlRunnerAdapter.db().dynamicInsertBatch(tableName, insertList);
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|