From 0ca7bf5c850eaef852a6b49d4b94e8366deedb29 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 26 May 2021 15:03:51 +0800
Subject: [PATCH] 20210525  申诉

---
 src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java |   49 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java b/src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java
index 10b8b37..de11da3 100644
--- a/src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java
+++ b/src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java
@@ -4,13 +4,20 @@
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xcong.excoin.common.contants.AppContants;
+import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
+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.OtcSettingDao;
 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.OtcSetting;
 import com.xcong.excoin.modules.otc.service.OtcOrderService;
+import com.xcong.excoin.utils.RedisUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -32,18 +39,50 @@
     private OtcEntrustOrderDao otcEntrustOrderDao;
     @Autowired
     private OtcMarketBussinessDao otcMarketBussinessDao;
-
+    @Autowired
+    private MemberWalletCoinDao memberWalletCoinDao;
+    @Autowired
+    private OtcSettingDao otcSettingDao;
+    @Autowired
+    private RedisUtils redisUtils;
 
     @Scheduled(cron = "0/1 * * * * ? ")
     public void autoCancelOrder() {
         List<OtcOrder> otcOrders = otcOrderDao.selectOrderListWithStatusAndType(OtcEntrustOrder.ORDER_TYPE_B, OtcOrder.STATUS_SUBMIT);
         if (CollUtil.isNotEmpty(otcOrders)) {
             for (OtcOrder otcOrder : otcOrders) {
-                long between = DateUtil.between(new Date(), DateUtil.offsetMinute(otcOrder.getCreateTime(), 30), DateUnit.SECOND, false);
+                long between = DateUtil.between(new Date(), DateUtil.offsetMinute(otcOrder.getCreateTime(), 3), DateUnit.SECOND, false);
 
                 if (between <= 0) {
+                    OtcOrder saleOrder = otcOrderDao.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_S);
+                    if (!saleOrder.getMemberId().equals(saleOrder.getEntrustMemberId())) {
+                        MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(saleOrder.getMemberId(), "USDT");
+                        memberWalletCoinDao.subFrozenBalance(saleOrder.getMemberId(), wallet.getId(), saleOrder.getCoinAmount());
+                    }
+
                     otcEntrustOrderDao.updateRemainAmount(otcOrder.getEntrustOrderId(), otcOrder.getCoinAmount());
                     otcOrderDao.updateOrderStatusByOrderNo(OtcOrder.STATUS_CANCEL, null, otcOrder.getOrderNo());
+
+                    Long memberId;
+                    if (otcOrder.getMemberId().equals(otcOrder.getEntrustMemberId())) {
+                        memberId = otcOrder.getOppositeMemberId();
+                    } else {
+                        memberId = otcOrder.getMemberId();
+                    }
+
+                    OtcSetting setting = otcSettingDao.selectById(1L);
+                    String times = redisUtils.getString(AppContants.OTC_ORDER_CANCEL_TIMES + memberId);
+                    if (StrUtil.isNotBlank(times)) {
+                        int i = Integer.parseInt(times);
+                        i++;
+                        if (i >= setting.getCancellNum()) {
+                            redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + memberId, i, 86400);
+                        } else {
+                            redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + memberId, i);
+                        }
+                    } else {
+                        redisUtils.set(AppContants.OTC_ORDER_CANCEL_TIMES + memberId, 1, 86400);
+                    }
                 }
             }
         }
@@ -60,7 +99,10 @@
                 Integer totalCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), null);
                 // 完成率
                 Integer finishCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), OtcOrder.STATUS_FINISH);
-                BigDecimal finishRatio = BigDecimal.valueOf(finishCnt).divide(BigDecimal.valueOf(totalCnt), 4, BigDecimal.ROUND_DOWN);
+                if (totalCnt != null && totalCnt != 0) {
+                    BigDecimal finishRatio = BigDecimal.valueOf(finishCnt).divide(BigDecimal.valueOf(totalCnt), 4, BigDecimal.ROUND_DOWN);
+                    mb.setFinishRatio(finishRatio);
+                }
                 // 平均付款时间
                 BigDecimal avgPayTime = otcOrderDao.selectMemberAvgPayTime(mb.getMemberId());
                 // 平均放币时间
@@ -68,7 +110,6 @@
 
                 mb.setBuyCnt(buyCnt);
                 mb.setTotalOrderCnt(totalCnt);
-                mb.setFinishRatio(finishRatio);
                 mb.setAvgPayTime(avgPayTime.intValue());
                 mb.setAvgCoinTime(avgCoinTime.intValue());
 

--
Gitblit v1.9.1