Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
event
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
陈世强
event
Commits
b771441b
提交
b771441b
authored
5月 14, 2025
作者:
925993793@qq.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
自定义专题-研究中心:增加导出excel接口以及资讯列表接口增加 格式化时间字段 dateFormat
上级
c9915324
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
94 行增加
和
2 行删除
+94
-2
FileController.java
src/main/java/com/zzsn/event/controller/FileController.java
+54
-0
InformationServiceImpl.java
...a/com/zzsn/event/service/impl/InformationServiceImpl.java
+5
-1
InfoDataSearchCondition.java
src/main/java/com/zzsn/event/vo/InfoDataSearchCondition.java
+2
-1
SpecialInformation.java
src/main/java/com/zzsn/event/vo/es/SpecialInformation.java
+33
-0
没有找到文件。
src/main/java/com/zzsn/event/controller/FileController.java
浏览文件 @
b771441b
...
@@ -404,6 +404,60 @@ public class FileController {
...
@@ -404,6 +404,60 @@ public class FileController {
}
}
}
}
/**
* 导出数据-excel格式-研究中心
*
* @param searchCondition 筛选条件
* @author lkg
* @date 2024/12/25
*/
@PostMapping
(
"/exportExcel"
)
public
void
exportExcel
(
@RequestBody
InfoDataSearchCondition
searchCondition
,
HttpServletResponse
response
)
{
int
count
=
esService
.
getCount
(
searchCondition
);
if
(
count
>
0
)
{
String
subjectId
=
searchCondition
.
getSubjectId
();
long
timestamp
=
System
.
currentTimeMillis
();
String
filename
=
subjectId
+
"_"
+
timestamp
+
".xlsx"
;
try
{
String
[]
fetchFields
=
new
String
[]{
"score"
,
"title"
,
"titleRaw"
,
"summary"
,
"summaryRaw"
,
"content"
,
"contentRaw"
,
"author"
,
"origin"
,
"publishDate"
,
"sourceAddress"
,
"hitWords"
};
searchCondition
.
setFetchFields
(
fetchFields
);
searchCondition
.
setPageSize
(
1000
);
String
[]
arr
=
new
String
[]{
"得分"
,
"标题"
,
"标题译文"
,
"摘要"
,
"摘要译文"
,
"正文"
,
"正文译文"
,
"作者"
,
"来源"
,
"发布时间"
,
"网址"
,
"命中词"
};
List
<
String
>
headers
=
Arrays
.
asList
(
arr
);
SXSSFWorkbook
workbook
=
new
SXSSFWorkbook
();
for
(
int
i
=
1
;
;
i
++)
{
searchCondition
.
setPageNo
(
i
);
List
<
SpecialInformation
>
informationList
=
esService
.
informationList
(
searchCondition
);
log
.
info
(
"本次循环-{},数据量为-{}"
,
i
,
informationList
.
size
());
if
(
CollectionUtils
.
isEmpty
(
informationList
))
{
break
;
}
List
<
List
<
String
>>
rows
=
new
ArrayList
<>();
informationList
.
forEach
(
e
->
rows
.
add
(
e
.
toExcelList
()));
BigExcelExportUtil
.
exportExcelData
(
workbook
,
i
-
1
,
headers
,
rows
,
"sheet"
+
i
);
log
.
info
(
"第【{}】个sheet页写入成功"
,
i
);
}
// 将Workbook写入字节流
ByteArrayOutputStream
outStream
=
new
ByteArrayOutputStream
();
workbook
.
write
(
outStream
);
// 将字节流转换为InputStream
byte
[]
bytes
=
outStream
.
toByteArray
();
filename
=
URLEncoder
.
encode
(
filename
,
"UTF-8"
).
replace
(
"+"
,
" "
);
response
.
setHeader
(
"Access-Control-Expose-Headers"
,
"Content-Disposition"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
filename
);
response
.
setContentLength
(
bytes
.
length
);
OutputStream
out
=
response
.
getOutputStream
();
out
.
write
(
bytes
);
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
else
{
throw
new
FileExportException
(
"数据量为0,无法导出"
);
}
}
private
byte
[]
getBytes
(
InfoDataSearchCondition
searchCondition
,
Integer
pageSize
)
{
private
byte
[]
getBytes
(
InfoDataSearchCondition
searchCondition
,
Integer
pageSize
)
{
String
[]
fetchFields
=
new
String
[]{
"score"
,
"title"
,
"titleRaw"
,
"summary"
,
"summaryRaw"
,
"content"
,
"contentRaw"
,
"author"
,
"origin"
,
"publishDate"
,
"sourceAddress"
,
"classificationType"
,
"hitWords"
,
"labels"
};
String
[]
fetchFields
=
new
String
[]{
"score"
,
"title"
,
"titleRaw"
,
"summary"
,
"summaryRaw"
,
"content"
,
"contentRaw"
,
"author"
,
"origin"
,
"publishDate"
,
"sourceAddress"
,
"classificationType"
,
"hitWords"
,
"labels"
};
...
...
src/main/java/com/zzsn/event/service/impl/InformationServiceImpl.java
浏览文件 @
b771441b
...
@@ -156,7 +156,11 @@ public class InformationServiceImpl implements InformationService {
...
@@ -156,7 +156,11 @@ public class InformationServiceImpl implements InformationService {
for
(
SpecialInformation
specialInformation
:
records
)
{
for
(
SpecialInformation
specialInformation
:
records
)
{
DisplayInfo
info
=
new
DisplayInfo
();
DisplayInfo
info
=
new
DisplayInfo
();
BeanUtils
.
copyProperties
(
specialInformation
,
info
);
BeanUtils
.
copyProperties
(
specialInformation
,
info
);
info
.
setPublishDate
(
EsDateUtil
.
esFieldDateMapping
(
info
.
getPublishDate
()));
String
publishDate
=
EsDateUtil
.
esFieldDateMapping
(
info
.
getPublishDate
());
String
dateFormat
=
searchCondition
.
getDateFormat
();
if
(!
dateFormat
.
equals
(
"yyyy-MM-dd HH:mm:ss"
))
{
info
.
setPublishDate
(
DateUtil
.
formatStr
(
publishDate
,
"yyyy-MM-dd HH:mm:ss"
,
dateFormat
));
}
//标签处理
//标签处理
List
<
LabelModelVo
>
modelVoList
=
modelMap
.
get
(
info
.
getSubjectId
());
List
<
LabelModelVo
>
modelVoList
=
modelMap
.
get
(
info
.
getSubjectId
());
formatLabel
(
modelVoList
,
info
);
formatLabel
(
modelVoList
,
info
);
...
...
src/main/java/com/zzsn/event/vo/InfoDataSearchCondition.java
浏览文件 @
b771441b
...
@@ -33,7 +33,8 @@ public class InfoDataSearchCondition {
...
@@ -33,7 +33,8 @@ public class InfoDataSearchCondition {
//搜索词
//搜索词
private
String
searchWord
;
private
String
searchWord
;
//时间格式化
private
String
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
;
//发布时间
//发布时间
private
String
publishDate
;
private
String
publishDate
;
...
...
src/main/java/com/zzsn/event/vo/es/SpecialInformation.java
浏览文件 @
b771441b
package
com
.
zzsn
.
event
.
vo
.
es
;
package
com
.
zzsn
.
event
.
vo
.
es
;
import
lombok.Data
;
import
lombok.Data
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.ObjectUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Data
@Data
public
class
SpecialInformation
{
public
class
SpecialInformation
{
...
@@ -144,4 +148,33 @@ public class SpecialInformation {
...
@@ -144,4 +148,33 @@ public class SpecialInformation {
/**数据来源(1-人工导入;空-正常采集)*/
/**数据来源(1-人工导入;空-正常采集)*/
private
Integer
dataFrom
;
private
Integer
dataFrom
;
public
List
<
String
>
toExcelList
(){
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
getRealValue
(
score
));
list
.
add
(
getRealValue
(
title
));
list
.
add
(
getRealValue
(
titleRaw
));
list
.
add
(
getRealValue
(
summary
));
list
.
add
(
getRealValue
(
summaryRaw
));
list
.
add
(
getRealValue
(
content
));
list
.
add
(
getRealValue
(
contentRaw
));
list
.
add
(
getRealValue
(
author
));
list
.
add
(
getRealValue
(
origin
));
list
.
add
(
getRealValue
(
publishDate
));
list
.
add
(
getRealValue
(
sourceAddress
));
if
(
CollectionUtils
.
isNotEmpty
(
hitWords
))
{
list
.
add
(
String
.
join
(
","
,
hitWords
));
}
else
{
list
.
add
(
""
);
}
return
list
;
}
private
String
getRealValue
(
Object
obj
){
if
(
ObjectUtils
.
isEmpty
(
obj
))
{
return
""
;
}
return
String
.
valueOf
(
obj
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论