驾驶舱功能调整
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.fallback.PqDashboardPageFeignClientFallbackFactory;
|
||||
import com.njcn.system.pojo.po.PqDashboardPage;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author 徐扬
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM,path = "/dashboard",fallbackFactory = PqDashboardPageFeignClientFallbackFactory.class,contextId = "dashboard")
|
||||
public interface PqDashboardPageFeignClient {
|
||||
|
||||
@PostMapping("/getDashboardPageByUserId")
|
||||
@ApiOperation("根据用户id查询用户驾驶舱")
|
||||
HttpResult<List<PqDashboardPage>> getDashboardPageByUserId(@RequestParam("id") String id,@RequestParam("state") boolean state);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.njcn.system.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.system.api.PqDashboardPageFeignClient;
|
||||
import com.njcn.system.pojo.po.PqDashboardPage;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年01月05日 15:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PqDashboardPageFeignClientFallbackFactory implements FallbackFactory<PqDashboardPageFeignClient> {
|
||||
|
||||
|
||||
/**
|
||||
* 输出远程请求接口异常日志
|
||||
* @param cause RPC请求异常
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PqDashboardPageFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new PqDashboardPageFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<List<PqDashboardPage>> getDashboardPageByUserId(String id, boolean state) {
|
||||
log.error("{}异常,降级处理,异常为:{}","根据用户id查询用户驾驶舱异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user