|
|
@@ -0,0 +1,198 @@
|
|
|
+package com.xjrsoft.module.job;
|
|
|
+
|
|
|
+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.XjrSoftApplication;
|
|
|
+import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
+import com.xjrsoft.common.utils.DatasourceUtil;
|
|
|
+import com.xjrsoft.module.hikvision.util.ApiUtil;
|
|
|
+import com.xjrsoft.module.hikvision.util.DataUtil;
|
|
|
+import com.xjrsoft.module.organization.entity.Department;
|
|
|
+import com.xjrsoft.module.schedule.entity.JianyueData;
|
|
|
+import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import javax.sql.DataSource;
|
|
|
+
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author dzx
|
|
|
+ * @date 2024/5/14
|
|
|
+ */
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = XjrSoftApplication.class)
|
|
|
+class HikvisionBaseDataTaskTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ 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<JianyueData> list = use.query(sql, JianyueData.class);
|
|
|
+ Map<String, Map<Long, String>> dataMap = new HashMap<>();
|
|
|
+ for (String table : tables) {
|
|
|
+ Map<Long, String> tableData = new HashMap<>();
|
|
|
+ for (JianyueData jianyueData : list) {
|
|
|
+ if(!table.equals(jianyueData.getTableName())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ tableData.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
|
|
|
+ }
|
|
|
+ dataMap.put(table, tableData);
|
|
|
+ }
|
|
|
+ DataUtil dataUtil = new DataUtil();
|
|
|
+ String tableName = "xjr_department";
|
|
|
+ Map<Long, String> department = dataUtil.insertDepartment(use, tableName, null);
|
|
|
+ //System.out.println(department.toString());
|
|
|
+
|
|
|
+// selectOrg(use, tableName);
|
|
|
+// deleteOrg(use, tableName);
|
|
|
+
|
|
|
+// selecAllPersonById(use);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// selectResource(use);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询资源信息
|
|
|
+ * @param db
|
|
|
+ * @throws SQLException
|
|
|
+ */
|
|
|
+ void selectResource(Db db) throws SQLException {
|
|
|
+ String apiPath = "/api/irds/v2/resource/resourcesByParams";
|
|
|
+ JsonObject jsonObject = new JsonObject();
|
|
|
+ jsonObject.addProperty("pageNo", 1);
|
|
|
+ jsonObject.addProperty("pageSize", 500);
|
|
|
+ jsonObject.addProperty("resourceType", "door");
|
|
|
+
|
|
|
+
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ String result = apiUtil.doPost(apiPath, jsonObject.toString(), null, null);
|
|
|
+ System.out.println("------------------------------------------------------------------------");
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ };
|
|
|
+
|
|
|
+ void selecAllPersonById(Db db) throws SQLException {
|
|
|
+ String apiPath = "/api/resource/v2/person/advance/personList";
|
|
|
+ JsonObject jsonObject = new JsonObject();
|
|
|
+ jsonObject.addProperty("pageNo", 1);
|
|
|
+ jsonObject.addProperty("pageSize", 500);
|
|
|
+ jsonObject.addProperty("personIds", "b9d90bdd018447f2951dadfaffd1e411");
|
|
|
+
|
|
|
+
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ String result = apiUtil.doPost(apiPath, jsonObject.toString(), null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ void selecAllPerson(Db db) throws SQLException {
|
|
|
+ String apiPath = "/api/resource/v2/person/personList";
|
|
|
+ JsonObject jsonObject = new JsonObject();
|
|
|
+ jsonObject.addProperty("pageNo", 1);
|
|
|
+ jsonObject.addProperty("pageSize", 500);
|
|
|
+
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ String result = apiUtil.doPost(apiPath, jsonObject.toString(), null, null);
|
|
|
+
|
|
|
+ System.out.println(result);
|
|
|
+
|
|
|
+ String sql = "SELECT t1.* FROM xjr_user t1" +
|
|
|
+ " INNER JOIN base_teacher t2 ON t1.id = t2.user_id" +
|
|
|
+ " WHERE t1.delete_mark = 0 AND t2.delete_mark = 0";
|
|
|
+ List<XjrUser> dataList = db.query(sql, XjrUser.class);
|
|
|
+ Map<String, Long> phoneMap = new HashMap<>();
|
|
|
+ for (XjrUser xjrUser : dataList) {
|
|
|
+ phoneMap.put(xjrUser.getMobile(), xjrUser.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ JsonParser jsonParser = new JsonParser();
|
|
|
+ JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
|
|
|
+ JsonArray array = resultJson.get("data").getAsJsonObject().get("list").getAsJsonArray();
|
|
|
+ Map<Long, String> idMap = new HashMap<>();
|
|
|
+ for (JsonElement jsonElement : array) {
|
|
|
+ JsonObject element = jsonElement.getAsJsonObject();
|
|
|
+ if(!element.has("phoneNo") || element.get("phoneNo").isJsonNull()){
|
|
|
+ System.out.println(element.toString());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String phoneNo = element.get("phoneNo").getAsString();
|
|
|
+
|
|
|
+ idMap.put(phoneMap.get(phoneNo), element.get("personId").getAsString());
|
|
|
+ }
|
|
|
+
|
|
|
+ insertRecord(db, "base_teacher", idMap);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ void selectOrg(Db db, String tableName) throws SQLException {
|
|
|
+ String sql = "SELECT * FROM " + tableName + " WHERE delete_mark = 0";
|
|
|
+ List<Department> dataList = db.query(sql, Department.class);
|
|
|
+ String apiPath = "/api/resource/v1/org/orgList";
|
|
|
+ JsonObject jsonObject = new JsonObject();
|
|
|
+ jsonObject.addProperty("pageNo", 1);
|
|
|
+ jsonObject.addProperty("pageSize", 500);
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ String result = apiUtil.doPost(apiPath, jsonObject.toString(), null);
|
|
|
+ System.out.println("-----------------------------------------------------");
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void deleteOrg(Db db, String tableName) throws SQLException {
|
|
|
+ String 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/delete";
|
|
|
+ Map<Long, String> idMap = new HashMap<>();
|
|
|
+ JsonParser jsonParser = new JsonParser();
|
|
|
+ ApiUtil apiUtil = new ApiUtil();
|
|
|
+ JsonArray dataArray = new JsonArray();
|
|
|
+ for (Department department : dataList) {
|
|
|
+ dataArray.add(department.getId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ JsonObject paramJson = new JsonObject();
|
|
|
+ paramJson.add("indexCodes", dataArray);
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ headerMap.put("tagId", "deleteOrg");
|
|
|
+ String result = apiUtil.doPost(apiPath, paramJson.toString(), null, headerMap);
|
|
|
+ System.out.println(result);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|