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
96c29d53
Commit
96c29d53
authored
Sep 25, 2023
by
陈健智
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
工具库-摘要提取次数修复
parent
3bd7cf71
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
14 deletions
+53
-14
src/main/java/com/zhiwei/brandkbs2/controller/app/AppToolsetController.java
+13
-8
src/main/java/com/zhiwei/brandkbs2/util/RedisUtil.java
+2
-6
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
+38
-0
No files found.
src/main/java/com/zhiwei/brandkbs2/controller/app/AppToolsetController.java
View file @
96c29d53
...
...
@@ -14,6 +14,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult;
import
com.zhiwei.brandkbs2.pojo.Project
;
import
com.zhiwei.brandkbs2.service.ProjectService
;
import
com.zhiwei.brandkbs2.util.RedisUtil
;
import
com.zhiwei.brandkbs2.util.Tools
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -31,6 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
/**
* @author cjz
...
...
@@ -79,7 +81,7 @@ public class AppToolsetController {
String
text
=
info
.
getString
(
"content"
);
String
articleSummaryResult
=
getArticleSummaryResult
(
text
);
// 剩余次数限制
String
redisKey
=
RedisUtil
.
getToolsetArticleSummaryLimitKey
(
UserThreadLocal
.
getProjectId
()
,
UserThreadLocal
.
getUserId
()
);
String
redisKey
=
RedisUtil
.
getToolsetArticleSummaryLimitKey
(
UserThreadLocal
.
getProjectId
());
String
redisResult
=
redisUtil
.
get
(
redisKey
);
int
usedCount
=
1
;
if
(
Objects
.
nonNull
(
redisResult
)){
...
...
@@ -88,9 +90,9 @@ public class AppToolsetController {
return
ResponseResult
.
failure
(
"本日摘要提取次数已达上限"
);
}
usedCount
=
redisCount
+
1
;
redisUtil
.
getAndSet
(
redisKey
,
String
.
valueOf
(
usedCount
)
);
redisUtil
.
setExpire
(
redisKey
,
String
.
valueOf
(
usedCount
),
Tools
.
getMillSecondNextDay
(),
TimeUnit
.
MILLISECONDS
);
}
else
{
redisUtil
.
setExpire
(
redisKey
,
String
.
valueOf
(
usedCount
));
redisUtil
.
setExpire
(
redisKey
,
String
.
valueOf
(
usedCount
)
,
Tools
.
getMillSecondNextDay
(),
TimeUnit
.
MILLISECONDS
);
}
res
.
put
(
"source"
,
info
.
get
(
"source"
));
res
.
put
(
"platform"
,
info
.
getString
(
"platform"
));
...
...
@@ -107,7 +109,7 @@ public class AppToolsetController {
JSONObject
res
=
new
JSONObject
();
Project
project
=
projectService
.
getProjectById
(
UserThreadLocal
.
getProjectId
());
// 调用前剩余可用次数
String
redisKey
=
RedisUtil
.
getToolsetArticleSummaryLimitKey
(
UserThreadLocal
.
getProjectId
()
,
UserThreadLocal
.
getUserId
()
);
String
redisKey
=
RedisUtil
.
getToolsetArticleSummaryLimitKey
(
UserThreadLocal
.
getProjectId
());
String
redisResult
=
redisUtil
.
get
(
redisKey
);
int
remainingCount
=
ARTICLE_SUMMARY_LIMIT
;
if
(
Objects
.
nonNull
(
redisResult
)){
...
...
@@ -117,11 +119,14 @@ public class AppToolsetController {
return
ResponseResult
.
failure
(
"本日摘要提取次数已达上限"
);
}
// excel信息提取
Map
<
String
,
String
>
map
=
new
LinkedHashMap
<>(
50
);
Map
<
String
,
String
>
map
=
new
LinkedHashMap
<>();
ReadExcelDTO
<
UploadArticleSummaryDTO
>
readExcel
=
new
ReadExcelDTO
<>();
readExcel
.
setClazz
(
UploadArticleSummaryDTO
.
class
);
readExcel
.
setAnalysisEventListener
(
new
ArticleSummaryListener
(
map
,
remainingCount
));
readExcel
.
setAnalysisEventListener
(
new
ArticleSummaryListener
(
map
));
EasyExcelUtil
.
read
(
file
,
readExcel
);
if
(
map
.
size
()
>
50
){
return
ResponseResult
.
failure
(
"超过每次批量提取上限50"
);
}
int
usedCount
=
0
;
// 本次批量调用次数
List
<
ExportArticleSummaryDTO
>
datas
=
new
ArrayList
<>(
50
);
// 摘要提取
...
...
@@ -140,7 +145,7 @@ public class AppToolsetController {
// 本次批量调用后剩余次数
remainingCount
=
remainingCount
-
usedCount
;
// 更新已用次数
redisUtil
.
getAndSet
(
redisKey
,
String
.
valueOf
(
ARTICLE_SUMMARY_LIMIT
-
remainingCount
)
);
redisUtil
.
setExpire
(
redisKey
,
String
.
valueOf
(
ARTICLE_SUMMARY_LIMIT
-
remainingCount
),
Tools
.
getMillSecondNextDay
(),
TimeUnit
.
MILLISECONDS
);
// excel输出到指定路径
String
filePath
=
EasyExcelUtil
.
generateExcelFilePath
(
brandkbsFilePath
,
project
.
getProjectName
(),
UserThreadLocal
.
getNickname
(),
"摘要提取结果"
);
EasyExcelUtil
.
write
(
filePath
,
"sheet1"
,
ExportArticleSummaryDTO
.
class
,
datas
);
...
...
@@ -152,7 +157,7 @@ public class AppToolsetController {
@ApiOperation
(
"摘要提取-剩余可用次数"
)
@GetMapping
(
"/article-summary/remaining"
)
public
ResponseResult
getArticleSummaryRemainingCount
(){
String
redisKey
=
RedisUtil
.
getToolsetArticleSummaryLimitKey
(
UserThreadLocal
.
getProjectId
()
,
UserThreadLocal
.
getUserId
()
);
String
redisKey
=
RedisUtil
.
getToolsetArticleSummaryLimitKey
(
UserThreadLocal
.
getProjectId
());
String
redisResult
=
redisUtil
.
get
(
redisKey
);
if
(
Objects
.
nonNull
(
redisResult
)){
return
ResponseResult
.
success
(
ARTICLE_SUMMARY_LIMIT
-
Integer
.
parseInt
(
redisResult
));
...
...
src/main/java/com/zhiwei/brandkbs2/util/RedisUtil.java
View file @
96c29d53
...
...
@@ -74,8 +74,8 @@ public class RedisUtil {
return
RedisKeyPrefix
.
PROJECT_WARN_NEW_CASE_CURSOR
+
projectId
;
}
public
static
String
getToolsetArticleSummaryLimitKey
(
String
projectId
,
String
userId
){
return
RedisKeyPrefix
.
TOOLSET_ARTICLE_SUMMARY_LIMIT
+
Tools
.
concat
(
projectId
,
userId
)
;
public
static
String
getToolsetArticleSummaryLimitKey
(
String
projectId
){
return
RedisKeyPrefix
.
TOOLSET_ARTICLE_SUMMARY_LIMIT
+
projectId
;
}
public
void
setExpire
(
String
key
,
String
value
,
long
timeout
,
TimeUnit
unit
)
{
...
...
@@ -97,10 +97,6 @@ public class RedisUtil {
return
stringRedisTemplate
.
opsForValue
().
get
(
key
);
}
public
void
getAndSet
(
String
key
,
String
newValue
){
stringRedisTemplate
.
opsForValue
().
getAndSet
(
key
,
newValue
);
}
public
Set
<
String
>
keys
(
String
key
)
{
return
stringRedisTemplate
.
keys
(
key
);
}
...
...
src/main/java/com/zhiwei/brandkbs2/util/Tools.java
View file @
96c29d53
...
...
@@ -4,6 +4,7 @@ import com.alibaba.excel.EasyExcel;
import
com.alibaba.excel.read.listener.PageReadListener
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.net.InternetDomainName
;
import
com.zhiwei.base.category.ClassCodec
;
import
com.zhiwei.base.entity.subclass.CompleteText
;
import
com.zhiwei.base.entity.subclass.IncompleteText
;
...
...
@@ -19,6 +20,7 @@ import com.zhiwei.brandkbs2.pojo.BaseMap;
import
com.zhiwei.qbjc.bean.pojo.common.MessagePlatform
;
import
com.zhiwei.qbjc.bean.pojo.common.Tag
;
import
com.zhiwei.qbjc.bean.tools.BeanTools
;
import
okhttp3.HttpUrl
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.MapUtils
;
...
...
@@ -1183,4 +1185,39 @@ public class Tools {
return
count
!=
mtags
.
size
();
}
/**
* 获取当前时间到第二天零点的毫秒数
* @return
*/
public
static
long
getMillSecondNextDay
(){
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTimeInMillis
()
-
System
.
currentTimeMillis
();
}
/**
* 获取url的域名
* @param url
* @return
*/
public
static
String
topDomainOfDomain
(
String
url
)
{
try
{
String
host
=
getHost
(
url
);
return
InternetDomainName
.
from
(
host
).
topPrivateDomain
().
toString
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
public
static
String
getHost
(
String
url
)
{
try
{
return
HttpUrl
.
parse
(
url
).
host
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
}
\ No newline at end of file
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