Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
K
know-base
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
张京坤
know-base
Commits
e573ff04
提交
e573ff04
authored
3月 19, 2024
作者:
chenshiqiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add export
上级
f0645305
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
180 行增加
和
68 行删除
+180
-68
KnowledgeController.java
...ava/com/zzsn/knowbase/controller/KnowledgeController.java
+45
-64
IKnowledgeService.java
...ain/java/com/zzsn/knowbase/service/IKnowledgeService.java
+6
-0
KnowledgeServiceImpl.java
.../com/zzsn/knowbase/service/impl/KnowledgeServiceImpl.java
+129
-4
没有找到文件。
src/main/java/com/zzsn/knowbase/controller/KnowledgeController.java
浏览文件 @
e573ff04
...
@@ -38,7 +38,7 @@ import java.util.concurrent.CompletableFuture;
...
@@ -38,7 +38,7 @@ import java.util.concurrent.CompletableFuture;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
*
@Description:
知识
* 知识
* @Author: chenshiqiang
* @Author: chenshiqiang
* @Version: V1.0
* @Version: V1.0
*/
*/
...
@@ -221,86 +221,67 @@ public class KnowledgeController {
...
@@ -221,86 +221,67 @@ public class KnowledgeController {
return
Result
.
OK
();
return
Result
.
OK
();
}
}
/*
/**
* 导出excel(专题-已采集)
* 预导出
*
* @param request
* @param
* @update by wp
* 异步调用
*
*
* @param newsIds 资讯知识ids
* @param fileIds 文件知识ids
*/
*/
@PostMapping
(
value
=
"/export
CollectionXls
"
)
@PostMapping
(
value
=
"/export"
)
public
Result
<?>
exportCollectionXls
(
HttpServletRequest
request
,
HttpServletResponse
response
,
KnowledgeVO
knowledgeVO
,
public
Result
<?>
exportCollectionXls
(
HttpServletRequest
request
,
String
i
ds
,
String
newsIds
,
String
fileI
ds
,
@RequestParam
(
name
=
"isAll"
,
defaultValue
=
"0"
)
String
isAll
)
{
@RequestParam
(
name
=
"isAll"
,
defaultValue
=
"0"
)
String
isAll
)
{
//获取数据
knowledgeService
.
exportExcel
(
newsIds
);
if
(
redisUtil
.
get
(
ids
)
==
null
)
{
knowledgeService
.
exportPackage
(
fileIds
);
try
{
String
[]
arr
=
new
String
[]{
"标题"
,
"正文"
,
"作者"
,
"来源"
,
"发布时间"
};
List
<
KnowledgeVO
>
informationList
=
knowledgeService
.
listByIds
(
ids
);
if
(
CollectionUtils
.
isNotEmpty
(
informationList
))
{
//动态补充表头
List
<
String
>
headers
=
Arrays
.
asList
(
arr
);
//每个sheet页最多5000条数据
List
<
List
<
KnowledgeVO
>>
partition
=
ListUtils
.
partition
(
informationList
,
5000
);
XSSFWorkbook
workbook
=
new
XSSFWorkbook
();
for
(
int
i
=
0
;
i
<
partition
.
size
();
i
++)
{
List
<
List
<
String
>>
rows
=
formatData
(
partition
.
get
(
i
));
ExcelExportUtil
.
exportExcelData
(
workbook
,
i
,
headers
,
rows
,
"sheet"
+
(
i
+
1
));
}
File
fileDir
=
ExcelExportUtil
.
getFileDir
();
String
filePath
=
fileDir
.
getAbsolutePath
()
+
File
.
separator
+
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
)
+
"info.xlsx"
;
FileOutputStream
outputStream
=
new
FileOutputStream
(
filePath
);
workbook
.
write
(
outputStream
);
redisUtil
.
set
(
ids
,
filePath
,
3600
*
24
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
Result
.
OK
(
false
);
}
}
return
Result
.
OK
(
true
);
return
Result
.
OK
(
true
);
}
}
/*
/**
* 导出excel(专题-已入库)
* 导出
*
* @param request
* @param
* @update by wp
* 异步调用
*
*
* @param newsIds 资讯知识ids
* @param fileIds 文件知识ids
*/
*/
@RequestMapping
(
value
=
"/download
Xls
"
)
@RequestMapping
(
value
=
"/download"
)
public
void
downloadXls
(
HttpServletResponse
response
,
String
i
ds
)
{
public
void
downloadXls
(
HttpServletResponse
response
,
String
newsIds
,
String
fileI
ds
)
{
//获取下载路径
//获取下载路径
Object
object
=
redisUtil
.
get
(
ids
);
Object
newsObject
=
redisUtil
.
get
(
newsIds
);
if
(
object
!=
null
)
{
Object
fileObject
=
redisUtil
.
get
(
fileIds
);
String
filePath
=
object
.
toString
();
String
newsFilePath
=
null
;
String
fileFilePath
=
null
;
if
(
fileObject
!=
null
)
{
newsFilePath
=
newsObject
.
toString
();
}
if
(
fileObject
!=
null
)
{
fileFilePath
=
fileObject
.
toString
();
}
try
{
try
{
redisUtil
.
del
(
ids
);
if
((!
newsIds
.
isEmpty
())&&(!
fileIds
.
isEmpty
()))
{
log
.
info
(
"files and news package downloading "
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
newsFilePath
);
list
.
add
(
fileFilePath
);
String
filePath
=
knowledgeService
.
comprocessByName
(
list
,
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
ExcelExportUtil
.
download
(
response
,
filePath
,
true
);
ExcelExportUtil
.
download
(
response
,
filePath
,
true
);
}
catch
(
Exception
e
)
{
return
;
e
.
printStackTrace
();
}
}
}
if
(
fileIds
.
isEmpty
())
{
//news
log
.
info
(
"only news downloading"
);
redisUtil
.
del
(
newsIds
);
ExcelExportUtil
.
download
(
response
,
newsFilePath
,
true
);
return
;
}
}
log
.
info
(
"only files downloading"
);
ExcelExportUtil
.
download
(
response
,
fileFilePath
,
true
);
private
List
<
List
<
String
>>
formatData
(
List
<
KnowledgeVO
>
knowledgeVOS
)
{
}
catch
(
Exception
e
)
{
List
<
List
<
String
>>
list
=
new
ArrayList
<>(
knowledgeVOS
.
size
());
e
.
printStackTrace
();
for
(
KnowledgeVO
knowledgeVO
:
knowledgeVOS
)
{
log
.
error
(
e
.
getMessage
());
List
<
String
>
innerList
=
new
ArrayList
<>();
innerList
.
add
(
knowledgeVO
.
getTitle
());
innerList
.
add
(
knowledgeVO
.
getContentAll
());
innerList
.
add
(
knowledgeVO
.
getAuthor
());
innerList
.
add
(
knowledgeVO
.
getOrigin
());
innerList
.
add
(
knowledgeVO
.
getPublishDate
());
list
.
add
(
innerList
);
}
}
return
list
;
}
}
}
}
@Data
@Data
...
...
src/main/java/com/zzsn/knowbase/service/IKnowledgeService.java
浏览文件 @
e573ff04
...
@@ -55,4 +55,10 @@ public interface IKnowledgeService {
...
@@ -55,4 +55,10 @@ public interface IKnowledgeService {
void
doExcel
(
HttpServletRequest
request
,
String
fileSuffix
,
String
userId
);
void
doExcel
(
HttpServletRequest
request
,
String
fileSuffix
,
String
userId
);
List
<
KnowledgeVO
>
listByIds
(
String
ids
);
List
<
KnowledgeVO
>
listByIds
(
String
ids
);
void
exportExcel
(
String
ids
);
String
exportPackage
(
String
ids
);
String
comprocessByName
(
List
<
String
>
list
,
String
filePath
);
}
}
src/main/java/com/zzsn/knowbase/service/impl/KnowledgeServiceImpl.java
浏览文件 @
e573ff04
...
@@ -19,6 +19,8 @@ import com.zzsn.knowbase.vo.KnowledgeVO;
...
@@ -19,6 +19,8 @@ import com.zzsn.knowbase.vo.KnowledgeVO;
import
com.zzsn.knowbase.vo.Result
;
import
com.zzsn.knowbase.vo.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.ListUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.lucene.search.join.ScoreMode
;
import
org.apache.lucene.search.join.ScoreMode
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
import
org.apache.pdfbox.pdmodel.PDDocument
;
...
@@ -26,6 +28,7 @@ import org.apache.pdfbox.pdmodel.PDPage;
...
@@ -26,6 +28,7 @@ import org.apache.pdfbox.pdmodel.PDPage;
import
org.apache.pdfbox.text.PDFTextStripper
;
import
org.apache.pdfbox.text.PDFTextStripper
;
import
org.apache.pdfbox.text.TextPosition
;
import
org.apache.pdfbox.text.TextPosition
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RequestOptions
;
...
@@ -47,13 +50,12 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -47,13 +50,12 @@ import org.springframework.web.multipart.MultipartFile;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
org.springframework.web.multipart.MultipartHttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.ByteArrayInputStream
;
import
java.io.*
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
/**
/**
* @Description: 知识
* @Description: 知识
...
@@ -682,6 +684,114 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -682,6 +684,114 @@ class KnowledgeServiceImpl implements IKnowledgeService {
return
list
;
return
list
;
}
}
@Override
public
void
exportExcel
(
String
ids
)
{
//获取数据
if
(
redisUtil
.
get
(
ids
)
==
null
)
{
try
{
String
[]
arr
=
new
String
[]{
"标题"
,
"正文"
,
"作者"
,
"来源"
,
"发布时间"
};
List
<
KnowledgeVO
>
informationList
=
this
.
listByIds
(
ids
);
if
(
CollectionUtils
.
isNotEmpty
(
informationList
))
{
//动态补充表头
List
<
String
>
headers
=
Arrays
.
asList
(
arr
);
//每个sheet页最多5000条数据
List
<
List
<
KnowledgeVO
>>
partition
=
ListUtils
.
partition
(
informationList
,
5000
);
XSSFWorkbook
workbook
=
new
XSSFWorkbook
();
for
(
int
i
=
0
;
i
<
partition
.
size
();
i
++)
{
List
<
List
<
String
>>
rows
=
formatData
(
partition
.
get
(
i
));
ExcelExportUtil
.
exportExcelData
(
workbook
,
i
,
headers
,
rows
,
"sheet"
+
(
i
+
1
));
}
File
fileDir
=
ExcelExportUtil
.
getFileDir
();
String
filePath
=
fileDir
.
getAbsolutePath
()
+
File
.
separator
+
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
)
+
"info.xlsx"
;
FileOutputStream
outputStream
=
new
FileOutputStream
(
filePath
);
workbook
.
write
(
outputStream
);
redisUtil
.
set
(
ids
,
filePath
,
3600
*
24
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
e
.
getMessage
());
}
}
}
@Override
public
String
exportPackage
(
String
ids
)
{
List
<
KnowledgeVO
>
knowledgeVOS
=
this
.
listByIds
(
ids
);
List
<
String
>
pathList
=
new
ArrayList
<>(
knowledgeVOS
.
size
());
for
(
KnowledgeVO
knowledgeVO
:
knowledgeVOS
)
{
pathList
.
add
(
filesStorage
+
knowledgeVO
.
getFiles
().
get
(
0
).
getFilePath
());
}
String
filePackage
=
comprocessByName
(
pathList
,
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
));
redisUtil
.
set
(
ids
,
filePackage
,
3600
*
24
);
return
filePackage
;
}
/*
* 将所有的文件都压缩到一个文件中去
*/
@Override
public
String
comprocessByName
(
List
<
String
>
fileNameList
,
String
downloadFileName
)
{
List
<
File
>
fileList
=
new
ArrayList
<
File
>();
for
(
String
fileName
:
fileNameList
)
{
fileList
.
add
(
new
File
(
fileName
));
}
return
comprocessByFile
(
fileList
,
downloadFileName
);
}
/*
* 将所有的文件都压缩到一个文件中去
*/
public
String
comprocessByFile
(
List
<
File
>
fileNamemList
,
String
key
)
{
String
tmpFile
=
Constants
.
USER_HOME
+
Constants
.
FSP
+
"brap"
+
Constants
.
FSP
+
"download"
+
Constants
.
FSP
;
byte
[]
buffer
=
new
byte
[
4096
];
FileInputStream
fis
=
null
;
ZipOutputStream
zos
=
null
;
File
zipFile
=
null
;
try
{
zipFile
=
new
File
(
tmpFile
+
key
+
".zip"
);
zos
=
new
ZipOutputStream
(
new
FileOutputStream
(
zipFile
));
for
(
File
file
:
fileNamemList
)
{
try
{
fis
=
new
FileInputStream
(
file
);
zos
.
putNextEntry
(
new
ZipEntry
(
file
.
getName
()));
int
len
;
// 读入需要下载的文件的内容,打包到zip文件
while
((
len
=
fis
.
read
(
buffer
))
>
0
)
{
zos
.
write
(
buffer
,
0
,
len
);
}
zos
.
flush
();
zos
.
closeEntry
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
null
!=
fis
)
{
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
file
!=
null
)
{
FileUtils
.
forceDelete
(
file
);
}
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
null
!=
zos
)
{
try
{
zos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
return
zipFile
.
getAbsolutePath
();
}
//导入发布库数据
//导入发布库数据
public
void
importInfo
(
List
<
List
<
String
>>
lists
,
String
kbKnowledgeId
,
String
knowledgeProjectId
,
String
typeId
,
String
createBy
)
{
public
void
importInfo
(
List
<
List
<
String
>>
lists
,
String
kbKnowledgeId
,
String
knowledgeProjectId
,
String
typeId
,
String
createBy
)
{
for
(
List
<
String
>
info
:
lists
)
{
for
(
List
<
String
>
info
:
lists
)
{
...
@@ -761,4 +871,19 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -761,4 +871,19 @@ class KnowledgeServiceImpl implements IKnowledgeService {
searchInfo
+
"#"
;
searchInfo
+
"#"
;
}
}
private
List
<
List
<
String
>>
formatData
(
List
<
KnowledgeVO
>
knowledgeVOS
)
{
List
<
List
<
String
>>
list
=
new
ArrayList
<>(
knowledgeVOS
.
size
());
for
(
KnowledgeVO
knowledgeVO
:
knowledgeVOS
)
{
List
<
String
>
innerList
=
new
ArrayList
<>();
innerList
.
add
(
knowledgeVO
.
getTitle
());
innerList
.
add
(
knowledgeVO
.
getContentAll
());
innerList
.
add
(
knowledgeVO
.
getAuthor
());
innerList
.
add
(
knowledgeVO
.
getOrigin
());
innerList
.
add
(
knowledgeVO
.
getPublishDate
());
list
.
add
(
innerList
);
}
return
list
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论