终端异常统计api接口
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
package com.njcn.prepare.harmonic.api.device;
|
||||||
|
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.constant.ServerInfo;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.prepare.harmonic.api.device.fallback.DeviceAbnormalFeignClientFallbackFactory;
|
||||||
|
import com.njcn.prepare.harmonic.api.line.fallback.DayDataFeignClientFallbackFactory;
|
||||||
|
import com.njcn.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
@FeignClient(
|
||||||
|
value = ServerInfo.PREPARE_BOOT,//对应模块名
|
||||||
|
path = "/deviceAbnormal",//对应controller请求类
|
||||||
|
fallbackFactory = DeviceAbnormalFeignClientFallbackFactory.class//服务降级处理类
|
||||||
|
)
|
||||||
|
public interface DeviceAbnormalFeignClient {
|
||||||
|
|
||||||
|
@PostMapping("/statistics")
|
||||||
|
public HttpResult<Boolean> dailyDeviceAbnormaStatistics (@RequestBody DeviceAbnormaStatisticsParam param);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.njcn.prepare.harmonic.api.device.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.pq.utils.DeviceEnumUtil;
|
||||||
|
import com.njcn.prepare.harmonic.api.device.DeviceAbnormalFeignClient;
|
||||||
|
import com.njcn.prepare.harmonic.pojo.param.DeviceAbnormaStatisticsParam;
|
||||||
|
import feign.hystrix.FallbackFactory;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class DeviceAbnormalFeignClientFallbackFactory implements FallbackFactory<DeviceAbnormalFeignClient> {
|
||||||
|
@Override
|
||||||
|
public DeviceAbnormalFeignClient 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 DeviceAbnormalFeignClient() {
|
||||||
|
@Override
|
||||||
|
public HttpResult<Boolean> dailyDeviceAbnormaStatistics( @RequestBody DeviceAbnormaStatisticsParam param) {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}", "终端异常统计: ", throwable.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Api(tags = "终端异常")
|
@Api(tags = "终端异常统计")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/deviceAbnormal")
|
@RequestMapping("/deviceAbnormal")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
|||||||
Reference in New Issue
Block a user