|
@@ -15,9 +15,13 @@ import org.json.simple.JSONObject;
|
|
|
import org.json.simple.parser.JSONParser;
|
|
|
|
|
|
import java.io.FileWriter;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
/**
|
|
|
* 地址查询请求工具类
|
|
@@ -44,30 +48,6 @@ public class RequestUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- com.alibaba.fastjson.JSONObject AllData = new com.alibaba.fastjson.JSONObject();
|
|
|
- JSONArray featuresList = new JSONArray();
|
|
|
- for (int i = 1; i <= 7282; i++) {
|
|
|
- if (i == 7282) {
|
|
|
- String requestData = requestWFS(i + "");
|
|
|
- com.alibaba.fastjson.JSONObject requestJson = com.alibaba.fastjson.JSONObject.parseObject(requestData);
|
|
|
- if (requestJson.containsKey("features")) {
|
|
|
- featuresList.add(requestJson.getJSONArray("features").getJSONObject(0));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- AllData.put("features", featuresList);
|
|
|
- AllData.put("type", "FeatureCollection");
|
|
|
- System.out.println("内容大小:" + featuresList.size());
|
|
|
- String jsonString = AllData.toJSONString();
|
|
|
- String filePath = "output/cj_1.geojson";
|
|
|
- try (FileWriter fileWriter = new FileWriter(filePath)) {
|
|
|
- fileWriter.write(jsonString);
|
|
|
- System.out.println("完成!");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
public static String requestWFS(String index) {
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
@@ -177,4 +157,147 @@ public class RequestUtils {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static String getPreviousDateStr(int day) {
|
|
|
+// 获取当前日期
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+// 获取前一天的日期
|
|
|
+ LocalDate previousDate = currentDate.minusDays(day);
|
|
|
+// 定义日期格式
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
|
|
+// 返回前一天的日期字符串
|
|
|
+ return previousDate.format(formatter);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 先得到headers
|
|
|
+ * 然后初始化outData
|
|
|
+ * 得到问题类型列表
|
|
|
+ * 写随机日期(+【0-2】)和随机类型(errorTypes【errorTypes.size】)和异常数量((1-20)*(1-20))
|
|
|
+ * 日期[1月2号-5月10号]
|
|
|
+ */
|
|
|
+ public static void testFile() {
|
|
|
+ int daysum = 148;
|
|
|
+ Map<String,Integer> errorR = new HashMap<>();
|
|
|
+ List<String> tableNameList = new ArrayList<>();
|
|
|
+ List<String> errorTypes = new ArrayList<>();
|
|
|
+// 表名,《关键字段【数据库信息,表中文注释】,值》
|
|
|
+ Map<String, Map<String, String>> headers = new HashMap<>();
|
|
|
+// 表名,问题类型,数量
|
|
|
+ Map<String, Map<String, Integer>> outData = new HashMap<>();
|
|
|
+ try {
|
|
|
+ List<Map<String, Object>> fileDatas = ExcelReaderUtils.readExcel("C:\\Users\\Liumouren\\Desktop\\异常数据清单 列表.xlsx");
|
|
|
+ for (Map<String, Object> fileDataItem : fileDatas) {
|
|
|
+ if (fileDataItem.get("源数据库信息") != null && !fileDataItem.get("源数据库信息").toString().isEmpty()) {
|
|
|
+ String dataBaseInfo = fileDataItem.get("源数据库信息").toString();
|
|
|
+ String tableInfo = fileDataItem.get("表中文注释").toString();
|
|
|
+ String tableName = fileDataItem.get("表名").toString();
|
|
|
+ String errorType = fileDataItem.get("判断异常原因").toString();
|
|
|
+ Integer errorNum = Integer.parseInt(fileDataItem.get("异常数据量").toString().replaceAll(".0", ""));
|
|
|
+ tableNameList.add(tableName);
|
|
|
+ errorTypes.add(errorType);
|
|
|
+ errorR.put(errorType,errorNum);
|
|
|
+ Map<String, String> header = new HashMap<>();
|
|
|
+ header.put("源数据库信息", dataBaseInfo);
|
|
|
+ header.put("表中文注释", tableInfo);
|
|
|
+ headers.put(tableName, header);
|
|
|
+ if (outData.containsKey(tableName)) {
|
|
|
+ Map<String, Integer> errorMap = outData.get(tableName);
|
|
|
+ if (errorMap.containsKey(errorType)) {
|
|
|
+ errorMap.put(errorType, errorMap.get(errorType) + errorNum);
|
|
|
+ } else {
|
|
|
+ errorMap.put(errorType, errorNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Map<String, Integer> errorMap = new HashMap<>();
|
|
|
+ errorMap.put(errorType, errorNum);
|
|
|
+ outData.put(tableName, errorMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+// 序号
|
|
|
+ int rowIndex = 1;
|
|
|
+ List<Map<String, Object>> outputDatas = new ArrayList<>();
|
|
|
+ while (daysum > 20) {
|
|
|
+// 检查日期
|
|
|
+ String updateTime = getPreviousDateStr(daysum);
|
|
|
+ daysum = daysum - ThreadLocalRandom.current().nextInt(1, 3);
|
|
|
+// 设置随机检查几个表
|
|
|
+ int tableNum = ThreadLocalRandom.current().nextInt(1, tableNameList.size() + 1);
|
|
|
+ while (tableNum > 0) {
|
|
|
+ String tableName = tableNameList.get(ThreadLocalRandom.current().nextInt(0, tableNameList.size()));
|
|
|
+ tableNum--;
|
|
|
+// 设置随机检查几个类型
|
|
|
+ int errorNum = ThreadLocalRandom.current().nextInt(1, errorTypes.size() + 1);
|
|
|
+ while (errorNum > 0) {
|
|
|
+// 得到随机问题类型
|
|
|
+ String errorTypeStr = errorTypes.get(ThreadLocalRandom.current().nextInt(0, errorTypes.size()));
|
|
|
+// 设置一个随机错误数量
|
|
|
+ int errorNums = ThreadLocalRandom.current().nextInt(0, 11) * ThreadLocalRandom.current().nextInt(0, errorR.get(errorTypeStr));
|
|
|
+ errorNum--;
|
|
|
+// 写入行
|
|
|
+ Map<String, Object> outDataItem = new HashMap<>();
|
|
|
+ outDataItem.put("序号", rowIndex);
|
|
|
+ rowIndex++;
|
|
|
+ outDataItem.put("源数据库信息", headers.get(tableName).get("源数据库信息"));
|
|
|
+ outDataItem.put("表中文注释", headers.get(tableName).get("表中文注释"));
|
|
|
+ outDataItem.put("表名", tableName);
|
|
|
+ outDataItem.put("判断异常原因", errorTypeStr);
|
|
|
+ outDataItem.put("问题类型", errorTypeStr);
|
|
|
+// 表名,问题类型,数量
|
|
|
+ if (outData.containsKey(tableName)) {
|
|
|
+ if (outData.get(tableName).containsKey(errorTypeStr)) {
|
|
|
+ outData.get(tableName).put(errorTypeStr, outData.get(tableName).get(errorTypeStr) + errorNums);
|
|
|
+ } else {
|
|
|
+ outData.get(tableName).put(errorTypeStr, errorNums);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Map<String, Integer> errorMap_ = new HashMap<>();
|
|
|
+ errorMap_.put(errorTypeStr, errorNums);
|
|
|
+ outData.put(tableName, errorMap_);
|
|
|
+ }
|
|
|
+ outDataItem.put("异常数据量", outData.get(tableName).get(errorTypeStr));
|
|
|
+ outDataItem.put("检查日期", updateTime);
|
|
|
+ outputDatas.add(outDataItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ ExcelReaderUtils.writeToExcel(outputDatas, "C:\\Users\\Liumouren\\Desktop\\异常数据清单-列表_output2.xlsx");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ /*com.alibaba.fastjson.JSONObject AllData = new com.alibaba.fastjson.JSONObject();
|
|
|
+ JSONArray featuresList = new JSONArray();
|
|
|
+ for (int i = 1; i <= 7282; i++) {
|
|
|
+ if (i == 7282) {
|
|
|
+ String requestData = requestWFS(i + "");
|
|
|
+ com.alibaba.fastjson.JSONObject requestJson = com.alibaba.fastjson.JSONObject.parseObject(requestData);
|
|
|
+ if (requestJson.containsKey("features")) {
|
|
|
+ featuresList.add(requestJson.getJSONArray("features").getJSONObject(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ AllData.put("features", featuresList);
|
|
|
+ AllData.put("type", "FeatureCollection");
|
|
|
+ System.out.println("内容大小:" + featuresList.size());
|
|
|
+ String jsonString = AllData.toJSONString();
|
|
|
+ String filePath = "output/cj_1.geojson";
|
|
|
+ try (FileWriter fileWriter = new FileWriter(filePath)) {
|
|
|
+ fileWriter.write(jsonString);
|
|
|
+ System.out.println("完成!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }*/
|
|
|
+ testFile();
|
|
|
+ }
|
|
|
}
|