Helius
2021-05-21 565db646d1f2e5ba8e680f97555dd6b18623bbde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.xcong.excoin.quartz.job;
 
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
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.entity.OtcEntrustOrder;
import com.xcong.excoin.modules.otc.entity.OtcMarketBussiness;
import com.xcong.excoin.modules.otc.entity.OtcOrder;
import com.xcong.excoin.modules.otc.service.OtcOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
@Slf4j
@Component
@ConditionalOnProperty(prefix = "app", name = "otc-job", havingValue = "true")
public class OtcOrderJob {
 
    @Autowired
    private OtcOrderDao otcOrderDao;
    @Autowired
    private OtcEntrustOrderDao otcEntrustOrderDao;
    @Autowired
    private OtcMarketBussinessDao otcMarketBussinessDao;
 
 
    @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);
 
                if (between <= 0) {
                    otcEntrustOrderDao.updateRemainAmount(otcOrder.getEntrustOrderId(), otcOrder.getCoinAmount());
                    otcOrderDao.updateOrderStatusByOrderNo(OtcOrder.STATUS_CANCEL, null, otcOrder.getOrderNo());
                }
            }
        }
    }
 
    @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);
                BigDecimal finishRatio = BigDecimal.valueOf(finishCnt).divide(BigDecimal.valueOf(totalCnt), 4, BigDecimal.ROUND_DOWN);
                // 平均付款时间
 
                // 平均放币时间
            }
        }
    }
 
}