初始化

This commit is contained in:
2022-06-21 20:47:46 +08:00
parent b666a24a98
commit 59da3376c1
1246 changed files with 129600 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package com.njcn.event.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.event.api.fallback.EventDetailFeignClientFallbackFactory;
import com.njcn.event.pojo.po.EventDetail;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022/3/16
*/
@FeignClient(value = ServerInfo.EVENT,path = "/event",fallbackFactory = EventDetailFeignClientFallbackFactory.class)
public interface EventDetailFeignClient {
/**
* 根据监测点id获取暂降事件
* @param id 监测点id
* @return 暂降事件信息
*/
@PostMapping("/getEventDetailData")
HttpResult<List<EventDetail>> getEventDetailData(@RequestParam("id")String id, @RequestParam("startTime")String startTime, @RequestParam("endTime")String endTime);
/**
* 根据监测点集合获取暂降事件
* @return 暂降事件信息
*/
@PostMapping("/getEventDetail")
HttpResult<List<EventDetail>> getEventDetail(@RequestBody List<String> lineIndexes, @RequestParam("startTime")String startTime, @RequestParam("endTime")String endTime);
/**
* 根据监测点集合分页获取暂降事件
* @return 暂降事件信息
*/
@PostMapping("/getEventDetailLimit")
HttpResult<List<EventDetail>> getEventDetailLimit(@RequestBody List<String> lineIndexes, @RequestParam("startTime")String startTime, @RequestParam("endTime")String endTime,@RequestParam("pageSize") Integer pageSize,@RequestParam("pageNum") Integer pageNum);
}

View File

@@ -0,0 +1,53 @@
package com.njcn.event.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.event.api.EventDetailFeignClient;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.utils.EventlEnumUtil;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author denghuajun
* @version 1.0.0
* @date 2022/3/16
*/
@Slf4j
@Component
public class EventDetailFeignClientFallbackFactory implements FallbackFactory<EventDetailFeignClient> {
@Override
public EventDetailFeignClient create(Throwable throwable) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (throwable.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) throwable.getCause();
exceptionEnum = EventlEnumUtil.getExceptionEnum(businessException.getResult());
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new EventDetailFeignClient() {
@Override
public HttpResult<List<EventDetail>> getEventDetailData(String id, String startTime, String endTime) {
log.error("{}异常,降级处理,异常为:{}", "根据监测点Id获取暂降事件信息", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<EventDetail>> getEventDetail(List<String> lineIndexes, String startTime, String endTime) {
log.error("{}异常,降级处理,异常为:{}", "根据监测点集合获取暂降事件", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<List<EventDetail>> getEventDetailLimit(List<String> lineIndexes, String startTime, String endTime, Integer pageSize, Integer pageNum) {
log.error("{}异常,降级处理,异常为:{}", "根据监测点集合获取暂降事件", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}