|
@@ -0,0 +1,158 @@
|
|
|
+package com.game.business.task;
|
|
|
+
|
|
|
+import com.game.business.domain.AppGame;
|
|
|
+import com.game.business.domain.AppGameItem;
|
|
|
+import com.game.business.service.IAppGameBettingService;
|
|
|
+import com.game.business.service.IAppGameItemService;
|
|
|
+import com.game.business.service.IAppGameLotteryService;
|
|
|
+import com.game.business.vo.AppUserGameBettingDetailsCountVO;
|
|
|
+import com.game.common.utils.DateUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class AppGameLotteryAutoTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppGameBettingService appGameBettingService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppGameItemService appGameItemService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppGameLotteryService appGameLotteryService;
|
|
|
+
|
|
|
+
|
|
|
+ public String autoTask(AppGame appGame, String gameDate){
|
|
|
+
|
|
|
+ Long gameId = appGame.getId();
|
|
|
+
|
|
|
+ Map<String, BigDecimal> dateBetting = appGameBettingService.getBettingAmountByDate(gameId, DateUtils.dateTime(new Date()));
|
|
|
+
|
|
|
+ // 余额投注总输赢
|
|
|
+ BigDecimal diamondCoinSum = dateBetting.get("diamondCoinSum");
|
|
|
+ BigDecimal diamondCoinWin = dateBetting.get("diamondCoinWin");
|
|
|
+ BigDecimal diamondCoinLose = dateBetting.get("diamondCoinLose");
|
|
|
+
|
|
|
+ // 金币投注总输赢
|
|
|
+ BigDecimal coinSum = dateBetting.get("coinSum");
|
|
|
+ BigDecimal coinWin = dateBetting.get("coinWin");
|
|
|
+ BigDecimal coinLose =dateBetting.get("coinLose");
|
|
|
+
|
|
|
+ if(coinSum.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ diamondCoinSum = diamondCoinSum.add(coinSum.divide(new BigDecimal("100.00")).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(coinWin.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ diamondCoinWin = diamondCoinWin.add(coinWin.divide(new BigDecimal("100.00")).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(coinLose.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ diamondCoinLose = diamondCoinLose.add(coinLose.divide(new BigDecimal("100.00")).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 余额选项投注详情
|
|
|
+ List<AppUserGameBettingDetailsCountVO> diamondCoinBettingDetailsList = appGameBettingService.getBettingAmountByGameDate(gameId, gameDate, 0);
|
|
|
+ Map<String, List<AppUserGameBettingDetailsCountVO>> diamondCoinMap = null;
|
|
|
+ double diamondCoinGameDateSum = 0.0;
|
|
|
+ if(diamondCoinBettingDetailsList != null && !diamondCoinBettingDetailsList.isEmpty()){
|
|
|
+ diamondCoinMap = diamondCoinBettingDetailsList.stream().collect(Collectors.groupingBy(AppUserGameBettingDetailsCountVO::getBettingTtem));
|
|
|
+ diamondCoinGameDateSum = diamondCoinBettingDetailsList.stream().mapToDouble(AppUserGameBettingDetailsCountVO::getOrderAmount).sum();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 金币选项投注详情
|
|
|
+ List<AppUserGameBettingDetailsCountVO> coinBettingDetailsList = appGameBettingService.getBettingAmountByGameDate(gameId, gameDate, 1);
|
|
|
+ Map<String, List<AppUserGameBettingDetailsCountVO>> coinMap = null;
|
|
|
+ if(coinBettingDetailsList != null && !coinBettingDetailsList.isEmpty()){
|
|
|
+ coinMap = coinBettingDetailsList.stream().collect(Collectors.groupingBy(AppUserGameBettingDetailsCountVO::getBettingTtem));
|
|
|
+ double coinGameDateSum = diamondCoinBettingDetailsList.stream().mapToDouble(AppUserGameBettingDetailsCountVO::getOrderAmount).sum();
|
|
|
+ if(coinGameDateSum > 0){
|
|
|
+ diamondCoinGameDateSum += coinGameDateSum / 100;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ AppGameItem appGameItem = new AppGameItem();
|
|
|
+ appGameItem.setGameId(gameId);
|
|
|
+ List<AppGameItem> itemList = appGameItemService.selectAppGameItemList(appGameItem);
|
|
|
+
|
|
|
+ double itemMultiple = 0;
|
|
|
+ for(AppGameItem item : itemList){
|
|
|
+ itemMultiple += item.getItemMultiple();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> pools = new ArrayList<>();
|
|
|
+
|
|
|
+ for(AppGameItem item : itemList){
|
|
|
+ Double rete = itemMultiple * 100 / item.getItemMultiple();
|
|
|
+ int int_rate = rete.intValue();
|
|
|
+ for (int i = 0; i < int_rate; i++) {
|
|
|
+ pools.add(item.getItemLocation());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //随机开奖
|
|
|
+ Collections.shuffle(pools);
|
|
|
+
|
|
|
+ int index = new Random().nextInt(pools.size());
|
|
|
+ String lottertSucc = pools.get(index);
|
|
|
+
|
|
|
+ AppGameItem gameItem = appGameItemService.selectAppGameItemByGameIdAndItemLocation(gameId, lottertSucc);
|
|
|
+
|
|
|
+ double lottertAmount = 0.0;
|
|
|
+ if(diamondCoinMap != null && diamondCoinMap.containsKey(lottertSucc)){
|
|
|
+ AppUserGameBettingDetailsCountVO detailsCountVO = diamondCoinMap.get(lottertSucc).get(0);
|
|
|
+ lottertAmount = detailsCountVO.getOrderAmount() * gameItem.getItemMultiple();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(coinMap != null && coinMap.containsKey(lottertSucc)){
|
|
|
+ AppUserGameBettingDetailsCountVO detailsCountVO = coinMap.get(lottertSucc).get(0);
|
|
|
+ lottertAmount += detailsCountVO.getOrderAmount() / 100.00 * gameItem.getItemMultiple();;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> itemPools = new ArrayList<>();
|
|
|
+
|
|
|
+ // 开奖次数
|
|
|
+ long count = appGameLotteryService.selectCountAuto(appGame.getClassifyId(), appGame.getId(), DateUtils.dateTime(new Date()));
|
|
|
+
|
|
|
+ // 开始走最低开盘
|
|
|
+ if(count > 500 && diamondCoinWin.subtract(diamondCoinSum).compareTo(BigDecimal.ZERO) > 0){
|
|
|
+
|
|
|
+ // 随机开奖
|
|
|
+ if(lottertAmount - diamondCoinGameDateSum > 0){
|
|
|
+
|
|
|
+ for (AppGameItem item : itemList) {
|
|
|
+ double orderAmount = 0.0;
|
|
|
+
|
|
|
+ if(diamondCoinMap != null){
|
|
|
+ if(diamondCoinMap.containsKey(item.getItemLocation())){
|
|
|
+ AppUserGameBettingDetailsCountVO detailsCountVO = diamondCoinMap.get(item.getItemLocation()).get(0);
|
|
|
+ orderAmount += detailsCountVO.getOrderAmount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(coinMap != null){
|
|
|
+ if(coinMap.containsKey(item.getItemLocation())){
|
|
|
+ AppUserGameBettingDetailsCountVO detailsCountVO = coinMap.get(item.getItemLocation()).get(0);
|
|
|
+ orderAmount += detailsCountVO.getOrderAmount() / 100.00;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(orderAmount == 0 || (orderAmount * itemMultiple) - diamondCoinGameDateSum <= 0){
|
|
|
+ itemPools.add(item.getItemLocation());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!itemPools.isEmpty()){
|
|
|
+ index = new Random().nextInt(itemPools.size());
|
|
|
+ lottertSucc = pools.get(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ return lottertSucc;
|
|
|
+ }
|
|
|
+}
|