|
@@ -1,11 +1,12 @@
|
|
|
package com.xjrsoft.module.schedule.util;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.db.Db;
|
|
|
import com.google.gson.JsonArray;
|
|
|
import com.google.gson.JsonElement;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.google.gson.JsonParser;
|
|
|
+import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
+import com.xjrsoft.common.utils.SqlRunnerAdapterUtil;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
import com.xjrsoft.module.base.entity.BaseCourseSubject;
|
|
|
import com.xjrsoft.module.base.entity.BaseGrade;
|
|
@@ -17,9 +18,7 @@ import com.xjrsoft.module.schedule.vo.StudentJianyuekbVo;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
-import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -36,15 +35,16 @@ public class DataUtil {
|
|
|
* 推送校区信息
|
|
|
* 此处将班级所属的部门当做校区进行推送
|
|
|
*/
|
|
|
- public Map<String, String> insertSchoolDistrict(Db db, String tableName, Map<String, String> ids) throws Exception {
|
|
|
+ public Map<String, String> insertSchoolDistrict(String tableName, Map<String, String> ids) throws Exception {
|
|
|
String sql = "SELECT * FROM " + tableName + " WHERE id IN (" +
|
|
|
"SELECT DISTINCT org_id FROM base_class WHERE delete_mark = 0 " +
|
|
|
")";
|
|
|
- List<Department> dataList = db.query(sql, Department.class);
|
|
|
+ List<Map<String, Object>> dataList = SqlRunnerAdapter.db().selectList(sql, Department.class);
|
|
|
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
- for (Department department : dataList) {
|
|
|
+ for (Map<String, Object> departmentMap : dataList) {
|
|
|
+ Department department = SqlRunnerAdapterUtil.convertMapToEntity(departmentMap, Department.class);
|
|
|
String url = ScheduleUtil.apiUrl + "SchoolDistrict/Create";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("name", department.getName());
|
|
@@ -70,18 +70,19 @@ public class DataUtil {
|
|
|
idMap.put(department.getId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> insertClass(Db db, String tableName, Map<String, String> gradeMap,
|
|
|
+ public Map<String, String> insertClass(String tableName, Map<String, String> gradeMap,
|
|
|
Map<String, String> teacherMap, String semesterSerialNo, Map<String, String> ids, Map<String, String> classroomMap) throws Exception {
|
|
|
String sql = "SELECT * FROM " + tableName + " WHERE delete_mark = 0 and is_graduate = 1";
|
|
|
- List<BaseClass> dataList = db.query(sql, BaseClass.class);
|
|
|
+ List<Map<String, Object>> dataList = SqlRunnerAdapter.db().selectList(sql, BaseClass.class);
|
|
|
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
- for (BaseClass baseClass : dataList) {
|
|
|
+ for (Map<String, Object> baseClassMap : dataList) {
|
|
|
+ BaseClass baseClass = SqlRunnerAdapterUtil.convertMapToEntity(baseClassMap, BaseClass.class);
|
|
|
String url = ScheduleUtil.apiUrl + "class/create";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("teacherSerialNo", teacherMap.get(baseClass.getTeacherId().toString()));
|
|
@@ -113,19 +114,20 @@ public class DataUtil {
|
|
|
idMap.put(baseClass.getId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> insertClassRoom(Db db, String tableName, String schoolDistrictId, Map<String, String> ids) throws Exception {
|
|
|
+ public Map<String, String> insertClassRoom(String tableName, String schoolDistrictId, Map<String, String> ids) throws Exception {
|
|
|
String sql = "SELECT t1.name, t1.capacity AS people_count,t2.name AS location, t1.floor_num AS floor, t1.id AS extendId FROM " + tableName + " t1" +
|
|
|
" INNER JOIN base_office_build t2 ON t1.office_build_id = t2.id" +
|
|
|
" WHERE t1.delete_mark = 0 AND t2.delete_mark = 0";
|
|
|
- List<ClassroomJianyuekbVo> dataList = db.query(sql, ClassroomJianyuekbVo.class);
|
|
|
+ List<Map<String, Object>> dataList = SqlRunnerAdapter.db().selectList(sql, ClassroomJianyuekbVo.class);
|
|
|
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
- for (ClassroomJianyuekbVo classroom : dataList) {
|
|
|
+ for (Map<String, Object> classroomMap : dataList) {
|
|
|
+ ClassroomJianyuekbVo classroom = SqlRunnerAdapterUtil.convertMapToEntity(classroomMap, ClassroomJianyuekbVo.class);
|
|
|
String url = ScheduleUtil.apiUrl + "classroom/create";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("schoolDistrictId", schoolDistrictId);
|
|
@@ -156,11 +158,11 @@ public class DataUtil {
|
|
|
idMap.put(classroom.getExtendId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> insertStudent(Db db, String tableName, Map<String, String> gradeMap, Map<String, String> ids) throws Exception {
|
|
|
+ public Map<String, String> insertStudent(String tableName, Map<String, String> gradeMap, Map<String, String> ids) throws Exception {
|
|
|
String sql = "SELECT t1.id AS registerNo, t2.name AS realName,t3.grade_id AS gradeSerialNo," +
|
|
|
" t2.name AS alias,t2.gender,t2.id AS extendId FROM " + tableName + " t1" +
|
|
|
" INNER JOIN xjr_user t2 ON t1.user_id = t2.id" +
|
|
@@ -168,11 +170,12 @@ public class DataUtil {
|
|
|
" WHERE t1.delete_mark = 0 AND t2.delete_mark = 0" +
|
|
|
" AND t1.student_id IS NOT NULL AND t1.student_id != ''" +
|
|
|
" AND t3.archives_status = 'FB2901'";
|
|
|
- List<StudentJianyuekbVo> dataList = db.query(sql, StudentJianyuekbVo.class);
|
|
|
+ List<Map<String, Object>> dataList = SqlRunnerAdapter.db().selectList(sql, StudentJianyuekbVo.class);
|
|
|
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
- for (StudentJianyuekbVo student : dataList) {
|
|
|
+ for (Map<String, Object> studentMap : dataList) {
|
|
|
+ StudentJianyuekbVo student = SqlRunnerAdapterUtil.convertMapToEntity(studentMap, StudentJianyuekbVo.class);
|
|
|
String url = ScheduleUtil.apiUrl + "student/create";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("registerNo", student.getRegisterNo());
|
|
@@ -206,22 +209,23 @@ public class DataUtil {
|
|
|
idMap.put(student.getExtendId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
* 新增教职工
|
|
|
*/
|
|
|
- public Map<String, String> insertTeacher(Db db, String tableName, Map<String, String> ids) throws Exception {
|
|
|
+ public Map<String, String> insertTeacher(String tableName, Map<String, String> ids) throws Exception {
|
|
|
String sql = "select t1.* from xjr_user t1" +
|
|
|
" inner join xjr_user_role_relation t2 on t1.id = t2.user_id" +
|
|
|
" inner join " + tableName + " t3 on t1.id = t3.user_id" +
|
|
|
" where t1.delete_mark = 0 and t2.role_id = 2";
|
|
|
- List<XjrUser> xjrUsers = db.query(sql, XjrUser.class);
|
|
|
+ List<Map<String, Object>> xjrUsers = SqlRunnerAdapter.db().selectList(sql, XjrUser.class);
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
- for (XjrUser user : xjrUsers) {
|
|
|
+ for (Map<String, Object> userMap : xjrUsers) {
|
|
|
+ XjrUser user = SqlRunnerAdapterUtil.convertMapToEntity(userMap, XjrUser.class);
|
|
|
String url = ScheduleUtil.apiUrl + "teacher/create";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("jobNumber", user.getUserName());
|
|
@@ -253,19 +257,20 @@ public class DataUtil {
|
|
|
idMap.put(user.getId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
* 新增课程
|
|
|
*/
|
|
|
- public Map<String, String> insertCourse(Db db, String tableName, Map<String, String> ids, Map<String, String> tagMap) throws Exception {
|
|
|
+ public Map<String, String> insertCourse(String tableName, Map<String, String> ids, Map<String, String> tagMap) throws Exception {
|
|
|
String sql = "select * from " + tableName + " where delete_mark = 0";
|
|
|
- List<BaseCourseSubject> list = db.query(sql, BaseCourseSubject.class);
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, BaseCourseSubject.class);
|
|
|
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
- for (BaseCourseSubject courseSubject : list) {
|
|
|
+ for (Map<String, Object> courseSubjectMap : list) {
|
|
|
+ BaseCourseSubject courseSubject = SqlRunnerAdapterUtil.convertMapToEntity(courseSubjectMap, BaseCourseSubject.class);
|
|
|
String url = ScheduleUtil.apiUrl + "courseclass/Create";
|
|
|
|
|
|
JsonObject paramJson = new JsonObject();
|
|
@@ -298,7 +303,7 @@ public class DataUtil {
|
|
|
idMap.put(courseSubject.getId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
|
|
|
return idMap;
|
|
|
}
|
|
@@ -306,9 +311,9 @@ public class DataUtil {
|
|
|
|
|
|
* 新增学期
|
|
|
*/
|
|
|
- public Map<String, String> insertSemester(Db db, String tableName, Map<String, String> ids) throws Exception {
|
|
|
+ public Map<String, String> insertSemester(String tableName, Map<String, String> ids) throws Exception {
|
|
|
String sql = "select * from " + tableName + " where delete_mark = 0";
|
|
|
- List<BaseSemester> list = db.query(sql, BaseSemester.class);
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, BaseSemester.class);
|
|
|
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
@@ -317,7 +322,8 @@ public class DataUtil {
|
|
|
String spring = "春";
|
|
|
String autumn = "秋";
|
|
|
|
|
|
- for (BaseSemester semester : list) {
|
|
|
+ for (Map<String, Object> semesterMap : list) {
|
|
|
+ BaseSemester semester = SqlRunnerAdapterUtil.convertMapToEntity(semesterMap, BaseSemester.class);
|
|
|
String url = ScheduleUtil.apiUrl + "semester/Create";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("schoolYear", Integer.parseInt(sdfYear.format(semester.getStartDate())));
|
|
@@ -356,19 +362,20 @@ public class DataUtil {
|
|
|
idMap.put(semester.getId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> insertCourseTag(Db db, String tableName, Map<String, String> ids) throws Exception {
|
|
|
+ public Map<String, String> insertCourseTag(String tableName, Map<String, String> ids) throws Exception {
|
|
|
String sql = "select * from " + tableName + " where delete_mark = 0" +
|
|
|
" and id in (select distinct base_label_id from base_course_subject where delete_mark = 0)";
|
|
|
- List<BaseLabel> list = db.query(sql, BaseLabel.class);
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, BaseLabel.class);
|
|
|
String url = ScheduleUtil.apiUrl + "courseclass/tag/create";
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
- for (BaseLabel department : list) {
|
|
|
+ for (Map<String, Object> departmentMap : list) {
|
|
|
+ BaseLabel department = SqlRunnerAdapterUtil.convertMapToEntity(departmentMap, BaseLabel.class);
|
|
|
if(ids != null && ids.get(department.getId().toString()) != null){
|
|
|
continue;
|
|
|
}
|
|
@@ -387,26 +394,26 @@ public class DataUtil {
|
|
|
idMap.put(department.getId().toString(), resultJson.get("data").getAsString());
|
|
|
}
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
* 插入年级
|
|
|
- * @param db 数据库链接
|
|
|
* @param tableName 表名字
|
|
|
* @param schoolDistrictMap 校区id
|
|
|
* @param ids 数据库id和jianyue的对应关系
|
|
|
* @return 返回数据库和jianyue的对应关系
|
|
|
*/
|
|
|
- public Map<String, String> insertGrade(Db db, String tableName, Map<String, String> schoolDistrictMap, Map<String, String> ids) throws Exception {
|
|
|
+ public Map<String, String> insertGrade(String tableName, Map<String, String> schoolDistrictMap, Map<String, String> ids) throws Exception {
|
|
|
String sql = "select * from " + tableName + " where delete_mark = 0 and status = 1";
|
|
|
- List<BaseGrade> list = db.query(sql, BaseGrade.class);
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, BaseGrade.class);
|
|
|
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
|
for (String gradeId : schoolDistrictMap.keySet()) {
|
|
|
- for (BaseGrade baseGrade : list) {
|
|
|
+ for (Map<String, Object> baseGradeMap : list) {
|
|
|
+ BaseGrade baseGrade = SqlRunnerAdapterUtil.convertMapToEntity(baseGradeMap, BaseGrade.class);
|
|
|
String url = ScheduleUtil.apiUrl + "eduyear/create";
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("schoolDistrictId", schoolDistrictMap.get(gradeId));
|
|
@@ -436,7 +443,7 @@ public class DataUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
- insertRecord(db, tableName, idMap);
|
|
|
+ insertRecord(tableName, idMap);
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
@@ -537,16 +544,15 @@ public class DataUtil {
|
|
|
|
|
|
|
|
|
*
|
|
|
- * @param db 数据库链接
|
|
|
* @param data 接口数据
|
|
|
* @param classroomMap 教室对应关系
|
|
|
* @param coureseMap 课程对应关系
|
|
|
* @param semesterMap 学期对应关系
|
|
|
* @param teacherMap 教师对应关系
|
|
|
*/
|
|
|
- public void insertCourseTable(Db db, JsonArray data, Map<String, String> classroomMap, Map<String, String> coureseMap,
|
|
|
- Map<String, String> semesterMap, Map<String, String> teacherMap, Map<String, String> classMap) throws SQLException {
|
|
|
- List<String> sqls = new ArrayList<>();
|
|
|
+ public void insertCourseTable(JsonArray data, Map<String, String> classroomMap, Map<String, String> coureseMap,
|
|
|
+ Map<String, String> semesterMap, Map<String, String> teacherMap, Map<String, String> classMap) {
|
|
|
+
|
|
|
|
|
|
Map<Integer, Integer> tmePeriod = ScheduleUtil.getTmePeriod();
|
|
|
int count = 1;
|
|
@@ -596,19 +602,18 @@ public class DataUtil {
|
|
|
+ "'" + asJsonObject.get("id").getAsString() + "' FROM DUAL"
|
|
|
+ " WHERE NOT EXISTS(SELECT * FROM course_table WHERE jianyue_id = '" + asJsonObject.get("id").getAsString() +"' and status = 1)";
|
|
|
|
|
|
- sqls.add(sql);
|
|
|
+
|
|
|
+ SqlRunnerAdapter.db().insert(sql);
|
|
|
count ++;
|
|
|
}
|
|
|
- db.executeBatch(sqls);
|
|
|
}
|
|
|
|
|
|
|
|
|
* 提取课时相关信息
|
|
|
- * @param db 数据库链接
|
|
|
* @param data 数据
|
|
|
*
|
|
|
*/
|
|
|
- public void insertClassTime(Db db, JsonArray data) throws SQLException {
|
|
|
+ public void insertClassTime(JsonArray data) {
|
|
|
|
|
|
Map<String, JsonObject> infoMap = new HashMap<>();
|
|
|
Map<Integer, Integer> tmePeriod = ScheduleUtil.getTmePeriod();
|
|
@@ -622,7 +627,7 @@ public class DataUtil {
|
|
|
json.add("numberOfDay", asJsonObject.get("numberOfDay"));
|
|
|
infoMap.put(numberOfDayName, json);
|
|
|
}
|
|
|
- List<String> sqls = new ArrayList<>();
|
|
|
+
|
|
|
int count = 1;
|
|
|
for (String number : infoMap.keySet()) {
|
|
|
String substring1 = number.substring(number.length() - 1);
|
|
@@ -642,29 +647,28 @@ public class DataUtil {
|
|
|
+ " WHERE NOT EXISTS(SELECT * FROM class_time WHERE time_period = "
|
|
|
+ jsonObject.get("tmePeriod").getAsInt()
|
|
|
+ " and number = " + substring1 + ")";
|
|
|
- sqls.add(sql);
|
|
|
+
|
|
|
+ SqlRunnerAdapter.db().insert(sql);
|
|
|
count ++;
|
|
|
}
|
|
|
- db.executeBatch(sqls);
|
|
|
}
|
|
|
|
|
|
|
|
|
* 插入记录表
|
|
|
- * @param db 数据库链接工具
|
|
|
* @param tableName 表名字
|
|
|
* @param idsMap id对应关系
|
|
|
*/
|
|
|
- public void insertRecord(Db db, String tableName, Map<String, String> idsMap) throws SQLException {
|
|
|
+ public void insertRecord(String tableName, Map<String, String> idsMap){
|
|
|
if(idsMap.isEmpty()){
|
|
|
return;
|
|
|
}
|
|
|
- List<String> sqls = new ArrayList<>();
|
|
|
+
|
|
|
for (String sourceId : idsMap.keySet()) {
|
|
|
String sql = "INSERT INTO jianyue_data(create_date,table_name,source_id,jianyue_id) value(now(),'"
|
|
|
+ tableName + "','" + sourceId + "','" + idsMap.get(sourceId) + "')";
|
|
|
- sqls.add(sql);
|
|
|
+
|
|
|
+ SqlRunnerAdapter.db().insert(sql);
|
|
|
}
|
|
|
- db.executeBatch(sqls);
|
|
|
}
|
|
|
|
|
|
}
|