Эх сурвалжийг харах

修改开奖列表,添加自定义开奖

kk 1 долоо хоног өмнө
parent
commit
4d4e4b9ec1

+ 12 - 2
game-business/src/main/java/com/game/business/controller/AppGameLotteryController.java

@@ -89,6 +89,16 @@ public class AppGameLotteryController extends BaseController{
             appGameItem.setGameId(gameId);
             List<AppGameItem> itemList = appGameItemService.selectAppGameItemList(appGameItem);
             Map<String, List<AppGameItem>> codeItmeMap = itemList.stream().collect(Collectors.groupingBy(AppGameItem::getItemLocation));
+
+            Map<String, List<AppGameItemMultiple>> gameDateMap = null;
+
+            if(appGame.getCode().equals(Common.GAME_ONE_CODE)){
+                List<AppGameItemMultiple> appGameItemMultipleList = appGameItemMultipleService.getAppGameItemMultipleList(appGame.getId());
+                if(appGameItemMultipleList != null && !appGameItemMultipleList.isEmpty()) {
+                    gameDateMap = appGameItemMultipleList.stream().collect(Collectors.groupingBy(AppGameItemMultiple::getGameDate));
+                }
+            }
+
             for (int i = 0; i <list.size(); i++) {
                 AppGameLottery appGameLottery  = list.get(i);
                 AppGameLotteryVO appGameLotteryVO = new AppGameLotteryVO();
@@ -101,8 +111,8 @@ public class AppGameLotteryController extends BaseController{
                     List<String> multipleList = new ArrayList<>();
 
                     if(appGame.getCode().equals(Common.GAME_ONE_CODE)){
-                        AppGameItemMultiple appGameItemMultiple = appGameItemMultipleService.getAppGameItemMultiple(appGameLottery.getGameId(), appGameLottery.getGameDate());
-                        if(appGameItemMultiple != null){
+                        if(gameDateMap != null && gameDateMap.containsKey(appGameLottery.getGameDate())){
+                            AppGameItemMultiple appGameItemMultiple = gameDateMap.get(appGameLottery.getGameDate()).get(0);
                             multipleList = Arrays.asList(appGameItemMultiple.getItemMultiple().split(","));
                         }
                     }

+ 3 - 0
game-business/src/main/java/com/game/business/mapper/AppGameBettingMapper.java

@@ -24,6 +24,9 @@ public interface AppGameBettingMapper extends BaseMapper<AppGameBetting> {
     Map<String, BigDecimal> getBettingAmountSum(Long userId);
     Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO);
 
+    Map<String, BigDecimal> getBettingAmountByDate(@Param(value = "gameId") Long gameId, @Param(value = "dateStr") String dateStr);
+    List<AppUserGameBettingDetailsCountVO> getBettingAmountByGameDate(@Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingType") Integer bettingType);
+
     Integer getBettingCount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingItem") String bettingItem);
     Integer getBettingItemCount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingItem") String bettingItem);
     BigDecimal getBettingAmount(@Param(value = "userId") Long userId, @Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "bettingItem") String bettingItem);

+ 4 - 0
game-business/src/main/java/com/game/business/service/IAppGameBettingService.java

@@ -46,6 +46,10 @@ public interface IAppGameBettingService extends IService<AppGameBetting> {
 
     Map<String, BigDecimal> getBettingAmountSum(Long userId);
 
+    Map<String, BigDecimal> getBettingAmountByDate(Long gameId, String dateStr);
+
+    List<AppUserGameBettingDetailsCountVO> getBettingAmountByGameDate(Long gameId, String gameDate, Integer bettingType);
+
     Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO);
 
     Integer getBettingCount(Long userId, Long gameId, String gameDate, String bettingItem);

+ 4 - 0
game-business/src/main/java/com/game/business/service/IAppGameItemMultipleService.java

@@ -3,10 +3,14 @@ package com.game.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.game.business.domain.AppGameItemMultiple;
 
+import java.util.List;
+
 public interface IAppGameItemMultipleService extends IService<AppGameItemMultiple> {
 
     Boolean checkAooGameItemMultiple(Long gameId, String gameDate);
 
     AppGameItemMultiple getAppGameItemMultiple(Long gameId, String gameDate);
 
+    List<AppGameItemMultiple> getAppGameItemMultipleList(Long gameId);
+
 }

+ 2 - 0
game-business/src/main/java/com/game/business/service/IAppGameLotteryService.java

@@ -12,6 +12,8 @@ public interface IAppGameLotteryService extends IService<AppGameLottery> {
 
     long selectCount(Long classId, Long gameId, String gameDate);
 
+    long selectCountAuto(Long classId, Long gameId, String dateStr);
+
     AppGameLottery selectLottery(Long classId, Long gameId, String gameDate);
 
     boolean save(AppGameLottery appGameLottery);

+ 10 - 0
game-business/src/main/java/com/game/business/service/impl/AppGameBettingServiceImpl.java

@@ -161,6 +161,16 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
         return appGameBettingMapper.getBettingAmountSum(userId);
     }
 
+    @Override
+    public Map<String, BigDecimal> getBettingAmountByDate(Long gameId, String dateStr) {
+        return appGameBettingMapper.getBettingAmountByDate(gameId, dateStr);
+    }
+
+    @Override
+    public List<AppUserGameBettingDetailsCountVO> getBettingAmountByGameDate(Long gameId, String gameDate, Integer bettingType) {
+        return appGameBettingMapper.getBettingAmountByGameDate(gameId, gameDate, bettingType);
+    }
+
     @Override
     public Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO) {
         return appGameBettingMapper.getBettingAmountByDateSum(finTranRecordDTO);

+ 12 - 0
game-business/src/main/java/com/game/business/service/impl/AppGameItemMultipleServiceImpl.java

@@ -8,6 +8,9 @@ import com.game.business.service.IAppGameItemMultipleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Collections;
+import java.util.List;
+
 @Service
 public class AppGameItemMultipleServiceImpl extends ServiceImpl<AppGameItemMultipleMapper, AppGameItemMultiple> implements IAppGameItemMultipleService {
 
@@ -29,4 +32,13 @@ public class AppGameItemMultipleServiceImpl extends ServiceImpl<AppGameItemMulti
         queryWrapper.eq(AppGameItemMultiple::getGameDate, gameDate);
         return appGameItemMultipleMapper.selectOne(queryWrapper);
     }
+
+    @Override
+    public List<AppGameItemMultiple> getAppGameItemMultiple(Long gameId) {
+        LambdaQueryWrapper<AppGameItemMultiple> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(AppGameItemMultiple::getGameId, gameId);
+        queryWrapper.orderByDesc(AppGameItemMultiple::getGameDate);
+        queryWrapper.last(" limit 2000");
+        return appGameItemMultipleMapper.selectList(queryWrapper);
+    }
 }

+ 10 - 0
game-business/src/main/java/com/game/business/service/impl/AppGameLotteryServiceImpl.java

@@ -27,6 +27,16 @@ public class AppGameLotteryServiceImpl extends ServiceImpl<AppGameLotteryMapper,
         return appGameLotteryMapper.selectCount(queryLotteryWrapper);
     }
 
+    @Override
+    public long selectCountAuto(Long classId, Long gameId, String dateStr) {
+        LambdaQueryWrapper<AppGameLottery> queryLotteryWrapper = Wrappers.lambdaQuery();;
+        queryLotteryWrapper.eq(AppGameLottery::getClassId, classId);
+        queryLotteryWrapper.eq(AppGameLottery::getGameId, gameId);
+        queryLotteryWrapper.eq(AppGameLottery::getIsLottery, 1);
+        queryLotteryWrapper.between(AppGameLottery::getGameRecordDate, dateStr + " 00:00:00", dateStr + " 23:59:59");
+        return appGameLotteryMapper.selectCount(queryLotteryWrapper);
+    }
+
     @Override
     public AppGameLottery selectLottery(Long classId, Long gameId, String gameDate) {
         LambdaQueryWrapper<AppGameLottery> queryLotteryWrapper = Wrappers.lambdaQuery();;

+ 8 - 1
game-business/src/main/java/com/game/business/task/AppGameBettingTask.java

@@ -62,6 +62,9 @@ public class AppGameBettingTask {
     @Autowired
     private IAppGameItemMultipleService appGameItemMultipleService;
 
+    @Autowired
+    private AppGameLotteryAutoTask appGameLotteryAutoTask;
+
     @Async("asyncExecutor")
     public void gameDataTask(String message, String gameCodeFinal) throws Exception {
 
@@ -348,7 +351,7 @@ public class AppGameBettingTask {
                 continue;
             }
 
-            String redisKey = CacheConstants.GAME_LOTTERY_TASK.concat(appGame.getId() + ":" + gameCode);
+            String redisKey = CacheConstants.GAME_LOTTERY_TASK.concat(appGame.getId() + ":" + gameDate);
             if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey, 1)){
                 continue;
             }
@@ -357,6 +360,10 @@ public class AppGameBettingTask {
 
                 AppGameLottery appGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), gameDate);
 
+                if(gameCode.equals("6")){
+                    gameLotterySucc = appGameLotteryAutoTask.autoTask(appGame, gameDate);
+                }
+
                 if(appGameLottery == null){
                     // 保存开奖记录
                     appGameLottery = new AppGameLottery();

+ 158 - 0
game-business/src/main/java/com/game/business/task/AppGameLotteryAutoTask.java

@@ -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;
+    }
+}

+ 21 - 0
game-business/src/main/resources/mapper/business/AppGameBettingMapper.xml

@@ -167,6 +167,27 @@
         </if>
     </select>
 
+    <select id="getBettingAmountByDate" resultType="java.util.Map">
+        select
+        ifnull(sum(case when betting_type = 1 then betting_amount else 0.00 end), 0.00) as coinSum,
+        ifnull(sum(case when betting_type = 1 and is_winning = 1  then betting_amount * betting_multiple else 0.00 end), 0.00) as coinWin,
+        ifnull(sum(case when betting_type = 1 and is_winning = 2 then betting_amount else 0.00 end), 0.00) as coinLose,
+        ifnull(sum(case when betting_type = 0 then betting_amount else 0.00 end), 0.00) as diamondCoinSum,
+        ifnull(sum(case when betting_type = 0 and is_winning = 1 then betting_amount * betting_multiple else 0.00 end), 0.00) as diamondCoinWin,
+        ifnull(sum(case when betting_type = 0 and is_winning = 2 then betting_amount else 0.00 end), 0.00) as diamondCoinLose
+        from app_game_betting and game_id = #{gameId} and date_format(create_time, '%Y-%m-%d') = #{dateStr})
+    </select>
+
+    <select id="getBettingAmountByGameDate" resultType="com.game.business.vo.AppUserGameBettingDetailsCountVO">
+        select
+            betting_item as bettingTtem,
+            sum(betting_amount) as orderAmount,
+            sum(case when is_winning = 1 then (betting_amount * betting_multiple) else 0.00 end) as winAmount,
+            sum(case when is_winning = 2 then betting_amount else 0.00 end) as loseAmount
+        from app_game_betting where game_id = #{gameId} and game_date = #{gameDate} and betting_type = #{bettingType}
+        group by betting_item
+    </select>
+
     <sql id="selectAppGameBettingVo">
         select id, class_id, game_id, user_id, game_date, live_user_id, live_room_id, money_id, is_live, betting_type, betting_game_type, betting_item, betting_multiple, betting_amount, betting_commission, is_winning, create_time, update_time from app_game_betting
     </sql>