|
@@ -83,29 +83,29 @@ class HikvisionBaseDataTaskTest {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
void test() throws Exception {
|
|
void test() throws Exception {
|
|
-// DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
|
|
|
|
-// Db use = Db.use(datasource);
|
|
|
|
-// String sql = "SELECT distinct table_name FROM hikvision_data WHERE 1 = 1";
|
|
|
|
-// List<JianyueData> query = use.query(sql, JianyueData.class);
|
|
|
|
-// Set<String> tables = new HashSet<>();
|
|
|
|
-// for (JianyueData jianyueData : query) {
|
|
|
|
-// tables.add(jianyueData.getTableName());
|
|
|
|
-// }
|
|
|
|
-// sql = "SELECT * FROM hikvision_data WHERE 0 = 0";
|
|
|
|
-// List<HikvisionData> list = use.query(sql, HikvisionData.class);
|
|
|
|
-// Map<String, Map<String, String>> dataMap = new HashMap<>();
|
|
|
|
-// for (String table : tables) {
|
|
|
|
-// Map<String, String> tableData = new HashMap<>();
|
|
|
|
-// for (HikvisionData hikvisiondata : list) {
|
|
|
|
-// if(!table.equals(hikvisiondata.getTableName())){
|
|
|
|
-// continue;
|
|
|
|
-// }
|
|
|
|
-// tableData.put(hikvisiondata.getSourceId(), hikvisiondata.getHikvisionId());
|
|
|
|
-// }
|
|
|
|
-// dataMap.put(table, tableData);
|
|
|
|
-// }
|
|
|
|
|
|
+ String sql = "SELECT distinct table_name FROM hikvision_data WHERE 1 = 1";
|
|
|
|
+ List<Map<String, Object>> maps = SqlRunnerAdapter.db().selectList(sql, HikvisionData.class);
|
|
|
|
+ Set<String> tables = new HashSet<>();
|
|
|
|
+ for (Map<String, Object> map : maps) {
|
|
|
|
+ String[] strings = SqlRunnerAdapterUtil.convertMapToStringArray(map);
|
|
|
|
+ tables.add(strings[0]);
|
|
|
|
+ }
|
|
|
|
+ sql = "SELECT * FROM hikvision_data WHERE 0 = 0";
|
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, HikvisionData.class);
|
|
|
|
+ Map<String, Map<String, String>> dataMap = new HashMap<>();
|
|
|
|
+ for (String table : tables) {
|
|
|
|
+ Map<String, String> tableData = new HashMap<>();
|
|
|
|
+ for (Map<String, Object> hikvision : list) {
|
|
|
|
+
|
|
|
|
+ if(!table.equals(hikvision.get("table_name").toString())){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ tableData.put(hikvision.get("source_id").toString(), hikvision.get("hikvision_id").toString());
|
|
|
|
+ }
|
|
|
|
+ dataMap.put(table, tableData);
|
|
|
|
+ }
|
|
// DataUtil dataUtil = new DataUtil();
|
|
// DataUtil dataUtil = new DataUtil();
|
|
-// String tableName = "xjr_department";
|
|
|
|
|
|
+ String tableName = "xjr_department";
|
|
// Map<String, String> department = dataUtil.insertDepartment(use, tableName, dataMap.get(tableName));
|
|
// Map<String, String> department = dataUtil.insertDepartment(use, tableName, dataMap.get(tableName));
|
|
// if(department.isEmpty() && dataMap.get(tableName) != null){
|
|
// if(department.isEmpty() && dataMap.get(tableName) != null){
|
|
// department = dataMap.get(tableName);
|
|
// department = dataMap.get(tableName);
|
|
@@ -127,9 +127,9 @@ class HikvisionBaseDataTaskTest {
|
|
// Map<String, String> classes = dataUtil.insertClass(use, tableName, baseClass);
|
|
// Map<String, String> classes = dataUtil.insertClass(use, tableName, baseClass);
|
|
|
|
|
|
|
|
|
|
-// tableName = "base_student";
|
|
|
|
-// Map<String, String> baseStudent = dataMap.get(tableName);
|
|
|
|
-// Map<String, String> student = dataUtil.insertStudentOne(use, tableName, baseStudent);
|
|
|
|
|
|
+ tableName = "base_student";
|
|
|
|
+ Map<String, String> baseStudent = dataMap.get(tableName);
|
|
|
|
+ Map<String, String> student = insertStudentOne(tableName, baseStudent);
|
|
|
|
|
|
// selectOrg(use, "base_class");
|
|
// selectOrg(use, "base_class");
|
|
|
|
|
|
@@ -170,43 +170,40 @@ class HikvisionBaseDataTaskTest {
|
|
db.executeBatch(sqls);
|
|
db.executeBatch(sqls);
|
|
}
|
|
}
|
|
|
|
|
|
- public Map<String, String> insertStudentOne(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,DATE_FORMAT(t1.birth_date, '%Y-%m-%d'),t1.mobile,t1.email,t1.credential_type,t1.credential_number FROM xjr_user t1" +
|
|
|
|
|
|
+ public Map<String, String> insertStudentOne(String tableName, Map<String, String> tableData) throws Exception {
|
|
|
|
+ String sql = "SELECT t1.id,t1.name,CONCAT(t3.id,'-',replace(t4.name,'级',''),'-',t3.class_type,'-',t2.stduy_status) as orgIndexCode," +
|
|
|
|
+ " t1.user_name,t1.gender,DATE_FORMAT(t1.birth_date, '%Y-%m-%d') as birthday,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_student_school_roll t2 ON t1.id = t2.user_id" +
|
|
" INNER JOIN base_class t3 ON t2.class_id = t3.id" +
|
|
" INNER JOIN base_class t3 ON t2.class_id = t3.id" +
|
|
" INNER JOIN base_grade t4 ON t3.grade_id = t4.id" +
|
|
" INNER JOIN base_grade t4 ON t3.grade_id = t4.id" +
|
|
" WHERE t1.delete_mark = 0 AND t2.delete_mark = 0" +
|
|
" WHERE t1.delete_mark = 0 AND t2.delete_mark = 0" +
|
|
- " AND t3.class_type IS NOT NULL" +
|
|
|
|
- " AND t1.id NOT IN (SELECT source_id FROM hikvision_data WHERE table_name = 'base_student'\n" +
|
|
|
|
- ") AND t4.name NOT IN ('2021级','2020级')";
|
|
|
|
- List<String[]> list = db.query(sql, String[].class);
|
|
|
|
|
|
+ " AND t3.class_type IS NOT NULL";
|
|
|
|
+ //" AND t1.name IN ('宋成男','白江龙','李松阳')";
|
|
|
|
+ List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, String[].class);
|
|
Map<Integer, String> clientMap = new HashMap<>();
|
|
Map<Integer, String> clientMap = new HashMap<>();
|
|
|
|
|
|
- String apiPath = "/api/resource/v2/person/single/add";
|
|
|
|
Map<String, String> idMap = new HashMap<>();
|
|
Map<String, String> idMap = new HashMap<>();
|
|
JsonParser jsonParser = new JsonParser();
|
|
JsonParser jsonParser = new JsonParser();
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
ApiUtil apiUtil = new ApiUtil();
|
|
Map<String, String> header = new HashMap<>();
|
|
Map<String, String> header = new HashMap<>();
|
|
header.put("tagId", "insert_student");
|
|
header.put("tagId", "insert_student");
|
|
|
|
|
|
- for(int i = 0; i < list.size(); i ++){
|
|
|
|
- String[] el = list.get(i);
|
|
|
|
- if(tableData != null && tableData.containsKey(el[0])){
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
+ for(int i = 1; i < list.size(); i ++){
|
|
|
|
+ Map<String, Object> objectMap = list.get(i);
|
|
|
|
+ String apiPath = "/api/resource/v2/person/single/add";
|
|
|
|
+
|
|
JsonObject paramJson = new JsonObject();
|
|
JsonObject paramJson = new JsonObject();
|
|
paramJson.addProperty("clientId", i);
|
|
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("personId", objectMap.get("id").toString());
|
|
|
|
+ paramJson.addProperty("personName", objectMap.get("name").toString());
|
|
|
|
+ paramJson.addProperty("orgIndexCode", objectMap.get("orgIndexCode").toString());
|
|
|
|
+ paramJson.addProperty("phoneNo", objectMap.get("mobile")==null?"":objectMap.get("mobile").toString());
|
|
|
|
+ paramJson.addProperty("jobNo", objectMap.get("user_name").toString());
|
|
|
|
+ paramJson.addProperty("birthday", objectMap.get("birthday")==null?"":objectMap.get("birthday").toString());
|
|
paramJson.addProperty("personType", 2);
|
|
paramJson.addProperty("personType", 2);
|
|
|
|
|
|
int gender;
|
|
int gender;
|
|
- switch (el[4]) {
|
|
|
|
|
|
+ switch (objectMap.get("gender").toString()) {
|
|
case "SB10001":
|
|
case "SB10001":
|
|
gender = 1;
|
|
gender = 1;
|
|
break;
|
|
break;
|
|
@@ -219,18 +216,21 @@ class HikvisionBaseDataTaskTest {
|
|
}
|
|
}
|
|
paramJson.addProperty("gender", gender);
|
|
paramJson.addProperty("gender", gender);
|
|
|
|
|
|
- clientMap.put(i, el[0]);
|
|
|
|
- System.out.println("请求参数:" + paramJson.toString());
|
|
|
|
|
|
+ if(tableData != null && tableData.containsKey(objectMap.get("id").toString())){
|
|
|
|
+ apiPath = "/api/resource/v1/person/single/update";
|
|
|
|
+ apiUtil.doPost(apiPath, paramJson.toString(), null, header);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ clientMap.put(i, objectMap.get("id").toString());
|
|
String result = apiUtil.doPost(apiPath, paramJson.toString(), null, header);
|
|
String result = apiUtil.doPost(apiPath, paramJson.toString(), null, header);
|
|
- System.out.println("返回结果:" + result);
|
|
|
|
JsonElement parse = jsonParser.parse(result);
|
|
JsonElement parse = jsonParser.parse(result);
|
|
JsonObject resultJson = parse.getAsJsonObject();
|
|
JsonObject resultJson = parse.getAsJsonObject();
|
|
if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
if("0".equals(resultJson.get("code").getAsString()) && "success".equals(resultJson.get("msg").getAsString())){
|
|
JsonObject array = resultJson.get("data").getAsJsonObject();
|
|
JsonObject array = resultJson.get("data").getAsJsonObject();
|
|
- idMap.put(el[0], array.get("personId").getAsString());
|
|
|
|
|
|
+ idMap.put(objectMap.get("id").toString(), array.get("personId").getAsString());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- insertRecord(db, tableName, idMap);
|
|
|
|
//插入记录表
|
|
//插入记录表
|
|
return idMap;
|
|
return idMap;
|
|
}
|
|
}
|