|
|
@@ -0,0 +1,123 @@
|
|
|
+package com.xjrsoft.module.job;
|
|
|
+
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.xjrsoft.XjrSoftApplication;
|
|
|
+import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
+import com.xjrsoft.common.utils.SqlRunnerAdapterUtil;
|
|
|
+import com.xjrsoft.module.hikvision.entity.HikvisionData;
|
|
|
+import com.xjrsoft.module.hikvision.mapper.HikvisionDataMapper;
|
|
|
+import com.xjrsoft.module.hikvision.util.DataUtil;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+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 2025/5/7
|
|
|
+ */
|
|
|
+
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = XjrSoftApplication.class)
|
|
|
+class HikvisionBaseDataTaskTest2 {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HikvisionDataMapper hikvisionDataMapper;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void execute() {
|
|
|
+ RefreshConnectionPool();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RefreshConnectionPool() {
|
|
|
+ String active = SpringUtil.getActiveProfile();
|
|
|
+ if (!"prod".equals(active)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String sql = "SELECT distinct table_name FROM hikvision_data WHERE 1 = 1";
|
|
|
+ List<Map<String, Object>> maps = SqlRunnerAdapter.db().selectList(sql);
|
|
|
+ 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);
|
|
|
+ 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();
|
|
|
+ //查询根机构
|
|
|
+ //JsonArray schoolDistrictData = dataUtil.getSchoolDistrictData();
|
|
|
+ //推送组织机构
|
|
|
+ String tableName = "xjr_department";
|
|
|
+// Map<String, String> department = new HashMap<>();
|
|
|
+// try {
|
|
|
+// department = dataUtil.insertDepartment(tableName, dataMap.get(tableName));
|
|
|
+// } catch (Exception e) {
|
|
|
+// System.out.println(e);
|
|
|
+// }
|
|
|
+// if (department.isEmpty() && dataMap.get(tableName) != null) {
|
|
|
+// department = dataMap.get(tableName);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// //推送教职工
|
|
|
+// tableName = "base_teacher";
|
|
|
+// try {
|
|
|
+// dataUtil.insertTeacher(tableName, dataMap.get(tableName), department);
|
|
|
+// } catch (Exception e) {
|
|
|
+// System.out.println(e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //推送车辆
|
|
|
+// String carTableName = "car_message_apply";
|
|
|
+// Map<String, String> baseCar = dataMap.get(carTableName);
|
|
|
+// try {
|
|
|
+// dataUtil.insertCar(carTableName, baseCar, hikvisionDataMapper);
|
|
|
+// } catch (Exception e) {
|
|
|
+// System.out.println(e);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ tableName = "base_class";
|
|
|
+ Map<String, String> baseClass = dataMap.get(tableName);
|
|
|
+ try {
|
|
|
+ dataUtil.insertClass(tableName, baseClass);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println(e);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tableName = "base_student";
|
|
|
+ List<HikvisionData> studentList = hikvisionDataMapper.selectList(
|
|
|
+ new QueryWrapper<HikvisionData>().lambda().eq(HikvisionData::getTableName, tableName)
|
|
|
+ );
|
|
|
+ Map<String, String> baseStudent = dataMap.get(tableName);
|
|
|
+ dataUtil.insertStudentOne(tableName, baseStudent, studentList);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|