parent
a86f84e4a1
commit
08e2a46c9a
|
|
@ -4,6 +4,8 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
|
|||
import com.xjs.english.domain.qo.translation.TranslationQo;
|
||||
import com.xjs.english.domain.vo.translation.TranslationVo;
|
||||
import com.xjs.english.service.TranslationService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -18,6 +20,7 @@ import static com.xjs.english.consts.TranslationTypeConst.YOUDAO;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("translation")
|
||||
@Api(tags = "业务模块-翻译管理")
|
||||
public class TranslationController {
|
||||
|
||||
@Autowired
|
||||
|
|
@ -26,6 +29,7 @@ public class TranslationController {
|
|||
private TranslationService baiDuTranslationServiceImpl;
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("翻译接口")
|
||||
public AjaxResult translation(@Validated @RequestBody TranslationQo translationQo) {
|
||||
TranslationVo translationVo=new TranslationVo();
|
||||
if (BAIDU.equals(translationQo.getTranslationType())) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class BaiDuTranslationQo {
|
|||
/**
|
||||
* 翻译目标语言
|
||||
*/
|
||||
private String to ;
|
||||
private String to ="auto";
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.xjs.english.domain.qo.translation;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
|
@ -12,6 +14,7 @@ import java.io.Serializable;
|
|||
* @create 2021-12-25
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "翻译Model",description="翻译条件")
|
||||
public class TranslationQo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
@ -19,18 +22,16 @@ public class TranslationQo implements Serializable {
|
|||
/**
|
||||
* 需要翻译的词(前端可以指定翻译词)
|
||||
*/
|
||||
@ApiModelProperty("翻译词")
|
||||
@NotBlank(message = "翻译内容不能为空")
|
||||
private String q="你傻吗,大傻逼?嗯,哈哈哈";
|
||||
|
||||
/**
|
||||
* 翻译目标语言(前端可以指定目标语言)
|
||||
*/
|
||||
private String to = "auto";
|
||||
|
||||
/**
|
||||
* 翻译api类型(例如:有道、谷歌、百度等)
|
||||
* 1、百度 2、有道 3、谷歌 4 ...
|
||||
*/
|
||||
@ApiModelProperty("翻译api类型(例如:有道、谷歌、百度等)")
|
||||
@NotNull(message = "翻译api类型不能为空")
|
||||
private Integer translationType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class YouDaoTranslationQo{
|
|||
/**
|
||||
* 目标语言(有道的目标语言无效,中转英、英转中)
|
||||
*/
|
||||
private String type;
|
||||
private String type="AUTO";
|
||||
|
||||
/**
|
||||
* 翻译的内容
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ public class BaiDuTranslationServiceImpl implements TranslationService {
|
|||
String sign = SecureUtil.md5(append);
|
||||
baiDuTranslationQo.setSign(sign);
|
||||
baiDuTranslationQo.setQ(translationQo.getQ());
|
||||
baiDuTranslationQo.setTo(translationQo.getTo());
|
||||
String translationStr = baiduFeignClient.translationApi(baiDuTranslationQo);
|
||||
JSONObject jsonObject = JSONObject.parseObject(translationStr);
|
||||
if(Objects.nonNull(jsonObject.getString("error_code"))){
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ public class YouDaoTranslationServiceImpl implements TranslationService {
|
|||
public TranslationVo translationApi(TranslationQo translationQo) {
|
||||
YouDaoTranslationQo youDaoTranslationQo = new YouDaoTranslationQo();
|
||||
youDaoTranslationQo.setI(translationQo.getQ());
|
||||
youDaoTranslationQo.setType(translationQo.getTo());
|
||||
|
||||
JSONObject translationApi = youDaoFeignClient.translationApi(youDaoTranslationQo);
|
||||
if(!"0".equals(translationApi.getString("errorCode"))){
|
||||
throw new BusinessException("有道翻译接口调用异常");
|
||||
|
|
|
|||
Loading…
Reference in New Issue