parent
c70d83f29f
commit
9ee9f820dc
|
|
@ -18,8 +18,7 @@
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
|
||||||
<mybatisplus.version>3.4.3.4</mybatisplus.version>
|
<mybatisplus.version>3.4.3.4</mybatisplus.version>
|
||||||
<hutool.version>5.7.17</hutool.version>
|
<hutool.version>5.7.17</hutool.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.xjs.translation;
|
package com.xjs;
|
||||||
|
|
||||||
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
import com.ruoyi.common.security.annotation.EnableCustomConfig;
|
||||||
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.xjs.log.aop;
|
||||||
|
|
||||||
|
import com.ruoyi.common.log.enums.BusinessType;
|
||||||
|
import com.ruoyi.common.log.enums.OperatorType;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc 自定义api日志注解
|
||||||
|
* @create 2021-12-26
|
||||||
|
*/
|
||||||
|
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface ApiLog {
|
||||||
|
/**
|
||||||
|
* api名称
|
||||||
|
*/
|
||||||
|
public String name() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求url
|
||||||
|
*/
|
||||||
|
public String url() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求方法
|
||||||
|
*/
|
||||||
|
public String method() default "Post";
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.xjs.log.aop;
|
||||||
|
|
||||||
|
import com.ruoyi.common.log.annotation.Log;
|
||||||
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.Signature;
|
||||||
|
import org.aspectj.lang.annotation.*;
|
||||||
|
import org.aspectj.lang.reflect.SourceLocation;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiejs
|
||||||
|
* @desc
|
||||||
|
* @create 2021-12-26
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Aspect
|
||||||
|
public class ApiLogAspect {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理完请求后执行
|
||||||
|
*
|
||||||
|
* @param joinPoint 切点
|
||||||
|
*/
|
||||||
|
@AfterReturning(pointcut = "@annotation(apiLog)", returning = "jsonResult")
|
||||||
|
public void doAfterReturning(JoinPoint joinPoint, ApiLog apiLog, Object jsonResult)
|
||||||
|
{
|
||||||
|
this.handleApiLog(joinPoint, apiLog, null, jsonResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@AfterThrowing(value = "@annotation(apiLog)", throwing = "e")
|
||||||
|
public void doAfterThrowing(JoinPoint joinPoint, ApiLog apiLog, Exception e)
|
||||||
|
{
|
||||||
|
handleApiLog(joinPoint, apiLog, e, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void handleApiLog(JoinPoint joinPoint, ApiLog apiLog, final Exception e, Object jsonResult) {
|
||||||
|
String name = apiLog.name();//请求名称
|
||||||
|
String url = apiLog.url();//请求地址
|
||||||
|
Object[] args = joinPoint.getArgs();//请求体
|
||||||
|
for (Object arg : args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.xjs.translation.client;
|
package com.xjs.translation.client;
|
||||||
|
|
||||||
|
import com.xjs.log.aop.ApiLog;
|
||||||
import com.xjs.translation.domain.qo.translation.BaiDuTranslationQo;
|
import com.xjs.translation.domain.qo.translation.BaiDuTranslationQo;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
@ -13,6 +14,9 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||||
public interface BaiduFeignClient {
|
public interface BaiduFeignClient {
|
||||||
|
|
||||||
@PostMapping(headers = {"Content-Type=application/x-www-form-urlencoded"})
|
@PostMapping(headers = {"Content-Type=application/x-www-form-urlencoded"})
|
||||||
|
@ApiLog(name = "baidu",
|
||||||
|
url = "http://api.fanyi.baidu.com/api/trans/vip/translate",
|
||||||
|
method = "Post")
|
||||||
String translationApi(BaiDuTranslationQo qo);
|
String translationApi(BaiDuTranslationQo qo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.xjs.translation.client;
|
package com.xjs.translation.client;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xjs.log.aop.ApiLog;
|
||||||
import com.xjs.translation.domain.qo.translation.YouDaoTranslationQo;
|
import com.xjs.translation.domain.qo.translation.YouDaoTranslationQo;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.cloud.openfeign.SpringQueryMap;
|
import org.springframework.cloud.openfeign.SpringQueryMap;
|
||||||
|
|
@ -15,5 +16,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
public interface YouDaoFeignClient {
|
public interface YouDaoFeignClient {
|
||||||
|
|
||||||
@GetMapping( headers ={ "Accept-Encoding=''"})
|
@GetMapping( headers ={ "Accept-Encoding=''"})
|
||||||
|
@ApiLog(name = "youdao",
|
||||||
|
url = "http://fanyi.youdao.com/translate",
|
||||||
|
method = "Get")
|
||||||
JSONObject translationApi(@SpringQueryMap YouDaoTranslationQo qo);
|
JSONObject translationApi(@SpringQueryMap YouDaoTranslationQo qo);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.xjs.translation.controller;
|
package com.xjs.translation.controller;
|
||||||
|
|
||||||
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.enums.BusinessType;
|
||||||
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
||||||
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
||||||
import com.xjs.translation.service.TranslationService;
|
import com.xjs.translation.service.TranslationService;
|
||||||
|
|
@ -30,6 +32,7 @@ public class TranslationController {
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("翻译接口")
|
@ApiOperation("翻译接口")
|
||||||
|
@Log(title = "翻译管理")
|
||||||
public AjaxResult translation(@Validated @RequestBody TranslationQo translationQo) {
|
public AjaxResult translation(@Validated @RequestBody TranslationQo translationQo) {
|
||||||
TranslationVo translationVo=new TranslationVo();
|
TranslationVo translationVo=new TranslationVo();
|
||||||
if (BAIDU.equals(translationQo.getTranslationType())) {
|
if (BAIDU.equals(translationQo.getTranslationType())) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.xjs.translation.service.impl;
|
package com.xjs.translation.service.impl;
|
||||||
|
|
||||||
import com.xjs.translation.XjsEnglishApp;
|
import com.xjs.XjsEnglishApp;
|
||||||
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
||||||
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
||||||
import com.xjs.translation.service.TranslationService;
|
import com.xjs.translation.service.TranslationService;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.xjs.translation.service.impl;
|
package com.xjs.translation.service.impl;
|
||||||
|
|
||||||
import com.xjs.translation.XjsEnglishApp;
|
import com.xjs.XjsEnglishApp;
|
||||||
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
import com.xjs.translation.domain.qo.translation.TranslationQo;
|
||||||
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
import com.xjs.translation.domain.vo.translation.TranslationVo;
|
||||||
import com.xjs.translation.service.TranslationService;
|
import com.xjs.translation.service.TranslationService;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue