Helius
2021-06-04 b851bab9fdd923e2f6b569a3fdcabb5738a47e88
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.xcong.excoin.rabbit.consumer;
 
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.configurations.RabbitMqConfig;
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 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 java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
 
@Slf4j
@Component
@ConditionalOnProperty(prefix = "app", name = "otc-job", havingValue = "true")
public class OtcConsumer {
 
    @Autowired
    private OtcMarketBussinessDao otcMarketBussinessDao;
 
    @Autowired
    private OtcEntrustOrderDao otcEntrustOrderDao;
 
    @Autowired
    private OtcOrderDao otcOrderDao;
 
    @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS)
    public void marketBussiness(String 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_MARKET_BUSSINESS)
    public void delayOrder(String content) {
        log.info("--{}-->{}", new Date(), content);
    }
}