Browse Source

导入文件夹

small-tupu
hanyuqing 6 months ago
parent
commit
c43a439fdf
  1. 42
      gyxtp/package-lock.json
  2. 2
      gyxtp/package.json
  3. 155
      gyxtp/src/view/small.vue
  4. 260
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyFileManageController.java
  5. 87
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/FolderUploadController.java
  6. 17
      ruoyi-api/src/main/java/com/ruoyi/api/service/impl/BuildService.java

42
gyxtp/package-lock.json

@ -15,7 +15,7 @@
"@vueuse/core": "^10.1.0",
"axios": "^1.7.7",
"core-js": "^3.8.3",
"echarts": "^5.5.1",
"echarts": "^5.3.3",
"echarts-wordcloud": "^2.0.0",
"element-plus": "^2.8.8",
"fabric": "^6.4.3",
@ -6538,18 +6538,18 @@
}
},
"node_modules/echarts": {
"version": "5.5.1",
"resolved": "https://registry.npmmirror.com/echarts/-/echarts-5.5.1.tgz",
"integrity": "sha512-Fce8upazaAXUVUVsjgV6mBnGuqgO+JNDlcgF79Dksy4+wgGpQB2lmYoO4TSweFg/mZITdpGHomw/cNBJZj1icA==",
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/echarts/-/echarts-5.3.3.tgz",
"integrity": "sha512-BRw2serInRwO5SIwRviZ6Xgm5Lb7irgz+sLiFMmy/HOaf4SQ+7oYqxKzRHAKp4xHQ05AuHw1xvoQWJjDQq/FGw==",
"dependencies": {
"tslib": "2.3.0",
"zrender": "5.6.0"
"zrender": "5.3.2"
}
},
"node_modules/echarts-wordcloud": {
"version": "2.1.0",
"resolved": "https://registry.npmmirror.com/echarts-wordcloud/-/echarts-wordcloud-2.1.0.tgz",
"integrity": "sha512-Kt1JmbcROgb+3IMI48KZECK2AP5lG6bSsOEs+AsuwaWJxQom31RTNd6NFYI01E/YaI1PFZeueaupjlmzSQasjQ==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/echarts-wordcloud/-/echarts-wordcloud-2.0.0.tgz",
"integrity": "sha512-K7l6pTklqdW7ZWzT/1CS0KhBSINr/cd7c5N1fVMzZMwLQHEwT7x+nivK7g5hkVh7WNcAv4Dn6/ZS5zMKRozC1g==",
"peerDependencies": {
"echarts": "^5.0.1"
}
@ -15875,9 +15875,9 @@
"dev": true
},
"node_modules/zrender": {
"version": "5.6.0",
"resolved": "https://registry.npmmirror.com/zrender/-/zrender-5.6.0.tgz",
"integrity": "sha512-uzgraf4njmmHAbEUxMJ8Oxg+P3fT04O+9p7gY+wJRVxo8Ge+KmYv0WJev945EH4wFuc4OY2NLXz46FZrWS9xJg==",
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/zrender/-/zrender-5.3.2.tgz",
"integrity": "sha512-8IiYdfwHj2rx0UeIGZGGU4WEVSDEdeVCaIg/fomejg1Xu6OifAL1GVzIPHg2D+MyUkbNgPWji90t0a8IDk+39w==",
"dependencies": {
"tslib": "2.3.0"
}
@ -20497,18 +20497,18 @@
"dev": true
},
"echarts": {
"version": "5.5.1",
"resolved": "https://registry.npmmirror.com/echarts/-/echarts-5.5.1.tgz",
"integrity": "sha512-Fce8upazaAXUVUVsjgV6mBnGuqgO+JNDlcgF79Dksy4+wgGpQB2lmYoO4TSweFg/mZITdpGHomw/cNBJZj1icA==",
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/echarts/-/echarts-5.3.3.tgz",
"integrity": "sha512-BRw2serInRwO5SIwRviZ6Xgm5Lb7irgz+sLiFMmy/HOaf4SQ+7oYqxKzRHAKp4xHQ05AuHw1xvoQWJjDQq/FGw==",
"requires": {
"tslib": "2.3.0",
"zrender": "5.6.0"
"zrender": "5.3.2"
}
},
"echarts-wordcloud": {
"version": "2.1.0",
"resolved": "https://registry.npmmirror.com/echarts-wordcloud/-/echarts-wordcloud-2.1.0.tgz",
"integrity": "sha512-Kt1JmbcROgb+3IMI48KZECK2AP5lG6bSsOEs+AsuwaWJxQom31RTNd6NFYI01E/YaI1PFZeueaupjlmzSQasjQ==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/echarts-wordcloud/-/echarts-wordcloud-2.0.0.tgz",
"integrity": "sha512-K7l6pTklqdW7ZWzT/1CS0KhBSINr/cd7c5N1fVMzZMwLQHEwT7x+nivK7g5hkVh7WNcAv4Dn6/ZS5zMKRozC1g==",
"requires": {}
},
"ee-first": {
@ -27478,9 +27478,9 @@
}
},
"zrender": {
"version": "5.6.0",
"resolved": "https://registry.npmmirror.com/zrender/-/zrender-5.6.0.tgz",
"integrity": "sha512-uzgraf4njmmHAbEUxMJ8Oxg+P3fT04O+9p7gY+wJRVxo8Ge+KmYv0WJev945EH4wFuc4OY2NLXz46FZrWS9xJg==",
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/zrender/-/zrender-5.3.2.tgz",
"integrity": "sha512-8IiYdfwHj2rx0UeIGZGGU4WEVSDEdeVCaIg/fomejg1Xu6OifAL1GVzIPHg2D+MyUkbNgPWji90t0a8IDk+39w==",
"requires": {
"tslib": "2.3.0"
}

2
gyxtp/package.json

@ -12,7 +12,7 @@
"@vueuse/core": "^10.1.0",
"axios": "^1.7.7",
"core-js": "^3.8.3",
"echarts": "^5.5.1",
"echarts": "^5.3.3",
"echarts-wordcloud": "^2.0.0",
"element-plus": "^2.8.8",
"fabric": "^6.4.3",

155
gyxtp/src/view/small.vue

@ -12,6 +12,7 @@
<img src="../assets/img2/open3.png" style="width: 60%;object-fit: contain;margin-top: 1.8vw;">
</div>
<div class="rightBox">
<div class="graphGround">
<div class="graphHeader">
<!-- <div class="gjz">-->
@ -26,6 +27,7 @@
<img src="../assets/img2/dingwei.png"
style="width: 2vw;object-fit: contain;position: absolute;z-index: 2000;top: 1vw;right: 2vw;cursor: pointer;"
@click="opending">
<div class="selectListInfo" v-if="isDing"
style="z-index: 2000;
max-height:35vw;
@ -98,6 +100,10 @@
</div>
</div>
</div>
<div class="container">
<h3>固定区域词云图</h3>
<div ref="chart" class="chart-container"></div>
</div>
</div>
<div style="background-color: transparent;height: 20%;width: 40%;position: absolute;top: 1vw;right: 0;"></div>
@ -113,16 +119,21 @@
</template>
</el-table-column>
</el-table>
</el-drawer>
</div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import 'echarts-wordcloud';
import RelationGraph, { RGJsonData, RGOptions } from 'relation-graph-vue3';
import LayoutFactory from '@/assets/js/graphvis.layout.min.js'
import { config } from '@/assets/defaultConfig.js'
@ -143,6 +154,46 @@ export default {
},
data() {
return {
chart: null,
words: [
{ name: '部署', value: 2 },
{ name: '运维', value: 2 },
{ name: '安全', value: 2 },
{ name: '测试', value: 2 },
{ name: '调试', value: 2 },
{ name: '日志', value: 2 },
{ name: '监控', value: 2 },
{ name: '性能', value: 2 },
{ name: '优化', value: 2 },
{ name: '缓存', value: 2 },
{ name: '架构', value: 3 },
{ name: '设计', value: 2 },
{ name: '需求', value: 2 },
{ name: '文档', value: 1 },
{ name: '会议', value: 1 },
{ name: '沟通', value: 1 },
{ name: '协作', value: 1 },
{ name: '脚本', value: 1 },
{ name: '自动化', value: 2 },
{ name: 'CI/CD', value: 2 },
{ name: '容器', value: 2 },
{ name: 'Docker', value: 2 },
{ name: 'Kubernetes', value: 2 },
{ name: '微服务', value: 3 },
{ name: 'API', value: 3 },
{ name: 'JSON', value: 1 },
{ name: 'HTTP', value: 2 },
{ name: '协议', value: 1 },
{ name: '加密', value: 1 },
{ name: '权限', value: 2 },
{ name: '登录', value: 2 },
{ name: '注册', value: 1 },
{ name: '用户', value: 2 },
{ name: '功能', value: 2 },
{ name: '模块', value: 1 }
],
getpoinName :"模糊综合评价方法",
// testoptions: {
// debug: true,
@ -193,9 +244,8 @@ export default {
defaultNodeWidth: 100,
defaultNodeHeight: 100,
toolBarDirection: 'h',
toolBarDirection: 'v',
toolBarPositionH: 'right',
toolBarPositionV: 'bottom',
// 使线
defaultLineShape: 1, // 2 = 线Bezier3 = 线
@ -273,8 +323,8 @@ export default {
defaultNodeColor: 'rgba(0, 206, 209, 1)',
lineLengths: 100,
defaultNodeFontSize: '20px', //
toolBarPositionH: 'right',
toolBarPositionV: 'top',
toolBarPositionH: 'center',
toolBarPositionV: 'bottom',
disableNodeClickEffect: true,
},
currentNode: {}, //
@ -363,6 +413,72 @@ export default {
}
},
methods: {
initChart() {
//
if (this.chart) {
this.chart.dispose()
}
// ECharts
this.chart = echarts.init(this.$refs.chart)
const option = {
tooltip: { show: true },
series: [
{
type: 'wordCloud',
shape: 'diamond', // 'circle' 'diamond'
sizeRange: [12, 40], // 12px60px
rotationRange: [0, 45], //
gridSize: 8, //
drawOutOfBound: false, //
layoutAnimation: true, //
left: 'center',
top: 'center',
width: '100%',
height: '100%',
data: this.words.map(item => ({
name: item.name,
value: item.value,
textStyle: { color: this.randomColor() }
})),
emphasis: {
focus: 'self',
textStyle: { textShadowBlur: 10, textShadowColor: '#333' }
},
//
minSize: 10, //
maxSize: 60, //
//
wordGap: 1, //
wordSizeRange: [10, 60], //
//
rotateStep: 45, //
// 便
backgroundColor: 'transparent'
}
],
backgroundColor: 'rgba(255, 255, 255, 0.21)'
}
this.chart.setOption(option)
},
randomColor() {
return `hsl(${Math.random() * 360}, 70%, 50%)`
},
handleResize() {
if (this.chart) {
this.chart.resize()
}
},
beforeDestroy() {
//
window.removeEventListener('resize', this.handleResize)
//
if (this.chart) {
this.chart.dispose()
this.chart = null
}
},
handleNodeClick(node) {
console.log(node);
},
@ -504,6 +620,7 @@ export default {
}
},
mounted() {
this.initChart()
this.getPointData()
getTitleBySamll().then((res)=>{
let data = res
@ -518,6 +635,7 @@ export default {
this.data1.push(data.zbMap)
this.data1.push(data.zhibMap)
})
},
}
</script>
@ -1095,4 +1213,33 @@ tr {
.el-tree--highlight-current {
background: no-repeat;
}
.container h3 {
margin: 0 0 10px 0;
font-size: 16px;
color: white;
text-align: center;
}
.container {
position: fixed;
bottom: 20px;
left:100px;
width: 400px; /* 增大宽度 */
height: 300px; /* 增大高度 */
background-color: transparent;
border: 1px solid #ddd;
border-radius: 12px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
padding: 12px;
z-index: 9999;
}
.chart-container {
width: 100%;
height: calc(100% - 42px); /* 调整标题高度 */
position: relative;
}
</style>

260
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyFileManageController.java

@ -275,6 +275,258 @@ 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);
//
// }
//
//
// }
// }
// }
// }
////
// }
//
//
// 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);
if (doc1 != null && doc2 != null) {
List<ZhyDoc> allDocs = test1Mapper.selectAllDoc1();
for (ZhyDoc doc : allDocs) {
if (doc.getDocTitle().equals(childValue)) {
doc.setDocParentId(doc1.getId());
String updateCql = "MATCH (doc:Doc {docId: '" + doc.getId() + "'}) " +
"SET doc.docParentId = '" + doc1.getId() + "' " +
"RETURN doc";
neo4jUtil.excuteCypherSql(updateCql);
}
}
// 插入文章
ZhyArticle article = new ZhyArticle();
article.setName(data.get("title"));
// article.setOpenUrl(data.get("urls"));
File file = new File(ARTICLE_PDF_DIR, article.getName()+".pdf");
System.out.println("文件路径: " + file.getAbsolutePath());
article.setLocalUrl(file.getAbsolutePath());
article.setAuthors(data.get("authors"));
article.setKeywords(data.get("keywords"));
article.setSummary(data.get("abstract"));
article.setUrls(data.get("urls"));
article.setSourceId(doc1.getId());
article.setSourceName(doc1.getDocTitle());
article.setTargetId(doc2.getId());
article.setTagertName(doc2.getDocTitle());
zhyArticleMapper.insertZhyArticle(article);
// 插入关系
ZhyDocRelation zz = new ZhyDocRelation();
zz.setRelationship("相关"); // 你可能需要从 CSV 中读取关系类型,或固定值
zz.setSource(doc1.getId());
zz.setTarget(doc2.getId());
zz.setSourceName(doc1.getDocTitle());
zz.setTargetName(doc2.getDocTitle());
zz.setCreateTime(new Date());
zz.setArticleId(article.getId());
System.out.println(zz);
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);
}
// 4. 批量创建 Neo4j 关系
List<ZhyDocRelation> listR = zhyDocRelationMapper.getAllRelation();
for (ZhyDocRelation rel : listR) {
String cql = "MATCH (a:Doc),(b:Doc) " +
"WHERE a.docId = '" + rel.getSource() + "' AND b.docId = '" + rel.getTarget() + "' " +
"CREATE (a)-[r:" + rel.getRelationship() + " {name: '" + rel.getRelationship() +"', DbId: '"+rel.getId()+ "'}]->(b) " +
"RETURN r";
neo4jUtil.excuteCypherSql(cql);
test1Mapper.updateGraphRelation(rel);
}
}
@PostMapping("/insertRelationByFile")
public AjaxResult insertRelationByFile(MultipartFile file) throws Throwable {
// 1. 校验文件是否为空
@ -357,6 +609,14 @@ public class ZhyFileManageController extends BaseController {
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);

87
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/FolderUploadController.java

@ -107,39 +107,88 @@ public class FolderUploadController {
// List<Map<String, String>> dataList = new ArrayList<>();
List<ZhyArticle> articles = new ArrayList<>();
ZhyArticle zhyArticle = null; // 当前正在构建的记录
System.out.println("有");
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(new FileInputStream(filePath), StandardCharsets.UTF_8))) {
String line;
ZhyArticle zhyArticle = null;
String currentField = null; // 当前字段:"authors", "agencies", "summary"
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) continue; // 跳过空行
if (line.isEmpty()) continue;
// ✅ 步骤1:检查前8个字符内是否有冒号(: 或 :)
int sepIndex = -1;
char separator = '\0';
String prefix = line.substring(0, Math.min(8, line.length())); // 前最多8个字符
if (prefix.contains(":")) {
sepIndex = prefix.indexOf(":");
separator = ':';
} else if (prefix.contains(":")) {
sepIndex = prefix.indexOf(":");
separator = ':';
}
if (line.startsWith("题名:")) {
if (zhyArticle != null) {
articles.add(zhyArticle);
}
// 开始一条新记录
zhyArticle = new ZhyArticle();
zhyArticle.setName(line.substring(3));
}else if (line.startsWith("作者:")) {
if (zhyArticle != null) {
zhyArticle.setAuthors(line.substring(3)); // 去掉"单位:"
// 判断是否是“字段行”(前8字符内有冒号)
if (sepIndex != -1) {
String fieldKey = line.substring(0, sepIndex).trim();
String value = line.substring(sepIndex + (separator == ':' ? 1 : 1)).trim();
// ✅ 只处理你关心的四个字段
if ("题名".equals(fieldKey)) {
if (zhyArticle != null) {
articles.add(zhyArticle);
}
zhyArticle = new ZhyArticle();
zhyArticle.setName(value);
currentField = null;
} else if ("作者".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setAuthors(value);
currentField = "authors";
}
} else if ("单位".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setAgencies(value);
currentField = "agencies";
}
} else if ("摘要".equals(fieldKey)) {
if (zhyArticle != null) {
zhyArticle.setSummary(value);
currentField = "summary";
}
}
} else if (line.startsWith("单位:")) {
if (zhyArticle != null) {
zhyArticle.setAgencies(line.substring(3)); // 去掉"单位:"
// ✅ 如果字段不在白名单内(如“中文刊名”),则:
// - 不处理
// - 不追加
// - 重置 currentField(防止后续行追加到错误字段)
else {
currentField = null; // 关键:断开与之前字段的联系
}
} else if (line.startsWith("摘要:")) {
if (zhyArticle != null) {
zhyArticle.setSummary(line.substring(3)); // 去掉"题名:"
}
// ✅ 普通行:不是字段行,追加到 currentField
else {
if (zhyArticle != null && currentField != null) {
if ("authors".equals(currentField)) {
String existing = zhyArticle.getAuthors();
zhyArticle.setAuthors((existing != null ? existing : "") + "\n" + line);
} else if ("agencies".equals(currentField)) {
String existing = zhyArticle.getAgencies();
zhyArticle.setAgencies((existing != null ? existing : "") + "\n" + line);
} else if ("summary".equals(currentField)) {
String existing = zhyArticle.getSummary();
zhyArticle.setSummary((existing != null ? existing : "") + "\n" + line);
}
}
// 如果 currentField == null,说明前面是未知字段,跳过
}
}
// 文件读完,别忘了把最后一条记录加上
// 添加最后一条记录
if (zhyArticle != null) {
articles.add(zhyArticle);
}

17
ruoyi-api/src/main/java/com/ruoyi/api/service/impl/BuildService.java

@ -193,23 +193,6 @@ public class BuildService {
}
//
}
// List<String> ids = new ArrayList<>();
// for (ZhyDocRelation rel : allRelation) {
// ids.add(String.valueOf(rel.getId()));
// }
// for (ZhyDocRelation rel : allRelation) {
// 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", "文件处理完成,共导入 " + dataList.size() + " 条数据");
}

Loading…
Cancel
Save