日志处理, 异常处理

This commit is contained in:
zhangchenbiao
2023-06-16 14:27:17 +08:00
parent a1b2b61717
commit 4e98eb7c76
10 changed files with 112 additions and 8 deletions

View File

@@ -168,5 +168,7 @@
<orderEntry type="library" name="Maven: com.aliyun:tea-fileform:0.0.3" level="project" />
<orderEntry type="library" name="Maven: com.aliyun:darabonba-array:0.1.0" level="project" />
<orderEntry type="library" name="Maven: com.aliyun:darabonba-number:0.0.3" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.9.5" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.5" level="project" />
</component>
</module>

View File

@@ -72,6 +72,14 @@
<groupId>com.aliyun</groupId>
<artifactId>ocr20191230</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,66 @@
package com.cool.store.mq;
import com.aliyun.openservices.ons.api.Constants;
import com.aliyun.openservices.ons.api.Message;
import com.cool.store.constants.CommonConstants;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Objects;
/**
* 切面处理类,操作日志异常日志记录处理
* @author jiangjixiang
*/
@Aspect
@Component
@Slf4j
public class RocketMqLogAspect {
/**
* 设置操作异常切入点记录异常日志 扫描所有controller包下操作
*/
@Pointcut(value = "execution(public * com.cool.store.mq.consumer.listener..*.consume(..))")
public void rocketMqMdc() {
}
/**
* 正常返回通知,拦截用户操作日志,连接点正常执行完成后执行, 如果连接点抛出异常,则不会执行
*
* @param joinPoint 切入点
* @param keys 返回结果
*/
@Before(value = "rocketMqMdc()")
public void mqBeforeLog(JoinPoint joinPoint) {
try {
Object[] args = joinPoint.getArgs();
Message message = (Message)args[0];
String traceId = message.getMsgID() + Constants.TOPIC_PARTITION_SEPARATOR + message.getReconsumeTimes();
Map<String, String> context = MDC.getCopyOfContextMap();
if(Objects.isNull(context)){
MDC.put(CommonConstants.REQUEST_ID, traceId);
}
} catch (IllegalArgumentException e) {
log.info("MDC mqBeforeLog", e);
}
}
@AfterReturning(value = "rocketMqMdc()")
public void doAfterReturning(JoinPoint joinPoint){
try {
MDC.clear();
} catch (Exception e) {
log.info("MDC doAfterReturning", e);
}
}
}

View File

@@ -1,6 +1,7 @@
package com.cool.store.service;
import com.cool.store.dto.partner.DescribePhoneNumberDTO;
import com.cool.store.exception.ApiException;
import com.cool.store.vo.cuser.IdentityCardInfoVO;
/**
@@ -23,6 +24,6 @@ public interface AliyunService {
* @param faceImageUrl
* @return
*/
IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl);
IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl) throws ApiException;
}

View File

@@ -6,11 +6,10 @@ import com.aliyun.dytnsapi20200217.models.DescribePhoneNumberOperatorAttributeRe
import com.aliyun.dytnsapi20200217.models.DescribePhoneNumberOperatorAttributeResponse;
import com.aliyun.ocr20191230.models.RecognizeIdentityCardResponse;
import com.aliyun.ocr20191230.models.RecognizeIdentityCardResponseBody;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.teaopenapi.models.Config;
import com.cool.store.dto.partner.DescribePhoneNumberDTO;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ApiException;
import com.cool.store.exception.ServiceException;
import com.cool.store.service.AliyunService;
import com.cool.store.vo.cuser.IdentityCardInfoVO;
@@ -62,7 +61,7 @@ public class AliyunServiceImpl implements AliyunService {
}
@Override
public IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl) {
public IdentityCardInfoVO getIdentityCardInfo(String faceImageUrl) throws ApiException {
//todo zcb ak sk替换
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId("LTAI5t9RaXvABZbHvoXjDFJ1")
@@ -94,14 +93,17 @@ public class AliyunServiceImpl implements AliyunService {
return result;
} catch (com.aliyun.tea.TeaException e) {
log.error("身份证解析报错TeaException{}", e);
throw new ApiException(e.getMessage());
} catch (MalformedURLException e) {
log.error("身份证解析报错MalformedURLException{}", e);
throw new ApiException(e.getMessage());
} catch (IOException e) {
log.error("身份证解析报错IOException{}", e);
throw new ApiException(e.getMessage());
} catch (Exception e) {
log.error("身份证解析报错Exception{}", e);
throw new ApiException(e.getMessage());
}
return null;
}
public static String convertDate(String date, String format) {