|
|
@@ -2,6 +2,7 @@ package com.kxs.stat.biz.mq;
|
|
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.kxs.common.core.constant.SecurityConstants;
|
|
|
@@ -10,9 +11,12 @@ import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
import com.kxs.common.core.util.R;
|
|
|
import com.kxs.common.core.util.RetOps;
|
|
|
import com.kxs.common.core.util.TotalDateUtil;
|
|
|
+import com.kxs.stat.api.amqp.rabbit.RabbitLkbActQueueMQ;
|
|
|
import com.kxs.stat.api.amqp.rabbit.RabbitLkbTradeQueueMQ;
|
|
|
+import com.kxs.stat.api.model.KxsLkbActTrade;
|
|
|
import com.kxs.stat.api.model.KxsLkbTrade;
|
|
|
import com.kxs.stat.biz.constant.enums.TotalTypeEnum;
|
|
|
+import com.kxs.stat.biz.service.KxsLkbActTradeService;
|
|
|
import com.kxs.stat.biz.service.KxsLkbTradeService;
|
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
import com.kxs.user.api.model.KxsUser;
|
|
|
@@ -38,12 +42,82 @@ import java.io.IOException;
|
|
|
public class RabbitLkbQueueListener {
|
|
|
|
|
|
private final KxsLkbTradeService kxsLkbTradeService;
|
|
|
+ private final KxsLkbActTradeService kxsLkbActTradeService;
|
|
|
|
|
|
private final RemoteKxsUserService remoteKxsUserService;
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- System.out.println(TotalDateUtil.getMonthNumber(LocalDateTimeUtil.parseDate("2024-03-14T12:54:41", DatePattern.UTC_SIMPLE_PATTERN)));
|
|
|
- System.out.println(TotalDateUtil.getDateNumber(LocalDateTimeUtil.parseDate("2024-03-14T12:54:41", DatePattern.UTC_SIMPLE_PATTERN)));
|
|
|
+// public static void main(String[] args) {
|
|
|
+// System.out.println(TotalDateUtil.getMonthNumber(LocalDateTimeUtil.parseDate("2024-03-14T12:54:41", DatePattern.UTC_SIMPLE_PATTERN)));
|
|
|
+// System.out.println(TotalDateUtil.getDateNumber(LocalDateTimeUtil.parseDate("2024-03-14T12:54:41", DatePattern.UTC_SIMPLE_PATTERN)));
|
|
|
+// }
|
|
|
+ /**
|
|
|
+ * 监听 来客吧商户激活 队列的处理器
|
|
|
+ *
|
|
|
+ * @param message 消息
|
|
|
+ */
|
|
|
+ @RabbitListener(queues = RabbitLkbActQueueMQ.QUEUE_NAME, ackMode = "MANUAL")
|
|
|
+ @RabbitHandler
|
|
|
+ public void onActMessage(String msg, Message message, Channel channel) {
|
|
|
+ try {
|
|
|
+ RabbitLkbActQueueMQ.MsgEntity parse = RabbitLkbActQueueMQ.parse(msg);
|
|
|
+ log.info("来客吧商户激活消费端Payload: " + parse);
|
|
|
+
|
|
|
+ KxsLkbActTrade lkbActTrade = kxsLkbActTradeService.getOne(Wrappers.<KxsLkbActTrade>lambdaQuery()
|
|
|
+ .eq(KxsLkbActTrade::getUserId, parse.getUserId())
|
|
|
+ .eq(KxsLkbActTrade::getTradeMonth, parse.getStatMonth())
|
|
|
+ .eq(KxsLkbActTrade::getTradeDate, parse.getStatDate())
|
|
|
+ .eq(KxsLkbActTrade::getTotalType, TotalTypeEnum.SELF.getType()));
|
|
|
+ if (lkbActTrade == null) {
|
|
|
+ lkbActTrade = new KxsLkbActTrade();
|
|
|
+ lkbActTrade.setActNum(1);
|
|
|
+ lkbActTrade.setTradeMonth(Integer.valueOf(parse.getStatMonth()));
|
|
|
+ lkbActTrade.setTradeDate(Integer.valueOf(parse.getStatDate()));
|
|
|
+ lkbActTrade.setTotalType(TotalTypeEnum.SELF.getType());
|
|
|
+ kxsLkbActTradeService.save(lkbActTrade);
|
|
|
+ }else{
|
|
|
+ lkbActTrade.setActNum(lkbActTrade.getActNum() + 1);
|
|
|
+ kxsLkbActTradeService.updateById(lkbActTrade);
|
|
|
+ }
|
|
|
+ //团队业绩
|
|
|
+ R<KxsUser> kxsUserR = remoteKxsUserService.loadUserById(Integer.valueOf(parse.getUserId()), SecurityConstants.FROM_IN);
|
|
|
+ KxsUser user = RetOps.of(kxsUserR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
+ String pidPath = user.getPidPath();
|
|
|
+ String[] split = pidPath.split(StrUtil.COMMA);
|
|
|
+ for (String userId : split) {
|
|
|
+ int pid = Integer.parseInt(userId);
|
|
|
+ if(pid <= 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ KxsLkbActTrade lkbActTradeTeam = kxsLkbActTradeService.getOne(Wrappers.<KxsLkbActTrade>lambdaQuery()
|
|
|
+ .eq(KxsLkbActTrade::getUserId, parse.getUserId())
|
|
|
+ .eq(KxsLkbActTrade::getTradeMonth, parse.getStatMonth())
|
|
|
+ .eq(KxsLkbActTrade::getTradeDate, parse.getStatDate())
|
|
|
+ .eq(KxsLkbActTrade::getTotalType, TotalTypeEnum.TEAM.getType()));
|
|
|
+ if (lkbActTradeTeam == null) {
|
|
|
+ lkbActTradeTeam = new KxsLkbActTrade();
|
|
|
+ lkbActTradeTeam.setActNum(1);
|
|
|
+ lkbActTradeTeam.setTradeMonth(Integer.valueOf(parse.getStatMonth()));
|
|
|
+ lkbActTradeTeam.setTradeDate(Integer.valueOf(parse.getStatDate()));
|
|
|
+ lkbActTradeTeam.setTotalType(TotalTypeEnum.TEAM.getType());
|
|
|
+ kxsLkbActTradeService.save(lkbActTradeTeam);
|
|
|
+ }else{
|
|
|
+ lkbActTradeTeam.setActNum(lkbActTradeTeam.getActNum() + 1);
|
|
|
+ kxsLkbActTradeService.updateById(lkbActTradeTeam);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ log.info("来客吧商户激活消费成功:{}", JSON.toJSONString(parse));
|
|
|
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error("来客吧商户激活消费失败:{}", JSON.toJSONString(msg), e);
|
|
|
+ try {
|
|
|
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ } catch (IOException ex) {
|
|
|
+ log.error("来客吧商户激活消费失败" + ex.getMessage(), ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* 监听 来客吧交易 队列的处理器
|
|
|
@@ -101,7 +175,7 @@ public class RabbitLkbQueueListener {
|
|
|
.getData()
|
|
|
.orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.USER_NOT_FOUND.getDescription()));
|
|
|
String pidPath = user.getPidPath();
|
|
|
- String[] split = pidPath.split(",");
|
|
|
+ String[] split = pidPath.split(StrUtil.COMMA);
|
|
|
for (String userId : split) {
|
|
|
int pid = Integer.parseInt(userId);
|
|
|
if(pid <= 0){
|