| | |
| | | package cc.mrbird.febs; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.dto.BatchTransferDto; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum; |
| | | import cc.mrbird.febs.dapp.enumerate.MemberLevelEnum; |
| | | import cc.mrbird.febs.dapp.enumerate.MoneyFlowEnum; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | 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; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | // @Resource |
| | | // private DappSystemService dappSystemService; |
| | | // |
| | | // @Resource |
| | | // private DappStorageMapper dappStorageMapper; |
| | | @Resource |
| | | private DappStorageMapper dappStorageMapper; |
| | | // |
| | | // @Resource |
| | | // private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | @Resource |
| | | private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | // |
| | | // @Resource |
| | | // private DappMemberDao dappMemberDao; |
| | | @Resource |
| | | private DappMemberDao dappMemberDao; |
| | | @Resource |
| | | private DappFundFlowDao dappFundFlowDao; |
| | | @Resource |
| | | private DappWalletCoinDao dappWalletCoinDao; |
| | | |
| | | |
| | | @Test |
| | | public void profitDailyJobOne() { |
| | | |
| | | Date date = new Date(); |
| | | DappStorage dappStorageLast = dappStorageMapper.selectOneByCreateTimeDesc(0, 1); |
| | | DateTime dateTime1 = DateUtil.offsetHour(dappStorageLast.getCreateTime(), 24); |
| | | int compare = DateUtil.compare(dateTime1, date); |
| | | if(compare > 0){ |
| | | System.out.println("时间未到"); |
| | | } |
| | | } |
| | | |
| | | @Test |
| | | public void returnDate() {//注册 |
| | | |
| | | QueryWrapper<DappFundFlowEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("type", MoneyFlowEnum.BU_CHANG_PERK.getValue()); |
| | | List<DappFundFlowEntity> dappFundFlowEntities = dappFundFlowDao.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(dappFundFlowEntities)){ |
| | | for(DappFundFlowEntity dappFundFlowEntity : dappFundFlowEntities){ |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | |
| | | DappWalletCoinEntity dappWalletCoinEntity = dappWalletCoinDao.selectByMemberId(memberId); |
| | | BigDecimal availableAmount = dappWalletCoinEntity.getAvailableAmount(); |
| | | BigDecimal totalAmount = dappWalletCoinEntity.getTotalAmount(); |
| | | if(dappWalletCoinEntity.getAvailableAmount().compareTo(amount) >= 0){ |
| | | dappWalletCoinEntity.setAvailableAmount(availableAmount.subtract(amount)); |
| | | dappWalletCoinEntity.setTotalAmount(totalAmount.subtract(amount)); |
| | | dappWalletCoinDao.updateWithLock(dappWalletCoinEntity); |
| | | } |
| | | dappFundFlowDao.deleteById(dappFundFlowEntity); |
| | | } |
| | | } |
| | | |
| | | 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_BU_CHANG_PERCENT)).setScale(2, BigDecimal.ROUND_DOWN); |
| | | dataDictionaryCustomMapper.updateDicValueByTypeAndCode( |
| | | DataDictionaryEnum.BUCAHNG_CHI.getType(), |
| | | DataDictionaryEnum.BUCAHNG_CHI.getCode(),bigDecimal.toString() |
| | | ); |
| | | |
| | | } |
| | | |
| | | @Test |
| | | public void withdraw() {//注册 |
| | | |
| | | ArrayList<BatchTransferDto> objects = new ArrayList<>(); |
| | | BatchTransferDto batchTransferDto = new BatchTransferDto("0x4b1e48d0c2fb8a80afa2ac1f8028fd25004d59b1",new BigDecimal("282.6")); |
| | | objects.add(batchTransferDto); |
| | | |
| | | BatchTransferDto batchTransferDtoFee1 = new BatchTransferDto("0xe457e3e1413750c7810681ca5e080951b819d91c",new BigDecimal("423")); |
| | | objects.add(batchTransferDtoFee1); |
| | | |
| | | BatchTransferDto batchTransferDtoFee2 = new BatchTransferDto("0x96d21a1aadf6156be9a79c5b18aaf9373cdbc8c2",new BigDecimal("295")); |
| | | objects.add(batchTransferDtoFee2); |
| | | |
| | | BatchTransferDto batchTransferDtoFee3 = new BatchTransferDto("0x86bdeb5d597aeffedc80f6b63c410c71da606b8a",new BigDecimal("149")); |
| | | objects.add(batchTransferDtoFee3); |
| | | ChainService.getInstance(ChainEnum.BSC_USDT.name()).transferList(objects); |
| | | } |
| | | // |
| | | @Test |
| | | public void register() {//注册 |
| | | ArrayList<BatchTransferDto> objects = new ArrayList<>(); |
| | | BatchTransferDto batchTransferDto = new BatchTransferDto("0x3caf594503573341ae7a83fc6daed9bd5276b6bd",new BigDecimal("1")); |
| | | objects.add(batchTransferDto); |
| | | List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectList(null); |
| | | for(DappMemberEntity memberEntityNow : dappMemberEntities){ |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberEntityNow.getId()); |
| | | if(StrUtil.isEmpty(dappMemberEntity.getRefererIds())){ |
| | | continue; |
| | | } |
| | | //获取全部上级 |
| | | ArrayList<DappMemberEntity> activeMembers = new ArrayList<>(); |
| | | List<String> refererIds = Arrays.asList(StrUtil.split(dappMemberEntity.getRefererIds(),",")); |
| | | for(String inviteId : refererIds){ |
| | | DappMemberEntity memberEntity = dappMemberDao.selectMemberInfoByInviteId(inviteId); |
| | | if(ObjectUtil.isNotEmpty(memberEntity)){ |
| | | activeMembers.add(memberEntity); |
| | | } |
| | | } |
| | | if(CollUtil.isEmpty(activeMembers)){ |
| | | continue; |
| | | } |
| | | |
| | | BatchTransferDto batchTransferDtoFee = new BatchTransferDto("0x3caf594503573341ae7a83fc6daed9bd5276b6bd",new BigDecimal("1")); |
| | | objects.add(batchTransferDtoFee); |
| | | ChainService.getInstance(ChainEnum.BSC_USDT.name()).transferList(objects); |
| | | for(DappMemberEntity activeMember : activeMembers){ |
| | | //获取每一个上级的所有直推,分辨大小区是否满足业绩需求 |
| | | List<DappMemberEntity> directMembers = dappMemberDao.selectChildMemberDirectOrNot(activeMember.getInviteId(), 1, null); |
| | | if(CollUtil.isEmpty(directMembers)){ |
| | | continue; |
| | | } |
| | | if(directMembers.size() < 2){ |
| | | continue; |
| | | } |
| | | //获取activeMember的每一个直推的团队有效业绩 |
| | | HashMap<Long, BigDecimal> daXiaoQu = new HashMap<>(); |
| | | for(DappMemberEntity directMember : directMembers){ |
| | | //每一个直推的团队 |
| | | List<DappMemberEntity> direct = dappMemberDao.selectChildMemberDirectOrNot(directMember.getInviteId(), 2, null); |
| | | direct.add(directMember); |
| | | if(CollUtil.isEmpty(direct)){ |
| | | continue; |
| | | } |
| | | //获取直推的团队的全部有效业绩 |
| | | List<Long> collect = direct.stream().map(DappMemberEntity::getId).collect(Collectors.toList()); |
| | | QueryWrapper<DappStorage> storageQueryWrapper = new QueryWrapper<>(); |
| | | storageQueryWrapper.in("member_id",collect); |
| | | // storageQueryWrapper.eq("state",1); |
| | | List<DappStorage> dappStorages = dappStorageMapper.selectList(storageQueryWrapper); |
| | | if(CollUtil.isEmpty(dappStorages)){ |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal directAchieve = dappStorages.stream() |
| | | .map(DappStorage::getAmount) // 映射amount到流中 |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | daXiaoQu.put(directMember.getId(),directAchieve); |
| | | } |
| | | if(daXiaoQu.isEmpty()){ |
| | | continue; |
| | | } |
| | | //输出小区的总业绩 |
| | | BigDecimal sum = sumExcludingMax(daXiaoQu); |
| | | BigDecimal dao_1_levelAchieve = new BigDecimal(MemberLevelEnum.DAO_1.getLevelAchieve()); |
| | | BigDecimal dao_2_levelAchieve = new BigDecimal(MemberLevelEnum.DAO_2.getLevelAchieve()); |
| | | BigDecimal dao_3_levelAchieve = new BigDecimal(MemberLevelEnum.DAO_3.getLevelAchieve()); |
| | | if(sum.compareTo(dao_3_levelAchieve) >= 0){ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_3.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | }else if(sum.compareTo(dao_2_levelAchieve) >= 0 && sum.compareTo(dao_3_levelAchieve) < 0){ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_2.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | }else if(sum.compareTo(dao_1_levelAchieve) >= 0 && sum.compareTo(dao_2_levelAchieve) < 0){ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_1.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | }else{ |
| | | activeMember.setLevel(MemberLevelEnum.DAO_0.getCode()); |
| | | dappMemberDao.updateById(activeMember); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static BigDecimal sumExcludingMax(HashMap<Long, BigDecimal> map) { |
| | | if (map == null) { |
| | | throw new NullPointerException("HashMap cannot be null"); |
| | | } |
| | | |
| | | // 使用Stream API找到最大的BigDecimal值及其对应的key |
| | | Optional<Map.Entry<Long, BigDecimal>> maxEntry = map.entrySet().stream() |
| | | .max((e1, e2) -> e1.getValue().compareTo(e2.getValue())); |
| | | |
| | | // 检查是否找到了最大值 |
| | | if (maxEntry.isPresent()) { |
| | | // 移除最大值对应的键值对 |
| | | map.remove(maxEntry.get().getKey()); |
| | | |
| | | // 计算剩余数据的累计和 |
| | | BigDecimal sumOfRemaining = map.entrySet().stream() |
| | | .map(Map.Entry::getValue) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 返回累计和 |
| | | return sumOfRemaining; |
| | | } else { |
| | | // 如果没有找到最大值(即HashMap为空),则返回BigDecimal.ZERO |
| | | return BigDecimal.ZERO; |
| | | } |
| | | } |
| | | // |
| | | // @Test |