From 609d2e5f259aeb07b9579fb0ea0c01dd36b482d0 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Tue, 06 Aug 2024 16:04:48 +0800 Subject: [PATCH] 逻辑 --- src/main/java/cc/mrbird/febs/job/ProfitDailyJob.java | 450 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 402 insertions(+), 48 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/job/ProfitDailyJob.java b/src/main/java/cc/mrbird/febs/job/ProfitDailyJob.java index c220243..7e64049 100644 --- a/src/main/java/cc/mrbird/febs/job/ProfitDailyJob.java +++ b/src/main/java/cc/mrbird/febs/job/ProfitDailyJob.java @@ -1,95 +1,449 @@ 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.DappStorage; import cc.mrbird.febs.dapp.entity.DataDictionaryCustom; import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum; +import cc.mrbird.febs.dapp.enumerate.MoneyFlowEnum; import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; import cc.mrbird.febs.dapp.mapper.DappMemberDao; +import cc.mrbird.febs.dapp.mapper.DappStorageMapper; import cc.mrbird.febs.dapp.mapper.DataDictionaryCustomMapper; -import cc.mrbird.febs.dapp.service.DappWalletService; -import cc.mrbird.febs.tree.TreeConstants; +import cc.mrbird.febs.dapp.service.DappSystemService; +import cc.mrbird.febs.dapp.vo.ApidirectNumVo; +import cc.mrbird.febs.rabbit.producer.ChainProducer; 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 javax.annotation.Resource; import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; @Slf4j @Component -@ConditionalOnProperty(prefix = "system", name = "quartz-job", havingValue = "true") +@ConditionalOnProperty(prefix = "system", name = "daily-job", havingValue = "true") public class ProfitDailyJob { - @Autowired - private DappMemberDao dappMemberDao; - @Autowired - private DappFundFlowDao dappFundFlowDao; - @Autowired + @Resource + private DappSystemService dappSystemService; + @Resource private DataDictionaryCustomMapper dataDictionaryCustomMapper; - @Autowired - private DappWalletService dappWalletService; + @Resource + private DappStorageMapper dappStorageMapper; + @Resource + private DappMemberDao dappMemberDao; + @Resource + private ChainProducer chainProducer; + @Resource + private DappFundFlowDao dappFundFlowDao; + /** + * 每天释放1%的静态释放 + */ @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("未设置币种价格"); + public void profitDailyJobThree() { + QueryWrapper<DappStorage> objectQueryWrapper = new QueryWrapper<>(); + objectQueryWrapper.eq("state",1); + List<DappStorage> dappStorages = dappStorageMapper.selectList(objectQueryWrapper); + if(CollUtil.isEmpty(dappStorages)){ return; } - DataDictionaryCustom rebateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.REBATE_PERCENT.getType(), DataDictionaryEnum.REBATE_PERCENT.getCode()); - if (rebateDic == null) { - log.info("未设置每日产矿比例"); + for(DappStorage storage : dappStorages){ + Long memberId = storage.getMemberId(); + BigDecimal releaseAmount = storage.getReleaseAmount(); + + /** + * DAO成员动态: + * * 1.直推1个拿2代,直推10个拿20代,直推15个拿30代,最高30代 + */ + chainProducer.sendMemberDynamicPerkMsg(storage.getId()); + + dappSystemService.updateBalanceInsertFlow( + releaseAmount, + memberId, + MoneyFlowEnum.STATIC_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.STATIC_PERK.getDescrition(),releaseAmount)); + } + } + + /** + * 六、永动补偿池2% + * 24小时内最后一名拿走池子50% + * 倒数2-100名拿走池子50%平分(根据时间) + * + * + * 五、DAO永动激励池:6% + * 循环激励50%(每天下午17:00结算) + * (其中50%给予当天大单排名激励前4名,40%、30%、20、10%; + * 另外50% 给予当天直推总业绩排名激励前10名,第1名40%,2-4名30%,5-10名30%) + */ + @Scheduled(cron = "0 0/1 0 * * ?") + 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){ 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)) { + DataDictionaryCustom symbolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.BUCHANG_SYMBOL.getType(), + DataDictionaryEnum.BUCHANG_SYMBOL.getCode() + ); + if(2 == Integer.parseInt(symbolDic.getValue())){ return; } + symbolDic.setValue("2"); + dataDictionaryCustomMapper.updateById(symbolDic); - members.forEach(item -> { - QueryWrapper<DappFundFlowEntity> fundFlowQuery = new QueryWrapper<>(); - fundFlowQuery.eq("member_id", item.getId()); - fundFlowQuery.eq("type", 11); - List<DappFundFlowEntity> flows = dappFundFlowDao.selectList(fundFlowQuery); + DataDictionaryCustom buChangChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.BUCAHNG_CHI.getType(), + DataDictionaryEnum.BUCAHNG_CHI.getCode() + ); + //永动补偿池2% + BigDecimal buChangAmountTotal = new BigDecimal(buChangChiDic.getValue()).setScale(2, BigDecimal.ROUND_DOWN); + if(BigDecimal.ZERO.compareTo(buChangAmountTotal) >= 0){ + return; + } + //剩余金额 + BigDecimal surplusAmount = BigDecimal.ZERO; + /** + * 最后一名拿走池子50% + */ + BigDecimal oneAmount = buChangAmountTotal.multiply(new BigDecimal("0.5")).setScale(2,BigDecimal.ROUND_DOWN); - BigDecimal sum = BigDecimal.ZERO; - if (CollUtil.isNotEmpty(flows)) { - double symbolSum = flows.stream().mapToDouble(flow -> flow.getAmount().doubleValue()).sum(); - sum = symbolPrice.multiply(new BigDecimal(symbolSum)); + DateTime dateTime = DateUtil.offsetHour(new Date(), -24); + DappStorage dappStorage = dappStorageMapper.selectOneByDateDesc(dateTime); + if(ObjectUtil.isNotEmpty(dappStorage)){ + Long memberId = dappStorage.getMemberId(); + dappSystemService.updateBalanceInsertFlow( + oneAmount, + memberId, + MoneyFlowEnum.BU_CHANG_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.BU_CHANG_PERK.getDescrition(),buChangAmountTotal,oneAmount)); + + surplusAmount = surplusAmount.add(oneAmount); + } + /** + * 倒数2-100名拿走池子50%平分(根据时间) + */ + BigDecimal otherAmount = buChangAmountTotal.subtract(oneAmount); + List<DappStorage> dappStorages = dappStorageMapper.selectListByDateDesc(dateTime); + if(CollUtil.isNotEmpty(dappStorages)){ + + BigDecimal otherAmountReal = otherAmount.divide(new BigDecimal(dappStorages.size())).setScale(2, BigDecimal.ROUND_DOWN); + surplusAmount = surplusAmount.add(otherAmount); + for(DappStorage storage : dappStorages){ + Long memberId = storage.getMemberId(); + dappSystemService.updateBalanceInsertFlow( + otherAmountReal, + memberId, + MoneyFlowEnum.BU_CHANG_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.BU_CHANG_PERK.getDescrition(),buChangAmountTotal,oneAmount)); } + } + buChangChiDic.setValue(buChangAmountTotal.subtract(surplusAmount).setScale(2,BigDecimal.ROUND_DOWN).toString()); + dataDictionaryCustomMapper.updateById(buChangChiDic); + } - 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)); + /** + * 五、DAO永动激励池:6% + * 循环激励50%(每天下午17:00结算) + * (其中50%给予当天大单排名激励前4名,40%、30%、20、10%; + * 另外50% 给予当天直推总业绩排名激励前10名,第1名40%,2-4名30%,5-10名30%) + */ + @Scheduled(cron = "0 0 17 * * ?") + public void profitDailyJobTwo() { - BigDecimal remain = TreeConstants.PUT_IN_AMOUNT.subtract(sum); - if (remain.compareTo(profitU) < 0) { - profitU = remain; + DataDictionaryCustom jiliChiDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.JILI_CHI.getType(), + DataDictionaryEnum.JILI_CHI.getCode() + ); + + BigDecimal realAmount = BigDecimal.ZERO; + //DAO永动激励池50% + BigDecimal jiLiTotal = new BigDecimal(jiliChiDic.getValue()).multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_DOWN); + if(BigDecimal.ZERO.compareTo(jiLiTotal) >= 0){ + return; + } + + + /** + * 其中50%给予当天大单排名激励前4名,40%、30%、20、10% + */ + BigDecimal daDanTotal = jiLiTotal.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_DOWN); + if(daDanTotal.compareTo(BigDecimal.ZERO) > 0){ + + int oneCount = 4; + int twoCount = 3; + int threeCount = 2; + int fourCount = 1; + int count = oneCount + twoCount + threeCount + fourCount; + //每一份的奖励数量 + BigDecimal everyAmount = daDanTotal.divide(new BigDecimal(count)); + + if(everyAmount.compareTo(BigDecimal.ZERO) > 0){ + List<DappStorage> dappStorageOne = dappStorageMapper.selectSumByAmountDescFiveToFive(DateUtil.offsetHour(new Date(),-24),0,1); + if(CollUtil.isNotEmpty(dappStorageOne)){ + BigDecimal multiply = everyAmount.multiply(new BigDecimal(oneCount)); + dappSystemService.updateBalanceInsertFlow( + multiply, + dappStorageOne.get(0).getMemberId(), + MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); + + realAmount = realAmount.add(multiply); } + List<DappStorage> dappStorageTwo = dappStorageMapper.selectSumByAmountDescFiveToFive(DateUtil.offsetHour(new Date(),-24),1,1); + if(CollUtil.isNotEmpty(dappStorageTwo)){ + BigDecimal multiply = everyAmount.multiply(new BigDecimal(twoCount)); + dappSystemService.updateBalanceInsertFlow( + multiply, + dappStorageTwo.get(0).getMemberId(), + MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); - BigDecimal profitSymbol = profitU.divide(symbolPrice, 2, RoundingMode.HALF_DOWN); + realAmount = realAmount.add(multiply); + } + List<DappStorage> dappStorageThree = dappStorageMapper.selectSumByAmountDescFiveToFive(DateUtil.offsetHour(new Date(),-24),2,1); + if(CollUtil.isNotEmpty(dappStorageThree)){ + BigDecimal multiply = everyAmount.multiply(new BigDecimal(threeCount)); + dappSystemService.updateBalanceInsertFlow( + multiply, + dappStorageThree.get(0).getMemberId(), + MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); - dappWalletService.updateWalletMineWithLock(profitSymbol, item.getId(), 1); - DappFundFlowEntity fundFlow = new DappFundFlowEntity(item.getId(), profitSymbol, 11, 2, null, null); - dappFundFlowDao.insert(fundFlow); + realAmount = realAmount.add(multiply); + } + List<DappStorage> dappStorageFour = dappStorageMapper.selectSumByAmountDescFiveToFive(DateUtil.offsetHour(new Date(),-24),3,1); + if(CollUtil.isNotEmpty(dappStorageFour)){ + BigDecimal multiply = everyAmount.multiply(new BigDecimal(fourCount)); + dappSystemService.updateBalanceInsertFlow( + multiply, + dappStorageFour.get(0).getMemberId(), + MoneyFlowEnum.DA_DAN_JI_LI_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.DA_DAN_JI_LI_PERK.getDescrition(),daDanTotal,multiply)); + + realAmount = realAmount.add(multiply); + } } - }); + } + + /** + * 另外50% 给予当天直推总业绩排名激励前10名,第1名40%,2-4名30%,5-10名30% + */ + BigDecimal directTotal = jiLiTotal.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_DOWN); +// /** +// * 存放直推业绩<上级的memberId,直推总业绩> +// */ +// HashMap<Long, BigDecimal> map = new HashMap<>(); +// +// List<DappStorage> dappStorages = dappStorageMapper.selectListByDate(new Date()); +// if(CollUtil.isNotEmpty(dappStorages)){ +// for(DappStorage dappStorage : dappStorages){ +// DappMemberEntity member = dappMemberDao.selectById(dappStorage.getMemberId()); +// if(StrUtil.isEmpty(member.getRefererId())){ +// continue; +// } +// DappMemberEntity memberRef = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); +// if(ObjectUtil.isEmpty(memberRef)){ +// continue; +// } +// Long id = memberRef.getId(); +// if(map.containsKey(id)){ +// BigDecimal bigDecimal = map.get(id); +// BigDecimal add = bigDecimal.add(dappStorage.getAmount()); +// map.put(id,add); +// }else{ +// map.put(id,dappStorage.getAmount()); +// } +// } +// } + + /** + * 存放直推人数<上级的memberId,直推人数> + */ + HashMap<Long, BigDecimal> map = new HashMap<>(); + + DateTime startTime = DateUtil.offsetHour(new Date(), -24); +// DateTime startTime = DateUtil.parseDateTime(startTimeStr); +// List<DappMemberEntity> dappMemberEntityList = dappMemberDao.selectListByDateFiveToFiver(startTime); + + List<DappStorage> dappStorages = dappStorageMapper.selectListByDateFiveToFiver(startTime); + Set<Long> collect = dappStorages.stream().map(DappStorage::getMemberId).collect(Collectors.toSet()); + +// List<DappMemberEntity> dappMemberEntityList = dappMemberDao.selectListByDate(new Date()); + if(CollUtil.isNotEmpty(collect)){ + for(Long memberId : collect){ + DappMemberEntity member = dappMemberDao.selectById(memberId); + if(StrUtil.isEmpty(member.getRefererId())){ + continue; + } + if(2 == member.getActiveStatus()){ + continue; + } + DappMemberEntity memberRef = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); + if(ObjectUtil.isEmpty(memberRef)){ + continue; + } + Long id = memberRef.getId(); + if(map.containsKey(id)){ + BigDecimal bigDecimal = map.get(id); + BigDecimal add = bigDecimal.add(new BigDecimal("1")); + map.put(id,add); + }else{ + map.put(id,new BigDecimal("1")); + } + } + } + /** + * 获取这个map的直推总业绩前十,分发奖励 + */ + if(!map.isEmpty()){ + // 使用Stream API按照BigDecimal从大到小排序 + List<Map.Entry<Long, BigDecimal>> topTenEntries = map.entrySet().stream() + .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) + .limit(10) + .collect(Collectors.toList()); + + List<ApidirectNumVo> apiDirectInfoVos = new ArrayList<>(); + for (Map.Entry<Long, BigDecimal> entry : topTenEntries) { + Long memberId = entry.getKey(); + BigDecimal directCnt = entry.getValue(); + ApidirectNumVo apiDirectInfoVo = new ApidirectNumVo(); + apiDirectInfoVo.setMemberId(memberId); + apiDirectInfoVo.setDirectCnt(directCnt); + DappStorage dappStorage = dappStorageMapper.selectNewRecordByRefMemberId(memberId); + apiDirectInfoVo.setCreateTime(dappStorage.getCreateTime()); + apiDirectInfoVos.add(apiDirectInfoVo); + } + + if(CollUtil.isNotEmpty(apiDirectInfoVos)){ + apiDirectInfoVos = apiDirectInfoVos.stream() + .sorted((a, b) -> { + // 先按照amount从大到小排序 + int compare = b.getDirectCnt().compareTo(a.getDirectCnt()); + if (compare != 0) { + return compare; + } + // 如果amount相同,则按照createTime从小到大排序 + return a.getCreateTime().compareTo(b.getCreateTime()); + }) + .collect(Collectors.toList()); + } + + int startNum = 1; + for (ApidirectNumVo numVo : apiDirectInfoVos) { + Long memberId = numVo.getMemberId(); + BigDecimal directAchieve = numVo.getDirectCnt(); + //第一名 + if(startNum == 1){ + BigDecimal bigDecimal = directTotal.multiply(new BigDecimal("0.4")).setScale(2, BigDecimal.ROUND_DOWN); + dappSystemService.updateBalanceInsertFlow( + bigDecimal, + memberId, + MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getDescrition(),directAchieve,startNum,bigDecimal)); + + realAmount = realAmount.add(bigDecimal); + }else if(startNum > 1 && startNum <=4){ + BigDecimal bigDecimal = directTotal.multiply(new BigDecimal("0.3")).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal divide = bigDecimal.divide(new BigDecimal("3"), 2, BigDecimal.ROUND_DOWN); + + dappSystemService.updateBalanceInsertFlow( + divide, + memberId, + MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getDescrition(),directAchieve,startNum,divide)); + + realAmount = realAmount.add(divide); + }else{ + BigDecimal bigDecimal = directTotal.multiply(new BigDecimal("0.3")).setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal divide = bigDecimal.divide(new BigDecimal("6"), 2, BigDecimal.ROUND_DOWN); + + dappSystemService.updateBalanceInsertFlow( + divide, + memberId, + MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getValue(), + StrUtil.format(MoneyFlowEnum.ZHI_TUI_JI_LI_PERK.getDescrition(),directAchieve,startNum,divide)); + + realAmount = realAmount.add(divide); + } + startNum = startNum + 1; + } + } + + BigDecimal subtract = new BigDecimal(jiliChiDic.getValue()).subtract(realAmount); + jiliChiDic.setValue(subtract.toString()); + dataDictionaryCustomMapper.updateById(jiliChiDic); + } + + public static void main(String[] args) { + + Date date = new Date(); + System.out.println(date); + DateTime dateTime1 = DateUtil.offsetHour(date, 24); + System.out.println(dateTime1); + + int compare = DateUtil.compare(date, dateTime1); + System.out.println(compare); + + DateTime dateTime = DateUtil.offsetHour(new Date(), -24); + System.out.println(dateTime); + DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(new Date())); + DateTime perkTime = DateUtil.parseTime("17:00:00"); + + String startTimeStr = null; + if(DateUtil.compare(nowTime,perkTime) >= 0){ + startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), 0)) + " 17:00:00"; + }else{ + startTimeStr = DateUtil.formatDate(DateUtil.offsetDay(new Date(), -1)) + " 17:00:00"; + } + + DateTime startTime = DateUtil.parseDateTime(startTimeStr); + + + + // 创建一个HashMap示例 + HashMap<Long, BigDecimal> map = new HashMap<>(); + map.put(1L, new BigDecimal("100.00")); + map.put(2L, new BigDecimal("200.00")); + map.put(3L, new BigDecimal("50.00")); + map.put(4L, new BigDecimal("300.00")); + map.put(5L, new BigDecimal("150.00")); + map.put(6L, new BigDecimal("150.00")); + map.put(7L, new BigDecimal("150.00")); + map.put(8L, new BigDecimal("150.00")); + map.put(9L, new BigDecimal("150.00")); + map.put(10L, new BigDecimal("150.00")); + map.put(11L, new BigDecimal("150.00")); + // ... 可以继续添加元素 + + // 使用Stream API按照BigDecimal从大到小排序,并获取前十个元素 + List<Map.Entry<Long, BigDecimal>> topTenEntries = map.entrySet().stream() + .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) + .limit(10) + .collect(Collectors.toList()); + + // 打印结果 + for (Map.Entry<Long, BigDecimal> entry : topTenEntries) { + System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue()); + } } } -- Gitblit v1.9.1