设备自动连接逻辑优化
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.CsDeviceClientFallbackFactory;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/device", fallbackFactory = CsDeviceClientFallbackFactory.class,contextId = "device")
|
||||
|
||||
public interface CsDeviceFeignClient {
|
||||
|
||||
@PostMapping("/updateRunStatus")
|
||||
HttpResult<String> updateRunStatus(@RequestParam("nDid") String nDid, @RequestParam("runStatus") Integer runStatus);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.CsDeviceFeignClient;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsDeviceClientFallbackFactory implements FallbackFactory<CsDeviceFeignClient> {
|
||||
@Override
|
||||
public CsDeviceFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsDeviceFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> updateRunStatus(String nDid, Integer runStatus) {
|
||||
log.error("{}异常,降级处理,异常为:{}","云设备状态调整异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public enum AccessResponseEnum {
|
||||
DEV_MODEL_NOT_FIND("A0303","装置型号未找到!"),
|
||||
DEV_IS_NOT_ZL("A0303","注册装置不是直连装置!"),
|
||||
DEV_IS_NOT_WG("A0303","注册装置不是网关!"),
|
||||
DEV_IS_NOT_PORTABLE("A0303","注册装置不是便携式装置!"),
|
||||
DEV_IS_NOT_PORTABLE("A0303","注册装置不是便携式装置或者在线监测设备!"),
|
||||
|
||||
REGISTER_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
ACCESS_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
|
||||
Reference in New Issue
Block a user