KKSU
2024-07-21 650d73c83bf3fefb2c90284639d6b5e706637bcd
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -1,5 +1,6 @@
package cc.mrbird.febs.dapp.service.impl;
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.exception.FebsException;
@@ -18,6 +19,7 @@
import cc.mrbird.febs.dapp.vo.*;
import cc.mrbird.febs.rabbit.producer.ChainProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@@ -94,7 +96,7 @@
        BigDecimal runPerk = dappFundFlowDao.selectSumRunPerkByMemberId(member.getId());
        walletInfo.setRunPerk(runPerk);
//        List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectList(null);
        List<DappStorage> allAddressNums = dappStorageMapper.selectListGroupByMemberId();
        walletInfo.setAddressNum(CollUtil.isEmpty(allAddressNums) ? 0 : allAddressNums.size());
@@ -242,17 +244,26 @@
        DappMemberEntity memberEntity = dappMemberDao.selectById(member.getId());
        BigDecimal usdtBalance = memberEntity.getUsdtBalance();
        if(BigDecimal.ZERO.compareTo(usdtBalance) >= 0){
            throw new FebsException("额度不足");
        }
        if(withdrawDto.getAmount().compareTo(usdtBalance) > 0){
            throw new FebsException("额度不足");
        }
        if(1 != memberEntity.getNodeType()){
            if(BigDecimal.ZERO.compareTo(usdtBalance) >= 0){
                throw new FebsException("额度不足");
            }
        List<MemberCoinWithdrawEntity> memberCoinWithdrawEntities = memberCoinWithdrawDao.selectListByDate(member.getId(),new Date());
        if(CollUtil.isNotEmpty(memberCoinWithdrawEntities)){
            throw new FebsException("今日已提现");
            if(BigDecimal.ZERO.compareTo(withdrawDto.getAmount()) >= 0){
                throw new FebsException("请输入正确的数量");
            }
            if(withdrawDto.getAmount().compareTo(usdtBalance) > 0){
                throw new FebsException("额度不足");
            }
        }else{
            if(BigDecimal.ZERO.compareTo(withdrawDto.getAmount()) >= 0){
                throw new FebsException("请输入正确的数量");
            }
        }
//        List<MemberCoinWithdrawEntity> memberCoinWithdrawEntities = memberCoinWithdrawDao.selectListByDate(member.getId(),new Date());
//        if(CollUtil.isNotEmpty(memberCoinWithdrawEntities)){
//            throw new FebsException("今日已提现");
//        }
        DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
        if (walletCoin.getAvailableAmount().compareTo(withdrawDto.getAmount()) < 0) {
@@ -267,9 +278,10 @@
        BigDecimal feeAmount = withdrawDto.getAmount().multiply(withdrawPercent).setScale(2, BigDecimal.ROUND_DOWN);
        updateWalletCoinWithLock(withdrawDto.getAmount(), member.getId(), 2);
        memberEntity.setUsdtBalance(usdtBalance.subtract(withdrawDto.getAmount()).setScale(2,BigDecimal.ROUND_DOWN));
        dappMemberDao.updateById(memberEntity);
        if(1 != memberEntity.getNodeType()){
            memberEntity.setUsdtBalance(usdtBalance.subtract(withdrawDto.getAmount()).setScale(2,BigDecimal.ROUND_DOWN));
            dappMemberDao.updateById(memberEntity);
        }
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(
                member.getId(),
@@ -410,6 +422,19 @@
            throw new FebsException("功能升级中");
        }
        DataDictionaryCustom startSymbolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.START_SYMBOL.getType(),
                DataDictionaryEnum.START_SYMBOL.getCode()
        );
        if("STOP".equals(startSymbolDic.getValue())){
            throw new FebsException("贡献暂未开启");
        }
        DateTime startTime = DateUtil.parseDateTime("2024-07-09 17:00:00");
        if(DateUtil.compare(DateUtil.date(), startTime) < 0){
            throw new FebsException("贡献暂未开启");
        }
        BigDecimal amount = transferDto.getAmount();
        if(BigDecimal.ZERO.compareTo(amount) >= 0){
            throw new FebsException("请输入正确的存储数量");
@@ -423,7 +448,7 @@
            throw new FebsException("存储数量必须是"+bigDecimal+"的整数倍");
        }
        DappStorage dappStorage = dappStorageMapper.selectAmountByAmountDesc(0, 1);
        DappStorage dappStorage = dappStorageMapper.selectAmountByAmountDesc(member.getId(),0, 1);
        if(ObjectUtil.isNotEmpty(dappStorage)){
            if(amount.compareTo(dappStorage.getAmount()) < 0){
                throw new FebsException("存储数量必须大于:"+dappStorage.getAmount());
@@ -677,10 +702,15 @@
                DataDictionaryEnum.BUCAHNG_CHI.getType(),
                DataDictionaryEnum.BUCAHNG_CHI.getCode()
        ).getValue());
        apiIndexInfoVo.setJiedianChi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.JIE_DIAN_CHI.getType(),
                DataDictionaryEnum.JIE_DIAN_CHI.getCode()
        ).getValue());
        List<DappStorage> dappStorages = dappStorageMapper.selectList(null);
        BigDecimal reduce = dappStorages.stream().map(DappStorage::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal bigDecimal = reduce.multiply(new BigDecimal(AppContants.DAO_NODE_PERCENT)).setScale(2, BigDecimal.ROUND_DOWN);
        apiIndexInfoVo.setJiedianChi(bigDecimal.toString());
//        apiIndexInfoVo.setJiedianChi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
//                DataDictionaryEnum.JIE_DIAN_CHI.getType(),
//                DataDictionaryEnum.JIE_DIAN_CHI.getCode()
//        ).getValue());
        apiIndexInfoVo.setJijinghuiChi(dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.JI_JING_HUI_CHI.getType(),
                DataDictionaryEnum.JI_JING_HUI_CHI.getCode()
@@ -695,7 +725,19 @@
    @Override
    public List<ApiStorageInfoVo> storageIndex() {
        List<ApiStorageInfoVo> apiStorageInfoVos = new ArrayList<>();
        List<DappStorage> dappStorages = dappStorageMapper.selectByAmountDesc(DateUtil.offsetHour(new Date(), -1), 0, 10);
        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(new Date()));
        DateTime perkTime = DateUtil.parseTime("17:00:00");
        String startTimeStr = null;
        if(DateUtil.compare(nowTime,perkTime) >= 0){
            startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 0)) + " 17:00:00";
        }else{
            startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), -1)) + " 17:00:00";
        }
        DateTime startTime = DateUtil.parseDateTime(startTimeStr);
        List<DappStorage> dappStorages = dappStorageMapper.selectSumByAmountDescFiveToFive(startTime, 0, 10);
//        List<DappStorage> dappStorages = dappStorageMapper.selectSumByAmountDesc(DateUtil.offsetHour(new Date(), -1), 0, 10);
        if(CollUtil.isNotEmpty(dappStorages)){
            for(DappStorage dappStorage : dappStorages){
                ApiStorageInfoVo apiStorageInfoVo = new ApiStorageInfoVo();
@@ -761,6 +803,77 @@
        return apiStorageInfoVos;
    }
    @Override
    public List<ApiDirectInfoVo> directNumIndex() {
        List<ApiDirectInfoVo> apiDirectInfoVos = new ArrayList<>();
        /**
         * 存放直推人数<上级的memberId,直推人数>
         */
        HashMap<Long, BigDecimal> map = new HashMap<>();
        DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(new Date()));
        DateTime perkTime = DateUtil.parseTime("17:00:00");
        String startTimeStr = null;
        if(DateUtil.compare(nowTime,perkTime) >= 0){
            startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 0)) + " 17:00:00";
        }else{
            startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), -1)) + " 17:00:00";
        }
        DateTime startTime = DateUtil.parseDateTime(startTimeStr);
//        List<DappMemberEntity> dappMemberEntityList = dappMemberDao.selectListByDateFiveToFiver(startTime);
        List<DappStorage> dappStorages = dappStorageMapper.selectListByDateFiveToFiver(startTime);
        Set<Long> collect = dappStorages.stream().map(DappStorage::getMemberId).collect(Collectors.toSet());
//        List<DappMemberEntity> dappMemberEntityList = dappMemberDao.selectListByDate(new Date());
        if(CollUtil.isNotEmpty(collect)){
            for(Long memberId : collect){
                DappMemberEntity member = dappMemberDao.selectById(memberId);
                if(StrUtil.isEmpty(member.getRefererId())){
                    continue;
                }
                if(2 == member.getActiveStatus()){
                    continue;
                }
                DappMemberEntity memberRef = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId());
                if(ObjectUtil.isEmpty(memberRef)){
                    continue;
                }
                Long id = memberRef.getId();
                if(map.containsKey(id)){
                    BigDecimal bigDecimal = map.get(id);
                    BigDecimal add = bigDecimal.add(new BigDecimal("1"));
                    map.put(id,add);
                }else{
                    map.put(id,new BigDecimal("1"));
                }
            }
        }
        /**
         * 获取这个map的直推人数前十,分发奖励
         */
        if(!map.isEmpty()){
            // 使用Stream API按照BigDecimal从大到小排序
            List<Map.Entry<Long, BigDecimal>> topTenEntries = map.entrySet().stream()
                    .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
                    .limit(10)
                    .collect(Collectors.toList());
            for (Map.Entry<Long, BigDecimal> entry : topTenEntries) {
                Long memberId = entry.getKey();
                BigDecimal directCnt = entry.getValue();
                ApiDirectInfoVo apiDirectInfoVo = new ApiDirectInfoVo();
                apiDirectInfoVo.setAddress(dappMemberDao.selectById(memberId).getAddress());
                apiDirectInfoVo.setAmount(directCnt);
                apiDirectInfoVos.add(apiDirectInfoVo);
            }
        }
        return apiDirectInfoVos;
    }
    public MemberNodeVo buildTeamMatrix(DbMemberNode dbMemberNode) {
        Long id = dbMemberNode.getId();