|
@@ -3,8 +3,12 @@ package org.dromara.server.consume.business;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjUtil;
|
|
import cn.hutool.core.util.ObjUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
+import org.dromara.backstage.api.RemotePtParameterService;
|
|
|
import org.dromara.backstage.api.domain.vo.RemoteCardVo;
|
|
import org.dromara.backstage.api.domain.vo.RemoteCardVo;
|
|
|
import org.dromara.backstage.api.domain.vo.RemoteMealTypeVo;
|
|
import org.dromara.backstage.api.domain.vo.RemoteMealTypeVo;
|
|
|
import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
|
|
import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
|
|
@@ -16,10 +20,17 @@ import org.dromara.common.core.enums.BalanceUpdateEnum;
|
|
|
import org.dromara.common.core.enums.ResultCodeEnum;
|
|
import org.dromara.common.core.enums.ResultCodeEnum;
|
|
|
import org.dromara.common.core.exception.consume.ConsumeException;
|
|
import org.dromara.common.core.exception.consume.ConsumeException;
|
|
|
import org.dromara.common.core.utils.RecordIdUtils;
|
|
import org.dromara.common.core.utils.RecordIdUtils;
|
|
|
|
|
+import org.dromara.common.message.kafka.domain.KafkaHeader;
|
|
|
|
|
+import org.dromara.common.message.kafka.domain.KafkaMessage;
|
|
|
|
|
+import org.dromara.server.base.mq.constant.CloudConsumeEventConstants;
|
|
|
import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
|
|
import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
|
|
|
|
|
+import org.dromara.server.common.domain.vo.yc.YcPushConsumeInfoVo;
|
|
|
|
|
+import org.dromara.server.base.mq.KafkaNormalProducer;
|
|
|
|
|
+import org.dromara.server.base.mq.constant.PushConsumeEventConstants;
|
|
|
import org.dromara.server.consume.domain.bo.*;
|
|
import org.dromara.server.consume.domain.bo.*;
|
|
|
import org.dromara.server.consume.domain.vo.*;
|
|
import org.dromara.server.consume.domain.vo.*;
|
|
|
import org.dromara.server.consume.service.*;
|
|
import org.dromara.server.consume.service.*;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
@@ -48,6 +59,10 @@ public class BaseBusiness {
|
|
|
private final IXfTermTotalService termTotalService;
|
|
private final IXfTermTotalService termTotalService;
|
|
|
private final IXfConsumeDetailService consumeDetailService;
|
|
private final IXfConsumeDetailService consumeDetailService;
|
|
|
private final IPtBagService bagService;
|
|
private final IPtBagService bagService;
|
|
|
|
|
+ private final KafkaNormalProducer kafkaProducer;
|
|
|
|
|
+
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private final RemotePtParameterService remotePtParameterService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生成原始消费记录
|
|
* 生成原始消费记录
|
|
@@ -143,6 +158,12 @@ public class BaseBusiness {
|
|
|
if (!updateBagBalance(bagVos)) {
|
|
if (!updateBagBalance(bagVos)) {
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.EXCEPTION, "更新钱包余额表失败", ""));
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.EXCEPTION, "更新钱包余额表失败", ""));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 5.发送一条消费记录到kafka
|
|
|
|
|
+ String pushConsume = remotePtParameterService.getPtParameterByKey("PUSH_CONSUME_MQ");
|
|
|
|
|
+ if(ObjectUtil.equals(pushConsume, "1")){
|
|
|
|
|
+ this.sendConsumeToKafka(detailVos,userAccountVo);
|
|
|
|
|
+ }
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -222,6 +243,22 @@ public class BaseBusiness {
|
|
|
return result.get();
|
|
return result.get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Async
|
|
|
|
|
+ public void sendCloudConsume(ConsumptionBo bo){
|
|
|
|
|
+ KafkaMessage<ConsumptionBo> message = new KafkaMessage<>();
|
|
|
|
|
+ KafkaHeader header = message.getHeader();
|
|
|
|
|
+ header.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
+ header.setEventId(CloudConsumeEventConstants.CONSUME_DETAIL);
|
|
|
|
|
+ header.setEventType(CloudConsumeEventConstants.CONSUME_DETAIL);
|
|
|
|
|
+ header.setSender(CloudConsumeEventConstants.SENDER);
|
|
|
|
|
+
|
|
|
|
|
+ message.setHeader(header);
|
|
|
|
|
+ message.setBody(bo);
|
|
|
|
|
+
|
|
|
|
|
+ kafkaProducer.sendKafkaMessage("TO_CLOUD_EVENT", message);
|
|
|
|
|
+ log.info("请求云端消费:{}", JSONUtil.toJsonStr(bo));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 创建一条消费明细记录
|
|
* 创建一条消费明细记录
|
|
|
*
|
|
*
|
|
@@ -274,5 +311,50 @@ public class BaseBusiness {
|
|
|
return consumeDetailService.createConsumeDetailRecord(consumeDetailBo);
|
|
return consumeDetailService.createConsumeDetailRecord(consumeDetailBo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将消费信息发送到kafka
|
|
|
|
|
+ * @param consumeList 消费记录列表
|
|
|
|
|
+ * @param accountVo 消费人员信息
|
|
|
|
|
+ */
|
|
|
|
|
+ private void sendConsumeToKafka(List<XfConsumeDetailVo> consumeList,RemoteUserAccountVo accountVo){
|
|
|
|
|
+ for (XfConsumeDetailVo vo : consumeList) {
|
|
|
|
|
+ YcPushConsumeInfoVo ycSendConsumeInfo = new YcPushConsumeInfoVo();
|
|
|
|
|
+ ycSendConsumeInfo.setRecordId(vo.getRecordId().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setUserId(vo.getUserId().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setUserNumb(vo.getUserNumb());
|
|
|
|
|
+ ycSendConsumeInfo.setXm(vo.getRealName());
|
|
|
|
|
+ ycSendConsumeInfo.setDeptId(vo.getDeptId().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setDeptName(vo.getDeptName());
|
|
|
|
|
+ ycSendConsumeInfo.setRoomId(vo.getRoomId().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setRoomName(vo.getRoomName());
|
|
|
|
|
+ ycSendConsumeInfo.setCardNo(vo.getCardNo().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setFactoryFixId(vo.getFactoryId().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setConsumeValue(vo.getConsumeMoney().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setCardValue(DateUtil.format(vo.getConsumeDate(),DefaultConstants.DATE_TIME_FORMAT));
|
|
|
|
|
+ ycSendConsumeInfo.setConsumeDate(vo.getConsumeDate().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setMealTypeId(vo.getMealType().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setMealName(vo.getMealName());
|
|
|
|
|
+ ycSendConsumeInfo.setTermNo(vo.getTermNo().toString());
|
|
|
|
|
+ ycSendConsumeInfo.setTermName(vo.getTermName());
|
|
|
|
|
+ ycSendConsumeInfo.setCategory(accountVo.getCategory());
|
|
|
|
|
+ ycSendConsumeInfo.setOtherSysId(accountVo.getOtherId());
|
|
|
|
|
+ ycSendConsumeInfo.setClassId(accountVo.getOtherDeptId());
|
|
|
|
|
+ ycSendConsumeInfo.setTermRecordID(vo.getTermRecordId());
|
|
|
|
|
+ ycSendConsumeInfo.setPosRecordState(vo.getRecordStatus().intValue());
|
|
|
|
|
+
|
|
|
|
|
+ KafkaMessage<YcPushConsumeInfoVo> message = new KafkaMessage<>();
|
|
|
|
|
+ KafkaHeader header = message.getHeader();
|
|
|
|
|
+ header.setTimestamp(System.currentTimeMillis());
|
|
|
|
|
+ header.setEventId(PushConsumeEventConstants.CONSUME_DETAIL);
|
|
|
|
|
+ header.setEventType(PushConsumeEventConstants.CONSUME_DETAIL);
|
|
|
|
|
+ header.setSender(PushConsumeEventConstants.SENDER);
|
|
|
|
|
+ message.setHeader(header);
|
|
|
|
|
+ message.setBody(ycSendConsumeInfo);
|
|
|
|
|
+
|
|
|
|
|
+ kafkaProducer.sendKafkaMessage("eventBus", message);
|
|
|
|
|
+ log.info("消费记录发送Kafka:{}", JSONUtil.toJsonStr(ycSendConsumeInfo));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|