Helius
2021-05-21 565db646d1f2e5ba8e680f97555dd6b18623bbde
modify
2 files added
6 files modified
136 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java 71 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java 2 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 1 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/otc/OtcOrderDao.xml 18 ●●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/OtcTest.java 20 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java
@@ -18,4 +18,10 @@
    int updateOrderStatusByOrderNo(@Param("status") Integer status, @Param("payName") String payName, @Param("orderNo") String orderNo);
    OtcOrder selectOrderByOrderNoAndType(@Param("orderNo") String orderNo, @Param("orderType") String orderType);
    List<OtcOrder> selectOrderListWithStatusAndType(@Param("type") String orderType, @Param("status") Integer status);
    Integer selectMemberCntForEntrust(@Param("entrustMemberId") Long entrustMemberId);
    Integer selectTotalOrderCount(@Param("entrustMemberId") Long entrustMemberId, @Param("status") Integer status);
}
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcEntrustOrderServiceImpl.java
@@ -75,7 +75,19 @@
            memberWalletCoinDao.updateFrozenBalance(member.getId(), coinWallet.getId(), totalAmount);
        }
//        OtcMarketBussiness mb = otcMarketBussinessDao.selectMarketBussinessByMemberId(member.getId());
        OtcMarketBussiness mb = otcMarketBussinessDao.selectMarketBussinessByMemberId(member.getId());
        if (mb == null) {
            OtcMarketBussiness otcMb = new OtcMarketBussiness();
            otcMb.setMemberId(member.getId());
            otcMb.setAvgCoinTime(0);
            otcMb.setAvgPayTime(0);
            otcMb.setTotalOrderCnt(0);
            otcMb.setBuyCnt(0);
            otcMb.setFinishRatio(BigDecimal.ZERO);
            otcMb.setStatus(OtcMarketBussiness.CHECK_PASS);
            otcMarketBussinessDao.insert(otcMb);
        }
        if (member.getIsTrader() == 2) {
            otcEntrustOrder.setIsMb(OtcEntrustOrder.IS_MB_N);
        } else {
src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
@@ -272,7 +272,7 @@
        buyDetail.setStatus(buyOrder.getStatus());
        buyDetail.setTotalAmount(buyOrder.getTotalAmount());
        buyDetail.setUnitPrice(buyOrder.getUnitPrice());
        buyDetail.setCreateTime(new Date());
        buyDetail.setCreateTime(buyOrder.getCreateTime());
        buyDetail.setIsMb(member.getIsTrader());
        OtcOrder saleOrder = this.baseMapper.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_S);
@@ -320,7 +320,7 @@
        saleDetail.setStatus(saleOrder.getStatus());
        saleDetail.setTotalAmount(saleOrder.getTotalAmount());
        saleDetail.setUnitPrice(saleOrder.getUnitPrice());
        saleDetail.setCreateTime(new Date());
        saleDetail.setCreateTime(saleOrder.getCreateTime());
        saleDetail.setIsMb(member.getIsTrader());
        saleDetail.setPayName(saleOrder.getPayName());
src/main/java/com/xcong/excoin/quartz/job/OtcOrderJob.java
New file
@@ -0,0 +1,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);
                // 平均付款时间
                // 平均放币时间
            }
        }
    }
}
src/main/java/com/xcong/excoin/rabbit/consumer/OtcConsumer.java
@@ -3,10 +3,12 @@
import com.xcong.excoin.configurations.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@ConditionalOnProperty(prefix = "app", name = "otc-job", havingValue = "true")
public class OtcConsumer {
src/main/resources/application.yml
@@ -107,6 +107,7 @@
  loop-job: false
  rabbit-consumer: false
  block-job: false
  otc-job: true
aliyun:
  oss:
src/main/resources/mapper/otc/OtcOrderDao.xml
@@ -52,4 +52,22 @@
        select * from otc_order
        where order_no=#{orderNo} and order_type=#{orderType}
    </select>
    <select id="selectOrderListWithStatusAndType" resultType="com.xcong.excoin.modules.otc.entity.OtcOrder">
        select * from otc_order
        where order_type=#{type} and status=#{status}
    </select>
    <select id="selectMemberCntForEntrust" resultType="java.lang.Integer">
        select count(distinct member_id) from otc_order
        where entrust_member_id=#{entrustMemberId} and status != 4 and entrust_member_id!=member_id
    </select>
    <select id="selectTotalOrderCount" resultType="java.lang.Integer">
        select count(1) from otc_order
        where entrust_member_id=#{entrustMemberId} and entrust_member_id!=member_id
        <if test="status != null">
            and status #{status}
        </if>
    </select>
</mapper>
src/test/java/com/xcong/excoin/OtcTest.java
New file
@@ -0,0 +1,20 @@
package com.xcong.excoin;
import com.xcong.excoin.rabbit.producer.OtcProducter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@Slf4j
@SpringBootTest
public class OtcTest {
    @Autowired
    private OtcProducter otcProducter;
    @Test
    public void rabbitTest() {
        otcProducter.sendMarketBussinessMsg("123456");
    }
}