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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
137 additions
and
111 deletions
+137
-111
src/main/java/com/zhiwei/brandkbs2/aop/AopDownloadTask.java
+8
-2
src/main/java/com/zhiwei/brandkbs2/controller/app/AppDownloadController.java
+99
-65
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
...
@@ -32,8 +32,7 @@ import org.springframework.web.bind.annotation.*;
...
@@ -32,8 +32,7 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.*
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -90,12 +89,12 @@ public class AppDownloadController extends BaseController {
...
@@ -90,12 +89,12 @@ public class AppDownloadController extends BaseController {
HttpEntity
<
String
>
requestEntity
=
new
HttpEntity
<>(
getHeaders
());
HttpEntity
<
String
>
requestEntity
=
new
HttpEntity
<>(
getHeaders
());
HttpEntity
<
org
.
springframework
.
core
.
io
.
Resource
>
entity
=
restTemplate
.
exchange
(
yuqingInterface
+
"/upload/template/form?projectId="
+
project
.
getBrandLinkedGroupId
(),
HttpMethod
.
GET
,
HttpEntity
<
org
.
springframework
.
core
.
io
.
Resource
>
entity
=
restTemplate
.
exchange
(
yuqingInterface
+
"/upload/template/form?projectId="
+
project
.
getBrandLinkedGroupId
(),
HttpMethod
.
GET
,
requestEntity
,
org
.
springframework
.
core
.
io
.
Resource
.
class
);
requestEntity
,
org
.
springframework
.
core
.
io
.
Resource
.
class
);
String
fileAddress
=
null
;
// excel写入至指定路径
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
project
.
getProjectName
(),
UserThreadLocal
.
getNickname
(),
project
.
getBrandName
()
+
"_稿件模板"
);
if
(
null
!=
entity
.
getBody
())
{
if
(
null
!=
entity
.
getBody
())
{
String
fileName
=
getFileNamePrefix
()
+
project
.
getBrandName
()
+
"_稿件模板"
;
EasyExcelUtil
.
write
(
filePath
,
entity
.
getBody
().
getInputStream
());
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
entity
.
getBody
().
getInputStream
());
}
}
return
ResponseResult
.
success
(
file
Address
);
return
ResponseResult
.
success
(
file
Path
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"稿件上传-稿件模板下载异常"
,
e
);
log
.
error
(
"稿件上传-稿件模板下载异常"
,
e
);
return
ResponseResult
.
failure
(
"稿件上传-稿件模板下载异常"
);
return
ResponseResult
.
failure
(
"稿件上传-稿件模板下载异常"
);
...
@@ -113,12 +112,13 @@ public class AppDownloadController extends BaseController {
...
@@ -113,12 +112,13 @@ public class AppDownloadController extends BaseController {
String
formType
=
info
.
getString
(
"formType"
);
String
formType
=
info
.
getString
(
"formType"
);
HttpEntity
<
JSONObject
>
requestEntity
=
new
HttpEntity
<>(
getHeaders
());
HttpEntity
<
JSONObject
>
requestEntity
=
new
HttpEntity
<>(
getHeaders
());
HttpEntity
<
org
.
springframework
.
core
.
io
.
Resource
>
entity
=
restTemplate
.
exchange
(
yuqingInterface
+
"/upload/list/download/file/"
+
id
+
"?formType="
+
formType
,
HttpMethod
.
GET
,
requestEntity
,
org
.
springframework
.
core
.
io
.
Resource
.
class
);
HttpEntity
<
org
.
springframework
.
core
.
io
.
Resource
>
entity
=
restTemplate
.
exchange
(
yuqingInterface
+
"/upload/list/download/file/"
+
id
+
"?formType="
+
formType
,
HttpMethod
.
GET
,
requestEntity
,
org
.
springframework
.
core
.
io
.
Resource
.
class
);
String
fileAddress
=
null
;
// excel写入至指定路径
String
projectName
=
projectService
.
getProjectVOById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
id
+
"_"
+
formType
);
if
(
null
!=
entity
.
getBody
())
{
if
(
null
!=
entity
.
getBody
())
{
String
fileName
=
getFileNamePrefix
()
+
id
+
"_"
+
formType
;
EasyExcelUtil
.
write
(
filePath
,
entity
.
getBody
().
getInputStream
());
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
entity
.
getBody
().
getInputStream
());
}
}
return
ResponseResult
.
success
(
file
Address
);
return
ResponseResult
.
success
(
file
Path
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"稿件上传-下载表格上传信息"
,
e
);
log
.
error
(
"稿件上传-下载表格上传信息"
,
e
);
return
ResponseResult
.
failure
(
"稿件上传下载表格上传信息"
);
return
ResponseResult
.
failure
(
"稿件上传下载表格上传信息"
);
...
@@ -132,9 +132,11 @@ public class AppDownloadController extends BaseController {
...
@@ -132,9 +132,11 @@ public class AppDownloadController extends BaseController {
String
projectId
=
UserThreadLocal
.
getProjectId
();
String
projectId
=
UserThreadLocal
.
getProjectId
();
List
<
ExportWordDTO
>
list
=
highWordService
.
downloadWord
(
projectId
);
List
<
ExportWordDTO
>
list
=
highWordService
.
downloadWord
(
projectId
);
ProjectVO
projectVO
=
projectService
.
getProjectVOById
(
projectId
);
ProjectVO
projectVO
=
projectService
.
getProjectVOById
(
projectId
);
String
fileName
=
getFileNamePrefix
()
+
projectVO
.
getBrandName
()
+
"_高频关键词"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportWordDTO
.
class
,
list
);
String
projectName
=
projectVO
.
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
projectVO
.
getBrandName
()
+
"_高频关键词"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportWordDTO
.
class
,
list
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"舆情列表高亮关键词"
)
@ApiOperation
(
"舆情列表高亮关键词"
)
...
@@ -144,9 +146,11 @@ public class AppDownloadController extends BaseController {
...
@@ -144,9 +146,11 @@ public class AppDownloadController extends BaseController {
String
projectId
=
UserThreadLocal
.
getProjectId
();
String
projectId
=
UserThreadLocal
.
getProjectId
();
List
<
ExportWordDTO
>
list
=
highlightWordService
.
downloadWord
(
projectId
);
List
<
ExportWordDTO
>
list
=
highlightWordService
.
downloadWord
(
projectId
);
ProjectVO
projectVO
=
projectService
.
getProjectVOById
(
projectId
);
ProjectVO
projectVO
=
projectService
.
getProjectVOById
(
projectId
);
String
fileName
=
getFileNamePrefix
()
+
projectVO
.
getBrandName
()
+
"_舆情列表高亮关键词"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportWordDTO
.
class
,
list
);
String
projectName
=
projectVO
.
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
projectVO
.
getBrandName
()
+
"_舆情列表高亮关键词"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportWordDTO
.
class
,
list
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"用户行为列表"
)
@ApiOperation
(
"用户行为列表"
)
...
@@ -162,10 +166,11 @@ public class AppDownloadController extends BaseController {
...
@@ -162,10 +166,11 @@ public class AppDownloadController extends BaseController {
@RequestParam
(
value
=
"behavior"
,
defaultValue
=
"true"
)
boolean
behavior
)
{
@RequestParam
(
value
=
"behavior"
,
defaultValue
=
"true"
)
boolean
behavior
)
{
List
<
ExportBehaviorDTO
>
downloadList
=
behaviorService
.
download
(
startTime
,
endTime
,
behavior
);
List
<
ExportBehaviorDTO
>
downloadList
=
behaviorService
.
download
(
startTime
,
endTime
,
behavior
);
String
behaviorName
=
behavior
?
"后台"
:
"前台"
;
String
behaviorName
=
behavior
?
"后台"
:
"前台"
;
String
sheetName
=
projectService
.
getProjectVOById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
()
+
"_"
+
behaviorName
;
// excel写入至指定路径
String
fileName
=
getFileNamePrefix
()
+
behaviorName
+
"_用户行为"
;
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
sheetName
,
ExportBehaviorDTO
.
class
,
downloadList
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
behaviorName
+
"_用户行为"
);
return
ResponseResult
.
success
(
fileAddress
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportBehaviorDTO
.
class
,
downloadList
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"用户操作记录列表"
)
@ApiOperation
(
"用户操作记录列表"
)
...
@@ -178,10 +183,11 @@ public class AppDownloadController extends BaseController {
...
@@ -178,10 +183,11 @@ public class AppDownloadController extends BaseController {
public
ResponseResult
downloadLogRecordList
(
@RequestParam
(
"startTime"
)
long
startTime
,
public
ResponseResult
downloadLogRecordList
(
@RequestParam
(
"startTime"
)
long
startTime
,
@RequestParam
(
"endTime"
)
long
endTime
)
{
@RequestParam
(
"endTime"
)
long
endTime
)
{
List
<
ExportUserLogRecordDTO
>
list
=
behaviorService
.
downloadUserLogRecord
(
startTime
,
endTime
);
List
<
ExportUserLogRecordDTO
>
list
=
behaviorService
.
downloadUserLogRecord
(
startTime
,
endTime
);
String
sheetName
=
projectService
.
getProjectVOById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
()
+
"_操作记录"
;
// excel写入至指定路径
String
fileName
=
getFileNamePrefix
()
+
"操作记录"
;
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
sheetName
,
ExportUserLogRecordDTO
.
class
,
list
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
"操作记录"
);
return
ResponseResult
.
success
(
fileAddress
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportUserLogRecordDTO
.
class
,
list
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"渠道列表"
)
@ApiOperation
(
"渠道列表"
)
...
@@ -200,10 +206,11 @@ public class AppDownloadController extends BaseController {
...
@@ -200,10 +206,11 @@ public class AppDownloadController extends BaseController {
@RequestParam
(
value
=
"show"
,
required
=
false
)
Boolean
show
,
@RequestParam
(
value
=
"show"
,
required
=
false
)
Boolean
show
,
@RequestParam
(
value
=
"keyword"
,
defaultValue
=
""
)
String
keyword
)
{
@RequestParam
(
value
=
"keyword"
,
defaultValue
=
""
)
String
keyword
)
{
List
<
ExportChannelDTO
>
downloadChannelList
=
channelService
.
findDownloadChannelList
(
contendId
,
emotion
,
platform
,
show
,
keyword
);
List
<
ExportChannelDTO
>
downloadChannelList
=
channelService
.
findDownloadChannelList
(
contendId
,
emotion
,
platform
,
show
,
keyword
);
String
brandName
=
projectService
.
getProjectByContendId
(
UserThreadLocal
.
getProjectId
(),
contendId
).
getBrandName
();
// excel写入至指定路径
String
fileName
=
getFileNamePrefix
()
+
brandName
+
"_渠道列表数据"
;
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
brandName
,
ExportChannelDTO
.
class
,
downloadChannelList
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
"渠道列表数据"
);
return
ResponseResult
.
success
(
fileAddress
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportChannelDTO
.
class
,
downloadChannelList
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"渠道稿件列表"
)
@ApiOperation
(
"渠道稿件列表"
)
...
@@ -212,9 +219,11 @@ public class AppDownloadController extends BaseController {
...
@@ -212,9 +219,11 @@ public class AppDownloadController extends BaseController {
@Auth
(
role
=
RoleEnum
.
COMMON_ADMIN
)
@Auth
(
role
=
RoleEnum
.
COMMON_ADMIN
)
public
ResponseResult
downloadArticleList
(
@RequestParam
(
value
=
"channelId"
)
String
channelId
)
{
public
ResponseResult
downloadArticleList
(
@RequestParam
(
value
=
"channelId"
)
String
channelId
)
{
List
<
ExportAdminChannelArticleDTO
>
downloadChannelArticleList
=
channelService
.
findDownloadChannelArticleList
(
channelId
);
List
<
ExportAdminChannelArticleDTO
>
downloadChannelArticleList
=
channelService
.
findDownloadChannelArticleList
(
channelId
);
String
fileName
=
getFileNamePrefix
()
+
channelId
+
"_渠道稿件列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
channelId
,
ExportAdminChannelArticleDTO
.
class
,
downloadChannelArticleList
);
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
channelId
+
"_渠道稿件列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
channelId
,
ExportAdminChannelArticleDTO
.
class
,
downloadChannelArticleList
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"渠道事件列表"
)
@ApiOperation
(
"渠道事件列表"
)
...
@@ -223,9 +232,11 @@ public class AppDownloadController extends BaseController {
...
@@ -223,9 +232,11 @@ public class AppDownloadController extends BaseController {
@Auth
(
role
=
RoleEnum
.
COMMON_ADMIN
)
@Auth
(
role
=
RoleEnum
.
COMMON_ADMIN
)
public
ResponseResult
downloadEventList
(
@RequestParam
(
value
=
"channelId"
)
String
channelId
)
{
public
ResponseResult
downloadEventList
(
@RequestParam
(
value
=
"channelId"
)
String
channelId
)
{
List
<
ExportAdminChannelEventDTO
>
downloadChannelEventList
=
channelService
.
findDownloadChannelEventList
(
channelId
);
List
<
ExportAdminChannelEventDTO
>
downloadChannelEventList
=
channelService
.
findDownloadChannelEventList
(
channelId
);
String
fileName
=
getFileNamePrefix
()
+
channelId
+
"_渠道事件列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
channelId
,
ExportAdminChannelEventDTO
.
class
,
downloadChannelEventList
);
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
channelId
+
"_渠道事件列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
channelId
,
ExportAdminChannelEventDTO
.
class
,
downloadChannelEventList
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"全网搜使用记录"
)
@ApiOperation
(
"全网搜使用记录"
)
...
@@ -237,16 +248,17 @@ public class AppDownloadController extends BaseController {
...
@@ -237,16 +248,17 @@ public class AppDownloadController extends BaseController {
Long
endTime
=
json
.
getLong
(
"endTime"
);
Long
endTime
=
json
.
getLong
(
"endTime"
);
boolean
day
=
json
.
getBooleanValue
(
"day"
);
boolean
day
=
json
.
getBooleanValue
(
"day"
);
List
<
JSONObject
>
collect
=
wholeSearchService
.
outputUsedList
(
personal
,
startTime
,
endTime
,
day
);
List
<
JSONObject
>
collect
=
wholeSearchService
.
outputUsedList
(
personal
,
startTime
,
endTime
,
day
);
String
fileName
=
getFileNamePrefix
()
+
startTime
+
"_"
+
endTime
+
"使用记录"
;
// excel写入至指定路径
String
fileAddress
=
null
;
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
startTime
+
"_"
+
endTime
+
"使用记录"
);
if
(
personal
)
{
if
(
personal
)
{
List
<
ExportWholeSearchRecordDTO
>
list
=
collect
.
stream
().
map
(
ExportWholeSearchRecordDTO:
:
createFromJSONObject
).
collect
(
Collectors
.
toList
());
List
<
ExportWholeSearchRecordDTO
>
list
=
collect
.
stream
().
map
(
ExportWholeSearchRecordDTO:
:
createFromJSONObject
).
collect
(
Collectors
.
toList
());
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet
"
,
ExportWholeSearchRecordDTO
.
class
,
list
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1
"
,
ExportWholeSearchRecordDTO
.
class
,
list
);
}
else
{
}
else
{
List
<
ExportLineDTO
>
list
=
collect
.
stream
().
map
(
ExportLineDTO:
:
createFromJSONObject
).
collect
(
Collectors
.
toList
());
List
<
ExportLineDTO
>
list
=
collect
.
stream
().
map
(
ExportLineDTO:
:
createFromJSONObject
).
collect
(
Collectors
.
toList
());
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet
"
,
ExportLineDTO
.
class
,
list
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1
"
,
ExportLineDTO
.
class
,
list
);
}
}
return
ResponseResult
.
success
(
file
Address
);
return
ResponseResult
.
success
(
file
Path
);
}
}
@ApiOperation
(
"项目关键词"
)
@ApiOperation
(
"项目关键词"
)
...
@@ -255,10 +267,10 @@ public class AppDownloadController extends BaseController {
...
@@ -255,10 +267,10 @@ public class AppDownloadController extends BaseController {
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
downloadArticles
(
@PathVariable
(
"pid"
)
String
pid
)
{
public
ResponseResult
downloadArticles
(
@PathVariable
(
"pid"
)
String
pid
)
{
ProjectVO
project
=
projectService
.
getProjectVOById
(
pid
);
ProjectVO
project
=
projectService
.
getProjectVOById
(
pid
);
String
fileName
=
getFileNamePrefix
()
+
project
.
getBrandName
()
+
"_命中关键词"
;
// excel写入至指定路径
String
file
Address
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
String
file
Path
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
project
.
getProjectName
(),
UserThreadLocal
.
getNickname
(),
project
.
getBrandName
()
+
"_命中关键词"
);
UploadKeywordDTO
.
class
,
UploadKeywordDTO
.
change2This
(
project
.
getHitKeywords
()));
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
UploadKeywordDTO
.
class
,
UploadKeywordDTO
.
change2This
(
project
.
getHitKeywords
()));
return
ResponseResult
.
success
(
file
Address
);
return
ResponseResult
.
success
(
file
Path
);
}
}
@ApiOperation
(
"舆情库原始数据"
)
@ApiOperation
(
"舆情库原始数据"
)
...
@@ -266,9 +278,11 @@ public class AppDownloadController extends BaseController {
...
@@ -266,9 +278,11 @@ public class AppDownloadController extends BaseController {
@LogRecord
(
description
=
"舆情库-原始数据导出"
,
values
=
{
"startTime"
,
"endTime"
,
"keyword"
,
"platforms"
,
"searchField"
},
entity
=
true
,
arguments
=
true
)
@LogRecord
(
description
=
"舆情库-原始数据导出"
,
values
=
{
"startTime"
,
"endTime"
,
"keyword"
,
"platforms"
,
"searchField"
},
entity
=
true
,
arguments
=
true
)
public
ResponseResult
exportOriginList
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
public
ResponseResult
exportOriginList
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
Pair
<
String
,
List
<
ExportAppYuqingDTO
>>
stringListPair
=
markDataService
.
downloadYuqingMarkList
(
markSearchDTO
);
Pair
<
String
,
List
<
ExportAppYuqingDTO
>>
stringListPair
=
markDataService
.
downloadYuqingMarkList
(
markSearchDTO
);
String
fileName
=
getFileNamePrefix
()
+
stringListPair
.
getLeft
()
+
"_原始数据列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportAppYuqingDTO
.
class
,
stringListPair
.
getRight
());
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
stringListPair
.
getLeft
()
+
"_原始数据列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportAppYuqingDTO
.
class
,
stringListPair
.
getRight
());
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"舆情库有效舆情数据"
)
@ApiOperation
(
"舆情库有效舆情数据"
)
...
@@ -276,9 +290,11 @@ public class AppDownloadController extends BaseController {
...
@@ -276,9 +290,11 @@ public class AppDownloadController extends BaseController {
@LogRecord
(
description
=
"舆情库-有效舆情导出"
,
values
=
{
"startTime"
,
"endTime"
,
"customTags"
,
"field"
,
"keyword"
,
"politicsLevel"
,
"mainBodyType"
,
"platforms"
,
"region"
,
"tags"
},
entity
=
true
,
arguments
=
true
)
@LogRecord
(
description
=
"舆情库-有效舆情导出"
,
values
=
{
"startTime"
,
"endTime"
,
"customTags"
,
"field"
,
"keyword"
,
"politicsLevel"
,
"mainBodyType"
,
"platforms"
,
"region"
,
"tags"
},
entity
=
true
,
arguments
=
true
)
public
ResponseResult
exportYuqingMarkList
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
public
ResponseResult
exportYuqingMarkList
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
Pair
<
String
,
List
<
ExportAppYuqingDTO
>>
stringListPair
=
markDataService
.
downloadYuqingMarkList
(
markSearchDTO
);
Pair
<
String
,
List
<
ExportAppYuqingDTO
>>
stringListPair
=
markDataService
.
downloadYuqingMarkList
(
markSearchDTO
);
String
fileName
=
getFileNamePrefix
()
+
stringListPair
.
getLeft
()
+
"_舆情列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportAppYuqingDTO
.
class
,
stringListPair
.
getRight
());
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
stringListPair
.
getLeft
()
+
"_舆情列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportAppYuqingDTO
.
class
,
stringListPair
.
getRight
());
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"渠道库文章列表"
)
@ApiOperation
(
"渠道库文章列表"
)
...
@@ -294,9 +310,11 @@ public class AppDownloadController extends BaseController {
...
@@ -294,9 +310,11 @@ public class AppDownloadController extends BaseController {
@RequestParam
(
"channelId"
)
String
channelId
,
@RequestParam
(
"channelId"
)
String
channelId
,
@RequestParam
(
value
=
"contendId"
,
defaultValue
=
"0"
)
String
contendId
)
{
@RequestParam
(
value
=
"contendId"
,
defaultValue
=
"0"
)
String
contendId
)
{
List
<
ExportAppChannelArticleDTO
>
exportAppChannelArticleDTOS
=
channelService
.
downloadArticlesByTime
(
startTime
,
endTime
,
channelId
,
contendId
);
List
<
ExportAppChannelArticleDTO
>
exportAppChannelArticleDTOS
=
channelService
.
downloadArticlesByTime
(
startTime
,
endTime
,
channelId
,
contendId
);
String
fileName
=
getFileNamePrefix
()
+
channelId
+
"稿件列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportAppChannelArticleDTO
.
class
,
exportAppChannelArticleDTOS
);
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
channelId
+
"稿件列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportAppChannelArticleDTO
.
class
,
exportAppChannelArticleDTOS
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"渠道库事件列表"
)
@ApiOperation
(
"渠道库事件列表"
)
...
@@ -312,18 +330,22 @@ public class AppDownloadController extends BaseController {
...
@@ -312,18 +330,22 @@ public class AppDownloadController extends BaseController {
@RequestParam
(
"channelId"
)
String
channelId
,
@RequestParam
(
"channelId"
)
String
channelId
,
@RequestParam
(
value
=
"contendId"
,
defaultValue
=
"0"
)
String
contendId
)
{
@RequestParam
(
value
=
"contendId"
,
defaultValue
=
"0"
)
String
contendId
)
{
List
<
ExportAppChannelEventDTO
>
exportAppChannelEventDTOS
=
channelService
.
downloadEventsByTime
(
startTime
,
endTime
,
channelId
,
contendId
);
List
<
ExportAppChannelEventDTO
>
exportAppChannelEventDTOS
=
channelService
.
downloadEventsByTime
(
startTime
,
endTime
,
channelId
,
contendId
);
String
fileName
=
getFileNamePrefix
()
+
channelId
+
"事件列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportAppChannelEventDTO
.
class
,
exportAppChannelEventDTOS
);
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
channelId
+
"事件列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportAppChannelEventDTO
.
class
,
exportAppChannelEventDTOS
);
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"竞品库竞品舆情"
)
@ApiOperation
(
"竞品库竞品舆情"
)
@PostMapping
(
value
=
"/contend/mark"
)
@PostMapping
(
value
=
"/contend/mark"
)
public
ResponseResult
exportContendMarkList
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
public
ResponseResult
exportContendMarkList
(
@RequestBody
MarkSearchDTO
markSearchDTO
)
{
Pair
<
String
,
List
<
ExportAppYuqingDTO
>>
stringListPair
=
markDataService
.
downloadContendMarkList
(
markSearchDTO
);
Pair
<
String
,
List
<
ExportAppYuqingDTO
>>
stringListPair
=
markDataService
.
downloadContendMarkList
(
markSearchDTO
);
String
fileName
=
getFileNamePrefix
()
+
stringListPair
.
getLeft
()
+
"_舆情列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportAppYuqingDTO
.
class
,
stringListPair
.
getRight
());
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
return
ResponseResult
.
success
(
fileAddress
);
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
"舆情列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportAppYuqingDTO
.
class
,
stringListPair
.
getRight
());
return
ResponseResult
.
success
(
filePath
);
}
}
@ApiOperation
(
"全网搜舆情"
)
@ApiOperation
(
"全网搜舆情"
)
...
@@ -347,12 +369,28 @@ public class AppDownloadController extends BaseController {
...
@@ -347,12 +369,28 @@ public class AppDownloadController extends BaseController {
}
}
}
}
List
<
ExportSearchWholeDTO
>
exportList
=
markDataService
.
exportSearchWhole
(
dto
);
List
<
ExportSearchWholeDTO
>
exportList
=
markDataService
.
exportSearchWhole
(
dto
);
String
fileName
=
getFileNamePrefix
()
+
"全网搜舆情列表数据"
;
// excel写入至指定路径
String
fileAddress
=
EasyExcelUtil
.
saveExcelWithPath
(
brandkbsFilePath
,
fileName
,
"sheet1"
,
ExportSearchWholeDTO
.
class
,
exportList
);
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
"全网搜舆情列表数据"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportSearchWholeDTO
.
class
,
exportList
);
if
(
dto
.
isExternalDataSource
())
{
if
(
dto
.
isExternalDataSource
())
{
wholeSearchService
.
decreaseRecord
(
dto
.
getSearch
(),
WholeSearchRecord
.
UsedType
.
output
,
exportList
.
size
());
wholeSearchService
.
decreaseRecord
(
dto
.
getSearch
(),
WholeSearchRecord
.
UsedType
.
output
,
exportList
.
size
());
}
}
return
ResponseResult
.
success
(
fileAddress
);
return
ResponseResult
.
success
(
filePath
);
}
@ApiOperation
(
"摘要提取批量模板"
)
@GetMapping
(
value
=
"/article-summary/template"
)
public
ResponseResult
downloadArticleSummaryTemplate
()
{
List
<
List
<
String
>>
head
=
new
ArrayList
<>();
head
.
add
(
Collections
.
singletonList
(
"序号"
));
head
.
add
(
Collections
.
singletonList
(
"链接"
));
head
.
add
(
Collections
.
singletonList
(
"文章内容"
));
// excel写入至指定路径
String
projectName
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
()).
getProjectName
();
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
projectName
,
UserThreadLocal
.
getNickname
(),
"摘要提取批量模板"
);
EasyExcelUtil
.
dynamicHeadWrite
(
filePath
,
"模板"
,
head
,
Collections
.
emptyList
());
return
ResponseResult
.
success
(
filePath
);
}
}
private
HttpHeaders
getHeaders
()
{
private
HttpHeaders
getHeaders
()
{
...
@@ -361,8 +399,4 @@ public class AppDownloadController extends BaseController {
...
@@ -361,8 +399,4 @@ public class AppDownloadController extends BaseController {
httpHeaders
.
set
(
"Content-Type"
,
"application/json"
);
httpHeaders
.
set
(
"Content-Type"
,
"application/json"
);
return
httpHeaders
;
return
httpHeaders
;
}
}
private
String
getFileNamePrefix
(){
return
UserThreadLocal
.
getProjectId
()
+
"_"
+
UserThreadLocal
.
getNickname
()
+
"_"
+
System
.
currentTimeMillis
()
+
"_"
;
}
}
}
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