| | |
| | | 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); |
| | | 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(), 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); |
| | | } |
| | | } |