Commit 6453ee8b by shentao

Merge branch 'feature' into 'dev'

2023/09/20 摘要提取接口访问异常处理、公告排序调整

See merge request !394
parents 33d92be7 0e447e4b
...@@ -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) {
JSONObject jsonObject;
// 即使抛出异常(大概率会是timeout),也要保证批量时其他链接正常执行
try {
String linkedGroupId = projectService.getProjectVOById(projectId).getBrandLinkedGroupId(); String linkedGroupId = projectService.getProjectVOById(projectId).getBrandLinkedGroupId();
JSONObject jsonObject = restTemplate.getForEntity(articleInfoUrl, JSONObject.class, url, linkedGroupId, UserThreadLocal.getNickname()).getBody(); jsonObject = restTemplate.getForEntity(articleInfoUrl, JSONObject.class, url, linkedGroupId, UserThreadLocal.getNickname()).getBody();
if (Objects.isNull(jsonObject) || !jsonObject.getBoolean("status")){ } 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,9 +188,12 @@ public class AppToolsetController { ...@@ -178,9 +188,12 @@ 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); String resultText = TEXT_SUMMARY_PREVIOUS + StringUtils.substring(text, 0, 5000);
// 请求参数 请求头 // 请求参数 请求头
...@@ -189,5 +202,9 @@ public class AppToolsetController { ...@@ -189,5 +202,9 @@ public class AppToolsetController {
HttpEntity<String> request = new HttpEntity<>(resultText, headers); HttpEntity<String> request = new HttpEntity<>(resultText, headers);
ResponseEntity<String> response = restTemplate.postForEntity(articleSummaryUrl, request, String.class); ResponseEntity<String> response = restTemplate.postForEntity(articleSummaryUrl, request, String.class);
return response.getBody(); return response.getBody();
}catch (Exception e){
log.info("访问摘要提取接口异常-", e);
return errorString;
}
} }
} }
...@@ -81,6 +81,7 @@ public class NoticeInfoServiceImpl implements NoticeInfoService { ...@@ -81,6 +81,7 @@ public class NoticeInfoServiceImpl implements NoticeInfoService {
if (StringUtils.isNotBlank(keyword)) { if (StringUtils.isNotBlank(keyword)) {
noticeInfoDao.addKeywordFuzz(query, keyword, "title"); noticeInfoDao.addKeywordFuzz(query, keyword, "title");
} }
query.with(Sort.by(Sort.Direction.DESC, "cTime"));
long total = noticeInfoDao.count(query); long total = noticeInfoDao.count(query);
mongoUtil.start(page, size, query); mongoUtil.start(page, size, query);
List<NoticeInfo> noticeInfoList = noticeInfoDao.findList(query); List<NoticeInfo> noticeInfoList = noticeInfoDao.findList(query);
...@@ -112,6 +113,7 @@ public class NoticeInfoServiceImpl implements NoticeInfoService { ...@@ -112,6 +113,7 @@ public class NoticeInfoServiceImpl implements NoticeInfoService {
Query query = new Query(); Query query = new Query();
query.addCriteria(Criteria.where("start").is(true)); query.addCriteria(Criteria.where("start").is(true));
query.addCriteria(Criteria.where("show").is(true)); query.addCriteria(Criteria.where("show").is(true));
query.with(Sort.by(Sort.Direction.DESC, "cTime"));
long total = noticeInfoDao.count(query); long total = noticeInfoDao.count(query);
mongoUtil.start(page, size, query); mongoUtil.start(page, size, query);
List<NoticeInfo> noticeInfoList = noticeInfoDao.findList(query); List<NoticeInfo> noticeInfoList = noticeInfoDao.findList(query);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment