1. 添加指标测试类
parent
be3946dbfd
commit
175c5b9bfc
@ -0,0 +1,147 @@
|
||||
package com.supervision.springaidemo;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.supervision.police.domain.ModelAtomicIndex;
|
||||
import com.supervision.police.domain.ModelIndex;
|
||||
import com.supervision.police.dto.AtomicData;
|
||||
import com.supervision.police.dto.JudgeLogic;
|
||||
import com.supervision.police.mapper.ModelAtomicIndexMapper;
|
||||
import com.supervision.police.mapper.ModelIndexMapper;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class ModelIndexTest {
|
||||
|
||||
@Autowired
|
||||
private ModelIndexMapper modelIndexMapper;
|
||||
|
||||
@Autowired
|
||||
private ModelAtomicIndexMapper modelAtomicIndexMapper;
|
||||
//@Test
|
||||
public void modelIndexGenerate() {
|
||||
|
||||
List<ModelIndex> modelIndexList = readModelIndex();
|
||||
|
||||
for (ModelIndex modelIndex : modelIndexList) {
|
||||
modelIndexMapper.insert(modelIndex);
|
||||
for (ModelAtomicIndex modelAtomicIndex : modelIndex.getAtomicIndexList()) {
|
||||
modelAtomicIndexMapper.insert(modelAtomicIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<ModelIndex> readModelIndex() {
|
||||
String path = "F:\\supervision\\doc\\宁夏公安\\宁夏大模型项目计划0722.xlsx";
|
||||
|
||||
ExcelReader reader = ExcelUtil.getReader(path, "原子指标拆分");
|
||||
List<List<Object>> list = reader.read(1);
|
||||
|
||||
ArrayList<Index> indices = new ArrayList<>();
|
||||
|
||||
Map<String, String> typeMap = Map.of("共性指标", "1", "入罪指标", "2", "出罪指标", "3");
|
||||
for (List<Object> row : list) {
|
||||
if (!"数据库查询".equals(row.get(4).toString())){
|
||||
continue;
|
||||
}
|
||||
String type = row.get(0).toString();
|
||||
Index index = new Index(typeMap.get(type), row.get(1).toString(), row.get(2).toString(),
|
||||
row.get(3).toString(), row.get(4).toString(), row.get(10).toString());
|
||||
|
||||
indices.add(index);
|
||||
}
|
||||
|
||||
Map<ModelIndex, List<ModelAtomicIndex>> modelIndexListMap = indices.stream().collect(Collectors.groupingBy(index -> {
|
||||
ModelIndex modelIndex = new ModelIndex();
|
||||
modelIndex.setId(index.getId());
|
||||
modelIndex.setName(index.getName());
|
||||
modelIndex.setShortName(index.getName());
|
||||
modelIndex.setIndexType(index.getType());
|
||||
modelIndex.setIndexScore(1);
|
||||
modelIndex.setCaseType("1");
|
||||
modelIndex.setDataStatus("1");
|
||||
modelIndex.setRemark("auto-generate");
|
||||
return modelIndex;
|
||||
}, Collectors.mapping(index -> {
|
||||
ModelAtomicIndex modelAtomicIndex = new ModelAtomicIndex();
|
||||
modelAtomicIndex.setId(UUID.fastUUID().toString());
|
||||
modelAtomicIndex.setName(index.getAtomicIndexName());
|
||||
modelAtomicIndex.setCaseType("1");
|
||||
modelAtomicIndex.setIndexSource("2");
|
||||
modelAtomicIndex.setQueryLang(index.getSql());
|
||||
modelAtomicIndex.setRemark("auto-generate");
|
||||
return modelAtomicIndex;
|
||||
}, Collectors.toList())));
|
||||
|
||||
|
||||
for (Map.Entry<ModelIndex, List<ModelAtomicIndex>> entry : modelIndexListMap.entrySet()) {
|
||||
ModelIndex key = entry.getKey();
|
||||
key.setId(UUID.fastUUID().toString());
|
||||
List<ModelAtomicIndex> value = entry.getValue();
|
||||
if (CollUtil.isEmpty(value)){
|
||||
System.out.println("-----valuen 为空----");
|
||||
continue;
|
||||
}
|
||||
List<String> atomicIds = value.stream().map(ModelAtomicIndex::getId).toList();
|
||||
key.setAtomicIndexNum(atomicIds.size());
|
||||
JudgeLogic judgeLogic = new JudgeLogic();
|
||||
judgeLogic.setRowLogic("2");
|
||||
judgeLogic.setGroupLogic("1");
|
||||
List<AtomicData> list1 = value.stream().map(atomicIndex -> {
|
||||
AtomicData atomicData = new AtomicData();
|
||||
atomicData.setAtomicIndex(atomicIndex.getId());
|
||||
atomicData.setRelationalSymbol("3");
|
||||
return atomicData;
|
||||
}).toList();
|
||||
judgeLogic.setAtomicData(list1);
|
||||
key.setJudgeLogic(JSONUtil.toJsonStr(CollUtil.newArrayList(judgeLogic)));
|
||||
|
||||
key.setAtomicIndexList(value);
|
||||
}
|
||||
|
||||
return modelIndexListMap.keySet().stream().toList();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ModelIndexTest().readModelIndex();
|
||||
}
|
||||
@Data
|
||||
public static class Index{
|
||||
|
||||
private String type;
|
||||
private String id;
|
||||
private String name;
|
||||
private String atomicIndexName;
|
||||
private String sourceType;
|
||||
private String sql;
|
||||
|
||||
public Index() {
|
||||
}
|
||||
|
||||
public Index(String type, String id, String name, String atomicIndexName, String sourceType, String sql) {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.atomicIndexName = atomicIndexName;
|
||||
this.sourceType = sourceType;
|
||||
this.sql = sql;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue