|
@@ -1,7 +1,6 @@
|
|
|
package com.xjrsoft.module.hikvision.util;
|
|
package com.xjrsoft.module.hikvision.util;
|
|
|
|
|
|
|
|
import cn.hutool.db.Db;
|
|
import cn.hutool.db.Db;
|
|
|
-import cn.hutool.db.Entity;
|
|
|
|
|
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;
|
|
@@ -67,7 +66,7 @@ public class DataUtil {
|
|
|
JsonElement parse = jsonParser.parse(result);
|
|
JsonElement parse = jsonParser.parse(result);
|
|
|
|
|
|
|
|
JsonObject resultJson = parse.getAsJsonObject();
|
|
JsonObject resultJson = parse.getAsJsonObject();
|
|
|
- if(resultJson.get("code").getAsInt() == 0 && "success".equals(resultJson.get("msg").getAsString())){
|
|
|
|
|
|
|
+ if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
|
JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
|
|
JsonArray array = resultJson.get("data").getAsJsonObject().get("successes").getAsJsonArray();
|
|
|
for (JsonElement jsonElement : array) {
|
|
for (JsonElement jsonElement : array) {
|
|
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
@@ -82,6 +81,57 @@ public class DataUtil {
|
|
|
return idMap;
|
|
return idMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public Map<Long, String> insertTeacher(Db db, String tableName, Map<Long, String> tableData, Map<Long, 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" +
|
|
|
|
|
+ " INNER JOIN xjr_department t4 ON t3.dept_id = t4.id " +
|
|
|
|
|
+ " 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<>();
|
|
|
|
|
+ for(int i = 0; i < list.size(); i ++){
|
|
|
|
|
+ String[] el = list.get(i);
|
|
|
|
|
+ if(tableData != null && tableData.containsKey(Long.parseLong(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("phoneNo", el[5]);
|
|
|
|
|
+ paramJson.addProperty("jobNo", el[9]);
|
|
|
|
|
+ paramJson.addProperty("birthday", el[4]);
|
|
|
|
|
+ paramArray.add(paramJson);
|
|
|
|
|
+
|
|
|
|
|
+ clientMap.put(i, Long.parseLong(el[0]));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String apiPath = "/api/resource/v1/person/batch/add";
|
|
|
|
|
+ Map<Long, String> idMap = new HashMap<>();
|
|
|
|
|
+ JsonParser jsonParser = new JsonParser();
|
|
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
|
|
+ header.put("tagId", "insert_teacher");
|
|
|
|
|
+
|
|
|
|
|
+ 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());
|
|
|
|
|
+ }
|
|
|
|
|
+ }else{
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ //插入记录表
|
|
|
|
|
+ insertRecord(db, tableName, idMap);
|
|
|
|
|
+ return idMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void insertRecord(Db db, String tableName, Map<Long, String> idsMap) throws SQLException {
|
|
void insertRecord(Db db, String tableName, Map<Long, String> idsMap) throws SQLException {
|
|
|
if(idsMap.isEmpty()){
|
|
if(idsMap.isEmpty()){
|
|
|
return;
|
|
return;
|