Compare commits

...

2 Commits

Author SHA1 Message Date
e132958d1b 修改项目名称 2025-06-06 10:44:22 +08:00
51eea73f98 修改项目名称 2025-06-06 10:14:22 +08:00
32 changed files with 142 additions and 73 deletions

1
.gitignore vendored
View File

@ -35,3 +35,4 @@ build/
### Mac OS ###
.DS_Store
/knowledge-base-server-log/

85
config/mysql/init.txt Normal file
View File

@ -0,0 +1,85 @@
CREATE DATABASE IF NOT EXISTS kbase DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE kbase;
-- 1. 用户基础表
CREATE TABLE IF NOT EXISTS user (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '用户ID,主键',
username VARCHAR(64) NOT NULL UNIQUE COMMENT '登录用户名,唯一',
password VARCHAR(128) NOT NULL COMMENT '用户密码(建议加密存储)',
add_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
) COMMENT='用户基础表';
-- 2. 角色表
CREATE TABLE IF NOT EXISTS role (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '角色ID',
role_code VARCHAR(64) NOT NULL UNIQUE COMMENT '角色编码(如 admin/user/guest)',
role_name VARCHAR(64) NOT NULL COMMENT '角色名称',
add_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
) COMMENT='系统角色表';
-- 3. 用户-角色关联表
CREATE TABLE IF NOT EXISTS user_role (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
user_id BIGINT NOT NULL COMMENT '用户ID',
role_id BIGINT NOT NULL COMMENT '角色ID',
add_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_user_id(user_id),
INDEX idx_role_id(role_id)
) COMMENT='用户与角色关联表';
-- 4. 文件表
CREATE TABLE IF NOT EXISTS file (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '文件ID',
file_name VARCHAR(255) NOT NULL COMMENT '文件名或路径',
file_path VARCHAR(512) NOT NULL COMMENT '存储路径',
add_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
) COMMENT='知识库文件表';
-- 5. 角色-文件可见规则表(适合批量规则分配权限)
CREATE TABLE IF NOT EXISTS role_file_rule (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
role_id BIGINT NOT NULL COMMENT '角色ID',
file_pattern VARCHAR(255) NOT NULL COMMENT '可访问文件名/路径模式(如前缀、正则)',
remark VARCHAR(255) COMMENT '规则说明',
add_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_role_id(role_id)
) COMMENT='角色-文件可访问规则表';
-- 6. 用户token表
CREATE TABLE IF NOT EXISTS user_token (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键,自增',
user_id BIGINT NOT NULL COMMENT '用户ID,业务逻辑关联user表',
token VARCHAR(128) NOT NULL UNIQUE COMMENT '用户登录token',
login_at BIGINT NOT NULL COMMENT '登录时间(毫秒时间戳)',
expired_at BIGINT NOT NULL COMMENT '过期时间(毫秒时间戳)',
add_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_user_id(user_id),
INDEX idx_token(token)
) COMMENT='用户登录Token表';
-- 7. 用户-文件直接授权关联表
CREATE TABLE IF NOT EXISTS user_file (
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
user_id BIGINT NOT NULL COMMENT '用户ID',
file_id BIGINT NOT NULL COMMENT '文件ID',
add_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
INDEX idx_user_id(user_id),
INDEX idx_file_id(file_id),
UNIQUE INDEX uniq_user_file(user_id, file_id)
) COMMENT='用户-文件直接授权关联表(用于特殊文件个别授权)';

View File

@ -4,9 +4,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>luke.micro.saas</groupId>
<artifactId>doc-parser-server</artifactId>
<artifactId>knowledge-base-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>doc-parser-server</name>
<name>knowledge-base-server</name>
<description>文档资源解析服务</description>
<properties>
@ -329,7 +329,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.doc.parser.DocParserApplication</mainClass>
<mainClass>com.knowledge.base.KnowledgeBaseApplication</mainClass>
</configuration>
<executions>
<execution>

View File

@ -1,4 +1,4 @@
package com.doc.parser;
package com.knowledge.base;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -9,10 +9,10 @@ import org.springframework.scheduling.annotation.EnableScheduling;
*/
@EnableScheduling
@SpringBootApplication
public class DocParserApplication {
public class KnowledgeBaseApplication {
public static void main(String[] args) {
SpringApplication.run(DocParserApplication.class, args);
SpringApplication.run(KnowledgeBaseApplication.class, args);
}
}

View File

@ -1,4 +1,4 @@
package com.doc.parser.application.anno;
package com.knowledge.base.application.anno;
import java.lang.annotation.*;

View File

@ -1,4 +1,4 @@
package com.doc.parser.application.aspect;
package com.knowledge.base.application.aspect;
import cn.hutool.json.JSONUtil;
import org.aspectj.lang.ProceedingJoinPoint;
@ -21,7 +21,7 @@ import java.lang.reflect.Method;
public class OperationLogAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(OperationLogAspect.class);
@Around("@annotation(com.doc.parser.application.anno.OperationLog)")
@Around("@annotation(com.knowledge.base.application.anno.OperationLog)")
public Object logOperation(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();

View File

@ -1,4 +1,4 @@
package com.doc.parser.application.enums;
package com.knowledge.base.application.enums;
/**
* @Author: luke ye

View File

@ -1,4 +1,4 @@
package com.doc.parser.application.enums;
package com.knowledge.base.application.enums;
/**
* @author Luke.ye

View File

@ -1,4 +1,4 @@
package com.doc.parser.application.enums;
package com.knowledge.base.application.enums;
/**
* @author Luke.ye

View File

@ -1,4 +1,4 @@
package com.doc.parser.application.exceptions;
package com.knowledge.base.application.exceptions;
/**
* @author Luke.ye

View File

@ -1,6 +1,6 @@
package com.doc.parser.application.filter;
package com.knowledge.base.application.filter;
import com.doc.parser.infrastructure.north.controller.UserController;
import com.knowledge.base.infrastructure.north.controller.UserController;
import org.springframework.stereotype.Component;
import javax.servlet.*;

View File

@ -1,9 +1,9 @@
package com.doc.parser.application.filter;
package com.knowledge.base.application.filter;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.doc.parser.application.enums.MDCKeyEnum;
import com.doc.parser.infrastructure.config.DynamicConfig;
import com.knowledge.base.application.enums.MDCKeyEnum;
import com.knowledge.base.infrastructure.config.DynamicConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

View File

@ -1,4 +1,4 @@
package com.doc.parser.application.filter;
package com.knowledge.base.application.filter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@ -8,7 +8,7 @@ import javax.servlet.ServletResponse;
import java.io.IOException;
import cn.hutool.core.util.IdUtil;
import com.doc.parser.application.enums.MDCKeyEnum;
import com.knowledge.base.application.enums.MDCKeyEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.ThreadContext;

View File

@ -1,4 +1,4 @@
package com.doc.parser.domain.enums;
package com.knowledge.base.domain.enums;
/**
* @author Luke.ye

View File

@ -1,4 +1,6 @@
package com.doc.parser.domain.iface;
package com.knowledge.base.domain.iface;
import com.knowledge.base.domain.enums.DocTypeEnum;
/**
* @author Luke.ye
@ -8,7 +10,7 @@ public interface DocumentImporter {
void importDocuments() throws Exception;
/**
* {@link com.doc.parser.domain.enums.DocTypeEnum}
* {@link DocTypeEnum}
* @return
*/
String getType();

View File

@ -1,7 +1,7 @@
package com.doc.parser.domain.impl;
package com.knowledge.base.domain.impl;
import com.doc.parser.domain.iface.DocumentImporter;
import com.doc.parser.infrastructure.util.LocalCacheUtil;
import com.knowledge.base.domain.iface.DocumentImporter;
import com.knowledge.base.infrastructure.util.LocalCacheUtil;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;

View File

@ -1,4 +1,4 @@
package com.doc.parser.domain.impl;
package com.knowledge.base.domain.impl;
/**
* @author Luke.ye

View File

@ -1,22 +1,12 @@
package com.doc.parser.domain.impl;
package com.knowledge.base.domain.impl;
import com.doc.parser.domain.enums.DocTypeEnum;
import com.doc.parser.domain.iface.DocumentImporter;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.knowledge.base.domain.enums.DocTypeEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.HashMap;
import java.util.Map;
/**
* @author Luke.ye

View File

@ -1,22 +1,14 @@
package com.doc.parser.domain.impl;
package com.knowledge.base.domain.impl;
import com.doc.parser.domain.enums.DocTypeEnum;
import com.doc.parser.domain.iface.DocumentImporter;
import com.knowledge.base.domain.enums.DocTypeEnum;
import org.springframework.stereotype.Component;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.util.*;
/**
* @author Luke.ye

View File

@ -1,6 +1,6 @@
package com.doc.parser.domain.impl;
package com.knowledge.base.domain.impl;
import com.doc.parser.domain.enums.DocTypeEnum;
import com.knowledge.base.domain.enums.DocTypeEnum;
import org.springframework.stereotype.Component;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

View File

@ -1,7 +1,7 @@
package com.doc.parser.domain.schedule;
package com.knowledge.base.domain.schedule;
import com.doc.parser.domain.iface.DocumentImporter;
import com.doc.parser.infrastructure.config.DynamicConfig;
import com.knowledge.base.domain.iface.DocumentImporter;
import com.knowledge.base.infrastructure.config.DynamicConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;

View File

@ -1,4 +1,4 @@
package com.doc.parser.infrastructure.config;
package com.knowledge.base.infrastructure.config;
/**
* @author Luke.ye

View File

@ -1,4 +1,4 @@
package com.doc.parser.infrastructure.config;
package com.knowledge.base.infrastructure.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;

View File

@ -1,4 +1,4 @@
package com.doc.parser.infrastructure.config;
package com.knowledge.base.infrastructure.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;

View File

@ -1,4 +1,4 @@
package com.doc.parser.infrastructure.config;
package com.knowledge.base.infrastructure.config;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

View File

@ -1,6 +1,6 @@
package com.doc.parser.infrastructure.north.controller;
package com.knowledge.base.infrastructure.north.controller;
import com.doc.parser.domain.iface.DocumentImporter;
import com.knowledge.base.domain.iface.DocumentImporter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

View File

@ -1,9 +1,9 @@
package com.doc.parser.infrastructure.north.controller;
package com.knowledge.base.infrastructure.north.controller;
import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONUtil;
import com.doc.parser.infrastructure.north.dto.SearchReq;
import com.doc.parser.infrastructure.util.LocalCacheUtil;
import com.knowledge.base.infrastructure.north.dto.SearchReq;
import com.knowledge.base.infrastructure.util.LocalCacheUtil;
import com.google.common.collect.Maps;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
@ -14,7 +14,6 @@ import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,8 +1,8 @@
package com.doc.parser.infrastructure.north.controller;
package com.knowledge.base.infrastructure.north.controller;
import cn.hutool.extra.spring.SpringUtil;
import com.doc.parser.infrastructure.config.ConstantConfig;
import com.doc.parser.infrastructure.config.DynamicConfig;
import com.knowledge.base.infrastructure.config.ConstantConfig;
import com.knowledge.base.infrastructure.config.DynamicConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

View File

@ -1,7 +1,7 @@
package com.doc.parser.infrastructure.north.dto;
package com.knowledge.base.infrastructure.north.dto;
import cn.hutool.core.bean.BeanUtil;
import com.doc.parser.application.enums.ErrorCodeEnum;
import com.knowledge.base.application.enums.ErrorCodeEnum;
import java.io.Serializable;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package com.doc.parser.infrastructure.north.dto;
package com.knowledge.base.infrastructure.north.dto;
import java.io.Serializable;
import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package com.doc.parser.infrastructure.util;
package com.knowledge.base.infrastructure.util;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

View File

@ -2,8 +2,8 @@
<Configuration status="INFO">
<!-- 使用相对路径指定日志目录 -->
<Properties>
<Property name="logDir">doc-parser-server-log</Property>
<Property name="appName">doc-parser-server</Property>
<Property name="logDir">knowledge-base-server-log</Property>
<Property name="appName">knowledge-base-server</Property>
</Properties>
<!-- 文件日志输出(滚动策略)-->