新增接口

This commit is contained in:
hzj
2024-05-16 18:53:25 +08:00
parent b1f9c45e4a
commit 165b1dc69d
23 changed files with 960 additions and 31 deletions

View File

@@ -0,0 +1,22 @@
package com.njcn.supervision.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.supervision.api.fallback.DeVReportManageFeignClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 流程实例 Api 接口
*
* @author 芋道源码
*/
@FeignClient(value = ServerInfo.SUPERVISION, path = "/deVReport", fallbackFactory = DeVReportManageFeignClientFallbackFactory.class)
public interface DeVReportManageFeignClient {
@GetMapping("/updateStatus")
HttpResult<Object> updateStatus(@RequestParam("businessKey") String businessKey, @RequestParam("status")Integer status);
}

View File

@@ -0,0 +1,22 @@
package com.njcn.supervision.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.supervision.api.fallback.TempLineFeignClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* 流程实例 Api 接口
*
* @author 芋道源码
*/
@FeignClient(value = ServerInfo.SUPERVISION, path = "/tempLine", fallbackFactory = TempLineFeignClientFallbackFactory.class)
public interface TempLineFeignClient {
@GetMapping("/updateStatus")
HttpResult<Object> updateStatus(@RequestParam("businessKey") String businessKey, @RequestParam("status")Integer status);
}

View File

@@ -0,0 +1,37 @@
package com.njcn.supervision.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.supervision.api.DeVReportManageFeignClient;
import com.njcn.supervision.utils.SupervisionEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022/3/16
*/
@Slf4j
@Component
public class DeVReportManageFeignClientFallbackFactory implements FallbackFactory<DeVReportManageFeignClient> {
@Override
public DeVReportManageFeignClient 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 DeVReportManageFeignClient() {
@Override
public HttpResult<Object> updateStatus(String businessKey, Integer status) {
log.error("{}异常,降级处理,异常为:{}", "更新流程状态", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -0,0 +1,37 @@
package com.njcn.supervision.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.supervision.api.TempLineFeignClient;
import com.njcn.supervision.utils.SupervisionEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022/3/16
*/
@Slf4j
@Component
public class TempLineFeignClientFallbackFactory implements FallbackFactory<TempLineFeignClient> {
@Override
public TempLineFeignClient 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 TempLineFeignClient() {
@Override
public HttpResult<Object> updateStatus(String businessKey, Integer status) {
log.error("{}异常,降级处理,异常为:{}", "更新流程状态", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}