提交 2b4f07b3 作者: 925993793@qq.com

增加翻译接口逻辑

上级 a42d3e4d
package com.zzsn.event.controller; package com.zzsn.event.controller;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzsn.event.constant.Constants; import com.zzsn.event.constant.Constants;
import com.zzsn.event.constant.Result; import com.zzsn.event.constant.Result;
...@@ -7,6 +8,8 @@ import com.zzsn.event.entity.Event; ...@@ -7,6 +8,8 @@ import com.zzsn.event.entity.Event;
import com.zzsn.event.es.EsService; import com.zzsn.event.es.EsService;
import com.zzsn.event.service.EventSimpleService; import com.zzsn.event.service.EventSimpleService;
import com.zzsn.event.service.IEventService; import com.zzsn.event.service.IEventService;
import com.zzsn.event.util.HttpUtil;
import com.zzsn.event.util.ObjectUtil;
import com.zzsn.event.util.user.UserUtil; import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo; import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
...@@ -16,6 +19,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -16,6 +19,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -42,6 +46,8 @@ public class EventDataController { ...@@ -42,6 +46,8 @@ public class EventDataController {
@Autowired @Autowired
private IXxlJobInfoService iXxlJobInfoService; private IXxlJobInfoService iXxlJobInfoService;
@Value("${translate.url:}")
private String TRANSLATE_URL;
/** /**
* 事件分页列表-门户 * 事件分页列表-门户
...@@ -147,6 +153,34 @@ public class EventDataController { ...@@ -147,6 +153,34 @@ public class EventDataController {
} }
/** /**
* 翻译
*
* @param transferData 但翻译文本
* @author lkg
* @date 2024/8/21
*/
@PostMapping("/translate")
public Result<?> translate(@RequestBody SubjectDataVo transferData){
TranslateVO translateVO = new TranslateVO();
translateVO.setFrom("auto");
translateVO.setTo("zh-CN");
List<String> content = new ArrayList<>();
content.add(transferData.getTitle());
content.add(transferData.getSummary());
content.add(transferData.getContent());
translateVO.setContent(content);
List<String> data = new ArrayList<>();
try {
String s = HttpUtil.doPost(TRANSLATE_URL, ObjectUtil.objectToJSONObject(translateVO), 10000);
data = JSONArray.parseArray(s, String.class);
} catch (Exception e) {
log.error("翻译请求失败!");
e.printStackTrace();
}
return Result.OK(data);
}
/**
* 单篇文章热词 * 单篇文章热词
* *
* @param index 索引名称 * @param index 索引名称
......
...@@ -92,7 +92,7 @@ public class EsService { ...@@ -92,7 +92,7 @@ public class EsService {
List<SubjectDataVo> allList = new ArrayList<>(); List<SubjectDataVo> allList = new ArrayList<>();
AtomicBoolean flag = new AtomicBoolean(true); AtomicBoolean flag = new AtomicBoolean(true);
AtomicInteger pageNo = new AtomicInteger(1); AtomicInteger pageNo = new AtomicInteger(1);
int size = 30; int size = 300;
do { do {
CompletableFuture<List<SubjectDataVo>> async = CompletableFuture.supplyAsync(() -> { CompletableFuture<List<SubjectDataVo>> async = CompletableFuture.supplyAsync(() -> {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
......
...@@ -30,6 +30,8 @@ public class SubjectDataVo { ...@@ -30,6 +30,8 @@ public class SubjectDataVo {
private String publishDate; private String publishDate;
//作者 //作者
private String author; private String author;
//语种
private String lang;
//索引名称 //索引名称
private String index; private String index;
//重复数 //重复数
......
package com.zzsn.event.vo;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* 翻译参数
*
* @author lkg
* @date 2024/8/21
*/
@Getter
@Setter
public class TranslateVO {
private String from;
private String to;
private List<String> content;
}
...@@ -132,3 +132,5 @@ scoreRule: ...@@ -132,3 +132,5 @@ scoreRule:
monthScore: 5 monthScore: 5
yearScore: 3 yearScore: 3
beforeYearScore: 1 beforeYearScore: 1
translate:
url: http://114.116.116.241:8018/translate/getTranslateInfoWithTag
...@@ -128,3 +128,5 @@ scoreRule: ...@@ -128,3 +128,5 @@ scoreRule:
monthScore: 5 monthScore: 5
yearScore: 3 yearScore: 3
beforeYearScore: 1 beforeYearScore: 1
translate:
url: http://192.168.200.133:8018/translate/getTranslateInfoWithTag
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论