KKSU
2024-05-09 00acaa0aa6fda098764a70e341ad29b4ffa0c35e
src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java
@@ -21,6 +21,7 @@
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -188,47 +189,57 @@
         * 生成对应的产矿流水
         */
        String address = e.adr;
        String blockHash = e.blockHash;
        DappMemberEntity dappMemberEntity = dappMemberDao.selectByAddress(address, null);
        if(ObjectUtil.isEmpty(dappMemberEntity)){
            return;
        }
        int decimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals();
        BigDecimal amount = new BigDecimal(e.amount.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN);
        BigDecimal price = new BigDecimal(e.price.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN);
        BigDecimal sameCoin = new BigDecimal(e.sameCoin.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN);
        BigDecimal finxMineCoin = new BigDecimal(e.finxMineCoin.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN);
        int decimals = ChainService.getInstance(ChainEnum.BSC_GFA.name()).decimals();
        BigDecimal amount = new BigDecimal(e.amount.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN);
        BigDecimal price = new BigDecimal(e.price.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN);
        BigDecimal usdtTarget = new BigDecimal(e.usdtTarget.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN);
        BigDecimal coinTarget = new BigDecimal(e.coinTarget.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN);
        BigDecimal usdtCoin = new BigDecimal(e.usdtCoin.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN);
        BigInteger lastMineTime = e.lastMineTime;
        BigInteger thisMineTime = e.thisMineTime;
        Long memberId = dappMemberEntity.getId();
        DappMemberFund dappMemberFund = new DappMemberFund();
        dappMemberFund.setMemberId(memberId);
        dappMemberFund.setAddress(address);
        dappMemberFund.setAmount(amount);
        dappMemberFund.setPrice(price);
        dappMemberFund.setSameCoin(sameCoin);
        dappMemberFund.setFinxMineCoin(finxMineCoin);
        dappMemberFund.setLastMineTime(lastMineTime.toString());
        dappMemberFund.setThisMineTime(thisMineTime.toString());
        dappMemberFundMapper.insert(dappMemberFund);
        QueryWrapper<DappMemberFund> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("block_hash",blockHash);
        objectQueryWrapper.eq("address",address);
        objectQueryWrapper.eq("price",price);
        objectQueryWrapper.eq("usdt_target",usdtTarget);
        objectQueryWrapper.eq("coin_target",coinTarget);
        List<DappMemberFund> dappMemberFunds = dappMemberFundMapper.selectList(objectQueryWrapper);
        if(CollUtil.isEmpty(dappMemberFunds)){
            Long memberId = dappMemberEntity.getId();
            DappMemberFund dappMemberFund = new DappMemberFund();
            dappMemberFund.setMemberId(memberId);
            dappMemberFund.setAddress(address);
            dappMemberFund.setBlockHash(blockHash);
            dappMemberFund.setAmount(amount);
            dappMemberFund.setPrice(price);
            dappMemberFund.setUsdtTarget(usdtTarget);
            dappMemberFund.setCoinTarget(coinTarget);
            dappMemberFund.setUsdtCoin(usdtCoin);
            dappMemberFund.setLastMineTime(lastMineTime.toString());
            dappMemberFundMapper.insert(dappMemberFund);
            DappFundFlowEntity fundFlowTuiJian1 = new DappFundFlowEntity(
                    memberId,
                    usdtTarget,
                    FlowTypeEnum.ZHIYA_CHA_CHU.getValue(),
                    DappFundFlowEntity.WITHDRAW_STATUS_AGREE,
                    StrUtil.format("金本位{},价格{}。",usdtTarget,price));
        DappFundFlowEntity fundFlowTuiJian1 = new DappFundFlowEntity(
                memberId,
                amount,
                FlowTypeEnum.ZHIYA_CHA_CHU.getValue(),
                DappFundFlowEntity.WITHDRAW_STATUS_AGREE,
                StrUtil.format("金本位{}",sameCoin));
            dappFundFlowDao.insert(fundFlowTuiJian1);
        dappFundFlowDao.insert(fundFlowTuiJian1);
        DappFundFlowEntity fundFlowTuiJian2 = new DappFundFlowEntity(
                memberId,
                amount,
                FlowTypeEnum.ZHIYA_CHA_CHU.getValue(),
                DappFundFlowEntity.WITHDRAW_STATUS_AGREE,
                StrUtil.format("币本位{},价格{}。",finxMineCoin,price));
        dappFundFlowDao.insert(fundFlowTuiJian2);
        log.info("本地交易:{},amount-{},price-{}", e.adr,amount,price);
            DappFundFlowEntity fundFlowTuiJian2 = new DappFundFlowEntity(
                    memberId,
                    coinTarget,
                    FlowTypeEnum.ZHIYA_CHA_CHU.getValue(),
                    DappFundFlowEntity.WITHDRAW_STATUS_AGREE,
                    StrUtil.format("币本位{},价格{}。",coinTarget,price));
            dappFundFlowDao.insert(fundFlowTuiJian2);
            log.info("本地交易:{},amount-{},price-{}", e.adr,amount,price);
        }
    }
}