终端周期检测代码调整

This commit is contained in:
xy
2024-07-03 14:18:49 +08:00
parent 306200791a
commit fd23719a41
11 changed files with 165 additions and 11 deletions

View File

@@ -0,0 +1,36 @@
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.DeviceFeignClientFallbackFactory;
import com.njcn.device.pq.api.fallback.LineFeignClientFallbackFactory;
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;
/**
* @author xy
*/
@FeignClient(
value = ServerInfo.DEVICE,
path = "/dev",
fallbackFactory = DeviceFeignClientFallbackFactory.class,
contextId = "dev")
public interface DeviceFeignClient {
/**
* 技术监督修改装置定检时间
*
* @param devId 监测点id
* @param thisTimeCheck 起始时间
* @param nextTimeCheck 结束时间
* @return 终端状态信息
*/
@PostMapping("/updateDevCheckTime")
@ApiOperation("技术监督修改装置定检时间")
HttpResult<String> updateDevCheckTime(@RequestParam("devId") String devId,
@RequestParam("thisTimeCheck") String thisTimeCheck,
@RequestParam("nextTimeCheck") String nextTimeCheck);
}

View File

@@ -0,0 +1,36 @@
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.biz.utils.DeviceEnumUtil;
import com.njcn.device.pq.api.DeviceFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author xy
*/
@Slf4j
@Component
public class DeviceFeignClientFallbackFactory implements FallbackFactory<DeviceFeignClient> {
@Override
public DeviceFeignClient 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 DeviceFeignClient() {
@Override
public HttpResult<String> updateDevCheckTime(String devId, String thisTimeCheck, String nextTimeCheck) {
log.error("{}异常,降级处理,异常为:{}", "技术监督修改装置定检时间", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}