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
2482e874
Commit
2482e874
authored
Sep 20, 2023
by
shentao
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature' into 'release'
2023/09/20 摘要批量提取接口访问异常处理、excel写入补充文本长度截取 See merge request
!395
parents
94e91895
3bd7cf71
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
13 deletions
+31
-13
src/main/java/com/zhiwei/brandkbs2/controller/app/AppToolsetController.java
+30
-13
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
+1
-0
No files found.
src/main/java/com/zhiwei/brandkbs2/controller/app/AppToolsetController.java
View file @
2482e874
...
@@ -17,6 +17,8 @@ import com.zhiwei.brandkbs2.util.RedisUtil;
...
@@ -17,6 +17,8 @@ import com.zhiwei.brandkbs2.util.RedisUtil;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
...
@@ -41,6 +43,7 @@ import java.util.*;
...
@@ -41,6 +43,7 @@ import java.util.*;
@Api
(
tags
=
"工具集"
,
description
=
"工具集"
)
@Api
(
tags
=
"工具集"
,
description
=
"工具集"
)
@Auth
(
role
=
RoleEnum
.
CUSTOMER
)
@Auth
(
role
=
RoleEnum
.
CUSTOMER
)
public
class
AppToolsetController
{
public
class
AppToolsetController
{
public
static
final
Logger
log
=
LogManager
.
getLogger
(
AppToolsetController
.
class
);
@Resource
(
name
=
"redisUtil"
)
@Resource
(
name
=
"redisUtil"
)
private
RedisUtil
redisUtil
;
private
RedisUtil
redisUtil
;
...
@@ -163,10 +166,17 @@ public class AppToolsetController {
...
@@ -163,10 +166,17 @@ public class AppToolsetController {
* @param projectId 项目id
* @param projectId 项目id
* @return
* @return
*/
*/
private
JSONObject
getUrlInfo
(
String
url
,
String
projectId
){
private
JSONObject
getUrlInfo
(
String
url
,
String
projectId
)
{
String
linkedGroupId
=
projectService
.
getProjectVOById
(
projectId
).
getBrandLinkedGroupId
();
JSONObject
jsonObject
;
JSONObject
jsonObject
=
restTemplate
.
getForEntity
(
articleInfoUrl
,
JSONObject
.
class
,
url
,
linkedGroupId
,
UserThreadLocal
.
getNickname
()).
getBody
();
// 即使抛出异常(大概率会是timeout),也要保证批量时其他链接正常执行
if
(
Objects
.
isNull
(
jsonObject
)
||
!
jsonObject
.
getBoolean
(
"status"
)){
try
{
String
linkedGroupId
=
projectService
.
getProjectVOById
(
projectId
).
getBrandLinkedGroupId
();
jsonObject
=
restTemplate
.
getForEntity
(
articleInfoUrl
,
JSONObject
.
class
,
url
,
linkedGroupId
,
UserThreadLocal
.
getNickname
()).
getBody
();
}
catch
(
Exception
e
)
{
log
.
info
(
"url:{},访问链接信息提取接口异常-"
,
url
,
e
);
return
null
;
}
if
(
Objects
.
isNull
(
jsonObject
)
||
!
jsonObject
.
getBoolean
(
"status"
))
{
return
null
;
return
null
;
}
}
return
jsonObject
.
getJSONObject
(
"data"
);
return
jsonObject
.
getJSONObject
(
"data"
);
...
@@ -178,16 +188,23 @@ public class AppToolsetController {
...
@@ -178,16 +188,23 @@ public class AppToolsetController {
* @return
* @return
*/
*/
private
String
getArticleSummaryResult
(
String
text
){
private
String
getArticleSummaryResult
(
String
text
){
// 即使抛出异常(大概率会是timeout),也要保证批量时其他链接正常执行
String
errorString
=
"访问超时,请稍后重试此条数据"
;
if
(
Objects
.
isNull
(
text
)){
if
(
Objects
.
isNull
(
text
)){
return
null
;
return
errorString
;
}
try
{
// 拼接提示词模板
String
resultText
=
TEXT_SUMMARY_PREVIOUS
+
StringUtils
.
substring
(
text
,
0
,
5000
);
// 请求参数 请求头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
TEXT_PLAIN
);
HttpEntity
<
String
>
request
=
new
HttpEntity
<>(
resultText
,
headers
);
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
articleSummaryUrl
,
request
,
String
.
class
);
return
response
.
getBody
();
}
catch
(
Exception
e
){
log
.
info
(
"访问摘要提取接口异常-"
,
e
);
return
errorString
;
}
}
// 拼接提示词模板
String
resultText
=
TEXT_SUMMARY_PREVIOUS
+
StringUtils
.
substring
(
text
,
0
,
5000
);
// 请求参数 请求头
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
TEXT_PLAIN
);
HttpEntity
<
String
>
request
=
new
HttpEntity
<>(
resultText
,
headers
);
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
articleSummaryUrl
,
request
,
String
.
class
);
return
response
.
getBody
();
}
}
}
}
src/main/java/com/zhiwei/brandkbs2/easyexcel/EasyExcelUtil.java
View file @
2482e874
...
@@ -107,6 +107,7 @@ public class EasyExcelUtil {
...
@@ -107,6 +107,7 @@ public class EasyExcelUtil {
*/
*/
public
static
<
T
>
void
write
(
String
filePath
,
String
sheetName
,
Class
<
T
>
clazz
,
List
<
T
>
datas
)
{
public
static
<
T
>
void
write
(
String
filePath
,
String
sheetName
,
Class
<
T
>
clazz
,
List
<
T
>
datas
)
{
try
{
try
{
formatExcelExports
(
clazz
,
datas
);
EasyExcel
.
write
(
filePath
,
clazz
).
sheet
(
sheetName
).
doWrite
(
datas
);
EasyExcel
.
write
(
filePath
,
clazz
).
sheet
(
sheetName
).
doWrite
(
datas
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"file:{},write error:"
,
filePath
,
e
);
log
.
error
(
"file:{},write error:"
,
filePath
,
e
);
...
...
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