wzy
2020-07-12 473609b38373aafec06b74984c73472ad5616d0a
add agent reutrn money test unit
4 files modified
72 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/member/dao/AgentReturnDao.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/entity/AgentReturnEntity.java 10 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/member/AgentReturnDao.xml 4 ●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/ReturnMoneyTest.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/dao/AgentReturnDao.java
@@ -3,8 +3,13 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.member.entity.AgentReturnEntity;
import java.util.List;
/**
 * @author helius
 */
public interface AgentReturnDao extends BaseMapper<AgentReturnEntity> {
    List<AgentReturnEntity> selectAllNeedMoneyReturn();
}
src/main/java/com/xcong/excoin/modules/member/entity/AgentReturnEntity.java
@@ -29,6 +29,16 @@
     */
    public static final int ORDER_TYPE_HOLD = 3;
    /**
     * 是否已返佣 0-否
     */
    public static final int IS_RETURN_N = 0;
    /**
     * 是否已返佣 1-是
     */
    public static final int IS_RETURN_Y = 1;
    private Long memberId;
    private Long orderId;
src/main/resources/mapper/member/AgentReturnDao.xml
@@ -2,4 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xcong.excoin.modules.member.dao.AgentReturnDao">
    <select id="selectAllNeedMoneyReturn" resultType="com.xcong.excoin.modules.member.entity.AgentReturnEntity">
        select * from agent_return where is_return=0
    </select>
</mapper>
src/test/java/com/xcong/excoin/ReturnMoneyTest.java
@@ -1,17 +1,25 @@
package com.xcong.excoin;
import cn.hutool.core.collection.CollUtil;
import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
import com.xcong.excoin.modules.contract.dao.ContractOrderDao;
import com.xcong.excoin.modules.contract.entity.ContractOrderEntity;
import com.xcong.excoin.modules.contract.service.impl.OrderWebsocketServiceImpl;
import com.xcong.excoin.modules.member.dao.AgentReturnDao;
import com.xcong.excoin.modules.member.dao.MemberWalletAgentDao;
import com.xcong.excoin.modules.member.entity.AgentReturnEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletAgentEntity;
import com.xcong.excoin.utils.SpringContextHolder;
import com.xcong.excoin.utils.ThreadPoolUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
/**
 * @author wzy
@@ -23,6 +31,12 @@
    @Resource
    private ContractOrderDao contractOrderDao;
    @Resource
    private AgentReturnDao agentReturnDao;
    @Resource
    private MemberWalletAgentDao memberWalletAgentDao;
    @Resource
    private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao;
    @Test
    public void returnTest() {
@@ -30,4 +44,43 @@
        OrderWebsocketServiceImpl orderWebsocketService = SpringContextHolder.getBean(OrderWebsocketServiceImpl.class);
        orderWebsocketService.calYj(19L, new BigDecimal(4.18004236), entity, AgentReturnEntity.ORDER_TYPE_OPEN);
    }
    @Test
    @Transactional(rollbackFor = Exception.class)
    public void moneyReturnTest() {
        List<AgentReturnEntity> list = agentReturnDao.selectAllNeedMoneyReturn();
        log.info("返佣条数:{}", list.size());
        if (CollUtil.isNotEmpty(list)) {
            for (AgentReturnEntity agentReturn : list) {
                BigDecimal needReturn = agentReturn.getReturnAmount();
                Long memberId = agentReturn.getMemberId();
                MemberWalletAgentEntity walletAgent = memberWalletAgentDao.selectWalletAgentBymIdAndCode(memberId, "USDT");
                if (walletAgent == null) {
                    continue;
                }
                log.info("用户ID:{}, 当前余额:{},总金额:{}, 返佣金额:{}", memberId, walletAgent.getAvailableBalance().toPlainString(), walletAgent.getTotalBalance().toPlainString(), needReturn);
                walletAgent.setAvailableBalance(walletAgent.getAvailableBalance().add(needReturn));
                walletAgent.setTotalBalance(walletAgent.getTotalBalance().add(needReturn));
                agentReturn.setIsReturn(AgentReturnEntity.IS_RETURN_Y);
                MemberAccountMoneyChange moneyChange = new MemberAccountMoneyChange();
                moneyChange.setAmount(needReturn);
                moneyChange.setContent("佣金到账");
                moneyChange.setType(MemberAccountMoneyChange.TYPE_WALLET_AGENT);
                moneyChange.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
                moneyChange.setMemberId(memberId);
                moneyChange.setSymbol("USDT");
//                // 更新代理钱包金额
//                memberWalletAgentDao.updateById(walletAgent);
//                // 更新返佣明细中状态
//                agentReturnDao.updateById(agentReturn);
//                // 插入财务流水记录
//                memberAccountMoneyChangeDao.insert(moneyChange);
            }
        }
    }
}