| | |
| | | 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; |
| | | import cc.mrbird.febs.common.utils.FebsUtil; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.ShareCodeUtil; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.chain.ContractChainService; |
| | | import cc.mrbird.febs.dapp.dto.ApproveDto; |
| | |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cc.mrbird.febs.dapp.vo.MoneyFlowVo; |
| | | import cc.mrbird.febs.dapp.vo.TeamListVo; |
| | | import cc.mrbird.febs.system.entity.User; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author |
| | |
| | | private final DappTransferRecordDao dappTransferRecordDao; |
| | | private final RedisUtils redisUtils; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final DappAchieveMapper dappAchieveMapper; |
| | | private final DappFundFlowDao dappFundFlowDao; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | @Override |
| | | public void connect(ConnectDto connectDto) { |
| | | DappMemberEntity member = dappMemberDao.selectByAddress(connectDto.getAddress(), null); |
| | | |
| | | if (member == null) { |
| | | if (ObjectUtil.isEmpty(member)) { |
| | | DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(connectDto.getInviteId()); |
| | | if (parent == null) { |
| | | throw new FebsException("邀请人不存在"); |
| | | if (ObjectUtil.isEmpty(parent)) { |
| | | throw new FebsException("邀请码不存在"); |
| | | } |
| | | |
| | | member = insertMember(connectDto.getAddress(), connectDto.getInviteId()); |
| | | } |
| | | |
| | | // if (member.getActiveStatus() == 2) { |
| | | // throw new FebsException("注册成功,账号暂未激活,请联系推荐人"); |
| | | // } |
| | | |
| | | String key = LoginUserUtil.getLoginKey(connectDto.getAddress(), connectDto.getNonce(), connectDto.getSign()); |
| | | redisUtils.set(connectDto.getAddress(), member); |
| | |
| | | if (currentUser.getDeptId() == null) { |
| | | member.setCurrentUser(currentUser.getUserId()); |
| | | } |
| | | return dappMemberDao.selectInPage(member, page); |
| | | IPage<DappMemberEntity> dappMemberEntityIPage = dappMemberDao.selectInPage(member, page); |
| | | List<DappMemberEntity> records = dappMemberEntityIPage.getRecords(); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(DappMemberEntity dappMemberEntity : records){ |
| | | QueryWrapper<DappAchieve> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("member_id",dappMemberEntity.getId()); |
| | | List<DappAchieve> dappAchieves = dappAchieveMapper.selectList(objectQueryWrapper); |
| | | |
| | | BigDecimal reduce = dappAchieves.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | dappMemberEntity.setZhiYaAmount(reduce); |
| | | } |
| | | } |
| | | return dappMemberEntityIPage; |
| | | } |
| | | |
| | | @Override |
| | |
| | | member.setAddress(address); |
| | | member.setChainType(chainType); |
| | | member.setAccountType(accountType); |
| | | // 如果有推荐人,则需要推荐人转币后激活 |
| | | member.setActiveStatus(2); |
| | | member.setBalance(ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(address)); |
| | | member.setUsdtBalance(ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(address)); |
| | | member.setActiveStatus(1); |
| | | member.setBalance(BigDecimal.ZERO); |
| | | member.setUsdtBalance(BigDecimal.ZERO); |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_SYSTEM_NODE_CNT_LIMIT); |
| | | int nodeCntLimit = Integer.parseInt(dic.getValue()); |
| | | |
| | | List<DappMemberEntity> memberCount = dappMemberDao.selectList(null); |
| | | if (memberCount.size() <= (nodeCntLimit + 4)) { |
| | | member.setNodeType(1); |
| | | } else { |
| | | member.setNodeType(2); |
| | | } |
| | | // DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_SYSTEM_NODE_CNT_LIMIT); |
| | | // int nodeCntLimit = Integer.parseInt(dic.getValue()); |
| | | // |
| | | // List<DappMemberEntity> memberCount = dappMemberDao.selectList(null); |
| | | // if (memberCount.size() <= (nodeCntLimit + 4)) { |
| | | // member.setNodeType(1); |
| | | // } else { |
| | | // member.setNodeType(2); |
| | | // } |
| | | |
| | | dappMemberDao.insert(member); |
| | | |
| | |
| | | return member; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String inputString = |
| | | "36707681,36605256,36506391,36402334," + |
| | | "36303396,36103193,35801871,34603197," + |
| | | "33502855,26309863,99073916,98024982," + |
| | | "97059583,95058331,92037722,91048635," + |
| | | "89019478,88021442,84073227,20441682"; |
| | | String target = "89019478"; |
| | | |
| | | // 调用函数进行匹配并输出结果 |
| | | if (findAndOutputIfMatchBeforeEighthPosition(inputString, target)) { |
| | | System.out.println(inputString); |
| | | } else { |
| | | System.out.println("No match found within the last 8 substrings."); |
| | | } |
| | | } |
| | | /** |
| | | * 检查给定的字符串中是否包含目标子串,并且该子串出现的位置是否小于8(从字符串开始到匹配子串的起始位置)。 |
| | | * 如果满足条件,则返回原始字符串;否则返回null。 |
| | | * |
| | | * @param inputString 给定的字符串 |
| | | * @param target 需要匹配的目标子串 |
| | | * @return 匹配的字符串(如果满足条件),否则为null |
| | | */ |
| | | public static boolean findAndOutputIfMatchBeforeEighthPosition(String inputString, String target) { |
| | | // 使用逗号分割字符串 |
| | | String[] substrings = inputString.split(","); |
| | | |
| | | // 遍历分割后的子串 |
| | | for (String substring : substrings) { |
| | | |
| | | System.out.println(substring); |
| | | // 检查是否包含目标子串 |
| | | if (substring.contains(target)) { |
| | | // 计算目标子串在子串中的起始位置(注意:这里不是索引位置) |
| | | int position = substring.indexOf(target); |
| | | // 如果起始位置小于8(即前8个字符内),则输出原始字符串 |
| | | if (position < 8) { |
| | | return true; // 输出整个原始字符串 |
| | | } |
| | | break; // 匹配但位置不在要求范围内,退出循环 |
| | | } |
| | | } |
| | | |
| | | // 如果没有找到匹配的子串或位置不满足条件,则返回null |
| | | return false; // 没有找到匹配项或匹配项位置不符合要求 |
| | | } |
| | | |
| | | /** |
| | | * 检查输入字符串从后往前匹配目标字符串的位置是否小于8(基于逗号分隔的子串数量) |
| | | * |
| | | * @param inputString 输入的字符串 |
| | | * @param target 目标字符串 |
| | | * @return 如果匹配的位置小于8,则返回true;否则返回false |
| | | */ |
| | | public static boolean shouldOutputString(String inputString, String target) { |
| | | // 按逗号分隔字符串 |
| | | String[] substrings = inputString.split(","); |
| | | |
| | | // 从后往前遍历子串数组 |
| | | for (int i = substrings.length - 1; i >= 0; i--) { |
| | | // 去掉子串两侧的空白字符(如果有的话) |
| | | String trimmedSubstring = substrings[i].trim(); |
| | | System.out.println(trimmedSubstring); |
| | | |
| | | // 检查子串是否与目标字符串匹配 |
| | | if (trimmedSubstring.equals(target)) { |
| | | // 如果匹配且位置小于8(基于0索引,所以实际上是倒数第9个或更前的位置) |
| | | if (substrings.length - i < 8) { |
| | | return true; // 输出整个原始字符串 |
| | | } |
| | | break; // 匹配但位置不在要求范围内,退出循环 |
| | | } |
| | | } |
| | | |
| | | return false; // 没有找到匹配项或匹配项位置不符合要求 |
| | | } |
| | | |
| | | @Override |
| | | public List<TeamListVo> findTeamList(TeamListDto teamListDto) { |
| | | public TeamListVo findTeamList() { |
| | | TeamListVo teamListVo = new TeamListVo(); |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | Page<TeamListDto> page = new Page<>(teamListDto.getPageNum(), teamListDto.getPageSize()); |
| | | teamListDto.setInviteId(member.getInviteId()); |
| | | return dappMemberDao.selectTeamListInPage(teamListDto, page).getRecords(); |
| | | List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectChildMemberDirectOrNot(member.getInviteId(), 2); |
| | | teamListVo.setTeamCount(CollUtil.isEmpty(dappMemberEntities) ? 0 : dappMemberEntities.size()); |
| | | if(CollUtil.isNotEmpty(dappMemberEntities)){ |
| | | List<Long> collect = dappMemberEntities.stream().map(DappMemberEntity::getId).collect(Collectors.toList()); |
| | | QueryWrapper<DappAchieve> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.in("member_id",collect); |
| | | List<DappAchieve> dappAchieveSumList = dappAchieveMapper.selectList(queryWrapper); |
| | | |
| | | List<DappAchieve> filteredList = dappAchieveSumList.stream() |
| | | .filter(obj -> obj.getState() == 1) |
| | | .collect(Collectors.toList()); |
| | | Set<Long> collect1 = filteredList.stream().map(DappAchieve::getMemberId).collect(Collectors.toSet()); |
| | | teamListVo.setAvaCount(CollUtil.isEmpty(collect1) ? 0 : collect1.size()); |
| | | BigDecimal avaAmount = filteredList.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | teamListVo.setAvaAmount(avaAmount); |
| | | }else{ |
| | | teamListVo.setAvaCount(0); |
| | | teamListVo.setAvaAmount(BigDecimal.ZERO); |
| | | } |
| | | |
| | | // ArrayList<DappMemberEntity> objects = new ArrayList<>(); |
| | | // //八层团队业绩 |
| | | // if(CollUtil.isNotEmpty(dappMemberEntities)){ |
| | | // for(DappMemberEntity memberEntity : dappMemberEntities){ |
| | | // String refererIds = memberEntity.getRefererIds(); |
| | | // if (shouldOutputString(refererIds, member.getInviteId())) { |
| | | // objects.add(memberEntity); |
| | | // } |
| | | // } |
| | | // List<Long> collect = objects.stream().map(DappMemberEntity::getId).collect(Collectors.toList()); |
| | | // QueryWrapper<DappAchieve> queryWrapper = new QueryWrapper<>(); |
| | | // queryWrapper.in("member_id",collect); |
| | | // List<DappAchieve> dappAchieveSumList = dappAchieveMapper.selectList(queryWrapper); |
| | | // |
| | | // List<DappAchieve> filteredList = dappAchieveSumList.stream() |
| | | // .filter(obj -> obj.getState() == 1) |
| | | // .collect(Collectors.toList()); |
| | | // BigDecimal perkAmount = filteredList.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // teamListVo.setPerkAmount(perkAmount); |
| | | // |
| | | // }else{ |
| | | // teamListVo.setPerkAmount(BigDecimal.ZERO); |
| | | // } |
| | | |
| | | |
| | | List<DappMemberEntity> dappMemberEntitiesAva = dappMemberDao.selectChildMemberDirectOrNot(member.getInviteId(), 1); |
| | | if(CollUtil.isNotEmpty(dappMemberEntitiesAva)){ |
| | | List<Long> collect = dappMemberEntitiesAva.stream().map(DappMemberEntity::getId).collect(Collectors.toList()); |
| | | QueryWrapper<DappAchieve> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.in("member_id",collect); |
| | | List<DappAchieve> dappAchieveSumList = dappAchieveMapper.selectList(queryWrapper); |
| | | if(CollUtil.isNotEmpty(dappAchieveSumList)){ |
| | | BigDecimal teamAchieveMemberSum = dappAchieveSumList.stream().map(item-> item.getAmount().multiply(item.getPrice())).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | teamListVo.setTeamAmount(teamAchieveMemberSum); |
| | | }else{ |
| | | teamListVo.setTeamAmount(BigDecimal.ZERO); |
| | | } |
| | | }else{ |
| | | teamListVo.setTeamAmount(BigDecimal.ZERO); |
| | | } |
| | | |
| | | |
| | | teamListVo.setBalance(member.getBalance().setScale(2,BigDecimal.ROUND_DOWN)); |
| | | teamListVo.setUsdtBalance(member.getUsdtBalance().setScale(2,BigDecimal.ROUND_DOWN)); |
| | | |
| | | return teamListVo; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<MoneyFlowVo> findMoneyFlowVos(TeamListDto teamListDto) { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | teamListDto.setMemberId(member.getId()); |
| | | |
| | | Page<MoneyFlowVo> page = new Page<>(teamListDto.getPageNum(), teamListDto.getPageSize()); |
| | | return dappFundFlowDao.findMoneyFlowVos(page, teamListDto); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse exist(String address) { |
| | | DappMemberEntity member = dappMemberDao.selectByAddress(address, null); |
| | | if(ObjectUtil.isEmpty(member)){ |
| | | return new FebsResponse().success().data(0); |
| | | } |
| | | return new FebsResponse().success().data(1); |
| | | |
| | | } |
| | | } |