| | |
| | | package cc.mrbird.febs.job; |
| | | |
| | | |
| | | import cc.mrbird.febs.dapp.entity.DappFundFlowEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DataDictionaryCustom; |
| | | import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberDao; |
| | | import cc.mrbird.febs.dapp.mapper.DataDictionaryCustomMapper; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | | import cc.mrbird.febs.tree.TreeConstants; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | 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 java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "system", name = "quartz-job", havingValue = "true") |
| | | public class ProfitDailyJob { |
| | | |
| | | @Autowired |
| | | private DappMemberDao dappMemberDao; |
| | | @Autowired |
| | | private DappFundFlowDao dappFundFlowDao; |
| | | @Autowired |
| | | private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | @Autowired |
| | | private DappWalletService dappWalletService; |
| | | |
| | | @Scheduled(cron = "0 0 0 * * ?") |
| | | public void profitDailyJob() { |
| | | log.info("每日产矿任务执行"); |
| | | DataDictionaryCustom symbolPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYMBOL_PRICE.getType(), DataDictionaryEnum.SYMBOL_PRICE.getCode()); |
| | | if (symbolPriceDic == null) { |
| | | log.info("未设置币种价格"); |
| | | return; |
| | | } |
| | | |
| | | DataDictionaryCustom rebateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.REBATE_PERCENT.getType(), DataDictionaryEnum.REBATE_PERCENT.getCode()); |
| | | if (rebateDic == null) { |
| | | log.info("未设置每日产矿比例"); |
| | | return; |
| | | } |
| | | |
| | | BigDecimal symbolPrice = new BigDecimal(symbolPriceDic.getValue()); |
| | | BigDecimal rebateRatio = new BigDecimal(rebateDic.getValue()); |
| | | |
| | | QueryWrapper<DappMemberEntity> query = new QueryWrapper<>(); |
| | | query.eq("active_status", 1); |
| | | List<DappMemberEntity> members = dappMemberDao.selectList(query); |
| | | if (CollUtil.isEmpty(members)) { |
| | | return; |
| | | } |
| | | |
| | | members.forEach(item -> { |
| | | QueryWrapper<DappFundFlowEntity> fundFlowQuery = new QueryWrapper<>(); |
| | | fundFlowQuery.eq("member_id", item.getId()); |
| | | fundFlowQuery.eq("type", 11); |
| | | List<DappFundFlowEntity> flows = dappFundFlowDao.selectList(fundFlowQuery); |
| | | |
| | | BigDecimal sum = BigDecimal.ZERO; |
| | | if (CollUtil.isNotEmpty(flows)) { |
| | | double symbolSum = flows.stream().mapToDouble(flow -> flow.getAmount().doubleValue()).sum(); |
| | | sum = symbolPrice.multiply(new BigDecimal(symbolSum)); |
| | | } |
| | | |
| | | if (CollUtil.isEmpty(flows) || TreeConstants.PUT_IN_AMOUNT.compareTo(sum) > 0) { |
| | | BigDecimal profitU = TreeConstants.PUT_IN_AMOUNT.multiply(rebateRatio.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_DOWN)); |
| | | |
| | | BigDecimal remain = TreeConstants.PUT_IN_AMOUNT.subtract(sum); |
| | | if (remain.compareTo(profitU) < 0) { |
| | | profitU = remain; |
| | | } |
| | | |
| | | BigDecimal profitSymbol = profitU.divide(symbolPrice, 2, RoundingMode.HALF_DOWN); |
| | | |
| | | dappWalletService.updateWalletMineWithLock(profitSymbol, item.getId(), 1); |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(item.getId(), profitSymbol, 11, 2, null, null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | // @Autowired |
| | | // private DappMemberDao dappMemberDao; |
| | | // @Autowired |
| | | // private DappFundFlowDao dappFundFlowDao; |
| | | // @Autowired |
| | | // private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | // @Autowired |
| | | // private DappWalletService dappWalletService; |
| | | // |
| | | // @Scheduled(cron = "0 0 0 * * ?") |
| | | // public void profitDailyJob() { |
| | | // log.info("每日产矿任务执行"); |
| | | // DataDictionaryCustom symbolPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYMBOL_PRICE.getType(), DataDictionaryEnum.SYMBOL_PRICE.getCode()); |
| | | // if (symbolPriceDic == null) { |
| | | // log.info("未设置币种价格"); |
| | | // return; |
| | | // } |
| | | // |
| | | // DataDictionaryCustom rebateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.REBATE_PERCENT.getType(), DataDictionaryEnum.REBATE_PERCENT.getCode()); |
| | | // if (rebateDic == null) { |
| | | // log.info("未设置每日产矿比例"); |
| | | // return; |
| | | // } |
| | | // |
| | | // BigDecimal symbolPrice = new BigDecimal(symbolPriceDic.getValue()); |
| | | // BigDecimal rebateRatio = new BigDecimal(rebateDic.getValue()); |
| | | // |
| | | // QueryWrapper<DappMemberEntity> query = new QueryWrapper<>(); |
| | | // query.eq("active_status", 1); |
| | | // List<DappMemberEntity> members = dappMemberDao.selectList(query); |
| | | // if (CollUtil.isEmpty(members)) { |
| | | // return; |
| | | // } |
| | | // |
| | | // members.forEach(item -> { |
| | | // QueryWrapper<DappFundFlowEntity> fundFlowQuery = new QueryWrapper<>(); |
| | | // fundFlowQuery.eq("member_id", item.getId()); |
| | | // fundFlowQuery.eq("type", 11); |
| | | // List<DappFundFlowEntity> flows = dappFundFlowDao.selectList(fundFlowQuery); |
| | | // |
| | | // BigDecimal sum = BigDecimal.ZERO; |
| | | // if (CollUtil.isNotEmpty(flows)) { |
| | | // double symbolSum = flows.stream().mapToDouble(flow -> flow.getAmount().doubleValue()).sum(); |
| | | // sum = symbolPrice.multiply(new BigDecimal(symbolSum)); |
| | | // } |
| | | // |
| | | // if (CollUtil.isEmpty(flows) || TreeConstants.PUT_IN_AMOUNT.compareTo(sum) > 0) { |
| | | // BigDecimal profitU = TreeConstants.PUT_IN_AMOUNT.multiply(rebateRatio.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_DOWN)); |
| | | // |
| | | // BigDecimal remain = TreeConstants.PUT_IN_AMOUNT.subtract(sum); |
| | | // if (remain.compareTo(profitU) < 0) { |
| | | // profitU = remain; |
| | | // } |
| | | // |
| | | // BigDecimal profitSymbol = profitU.divide(symbolPrice, 8, RoundingMode.HALF_DOWN); |
| | | // |
| | | // dappWalletService.updateWalletMineWithLock(profitSymbol, item.getId(), 1); |
| | | // DappFundFlowEntity fundFlow = new DappFundFlowEntity(item.getId(), profitSymbol, 11, 2, null, null); |
| | | // dappFundFlowDao.insert(fundFlow); |
| | | // } |
| | | // }); |
| | | // |
| | | // |
| | | // } |
| | | } |