From 0d30c93d000413c6eb34f489ef17688ad4175201 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Mon, 29 Apr 2024 18:18:21 +0800 Subject: [PATCH] 55测试环境 --- src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java | 140 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 137 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java b/src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java index e26554d..3766adb 100644 --- a/src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java +++ b/src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java @@ -1,27 +1,161 @@ package com.xcong.excoin.rabbit.consumer; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; import com.xcong.excoin.configurations.RabbitMqConfig; +import com.xcong.excoin.modules.member.dao.MemberDao; +import com.xcong.excoin.modules.member.dao.MemberSettingDao; +import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; +import com.xcong.excoin.modules.member.entity.MemberEntity; +import com.xcong.excoin.modules.member.entity.MemberSettingEntity; +import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; +import com.xcong.excoin.modules.otc.dao.OtcEntrustOrderDao; +import com.xcong.excoin.modules.otc.dao.OtcMarketBussinessDao; +import com.xcong.excoin.modules.otc.dao.OtcOrderDao; +import com.xcong.excoin.modules.otc.dao.OtcReturnMoneyDao; +import com.xcong.excoin.modules.otc.entity.OtcEntrustOrder; +import com.xcong.excoin.modules.otc.entity.OtcMarketBussiness; +import com.xcong.excoin.modules.otc.entity.OtcOrder; +import com.xcong.excoin.modules.otc.entity.OtcReturnMoney; +import com.xcong.excoin.utils.LogRecordUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.util.Date; +import java.util.List; +import java.util.Map; @Slf4j @Component @ConditionalOnProperty(prefix = "app", name = "otc-job", havingValue = "true") public class OtcConsumer { + @Autowired + private OtcMarketBussinessDao otcMarketBussinessDao; -// @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS) + @Autowired + private OtcEntrustOrderDao otcEntrustOrderDao; + + @Autowired + private OtcOrderDao otcOrderDao; + + @Autowired + private MemberDao memberDao; + + @Autowired + private MemberSettingDao memberSettingDao; + + @Autowired + private MemberWalletCoinDao memberWalletCoinDao; + + @Autowired + private OtcReturnMoneyDao otcReturnMoneyDao; + + @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS) public void marketBussiness(String content) { - log.info("---->{}", content); + log.info("收到市商消息:{}", content); + JSONObject jsonObject = JSONObject.parseObject(content); + Integer entrustOrderIdInt = jsonObject.getInteger("entrustOrderId"); + Long entrustOrderId = entrustOrderIdInt.longValue(); + Integer status = jsonObject.getInteger("status"); + OtcEntrustOrder entrustOrder = otcEntrustOrderDao.selectById(entrustOrderId); + + OtcMarketBussiness mb = otcMarketBussinessDao.selectMarketBussinessByMemberId(entrustOrder.getMemberId()); + + if (!OtcOrder.STATUS_CANCEL.equals(status)) { + if (OtcEntrustOrder.ORDER_TYPE_S.equals(entrustOrder.getOrderType())) { + mb.setSaleOrderCnt(mb.getSaleOrderCnt() + 1); + mb.setSaleTotalCnt(mb.getSaleTotalCnt() + 1); + } else { + mb.setBuyOrderCnt(mb.getBuyOrderCnt() + 1); + mb.setTotalOrderCnt(mb.getTotalOrderCnt() + 1); + } + } else { + if (OtcEntrustOrder.ORDER_TYPE_S.equals(entrustOrder.getOrderType())) { + mb.setSaleTotalCnt(mb.getSaleTotalCnt() + 1); + } else { + mb.setTotalOrderCnt(mb.getTotalOrderCnt() + 1); + } + } + + if (mb.getTotalOrderCnt() != 0) { + BigDecimal buyFinishRatio = BigDecimal.valueOf(mb.getBuyOrderCnt()).divide(BigDecimal.valueOf(mb.getTotalOrderCnt()), 8, BigDecimal.ROUND_DOWN); + mb.setFinishRatio(buyFinishRatio); + } + + if (mb.getSaleTotalCnt() != 0) { + BigDecimal saleFinishRatio = BigDecimal.valueOf(mb.getSaleOrderCnt()).divide(BigDecimal.valueOf(mb.getSaleTotalCnt()), 8, BigDecimal.ROUND_DOWN); + mb.setSaleFinishRatio(saleFinishRatio); + } + + + // 平均付款时间 +// BigDecimal avgPayTime = otcOrderDao.selectMemberAvgPayTime(mb.getMemberId()); +// // 平均放币时间 +// BigDecimal avgCoinTime = otcOrderDao.selectMemberAvgCoinTime(mb.getMemberId()); +// +// mb.setAvgPayTime(avgPayTime.intValue()); +// mb.setAvgCoinTime(avgCoinTime.intValue()); + + otcMarketBussinessDao.updateById(mb); } - @RabbitListener(queues = RabbitMqConfig.QUEUE_DELAY) +// @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS) public void delayOrder(String content) { log.info("--{}-->{}", new Date(), content); } + + + @RabbitListener(queues = RabbitMqConfig.QUEUE_ORDER_RETURN) + @Transactional(rollbackFor = Exception.class) + public void orderReturn(String content) { + log.info("收到返佣消息:{}", content); + OtcOrder order = otcOrderDao.selectOrderUnEntrust(content); + + MemberEntity member = memberDao.selectById(order.getMemberId()); + List<String> refererIds = StrUtil.split(member.getRefererIds(), ','); + + List<MemberEntity> parentMembers = memberDao.selectMemberListByReferer(refererIds); + + if (CollUtil.isNotEmpty(parentMembers)) { + int isFirst = 1; + for (MemberEntity parent : parentMembers) { + MemberSettingEntity memberSetting = memberSettingDao.selectMemberSettingByMemberId(parent.getId()); + + BigDecimal returnRatio = BigDecimal.ZERO; + if (isFirst == 1) { + returnRatio = memberSetting.getOtcReturnFirst(); + } else { + returnRatio = memberSetting.getOtcReturnSecond(); + } + + BigDecimal returnAmount = order.getCoinAmount().multiply(returnRatio); + + MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(parent.getId(), "USDT"); + memberWalletCoinDao.updateBlockBalance(wallet.getId(), returnAmount, BigDecimal.ZERO, 0); + + LogRecordUtils.insertMemberAccountMoneyChange(parent.getId(),"订单返利:" + content, returnAmount, "USDT", 1, 1); + + OtcReturnMoney otcReturnMoney = new OtcReturnMoney(); + otcReturnMoney.setToMemberId(parent.getId()); + otcReturnMoney.setOrderNo(content); + otcReturnMoney.setFromMemberId(member.getId()); + otcReturnMoney.setAmount(returnAmount); + otcReturnMoneyDao.insert(otcReturnMoney); + + isFirst = 0; + } + } + + order.setIsReturn(1); + otcOrderDao.updateIsReturnByOrderNo(1, content); + } + } -- Gitblit v1.9.1