zbj//1.web新增用户信息添加日志
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.njcn.device.pq.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.device.pq.api.fallback.PqsTerminalLogsClientFallbackFactory;
|
||||
import com.njcn.device.pq.api.fallback.TerminalBaseClientFallbackFactory;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年02月14日 14:02
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.DEVICE, path = "/pqsTerminalLogs", fallbackFactory = PqsTerminalLogsClientFallbackFactory.class, contextId = "pqsTerminalLogs")
|
||||
public interface PqsTerminalLogsClient {
|
||||
|
||||
/**
|
||||
* 新增日志表数据
|
||||
*
|
||||
* @author zbj
|
||||
* @date 2023/4/13
|
||||
*/
|
||||
@PostMapping("/saveLogs")
|
||||
HttpResult<Object> saveLogs(@RequestBody PqsTerminalLogs pqsTerminalLogs);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.njcn.device.pq.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.device.pq.api.PqsTerminalLogsClient;
|
||||
import com.njcn.device.pq.api.TerminalBaseClient;
|
||||
import com.njcn.device.pq.pojo.po.Line;
|
||||
import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
|
||||
import com.njcn.device.pq.utils.DeviceEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zbj
|
||||
* @version 1.0.0
|
||||
* @date 2023年04月13日 13:34
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PqsTerminalLogsClientFallbackFactory implements FallbackFactory<PqsTerminalLogsClient> {
|
||||
@Override
|
||||
public PqsTerminalLogsClient create(Throwable throwable) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (throwable.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) throwable.getCause();
|
||||
exceptionEnum = DeviceEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new PqsTerminalLogsClient()
|
||||
{
|
||||
@Override
|
||||
public HttpResult<Object> saveLogs(PqsTerminalLogs pqsTerminalLogs) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "新增日志表数据", throwable.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user