main
liu 1 year ago
parent 453bb5f60e
commit 364d7d23d5

@ -1,24 +0,0 @@
package com.supervision.config;
import io.minio.MinioClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MinioConfig {
/**
* JavaMinioClient
*/
@Bean
@ConditionalOnProperty(prefix = "minio",name = "url")
public MinioClient minioClient(MinioProperties minioProperties) {
return MinioClient.builder().endpoint(minioProperties.getUrl())
.credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
.build();
}
}

@ -1,19 +0,0 @@
package com.supervision.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "minio")
public class MinioProperties {
private String url;
private String accessKey;
private String secretKey;
private String bucketName;
}

@ -43,7 +43,7 @@ public class WebConfig implements WebMvcConfigurer {
paths.add("/favicon.ico");
paths.add("/user/login");
// 开发环境,放开不校验token.每次修改这里需要重启(热部署不行)
// paths.add("/**");
paths.add("/**");
return paths;
}

@ -1,95 +0,0 @@
package com.supervision.util;
import com.supervision.config.MinioProperties;
import io.minio.*;
import io.minio.http.Method;
import lombok.extern.slf4j.Slf4j;
import java.io.InputStream;
import java.util.UUID;
@Slf4j
public class MinioUtil {
private static final MinioClient minioClient = SpringBeanUtil.getBean(MinioClient.class);
private static final String bucketName = SpringBeanUtil.getBean(MinioProperties.class).getBucketName();
static {
try {
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
log.info("未找到bucket,自动建立");
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*
*/
public static String uploadFile(InputStream stream) throws Exception {
ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(UUID.randomUUID().toString())
.stream(stream, stream.available(), -1).build());
return objectWriteResponse.object();
}
/**
*
* @param stream
* @param contentType
* @return id
* @throws Exception
*/
public static String uploadFile(InputStream stream,String contentType) throws Exception {
ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(UUID.randomUUID().toString())
.stream(stream, stream.available(), -1).contentType(contentType).build());
return objectWriteResponse.object();
}
/**
*
*/
public static InputStream download(String fileId) throws Exception {
return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileId).build());
}
/**
*
*/
public static void deleteObject(String fileId) throws Exception {
minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(fileId).build());
}
/**
*
*
* @Param: [bucket, objectName]
* @return: java.lang.String
* @Author: MrFugui
* @Date: 2021/11/15
*/
public static String getObjectInfo(String fileId) throws Exception {
return minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(fileId).build()).toString();
}
/**
* HTTP GETpresigned URL/URL使
*
* @Param: [bucketName, objectName, expires]
* @return: java.lang.String
* @Author: MrFugui
* @Date: 2021/11/15
*/
public static String getPresignedObjectUrl(String bucketName, String objectName, Integer expires) throws Exception {
GetPresignedObjectUrlArgs build = GetPresignedObjectUrlArgs
.builder().bucket(bucketName).object(objectName).expiry(expires).method(Method.GET).build();
return minioClient.getPresignedObjectUrl(build);
}
}

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.supervision</groupId>
<artifactId>KBQA</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>kbqa-graph</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>knowledge-report</name>
<dependencies>
<dependency>
<groupId>com.supervision</groupId>
<artifactId>kbqa-common</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.nebula-contrib</groupId>
<artifactId>ngbatis</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,13 @@
package com.supervision;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.supervision.**","org.nebula"})
public class KnowledgeGraphApplication {
public static void main(String[] args) {
SpringApplication.run(KnowledgeGraphApplication.class, args);
}
}

@ -0,0 +1,26 @@
package com.supervision.config;
// Copyright (c) 2022 All project authors. All rights reserved.
//
// This source code is licensed under Apache 2.0 License.
import org.nebula.contrib.ngbatis.PkGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*
* @author yeweicheng
* @since 2022-06-14 12:32
* <br>Now is history!
*/
@Configuration
public class PkGeneratorConfig {
@Bean
public PkGenerator pkGenerator() {
return new SnowflakePKGenerator();
}
}

@ -0,0 +1,16 @@
package com.supervision.config;
import cn.hutool.core.util.IdUtil;
import org.nebula.contrib.ngbatis.PkGenerator;
public class SnowflakePKGenerator implements PkGenerator {
@Override
@SuppressWarnings("all")
public <T> T generate(String tagName, Class<T> pkType) {
if (pkType == String.class) {
return (T) IdUtil.getSnowflakeNextIdStr();
}
return (T) Long.valueOf(IdUtil.getSnowflakeNextIdStr());
}
}

@ -0,0 +1,32 @@
package com.supervision.controller;
import com.supervision.ngbatis.dao.ItemBranchDao;
import com.supervision.ngbatis.domain.ItemBranch;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("test")
@RequiredArgsConstructor
public class TestController {
@Resource
private ItemBranchDao itemBranchDao;
@GetMapping("hello")
public void hello() {
ItemBranch itemBranch = new ItemBranch();
itemBranch.setItemName("退休");
itemBranchDao.insert(itemBranch);
}
}

@ -0,0 +1,9 @@
package com.supervision.ngbatis.dao;
import com.supervision.ngbatis.domain.ItemBranch;
import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic;
public interface ItemBranchDao extends NebulaDaoBasic<ItemBranch,String> {
}

@ -0,0 +1,17 @@
package com.supervision.ngbatis.domain;
import lombok.Data;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@Table(name = "itemBranchTag")
public class ItemBranch {
@Id
private String id;
private String itemName;
}

@ -0,0 +1,102 @@
server:
port: 9810
servlet:
context-path: /knowledge-graph
undertow:
# HTTP post内容的最大大小。当值为-1时默认值为大小是无限的
max-http-post-size: -1
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
# 每块buffer的空间大小,越小的空间被利用越充分
buffer-size: 512
# 是否分配的直接内存
direct-buffers: true
spring:
profiles:
active: dev
application:
name: knowledge-graph
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.10.137:3306/knowledge_report?useUnicode=true&characterEncoding=utf-8&useSSL=true&nullCatalogMeansCurrent=true&serverTimezone=GMT%2B8
username: root
password: '123456'
initial-size: 5 # 初始化大小
min-idle: 10 # 最小连接数
max-active: 20 # 最大连接数
max-wait: 60000 # 获取连接时的最大等待时间
min-evictable-idle-time-millis: 300000 # 一个连接在池中最小生存的时间,单位是毫秒
time-between-eviction-runs-millis: 60000 # 多久才进行一次检测需要关闭的空闲连接,单位是毫秒
filters: stat,wall # 配置扩展插件stat-监控统计log4j-日志wall-防火墙防止SQL注入去掉后监控界面的sql无法统计
validation-query: SELECT 1 # 检测连接是否有效的 SQL语句为空时以下三个配置均无效
test-on-borrow: true # 申请连接时执行validationQuery检测连接是否有效默认true开启后会降低性能
test-on-return: true # 归还连接时执行validationQuery检测连接是否有效默认false开启后会降低性能
test-while-idle: true # 申请连接时如果空闲时间大于timeBetweenEvictionRunsMillis执行validationQuery检测连接是否有效默认false建议开启不影响性能
stat-view-servlet:
enabled: false # 是否开启 StatViewServlet
filter:
stat:
enabled: true # 是否开启 FilterStat默认true
log-slow-sql: true # 是否开启 慢SQL 记录默认false
slow-sql-millis: 5000 # 慢 SQL 的标准,默认 3000单位毫秒
merge-sql: false # 合并多个连接池的监控数据默认false
redis:
host: 192.168.10.137
port: 6379
password: 123456
minio:
url: http://192.168.10.137:9002
accessKey: admin
secretKey: 12345678
bucketName: kbqa-dev
mybatis-plus:
mapper-locations: classpath*:mapper/**/*.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
nebula:
ngbatis:
# ^v1.1.2
# 连接使用 nebula-java 中的 SessionPool
use-session-pool: true
# 填入 graphd 的 ip 和端口号,下面仅供参考
hosts: 192.168.10.137:9669
# 连接图数据库所用的用户名
username: root
# 连接图数据库所用的密码
password: 123456
# 所要连接的图数据库图空间名
space: kbqa
# 连接池配置
pool-config:
# 连接池中最小空闲连接数
min-conns-size: 0
# 连接池中最大空闲连接数
max-conns-size: 10
# 客户端同服务端建立连接的超时时间设置,单位为 ms超过设定时间未建立起连接则报错
timeout: 0
# 连接空闲时间,为 0 表示连接永不删除,单位为 ms
idle-time: 0
# 连接池检测空闲连接的时间间隔,为 -1 表示不进行检测
interval-idle: -1
# 连接等候时间,超过则不再等候连接
wait-time: 0
# 集群允许最小的服务可用率1.0 表示为所有机器 graphd 可用0.25 表示集群中 1/4 机器可用即可
min-cluster-health-rate: 1.0
# 是否允许 SSL 连接,目前暂不支持
enable-ssl: false
cql:
parser:
# 更换开发者自定义的 xml 所在位置
mapper-locations: nebulaMapper/**/*.xml # 默认为 mapper/**/*.xml
logging:
level:
org.nebula.contrib: DEBUG

@ -0,0 +1,3 @@
<mapper namespace="com.supervision.ngbatis.dao.ItemBranchDao">
</mapper>

@ -21,26 +21,8 @@ public class TestController {
return "OK";
}
public static void main(String[] args) {
// 创建 Trie 对象
Trie trie = Trie.builder()
.addKeyword("果果")
.addKeyword("香蕉")
.build();
// 需要匹配的中文文本
String text = "我喜欢吃苹果和香蕉,水果是我的最爱。";
// 在中文文本中查找匹配关键词
Collection<Emit> emits = trie.parseText(text);
// 输出匹配结果
for (Emit emit : emits) {
System.out.println("在文本中找到关键词 '" + emit.getKeyword() + "',位置:" + emit.getStart());
}
}
}

@ -3,6 +3,9 @@ package com.supervision.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.tokenizer.Result;
import cn.hutool.extra.tokenizer.TokenizerEngine;
import cn.hutool.extra.tokenizer.TokenizerUtil;
import cn.hutool.json.JSONUtil;
import com.supervision.exception.BusinessException;
import com.supervision.util.TokenUtil;
@ -39,4 +42,5 @@ public class UserController {
return null;
}
}

@ -20,6 +20,7 @@
<module>kbqa-report</module>
<module>kbqa-common</module>
<module>kbqa-model</module>
<module>kbqa-graph</module>
</modules>
<properties>

Loading…
Cancel
Save