Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
K
know-base
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
张京坤
know-base
Commits
4f189a27
提交
4f189a27
authored
1月 19, 2024
作者:
chenshiqiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
import excel
上级
cf818d6e
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
240 行增加
和
36 行删除
+240
-36
KnowledgeController.java
...ava/com/zzsn/knowbase/controller/KnowledgeController.java
+25
-4
KnowledgeExcel.java
src/main/java/com/zzsn/knowbase/entity/KnowledgeExcel.java
+57
-0
KnowledgeMessage.java
...ava/com/zzsn/knowbase/kafka/message/KnowledgeMessage.java
+1
-0
IKnowledgeService.java
...ain/java/com/zzsn/knowbase/service/IKnowledgeService.java
+2
-2
AsyncService.java
...ain/java/com/zzsn/knowbase/service/impl/AsyncService.java
+2
-6
KnowledgeServiceImpl.java
.../com/zzsn/knowbase/service/impl/KnowledgeServiceImpl.java
+27
-23
ExcelExportUtil.java
src/main/java/com/zzsn/knowbase/util/ExcelExportUtil.java
+126
-1
没有找到文件。
src/main/java/com/zzsn/knowbase/controller/KnowledgeController.java
浏览文件 @
4f189a27
...
@@ -6,11 +6,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
...
@@ -6,11 +6,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import
com.zzsn.knowbase.entity.KbAuthorizedUser
;
import
com.zzsn.knowbase.entity.KbAuthorizedUser
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.entity.KnowFile
;
import
com.zzsn.knowbase.entity.Knowledge
;
import
com.zzsn.knowbase.entity.Knowledge
;
import
com.zzsn.knowbase.entity.KnowledgeExcel
;
import
com.zzsn.knowbase.service.IKnowledgeService
;
import
com.zzsn.knowbase.service.IKnowledgeService
;
import
com.zzsn.knowbase.service.ILocalFileService
;
import
com.zzsn.knowbase.service.ILocalFileService
;
import
com.zzsn.knowbase.util.DocUtil
;
import
com.zzsn.knowbase.util.*
;
import
com.zzsn.knowbase.util.HttpUtil
;
import
com.zzsn.knowbase.util.SpringContextUtils
;
import
com.zzsn.knowbase.vo.IntelligentQaParam
;
import
com.zzsn.knowbase.vo.IntelligentQaParam
;
import
com.zzsn.knowbase.vo.KnowledgeParam
;
import
com.zzsn.knowbase.vo.KnowledgeParam
;
import
com.zzsn.knowbase.vo.KnowledgeVO
;
import
com.zzsn.knowbase.vo.KnowledgeVO
;
...
@@ -27,7 +26,10 @@ import org.springframework.web.util.WebUtils;
...
@@ -27,7 +26,10 @@ import org.springframework.web.util.WebUtils;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CompletableFuture
;
...
@@ -178,6 +180,25 @@ public class KnowledgeController {
...
@@ -178,6 +180,25 @@ public class KnowledgeController {
*/
*/
@RequestMapping
(
value
=
"/importInfo"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/importInfo"
,
method
=
RequestMethod
.
POST
)
public
Result
<?>
importInfo
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
Result
<?>
importInfo
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
return
knowledgeService
.
doImportInfo
(
request
);
KbAuthorizedUser
userInfo
=
SpringContextUtils
.
getUserInfo
();
assert
userInfo
!=
null
;
knowledgeService
.
doImportInfo
(
request
,
userInfo
.
getId
());
return
Result
.
OK
(
"导入正在后台进行"
);
}
/**
* 下载导入模板
*/
@RequestMapping
(
value
=
"/download"
)
public
Result
<?>
download
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
File
fileDir
=
ExcelExportUtil
.
getFileDir
();
List
<
KnowledgeExcel
>
dataList
=
new
ArrayList
<>();
String
filePath
=
fileDir
.
getAbsolutePath
()
+
File
.
separator
+
"info.xlsx"
;
ExcelExportUtil
.
writeExcelFront
(
dataList
,
"知识库列表导入模板"
,
filePath
,
KnowledgeExcel
.
class
);
ExcelExportUtil
.
download
(
response
,
filePath
,
true
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
Result
.
OK
();
}
}
}
}
src/main/java/com/zzsn/knowbase/entity/KnowledgeExcel.java
0 → 100644
浏览文件 @
4f189a27
package
com
.
zzsn
.
knowbase
.
entity
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.jeecgframework.poi.excel.annotation.Excel
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @Description: 知识
* @Author: chenshiqiang
* @Version: V1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
KnowledgeExcel
{
/**
* 标题
*/
@ExcelProperty
(
value
=
"标题"
,
index
=
0
)
private
String
title
;
@ExcelProperty
(
value
=
"正文"
,
index
=
1
)
private
String
content
;
/**
* 作者
*/
@ExcelProperty
(
value
=
"作者"
,
index
=
2
)
private
String
author
;
/**
* 来源
*/
@ExcelProperty
(
value
=
"来源"
,
index
=
3
)
private
String
origin
;
/**
* 发布时间
*/
@ExcelProperty
(
value
=
"发布时间"
,
index
=
4
)
private
String
publishDate
;
}
src/main/java/com/zzsn/knowbase/kafka/message/KnowledgeMessage.java
浏览文件 @
4f189a27
...
@@ -35,6 +35,7 @@ public class KnowledgeMessage {
...
@@ -35,6 +35,7 @@ public class KnowledgeMessage {
* 审核状态
* 审核状态
*/
*/
private
Integer
verifyStatus
;
private
Integer
verifyStatus
;
private
Integer
verifyTime
;
/**
/**
* 审核人名字
* 审核人名字
*/
*/
...
...
src/main/java/com/zzsn/knowbase/service/IKnowledgeService.java
浏览文件 @
4f189a27
...
@@ -49,7 +49,7 @@ public interface IKnowledgeService {
...
@@ -49,7 +49,7 @@ public interface IKnowledgeService {
KnowledgeVO
getById
(
String
id
);
KnowledgeVO
getById
(
String
id
);
Result
<?>
doImportInfo
(
HttpServletRequest
request
);
Result
<?>
doImportInfo
(
HttpServletRequest
request
,
String
userId
);
void
doExcel
(
HttpServletRequest
request
,
String
fileSuffix
);
void
doExcel
(
HttpServletRequest
request
,
String
fileSuffix
,
String
userId
);
}
}
src/main/java/com/zzsn/knowbase/service/impl/AsyncService.java
浏览文件 @
4f189a27
...
@@ -23,12 +23,8 @@ public class AsyncService {
...
@@ -23,12 +23,8 @@ public class AsyncService {
//异步执行文件解析
//异步执行文件解析
@Async
@Async
public
void
doimport
(
HttpServletRequest
request
,
MultipartFile
multipartFile
,
String
fileSuffix
)
{
public
void
doimport
(
HttpServletRequest
request
,
String
fileSuffix
,
String
userId
)
{
String
subjectId
=
request
.
getParameter
(
"subjectId"
);
knowledgeService
.
doExcel
(
request
,
fileSuffix
,
userId
);
String
isTopping
=
request
.
getParameter
(
"isTopping"
);
String
isExamine
=
request
.
getParameter
(
"isExamine"
);
knowledgeService
.
doExcel
(
request
,
fileSuffix
);
}
}
...
...
src/main/java/com/zzsn/knowbase/service/impl/KnowledgeServiceImpl.java
浏览文件 @
4f189a27
...
@@ -155,12 +155,6 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -155,12 +155,6 @@ class KnowledgeServiceImpl implements IKnowledgeService {
KnowledgeMessage
knowledgeMessage
=
new
KnowledgeMessage
();
KnowledgeMessage
knowledgeMessage
=
new
KnowledgeMessage
();
BeanUtils
.
copyProperties
(
knowledge
,
knowledgeMessage
);
BeanUtils
.
copyProperties
(
knowledge
,
knowledgeMessage
);
knowledgeMessage
.
setType
(
knowledge
.
getTypeId
());
knowledgeMessage
.
setType
(
knowledge
.
getTypeId
());
// CleanerProperties props = new CleanerProperties();
// props.setPruneTags("table");
// String htmlWithoutTable = new HtmlCleaner(props).clean(html).getText().toString();
// htmlWithoutTable = htmlWithoutTable.replace("<p>", "");
// List<String>contentStringWithoutTableList = Arrays.asList(htmlWithoutTable.split("</p>"));
knowledgeMessage
.
setContents
(
contentList
);
knowledgeMessage
.
setContents
(
contentList
);
produceInfo
.
sendKnowledgeContents
(
knowledgeMessage
);
produceInfo
.
sendKnowledgeContents
(
knowledgeMessage
);
}
}
...
@@ -456,7 +450,7 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -456,7 +450,7 @@ class KnowledgeServiceImpl implements IKnowledgeService {
}
}
@Override
@Override
public
Result
<?>
doImportInfo
(
HttpServletRequest
request
)
{
public
Result
<?>
doImportInfo
(
HttpServletRequest
request
,
String
userId
)
{
MultipartHttpServletRequest
multipartRequest
=
(
MultipartHttpServletRequest
)
request
;
MultipartHttpServletRequest
multipartRequest
=
(
MultipartHttpServletRequest
)
request
;
Map
<
String
,
MultipartFile
>
fileMap
=
multipartRequest
.
getFileMap
();
Map
<
String
,
MultipartFile
>
fileMap
=
multipartRequest
.
getFileMap
();
if
(
fileMap
.
size
()
<
1
)
{
if
(
fileMap
.
size
()
<
1
)
{
...
@@ -466,7 +460,7 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -466,7 +460,7 @@ class KnowledgeServiceImpl implements IKnowledgeService {
int
index
=
multipartFile
.
getOriginalFilename
().
lastIndexOf
(
"."
);
int
index
=
multipartFile
.
getOriginalFilename
().
lastIndexOf
(
"."
);
String
fileSuffix
=
multipartFile
.
getOriginalFilename
().
substring
(
index
+
1
);
String
fileSuffix
=
multipartFile
.
getOriginalFilename
().
substring
(
index
+
1
);
if
(
"doc"
.
equals
(
fileSuffix
)
||
"docx"
.
equals
(
fileSuffix
)
||
"xls"
.
equals
(
fileSuffix
)
||
"xlsx"
.
equals
(
fileSuffix
))
{
if
(
"doc"
.
equals
(
fileSuffix
)
||
"docx"
.
equals
(
fileSuffix
)
||
"xls"
.
equals
(
fileSuffix
)
||
"xlsx"
.
equals
(
fileSuffix
))
{
asyncService
.
doimport
(
request
,
multipartFile
,
fileSuffix
);
asyncService
.
doimport
(
request
,
fileSuffix
,
userId
);
return
Result
.
OK
(
"已进行处理"
);
return
Result
.
OK
(
"已进行处理"
);
}
else
{
}
else
{
return
Result
.
error
(
"不支持的文件类型"
);
return
Result
.
error
(
"不支持的文件类型"
);
...
@@ -475,11 +469,10 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -475,11 +469,10 @@ class KnowledgeServiceImpl implements IKnowledgeService {
}
}
@Override
@Override
public
void
doExcel
(
HttpServletRequest
request
,
String
fileSuffix
)
{
public
void
doExcel
(
HttpServletRequest
request
,
String
fileSuffix
,
String
userId
)
{
String
kbKnowledgeId
=
request
.
getParameter
(
"kbKnowledgeId"
);
String
kbKnowledgeId
=
request
.
getParameter
(
"kbKnowledgeId"
);
String
knowledgeProjectId
=
request
.
getParameter
(
"knowledgeProjectId"
);
String
knowledgeProjectId
=
request
.
getParameter
(
"knowledgeProjectId"
);
String
typeId
=
request
.
getParameter
(
"typeId"
);
String
typeId
=
request
.
getParameter
(
"typeId"
);
String
createBy
=
request
.
getParameter
(
"createBy"
);
try
{
try
{
MultipartHttpServletRequest
multipartRequest
=
(
MultipartHttpServletRequest
)
request
;
MultipartHttpServletRequest
multipartRequest
=
(
MultipartHttpServletRequest
)
request
;
Map
<
String
,
MultipartFile
>
fileMap
=
multipartRequest
.
getFileMap
();
Map
<
String
,
MultipartFile
>
fileMap
=
multipartRequest
.
getFileMap
();
...
@@ -488,9 +481,9 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -488,9 +481,9 @@ class KnowledgeServiceImpl implements IKnowledgeService {
// 将MultipartFile的文件内容保存到字节数组
// 将MultipartFile的文件内容保存到字节数组
byte
[]
fileData
=
multipartFile
.
getBytes
();
byte
[]
fileData
=
multipartFile
.
getBytes
();
List
<
List
<
String
>>
lists
=
ExcelExportUtil
.
readExcel
(
new
ByteArrayInputStream
(
fileData
),
1
,
9
);
List
<
List
<
String
>>
lists
=
ExcelExportUtil
.
readExcel
(
new
ByteArrayInputStream
(
fileData
),
1
,
5
);
//存入es
//存入es
importInfo
(
lists
,
kbKnowledgeId
,
knowledgeProjectId
,
typeId
,
createBy
);
importInfo
(
lists
,
kbKnowledgeId
,
knowledgeProjectId
,
typeId
,
userId
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -508,26 +501,37 @@ class KnowledgeServiceImpl implements IKnowledgeService {
...
@@ -508,26 +501,37 @@ class KnowledgeServiceImpl implements IKnowledgeService {
.
importData
(
1
)
.
importData
(
1
)
.
build
();
.
build
();
specialInformation
.
setId
(
codeGenerateUtil
.
geneIdNo
(
Constants
.
FINANCE
,
8
));
specialInformation
.
setId
(
codeGenerateUtil
.
geneIdNo
(
Constants
.
FINANCE
,
8
));
//判断正文是否为空
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
0
)))
{
if
(
StringUtils
.
isEmpty
(
info
.
get
(
3
)))
{
specialInformation
.
setTitle
(
info
.
get
(
0
));
log
.
error
(
"上传的数据为空"
);
}
else
{
return
;
log
.
error
(
"上传的数据{}标题为空,此条数据忽略"
,
info
.
get
(
0
));
continue
;
}
}
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
1
)))
{
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
1
)))
{
specialInformation
.
setTitle
(
info
.
get
(
1
));
specialInformation
.
setContents
(
Collections
.
singletonList
(
Content
.
builder
()
.
contentId
(
codeGenerateUtil
.
geneIdNo
(
Constants
.
FINANCE
,
8
))
.
content
(
info
.
get
(
1
)).
build
()));
}
else
{
log
.
error
(
"上传的数据{}正文为空,此条数据忽略"
,
info
.
get
(
0
));
continue
;
}
}
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
4
)))
{
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
2
)))
{
specialInformation
.
setAuthor
(
info
.
get
(
4
));
specialInformation
.
setAuthor
(
info
.
get
(
2
));
}
}
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
5
)))
{
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
3
)))
{
specialInformation
.
setOrigin
(
info
.
get
(
5
));
specialInformation
.
setOrigin
(
info
.
get
(
3
));
}
}
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
6
)))
{
if
(
StringUtils
.
isNotEmpty
(
info
.
get
(
4
)))
{
specialInformation
.
setPublishDate
(
EsDateUtil
.
esFieldDateFormat
(
info
.
get
(
6
)));
specialInformation
.
setPublishDate
(
EsDateUtil
.
esFieldDateFormat
(
info
.
get
(
4
)));
}
}
specialInformation
.
setDeleteFlag
(
0
);
specialInformation
.
setDeleteFlag
(
0
);
specialInformation
.
setCreateTime
(
cn
.
hutool
.
core
.
date
.
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd'T'HH:mm:ss"
));
specialInformation
.
setCreateTime
(
cn
.
hutool
.
core
.
date
.
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd'T'HH:mm:ss"
));
esOpUtil
.
docSavaByEntity
(
Constants
.
ES_DATA_FOR_KNOWLEDGE
,
specialInformation
.
getId
(),
specialInformation
);
esOpUtil
.
docSavaByEntity
(
Constants
.
ES_DATA_FOR_KNOWLEDGE
,
specialInformation
.
getId
(),
specialInformation
);
KnowledgeMessage
knowledgeMessage
=
new
KnowledgeMessage
();
BeanUtils
.
copyProperties
(
specialInformation
,
knowledgeMessage
);
knowledgeMessage
.
setType
(
specialInformation
.
getTypeId
());
knowledgeMessage
.
setContents
(
specialInformation
.
getContents
());
produceInfo
.
sendKnowledgeContents
(
knowledgeMessage
);
}
catch
(
NumberFormatException
e
)
{
}
catch
(
NumberFormatException
e
)
{
log
.
error
(
"处理异常"
);
log
.
error
(
"处理异常"
);
}
}
...
...
src/main/java/com/zzsn/knowbase/util/ExcelExportUtil.java
浏览文件 @
4f189a27
package
com
.
zzsn
.
knowbase
.
util
;
package
com
.
zzsn
.
knowbase
.
util
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelWriter
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
com.alibaba.excel.write.metadata.WriteSheet
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.style.HorizontalCellStyleStrategy
;
import
com.zzsn.knowbase.entity.KnowledgeExcel
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFDateUtil
;
import
org.apache.poi.hssf.usermodel.HSSFDateUtil
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.io.InputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.net.URLEncoder
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -66,4 +77,118 @@ public class ExcelExportUtil {
...
@@ -66,4 +77,118 @@ public class ExcelExportUtil {
return
xssfCell
.
getStringCellValue
();
return
xssfCell
.
getStringCellValue
();
}
}
}
}
public
static
File
getFileDir
()
{
// 构建上传文件的存放 "文件夹" 路径
String
fileDirPath
=
new
String
(
"src/main/resources/static/uploadFiles"
);
File
fileDir
=
new
File
(
fileDirPath
);
if
(!
fileDir
.
exists
())
{
// 递归生成文件夹
fileDir
.
mkdirs
();
}
return
fileDir
;
}
/**
* 导出
* @param data
* @param sheetName
* @param filePath
* @param clazz
* @throws Exception
*/
public
static
Boolean
writeExcelFront
(
List
data
,
String
sheetName
,
String
filePath
,
Class
clazz
)
throws
Exception
{
//表头样式
System
.
out
.
println
(
"开始写入"
);
WriteCellStyle
headWriteCellStyle
=
new
WriteCellStyle
();
//设置表头居中对齐
headWriteCellStyle
.
setHorizontalAlignment
(
HorizontalAlignment
.
CENTER
);
//内容样式
WriteCellStyle
contentWriteCellStyle
=
new
WriteCellStyle
();
//设置内容靠左对齐
contentWriteCellStyle
.
setHorizontalAlignment
(
HorizontalAlignment
.
LEFT
);
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
new
HorizontalCellStyleStrategy
(
headWriteCellStyle
,
contentWriteCellStyle
);
int
total
=
data
.
size
();
//总数
int
max
=
50000
;
//每sheet页允许最大数
int
avg
=
total
/
max
;
//sheet页个数
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
filePath
,
clazz
).
excelType
(
ExcelTypeEnum
.
XLSX
).
registerWriteHandler
(
horizontalCellStyleStrategy
).
build
();
try
{
for
(
int
j
=
0
;
j
<
avg
+
1
;
j
++)
{
String
sheetnames
=
sheetName
;
int
num
=
j
*
max
;
List
dataList1
=
new
ArrayList
<>();
if
(
StringUtils
.
isNotBlank
(
sheetnames
))
{
sheetnames
=
sheetnames
+
(
j
+
1
);
}
else
{
sheetnames
=
j
+
""
;
}
for
(
int
n
=
num
;
n
<
total
;
n
++)
{
//n即为每个sheet页应该开始的数
if
(
n
>=
num
+
50000
){
break
;
}
dataList1
.
add
(
data
.
get
(
n
));
//从总的list数据里面取出该处于哪个sheet页的数据,然后加进exportList,exportList即为当前sheet页应该有的数据
}
WriteSheet
writeSheet
=
EasyExcel
.
writerSheet
(
j
,
sheetnames
).
build
();
excelWriter
.
write
(
dataList1
,
writeSheet
);
}
}
finally
{
// 千万别忘记finish 会帮忙关闭流
if
(
excelWriter
!=
null
)
{
excelWriter
.
finish
();
}
}
System
.
out
.
println
(
"写入完成"
);
return
true
;
}
public
static
void
download
(
HttpServletResponse
response
,
String
filePath
,
boolean
delete
)
throws
UnsupportedEncodingException
{
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
response
.
setHeader
(
"Content-Disposition"
,
"attachment;fileName="
+
URLEncoder
.
encode
(
file
.
getName
(),
"utf8"
));
//加上设置大小 下载下来的excel文件才不会在打开前提示修复
response
.
addHeader
(
"Content-Length"
,
String
.
valueOf
(
file
.
length
()));
byte
[]
buffer
=
new
byte
[
1024
];
//输出流
OutputStream
os
=
null
;
FileInputStream
fis
=
null
;
BufferedInputStream
bis
=
null
;
try
{
fis
=
new
FileInputStream
(
file
);
bis
=
new
BufferedInputStream
(
fis
);
os
=
response
.
getOutputStream
();
int
i
=
bis
.
read
(
buffer
);
while
(
i
!=
-
1
)
{
os
.
write
(
buffer
);
os
.
flush
();
i
=
bis
.
read
(
buffer
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
os
!=
null
)
{
os
.
close
();
}
if
(
fis
!=
null
)
{
fis
.
close
();
}
if
(
bis
!=
null
)
{
bis
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
delete
)
{
//文件下载结束后,删除上传到项目的文件
file
.
delete
();
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论