离线数据上传入库

This commit is contained in:
guofeihu
2024-07-31 08:47:12 +08:00
parent 777abc0824
commit fde625de7e
7 changed files with 187 additions and 13 deletions

View File

@@ -0,0 +1,21 @@
package com.njcn.csharmonic.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.csharmonic.api.fallback.EventFeignClientFallbackFactory;
import com.njcn.csharmonic.pojo.po.CsEventPO;
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 gfh
*/
@FeignClient(value = ServerInfo.CS_HARMONIC_BOOT, path = "/event", fallbackFactory = EventFeignClientFallbackFactory.class,contextId = "event")
public interface EventFeignClient {
@PostMapping("/saveBatchEventList")
HttpResult<String> saveBatchEventList(@RequestBody List<CsEventPO> csEventPOS);
}

View File

@@ -0,0 +1,35 @@
package com.njcn.csharmonic.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.csharmonic.api.EventFeignClient;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author gfh
*/
@Slf4j
@Component
public class EventFeignClientFallbackFactory implements FallbackFactory<EventFeignClient> {
@Override
public EventFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new EventFeignClient() {
@Override
public HttpResult<String> saveBatchEventList(List<CsEventPO> csEventPOS) {
log.error("{}异常,降级处理,异常为:{}","获取当天事件未读消息未读消息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -6,6 +6,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.vo.CsEventVO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
import com.njcn.csharmonic.service.CsEventPOService;
@@ -66,7 +67,13 @@ public class EventController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, eventVO, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/saveBatchEventList")
@ApiOperation("批量新增事件")
@ApiImplicitParam(name = "csEventPOS", value = "事件集合", required = true)
public HttpResult<String> saveBatchEventList(@RequestBody List<CsEventPO> csEventPOS) {
String methodDescribe = getMethodDescribe("saveBatchEventList");
csEventPOService.saveBatchEventList(csEventPOS);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -39,4 +39,6 @@ public interface CsEventPOService extends IService<CsEventPO>{
CsEventVO getWavePics(String eventId, int i);
List<EventDetailVO> queryEventList(CsEventUserQueryParam csEventUserQueryParam);
void saveBatchEventList(List<CsEventPO> csEventPOS);
}

View File

@@ -35,6 +35,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csharmonic.mapper.CsEventPOMapper;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.service.CsEventPOService;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@@ -110,6 +111,12 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
return list;
}
@Override
@Transactional
public void saveBatchEventList(List<CsEventPO> csEventPOS) {
this.saveBatch(csEventPOS);
}
/**
* @return WaveDataDTO