Răsfoiți Sursa

添加 中奖次数、连中次数; 添加投注记录统计

kk 3 luni în urmă
părinte
comite
6405a80b0a

+ 17 - 0
game-business/src/main/java/com/game/business/controller/AppGameBettingController.java

@@ -7,6 +7,7 @@ import com.game.business.vo.AppGameBettingCountVO;
 import com.game.business.vo.AppGameBettingDetailsCountVO;
 import com.game.business.service.*;
 import com.game.business.vo.AppGameBettingVO;
+import com.game.business.vo.AppUserGameBettingCountVO;
 import com.game.common.annotation.Anonymous;
 import com.game.common.constant.finance.FinTranType1;
 import com.game.common.constant.finance.FinTranType2;
@@ -15,6 +16,7 @@ import com.game.common.core.controller.BaseController;
 import com.game.common.core.domain.HttpRet;
 import com.game.common.core.domain.HttpRetPageArr;
 import com.game.common.core.redis.RedisCache;
+import com.game.common.utils.SecurityUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
@@ -325,4 +327,19 @@ public class AppGameBettingController extends BaseController{
         }
         return HttpRetPageArr.success("查询成功",getDataTable(resultList));
     }
+
+
+    /**
+     * 游戏投注记录
+     */
+    @Anonymous
+    @PostMapping(value = "/listHistory")
+    @ApiOperation(value = "游戏投注记录", notes = "游戏投注记录")
+    public HttpRetPageArr<AppUserGameBettingCountVO> listHistory(@RequestParam(name = "gameId") Long gameId , @RequestParam(name = "bettingType", required = false) Integer bettingType)
+    {
+        startPage();
+        Long userId = SecurityUtils.getUserId();
+        List<AppUserGameBettingCountVO> list = appGameBettingService.getUserCount(gameId, userId, bettingType);
+        return HttpRetPageArr.success("查询成功",getDataTable(list));
+    }
 }

+ 12 - 0
game-business/src/main/java/com/game/business/controller/AppGameItemController.java

@@ -3,6 +3,7 @@ package com.game.business.controller;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
+import com.game.common.core.domain.HttpRetArr;
 import com.game.common.core.domain.R;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,6 +54,17 @@ public class AppGameItemController extends BaseController
         return getDataTable(list);
     }
 
+    /**
+     * 查询游戏选项列表
+     */
+    @GetMapping("/listAll")
+    @ApiOperation(value = "查询游戏所有选项", notes = "查询游戏所有选项")
+    public HttpRetArr<AppGameItem> listAll(AppGameItem appGameItem)
+    {
+        List<AppGameItem> list = appGameItemService.selectAppGameItemList(appGameItem);
+        return HttpRetArr.success("查询成功", list);
+    }
+
     /**
      * 导出游戏选项列表
      */

+ 11 - 1
game-business/src/main/java/com/game/business/domain/AppGameItem.java

@@ -50,8 +50,18 @@ private static final long serialVersionUID=1L;
 
     /** 选项值(第三方同步) */
     @ApiModelProperty(value = "选项值(第三方同步)")
-    @Excel(name = "选项值" , readConverterExp = "第=三方同步")
+    @Excel(name = "选项值" , readConverterExp = "第三方同步")
     @TableField(value = "item_location")
     private String itemLocation;
 
+    @ApiModelProperty(value = "开奖次数")
+    @Excel(name = "开奖次数" , readConverterExp = "开奖次数")
+    @TableField(value = "lottery_count")
+    private Integer lotteryCount;
+
+    @ApiModelProperty(value = "连中次数")
+    @Excel(name = "连中次数" , readConverterExp = "连中次数")
+    @TableField(value = "consecutive")
+    private Integer consecutive;
+
 }

+ 15 - 0
game-business/src/main/java/com/game/business/dto/AppItemCountDTO.java

@@ -0,0 +1,15 @@
+package com.game.business.dto;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "游戏选项连中次数", description = "游戏选项连中次数")
+public class AppItemCountDTO {
+
+    private Long gameId;
+
+    private String itemLocation;
+
+    private Integer consecutive;
+}

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

@@ -4,6 +4,7 @@ package com.game.business.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.game.business.domain.AppGameBetting;
 import com.game.business.vo.AppGameBettingDetailsCountVO;
+import com.game.business.vo.AppUserGameBettingCountVO;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -11,4 +12,5 @@ import java.util.List;
 public interface AppGameBettingMapper extends BaseMapper<AppGameBetting> {
 
     List<AppGameBettingDetailsCountVO> getCount(@Param(value = "strDate") String strDate, @Param(value = "userId") Long userId,  @Param(value = "bettingType") Integer bettingType);
+    List<AppUserGameBettingCountVO> getUserCount(@Param(value = "gameId") Long gameId, @Param(value = "userId") Long userId, @Param(value = "bettingType") Integer bettingType);
 }

+ 18 - 0
game-business/src/main/java/com/game/business/mapper/AppGameItemMapper.java

@@ -3,6 +3,7 @@ package com.game.business.mapper;
 import java.util.List;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.game.business.domain.AppGameItem;
+import com.game.business.dto.AppItemCountDTO;
 
 /**
  * 游戏选项Mapper接口
@@ -43,6 +44,23 @@ public interface AppGameItemMapper extends BaseMapper<AppGameItem> {
      */
     public int updateAppGameItem(AppGameItem appGameItem);
 
+    /**
+     * 修改游戏选项开奖值
+     *
+     * @param appGameItem 修改游戏选项开奖值
+     * @return 结果
+     */
+    int updateLotteryCount(AppGameItem appGameItem);
+
+    /**
+     * 修改连中次数
+     *
+     * @param appGameItem 修改连中次数
+     * @return 结果
+     */
+    int updateConsecutive(AppItemCountDTO appGameItem);
+
+
     /**
      * 删除游戏选项
      *

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

@@ -3,6 +3,7 @@ package com.game.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.game.business.domain.AppGameBetting;
 import com.game.business.vo.AppGameBettingDetailsCountVO;
+import com.game.business.vo.AppUserGameBettingCountVO;
 
 import java.util.List;
 
@@ -16,6 +17,8 @@ public interface IAppGameBettingService extends IService<AppGameBetting> {
 
     List<AppGameBettingDetailsCountVO> getCount(String strDate, Long userId, Integer bettingType);
 
+    List<AppUserGameBettingCountVO> getUserCount(Long gameId, Long userId, Integer bettingType);
+
     List<AppGameBetting> selectListByGameId(Long gameId, Long userId, Integer isWinning, String strDate, Integer bettingType);
 
     /**

+ 17 - 0
game-business/src/main/java/com/game/business/service/IAppGameItemService.java

@@ -3,6 +3,7 @@ package com.game.business.service;
 import java.util.List;
 import com.game.business.domain.AppGameItem;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.game.business.dto.AppItemCountDTO;
 
 /**
  * 游戏选项Service接口
@@ -52,6 +53,22 @@ public interface IAppGameItemService extends IService<AppGameItem> {
      */
     public int updateAppGameItem(AppGameItem appGameItem);
 
+    /**
+     * 修改游戏选项开奖值
+     *
+     * @param appGameItem 修改游戏选项开奖值
+     * @return 结果
+     */
+    int updateLotteryCount(AppGameItem appGameItem);
+
+    /**
+     * 修改连中次数
+     *
+     * @param appGameItem 修改连中次数
+     * @return 结果
+     */
+    int updateConsecutive(AppItemCountDTO appGameItem);
+
     /**
      * 批量删除游戏选项
      *

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

@@ -7,6 +7,7 @@ import com.game.business.domain.AppGameBetting;
 import com.game.business.vo.AppGameBettingDetailsCountVO;
 import com.game.business.mapper.AppGameBettingMapper;
 import com.game.business.service.IAppGameBettingService;
+import com.game.business.vo.AppUserGameBettingCountVO;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -47,6 +48,11 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
         return appGameBettingMapper.getCount(strDate, userId, bettingType);
     }
 
+    @Override
+    public List<AppUserGameBettingCountVO> getUserCount(Long gameId, Long userId, Integer bettingType) {
+        return appGameBettingMapper.getUserCount(gameId, userId, bettingType);
+    }
+
     @Override
     public List<AppGameBetting> selectListByGameId(Long gameId, Long userId, Integer isWinning, String strDate, Integer bettingType) {
         LambdaQueryWrapper<AppGameBetting> queryWrapper = Wrappers.lambdaQuery();;

+ 12 - 1
game-business/src/main/java/com/game/business/service/impl/AppGameItemServiceImpl.java

@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import java.util.List;
 
-import com.game.business.domain.AppGameBetting;
+import com.game.business.dto.AppItemCountDTO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.game.business.mapper.AppGameItemMapper;
@@ -84,6 +84,17 @@ public class AppGameItemServiceImpl extends ServiceImpl<AppGameItemMapper, AppGa
         return appGameItemMapper.updateAppGameItem(appGameItem);
     }
 
+    @Override
+    @DataSource(DataSourceType.SLAVE)
+    public int updateLotteryCount(AppGameItem appGameItem) {
+        return appGameItemMapper.updateLotteryCount(appGameItem);
+    }
+
+    @Override
+    public int updateConsecutive(AppItemCountDTO appGameItem) {
+        return appGameItemMapper.updateConsecutive(appGameItem);
+    }
+
     /**
      * 批量删除游戏选项
      *

+ 61 - 13
game-business/src/main/java/com/game/business/task/AppGameBettingTask.java

@@ -1,23 +1,20 @@
 package com.game.business.task;
 
-import cn.hutool.core.util.IdUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.game.business.domain.*;
+import com.game.business.dto.AppItemCountDTO;
 import com.game.business.service.*;
 import com.game.common.constant.finance.FinTranType1;
 import com.game.common.constant.finance.FinTranType2;
 import com.game.common.constant.finance.FinTranType3;
-import com.game.common.core.domain.HttpRet;
 import com.game.common.core.redis.RedisCache;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Component
@@ -41,6 +38,9 @@ public class AppGameBettingTask {
     @Autowired
     private IAppGameClassifyService appGameClassifyService;
 
+    @Autowired
+    private IAppGameItemService appGameItemService;
+
     @Autowired
     private RedisCache redisCache;
 
@@ -197,6 +197,18 @@ public class AppGameBettingTask {
                 continue;
             }
 
+            Integer isLottery = gameLotteryObject.getInteger("isLottery");
+            String gameLotterySucc = gameLotteryObject.getString("gameLotterySucc");
+
+            if(isLottery != 1){
+                continue;
+            }
+
+            if(gameLotterySucc == null || gameLotterySucc.trim().isEmpty()){
+//                System.out.println("游戏socket推送倒计时,time为空。");
+                continue;
+            }
+
             long count = appGameLotteryService.selectCount(appGame.getClassifyId(), appGame.getId(), gameDate);
 
             if(count > 0){
@@ -204,9 +216,6 @@ public class AppGameBettingTask {
                 continue;
             }
 
-            Integer isLottery = gameLotteryObject.getInteger("isLottery");
-            String gameLotterySucc = gameLotteryObject.getString("gameLotterySucc");
-
             // 保存开奖记录
             AppGameLottery appGameLottery = new AppGameLottery();
             appGameLottery.setGameId(appGame.getId());
@@ -217,9 +226,7 @@ public class AppGameBettingTask {
             appGameLottery.setGameLotterySucc(gameLotterySucc);
             appGameLotteryService.save(appGameLottery);
 
-            if(isLottery != 1){
-                continue;
-            }
+            this.updateItme(appGame.getId(), gameLotterySucc);
 
             this.gameBettingTask(appGameClassify.getId(), appGame.getId(), gameDate, gameLotterySucc);
 
@@ -228,7 +235,48 @@ public class AppGameBettingTask {
 
     }
 
-    @Transactional
+    public void updateItme(Long gameId, String gameLotterySucc){
+
+        // 获取上次开奖结果
+        List<AppItemCountDTO> itemCountList = new ArrayList<>();
+        String gameLotterySuccCache =  redisCache.getCacheObject("G:GameCount:" + gameId);
+        if(gameLotterySuccCache != null && !gameLotterySuccCache.trim().isEmpty()){
+            itemCountList = JSONArray.parseArray(gameLotterySuccCache, AppItemCountDTO.class);
+        }
+
+        // 修改游戏选项
+        String [] bettingItems = gameLotterySucc.split(",");
+        List<AppItemCountDTO> nowItemCountList = new ArrayList<>();
+        for(int j = 0; j < bettingItems.length; j++) {
+            String bettingItemStr = bettingItems[j];
+
+            AppItemCountDTO appItemCountDTO = new AppItemCountDTO();
+            appItemCountDTO.setGameId(gameId);
+            appItemCountDTO.setItemLocation(bettingItemStr);
+            appItemCountDTO.setConsecutive(1);
+
+            AppGameItem appGameItem = new AppGameItem();
+            appGameItem.setGameId(gameId);
+            appGameItem.setItemLocation(bettingItemStr);
+            // 开奖次数
+            appGameItemService.updateLotteryCount(appGameItem);
+
+            if(!itemCountList.isEmpty()){
+                for (AppItemCountDTO appItemCount : itemCountList){
+                    if(appItemCount.getItemLocation().equals(bettingItemStr)){
+                        appItemCountDTO.setConsecutive(appItemCount.getConsecutive() + 1);
+                    }
+                }
+            }
+
+            // 更新连中
+            appGameItemService.updateConsecutive(appItemCountDTO);
+            nowItemCountList.add(appItemCountDTO);
+        }
+
+        redisCache.setCacheObject("G:GameCount:" + gameId, JSON.toJSONString(nowItemCountList));
+    }
+
     public void gameBettingTask(Long classId, Long gameId, String gameDate, String bettingItem){
 
         List<AppGameBetting> list = appGameBettingService.getIsWinning(classId, gameId, gameDate, 0);

+ 33 - 0
game-business/src/main/java/com/game/business/vo/AppUserGameBettingCountVO.java

@@ -0,0 +1,33 @@
+package com.game.business.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@ApiModel(value = "游戏选项连中次数", description = "游戏选项连中次数")
+public class AppUserGameBettingCountVO {
+
+    @ApiModelProperty(value = "当前期号")
+    private String gameDate;
+
+    @ApiModelProperty(value = "数量")
+    private long bettingCount;
+
+    @ApiModelProperty(value = "下单金额")
+    private double orderAmount;
+
+    @ApiModelProperty(value = "赢")
+    private double winAmount;
+
+    @ApiModelProperty(value = "输")
+    private double loseAmount;
+
+    @ApiModelProperty(value = "当前开奖项")
+    private String gameLotterySucc;
+
+    @ApiModelProperty(value = "当前开奖时间")
+    private Date gameRecordDate;
+}

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

@@ -15,4 +15,20 @@
         and betting_type = #{bettingType}
         group by game_id
     </select>
+
+    <select id="getUserCount" resultType="com.game.business.vo.AppUserGameBettingCountVO">
+        select tmp.*,agl.game_lottery_succ as gameLotterySucc,agl.game_record_date as gameRecordDate from (
+          select
+              game_date as gameDate,
+              count(id) as bettingCount,
+              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 user_id = #{userId} and betting_type = #{bettingType}
+          group by game_date
+        ) tmp
+        left join app_game_lottery agl on agl.game_date = tmp.gameDate and agl.game_id = #{gameId}
+        where agl.is_lottery = 1
+        order by tmp.gameDate desc
+    </select>
 </mapper>

+ 20 - 1
game-business/src/main/resources/mapper/business/AppGameItemMapper.xml

@@ -10,10 +10,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="itemName"    column="item_name"    />
         <result property="itemMultiple"    column="item_multiple"    />
         <result property="itemLocation"    column="item_location"    />
+        <result property="lotteryCount"    column="lottery_count"    />
+        <result property="consecutive"    column="consecutive"    />
     </resultMap>
 
     <sql id="selectAppGameItemVo">
-        select id, game_id, item_name, item_multiple, item_location from app_game_item
+        select id, game_id, item_name, item_multiple, item_location, lottery_count, consecutive from app_game_item
     </sql>
 
     <select id="selectAppGameItemList" parameterType="com.game.business.domain.AppGameItem" resultMap="AppGameItemResult">
@@ -38,12 +40,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="itemName != null">item_name,</if>
             <if test="itemMultiple != null">item_multiple,</if>
             <if test="itemLocation != null">item_location,</if>
+            <if test="lotteryCount != null">#{lottery_count},</if>
+            <if test="consecutive != null">#{consecutive},</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="gameId != null">#{gameId},</if>
             <if test="itemName != null">#{itemName},</if>
             <if test="itemMultiple != null">#{itemMultiple},</if>
             <if test="itemLocation != null">#{itemLocation},</if>
+            <if test="lotteryCount != null">#{lotteryCount},</if>
+            <if test="consecutive != null">#{consecutive},</if>
          </trim>
     </insert>
 
@@ -54,6 +60,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="itemName != null">item_name = #{itemName},</if>
             <if test="itemMultiple != null">item_multiple = #{itemMultiple},</if>
             <if test="itemLocation != null">item_location = #{itemLocation},</if>
+            <if test="lotteryCount != null">lottery_count = #{lotteryCount},</if>
+            <if test="consecutive != null">consecutive = #{consecutive},</if>
         </trim>
         where id = #{id}
     </update>
@@ -68,4 +76,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <update id="updateLotteryCount" parameterType="com.game.business.domain.AppGameItem">
+        update app_game_item set lottery_count = lottery_count + 1
+        where game_id = #{gameId} and item_location = #{itemLocation}
+    </update>
+
+    <update id="updateConsecutive" parameterType="com.game.business.dto.AppItemCountDTO">
+        update app_game_item set consecutive = consecutive + 1
+        where game_id = #{gameId} and item_location = #{itemLocation} and consecutive &lt; #{consecutive}
+    </update>
+
 </mapper>