Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
K
know-base
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
张京坤
know-base
Commits
34b0fb4d
提交
34b0fb4d
authored
1月 10, 2024
作者:
obcy
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
8452edd6
08b80d1a
全部展开
显示空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
650 行增加
和
36 行删除
+650
-36
RedisConfig.java
src/main/java/com/zzsn/knowbase/config/RedisConfig.java
+32
-0
KnowInterceptor.java
...com/zzsn/knowbase/config/interceptor/KnowInterceptor.java
+12
-12
Constants.java
src/main/java/com/zzsn/knowbase/constant/Constants.java
+10
-1
KnowledgeController.java
...ava/com/zzsn/knowbase/controller/KnowledgeController.java
+42
-8
KnowFile.java
src/main/java/com/zzsn/knowbase/entity/KnowFile.java
+2
-1
Knowledge.java
src/main/java/com/zzsn/knowbase/entity/Knowledge.java
+6
-1
DocumentType.java
src/main/java/com/zzsn/knowbase/enums/DocumentType.java
+25
-0
IKnowledgeService.java
...ain/java/com/zzsn/knowbase/service/IKnowledgeService.java
+5
-2
ILocalFileService.java
...ain/java/com/zzsn/knowbase/service/ILocalFileService.java
+43
-0
KnowledgeServiceImpl.java
.../com/zzsn/knowbase/service/impl/KnowledgeServiceImpl.java
+0
-0
LocalFileServiceImpl.java
.../com/zzsn/knowbase/service/impl/LocalFileServiceImpl.java
+151
-0
RedisUtil.java
src/main/java/com/zzsn/knowbase/util/RedisUtil.java
+0
-0
DefaultFileUtility.java
.../java/com/zzsn/knowbase/util/file/DefaultFileUtility.java
+202
-0
FileUtility.java
src/main/java/com/zzsn/knowbase/util/file/FileUtility.java
+41
-0
KnowledgeParam.java
src/main/java/com/zzsn/knowbase/vo/KnowledgeParam.java
+28
-5
KnowledgeVO.java
src/main/java/com/zzsn/knowbase/vo/KnowledgeVO.java
+12
-2
application.yml
src/main/resources/application.yml
+19
-3
KnowBaseApplicationTests.java
...test/java/com/zzsn/knowbase/KnowBaseApplicationTests.java
+20
-1
没有找到文件。
src/main/java/com/zzsn/knowbase/config/RedisConfig.java
0 → 100644
浏览文件 @
34b0fb4d
package
com
.
zzsn
.
knowbase
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
/**
* redisConfig
*
* @author ShiQiangChen
* @date 2024/1/8
*/
@Configuration
public
class
RedisConfig
{
@Bean
public
RedisTemplate
<
String
,
?>
getRedisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
String
,
?>
template
=
new
RedisTemplate
<>();
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashValueSerializer
(
new
GenericJackson2JsonRedisSerializer
());
template
.
setValueSerializer
(
new
GenericJackson2JsonRedisSerializer
());
template
.
setEnableTransactionSupport
(
true
);
template
.
setConnectionFactory
(
factory
);
return
template
;
}
}
\ No newline at end of file
src/main/java/com/zzsn/knowbase/config/interceptor/KnowInterceptor.java
浏览文件 @
34b0fb4d
...
...
@@ -26,18 +26,18 @@ import java.util.Map;
public
class
KnowInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
// 在请求处理之前进行调用(Controller方法调用之前)
// 返回true才会继续执行后续的Interceptor和Controller
// 返回false则取消当前请求
String
token
=
request
.
getHeader
(
"X-Access-Token"
);
KbAuthorizedUserService
userService
=
SpringContextUtils
.
getBean
(
KbAuthorizedUserService
.
class
);
Result
<?>
result
=
userService
.
doCheck
(
token
);
/**第三方用户验证未通过,直接拦截请求并返回提示*/
if
(!
result
.
isSuccess
()){
doRes
(
request
,
response
);
return
false
;
}
//
// 在请求处理之前进行调用(Controller方法调用之前)
//
// 返回true才会继续执行后续的Interceptor和Controller
//
// 返回false则取消当前请求
//
String token = request.getHeader("X-Access-Token");
//
//
KbAuthorizedUserService userService = SpringContextUtils.getBean(KbAuthorizedUserService.class);
//
Result<?> result = userService.doCheck(token);
//
/**第三方用户验证未通过,直接拦截请求并返回提示*/
//
if (!result.isSuccess()){
//
doRes(request,response);
//
return false;
//
}
return
true
;
}
...
...
src/main/java/com/zzsn/knowbase/constant/Constants.java
浏览文件 @
34b0fb4d
...
...
@@ -254,5 +254,14 @@ public class Constants {
//招投标索引
public
final
static
String
TENDER
=
"tender"
;
public
static
final
Integer
MAX_FILE_SIZE
=
5
*
1024
*
1024
;
public
static
final
Integer
CONVERT_TIMEOUT_MS
=
120000
;
public
static
final
String
CONVERTATION_ERROR_MESSAGE_TEMPLATE
=
"Error occurred in the ConvertService: "
;
public
static
final
Long
FULL_LOADING_IN_PERCENT
=
100L
;
public
static
final
Integer
FILE_SAVE_TIMEOUT
=
5000
;
public
static
final
Integer
MAX_KEY_LENGTH
=
20
;
public
static
final
Integer
ANONYMOUS_USER_ID
=
4
;
public
static
final
Integer
KILOBYTE_SIZE
=
1024
;
private
Constants
()
{
}
}
src/main/java/com/zzsn/knowbase/controller/KnowledgeController.java
浏览文件 @
34b0fb4d
...
...
@@ -3,8 +3,10 @@ package com.zzsn.knowbase.controller;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.entity.Knowledge
;
import
com.zzsn.knowbase.service.IKnowledgeService
;
import
com.zzsn.knowbase.service.ILocalFileService
;
import
com.zzsn.knowbase.util.DocUtil
;
import
com.zzsn.knowbase.util.HttpUtil
;
import
com.zzsn.knowbase.vo.IntelligentQaParam
;
...
...
@@ -17,10 +19,16 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.util.WebUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @Description: 知识
...
...
@@ -35,8 +43,11 @@ public class KnowledgeController {
@Autowired
private
IKnowledgeService
knowledgeService
;
@Value
(
"${python.IntelligentQaUrl:}"
)
private
String
IntelligentQaUrl
;
@Value
(
"${python.intelligentQaUrl:}"
)
private
String
intelligentQaUrl
;
@Autowired
private
ILocalFileService
localFileService
;
/**
* 分页列表查询
...
...
@@ -51,6 +62,20 @@ public class KnowledgeController {
return
Result
.
OK
(
pageList
);
}
/**
* 分页列表查询
*/
@GetMapping
(
value
=
"/listFromPython"
)
public
Result
<?>
listFromPython
(
KnowledgeParam
knowledgeParam
,
@RequestParam
(
name
=
"pageNo"
,
defaultValue
=
"1"
)
Integer
pageNo
,
@RequestParam
(
name
=
"pageSize"
,
defaultValue
=
"10"
)
Integer
pageSize
,
@RequestParam
(
name
=
"column"
,
defaultValue
=
"common"
)
String
column
,
@RequestParam
(
name
=
"order"
,
defaultValue
=
"desc"
)
String
order
)
{
IPage
<
KnowledgeVO
>
pageList
=
knowledgeService
.
listFromPython
(
knowledgeParam
,
pageNo
,
pageSize
,
column
,
order
);
return
Result
.
OK
(
pageList
);
}
/**
* 添加
*
...
...
@@ -59,8 +84,17 @@ public class KnowledgeController {
*/
@ApiOperation
(
value
=
"知识-添加"
,
notes
=
"知识-添加"
)
@PostMapping
(
value
=
"/uploadKnowledge"
)
public
Result
<?>
uploadKnowledge
(
HttpServletRequest
request
,
@RequestBody
Knowledge
knowledge
)
{
knowledgeService
.
addKnowledge
(
request
,
knowledge
);
public
Result
<?>
uploadKnowledge
(
HttpServletRequest
request
,
Knowledge
knowledge
)
{
MultipartHttpServletRequest
multipartRequest
=
WebUtils
.
getNativeRequest
(
request
,
MultipartHttpServletRequest
.
class
);
Map
<
String
,
MultipartFile
>
fileMap
=
multipartRequest
.
getFileMap
();
List
<
Result
<
KnowFile
>>
resultList
=
localFileService
.
upload
(
fileMap
);
if
(
null
==
resultList
||
resultList
.
isEmpty
()){
return
Result
.
error
(
"上传文件失败"
);
}
for
(
Result
<
KnowFile
>
knowFileResult
:
resultList
)
{
knowledgeService
.
addKnowledge
(
knowFileResult
.
getResult
(),
knowledge
);
}
return
Result
.
OK
(
"添加成功!"
);
}
...
...
@@ -80,12 +114,12 @@ public class KnowledgeController {
/**
* 通过id删除
*
* @param id
* @param id
s
* @return
*/
@DeleteMapping
(
value
=
"/delete"
)
public
Result
<?>
delete
(
@RequestParam
(
name
=
"id"
)
String
id
)
{
knowledgeService
.
deleteKnowledge
(
id
);
public
Result
<?>
delete
(
@RequestParam
(
name
=
"id"
)
String
id
s
)
{
knowledgeService
.
deleteKnowledge
(
id
s
);
return
Result
.
OK
(
"删除成功!"
);
}
/**
...
...
@@ -108,7 +142,7 @@ public class KnowledgeController {
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"question"
,
intelligentQaParam
.
getQuestion
());
params
.
put
(
"knowledge_base_id"
,
Arrays
.
asList
(
intelligentQaParam
.
getKnowledgeProjectIds
().
split
(
","
)));
String
result
=
HttpUtil
.
doPost
(
I
ntelligentQaUrl
,
params
,
120000
);
String
result
=
HttpUtil
.
doPost
(
i
ntelligentQaUrl
,
params
,
120000
);
if
(!
result
.
isEmpty
()){
JSONObject
jsonObject
=
JSON
.
parseObject
(
result
);
return
Result
.
OK
(
jsonObject
.
get
(
"result"
));
...
...
src/main/java/com/zzsn/knowbase/entity/KnowFile.java
浏览文件 @
34b0fb4d
...
...
@@ -17,7 +17,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public
class
KnowFile
{
private
String
fileId
;
private
String
fileName
;
private
String
filePath
;
private
String
fileType
;
private
Integer
fileSize
;
private
Long
fileSize
;
}
src/main/java/com/zzsn/knowbase/entity/Knowledge.java
浏览文件 @
34b0fb4d
...
...
@@ -35,7 +35,7 @@ public class Knowledge implements Serializable {
*/
@TableId
(
type
=
IdType
.
ASSIGN_ID
)
@ApiModelProperty
(
value
=
"主键"
)
private
String
id
;
String
id
;
/**
* 标题
*/
...
...
@@ -79,6 +79,10 @@ public class Knowledge implements Serializable {
*/
private
String
publishDate
;
/**
* 审核时间
*/
private
String
verifyTime
;
/**
* 审核状态
*/
private
Integer
verifyStatus
;
...
...
@@ -101,6 +105,7 @@ public class Knowledge implements Serializable {
private
Integer
deleteFlag
;
private
List
<
Content
>
contents
;
private
List
<
KnowFile
>
files
;
private
Integer
score
;
}
...
...
src/main/java/com/zzsn/knowbase/enums/DocumentType.java
0 → 100644
浏览文件 @
34b0fb4d
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
com
.
zzsn
.
knowbase
.
enums
;
public
enum
DocumentType
{
word
,
cell
,
slide
}
src/main/java/com/zzsn/knowbase/service/IKnowledgeService.java
浏览文件 @
34b0fb4d
package
com
.
zzsn
.
knowbase
.
service
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.entity.Knowledge
;
import
com.zzsn.knowbase.vo.KnowledgeParam
;
import
com.zzsn.knowbase.vo.KnowledgeVO
;
...
...
@@ -19,7 +20,7 @@ public interface IKnowledgeService {
/**
* 新增
*/
void
addKnowledge
(
HttpServletRequest
httpServletRequest
,
Knowledge
knowledge
);
void
addKnowledge
(
KnowFile
knowFile
,
Knowledge
knowledge
);
/**
* 修改
...
...
@@ -29,7 +30,7 @@ public interface IKnowledgeService {
/**
* 删除
*/
void
deleteKnowledge
(
String
id
)
;
void
deleteKnowledge
(
String
id
s
)
;
/**
* 分页检索
...
...
@@ -41,4 +42,6 @@ public interface IKnowledgeService {
* @return
*/
IPage
<
KnowledgeVO
>
queryPageList
(
KnowledgeParam
knowledgeParam
,
Integer
pageNo
,
Integer
pageSize
,
String
column
,
String
order
);
IPage
<
KnowledgeVO
>
listFromPython
(
KnowledgeParam
knowledgeParam
,
Integer
pageNo
,
Integer
pageSize
,
String
column
,
String
order
);
}
src/main/java/com/zzsn/knowbase/service/ILocalFileService.java
0 → 100644
浏览文件 @
34b0fb4d
package
com
.
zzsn
.
knowbase
.
service
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.vo.Result
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
import
java.util.Map
;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/1/9 9:34
* @Content: 文件上传下载服务
*/
public
interface
ILocalFileService
{
/**
* 文件上传
* @param file
* @return
*/
Result
<
KnowFile
>
upload
(
MultipartFile
file
);
/**
* 批量文件上传
* @param fileMap
* @return
*/
List
<
Result
<
KnowFile
>>
upload
(
Map
<
String
,
MultipartFile
>
fileMap
);
/**
* 文件下载
* @param fileName
* @param filePath
* @return
*/
ResponseEntity
<
Resource
>
download
(
String
fileName
,
String
filePath
);
}
src/main/java/com/zzsn/knowbase/service/impl/KnowledgeServiceImpl.java
浏览文件 @
34b0fb4d
差异被折叠。
点击展开。
src/main/java/com/zzsn/knowbase/service/impl/LocalFileServiceImpl.java
0 → 100644
浏览文件 @
34b0fb4d
package
com
.
zzsn
.
knowbase
.
service
.
impl
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.service.ILocalFileService
;
import
com.zzsn.knowbase.util.file.FileUtility
;
import
com.zzsn.knowbase.vo.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.UrlResource
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.MalformedURLException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
/**
* @Version 1.0
* @Author: ZhangJingKun
* @Date: 2024/1/9 9:36
* @Content:
*/
@Service
@Slf4j
public
class
LocalFileServiceImpl
implements
ILocalFileService
{
@Autowired
private
FileUtility
fileUtility
;
@Value
(
"${files.storage}"
)
String
filesStorage
;
@Override
public
Result
<
KnowFile
>
upload
(
MultipartFile
file
)
{
try
{
String
fullFileName
=
file
.
getOriginalFilename
();
// get file name
String
fileExtension
=
fileUtility
.
getFileExtension
(
fullFileName
);
// get file extension
long
fileSize
=
file
.
getSize
();
// get file size
// check if the file size exceeds the maximum file size or is less than 0
if
(
fileUtility
.
getMaxFileSize
()
<
fileSize
||
fileSize
<=
0
)
{
Result
result
=
Result
.
error
(
"文件大小不正确!"
);
return
result
;
}
// check if file extension is supported by the editor
if
(!
fileUtility
.
getFileExts
().
contains
(
fileExtension
))
{
Result
result
=
Result
.
error
(
"不支持的文件类型!"
);
return
result
;
}
String
fileName
=
file
.
getOriginalFilename
();
String
fileSuffix
=
getFileSuffix
(
fileName
);
String
uid
=
UUID
.
randomUUID
().
toString
();
String
filePath
=
getFilePath
()
+
uid
+
"."
+
fileSuffix
;
byte
[]
bytes
=
file
.
getBytes
();
// get file in bytes
//Files.write(Paths.get(filePath), bytes);
file
.
transferTo
(
new
File
(
filePath
));
KnowFile
knowFile
=
new
KnowFile
();
knowFile
.
setFileId
(
uid
);
knowFile
.
setFileName
(
fileName
);
knowFile
.
setFilePath
(
filePath
);
knowFile
.
setFileType
(
fileSuffix
);
knowFile
.
setFileSize
(
fileSize
);
Result
result
=
Result
.
OK
(
knowFile
);
return
result
;
// create user metadata and return it
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
// if the operation of file uploading is unsuccessful, an error occurs
Result
result
=
Result
.
error
(
"上传文件时出现问题!"
);
return
result
;
}
@Override
public
List
<
Result
<
KnowFile
>>
upload
(
Map
<
String
,
MultipartFile
>
fileMap
)
{
List
<
Result
<
KnowFile
>>
list
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
MultipartFile
>
entity
:
fileMap
.
entrySet
())
{
MultipartFile
file
=
entity
.
getValue
();
// 获取上传文件对象
Result
<
KnowFile
>
result
=
upload
(
file
);
list
.
add
(
result
);
}
return
list
;
}
/**
* 文件下载
*/
@Override
public
ResponseEntity
<
Resource
>
download
(
String
fileName
,
String
filePath
)
{
Path
path
=
Paths
.
get
(
filePath
);
try
{
Resource
resource
=
new
UrlResource
(
path
.
toUri
());
if
(
resource
.
exists
()
||
resource
.
isReadable
())
{
return
ResponseEntity
.
ok
()
.
header
(
"Content-Disposition"
,
"attachment; filename=\""
+
fileName
+
"\""
)
.
body
(
resource
);
}
else
{
throw
new
RuntimeException
(
"文件不存在或不可读"
);
}
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
"文件读取失败"
);
}
}
//获取文件夹路径
private
String
getFilePath
(){
LocalDate
currentDate
=
LocalDate
.
now
();
//System.out.println("当前日期: " + currentDate);
String
filePath
=
filesStorage
+
currentDate
+
"/"
;
//判断文件夹是否存在,不存在创建
Path
directory
=
Paths
.
get
(
filePath
);
if
(!
Files
.
exists
(
directory
))
{
try
{
Files
.
createDirectories
(
directory
);
log
.
info
(
"文件夹创建成功:"
+
filePath
);
}
catch
(
IOException
e
)
{
log
.
error
(
"文件夹创建失败:"
+
filePath
);
e
.
printStackTrace
();
}
}
return
filePath
;
}
//获取文件后缀
private
String
getFileSuffix
(
String
fileName
){
int
lastIndexOfDot
=
fileName
.
lastIndexOf
(
'.'
);
String
fileExtension
=
""
;
if
(
lastIndexOfDot
!=
-
1
)
{
fileExtension
=
fileName
.
substring
(
lastIndexOfDot
+
1
);
}
return
fileExtension
;
}
}
src/main/java/com/zzsn/knowbase/util/RedisUtil.java
0 → 100644
浏览文件 @
34b0fb4d
差异被折叠。
点击展开。
src/main/java/com/zzsn/knowbase/util/file/DefaultFileUtility.java
0 → 100644
浏览文件 @
34b0fb4d
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
com
.
zzsn
.
knowbase
.
util
.
file
;
import
com.zzsn.knowbase.constant.Constants
;
import
com.zzsn.knowbase.enums.DocumentType
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
@Component
@Qualifier
(
"default"
)
public
class
DefaultFileUtility
implements
FileUtility
{
@Value
(
"${filesize-max}"
)
private
String
filesizeMax
;
@Value
(
"${files.docservice.viewed-docs}"
)
private
String
docserviceViewedDocs
;
@Value
(
"${files.docservice.edited-docs}"
)
private
String
docserviceEditedDocs
;
@Value
(
"${files.docservice.convert-docs}"
)
private
String
docserviceConvertDocs
;
@Value
(
"${files.docservice.fillforms-docs}"
)
private
String
docserviceFillDocs
;
// document extensions
private
List
<
String
>
extsDocument
=
Arrays
.
asList
(
".doc"
,
".docx"
,
".docm"
,
".dot"
,
".dotx"
,
".dotm"
,
".odt"
,
".fodt"
,
".ott"
,
".rtf"
,
".txt"
,
".html"
,
".htm"
,
".mht"
,
".xml"
,
".pdf"
,
".djvu"
,
".fb2"
,
".epub"
,
".xps"
,
".oform"
);
// spreadsheet extensions
private
List
<
String
>
extsSpreadsheet
=
Arrays
.
asList
(
".xls"
,
".xlsx"
,
".xlsm"
,
".xlsb"
,
".xlt"
,
".xltx"
,
".xltm"
,
".ods"
,
".fods"
,
".ots"
,
".csv"
);
// presentation extensions
private
List
<
String
>
extsPresentation
=
Arrays
.
asList
(
".pps"
,
".ppsx"
,
".ppsm"
,
".ppt"
,
".pptx"
,
".pptm"
,
".pot"
,
".potx"
,
".potm"
,
".odp"
,
".fodp"
,
".otp"
);
// get the document type
public
DocumentType
getDocumentType
(
final
String
fileName
)
{
String
ext
=
getFileExtension
(
fileName
).
toLowerCase
();
// get file extension from its name
// word type for document extensions
if
(
extsDocument
.
contains
(
ext
))
{
return
DocumentType
.
word
;
}
// cell type for spreadsheet extensions
if
(
extsSpreadsheet
.
contains
(
ext
))
{
return
DocumentType
.
cell
;
}
// slide type for presentation extensions
if
(
extsPresentation
.
contains
(
ext
))
{
return
DocumentType
.
slide
;
}
// default file type is word
return
DocumentType
.
word
;
}
// get file name from its URL
public
String
getFileName
(
final
String
url
)
{
if
(
url
==
null
)
{
return
""
;
}
// get file name from the last part of URL
String
fileName
=
url
.
substring
(
url
.
lastIndexOf
(
'/'
)
+
1
);
fileName
=
fileName
.
split
(
"\\?"
)[
0
];
return
fileName
;
}
// get file name without extension
public
String
getFileNameWithoutExtension
(
final
String
url
)
{
String
fileName
=
getFileName
(
url
);
if
(
fileName
==
null
)
{
return
null
;
}
String
fileNameWithoutExt
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
return
fileNameWithoutExt
;
}
// get file extension from URL
public
String
getFileExtension
(
final
String
url
)
{
String
fileName
=
getFileName
(
url
);
if
(
fileName
==
null
)
{
return
null
;
}
String
fileExt
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
return
fileExt
.
toLowerCase
();
}
// get an editor internal extension
public
String
getInternalExtension
(
final
DocumentType
type
)
{
// .docx for word file type
if
(
type
.
equals
(
DocumentType
.
word
))
{
return
".docx"
;
}
// .xlsx for cell file type
if
(
type
.
equals
(
DocumentType
.
cell
))
{
return
".xlsx"
;
}
// .pptx for slide file type
if
(
type
.
equals
(
DocumentType
.
slide
))
{
return
".pptx"
;
}
// the default file type is .docx
return
".docx"
;
}
public
List
<
String
>
getFillExts
()
{
return
Arrays
.
asList
(
docserviceFillDocs
.
split
(
"\\|"
));
}
// get file extensions that can be viewed
public
List
<
String
>
getViewedExts
()
{
return
Arrays
.
asList
(
docserviceViewedDocs
.
split
(
"\\|"
));
}
// get file extensions that can be edited
public
List
<
String
>
getEditedExts
()
{
return
Arrays
.
asList
(
docserviceEditedDocs
.
split
(
"\\|"
));
}
// get file extensions that can be converted
public
List
<
String
>
getConvertExts
()
{
return
Arrays
.
asList
(
docserviceConvertDocs
.
split
(
"\\|"
));
}
// get all the supported file extensions
public
List
<
String
>
getFileExts
()
{
List
<
String
>
res
=
new
ArrayList
<>();
res
.
addAll
(
getViewedExts
());
res
.
addAll
(
getEditedExts
());
res
.
addAll
(
getConvertExts
());
res
.
addAll
(
getFillExts
());
return
res
;
}
// generate the file path from file directory and name
public
Path
generateFilepath
(
final
String
directory
,
final
String
fullFileName
)
{
String
fileName
=
getFileNameWithoutExtension
(
fullFileName
);
// get file name without extension
String
fileExtension
=
getFileExtension
(
fullFileName
);
// get file extension
Path
path
=
Paths
.
get
(
directory
+
fullFileName
);
// get the path to the files with the specified name
for
(
int
i
=
1
;
Files
.
exists
(
path
);
i
++)
{
// run through all the files with the specified name
// get a name of each file without extension and add an index to it
fileName
=
getFileNameWithoutExtension
(
fullFileName
)
+
"("
+
i
+
")"
;
// create a new path for this file with the correct name and extension
path
=
Paths
.
get
(
directory
+
fileName
+
fileExtension
);
}
path
=
Paths
.
get
(
directory
+
fileName
+
fileExtension
);
return
path
;
}
// get maximum file size
public
long
getMaxFileSize
()
{
long
size
=
Long
.
parseLong
(
filesizeMax
);
return
size
>
0
?
size
:
Constants
.
MAX_FILE_SIZE
;
}
}
src/main/java/com/zzsn/knowbase/util/file/FileUtility.java
0 → 100644
浏览文件 @
34b0fb4d
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package
com
.
zzsn
.
knowbase
.
util
.
file
;
import
com.zzsn.knowbase.enums.DocumentType
;
import
java.nio.file.Path
;
import
java.util.List
;
// specify the file utility functions
public
interface
FileUtility
{
DocumentType
getDocumentType
(
String
fileName
);
// get the document type
String
getFileName
(
String
url
);
// get file name from its URL
String
getFileNameWithoutExtension
(
String
url
);
// get file name without extension
String
getFileExtension
(
String
url
);
// get file extension from URL
String
getInternalExtension
(
DocumentType
type
);
// get an editor internal extension
List
<
String
>
getFileExts
();
// get all the supported file extensions
List
<
String
>
getFillExts
();
// get file extensions that can be filled
List
<
String
>
getViewedExts
();
// get file extensions that can be viewed
List
<
String
>
getEditedExts
();
// get file extensions that can be edited
List
<
String
>
getConvertExts
();
// get file extensions that can be converted
Path
generateFilepath
(
String
directory
,
String
fullFileName
);
/* generate the file path
from file directory and name */
long
getMaxFileSize
();
// get maximum file size
}
src/main/java/com/zzsn/knowbase/vo/KnowledgeParam.java
浏览文件 @
34b0fb4d
...
...
@@ -17,7 +17,6 @@ import lombok.NoArgsConstructor;
@Data
public
class
KnowledgeParam
{
private
String
id
;
private
String
title
;
/**
* 来源
*/
...
...
@@ -25,7 +24,7 @@ public class KnowledgeParam {
/**
* 作者
*/
private
Integer
author
;
private
String
author
;
/**
* 发布时间
*/
...
...
@@ -49,10 +48,34 @@ public class KnowledgeParam {
/**
* 类型
*/
private
String
type
;
private
String
types
;
/**
* 发布开始时间
*/
private
String
startTime
;
/**
* 发布结束时间
*/
private
String
endTime
;
private
String
content
;
/**
* 搜索信息
*/
private
String
searchInfo
;
/**
* 范围 1标题 2正文
*/
private
Integer
searchScope
;
/**
* 精确搜索
*/
private
String
searchAccuracy
;
/**
* 审核开始时间
*/
private
String
verifyStartTime
;
/**
* 审核结束时间
*/
private
String
verifyEndTime
;
}
src/main/java/com/zzsn/knowbase/vo/KnowledgeVO.java
浏览文件 @
34b0fb4d
package
com
.
zzsn
.
knowbase
.
vo
;
import
com.zzsn.knowbase.entity.Knowledge
;
import
lombok.Builder
;
import
lombok.Data
;
/**
...
...
@@ -10,6 +10,16 @@ import lombok.Data;
* @date 2024/1/4
*/
@Data
public
class
KnowledgeVO
extends
Knowledge
{
@Builder
public
class
KnowledgeVO
{
private
String
content
;
private
String
id
;
private
String
verifyTime
;
private
String
publishDate
;
private
String
type
;
private
String
verifierName
;
private
Integer
score
;
private
Integer
verifyStatus
;
}
src/main/resources/application.yml
浏览文件 @
34b0fb4d
...
...
@@ -2,6 +2,10 @@ server:
port
:
9088
spring
:
servlet
:
multipart
:
max-request-size
:
1024MB
max-file-size
:
100MB
datasource
:
url
:
jdbc:mysql://114.116.44.11:3306/knowledge?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&AllowPublicKeyRetrieval=True
username
:
ciglobal
...
...
@@ -18,8 +22,6 @@ spring:
brokers
:
114.115.159.144:9092
zkNodes
:
114.115.159.144:2181
requiredAcks
:
1
redis
:
database
:
0
host
:
114.115.236.206
...
...
@@ -39,9 +41,23 @@ mybatis-plus:
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case
:
true
python
:
IntelligentQaUrl
:
http://116.63.179.212:7862/platform/chat
intelligentQaUrl
:
http://116.63.179.212:7862/platform/chat
searchUrl
:
http://114.115.172.99:10013/platform/search
deleteUrl
:
http://114.115.172.99:10013/platform/delete
know
:
thirdpartyurl
:
checkuserurl
:
http://127.0.0.1:9988/sys/checkToken
getusersurl
:
http://127.0.0.1:9988/sys/user/thirdparty
files
:
storage
:
E:/aaa/
docservice
:
fillforms-docs
:
.docx|.oform
viewed-docs
:
.djvu|.oxps|.pdf|.xps
edited-docs
:
.csv|.docm|.docx|.docxf|.dotm|.dotx|.epub|.fb2|.html|.odp|.ods|.odt|.otp|.ots|.ott|.potm|.potx|.ppsm|.ppsx|.pptm|.pptx|.rtf|.txt|.xlsm|.xlsx|.xltm|.xltx
convert-docs
:
.doc|.dot|.dps|.dpt|.epub|.et|.ett|.fb2|.fodp|.fods|.fodt|.htm|.html|.mht|.mhtml|.odp|.ods|.odt|.otp|.ots|.ott|.pot|.pps|.ppt|.rtf|.stw|.sxc|.sxi|.sxw|.wps|.wpt|.xls|.xlsb|.xlt|.xml
timeout
:
120000
history
:
postfix
:
-hist
filesize-max
:
5242880
src/test/java/com/zzsn/knowbase/KnowBaseApplicationTests.java
浏览文件 @
34b0fb4d
package
com
.
zzsn
.
knowbase
;
import
com.zzsn.knowbase.constant.Constants
;
import
com.zzsn.knowbase.service.ILocalFileService
;
import
com.zzsn.knowbase.util.CodeGenerateUtil
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.ResponseEntity
;
import
java.io.File
;
import
java.io.IOException
;
@SpringBootTest
class
KnowBaseApplicationTests
{
@Autowired
private
CodeGenerateUtil
codeGenerateUtil
;
@Autowired
private
ILocalFileService
localFileService
;
@Test
void
contextLoads
()
{
void
contextLoads
()
throws
IOException
{
ResponseEntity
<
Resource
>
re
=
localFileService
.
download
(
"abc.docx"
,
"E:/aaa/abc.docx"
);
File
file
=
re
.
getBody
().
getFile
();
System
.
out
.
println
(
re
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论