|
|
|
@ -0,0 +1,130 @@
|
|
|
|
|
package com.supervision;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import com.supervision.model.AskTemplateQuestionLibrary;
|
|
|
|
|
import com.supervision.model.CommonDic;
|
|
|
|
|
import com.supervision.service.AskTemplateQuestionLibraryService;
|
|
|
|
|
import com.supervision.service.CommonDicService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.junit.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.SpringJUnit4ClassRunner;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
|
|
public class VecTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommonDicService commonDicService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String BASE_URL = "http://192.168.10.137:8711";
|
|
|
|
|
@Test
|
|
|
|
|
public void mainTest() throws Exception {
|
|
|
|
|
String filePath = "F:\\tmp\\1\\副本医生临床问诊问题收集v1.xlsx";
|
|
|
|
|
|
|
|
|
|
ExcelReader reader = ExcelUtil.getReader(filePath,1);
|
|
|
|
|
List<Map<String, Object>> dataList = reader.readAll();
|
|
|
|
|
|
|
|
|
|
// 加载数据库中的问题数据
|
|
|
|
|
List<AskTemplateQuestionLibrary> questionLibraries = askTemplateQuestionLibraryService.list();
|
|
|
|
|
Map<String, AskTemplateQuestionLibrary> idMapQuestion = questionLibraries.stream().collect(Collectors.toMap(AskTemplateQuestionLibrary::getId, v -> v));
|
|
|
|
|
List<CommonDic> commonDics = commonDicService.lambdaQuery().eq(CommonDic::getGroupCode, "AQT").list();
|
|
|
|
|
Map<Long, CommonDic> pathMapDic = commonDics.stream().collect(Collectors.toMap(CommonDic::getId, v -> v));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Map<String, Object> map : dataList) {
|
|
|
|
|
String question = MapUtil.getStr(map, "部分问诊问题(示例)");
|
|
|
|
|
String questionCode = askMatch(StrUtil.trim(question));
|
|
|
|
|
if (StrUtil.isEmpty(questionCode)){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
map.put("匹配到的问题Code",questionCode);
|
|
|
|
|
if (!NumberUtil.isNumber(questionCode)){
|
|
|
|
|
log.warn("question:{}的匹配Code不是数字:{}",question,questionCode);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
AskTemplateQuestionLibrary library = idMapQuestion.get(questionCode);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(library)){
|
|
|
|
|
map.put("匹配到的问题",library.getDescription());
|
|
|
|
|
CommonDic commonDic = pathMapDic.get(library.getDictId());
|
|
|
|
|
if (ObjectUtil.isNotEmpty(commonDic)){
|
|
|
|
|
String nameZhPath = commonDic.getNameZhPath();
|
|
|
|
|
List<String> split = StrUtil.split(nameZhPath, "/");
|
|
|
|
|
String first = split.get(0);
|
|
|
|
|
String second = null;
|
|
|
|
|
if (split.size()>1){
|
|
|
|
|
second = split.get(1);
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.equals(MapUtil.getStr(map,"一级问诊类目"),first)
|
|
|
|
|
&& StrUtil.equals(MapUtil.getStr(map,"二级问诊类目"),second)){
|
|
|
|
|
map.put("匹配结果","正确");
|
|
|
|
|
}else {
|
|
|
|
|
map.put("匹配结果","错误");
|
|
|
|
|
}
|
|
|
|
|
map.put("匹配到的问题路径",commonDic.getNameZhPath());
|
|
|
|
|
map.put("匹配到的字典id",commonDic.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("开始把结果数据写入表格");
|
|
|
|
|
ExcelUtil.getWriter(filePath,"结果对比").write(dataList).flush() ;
|
|
|
|
|
log.info("结束把结果数据写入表格");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String askMatch(String question){
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(question, "问题不能为空");
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put("question",question);
|
|
|
|
|
HttpRequest request = HttpRequest.post(BASE_URL + "/matchQuestion")
|
|
|
|
|
.body(JSONUtil.toJsonStr(params));
|
|
|
|
|
log.info("askMatch:question:{}", question);
|
|
|
|
|
try (HttpResponse response = request.execute()){
|
|
|
|
|
String body = response.body();
|
|
|
|
|
log.info("askMatch:响应结果:{}", body);
|
|
|
|
|
JSONObject entries = JSONUtil.parseObj(body);
|
|
|
|
|
if (entries.get("code",Integer.class) != 200){
|
|
|
|
|
log.warn("askMatch:匹配失败");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
JSONArray jsonArray = JSONUtil.parseArray(entries.get("data"));
|
|
|
|
|
if (CollUtil.isNotEmpty(jsonArray)){
|
|
|
|
|
return JSONUtil.parseObj(jsonArray.get(0)).get("matchQuestionCode",String.class);
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("chat:请求失败", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.warn("askMatch:匹配失败");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|