Helius
2021-06-01 25aec7899b8ab3d483bbfd6d7580c6966318ee7f
src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java
@@ -1,26 +1,63 @@
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.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;
//    @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS)
    @Autowired
    private OtcEntrustOrderDao otcEntrustOrderDao;
    @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS)
    public void marketBussiness(String content) {
        log.info("---->{}", 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());
        mb.setTotalOrderCnt(mb.getTotalOrderCnt() + 1);
        if (!OtcOrder.STATUS_CANCEL.equals(status)) {
            if (OtcEntrustOrder.ORDER_TYPE_S.equals(entrustOrder.getOrderType())) {
                mb.setSaleOrderCnt(mb.getSaleOrderCnt() + 1);
            } else {
                mb.setBuyOrderCnt(mb.getBuyOrderCnt() + 1);
            }
        }
        BigDecimal buyFinishRatio = BigDecimal.valueOf(mb.getBuyOrderCnt()).divide(BigDecimal.valueOf(mb.getTotalOrderCnt()), 8, BigDecimal.ROUND_DOWN);
        BigDecimal saleFinishRatio = BigDecimal.valueOf(mb.getSaleOrderCnt()).divide(BigDecimal.valueOf(mb.getTotalOrderCnt()), 8, BigDecimal.ROUND_DOWN);
        mb.setFinishRatio(buyFinishRatio);
        mb.setSaleFinishRatio(saleFinishRatio);
        otcMarketBussinessDao.updateById(mb);
    }
    @RabbitListener(queues = RabbitMqConfig.QUEUE_DELAY)
//    @RabbitListener(queues = RabbitMqConfig.QUEUE_MARKET_BUSSINESS)
    public void delayOrder(String content) {
        log.info("--{}-->{}", new Date(), content);
    }