Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
brandkbs2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenjunjie
brandkbs2
Commits
79975002
Commit
79975002
authored
Sep 19, 2023
by
陈健智
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传任务调整
parent
07da5aee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
46 deletions
+38
-46
src/main/java/com/zhiwei/brandkbs2/aop/AopDownloadTask.java
+8
-2
src/main/java/com/zhiwei/brandkbs2/controller/app/AppDownloadController.java
+0
-0
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
+30
-44
No files found.
src/main/java/com/zhiwei/brandkbs2/aop/AopDownloadTask.java
View file @
79975002
package
com
.
zhiwei
.
brandkbs2
.
aop
;
package
com
.
zhiwei
.
brandkbs2
.
aop
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.exception.ExceptionCast
;
import
com.zhiwei.brandkbs2.exception.ExceptionCast
;
import
com.zhiwei.brandkbs2.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
...
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
...
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.Objects
;
/**
/**
* @author cjz
* @author cjz
...
@@ -34,7 +36,7 @@ public class AopDownloadTask {
...
@@ -34,7 +36,7 @@ public class AopDownloadTask {
@Resource
(
name
=
"downloadTaskServiceImpl"
)
@Resource
(
name
=
"downloadTaskServiceImpl"
)
DownloadTaskService
downloadTaskService
;
DownloadTaskService
downloadTaskService
;
@Around
(
value
=
"execution(public * com..controller..app..AppDownloadController.*(..)))"
)
@Around
(
value
=
"execution(public * com..controller..app..AppDownloadController.*(..))
|| execution(public * com..controller..app..AppToolsetController.getBatchArticleSummary(..))
)"
)
public
Object
around
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
public
Object
around
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Signature
signature
=
joinPoint
.
getSignature
();
Signature
signature
=
joinPoint
.
getSignature
();
Method
method
=
((
MethodSignature
)
signature
).
getMethod
();
Method
method
=
((
MethodSignature
)
signature
).
getMethod
();
...
@@ -53,7 +55,11 @@ public class AopDownloadTask {
...
@@ -53,7 +55,11 @@ public class AopDownloadTask {
ExceptionCast
.
cast
(
CommonCodeEnum
.
FAIL
,
"下载异常"
,
e
);
ExceptionCast
.
cast
(
CommonCodeEnum
.
FAIL
,
"下载异常"
,
e
);
}
}
// 更新下载任务
// 更新下载任务
fileAddress
=
((
ResponseResult
)
proceed
).
getData
().
toString
();
if
(
Objects
.
equals
(
method
.
getName
(),
"getBatchArticleSummary"
)){
fileAddress
=
JSONObject
.
parseObject
(((
ResponseResult
)
proceed
).
getData
().
toString
()).
getString
(
"filePath"
);
}
else
{
fileAddress
=
((
ResponseResult
)
proceed
).
getData
().
toString
();
}
downloadTaskService
.
updateDownloadTask
(
taskId
,
100
,
DownloadTask
.
Status
.
FINISH
.
getName
(),
fileAddress
);
downloadTaskService
.
updateDownloadTask
(
taskId
,
100
,
DownloadTask
.
Status
.
FINISH
.
getName
(),
fileAddress
);
return
proceed
;
return
proceed
;
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/controller/app/AppDownloadController.java
View file @
79975002
This diff is collapsed.
Click to expand it.
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
View file @
79975002
...
@@ -8,6 +8,7 @@ import com.alibaba.excel.read.metadata.ReadSheet;
...
@@ -8,6 +8,7 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import
com.alibaba.excel.write.metadata.WriteSheet
;
import
com.alibaba.excel.write.metadata.WriteSheet
;
import
com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO
;
import
com.zhiwei.brandkbs2.easyexcel.config.ReadExcelDTO
;
import
com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO
;
import
com.zhiwei.brandkbs2.easyexcel.config.WriteExcelDTO
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
...
@@ -113,6 +114,28 @@ public class EasyExcelUtil {
...
@@ -113,6 +114,28 @@ public class EasyExcelUtil {
}
}
/**
/**
* 写单个sheet
* @param filePath 文件路径
* @param input 文件输入流
*/
public
static
void
write
(
String
filePath
,
InputStream
input
){
try
{
FileOutputStream
output
=
new
FileOutputStream
(
filePath
);
ReadableByteChannel
inputChannel
=
Channels
.
newChannel
(
input
);
WritableByteChannel
outputChannel
=
Channels
.
newChannel
(
output
);
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
10240
);
long
size
=
0
;
while
(
inputChannel
.
read
(
buffer
)
!=
-
1
)
{
buffer
.
flip
();
size
+=
outputChannel
.
write
(
buffer
);
buffer
.
clear
();
}
}
catch
(
Exception
e
){
log
.
error
(
"file:{},write error:"
,
filePath
,
e
);
}
}
/**
* 写多个sheet
* 写多个sheet
*
*
* @param filePath 文件路径
* @param filePath 文件路径
...
@@ -198,52 +221,15 @@ public class EasyExcelUtil {
...
@@ -198,52 +221,15 @@ public class EasyExcelUtil {
}
}
/**
/**
* 将excel文件保存至指定路径
* 生成excel路径
* @param filePath
* @param filePath 文件保存路径
* @param fileName
* @param projectName 项目名
* @param sheetName
* @param nickName 昵称
* @param clazz
* @param fileName 文件名
* @param datas
* @param <T>
*/
public
static
<
T
>
String
saveExcelWithPath
(
String
filePath
,
String
fileName
,
String
sheetName
,
Class
<
T
>
clazz
,
List
<
T
>
datas
){
try
{
formatExcelExports
(
clazz
,
datas
);
String
fileAddress
=
filePath
+
fileName
+
".xlsx"
;
FileOutputStream
out
=
new
FileOutputStream
(
fileAddress
);
EasyExcel
.
write
(
out
,
clazz
).
sheet
(
sheetName
).
doWrite
(
datas
);
return
fileAddress
;
}
catch
(
Exception
e
){
log
.
error
(
"file:{},saveExcelWithPath error:"
,
fileName
,
e
);
return
null
;
}
}
/**
* InputStream转换excel文件保存至指定路径
* @param filePath
* @param fileName
* @param input
* @return
* @return
*/
*/
public
static
String
saveExcelWithPath
(
String
filePath
,
String
fileName
,
InputStream
input
){
public
static
String
generateExcelFilePath
(
String
filePath
,
String
projectName
,
String
nickName
,
String
fileName
){
try
{
return
filePath
+
Tools
.
concat
(
projectName
,
nickName
,
System
.
currentTimeMillis
(),
fileName
)
+
".xlsx"
;
String
fileAddress
=
filePath
+
fileName
+
".xlsx"
;
FileOutputStream
output
=
new
FileOutputStream
(
fileAddress
);
ReadableByteChannel
inputChannel
=
Channels
.
newChannel
(
input
);
WritableByteChannel
outputChannel
=
Channels
.
newChannel
(
output
);
ByteBuffer
buffer
=
ByteBuffer
.
allocateDirect
(
10240
);
long
size
=
0
;
while
(
inputChannel
.
read
(
buffer
)
!=
-
1
)
{
buffer
.
flip
();
size
+=
outputChannel
.
write
(
buffer
);
buffer
.
clear
();
}
return
fileAddress
;
}
catch
(
Exception
e
){
log
.
error
(
"file:{},saveExcelWithPath error:"
,
fileName
,
e
);
return
null
;
}
}
}
private
static
<
T
>
void
formatExcelExports
(
Class
<
T
>
clazz
,
List
<
T
>
datas
){
private
static
<
T
>
void
formatExcelExports
(
Class
<
T
>
clazz
,
List
<
T
>
datas
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment