Compare commits

..

No commits in common. "e132958d1be1a858ac3ad43f40f1a8d0661c6425" and "bbe5b6ccab777ba3754181038dc3fe3be6fc83e1" have entirely different histories.

32 changed files with 73 additions and 142 deletions

1
.gitignore vendored
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,22 @@
package com.knowledge.base.domain.impl; package com.doc.parser.domain.impl;
import com.knowledge.base.domain.enums.DocTypeEnum; 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 org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.*; import java.nio.file.*;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author Luke.ye * @author Luke.ye

View File

@ -1,14 +1,22 @@
package com.knowledge.base.domain.impl; package com.doc.parser.domain.impl;
import com.knowledge.base.domain.enums.DocTypeEnum; import com.doc.parser.domain.enums.DocTypeEnum;
import com.doc.parser.domain.iface.DocumentImporter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper; 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 org.springframework.beans.factory.annotation.Value;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
import java.util.*;
/** /**
* @author Luke.ye * @author Luke.ye

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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