功能提交

This commit is contained in:
2025-03-21 16:38:04 +08:00
parent 6df4074c59
commit 72b2283165
7 changed files with 137 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
package com.njcn.supervision.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.supervision.api.fallback.TempLineRunTestFeignClientFallbackFactory;
import com.njcn.supervision.api.fallback.UserLedgerFeignClientFallbackFactory;
import com.njcn.supervision.pojo.param.user.UserReportParam;
import com.njcn.supervision.pojo.po.user.UserReportPO;
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 java.util.List;
/**
* 流程实例 Api 接口
*
*/
@FeignClient(value = ServerInfo.SUPERVISION, path = "/userReport", fallbackFactory = UserLedgerFeignClientFallbackFactory.class)
public interface UserLedgerFeignClient {
@PostMapping("/selectUserList")
List<UserReportPO> selectUserList(@RequestBody UserReportParam userReportParam);
}

View File

@@ -0,0 +1,38 @@
package com.njcn.supervision.api.fallback;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.supervision.api.TempLineRunTestFeignClient;
import com.njcn.supervision.api.UserLedgerFeignClient;
import com.njcn.supervision.pojo.param.user.UserReportParam;
import com.njcn.supervision.pojo.po.user.UserReportPO;
import com.njcn.supervision.utils.SupervisionEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
public class UserLedgerFeignClientFallbackFactory implements FallbackFactory<UserLedgerFeignClient> {
@Override
public UserLedgerFeignClient create(Throwable throwable) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (throwable.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) throwable.getCause();
exceptionEnum = SupervisionEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new UserLedgerFeignClient() {
@Override
public List<UserReportPO> selectUserList(UserReportParam userReportParam) {
log.error("{}异常,降级处理,异常为:{}", "查询用户台账", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}