|
|
@ -1,5 +1,7 @@
|
|
|
|
package com.xjs.translation.controller;
|
|
|
|
package com.xjs.translation.controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
|
|
import com.ruoyi.common.log.annotation.Log;
|
|
|
|
import com.ruoyi.common.security.annotation.RequiresLogin;
|
|
|
|
import com.ruoyi.common.security.annotation.RequiresLogin;
|
|
|
@ -9,12 +11,12 @@ import com.xjs.translation.domain.vo.translation.TranslationVo;
|
|
|
|
import com.xjs.translation.factory.TranslationFactory;
|
|
|
|
import com.xjs.translation.factory.TranslationFactory;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static com.xjs.common.consts.TranslationTypeConst.BAIDU;
|
|
|
|
import static com.xjs.common.consts.TranslationTypeConst.BAIDU;
|
|
|
|
import static com.xjs.common.consts.TranslationTypeConst.YOUDAO;
|
|
|
|
import static com.xjs.common.consts.TranslationTypeConst.YOUDAO;
|
|
|
@ -27,6 +29,7 @@ import static com.xjs.common.consts.TranslationTypeConst.YOUDAO;
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("translation")
|
|
|
|
@RequestMapping("translation")
|
|
|
|
@Api(tags = "业务模块-翻译管理")
|
|
|
|
@Api(tags = "业务模块-翻译管理")
|
|
|
|
|
|
|
|
@Log4j2
|
|
|
|
public class TranslationController {
|
|
|
|
public class TranslationController {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
@ -49,4 +52,39 @@ public class TranslationController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AjaxResult.success(translationVo);
|
|
|
|
return AjaxResult.success(translationVo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("forRPC")
|
|
|
|
|
|
|
|
@ApiOperation("翻译接口远程PRC调用")
|
|
|
|
|
|
|
|
public R<TranslationVo> translation(String content) {
|
|
|
|
|
|
|
|
TranslationFactory translationFactory = this.randomApi();
|
|
|
|
|
|
|
|
TranslationQo translationQo = new TranslationQo();
|
|
|
|
|
|
|
|
translationQo.setQ(content);
|
|
|
|
|
|
|
|
TranslationVo translationVo;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
translationVo = translationFactory.translationApi(translationQo);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
translationVo = new TranslationVo();
|
|
|
|
|
|
|
|
translationVo.setErrorCode(500L);
|
|
|
|
|
|
|
|
log.error("翻译接口平台异常");
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return R.ok(translationVo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 封装随机调用api
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return 文案工厂
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private TranslationFactory randomApi() {
|
|
|
|
|
|
|
|
ArrayList<TranslationFactory> factories = new ArrayList<>();
|
|
|
|
|
|
|
|
//添加了新接口只需要在这add接口进去
|
|
|
|
|
|
|
|
factories.add(youDaoTranslationFactory);
|
|
|
|
|
|
|
|
factories.add(baiDuTranslationFactory);
|
|
|
|
|
|
|
|
//--------add----------------------------;-
|
|
|
|
|
|
|
|
//随机调用集合中的接口
|
|
|
|
|
|
|
|
return RandomUtil.randomEle(factories);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|