|
@@ -69,7 +69,7 @@ public class DataUtil {
|
|
|
JsonElement parse = jsonParser.parse(result);
|
|
|
|
|
|
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();
|
|
|
for (JsonElement jsonElement : array) {
|
|
|
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
|
@@ -84,6 +84,57 @@ public class DataUtil {
|
|
|
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;
|
|
|
+ }
|
|
|
+
|
|
|
/*同步车辆数据*/
|
|
|
public Map<String, String> insertCar(Db db, String tableName, Map<Long, String> tableData) throws Exception {
|
|
|
String sql = "SELECT * FROM " + tableName + " WHERE delete_mark = 0 and status = 1";
|
|
@@ -161,4 +212,16 @@ public class DataUtil {
|
|
|
db.executeBatch(sqls);
|
|
|
}
|
|
|
|
|
|
+// void insertRecord(Db db, String tableName, Map<Long, String> idsMap) throws SQLException {
|
|
|
+// if(idsMap.isEmpty()){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// List<String> sqls = new ArrayList<>();
|
|
|
+// for (Long sourceId : idsMap.keySet()) {
|
|
|
+// String sql = "INSERT INTO hikvision_data(create_date,table_name,source_id,hikvision_id) value(now(),'"
|
|
|
+// + tableName + "'," + sourceId + ",'" + idsMap.get(sourceId) + "')";
|
|
|
+// sqls.add(sql);
|
|
|
+// }
|
|
|
+// db.executeBatch(sqls);
|
|
|
+// };
|
|
|
}
|