|
|
|
@ -2,17 +2,28 @@ package com.supervision.demo;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.supervision.common.constant.IndexRuleConstants;
|
|
|
|
|
import com.supervision.police.domain.ComDictionary;
|
|
|
|
|
import com.supervision.police.domain.ModelAtomicIndex;
|
|
|
|
|
import com.supervision.police.domain.ModelIndex;
|
|
|
|
|
import com.supervision.police.domain.NotePrompt;
|
|
|
|
|
import com.supervision.police.service.ComDictionaryService;
|
|
|
|
|
import com.supervision.police.service.ModelAtomicIndexService;
|
|
|
|
|
import com.supervision.police.service.ModelIndexService;
|
|
|
|
|
import com.supervision.police.service.NotePromptService;
|
|
|
|
|
import com.supervision.police.vo.ModelIndexReqVO;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
@ -24,7 +35,11 @@ public class IndexTest {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelAtomicIndexService modelAtomicIndexService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ModelIndexService modelIndexService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private NotePromptService notePromptService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ComDictionaryService comDictionaryService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图谱生成原子指标历史数据关联提示词
|
|
|
|
@ -69,4 +84,73 @@ public class IndexTest {
|
|
|
|
|
});
|
|
|
|
|
log.info("未匹配的:{}。共:{}个", unMatched, unMatched.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出指标数据excel
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void exportIndex() {
|
|
|
|
|
//将结果生成Excel保存到桌面
|
|
|
|
|
Map<String, Object> data = (Map<String, Object>) modelIndexService.selectAll(new ModelIndexReqVO(), 1, 100000).getData();
|
|
|
|
|
List<ComDictionary> dicts = comDictionaryService.list();
|
|
|
|
|
System.out.println(data);
|
|
|
|
|
List<ModelIndex> list = (List<ModelIndex>) data.get("result");
|
|
|
|
|
list.sort(Comparator.comparing(ModelIndex::getIndexType));
|
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
list.forEach(index -> {
|
|
|
|
|
Map<String, Object> indexMap = new HashMap<>();
|
|
|
|
|
indexMap.put("指标名称", index.getName());
|
|
|
|
|
indexMap.put("指标得分", index.getIndexScore());
|
|
|
|
|
indexMap.put("指标类型", comDictionaryService.getName(dicts, "index_type", index.getIndexType()));
|
|
|
|
|
List<Map<String, String>> atomicIndexMapList = new ArrayList<>();
|
|
|
|
|
index.getAtomicIndexList().forEach(atomicIndex -> {
|
|
|
|
|
Map<String, String> atomicIndexMap = new HashMap<>();
|
|
|
|
|
atomicIndexMap.put("原子指标名称", atomicIndex.getName());
|
|
|
|
|
atomicIndexMap.put("指标来源", comDictionaryService.getName(dicts, "index_source", atomicIndex.getIndexSource()));
|
|
|
|
|
atomicIndexMapList.add(atomicIndexMap);
|
|
|
|
|
});
|
|
|
|
|
if (!atomicIndexMapList.isEmpty()) {
|
|
|
|
|
indexMap.put("原子指标", atomicIndexMapList);
|
|
|
|
|
}
|
|
|
|
|
result.add(indexMap);
|
|
|
|
|
});
|
|
|
|
|
System.out.println(result);
|
|
|
|
|
// 使用Apache POI生成Excel文件
|
|
|
|
|
try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
|
|
Sheet sheet = workbook.createSheet("Index Data");
|
|
|
|
|
int rowNum = 0;
|
|
|
|
|
Row headerRow = sheet.createRow(rowNum++);
|
|
|
|
|
String[] headers = {"指标类型", "指标名称", "指标得分", "原子指标名称", "指标来源"};
|
|
|
|
|
for (int i = 0; i < headers.length; i++) {
|
|
|
|
|
Cell cell = headerRow.createCell(i);
|
|
|
|
|
cell.setCellValue(headers[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Map<String, Object> indexMap : result) {
|
|
|
|
|
List<Map<String, String>> atomicIndexMapList = (List<Map<String, String>>) indexMap.get("原子指标");
|
|
|
|
|
int startRow = rowNum;
|
|
|
|
|
for (Map<String, String> atomicIndexMap : atomicIndexMapList) {
|
|
|
|
|
Row row = sheet.createRow(rowNum++);
|
|
|
|
|
row.createCell(3).setCellValue(atomicIndexMap.get("原子指标名称"));
|
|
|
|
|
row.createCell(4).setCellValue(atomicIndexMap.get("指标来源"));
|
|
|
|
|
}
|
|
|
|
|
if (atomicIndexMapList.size() > 1) {
|
|
|
|
|
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 0, 0));
|
|
|
|
|
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 1, 1));
|
|
|
|
|
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 2, 2));
|
|
|
|
|
}
|
|
|
|
|
Row firstRow = sheet.getRow(startRow);
|
|
|
|
|
firstRow.createCell(0).setCellValue((String) indexMap.get("指标类型"));
|
|
|
|
|
firstRow.createCell(1).setCellValue((String) indexMap.get("指标名称"));
|
|
|
|
|
firstRow.createCell(2).setCellValue((Integer) indexMap.get("指标得分"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将Excel文件保存到桌面
|
|
|
|
|
try (FileOutputStream fileOut = new FileOutputStream(System.getProperty("user.home") + "/Desktop/IndexData.xlsx")) {
|
|
|
|
|
workbook.write(fileOut);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|