Helius
2021-06-08 30c1c9d16a57d2bbc7cd1511d02c5ddcc6a143f6
src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java
@@ -4,15 +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;
@@ -36,7 +41,10 @@
    private OtcMarketBussinessDao otcMarketBussinessDao;
    @Autowired
    private MemberWalletCoinDao memberWalletCoinDao;
    @Autowired
    private OtcSettingDao otcSettingDao;
    @Autowired
    private RedisUtils redisUtils;
    @Scheduled(cron = "0/1 * * * * ? ")
    public void autoCancelOrder() {
@@ -54,25 +62,55 @@
                    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);
                    }
                }
            }
        }
    }
    @Scheduled(cron = "0 0/5 * * * ? ")
//    @Scheduled(cron = "0 0/5 * * * ? ")
    public void marketBussinessJob() {
        List<OtcMarketBussiness> list = otcMarketBussinessDao.selectList(null);
        if (CollUtil.isNotEmpty(list)) {
            for (OtcMarketBussiness mb : list) {
                // 服务人数
                Integer buyCnt = otcOrderDao.selectMemberCntForEntrust(mb.getMemberId());
                // 总单数
                Integer totalCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), null);
                // 完成率
                Integer finishCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), OtcOrder.STATUS_FINISH);
                if (totalCnt != null) {
                    BigDecimal finishRatio = BigDecimal.valueOf(finishCnt).divide(BigDecimal.valueOf(totalCnt), 4, BigDecimal.ROUND_DOWN);
                // 买单数
                Integer buyTotalCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), null, OtcEntrustOrder.ORDER_TYPE_B);
                // 买单完成率
                Integer buyFinishCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), OtcOrder.STATUS_FINISH, OtcEntrustOrder.ORDER_TYPE_B);
                if (buyTotalCnt != null && buyTotalCnt != 0) {
                    BigDecimal finishRatio = BigDecimal.valueOf(buyFinishCnt).divide(BigDecimal.valueOf(buyTotalCnt), 4, BigDecimal.ROUND_DOWN);
                    mb.setFinishRatio(finishRatio);
                }
                // 买单数
                Integer saleTotalCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), null, OtcEntrustOrder.ORDER_TYPE_S);
                // 买单完成率
                Integer saleFinishCnt = otcOrderDao.selectTotalOrderCount(mb.getMemberId(), OtcOrder.STATUS_FINISH, OtcEntrustOrder.ORDER_TYPE_S);
                if (saleTotalCnt != null && saleTotalCnt != 0) {
                    BigDecimal finishRatio = BigDecimal.valueOf(saleFinishCnt).divide(BigDecimal.valueOf(saleTotalCnt), 4, BigDecimal.ROUND_DOWN);
                    mb.setSaleFinishRatio(finishRatio);
                }
                // 平均付款时间
                BigDecimal avgPayTime = otcOrderDao.selectMemberAvgPayTime(mb.getMemberId());
@@ -80,7 +118,8 @@
                BigDecimal avgCoinTime = otcOrderDao.selectMemberAvgCoinTime(mb.getMemberId());
                mb.setBuyCnt(buyCnt);
                mb.setTotalOrderCnt(totalCnt);
                mb.setTotalOrderCnt(buyTotalCnt);
                mb.setSaleOrderCnt(saleTotalCnt);
                mb.setAvgPayTime(avgPayTime.intValue());
                mb.setAvgCoinTime(avgCoinTime.intValue());