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
d6cb9456
Commit
d6cb9456
authored
Oct 20, 2023
by
shentao
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature' into 'dev'
2023/10/20 词云调整 See merge request
!405
parents
2dbdf471
1d47b444
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
16 deletions
+50
-16
src/main/java/com/zhiwei/brandkbs2/controller/app/AppToolsetController.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
+5
-0
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/HighWordArticleListener.java
+8
-0
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/HighWordKeywordListener.java
+7
-0
src/main/java/com/zhiwei/brandkbs2/service/ToolsetService.java
+1
-1
src/main/java/com/zhiwei/brandkbs2/service/impl/ToolsetServiceImpl.java
+28
-14
No files found.
src/main/java/com/zhiwei/brandkbs2/controller/app/AppToolsetController.java
View file @
d6cb9456
...
...
@@ -69,6 +69,6 @@ public class AppToolsetController {
@LogRecord
(
description
=
"工具库-词云提取"
)
public
ResponseResult
getHighWord
(
@RequestParam
MultipartFile
file
,
@ApiParam
(
name
=
"type"
,
value
=
"关键词|文章"
)
@RequestParam
String
type
){
return
ResponseResult
.
success
(
toolsetService
.
getHighWord
(
file
,
type
)
);
return
toolsetService
.
getHighWord
(
file
,
type
);
}
}
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
View file @
d6cb9456
...
...
@@ -16,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.Field
;
import
java.net.URLEncoder
;
...
...
@@ -66,6 +67,10 @@ public class EasyExcelUtil {
}
}
public
static
void
readWithoutTryCatch
(
MultipartFile
file
,
ReadExcelDTO
readExcelDTO
)
throws
IOException
{
EasyExcel
.
read
(
file
.
getInputStream
(),
readExcelDTO
.
getClazz
(),
readExcelDTO
.
getAnalysisEventListener
()).
sheet
().
doRead
();
}
/**
* 读取多个sheet
*
...
...
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/HighWordArticleListener.java
View file @
d6cb9456
...
...
@@ -6,6 +6,7 @@ import com.zhiwei.brandkbs2.easyexcel.dto.UploadHighWordArticleDTO;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author cjz
...
...
@@ -22,6 +23,13 @@ public class HighWordArticleListener extends AnalysisEventListener<UploadHighWor
}
@Override
public
void
invokeHeadMap
(
Map
<
Integer
,
String
>
headMap
,
AnalysisContext
context
){
if
(!
"序号"
.
equals
(
headMap
.
get
(
0
))
||
!
"标题"
.
equals
(
headMap
.
get
(
1
))
||
!
"文本"
.
equals
(
headMap
.
get
(
2
))
||
!
"链接"
.
equals
(
headMap
.
get
(
3
)))
{
throw
new
IllegalArgumentException
(
"表格格式有误"
);
}
}
@Override
public
void
invoke
(
UploadHighWordArticleDTO
data
,
AnalysisContext
context
)
{
if
(
StringUtils
.
isNotBlank
(
data
.
getContent
()))
{
contents
.
add
(
data
.
getContent
());
...
...
src/main/java/com/zhiwei/brandkbs2/easyexcel/listener/HighWordKeywordListener.java
View file @
d6cb9456
...
...
@@ -22,6 +22,13 @@ public class HighWordKeywordListener extends AnalysisEventListener<UploadHighWor
}
@Override
public
void
invokeHeadMap
(
Map
<
Integer
,
String
>
headMap
,
AnalysisContext
context
){
if
(!
"序号"
.
equals
(
headMap
.
get
(
0
))
||
!
"关键词"
.
equals
(
headMap
.
get
(
1
))
||
!
"词频"
.
equals
(
headMap
.
get
(
2
)))
{
throw
new
IllegalArgumentException
(
"表格格式有误"
);
}
}
@Override
public
void
invoke
(
UploadHighWordKeywordDTO
data
,
AnalysisContext
context
)
{
map
.
compute
(
data
.
getKeyword
(),
(
k
,
v
)
->{
if
(
Objects
.
isNull
(
v
)){
...
...
src/main/java/com/zhiwei/brandkbs2/service/ToolsetService.java
View file @
d6cb9456
...
...
@@ -68,5 +68,5 @@ public interface ToolsetService {
* @param type 类型 关键词|文章
* @return
*/
List
<
JSONObject
>
getHighWord
(
MultipartFile
file
,
String
type
);
ResponseResult
getHighWord
(
MultipartFile
file
,
String
type
);
}
src/main/java/com/zhiwei/brandkbs2/service/impl/ToolsetServiceImpl.java
View file @
d6cb9456
...
...
@@ -291,7 +291,7 @@ public class ToolsetServiceImpl implements ToolsetService {
}
@Override
public
List
<
JSONObject
>
getHighWord
(
MultipartFile
file
,
String
type
)
{
public
ResponseResult
getHighWord
(
MultipartFile
file
,
String
type
)
{
if
(
Objects
.
equals
(
"关键词"
,
type
)){
return
getKeywordHighWord
(
file
);
}
...
...
@@ -303,14 +303,21 @@ public class ToolsetServiceImpl implements ToolsetService {
* @param file excel文件
* @return
*/
private
List
<
JSONObject
>
getKeywordHighWord
(
MultipartFile
file
){
private
ResponseResult
getKeywordHighWord
(
MultipartFile
file
){
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
// excel信息提取
ReadExcelDTO
<
UploadHighWordKeywordDTO
>
readExcel
=
new
ReadExcelDTO
<>();
readExcel
.
setClazz
(
UploadHighWordKeywordDTO
.
class
);
readExcel
.
setAnalysisEventListener
(
new
HighWordKeywordListener
(
map
));
EasyExcelUtil
.
read
(
file
,
readExcel
);
Map
<
String
,
Integer
>
sortMap
=
Tools
.
sortMap
(
map
,
200
);
try
{
ReadExcelDTO
<
UploadHighWordKeywordDTO
>
readExcel
=
new
ReadExcelDTO
<>();
readExcel
.
setClazz
(
UploadHighWordKeywordDTO
.
class
);
readExcel
.
setAnalysisEventListener
(
new
HighWordKeywordListener
(
map
));
EasyExcelUtil
.
readWithoutTryCatch
(
file
,
readExcel
);
}
catch
(
Exception
e
){
return
ResponseResult
.
failure
(
"表格格式有误"
);
}
if
(
map
.
size
()
>
500
){
return
ResponseResult
.
failure
(
"表格关键词数量超过上限500"
);
}
Map
<
String
,
Integer
>
sortMap
=
Tools
.
sortMap
(
map
,
500
);
List
<
JSONObject
>
res
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
sortMap
.
entrySet
())
{
JSONObject
jsonObject
=
new
JSONObject
();
...
...
@@ -318,7 +325,7 @@ public class ToolsetServiceImpl implements ToolsetService {
jsonObject
.
put
(
"value"
,
entry
.
getValue
());
res
.
add
(
jsonObject
);
}
return
res
;
return
ResponseResult
.
success
(
res
)
;
}
/**
...
...
@@ -326,14 +333,21 @@ public class ToolsetServiceImpl implements ToolsetService {
* @param file excel文件
* @return
*/
private
List
<
JSONObject
>
getArticleHighWord
(
MultipartFile
file
){
private
ResponseResult
getArticleHighWord
(
MultipartFile
file
){
List
<
String
>
contents
=
new
ArrayList
<>();
// excel信息提取
ReadExcelDTO
<
UploadHighWordArticleDTO
>
readExcel
=
new
ReadExcelDTO
<>();
readExcel
.
setClazz
(
UploadHighWordArticleDTO
.
class
);
readExcel
.
setAnalysisEventListener
(
new
HighWordArticleListener
(
contents
));
EasyExcelUtil
.
read
(
file
,
readExcel
);
return
textUtil
.
getHighWordsJsonDifferentFieldName
(
contents
,
200
);
try
{
ReadExcelDTO
<
UploadHighWordArticleDTO
>
readExcel
=
new
ReadExcelDTO
<>();
readExcel
.
setClazz
(
UploadHighWordArticleDTO
.
class
);
readExcel
.
setAnalysisEventListener
(
new
HighWordArticleListener
(
contents
));
EasyExcelUtil
.
readWithoutTryCatch
(
file
,
readExcel
);
}
catch
(
Exception
e
){
return
ResponseResult
.
failure
(
"表格格式有误"
);
}
if
(
contents
.
size
()
>
500
){
return
ResponseResult
.
failure
(
"表格文章数量超过上限500"
);
}
return
ResponseResult
.
success
(
textUtil
.
getHighWordsJsonDifferentFieldName
(
contents
,
500
));
}
/**
...
...
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