Browse Source

2025.1.20 新增实体

wzx
linsheng0116 1 year ago
parent
commit
b7573f3a59
  1. 8
      kcui/src/api/file.js
  2. 224
      kcui/src/view/Home.vue
  3. 1
      pom.xml
  4. 4
      src/main/java/com/main/woka/Common/util/KcInfo.java
  5. 3
      src/main/java/com/main/woka/Filter/SaTokenFilter.java
  6. 151
      src/main/java/com/main/woka/Web/Controller/KcTlFileController.java
  7. 2
      src/main/resources/Mapper/KcInfoRelationMapper.xml

8
kcui/src/api/file.js

@ -19,4 +19,12 @@ export function addFile(file, config = {}) {
data: formData,
...finalConfig
});
}
export function addNode(data) {
return request({
url: '/file/addNode',
method: 'post',
data:data
})
}

224
kcui/src/view/Home.vue

@ -8,6 +8,33 @@
<div id="graph-panel" style="width: 100%;height: 100%;"></div>
</div>
</div>
<!-- 弹窗 -->
<div v-if="isModalVisible" class="modal-overlay" @click.self="closeModal">
<div class="modal-content">
<h3>请输入分支内容</h3>
<label for="fileId">fileId:</label>
<input type="text" id="fileId" v-model="newBranchFileId" />
<label for="txtName">节点名称:</label>
<input type="text" id="txtName" v-model="newBranchContent" />
<label for="TxtValue">节点内容:</label>
<textarea id="TxtValue" v-model="newBranchValue"></textarea>
<label for="parentId">父级节点ID:</label>
<input type="text" id="parentId" v-model="newBranchParentId" />
<label for="relation">关系:</label>
<input type="text" id="relation" v-model="newBranchRelation"
@input="newBranchRelation = $event.target.value.replace(/[^a-zA-Z\u4e00-\u9fa5]/g, '')" />
<label for="level">层级:</label>
<input type="number" id="level" v-model="newBranchLevel" />
<button @click="addNewBranch">提交</button>
</div>
</div>
</div>
</template>
@ -16,6 +43,7 @@ import {getgraphInfo, test, userLogin} from "@/api/login";
import VisGraph from '@/assets/js/graphvis.min.20241008.js'
import LayoutFactory from '@/assets/js/graphvis.layout.min.js'
import {config} from '@/assets/defaultConfig.js'
import {addNode} from "@/api/file";
export default {
// eslint-disable-next-line vue/multi-word-component-names
@ -29,6 +57,17 @@ export default {
links: []
},
config,
visGraph: null, // VisGraph
isModalVisible: false,
newBranchContent: '',
selectedNode: null,
newBranchValue: '',
newBranchFileId: '',
newBranchLevel: null,
newBranchParentId: '',
newBranchRelation:''
}
},
methods:{
@ -65,10 +104,77 @@ export default {
// this.goCenter();
}
this.loading = false;
},
//
createGraph() {
this.visGraph = new VisGraph(document.getElementById('graph-panel'), this.config)
const configWithEvents = {
...this.config,
node: {
...this.config.node,
ondblClick: (event, node) => {
this.showPopup(node);
}
}
};
this.visGraph = new VisGraph(document.getElementById('graph-panel'), configWithEvents);
},
showPopup(node) {
this.selectedNode = node;
this.newBranchParentId = node.properties.docId;
this.newBranchLevel = node.properties.level - 1;
this.isModalVisible = true; //
},
closeModal() {
this.isModalVisible = false;
this.newBranchContent = '';
this.selectedNode = null;
},
async addNewBranch() {
const content = this.newBranchContent.trim();
const value = this.newBranchValue.trim();
const fileId = this.newBranchFileId.trim();
const relation = this.newBranchRelation.trim();
if (this.selectedNode && content && value) {
//
const data = {
fileId: fileId,
txtName: content,
TxtValue: value,
relation: relation,
parentId: this.newBranchParentId,
level: this.newBranchLevel
};
try {
await addNode(data);
//
const newNodeId = Date.now().toString(); // 使ID
const newNode = {
id: newNodeId,
label: content,
properties: { name: content, docId: newNodeId, level: this.newBranchLevel },
...this.getNodeStyle(this.newBranchLevel) //
};
const newLink = {
source: this.selectedNode.id,
target: newNodeId,
type: '',
};
this.graphData.nodes.push(newNode);
this.graphData.links.push(newLink);
//
this.visGraph.drawData(this.graphData);
this.reLayout();
this.closeModal(); //
} catch (error) {
console.error('Failed to add new branch:', error);
alert('Failed to add new branch. Please try again.');
}
}
},
//
reLayout(alpha) {
@ -123,103 +229,15 @@ export default {
var allOne = nodeList[0].docId
for (let a = 0; a < nodeList.length; a++) {
if (nodeList[a].group == '0') {
const aaa = {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne}
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: aaa,
size: 450,
color: '227,203,0',
font: 'normal 70px Arial',
fontColor: '255,255,255'
})
}
if (nodeList[a].group == '1') {
const aaa = {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne}
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: aaa,
size: 350,
width:350,
height:300,
color: '47,47,230',
font: 'normal 68px Arial',
fontColor: '255,255,255'
})
}
if (nodeList[a].group == '2') {
const aaa = {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne}
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: aaa,
size: 300,
width:300,
height:250,
color: '255,138,0',
font: 'normal 50px Arial',
fontColor: '255,255,255'
})
}
if (nodeList[a].group == '3') {
const aaa = {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne}
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: aaa,
size: 250,
width:250,
height:250,
color: '30,255,0',
font: 'normal 40px Arial',
fontColor: '0,0,0'
})
}
if (nodeList[a].group == '4') {
const aaa = {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne}
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: aaa,
size: 200,
width:200,
height:200,
color: '248,143,248',
font: 'normal 32px Arial',
fontColor: '255,255,255'
})
}
if (nodeList[a].group == '5') {
const aaa = {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne}
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: aaa,
size: 150,
width:150,
height:150,
color: '65,154,255',
font: 'normal 30px Arial',
fontColor: '255,255,255'
})
}
if (nodeList[a].group == '6') {
const aaa = {name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne}
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: aaa,
size: 100,
width:100,
height:100,
color: '0,228,255',
font: 'normal 28px Arial',
fontColor: '0,0,0'
})
}
const group = parseInt(nodeList[a].group, 10);
const style = this.getNodeStyle(group);
nodes.push({
id: nodeList[a].id,
label: nodeList[a].name,
properties: { name: nodeList[a].name, docId: nodeList[a].docId, parent: allOne },
...style // style
});
}
@ -242,7 +260,19 @@ export default {
}
this.drawGraphData();
},
getNodeStyle(group) {
const styles = [
{ size: 450, color: '227,203,0', font: 'normal 70px Arial', fontColor: '255,255,255' },
{ size: 350, width: 350, height: 300, color: '47,47,230', font: 'normal 68px Arial', fontColor: '255,255,255' },
{ size: 300, width: 300, height: 250, color: '255,138,0', font: 'normal 50px Arial', fontColor: '255,255,255' },
{ size: 250, width: 250, height: 250, color: '30,255,0', font: 'normal 40px Arial', fontColor: '0,0,0' },
{ size: 200, width: 200, height: 200, color: '248,143,248', font: 'normal 32px Arial', fontColor: '255,255,255' },
{ size: 150, width: 150, height: 150, color: '65,154,255', font: 'normal 30px Arial', fontColor: '255,255,255' },
{ size: 100, width: 100, height: 100, color: '0,228,255', font: 'normal 28px Arial', fontColor: '0,0,0' }
];
return styles[group] || {};
},
doLogin(){
userLogin().then((res)=>{
console.log(res);

1
pom.xml

@ -150,6 +150,7 @@
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>

4
src/main/java/com/main/woka/Common/util/KcInfo.java

@ -18,13 +18,11 @@ public class KcInfo {
private Long isGraph;
private Long level;
private Long groupId;
private Integer fileId;
public Integer getFileId() {return fileId;}
public void setFileId(Integer fileId) {this.fileId = fileId;}
private Integer fileId;
public Long getId() {
return id;
}

3
src/main/java/com/main/woka/Filter/SaTokenFilter.java

@ -4,7 +4,6 @@ import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ -21,7 +20,7 @@ public class SaTokenFilter implements WebMvcConfigurer {
// SaRouter.match("/admin/**", r -> StpUtil.checkRoleOr("admin", "super-admin"));
// // 权限校验 -- 不同模块校验不同权限
// SaRouter.match("/user/**", r -> StpUtil.checkPermission("user"));
})).excludePathPatterns("/user/doLogin"); //开放
})).excludePathPatterns("/user/doLogin").excludePathPatterns("/file/**"); //开放
}
}

151
src/main/java/com/main/woka/Web/Controller/KcTlFileController.java

@ -1,25 +1,27 @@
package com.main.woka.Web.Controller;
import com.main.woka.Common.core.AjaxResult;
import com.main.woka.Common.util.KcTlFile;
import com.main.woka.Common.util.Neo4jUtil;
import com.main.woka.Common.util.WebSocket;
import com.main.woka.Common.util.*;
import com.main.woka.Web.Mapper.KcFileMapper;
import com.main.woka.Web.Mapper.KcInfoRelationMapper;
import com.main.woka.Web.Service.impl.KcTlFileServiceImpl;
import com.main.woka.Web.Service.impl.PdfUtil;
import org.neo4j.driver.v1.StatementResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;
@RestController
@RequestMapping("/file")
@ -113,6 +115,147 @@ public class KcTlFileController extends BaseController {
return subDir.getPath();
}
@PostMapping("/addNode")
public AjaxResult addNode(@RequestBody Map<String, String> requestBody) throws IOException {
System.out.println(requestBody);
Integer fileId = Integer.valueOf(requestBody.get("fileId"));
String txtName = requestBody.get("txtName");
String TxtValue = requestBody.get("TxtValue");
String relation = requestBody.get("relation");
Long parentId = Long.valueOf(requestBody.get("parentId"));
Long level = Long.valueOf(requestBody.get("level"));
KcTlFile kcTlFile = kcFileMapper.getFileById(fileId);
String url = kcTlFile.getFileUrl();
int lastBackslashIndex = url.lastIndexOf('\\');
String pathPart = url.substring(0, lastBackslashIndex + 1);
String result = pathPart + "wordSplitter";
String txtUrl = createTxtFile(result, txtName, TxtValue);
KcInfo kcInfo = new KcInfo();
kcInfo.setFileId(fileId);
kcInfo.setCreateTime(new Date());
kcInfo.setTwUrl(txtUrl);
kcInfo.setName(txtName);
kcInfo.setParentId(parentId);
kcInfo.setLevel(level);
kcInfo.setCreateTime(new Date());
kcInfo.setCreateBy(Long.valueOf(String.valueOf(getUserId())));
kcFileMapper.insertDoc(kcInfo);
//创建图谱
String cql = "create (doc: Doc{";
List<Map> listNew = new ArrayList<>();
if (kcInfo.getId() != null) {
Map<String, String> bb = new HashMap<>();
bb.put("key", "docId");
bb.put("value", String.valueOf(kcInfo.getId()));
listNew.add(bb);
}
if (kcInfo.getName() != null && !kcInfo.getName().equals("")) {
Map<String, String> bb = new HashMap<>();
bb.put("key", "name");
bb.put("value", String.valueOf(kcInfo.getName()));
listNew.add(bb);
}
if (kcInfo.getLevel() != null) {
Map<String, String> bb = new HashMap<>();
if (kcInfo.getLevel() == 1) {
bb.put("key", "leve");
bb.put("value", "leve1");
}
if (kcInfo.getLevel() == 2) {
bb.put("key", "leve");
bb.put("value", "leve2");
}
if (kcInfo.getLevel() == 3) {
bb.put("key", "leve");
bb.put("value", "leve3");
}
if (kcInfo.getLevel() == 4) {
bb.put("key", "leve");
bb.put("value", "leve4");
}
if (kcInfo.getLevel() == 5) {
bb.put("key", "leve");
bb.put("value", "leve5");
}
if (kcInfo.getLevel() == 6) {
bb.put("key", "leve");
bb.put("value", "leve6");
}
listNew.add(bb);
}
for (int a = 0; a < listNew.size(); a++) {
if (listNew.get(a).size() > 1) {
if (a == 0) {
cql = cql + listNew.get(a).get("key") + ":'" + listNew.get(a).get("value") + "'";
} else if (a == (listNew.size() - 1)) {
cql = cql + "," + listNew.get(a).get("key") + ":'" + listNew.get(a).get("value") + "'})";
} else {
cql = cql + "," + listNew.get(a).get("key") + ":'" + listNew.get(a).get("value") + "'";
}
} else {
cql = cql + listNew.get(a).get("key") + ":'" + listNew.get(a).get("value") + "'}) return doc";
}
}
StatementResult result1 = neo4jUtil.excuteCypherSql(cql);
int yy = kcFileMapper.updateGraphStatus(kcInfo.getId());
//创建关系
KcInfoRelation zz = new KcInfoRelation();
zz.setRelation(relation);
zz.setSourceId(parentId);
zz.setTargetId(kcInfo.getId());
//查询上级
KcInfo zz1 = new KcInfo();
zz1.setId(parentId);
KcInfo oldDoc = kcFileMapper.selectDocById(zz1);
zz.setSourceName(oldDoc.getName());
zz.setTargetName(txtName);
zz.setCreateTime(new Date());
kcInfoRelationMapper.insertKcRelationship(zz);
//创建图谱
String cqr = "MATCH (a:Doc),(b:Doc) WHERE a.docId = '" + zz.getSourceId() + "' AND b.docId = '" + zz.getTargetId() + "'CREATE (a)-[r:" + zz.getRelation() + "] -> (b) RETURN r";
StatementResult result2 = neo4jUtil.excuteCypherSql(cqr);
zz.setIsGraph(1l);
int yy1 = kcInfoRelationMapper.updateKcRelationship(zz);
return AjaxResult.success();
}
public String createTxtFile(String url, String txtName, String txtValue) {
String directory = url;
String filePath = Paths.get(directory, txtName).toString() + ".txt";
try (FileWriter writer = new FileWriter(filePath)) {
writer.write(txtValue);
System.out.println("File created successfully at: " + filePath);
} catch (IOException e) {
System.err.println("An error occurred while creating the file.");
e.printStackTrace();
}
return filePath;
}
}

2
src/main/resources/Mapper/KcInfoRelationMapper.xml

@ -96,7 +96,7 @@
<trim prefix="SET" suffixOverrides=",">
<if test="relation != null and relation != ''">relation = #{relation},</if>
<if test="sourceId != null">source_id = #{sourceId},</if>
<if test="targetId != null">targe_id = #{targetId},</if>
<if test="targetId != null">target_id = #{targetId},</if>
<if test="isGraph != null">is_graph = #{isGraph},</if>
</trim>
where id = #{id}

Loading…
Cancel
Save