推送日志对外接口
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package com.njcn.csdevice.api;
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.constant.ServerInfo;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.csdevice.api.fallback.EventLogsClientFallbackFactory;
|
||||||
|
import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@FeignClient(value = ServerInfo.CS_DEVICE_BOOT, path = "/csEventSendMsg", fallbackFactory = EventLogsClientFallbackFactory.class,contextId = "csEventSendMsg")
|
||||||
|
public interface EventLogsFeignClient {
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
HttpResult<String> addLogs(@RequestBody List<CsEventSendMsg> list);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.njcn.csdevice.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.csdevice.api.EventLogsFeignClient;
|
||||||
|
import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
||||||
|
import feign.hystrix.FallbackFactory;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class EventLogsClientFallbackFactory implements FallbackFactory<EventLogsFeignClient> {
|
||||||
|
@Override
|
||||||
|
public EventLogsFeignClient create(Throwable cause) {
|
||||||
|
//判断抛出异常是否为解码器抛出的业务异常
|
||||||
|
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||||
|
if (cause.getCause() instanceof BusinessException) {
|
||||||
|
BusinessException businessException = (BusinessException) cause.getCause();
|
||||||
|
}
|
||||||
|
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||||
|
return new EventLogsFeignClient() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpResult<String> addLogs(List<CsEventSendMsg> list) {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}","新增推送日志",cause.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,9 +41,9 @@ public class CsEventSendMsgController extends BaseController {
|
|||||||
|
|
||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@ApiOperation("插入推送日志")
|
@ApiOperation("新增推送日志")
|
||||||
@ApiImplicitParam(name = "list", value = "日志记录", required = true)
|
@ApiImplicitParam(name = "list", value = "日志记录", required = true)
|
||||||
public HttpResult addLogs(@RequestBody List<CsEventSendMsg> list) {
|
public HttpResult<String> addLogs(@RequestBody List<CsEventSendMsg> list) {
|
||||||
String methodDescribe = getMethodDescribe("addLogs");
|
String methodDescribe = getMethodDescribe("addLogs");
|
||||||
csEventSendMsgService.saveBatch(list);
|
csEventSendMsgService.saveBatch(list);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
|||||||
Reference in New Issue
Block a user