|
@@ -5,11 +5,15 @@ import com.google.gson.JsonArray;
|
|
|
import com.google.gson.JsonElement;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.google.gson.JsonParser;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.base.entity.BaseGrade;
|
|
|
import com.xjrsoft.module.organization.entity.Department;
|
|
|
import com.xjrsoft.module.personnel.entity.CarMessageApply;
|
|
|
+import com.xjrsoft.module.system.entity.DictionaryDetail;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import lombok.var;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -29,7 +33,7 @@ public class DataUtil {
|
|
|
* 同步组织数据
|
|
|
* 只有批量添加接口,需要一个层级一个层级的添加
|
|
|
*/
|
|
|
- public Map<Long, String> insertDepartment(Db db, String tableName, Map<Long, String> tableData) throws Exception {
|
|
|
+ public Map<String, String> insertDepartment(Db db, String tableName, Map<String, String> tableData) throws Exception {
|
|
|
String sql = "SELECT DISTINCT LENGTH(hierarchy) FROM " + tableName + " WHERE delete_mark = 0";
|
|
|
List<Integer[]> list = db.query(sql, Integer[].class);
|
|
|
Set<Integer> levelSet = new HashSet<>();
|
|
@@ -40,15 +44,15 @@ public class DataUtil {
|
|
|
sql = "SELECT * FROM " + tableName + " WHERE delete_mark = 0 ORDER BY LENGTH(hierarchy)";
|
|
|
List<Department> dataList = db.query(sql, Department.class);
|
|
|
String apiPath = "/api/resource/v1/org/batch/add";
|
|
|
- Map<Long, String> idMap = new HashMap<>();
|
|
|
+ Map<String, String> idMap = new HashMap<>();
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
|
|
|
|
- Map<String, Long> idCodeMap = new HashMap<>();
|
|
|
+ Map<String, String> idCodeMap = new HashMap<>();
|
|
|
for (Integer level : levelSet) {
|
|
|
JsonArray dataArray = new JsonArray();
|
|
|
for (Department department : dataList) {
|
|
|
- if(tableData.containsKey(department.getId())){
|
|
|
+ if(tableData.containsKey(department.getId().toString())){
|
|
|
continue;
|
|
|
}
|
|
|
if(department.getHierarchy().length() == level){
|
|
@@ -62,7 +66,7 @@ public class DataUtil {
|
|
|
}
|
|
|
paramJson.addProperty("orgCode", department.getCode());
|
|
|
dataArray.add(paramJson);
|
|
|
- idCodeMap.put(department.getCode(), department.getId());
|
|
|
+ idCodeMap.put(department.getCode(), department.getId().toString());
|
|
|
}
|
|
|
}
|
|
|
String result = apiUtil.doPost(apiPath, dataArray.toString(), null, null);
|
|
@@ -75,16 +79,254 @@ public class DataUtil {
|
|
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
idMap.put(idCodeMap.get(jsonObject.get("clientId").getAsString()), jsonObject.get("orgIndexCode").getAsString());
|
|
|
}
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //插入记录表
|
|
|
+ insertRecord(db, tableName, idMap);
|
|
|
+ return idMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送学生班级信息
|
|
|
+ */
|
|
|
+ public Map<String, String> insertClass(Db db, String tableName, Map<String, String> tableData) throws SQLException {
|
|
|
+ Map<String, String> idMap = new HashMap<>();
|
|
|
+ //1、查询字典,将走读住读、班级类型先推送过去
|
|
|
+ String sql = "SELECT * FROM xjr_dictionary_detail WHERE delete_mark = 0 AND item_id = 2023000000000000030";
|
|
|
+ List<DictionaryDetail> detailList = db.query(sql, DictionaryDetail.class);
|
|
|
+
|
|
|
+ String apiPath = "/api/resource/v1/org/batch/add";
|
|
|
+ JsonParser jsonParser = new JsonParser();
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ int clientId = 1;
|
|
|
+ Map<Integer, String> idCodeMap = new HashMap<>();
|
|
|
+ JsonArray dataArray = new JsonArray();
|
|
|
+
|
|
|
+ Set<String> stduyStatus = new HashSet<>();
|
|
|
+
|
|
|
+ for (DictionaryDetail dict : detailList) {
|
|
|
+ if(tableData != null && tableData.containsKey(dict.getId().toString())){
|
|
|
+ stduyStatus.add(dict.getId().toString());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.addProperty("clientId", clientId);
|
|
|
+ paramJson.addProperty("orgIndexCode", dict.getCode());
|
|
|
+ paramJson.addProperty("orgName", dict.getName() + "学生");
|
|
|
+ paramJson.addProperty("parentIndexCode", "root000000");
|
|
|
+ paramJson.addProperty("orgCode", dict.getCode());
|
|
|
+ dataArray.add(paramJson);
|
|
|
+ idCodeMap.put(clientId, dict.getCode());
|
|
|
+ clientId ++;
|
|
|
+ }
|
|
|
+ String result = apiUtil.doPost(apiPath, dataArray.toString(), null, null);
|
|
|
+ JsonElement parse = jsonParser.parse(result);
|
|
|
+
|
|
|
+ JsonObject resultJson = parse.getAsJsonObject();
|
|
|
+ if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
|
+ JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
|
|
|
+ for (JsonElement jsonElement : array) {
|
|
|
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
+ idMap.put(idCodeMap.get(jsonObject.get("clientId").getAsInt()), jsonObject.get("orgIndexCode").getAsString());
|
|
|
+ stduyStatus.add(jsonObject.get("orgIndexCode").getAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //推送班级类型
|
|
|
+ sql = "SELECT * FROM xjr_dictionary_detail WHERE delete_mark = 0 AND item_id = 2023000000000000039";
|
|
|
+ detailList = db.query(sql, DictionaryDetail.class);
|
|
|
+ dataArray = new JsonArray();
|
|
|
+ Set<String> classTypeSet = new HashSet<>();
|
|
|
+ for (String status : stduyStatus) {
|
|
|
+ for (DictionaryDetail dict : detailList) {
|
|
|
+ if(tableData != null && tableData.containsKey(dict.getCode())){
|
|
|
+ classTypeSet.add(dict.getCode());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.addProperty("clientId", clientId);
|
|
|
+ paramJson.addProperty("orgIndexCode", dict.getCode() + "-" + status);
|
|
|
+ paramJson.addProperty("orgName", dict.getName());
|
|
|
+ paramJson.addProperty("parentIndexCode", status);
|
|
|
+ paramJson.addProperty("orgCode", dict.getCode());
|
|
|
+ dataArray.add(paramJson);
|
|
|
+ idCodeMap.put(clientId, dict.getCode());
|
|
|
+ clientId ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result = apiUtil.doPost(apiPath, dataArray.toString(), null, null);
|
|
|
+ parse = jsonParser.parse(result);
|
|
|
+ resultJson = parse.getAsJsonObject();
|
|
|
+ if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
|
+ JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
|
|
|
+ for (JsonElement jsonElement : array) {
|
|
|
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
+ idMap.put(idCodeMap.get(jsonObject.get("clientId").getAsInt()), jsonObject.get("orgIndexCode").getAsString());
|
|
|
+ classTypeSet.add(jsonObject.get("orgIndexCode").getAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //推送年级
|
|
|
+ sql = "SELECT * FROM base_grade WHERE delete_mark = 0 AND STATUS = 1";
|
|
|
+ List<BaseGrade> gradeList = db.query(sql, BaseGrade.class);
|
|
|
+ Map<Long, String> gradeNameMap = new HashMap<>();
|
|
|
+ dataArray = new JsonArray();
|
|
|
+ for (String classType : classTypeSet) {
|
|
|
+ for (BaseGrade baseGrade : gradeList) {
|
|
|
+ gradeNameMap.put(baseGrade.getId(), baseGrade.getName());
|
|
|
+ if(tableData != null && tableData.containsKey(baseGrade.getId().toString())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.addProperty("clientId", clientId);
|
|
|
+ paramJson.addProperty("orgIndexCode", baseGrade.getName() + "-" + classType);
|
|
|
+ paramJson.addProperty("orgName", baseGrade.getName());
|
|
|
+ paramJson.addProperty("parentIndexCode", classType);
|
|
|
+ paramJson.addProperty("orgCode", clientId);
|
|
|
+ dataArray.add(paramJson);
|
|
|
+ idCodeMap.put(clientId, baseGrade.getName());
|
|
|
+ clientId ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result = apiUtil.doPost(apiPath, dataArray.toString(), null, null);
|
|
|
+ parse = jsonParser.parse(result);
|
|
|
+ Set<String> gradeSet = new HashSet<>();
|
|
|
+ resultJson = parse.getAsJsonObject();
|
|
|
+ if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
|
+ JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
|
|
|
+ for (JsonElement jsonElement : array) {
|
|
|
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
+ idMap.put(idCodeMap.get(jsonObject.get("clientId").getAsInt()), jsonObject.get("orgIndexCode").getAsString());
|
|
|
+ gradeSet.add(jsonObject.get("orgIndexCode").getAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //推送班级
|
|
|
+ sql = "SELECT * FROM base_class WHERE delete_mark = 0 AND is_graduate = 1 AND class_type IS NOT NULL";
|
|
|
+ List<BaseClass> classList = db.query(sql, BaseClass.class);
|
|
|
+
|
|
|
+ dataArray = new JsonArray();
|
|
|
+ for (String grade : gradeSet) {
|
|
|
+ String[] gradeGroup = grade.split("-");
|
|
|
+ for (BaseClass baseClass : classList) {
|
|
|
+ if(tableData != null && tableData.containsKey(baseClass.getId().toString())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String gradeName = gradeNameMap.get(baseClass.getGradeId());
|
|
|
+ if(!gradeGroup[0].equals(gradeName)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
+ if(!gradeGroup[1].equals(baseClass.getClassType())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.addProperty("clientId", clientId);
|
|
|
+ paramJson.addProperty("orgIndexCode", baseClass.getId() + "-" + grade);
|
|
|
+ paramJson.addProperty("orgName", baseClass.getName());
|
|
|
+ paramJson.addProperty("parentIndexCode", grade);
|
|
|
+ paramJson.addProperty("orgCode", clientId);
|
|
|
+ dataArray.add(paramJson);
|
|
|
+ idCodeMap.put(clientId, baseClass.getId().toString());
|
|
|
+ clientId ++;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ result = apiUtil.doPost(apiPath, dataArray.toString(), null, null);
|
|
|
+ parse = jsonParser.parse(result);
|
|
|
+ resultJson = parse.getAsJsonObject();
|
|
|
+ if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
|
+ JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
|
|
|
+ for (JsonElement jsonElement : array) {
|
|
|
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
+ idMap.put(idCodeMap.get(jsonObject.get("clientId").getAsInt()), jsonObject.get("orgIndexCode").getAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//插入记录表
|
|
|
insertRecord(db, tableName, idMap);
|
|
|
+
|
|
|
return idMap;
|
|
|
}
|
|
|
|
|
|
- public Map<Long, String> insertTeacher(Db db, String tableName, Map<Long, String> tableData, Map<Long, String> deptMap) throws Exception {
|
|
|
+ public Map<String, String> insertStudent(Db db, String tableName, Map<String, String> tableData) throws Exception {
|
|
|
+ String sql = "SELECT t1.id,t1.name,CONCAT(t3.id,'-',t4.name,'-',t3.class_type,'-',t2.stduy_status)," +
|
|
|
+ " t1.user_name,t1.gender,t1.birth_date,t1.mobile,t1.email,t1.credential_type,t1.credential_number FROM xjr_user t1" +
|
|
|
+ " INNER JOIN base_student_school_roll t2 ON t1.id = t2.user_id" +
|
|
|
+ " INNER JOIN base_class t3 ON t2.class_id = t3.id" +
|
|
|
+ " INNER JOIN base_grade t4 ON t2.grade_id = t4.id" +
|
|
|
+ " WHERE t1.delete_mark = 0 AND t2.delete_mark = 0";
|
|
|
+ List<String[]> list = db.query(sql, String[].class);
|
|
|
+ Map<Integer, String> clientMap = new HashMap<>();
|
|
|
+
|
|
|
+ String apiPath = "/api/resource/v1/person/batch/add";
|
|
|
+ Map<String, String> idMap = new HashMap<>();
|
|
|
+ JsonParser jsonParser = new JsonParser();
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("tagId", "insert_student");
|
|
|
+
|
|
|
+ int maxCount = 1000;
|
|
|
+
|
|
|
+ int frequency = list.size() / maxCount;
|
|
|
+ for(int index = 0; index < frequency; index ++){
|
|
|
+ JsonArray paramArray = new JsonArray();
|
|
|
+
|
|
|
+ for(int i = (index * maxCount); i < ((index + 1) * maxCount); i ++){
|
|
|
+ if(i >= list.size()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] el = list.get(i);
|
|
|
+ if(tableData != null && tableData.containsKey(el[0])){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.addProperty("clientId", i);
|
|
|
+ paramJson.addProperty("personId", el[0]);
|
|
|
+ paramJson.addProperty("personName", el[1]);
|
|
|
+ paramJson.addProperty("orgIndexCode", el[2]);
|
|
|
+ paramJson.addProperty("phoneNo", el[6]);
|
|
|
+ paramJson.addProperty("jobNo", el[3]);
|
|
|
+ paramJson.addProperty("birthday", el[5]);
|
|
|
+ paramJson.addProperty("personType", 2);
|
|
|
+
|
|
|
+ int gender;
|
|
|
+ switch (el[4]) {
|
|
|
+ case "SB10001":
|
|
|
+ gender = 1;
|
|
|
+ break;
|
|
|
+ case "SB10002":
|
|
|
+ gender = 2;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ gender = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ paramJson.addProperty("gender", gender);
|
|
|
+ paramArray.add(paramJson);
|
|
|
+
|
|
|
+ clientMap.put(i, el[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ String result = apiUtil.doPost(apiPath, paramArray.toString(), null, header);
|
|
|
+ JsonElement parse = jsonParser.parse(result);
|
|
|
+ JsonObject resultJson = parse.getAsJsonObject();
|
|
|
+ if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
|
+ JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
|
|
|
+ for (JsonElement jsonElement : array) {
|
|
|
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
|
+ idMap.put(clientMap.get(jsonObject.get("clientId").getAsInt()), jsonObject.get("personId").getAsString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入记录表
|
|
|
+ insertRecord(db, tableName, idMap);
|
|
|
+ return idMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<String, String> insertTeacher(Db db, String tableName, Map<String, String> tableData, Map<String, String> deptMap) throws Exception {
|
|
|
String sql = "SELECT t1.id,t1.name,t1.gender,t3.dept_id,t1.birth_date,t1.mobile,t1.email,t1.credential_type,t1.credential_number,t1.user_name FROM xjr_user t1" +
|
|
|
" INNER JOIN " + tableName + " t2 ON t1.id = t2.user_id" +
|
|
|
" INNER JOIN xjr_user_dept_relation t3 ON t1.id = t3.user_id" +
|
|
@@ -92,27 +334,42 @@ public class DataUtil {
|
|
|
" WHERE t1.delete_mark = 0 AND t2.delete_mark = 0 AND t4.delete_mark = 0";
|
|
|
List<String[]> list = db.query(sql, String[].class);
|
|
|
JsonArray paramArray = new JsonArray();
|
|
|
- Map<Integer, Long> clientMap = new HashMap<>();
|
|
|
+ Map<Integer, String> clientMap = new HashMap<>();
|
|
|
for(int i = 0; i < list.size(); i ++){
|
|
|
String[] el = list.get(i);
|
|
|
- if(tableData != null && tableData.containsKey(Long.parseLong(el[0]))){
|
|
|
+ if(tableData != null && tableData.containsKey(el[0])){
|
|
|
continue;
|
|
|
}
|
|
|
JsonObject paramJson = new JsonObject();
|
|
|
paramJson.addProperty("clientId", i);
|
|
|
paramJson.addProperty("personId", el[0]);
|
|
|
paramJson.addProperty("personName", el[1]);
|
|
|
- paramJson.addProperty("orgIndexCode", deptMap.get(Long.parseLong(el[3])));
|
|
|
+ paramJson.addProperty("orgIndexCode", deptMap.get(el[3]));
|
|
|
paramJson.addProperty("phoneNo", el[5]);
|
|
|
paramJson.addProperty("jobNo", el[9]);
|
|
|
paramJson.addProperty("birthday", el[4]);
|
|
|
+ paramJson.addProperty("personType", 1);
|
|
|
+
|
|
|
+ int gender;
|
|
|
+ switch (el[2]) {
|
|
|
+ case "SB10001":
|
|
|
+ gender = 1;
|
|
|
+ break;
|
|
|
+ case "SB10002":
|
|
|
+ gender = 2;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ gender = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ paramJson.addProperty("gender", gender);
|
|
|
paramArray.add(paramJson);
|
|
|
|
|
|
- clientMap.put(i, Long.parseLong(el[0]));
|
|
|
+ clientMap.put(i, el[0]);
|
|
|
}
|
|
|
|
|
|
String apiPath = "/api/resource/v1/person/batch/add";
|
|
|
- Map<Long, String> idMap = new HashMap<>();
|
|
|
+ Map<String, String> idMap = new HashMap<>();
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
|
Map<String, String> header = new HashMap<>();
|
|
@@ -206,7 +463,7 @@ public class DataUtil {
|
|
|
for (var entry : idsMap.entrySet()) {
|
|
|
var sourceId = entry.getKey();
|
|
|
var sql = "INSERT INTO hikvision_data(create_date, table_name, source_id, hikvision_id) " +
|
|
|
- "VALUES(now(), '" + tableName + "', " + sourceId + ", '" + entry.getValue() + "')";
|
|
|
+ "VALUES(now(), '" + tableName + "', '" + sourceId + "', '" + entry.getValue() + "')";
|
|
|
sqls.add(sql);
|
|
|
}
|
|
|
db.executeBatch(sqls);
|