优化修改
This commit is contained in:
parent
5670717996
commit
7f1f76de3d
|
@ -23,10 +23,7 @@ import java.security.interfaces.RSAPublicKey;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求客户端
|
* 请求客户端
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.supervision.edh.controller;
|
package com.supervision.edh.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.supervision.edh.common.AjaxResult;
|
import com.supervision.edh.common.AjaxResult;
|
||||||
import com.supervision.edh.domain.EdhReceiveDataLog;
|
import com.supervision.edh.domain.EdhReceiveDataLog;
|
||||||
import com.supervision.edh.enums.BuzStatusEnum;
|
import com.supervision.edh.enums.BuzStatusEnum;
|
||||||
|
@ -13,16 +14,24 @@ import com.supervision.edh.utils.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.AsyncResult;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.crypto.BadPaddingException;
|
||||||
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName SupervisionEdhServerController
|
* @ClassName SupervisionEdhServerController
|
||||||
|
@ -45,16 +54,15 @@ public class SupervisionEdhServerController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private EventProcessingServiceImpl processingService;
|
private EventProcessingServiceImpl processingService;
|
||||||
|
|
||||||
@RequestMapping("/receive")
|
@PostMapping("/receive")
|
||||||
public @ResponseBody
|
public String receive(HttpServletRequest request) throws IOException {
|
||||||
String receive(HttpServletRequest request) throws IOException {
|
|
||||||
RequestWrapper requestWrapper = new RequestWrapper(request);
|
RequestWrapper requestWrapper = new RequestWrapper(request);
|
||||||
String body = requestWrapper.getBodyString();
|
String body = requestWrapper.getBodyString();
|
||||||
System.out.println(body);
|
System.out.println(body);
|
||||||
Map<String, Object> paramsTemp = JSON.parseObject(body);
|
Map<String, Object> paramsTemp = JSON.parseObject(body);
|
||||||
System.out.println(paramsTemp);
|
System.out.println(paramsTemp);
|
||||||
Map<String, Object> params = JSON.parseObject(paramsTemp.get("req").toString());
|
Map<String, Object> params = JSON.parseObject(paramsTemp.get("req").toString());
|
||||||
logger.info("接收到请求参数:{}", params);
|
// logger.info("接收到请求参数:{}", params);
|
||||||
// 检查参数,并获取校验结果
|
// 检查参数,并获取校验结果
|
||||||
String checkResult = checkRequestParam(params);
|
String checkResult = checkRequestParam(params);
|
||||||
if (!ResponseBuilder.reqPass().equals(checkResult)) {
|
if (!ResponseBuilder.reqPass().equals(checkResult)) {
|
||||||
|
@ -102,15 +110,37 @@ public class SupervisionEdhServerController {
|
||||||
dataLog.setSubTypeName(SubTypeEnum.getNameByType(eventPojo.getSubType()));
|
dataLog.setSubTypeName(SubTypeEnum.getNameByType(eventPojo.getSubType()));
|
||||||
dataLog.setData(eventPojo.getData());
|
dataLog.setData(eventPojo.getData());
|
||||||
dataLog.setVer(ver);
|
dataLog.setVer(ver);
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
|
||||||
|
dataLog.setEventTime(sdf.parse(timeStamp));//事件上报时间
|
||||||
receiveDataLogService.save(dataLog);
|
receiveDataLogService.save(dataLog);
|
||||||
|
|
||||||
//解析并处理数据
|
//解析并处理数据
|
||||||
processingService.asyncProcessEvent(eventPojo, data, eventId);
|
//processingService.asyncProcessEvent(eventPojo, data, eventId);
|
||||||
|
CompletableFuture<Void> future = processingService.asyncProcessEvent(eventPojo, data, eventId);
|
||||||
|
future.get(); // 阻塞等待任务完成(如果任务抛出异常,会抛出 ExecutionException)
|
||||||
return ResponseBuilder.success();
|
return ResponseBuilder.success();
|
||||||
|
} catch (BadPaddingException e) {
|
||||||
|
// RSA 解密失败,可能是密钥不匹配或数据被篡改
|
||||||
|
logger.error("解密失败:密钥不匹配或数据无效,错误信息:{}", e.getMessage());
|
||||||
|
return ResponseBuilder.failMsg("解密失败:请检查加密公钥是否匹配或数据是否被篡改");
|
||||||
|
} catch (IllegalBlockSizeException e) {
|
||||||
|
// 数据块大小错误(如 RSA 加密数据长度超限)
|
||||||
|
logger.error("解密失败:数据块大小错误,错误信息:{}", e.getMessage());
|
||||||
|
return ResponseBuilder.failMsg("解密失败:数据格式错误");
|
||||||
|
} catch (InvalidKeyException e) {
|
||||||
|
// 无效的私钥
|
||||||
|
logger.error("解密失败:提供的私钥无效,错误信息:{}", e.getMessage());
|
||||||
|
return ResponseBuilder.failMsg("解密失败:私钥无效");
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
logger.error("数据解析异常:上报数据格式有误,错误信息:{}", e.getMessage());
|
||||||
|
return ResponseBuilder.failMsg("数据解析异常:上报数据格式有误");
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
// 捕获异步任务抛出的异常
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
logger.error("异步任务执行失败 - event_id={},错误信息={}",params.get("event_id"),cause.getMessage());
|
||||||
|
return ResponseBuilder.failMsg("异步任务失败: " + cause.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("出错了,错误信息:{}", e.getMessage());
|
logger.error("出错了,错误信息:{}", e.getMessage());
|
||||||
//return ResponseBuilder.fail(BuzStatusEnum.SYS_ERR);
|
|
||||||
return ResponseBuilder.failMsg(e.getMessage());
|
return ResponseBuilder.failMsg(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +160,9 @@ public class SupervisionEdhServerController {
|
||||||
|
|
||||||
// 统一校验必填参数
|
// 统一校验必填参数
|
||||||
for (String paramName : requiredParams) {
|
for (String paramName : requiredParams) {
|
||||||
|
if (!params.containsKey(paramName)) {
|
||||||
|
return ResponseBuilder.failMsg("缺少必填参数: " + paramName);
|
||||||
|
}
|
||||||
Object value = params.get(paramName);
|
Object value = params.get(paramName);
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class EdhReceiveDataLog {
|
||||||
|
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
private Date updateTime;
|
private Date eventTime;
|
||||||
|
|
||||||
private Date isDeleted;
|
private Date isDeleted;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package com.supervision.edh.service.handle.core;
|
package com.supervision.edh.service.handle.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.supervision.edh.domain.EdhDrugOperatorsBaseInfo;
|
import com.supervision.edh.domain.EdhDrugOperatorsBaseInfo;
|
||||||
import com.supervision.edh.domain.vo.EdhDrugOperatorsBaseInfoVO;
|
import com.supervision.edh.domain.vo.EdhDrugOperatorsBaseInfoVO;
|
||||||
import com.supervision.edh.service.IEdhDrugOperatorsBaseInfoService;
|
import com.supervision.edh.service.IEdhDrugOperatorsBaseInfoService;
|
||||||
import com.supervision.edh.service.IEdhReceiveDataLogService;
|
|
||||||
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
||||||
import com.supervision.edh.service.handle.EventSubType;
|
import com.supervision.edh.service.handle.EventSubType;
|
||||||
import com.supervision.edh.utils.JsonUtils;
|
import com.supervision.edh.utils.JsonUtils;
|
||||||
|
@ -14,12 +10,10 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -30,8 +24,8 @@ import java.util.stream.Collectors;
|
||||||
* @date 2025年06月18日 11:14:43
|
* @date 2025年06月18日 11:14:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EventSubType("1014")
|
@EventSubType("1011")
|
||||||
public class SubType1014Handler extends AbstractEventDataHandler<EdhDrugOperatorsBaseInfoVO> {
|
public class SubType1011Handler extends AbstractEventDataHandler<EdhDrugOperatorsBaseInfoVO> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
|
@ -1,12 +1,8 @@
|
||||||
package com.supervision.edh.service.handle.core;
|
package com.supervision.edh.service.handle.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.supervision.edh.domain.EdhDrugOperateLicenseBaseInfo;
|
import com.supervision.edh.domain.EdhDrugOperateLicenseBaseInfo;
|
||||||
import com.supervision.edh.domain.EdhDrugOperatorsBaseInfo;
|
|
||||||
import com.supervision.edh.domain.vo.EdhDrugOperateLicenseBaseInfoVO;
|
import com.supervision.edh.domain.vo.EdhDrugOperateLicenseBaseInfoVO;
|
||||||
import com.supervision.edh.domain.vo.EdhDrugOperatorsBaseInfoVO;
|
|
||||||
import com.supervision.edh.service.IEdhDrugOperateLicenseBaseInfoService;
|
import com.supervision.edh.service.IEdhDrugOperateLicenseBaseInfoService;
|
||||||
import com.supervision.edh.service.IEdhDrugOperatorsBaseInfoService;
|
|
||||||
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
||||||
import com.supervision.edh.service.handle.EventSubType;
|
import com.supervision.edh.service.handle.EventSubType;
|
||||||
import com.supervision.edh.utils.JsonUtils;
|
import com.supervision.edh.utils.JsonUtils;
|
||||||
|
@ -28,8 +24,8 @@ import java.util.stream.Collectors;
|
||||||
* @date 2025年06月19日 10:14:43
|
* @date 2025年06月19日 10:14:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EventSubType("1015")
|
@EventSubType("1012")
|
||||||
public class SubType1015Handler extends AbstractEventDataHandler<EdhDrugOperateLicenseBaseInfoVO> {
|
public class SubType1012Handler extends AbstractEventDataHandler<EdhDrugOperateLicenseBaseInfoVO> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
|
@ -1,10 +1,7 @@
|
||||||
package com.supervision.edh.service.handle.core;
|
package com.supervision.edh.service.handle.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.supervision.edh.domain.vo.EdhDomesticDrugBaseInfoVO;
|
import com.supervision.edh.domain.vo.EdhDomesticDrugBaseInfoVO;
|
||||||
import com.supervision.edh.domain.vo.EdhDrugOperateLicenseBaseInfoVO;
|
|
||||||
import com.supervision.edh.service.IEdhDomesticDrugBaseInfoService;
|
import com.supervision.edh.service.IEdhDomesticDrugBaseInfoService;
|
||||||
import com.supervision.edh.service.IEdhDrugOperateLicenseBaseInfoService;
|
|
||||||
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
||||||
import com.supervision.edh.service.handle.EventSubType;
|
import com.supervision.edh.service.handle.EventSubType;
|
||||||
import com.supervision.edh.utils.JsonUtils;
|
import com.supervision.edh.utils.JsonUtils;
|
||||||
|
@ -21,8 +18,8 @@ import org.springframework.util.CollectionUtils;
|
||||||
* @date 2025年06月20日 10:14:43
|
* @date 2025年06月20日 10:14:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EventSubType("1018")
|
@EventSubType("1013")
|
||||||
public class SubType1018Handler extends AbstractEventDataHandler<EdhDomesticDrugBaseInfoVO> {
|
public class SubType1013Handler extends AbstractEventDataHandler<EdhDomesticDrugBaseInfoVO> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
|
@ -1,7 +1,5 @@
|
||||||
package com.supervision.edh.service.handle.core;
|
package com.supervision.edh.service.handle.core;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.supervision.edh.domain.EdhDrugInvoiceApplyInfo;
|
import com.supervision.edh.domain.EdhDrugInvoiceApplyInfo;
|
||||||
import com.supervision.edh.domain.vo.EdhDrugInvoiceApplyInfoVO;
|
import com.supervision.edh.domain.vo.EdhDrugInvoiceApplyInfoVO;
|
||||||
import com.supervision.edh.domain.vo.InstanceVO;
|
import com.supervision.edh.domain.vo.InstanceVO;
|
||||||
|
@ -9,7 +7,6 @@ import com.supervision.edh.domain.vo.DrugVO;
|
||||||
import com.supervision.edh.service.IEdhDrugInvoiceApplyInfoService;
|
import com.supervision.edh.service.IEdhDrugInvoiceApplyInfoService;
|
||||||
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
||||||
import com.supervision.edh.service.handle.EventSubType;
|
import com.supervision.edh.service.handle.EventSubType;
|
||||||
import com.supervision.edh.utils.DateUtils;
|
|
||||||
import com.supervision.edh.utils.JsonUtils;
|
import com.supervision.edh.utils.JsonUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -28,8 +25,8 @@ import java.util.stream.Collectors;
|
||||||
* @date 2025年06月20日 10:14:43
|
* @date 2025年06月20日 10:14:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EventSubType("2015")
|
@EventSubType("2011")
|
||||||
public class SubType2015Handler extends AbstractEventDataHandler<EdhDrugInvoiceApplyInfoVO> {
|
public class SubType2011Handler extends AbstractEventDataHandler<EdhDrugInvoiceApplyInfoVO> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
|
@ -1,6 +1,5 @@
|
||||||
package com.supervision.edh.service.handle.core;
|
package com.supervision.edh.service.handle.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.supervision.edh.domain.EdhDrugDeliveryNoteApplyInfo;
|
import com.supervision.edh.domain.EdhDrugDeliveryNoteApplyInfo;
|
||||||
import com.supervision.edh.domain.vo.DrugVO;
|
import com.supervision.edh.domain.vo.DrugVO;
|
||||||
import com.supervision.edh.domain.vo.EdhDrugDeliveryNoteApplyInfoVO;
|
import com.supervision.edh.domain.vo.EdhDrugDeliveryNoteApplyInfoVO;
|
||||||
|
@ -26,8 +25,8 @@ import java.util.stream.Collectors;
|
||||||
* @date 2025年06月21日 10:14:43
|
* @date 2025年06月21日 10:14:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EventSubType("2016")
|
@EventSubType("2012")
|
||||||
public class SubType2016Handler extends AbstractEventDataHandler<EdhDrugDeliveryNoteApplyInfoVO> {
|
public class SubType2012Handler extends AbstractEventDataHandler<EdhDrugDeliveryNoteApplyInfoVO> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
|
@ -1,12 +1,8 @@
|
||||||
package com.supervision.edh.service.handle.core;
|
package com.supervision.edh.service.handle.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.supervision.edh.domain.EdhDrugDeliveryNoteApplyInfo;
|
|
||||||
import com.supervision.edh.domain.EdhDrugInvoiceApplyInfo;
|
|
||||||
import com.supervision.edh.domain.EdhWarehouseStockApplyInfo;
|
import com.supervision.edh.domain.EdhWarehouseStockApplyInfo;
|
||||||
import com.supervision.edh.domain.vo.*;
|
import com.supervision.edh.domain.vo.*;
|
||||||
import com.supervision.edh.service.IEdhWarehouseStockApplyInfoService;
|
import com.supervision.edh.service.IEdhWarehouseStockApplyInfoService;
|
||||||
import com.supervision.edh.service.IEdhWhTempHumidityApplyInfoService;
|
|
||||||
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
||||||
import com.supervision.edh.service.handle.EventSubType;
|
import com.supervision.edh.service.handle.EventSubType;
|
||||||
import com.supervision.edh.utils.JsonUtils;
|
import com.supervision.edh.utils.JsonUtils;
|
||||||
|
@ -27,8 +23,8 @@ import java.util.stream.Collectors;
|
||||||
* @date 2025年06月23日 11:22:43
|
* @date 2025年06月23日 11:22:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EventSubType("2019")
|
@EventSubType("2013")
|
||||||
public class SubType2019Handler extends AbstractEventDataHandler<EdhWarehouseStockApplyInfoVO> {
|
public class SubType2013Handler extends AbstractEventDataHandler<EdhWarehouseStockApplyInfoVO> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
|
@ -1,6 +1,5 @@
|
||||||
package com.supervision.edh.service.handle.core;
|
package com.supervision.edh.service.handle.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
||||||
import com.supervision.edh.domain.vo.EdhWhTempHumidityApplyInfoVO;
|
import com.supervision.edh.domain.vo.EdhWhTempHumidityApplyInfoVO;
|
||||||
import com.supervision.edh.service.IEdhWhTempHumidityApplyInfoService;
|
import com.supervision.edh.service.IEdhWhTempHumidityApplyInfoService;
|
||||||
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
import com.supervision.edh.service.handle.AbstractEventDataHandler;
|
||||||
|
@ -19,8 +18,8 @@ import org.springframework.util.CollectionUtils;
|
||||||
* @date 2025年06月21日 16:14:43
|
* @date 2025年06月21日 16:14:43
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@EventSubType("2052")
|
@EventSubType("2014")
|
||||||
public class SubType2052Handler extends AbstractEventDataHandler<EdhWhTempHumidityApplyInfoVO> {
|
public class SubType2014Handler extends AbstractEventDataHandler<EdhWhTempHumidityApplyInfoVO> {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
|
@ -7,9 +7,12 @@ import lombok.RequiredArgsConstructor;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.scheduling.annotation.AsyncResult;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason
|
* @author Jason
|
||||||
|
@ -22,10 +25,22 @@ public class EventProcessingServiceImpl{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(EventProcessingServiceImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(EventProcessingServiceImpl.class);
|
||||||
private final EventHandlerFactory handlerFactory;
|
private final EventHandlerFactory handlerFactory;
|
||||||
|
|
||||||
@Async
|
// @Async
|
||||||
public void asyncProcessEvent(EventPojo eventPojo, String data,String eventId) {
|
// public void asyncProcessEvent(EventPojo eventPojo, String data,String eventId) {
|
||||||
EventDataHandler handler = handlerFactory.getHandler(eventPojo.getSubType());
|
// EventDataHandler handler = handlerFactory.getHandler(eventPojo.getSubType());
|
||||||
handler.handleData(data,eventId);
|
// handler.handleData(data,eventId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public CompletableFuture<Void> asyncProcessEvent(EventPojo eventPojo, String data,String eventId) {
|
||||||
|
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||||
|
try {
|
||||||
|
// 业务逻辑...
|
||||||
|
EventDataHandler handler = handlerFactory.getHandler(eventPojo.getSubType());
|
||||||
|
handler.handleData(data,eventId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
future.completeExceptionally(e); // 传递异常
|
||||||
|
}
|
||||||
|
return future;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class JsonUtils {
|
||||||
return mapper.readValue(json, clazz);
|
return mapper.readValue(json, clazz);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
log.error("数据解析错误:"+e.getMessage());
|
log.error("数据解析错误:"+e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException("数据解析错误: " + e.getMessage()); // 自定义业务异常
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue