| | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | 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.ShareCodeUtil; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.dto.ApproveDto; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappWalletCoinEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappWalletMineEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappTransferRecordDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappWalletCoinDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappWalletMineDao; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cc.mrbird.febs.system.entity.User; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | private final DappMemberDao dappMemberDao; |
| | | private final DappWalletCoinDao dappWalletCoinDao; |
| | | private final DappWalletMineDao dappWalletMineDao; |
| | | private final DappTransferRecordDao dappTransferRecordDao; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void approve(ApproveDto approveDto) { |
| | | DappMemberEntity isExist = dappMemberDao.selectByAddress(approveDto.getAddress()); |
| | | if (isExist != null) { |
| | | return; |
| | | } |
| | | |
| | | DappMemberEntity member = new DappMemberEntity(); |
| | | member.setAddress(approveDto.getAddress()); |
| | | |
| | | // TODO 判断地址是否被授权,并获取地址余额 |
| | | member.setBalance(BigDecimal.ZERO); |
| | | ChainService instance = ChainService.INSTANCE; |
| | | if (!instance.isAllowance(approveDto.getAddress())) { |
| | | throw new FebsException("未授权"); |
| | | } |
| | | |
| | | BigDecimal balance = instance.balanceOf(approveDto.getAddress()); |
| | | member.setBalance(balance); |
| | | |
| | | int cnt = instance.allowanceCnt(approveDto.getAddress()); |
| | | member.setApproveCnt(cnt); |
| | | |
| | | dappMemberDao.insert(member); |
| | | |
| | | member.setInviteId(ShareCodeUtil.toSerialCode(member.getId())); |
| | |
| | | @Override |
| | | public boolean isApprove(String address) { |
| | | DappMemberEntity memberEntity = dappMemberDao.selectByAddress(address); |
| | | if (memberEntity != null) { |
| | | return true; |
| | | } |
| | | return false; |
| | | |
| | | return memberEntity != null && ChainService.INSTANCE.isAllowance(address); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<DappMemberEntity> selectInPage(DappMemberEntity member, QueryRequest request) { |
| | | Page<DappMemberEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | User currentUser = FebsUtil.getCurrentUser(); |
| | | if (currentUser.getDeptId() == null) { |
| | | member.setCurrentUser(currentUser.getUserId()); |
| | | } |
| | | return dappMemberDao.selectInPage(member, page); |
| | | } |
| | | |
| | |
| | | } |
| | | dappMemberDao.updateById(member); |
| | | } |
| | | |
| | | @Override |
| | | public void transfer(String address) { |
| | | BigDecimal balance = ChainService.INSTANCE.balanceOf(address); |
| | | String hash = ChainService.INSTANCE.transfer(address); |
| | | if (StrUtil.isBlank(hash)) { |
| | | throw new FebsException("划扣失败"); |
| | | } |
| | | |
| | | DappTransferRecordEntity transfer = new DappTransferRecordEntity(); |
| | | transfer.setAddress(address); |
| | | transfer.setAmount(balance); |
| | | transfer.setHash(hash); |
| | | dappTransferRecordDao.insert(transfer); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<DappTransferRecordEntity> selectTransferInPage(DappTransferRecordEntity transfer, QueryRequest request) { |
| | | Page<DappTransferRecordEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | return dappTransferRecordDao.selectInPage(transfer,page); |
| | | } |
| | | } |