|
|
|
@ -275,168 +275,168 @@ public class ZhyFileManageController extends BaseController { |
|
|
|
// 默认 fallback
|
|
|
|
return isDefinitelyUtf8 ? "UTF-8" : "GBK"; |
|
|
|
} |
|
|
|
// @PostMapping("/insertRelationByFile")
|
|
|
|
// public AjaxResult insertRelationByFile(MultipartFile file) throws Throwable {
|
|
|
|
// // 1. 校验文件是否为空
|
|
|
|
// if (file.isEmpty()) {
|
|
|
|
// return AjaxResult.error("上传的文件为空");
|
|
|
|
// }
|
|
|
|
// String filePath1 =ARTICLE_DIR;
|
|
|
|
// // 2. 读取 CSV 文件(使用 GBK 编码)
|
|
|
|
// List<Map<String, String>> dataList = new ArrayList<>();
|
|
|
|
// String[] headers = null;
|
|
|
|
//
|
|
|
|
// InputStream inputStream = null;
|
|
|
|
// BufferedReader reader = null;
|
|
|
|
// try {
|
|
|
|
// inputStream = file.getInputStream();
|
|
|
|
//
|
|
|
|
// // 🔍 第一步:探测编码
|
|
|
|
// String encoding = detectCsvEncoding(inputStream);
|
|
|
|
// System.out.println("自动检测到编码: " + encoding);
|
|
|
|
//
|
|
|
|
// // 重新打开流(因为探测时已读取部分数据)
|
|
|
|
// inputStream.close();
|
|
|
|
// inputStream = file.getInputStream();
|
|
|
|
//
|
|
|
|
// reader = new BufferedReader(new InputStreamReader(inputStream, encoding));
|
|
|
|
//
|
|
|
|
// String line;
|
|
|
|
// int lineNumber = 0;
|
|
|
|
//
|
|
|
|
// while ((line = reader.readLine()) != null) {
|
|
|
|
// lineNumber++;
|
|
|
|
//
|
|
|
|
// // 去除 BOM(如果存在)
|
|
|
|
// if (lineNumber == 1 && line.startsWith("\uFEFF")) {
|
|
|
|
// line = line.substring(1);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // ✅ 替换 split(",") 为能处理引号内逗号的解析方法
|
|
|
|
// String[] row = parseCsvLine(line);
|
|
|
|
// for (int i = 0; i < row.length; i++) {
|
|
|
|
// row[i] = row[i].trim(); // 去空格
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (lineNumber == 1) {
|
|
|
|
// // 第一行是表头
|
|
|
|
// headers = row;
|
|
|
|
// continue; // 跳过第一行,不加入数据
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // 将每一行转为 Map<String, String>
|
|
|
|
// Map<String, String> rowMap = new HashMap<>();
|
|
|
|
// for (int i = 0; i < headers.length && i < row.length; i++) {
|
|
|
|
// String key = headers[i].trim();
|
|
|
|
// // 只保留你需要的字段
|
|
|
|
// if (Arrays.asList("ck", "main_keyword", "sub_keyword", "title", "authors", "keywords", "abstract", "url", "urls").contains(key)) {
|
|
|
|
// rowMap.put(key, row[i]);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// dataList.add(rowMap);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// } catch (IOException e) {
|
|
|
|
// return AjaxResult.error("读取文件时发生错误:" + e.getMessage());
|
|
|
|
// } finally {
|
|
|
|
// try {
|
|
|
|
// if (reader != null) reader.close();
|
|
|
|
// if (inputStream != null) inputStream.close();
|
|
|
|
// } catch (IOException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// List<ZhyDocRelation> allRelation=new ArrayList<>();
|
|
|
|
// // 3. 处理每一行数据(和你原来逻辑一致)
|
|
|
|
// for (Map<String, String> data : dataList) {
|
|
|
|
// System.out.println("44444444444444");
|
|
|
|
// System.out.println(data);
|
|
|
|
// String mainKeyword = data.get("main_keyword");
|
|
|
|
// Pattern pattern = Pattern.compile("'([^']*)'");
|
|
|
|
// Matcher matcher = pattern.matcher(mainKeyword);
|
|
|
|
//
|
|
|
|
// ArrayList<String> mainKeywordList = new ArrayList<>();
|
|
|
|
// while (matcher.find()) {
|
|
|
|
// mainKeywordList.add(matcher.group(1)); // 提取引号内的内容
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//// System.out.println(mainKeywordList);
|
|
|
|
// Map mapLevel=new HashMap();
|
|
|
|
// for (int i=0;i<mainKeywordList.size();i++){
|
|
|
|
//// System.out.println(mainKeywordList.get(i));
|
|
|
|
// ZhyDoc doc=test1Mapper.selectDocByTitle(mainKeywordList.get(i));
|
|
|
|
// if(doc!=null){
|
|
|
|
// if(doc.getDocLevel()==1l){
|
|
|
|
// mapLevel.put("l1",mainKeywordList.get(i));
|
|
|
|
// }
|
|
|
|
// if(doc.getDocLevel()==2l){
|
|
|
|
// mapLevel.put("l2",mainKeywordList.get(i));
|
|
|
|
// }
|
|
|
|
// if(doc.getDocLevel()==3l){
|
|
|
|
// mapLevel.put("l3",mainKeywordList.get(i));
|
|
|
|
// }
|
|
|
|
// if(doc.getDocLevel()==4l){
|
|
|
|
// mapLevel.put("l4",mainKeywordList.get(i));
|
|
|
|
// }
|
|
|
|
// if(doc.getDocLevel()==5l){
|
|
|
|
// mapLevel.put("l5",mainKeywordList.get(i));
|
|
|
|
// }
|
|
|
|
// if(doc.getDocLevel()==6l){
|
|
|
|
// mapLevel.put("l6",mainKeywordList.get(i));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//// System.out.println(mapLevel);
|
|
|
|
// //如果选择了l1,则看是否选择l2、l3、l4、l5、l6
|
|
|
|
// String[] levels = {"l1", "l2", "l3", "l4", "l5", "l6"};
|
|
|
|
// int n = levels.length;
|
|
|
|
//
|
|
|
|
// for (int i = 0; i < n - 1; i++) {
|
|
|
|
// String parentKey = levels[i];
|
|
|
|
// if (mapLevel.containsKey(parentKey)) {
|
|
|
|
// String parentValue = mapLevel.get(parentKey).toString();
|
|
|
|
// for (int j = i + 1; j < n; j++) {
|
|
|
|
// String childKey = levels[j];
|
|
|
|
// if (mapLevel.containsKey(childKey)) {
|
|
|
|
// String childValue = mapLevel.get(childKey).toString();
|
|
|
|
//
|
|
|
|
// ZhyDocRelation relation=new ZhyDocRelation();
|
|
|
|
// relation.setSourceName(parentValue);
|
|
|
|
// relation.setTargetName(childValue);
|
|
|
|
// List<Map> relations=zhyDocRelationMapper.selectZhyRelationshipArticle(relation);
|
|
|
|
//// System.out.println(relations);
|
|
|
|
// if(relations.size()>0){
|
|
|
|
// boolean flag=false;
|
|
|
|
// for (int p=0;p<relations.size();p++){
|
|
|
|
// if(relations.get(p).get("articleName").equals(data.get("title"))) {
|
|
|
|
// flag=true;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if(!flag){
|
|
|
|
// createRelation(parentValue, childValue,data,filePath1);
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// }else{
|
|
|
|
// //插入关系
|
|
|
|
//
|
|
|
|
// createRelation(parentValue, childValue,data,filePath1);
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
////
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
@PostMapping("/insertRelationByFile") |
|
|
|
public AjaxResult insertRelationByFile(MultipartFile file) throws Throwable { |
|
|
|
// 1. 校验文件是否为空
|
|
|
|
if (file.isEmpty()) { |
|
|
|
return AjaxResult.error("上传的文件为空"); |
|
|
|
} |
|
|
|
String filePath1 =ARTICLE_DIR; |
|
|
|
// 2. 读取 CSV 文件(使用 GBK 编码)
|
|
|
|
List<Map<String, String>> dataList = new ArrayList<>(); |
|
|
|
String[] headers = null; |
|
|
|
|
|
|
|
InputStream inputStream = null; |
|
|
|
BufferedReader reader = null; |
|
|
|
try { |
|
|
|
inputStream = file.getInputStream(); |
|
|
|
|
|
|
|
// 🔍 第一步:探测编码
|
|
|
|
String encoding = detectCsvEncoding(inputStream); |
|
|
|
System.out.println("自动检测到编码: " + encoding); |
|
|
|
|
|
|
|
// 重新打开流(因为探测时已读取部分数据)
|
|
|
|
inputStream.close(); |
|
|
|
inputStream = file.getInputStream(); |
|
|
|
|
|
|
|
reader = new BufferedReader(new InputStreamReader(inputStream, encoding)); |
|
|
|
|
|
|
|
String line; |
|
|
|
int lineNumber = 0; |
|
|
|
|
|
|
|
while ((line = reader.readLine()) != null) { |
|
|
|
lineNumber++; |
|
|
|
|
|
|
|
// 去除 BOM(如果存在)
|
|
|
|
if (lineNumber == 1 && line.startsWith("\uFEFF")) { |
|
|
|
line = line.substring(1); |
|
|
|
} |
|
|
|
|
|
|
|
// ✅ 替换 split(",") 为能处理引号内逗号的解析方法
|
|
|
|
String[] row = parseCsvLine(line); |
|
|
|
for (int i = 0; i < row.length; i++) { |
|
|
|
row[i] = row[i].trim(); // 去空格
|
|
|
|
} |
|
|
|
|
|
|
|
if (lineNumber == 1) { |
|
|
|
// 第一行是表头
|
|
|
|
headers = row; |
|
|
|
continue; // 跳过第一行,不加入数据
|
|
|
|
} |
|
|
|
|
|
|
|
// 将每一行转为 Map<String, String>
|
|
|
|
Map<String, String> rowMap = new HashMap<>(); |
|
|
|
for (int i = 0; i < headers.length && i < row.length; i++) { |
|
|
|
String key = headers[i].trim(); |
|
|
|
// 只保留你需要的字段
|
|
|
|
if (Arrays.asList("ck", "main_keyword", "sub_keyword", "title", "authors", "keywords", "abstract", "url", "urls").contains(key)) { |
|
|
|
rowMap.put(key, row[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
dataList.add(rowMap); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
return AjaxResult.error("读取文件时发生错误:" + e.getMessage()); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
if (reader != null) reader.close(); |
|
|
|
if (inputStream != null) inputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
List<ZhyDocRelation> allRelation=new ArrayList<>(); |
|
|
|
// 3. 处理每一行数据(和你原来逻辑一致)
|
|
|
|
for (Map<String, String> data : dataList) { |
|
|
|
System.out.println("44444444444444"); |
|
|
|
System.out.println(data); |
|
|
|
String mainKeyword = data.get("main_keyword"); |
|
|
|
Pattern pattern = Pattern.compile("'([^']*)'"); |
|
|
|
Matcher matcher = pattern.matcher(mainKeyword); |
|
|
|
|
|
|
|
ArrayList<String> mainKeywordList = new ArrayList<>(); |
|
|
|
while (matcher.find()) { |
|
|
|
mainKeywordList.add(matcher.group(1)); // 提取引号内的内容
|
|
|
|
} |
|
|
|
|
|
|
|
// System.out.println(mainKeywordList);
|
|
|
|
Map mapLevel=new HashMap(); |
|
|
|
for (int i=0;i<mainKeywordList.size();i++){ |
|
|
|
// System.out.println(mainKeywordList.get(i));
|
|
|
|
ZhyDoc doc=test1Mapper.selectDocByTitle(mainKeywordList.get(i)); |
|
|
|
if(doc!=null){ |
|
|
|
if(doc.getDocLevel()==1l){ |
|
|
|
mapLevel.put("l1",mainKeywordList.get(i)); |
|
|
|
} |
|
|
|
if(doc.getDocLevel()==2l){ |
|
|
|
mapLevel.put("l2",mainKeywordList.get(i)); |
|
|
|
} |
|
|
|
if(doc.getDocLevel()==3l){ |
|
|
|
mapLevel.put("l3",mainKeywordList.get(i)); |
|
|
|
} |
|
|
|
if(doc.getDocLevel()==4l){ |
|
|
|
mapLevel.put("l4",mainKeywordList.get(i)); |
|
|
|
} |
|
|
|
if(doc.getDocLevel()==5l){ |
|
|
|
mapLevel.put("l5",mainKeywordList.get(i)); |
|
|
|
} |
|
|
|
if(doc.getDocLevel()==6l){ |
|
|
|
mapLevel.put("l6",mainKeywordList.get(i)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// System.out.println(mapLevel);
|
|
|
|
//如果选择了l1,则看是否选择l2、l3、l4、l5、l6
|
|
|
|
String[] levels = {"l1", "l2", "l3", "l4", "l5", "l6"}; |
|
|
|
int n = levels.length; |
|
|
|
|
|
|
|
for (int i = 0; i < n - 1; i++) { |
|
|
|
String parentKey = levels[i]; |
|
|
|
if (mapLevel.containsKey(parentKey)) { |
|
|
|
String parentValue = mapLevel.get(parentKey).toString(); |
|
|
|
for (int j = i + 1; j < n; j++) { |
|
|
|
String childKey = levels[j]; |
|
|
|
if (mapLevel.containsKey(childKey)) { |
|
|
|
String childValue = mapLevel.get(childKey).toString(); |
|
|
|
|
|
|
|
ZhyDocRelation relation=new ZhyDocRelation(); |
|
|
|
relation.setSourceName(parentValue); |
|
|
|
relation.setTargetName(childValue); |
|
|
|
List<Map> relations=zhyDocRelationMapper.selectZhyRelationshipArticle(relation); |
|
|
|
// System.out.println(relations);
|
|
|
|
if(relations.size()>0){ |
|
|
|
boolean flag=false; |
|
|
|
for (int p=0;p<relations.size();p++){ |
|
|
|
if(relations.get(p).get("articleName").equals(data.get("title"))) { |
|
|
|
flag=true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!flag){ |
|
|
|
createRelation(parentValue, childValue,data,filePath1); |
|
|
|
|
|
|
|
} |
|
|
|
}else{ |
|
|
|
//插入关系
|
|
|
|
|
|
|
|
createRelation(parentValue, childValue,data,filePath1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//
|
|
|
|
// return AjaxResult.success().put("msg", "成功");
|
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success().put("msg", "成功"); |
|
|
|
} |
|
|
|
public void createRelation(String parentValue,String childValue,Map<String, String> data,String local) throws IOException { |
|
|
|
ZhyDoc doc1 = test1Mapper.selectDocByTitle(parentValue); |
|
|
|
ZhyDoc doc2 = test1Mapper.selectDocByTitle(childValue); |
|
|
|
@ -527,198 +527,198 @@ public class ZhyFileManageController extends BaseController { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@PostMapping("/insertRelationByFile") |
|
|
|
public AjaxResult insertRelationByFile(MultipartFile file) throws Throwable { |
|
|
|
// 1. 校验文件是否为空
|
|
|
|
if (file.isEmpty()) { |
|
|
|
return AjaxResult.error("上传的文件为空"); |
|
|
|
} |
|
|
|
// 2. 校验是否为 CSV 文件
|
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
if (fileName == null || !fileName.toLowerCase().endsWith(".csv")) { |
|
|
|
return AjaxResult.error("仅支持上传 CSV 格式的文件"); |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 自动检测编码并读取 CSV 文件(支持 GBK / UTF-8)
|
|
|
|
List<Map<String, String>> dataList = new ArrayList<>(); |
|
|
|
String[] headers = null; |
|
|
|
|
|
|
|
InputStream inputStream = null; |
|
|
|
BufferedReader reader = null; |
|
|
|
try { |
|
|
|
inputStream = file.getInputStream(); |
|
|
|
|
|
|
|
// 🔍 第一步:探测编码
|
|
|
|
String encoding = detectCsvEncoding(inputStream); |
|
|
|
System.out.println("自动检测到编码: " + encoding); |
|
|
|
|
|
|
|
// 重新打开流(因为探测时已读取部分数据)
|
|
|
|
inputStream.close(); |
|
|
|
inputStream = file.getInputStream(); |
|
|
|
|
|
|
|
reader = new BufferedReader(new InputStreamReader(inputStream, encoding)); |
|
|
|
|
|
|
|
String line; |
|
|
|
int lineNumber = 0; |
|
|
|
|
|
|
|
while ((line = reader.readLine()) != null) { |
|
|
|
lineNumber++; |
|
|
|
|
|
|
|
// 去除 BOM(如果存在)
|
|
|
|
if (lineNumber == 1 && line.startsWith("\uFEFF")) { |
|
|
|
line = line.substring(1); |
|
|
|
} |
|
|
|
|
|
|
|
// ✅ 替换 split(",") 为能处理引号内逗号的解析方法
|
|
|
|
String[] row = parseCsvLine(line); |
|
|
|
for (int i = 0; i < row.length; i++) { |
|
|
|
row[i] = row[i].trim(); // 去空格
|
|
|
|
} |
|
|
|
|
|
|
|
if (lineNumber == 1) { |
|
|
|
// 第一行是表头
|
|
|
|
headers = row; |
|
|
|
continue; // 跳过第一行,不加入数据
|
|
|
|
} |
|
|
|
|
|
|
|
// 将每一行转为 Map<String, String>
|
|
|
|
Map<String, String> rowMap = new HashMap<>(); |
|
|
|
for (int i = 0; i < headers.length && i < row.length; i++) { |
|
|
|
String key = headers[i].trim(); |
|
|
|
// 只保留你需要的字段
|
|
|
|
if (Arrays.asList("ck", "main_keyword", "sub_keyword", "title", "authors", "keywords", "abstract", "url", "urls").contains(key)) { |
|
|
|
rowMap.put(key, row[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
dataList.add(rowMap); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
return AjaxResult.error("读取文件时发生错误:" + e.getMessage()); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
if (reader != null) reader.close(); |
|
|
|
if (inputStream != null) inputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
System.out.println("共读取到 " + dataList.size() + " 条数据:"); |
|
|
|
for (int i = 0; i < dataList.size(); i++) { |
|
|
|
Map<String, String> data = dataList.get(i); |
|
|
|
|
|
|
|
String title1=data.get("main_keyword"); |
|
|
|
String mainKeyword = data.get("main_keyword"); |
|
|
|
Pattern pattern = Pattern.compile("'([^']*)'"); |
|
|
|
Matcher matcher = pattern.matcher(mainKeyword); |
|
|
|
|
|
|
|
ArrayList<String> mainKeywordList = new ArrayList<>(); |
|
|
|
while (matcher.find()) { |
|
|
|
mainKeywordList.add(matcher.group(1)); // 提取引号内的内容
|
|
|
|
} |
|
|
|
System.out.println(title1); |
|
|
|
String title2=data.get("sub_keyword"); |
|
|
|
System.out.println(title2); |
|
|
|
//关联父节点
|
|
|
|
ZhyDoc doc1=test1Mapper.selectDocByTitle(title1); |
|
|
|
ZhyDoc doc2=test1Mapper.selectDocByTitle(title2); |
|
|
|
System.out.println("33333333333333333"); |
|
|
|
System.out.println(doc1); |
|
|
|
System.out.println(doc2); |
|
|
|
if(doc1!=null&doc2!=null){ |
|
|
|
List<ZhyDoc> list = test1Mapper.selectAllDoc1(); |
|
|
|
ZhyArticle article=new ZhyArticle(); |
|
|
|
|
|
|
|
article.setName(data.get("title")); |
|
|
|
article.setOpenUrl(data.get("url")); |
|
|
|
article.setAuthors(data.get("authors")); |
|
|
|
article.setKeywords(data.get("keywords")); |
|
|
|
article.setSummary(data.get("abstract")); |
|
|
|
article.setUrls(data.get("urls")); |
|
|
|
|
|
|
|
File file1 = new File(ARTICLE_PDF_DIR, sanitizeFilenameStrict(article.getName())+".pdf"); |
|
|
|
|
|
|
|
article.setLocalUrl(file1.getAbsolutePath()); |
|
|
|
article.setSourceId(doc1.getId()); |
|
|
|
article.setSourceName(doc1.getDocTitle()); |
|
|
|
article.setTargetId(doc2.getId()); |
|
|
|
article.setTagertName(doc2.getDocTitle()); |
|
|
|
|
|
|
|
zhyArticleMapper.insertZhyArticle(article); |
|
|
|
System.out.println("sssssssssssss"); |
|
|
|
System.out.println(article.getId()); |
|
|
|
// for(int a=0;a<list.size();a++){
|
|
|
|
// test1Mapper.updateParentId(list.get(a));
|
|
|
|
// @PostMapping("/insertRelationByFile")
|
|
|
|
// public AjaxResult insertRelationByFile(MultipartFile file) throws Throwable {
|
|
|
|
// // 1. 校验文件是否为空
|
|
|
|
// if (file.isEmpty()) {
|
|
|
|
// return AjaxResult.error("上传的文件为空");
|
|
|
|
// }
|
|
|
|
//// 2. 校验是否为 CSV 文件
|
|
|
|
// String fileName = file.getOriginalFilename();
|
|
|
|
// if (fileName == null || !fileName.toLowerCase().endsWith(".csv")) {
|
|
|
|
// return AjaxResult.error("仅支持上传 CSV 格式的文件");
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//// 3. 自动检测编码并读取 CSV 文件(支持 GBK / UTF-8)
|
|
|
|
// List<Map<String, String>> dataList = new ArrayList<>();
|
|
|
|
// String[] headers = null;
|
|
|
|
//
|
|
|
|
// InputStream inputStream = null;
|
|
|
|
// BufferedReader reader = null;
|
|
|
|
// try {
|
|
|
|
// inputStream = file.getInputStream();
|
|
|
|
//
|
|
|
|
// // 🔍 第一步:探测编码
|
|
|
|
// String encoding = detectCsvEncoding(inputStream);
|
|
|
|
// System.out.println("自动检测到编码: " + encoding);
|
|
|
|
//
|
|
|
|
// // 重新打开流(因为探测时已读取部分数据)
|
|
|
|
// inputStream.close();
|
|
|
|
// inputStream = file.getInputStream();
|
|
|
|
//
|
|
|
|
// reader = new BufferedReader(new InputStreamReader(inputStream, encoding));
|
|
|
|
//
|
|
|
|
// String line;
|
|
|
|
// int lineNumber = 0;
|
|
|
|
//
|
|
|
|
// while ((line = reader.readLine()) != null) {
|
|
|
|
// lineNumber++;
|
|
|
|
//
|
|
|
|
// // 去除 BOM(如果存在)
|
|
|
|
// if (lineNumber == 1 && line.startsWith("\uFEFF")) {
|
|
|
|
// line = line.substring(1);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // ✅ 替换 split(",") 为能处理引号内逗号的解析方法
|
|
|
|
// String[] row = parseCsvLine(line);
|
|
|
|
// for (int i = 0; i < row.length; i++) {
|
|
|
|
// row[i] = row[i].trim(); // 去空格
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (lineNumber == 1) {
|
|
|
|
// // 第一行是表头
|
|
|
|
// headers = row;
|
|
|
|
// continue; // 跳过第一行,不加入数据
|
|
|
|
// }
|
|
|
|
// test1Mapper.insertDocList(list);
|
|
|
|
ZhyDocRelation zz = new ZhyDocRelation(); |
|
|
|
zz.setRelationship(relation); |
|
|
|
zz.setSource(doc1.getId()); |
|
|
|
zz.setTarget(doc2.getId()); |
|
|
|
zz.setSourceName(doc1.getDocTitle()); |
|
|
|
zz.setTargetName(doc2.getDocTitle()); |
|
|
|
zz.setCreateTime(new Date()); |
|
|
|
zz.setArticleId(article.getId()); |
|
|
|
zhyDocRelationMapper.insertZhyRelationship(zz); |
|
|
|
List<String> ids = new ArrayList<>(); |
|
|
|
ids.add(String.valueOf(zz.getId())); |
|
|
|
ESDao esDao = new ESDao(); |
|
|
|
esDao.id = article.getId().toString(); |
|
|
|
esDao.DBid = article.getId().toString(); |
|
|
|
esDao.type = "line"; |
|
|
|
if(article.getLocalUrl()!=null){ |
|
|
|
System.out.println("333333"); |
|
|
|
try { |
|
|
|
String txt=article.getLocalUrl().replace("pdf", "txt"); |
|
|
|
List<String> content = extractContentUntilSecondPage(txt); |
|
|
|
if (content != null) { |
|
|
|
// 打印结果
|
|
|
|
for (String line : content) { |
|
|
|
System.out.println(line); |
|
|
|
} |
|
|
|
String result = String.join("", content); |
|
|
|
esDao.abstracts = result; |
|
|
|
} else { |
|
|
|
System.out.println("未找到相关内容或文件不存在。"); |
|
|
|
esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary(); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary(); |
|
|
|
} |
|
|
|
esDao.data = ids.toString(); |
|
|
|
esService.insertDocById("links",esDao); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//获取所有关系
|
|
|
|
List<ZhyDocRelation> listR = zhyDocRelationMapper.getAllRelation(); |
|
|
|
// List<String> ids = new ArrayList<>();
|
|
|
|
//创建
|
|
|
|
for(int i=0;i<listR.size();i++){ |
|
|
|
// ids.add(String.valueOf(listR.get(i).getId()));
|
|
|
|
String cql = "MATCH (a:Doc),(b:Doc) WHERE a.docId = '"+listR.get(i).getSource() +"' AND " + "b.docId = '"+listR.get(i).getTarget()+"'"; |
|
|
|
cql = cql + " CREATE (a)-[r:"+String.valueOf(listR.get(i).getRelationship())+"{ name: '"+String.valueOf(listR.get(i).getRelationship())+"', DbId: '"+String.valueOf(listR.get(i).getId())+"' }] -> (b) RETURN r"; |
|
|
|
neo4jUtil.excuteCypherSql(cql); |
|
|
|
test1Mapper.updateGraphRelation(listR.get(i)); |
|
|
|
} |
|
|
|
// for (ZhyDocRelation rel : listR) {
|
|
|
|
// ZhyArticle article=zhyArticleMapper.selectZhyArticleById(rel.getArticleId());
|
|
|
|
// ESDao esDao = new ESDao();
|
|
|
|
// esDao.id = article.getId().toString();
|
|
|
|
// esDao.DBid = article.getId().toString();
|
|
|
|
// esDao.type = "line";
|
|
|
|
// esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary();
|
|
|
|
// esDao.data = ids.toString();
|
|
|
|
//
|
|
|
|
// // 将每一行转为 Map<String, String>
|
|
|
|
// Map<String, String> rowMap = new HashMap<>();
|
|
|
|
// for (int i = 0; i < headers.length && i < row.length; i++) {
|
|
|
|
// String key = headers[i].trim();
|
|
|
|
// // 只保留你需要的字段
|
|
|
|
// if (Arrays.asList("ck", "main_keyword", "sub_keyword", "title", "authors", "keywords", "abstract", "url", "urls").contains(key)) {
|
|
|
|
// rowMap.put(key, row[i]);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// dataList.add(rowMap);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// } catch (IOException e) {
|
|
|
|
// return AjaxResult.error("读取文件时发生错误:" + e.getMessage());
|
|
|
|
// } finally {
|
|
|
|
// try {
|
|
|
|
// if (reader != null) reader.close();
|
|
|
|
// if (inputStream != null) inputStream.close();
|
|
|
|
// } catch (IOException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
return AjaxResult.success().put("msg", "成功"); |
|
|
|
} |
|
|
|
//
|
|
|
|
// System.out.println("共读取到 " + dataList.size() + " 条数据:");
|
|
|
|
// for (int i = 0; i < dataList.size(); i++) {
|
|
|
|
// Map<String, String> data = dataList.get(i);
|
|
|
|
//
|
|
|
|
// String title1=data.get("main_keyword");
|
|
|
|
// String mainKeyword = data.get("main_keyword");
|
|
|
|
// Pattern pattern = Pattern.compile("'([^']*)'");
|
|
|
|
// Matcher matcher = pattern.matcher(mainKeyword);
|
|
|
|
//
|
|
|
|
// ArrayList<String> mainKeywordList = new ArrayList<>();
|
|
|
|
// while (matcher.find()) {
|
|
|
|
// mainKeywordList.add(matcher.group(1)); // 提取引号内的内容
|
|
|
|
// }
|
|
|
|
// System.out.println(title1);
|
|
|
|
// String title2=data.get("sub_keyword");
|
|
|
|
// System.out.println(title2);
|
|
|
|
// //关联父节点
|
|
|
|
// ZhyDoc doc1=test1Mapper.selectDocByTitle(title1);
|
|
|
|
// ZhyDoc doc2=test1Mapper.selectDocByTitle(title2);
|
|
|
|
// System.out.println("33333333333333333");
|
|
|
|
// System.out.println(doc1);
|
|
|
|
// System.out.println(doc2);
|
|
|
|
// if(doc1!=null&doc2!=null){
|
|
|
|
// List<ZhyDoc> list = test1Mapper.selectAllDoc1();
|
|
|
|
// ZhyArticle article=new ZhyArticle();
|
|
|
|
//
|
|
|
|
// article.setName(data.get("title"));
|
|
|
|
// article.setOpenUrl(data.get("url"));
|
|
|
|
// article.setAuthors(data.get("authors"));
|
|
|
|
// article.setKeywords(data.get("keywords"));
|
|
|
|
// article.setSummary(data.get("abstract"));
|
|
|
|
// article.setUrls(data.get("urls"));
|
|
|
|
//
|
|
|
|
// File file1 = new File(ARTICLE_PDF_DIR, sanitizeFilenameStrict(article.getName())+".pdf");
|
|
|
|
//
|
|
|
|
// article.setLocalUrl(file1.getAbsolutePath());
|
|
|
|
// article.setSourceId(doc1.getId());
|
|
|
|
// article.setSourceName(doc1.getDocTitle());
|
|
|
|
// article.setTargetId(doc2.getId());
|
|
|
|
// article.setTagertName(doc2.getDocTitle());
|
|
|
|
//
|
|
|
|
// zhyArticleMapper.insertZhyArticle(article);
|
|
|
|
// System.out.println("sssssssssssss");
|
|
|
|
// System.out.println(article.getId());
|
|
|
|
//// for(int a=0;a<list.size();a++){
|
|
|
|
//// test1Mapper.updateParentId(list.get(a));
|
|
|
|
//// }
|
|
|
|
//// test1Mapper.insertDocList(list);
|
|
|
|
// ZhyDocRelation zz = new ZhyDocRelation();
|
|
|
|
// zz.setRelationship(relation);
|
|
|
|
// zz.setSource(doc1.getId());
|
|
|
|
// zz.setTarget(doc2.getId());
|
|
|
|
// zz.setSourceName(doc1.getDocTitle());
|
|
|
|
// zz.setTargetName(doc2.getDocTitle());
|
|
|
|
// zz.setCreateTime(new Date());
|
|
|
|
// zz.setArticleId(article.getId());
|
|
|
|
// zhyDocRelationMapper.insertZhyRelationship(zz);
|
|
|
|
// List<String> ids = new ArrayList<>();
|
|
|
|
// ids.add(String.valueOf(zz.getId()));
|
|
|
|
// ESDao esDao = new ESDao();
|
|
|
|
// esDao.id = article.getId().toString();
|
|
|
|
// esDao.DBid = article.getId().toString();
|
|
|
|
// esDao.type = "line";
|
|
|
|
// if(article.getLocalUrl()!=null){
|
|
|
|
// System.out.println("333333");
|
|
|
|
// try {
|
|
|
|
// String txt=article.getLocalUrl().replace("pdf", "txt");
|
|
|
|
// List<String> content = extractContentUntilSecondPage(txt);
|
|
|
|
// if (content != null) {
|
|
|
|
// // 打印结果
|
|
|
|
// for (String line : content) {
|
|
|
|
// System.out.println(line);
|
|
|
|
// }
|
|
|
|
// String result = String.join("", content);
|
|
|
|
// esDao.abstracts = result;
|
|
|
|
// } else {
|
|
|
|
// System.out.println("未找到相关内容或文件不存在。");
|
|
|
|
// esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary();
|
|
|
|
// }
|
|
|
|
// } catch (IOException e) {
|
|
|
|
// e.printStackTrace();
|
|
|
|
// esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary();
|
|
|
|
// }
|
|
|
|
// }else{
|
|
|
|
// esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary();
|
|
|
|
// }
|
|
|
|
// esDao.data = ids.toString();
|
|
|
|
// esService.insertDocById("links",esDao);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //获取所有关系
|
|
|
|
// List<ZhyDocRelation> listR = zhyDocRelationMapper.getAllRelation();
|
|
|
|
//// List<String> ids = new ArrayList<>();
|
|
|
|
// //创建
|
|
|
|
// for(int i=0;i<listR.size();i++){
|
|
|
|
//// ids.add(String.valueOf(listR.get(i).getId()));
|
|
|
|
// String cql = "MATCH (a:Doc),(b:Doc) WHERE a.docId = '"+listR.get(i).getSource() +"' AND " + "b.docId = '"+listR.get(i).getTarget()+"'";
|
|
|
|
// cql = cql + " CREATE (a)-[r:"+String.valueOf(listR.get(i).getRelationship())+"{ name: '"+String.valueOf(listR.get(i).getRelationship())+"', DbId: '"+String.valueOf(listR.get(i).getId())+"' }] -> (b) RETURN r";
|
|
|
|
// neo4jUtil.excuteCypherSql(cql);
|
|
|
|
// test1Mapper.updateGraphRelation(listR.get(i));
|
|
|
|
// }
|
|
|
|
//// for (ZhyDocRelation rel : listR) {
|
|
|
|
//// ZhyArticle article=zhyArticleMapper.selectZhyArticleById(rel.getArticleId());
|
|
|
|
//// ESDao esDao = new ESDao();
|
|
|
|
//// esDao.id = article.getId().toString();
|
|
|
|
//// esDao.DBid = article.getId().toString();
|
|
|
|
//// esDao.type = "line";
|
|
|
|
//// esDao.abstracts = article.getName()+article.getKeywords()+article.getSummary();
|
|
|
|
//// esDao.data = ids.toString();
|
|
|
|
////
|
|
|
|
//// }
|
|
|
|
//
|
|
|
|
// return AjaxResult.success().put("msg", "成功");
|
|
|
|
// }
|
|
|
|
|
|
|
|
public List<String> extractContentUntilSecondPage(String filePath) throws IOException { |
|
|
|
File file = new File(filePath); |
|
|
|
|