From 0066395d8a6ea70d622e5173144e9dee2c7a8f1e Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 28 Nov 2023 10:30:02 +0800
Subject: [PATCH] 匹配
---
src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 222 insertions(+), 0 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java
index afa2e83..a0103a0 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java
@@ -8,8 +8,11 @@
import cc.mrbird.febs.mall.service.*;
import cc.mrbird.febs.mall.vo.AdminMallMoneyFlowVo;
import cc.mrbird.febs.mall.vo.AdminTeamEqualsPerkVo;
+import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cc.mrbird.febs.system.mapper.UserMapper;
import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
import cn.hutool.core.math.MathUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@@ -54,6 +57,14 @@
private final MallGoodsMapper mallGoodsMapper;
private final ICommonService commonService;
+
+ private final MallProductBuyRecordMapper mallProductBuyRecordMapper;
+ private final MallProductBuyMapper mallProductBuyMapper;
+ private final MallProductSellMapper mallProductSellMapper;
+ private final MallProductSellRecordMapper mallProductSellRecordMapper;
+ private final MallProductNftMapper mallProductNftMapper;
+ private final AgentProducer agentProducer;
+ private final MallMemberAmountMapper mallMemberAmountMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -810,5 +821,216 @@
List<MallMember> secondLevelRecord = getStarRecord(thirdLevelRecord, MemberLevelEnum.SECOND_LEVEL.name(), amount, orderNo, 0L,MoneyFlowTypeEnum.STAR_PERK_TWO.getValue());
}
+ @Override
+ public void BuyToSell() {
+ /**
+ * nft产品周期到期的已完成买单变成卖单
+ * 计算收益,本金
+ */
+ List<MallProductNft> mallProductNfts = mallProductNftMapper.selectList(null);
+ if(CollUtil.isEmpty(mallProductNfts)){
+ return;
+ }
+ DateTime now = DateUtil.date();
+ for(MallProductNft mallProductNft : mallProductNfts){
+ Long nftId = mallProductNft.getId();
+ List<MallProductBuy> mallProductBuys = mallProductBuyMapper.selectListByStateAndProductNFTId(
+ ProductEnum.PRODUCT_BUY_SUCCESS.getValue(),
+ nftId,
+ ProductEnum.PRODUCT_BUY_MATE_STATE_FAIL.getValue());
+ if(CollUtil.isEmpty(mallProductBuys)){
+ continue;
+ }
+ //周期
+ int cycle = mallProductNft.getCycle();
+ //收益率
+ BigDecimal profitPercent = mallProductNft.getProfit();
+ for(MallProductBuy mallProductBuy : mallProductBuys){
+
+ Date payTime = mallProductBuy.getPayTime();
+ //偏移时间
+ DateTime dateTime = DateUtil.offsetDay(payTime, cycle);
+ int compare = DateUtil.compare(now, dateTime);
+ if(compare <= 0){
+ /**
+ * 更新买单状态
+ * 收益生成一条卖单
+ * 本金生成一条卖单
+ */
+ mallProductBuy.setMateState(ProductEnum.PRODUCT_BUY_MATE_STATE_SUCCESS.getValue());
+ mallProductBuyMapper.updateById(mallProductBuy);
+ BigDecimal nftTotal = mallProductBuy.getNftTotal();
+ insertSell(mallProductBuy.getMemberId(),nftTotal,nftTotal,BigDecimal.ZERO,BigDecimal.ZERO);
+ BigDecimal profit = nftTotal.multiply(profitPercent.multiply(new BigDecimal(0.01)));
+ insertSell(mallProductBuy.getMemberId(),profit,profit,BigDecimal.ZERO,BigDecimal.ZERO);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void timeGetOrderBuy() {
+ DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
+ DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+ DataDictionaryEnum.YU_YUE_END_TIME.getType(),
+ DataDictionaryEnum.YU_YUE_END_TIME.getCode()
+ );
+ DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
+ /**
+ * 当前时间比结束时间大
+ */
+ if(nowTime.compareTo(endTime) >= 0){
+ List<MallProductBuyRecord> mallProductBuyRecords = mallProductBuyRecordMapper.selectByState(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue());
+ if(CollUtil.isNotEmpty(mallProductBuyRecords)){
+ for(MallProductBuyRecord mallProductBuyRecord : mallProductBuyRecords){
+ /**
+ * 用户有超时未支付的订单
+ * 1、冻结账户
+ * 2、更新买单主表
+ * 2、更新卖单主表
+ * 3、更新买单子表的数据
+ * 3、更新卖单子表的数据
+ */
+ agentProducer.sendFcmOrderBuyCancelMsg(mallProductBuyRecord.getId());
+
+// Long buyId = mallProductBuyRecord.getBuyId();
+// Long sellRecordId = mallProductBuyRecord.getSellRecordId();
+// MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(buyId);
+// Long memberIdBuy = mallProductBuy.getMemberId();
+// //冻结账户
+// MallMember mallMemberBuy = memberMapper.selectById(memberIdBuy);
+// mallMemberBuy.setIsFrozen(ProductEnum.MEMBER_FROZEN.getValue());
+// memberMapper.updateById(mallMemberBuy);
+// //更新买单子表的数据
+// mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue());
+// mallProductBuyRecordMapper.updateById(mallProductBuyRecord);
+// //更新买单主表
+// mallProductBuy.setNftAva(mallProductBuy.getNftAva().add(mallProductBuyRecord.getPickNftCnt()));
+// mallProductBuyMapper.updateById(mallProductBuy);
+// //更新卖单子表的数据
+// MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId);
+// mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue());
+// mallProductSellRecordMapper.updateById(mallProductSellRecord);
+// //更新卖单主表
+// Long sellId = mallProductSellRecord.getSellId();
+// MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId);
+// mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().add(mallProductSellRecord.getNftCnt()));
+// mallProductSellMapper.updateById(mallProductSell);
+ }
+ }
+ }
+
+ }
+
+ @Override
+ public void timeGetOrderSell() {
+ DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
+ DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+ DataDictionaryEnum.YU_YUE_END_TIME.getType(),
+ DataDictionaryEnum.YU_YUE_END_TIME.getCode()
+ );
+ DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
+ /**
+ * 当前时间比结束时间大
+ */
+ if(nowTime.compareTo(endTime) >= 0){
+ List<MallProductSellRecord> mallProductSellRecords = mallProductSellRecordMapper.selectListByState(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue());
+ if(CollUtil.isNotEmpty(mallProductSellRecords)){
+ for(MallProductSellRecord mallProductSellRecord : mallProductSellRecords){
+ /**
+ * 卖方
+ * 1:冻结账户
+ */
+ Long sellId = mallProductSellRecord.getSellId();
+ MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId);
+ MallMember mallMember = memberMapper.selectById(mallProductSell.getMemberId());
+ mallMember.setIsFrozen(ProductEnum.MEMBER_FROZEN.getValue());
+ memberMapper.updateById(mallMember);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void timeGetOrderBuyCancel() {
+ /**
+ * nft产品周期到期的已完成买单变成卖单
+ * 计算收益,本金
+ */
+ List<MallProductNft> mallProductNfts = mallProductNftMapper.selectList(null);
+ if(CollUtil.isEmpty(mallProductNfts)){
+ return;
+ }
+ DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date()));
+ DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+ DataDictionaryEnum.YU_YUE_END_TIME.getType(),
+ DataDictionaryEnum.YU_YUE_END_TIME.getCode()
+ );
+ DateTime endTime = DateUtil.parseTime(endTimeDic.getValue());
+ for(MallProductNft mallProductNft : mallProductNfts){
+ Long nftId = mallProductNft.getId();
+ List<MallProductBuy> mallProductBuys = mallProductBuyMapper.selectListByStateAndProductNFTId(
+ ProductEnum.PRODUCT_BUY_ON_GOING.getValue(),
+ nftId,
+ ProductEnum.PRODUCT_BUY_MATE_STATE_FAIL.getValue());
+ if(CollUtil.isEmpty(mallProductBuys)){
+ continue;
+ }
+ for(MallProductBuy mallProductBuy : mallProductBuys){
+ /**
+ * 当前时间比结束时间大
+ */
+ if(nowTime.compareTo(endTime) >= 0){
+ /**
+ * 返回令牌
+ * 预约记录超时
+ */
+ String orderNo = mallProductBuy.getOrderNo();
+ mallProductBuy.setState(ProductEnum.PRODUCT_BUY_TIMEOUT.getValue());
+ mallProductBuyMapper.updateById(mallProductBuy);
+
+ Long memberId = mallProductBuy.getMemberId();
+ MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectByOrderAndType(orderNo,
+ MoneyFlowTypeNewEnum.TOKEN_BUY_FROZEN.getValue(),
+ FlowTypeNewEnum.TOKEN.getValue(),
+ memberId);
+ if(ObjectUtil.isEmpty(mallMoneyFlow)){
+ continue;
+ }
+ BigDecimal absAmount = mallMoneyFlow.getAmount().abs();
+ MallMemberAmount mallMemberAmount = mallMemberAmountMapper.selectByMemberId(memberId);
+ mallMemberAmount.setTokenAva(mallMemberAmount.getTokenAva().add(absAmount));
+ mallMemberAmount.setTokenFrozen(mallMemberAmount.getTokenFrozen().subtract(absAmount));
+ mallMemberAmountMapper.updateTokenAvaAndTokenFrozenById(mallMemberAmount);
+
+ mallMoneyFlowService.addMoneyFlow(
+ memberId,
+ absAmount,
+ MoneyFlowTypeNewEnum.TOKEN_BUY_FROZEN_RETURN.getValue(),
+ orderNo,
+ null,
+ FlowTypeNewEnum.TOKEN.getValue(),
+ MoneyFlowTypeNewEnum.TOKEN_BUY_FROZEN_RETURN.getDescrition());
+
+
+ }
+ }
+ }
+ }
+
+ public void insertSell(Long memberId,BigDecimal nftCnt,BigDecimal nftCntAva,
+ BigDecimal nftFee,BigDecimal fcmFeeCnt){
+ String orderNo = MallUtils.getOrderNum("NFT");
+ MallProductSell mallProductSell = new MallProductSell();
+ mallProductSell.setMemberId(memberId);
+ mallProductSell.setOrderNo(orderNo);
+ mallProductSell.setNftTotal(nftCnt);
+ mallProductSell.setNftCnt(nftCntAva);
+ mallProductSell.setNftCntAva(nftCntAva);
+ mallProductSell.setNftFee(nftFee);
+ mallProductSell.setFcmFee(fcmFeeCnt);
+ mallProductSell.setState(ProductEnum.PRODUCT_SELL_ON_GOING.getValue());
+ mallProductSellMapper.insert(mallProductSell);
+ }
}
--
Gitblit v1.9.1