Browse Source

修改代码生成

kk 8 months ago
parent
commit
def7bb82ff

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

@@ -5,6 +5,7 @@ import com.game.business.service.*;
 import com.game.common.core.controller.BaseController;
 import com.game.common.core.domain.AjaxResult;
 import io.swagger.annotations.Api;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -62,6 +63,21 @@ public class AppGameBettingController extends BaseController{
             return error("游戏不存在。");
         }
 
+        if(StringUtils.isBlank(appGame.getGameDate())){
+            return error("游戏期号不存在,无法下单。");
+        }
+
+        if(StringUtils.isBlank(appGame.getGameTime())){
+            return error("游戏倒计时不存在,无法下单。");
+        }
+
+        String[] timeArry = appGame.getGameTime().substring(0, 4).split(":");
+        int m = Integer.parseInt(timeArry[1]);
+
+        if(m <= 3){
+            return error("游戏已封盘,无法下单。");
+        }
+
         synchronized (this){
 
             AppUser appUser = appUserService.getById(gameBetting.getUserId());
@@ -80,6 +96,7 @@ public class AppGameBettingController extends BaseController{
             appUser.setDiamondCoinTotal(appUser.getDiamondCoinCashTotal() - gameBetting.getBettingAmount());
             appUserService.updateAppUser(appUser);
 
+            gameBetting.setGameDate(appGame.getGameDate());
             // 插入投注记录
             appGameBettingService.save(gameBetting);
 

+ 19 - 0
game-business/src/main/java/com/game/business/domain/AppGame.java

@@ -37,12 +37,31 @@ private static final long serialVersionUID=1L;
     @TableField(value = "name")
     private String name;
 
+    /** 编码 */
+    @ApiModelProperty(value = "编码(对应游戏方ID)")
+    @Excel(name = "编码")
+    @TableField(value = "code")
+    private String code;
+
     /** 所属分类id */
     @ApiModelProperty(value = "所属分类id")
     @Excel(name = "所属分类id")
     @TableField(value = "classify_id")
     private Long classifyId;
 
+    /** 游戏当前期号 */
+    @ApiModelProperty(value = "游戏当前期号(socket推送填充、更新)")
+    @Excel(name = "游戏当前期号")
+    @TableField(value = "game_date")
+    private String gameDate;
+
+    /** 游戏当前期号 */
+    @ApiModelProperty(value = "游戏当前游戏倒计时(socket推送填充、更新)")
+    @Excel(name = "游戏当前倒计时")
+    @TableField(value = "game_time")
+    private String gameTime;
+
+
     /** logo */
     @ApiModelProperty(value = "logo")
     @Excel(name = "logo")

+ 6 - 0
game-business/src/main/java/com/game/business/domain/AppGameClassify.java

@@ -36,6 +36,12 @@ private static final long serialVersionUID=1L;
     @TableField(value = "name")
     private String name;
 
+    /** 编码 */
+    @ApiModelProperty(value = "编码(对应游戏方ID)")
+    @Excel(name = "编码")
+    @TableField(value = "code")
+    private String code;
+
     /** logo */
     @ApiModelProperty(value = "logo")
     @Excel(name = "logo")

+ 3 - 3
game-business/src/main/java/com/game/business/util/Common.java

@@ -2,10 +2,10 @@ package com.game.business.util;
 
 public class Common {
 
-    public static final String GANME_ONE_NAME = "";
-    public static final String GAME_ONE_CODE = "";
+    public static final String GANME_ONE_NAME = "one";
+    public static final String GAME_ONE_CODE = "1";
     public static final String GANME_TWO_NAME = "";
     public static final String GANME_THREES_NAME = "";
 
-    public static final String WS_GAME_URL = "";
+    public static final String WS_GAME_URL = "ws://47.115.49.14:8000/ws";
 }

+ 160 - 22
game-business/src/main/java/com/game/business/websocket/client/GameOneClient.java

@@ -1,18 +1,23 @@
 package com.game.business.websocket.client;
 
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.game.business.config.GameOneConfig;
 import com.game.business.domain.AppGame;
+import com.game.business.domain.AppGameClassify;
 import com.game.business.domain.AppGameLottery;
+import com.game.business.service.IAppGameClassifyService;
 import com.game.business.service.IAppGameLotteryService;
 import com.game.business.service.IAppGameService;
+import com.game.business.task.AppGameBettingTask;
 import com.game.business.util.Common;
-import com.game.common.utils.DateUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.websocket.*;
+import java.util.Date;
 
 @Component
 @ClientEndpoint
@@ -24,6 +29,12 @@ public class GameOneClient {
     @Autowired
     private IAppGameService appGameService;
 
+    @Autowired
+    private IAppGameClassifyService appGameClassifyService;
+
+    @Autowired
+    private AppGameBettingTask appGameBettingTask;
+
     @OnOpen
     public void onOpen(Session session) throws Exception{
         System.out.printf("game one 游戏已连接 server");
@@ -57,43 +68,170 @@ public class GameOneClient {
     public void onMessage(Session session, String message){
         try {
             if(StringUtils.isBlank(message)){
-                System.out.printf("game one 数据为空");
+                System.out.println("game one 数据为空");
                 return;
             }
 
-            System.out.printf("game one 接收数据[" + message + "]");
+            System.out.println("game one 接收数据" + message);
+            JSONArray dataArry = JSONArray.parseArray(message);
 
-            JSONObject jsonObject = JSONObject.parseObject(message);
-            String code = jsonObject.getString("code");
+            Integer type = null;
 
-            if(StringUtils.isBlank(code) || !code.equals(Common.GAME_ONE_CODE)){
-                System.out.printf("game one 接收数据错误[" + message + "]");
+            for (int i = 0; i < dataArry.size(); i++) {
+                JSONObject jsonObject = dataArry.getJSONObject(i);
+                if(jsonObject.containsKey("type")){
+                    type = jsonObject.getInteger("type");
+                }
+            }
+
+            if(type == null){
+                System.out.println("游戏socket推送类型为空。");
                 return;
             }
 
-            // 是否为开奖
-            Integer isLottery = jsonObject.getInteger("isLottery");
-            if(isLottery == 0){
+            // 更新倒计时
+            if(type == 1){
+
+                JSONArray gameDataArry = null;
+                String time = null;
+                String classCode = null;
+                for (int i = 0; i < dataArry.size(); i++) {
+                    JSONObject jsonObject = dataArry.getJSONObject(i);
+                    if(jsonObject.containsKey("data")){
+                        gameDataArry = jsonObject.getJSONArray("data");
+                    }
+                    if(jsonObject.containsKey("time")){
+                        time = jsonObject.getString("time");
+                    }
+                    if(jsonObject.containsKey("id")){
+                        classCode = jsonObject.getString("id");
+                    }
+                }
+
+                if(classCode == null){
+                    System.out.println("游戏socket推送倒计时,平台ID为空。");
+                    return;
+                }
+
+                LambdaQueryWrapper<AppGameClassify> queryWrapper = new LambdaQueryWrapper<>();
+                queryWrapper.eq(AppGameClassify::getCode, classCode);
+                AppGameClassify appGameClassify = appGameClassifyService.getOne(queryWrapper);
+                if(appGameClassify == null){
+                    System.out.println("开奖游戏平台不存在:" + classCode);
+                }
+
+                if(gameDataArry == null){
+                    System.out.println("游戏socket推送倒计时,data对象为空。");
+                    return;
+                }
+
+                if(time == null){
+                    System.out.println("游戏socket推送倒计时,time为空。");
+                    return;
+                }
+
+                for (int i = 0; i < gameDataArry.size(); i++) {
+                    JSONObject jsonObject = gameDataArry.getJSONObject(i);
+                    String gameCode = jsonObject.getString("id");
+                    if(gameCode == null){
+                        System.out.println("游戏socket推送倒计时,游戏id为空。");
+                        continue;
+                    }
+
+                    LambdaQueryWrapper<AppGame> queryGameWrapper = new LambdaQueryWrapper<>();
+                    queryGameWrapper.eq(AppGame::getCode, gameCode);
+                    queryGameWrapper.eq(AppGame::getClassifyId, appGameClassify.getId());
+                    AppGame appGame = appGameService.getOne(queryGameWrapper);
+                    if(appGame == null){
+                        System.out.println("开奖游戏不存在:" + gameCode);
+                    }
+                    appGame.setGameTime(time);
+                    appGameService.updateById(appGame);
+                }
                 return;
             }
 
-            AppGame appGame = appGameService.selectAppGameById(0L);
+            if(type != 2 && type != 3){
+                return;
+            }
 
-            String gameDate = jsonObject.getString("gameDate");
-            String gameRecordDate = jsonObject.getString("gameRecordDate");
-            String gameLotterySucc = jsonObject.getString("gameLotterySucc");
+            JSONArray gameArry = null;
+            String classCode = null;
+            for (int i = 0; i < dataArry.size(); i++) {
+                JSONObject jsonObject = dataArry.getJSONObject(i);
+                if(jsonObject.containsKey("gameTypeSortArrayVOS")){
+                    gameArry = jsonObject.getJSONArray("data");
+                }
+                if(jsonObject.containsKey("id")){
+                    classCode = jsonObject.getString("id");
+                }
+            }
 
-            AppGameLottery appGameLottery = new AppGameLottery();
-            appGameLottery.setGameId(appGame.getId());
-            appGameLottery.setGameDate(gameDate);
-            appGameLottery.setIsLottery(isLottery);
-            appGameLottery.setGameRecordDate(DateUtils.parseDate(gameRecordDate));
-            appGameLottery.setGameLotterySucc(gameLotterySucc);
+            if(gameArry == null){
+                System.out.println("游戏socket推送期号或开奖,gameTypeSortArrayVOS对象为空。");
+                return;
+            }
 
-            appGameLotteryService.save(appGameLottery);
+            if(classCode == null){
+                System.out.println("游戏socket推送期号或开奖,平台ID为空。");
+                return;
+            }
 
-            // 开奖结算
+            LambdaQueryWrapper<AppGameClassify> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(AppGameClassify::getCode, classCode);
+            AppGameClassify appGameClassify = appGameClassifyService.getOne(queryWrapper);
+            if(appGameClassify == null){
+                System.out.println("开奖游戏平台不存在:" + classCode);
+            }
 
+            for (int i = 0; i < gameArry.size(); i++) {
+                JSONObject gameLotteryObject = gameArry.getJSONObject(i);
+                String gameCode = gameLotteryObject.getString("id");
+
+                if(gameCode == null){
+                    System.out.println("游戏socket推送期号或开奖,游戏ID为空。");
+                    return;
+                }
+
+                LambdaQueryWrapper<AppGame> queryGameWrapper = new LambdaQueryWrapper<>();
+                queryGameWrapper.eq(AppGame::getCode, gameCode);
+                queryGameWrapper.eq(AppGame::getClassifyId, appGameClassify.getId());
+                AppGame appGame = appGameService.getOne(queryGameWrapper);
+                if(appGame == null){
+                    System.out.println("开奖游戏不存在:" + gameCode);
+                }
+
+                String gameDate = gameLotteryObject.getString("gameDate");
+
+                if(gameDate == null){
+                    System.out.println("游戏socket推送期号或开奖,期号为空。");
+                    return;
+                }
+
+                if(type == 3){
+                    appGame.setGameDate(gameDate);
+                    appGameService.updateById(appGame);
+                    continue;
+                }
+
+                Integer isLottery = gameLotteryObject.getInteger("isLottery");
+                String gameLotterySucc = gameLotteryObject.getString("gameLotterySucc");
+
+                // 保存开奖记录
+                AppGameLottery appGameLottery = new AppGameLottery();
+                appGameLottery.setGameId(appGame.getId());
+                appGameLottery.setGameDate(gameDate);
+                appGameLottery.setIsLottery(isLottery);
+                appGameLottery.setGameRecordDate(new Date());
+                appGameLottery.setGameLotterySucc(gameLotterySucc);
+                appGameLotteryService.save(appGameLottery);
+
+                if(isLottery != 1){
+                    continue;
+                }
+
+                appGameBettingTask.gameBettingTask(appGameClassify.getId(), appGame.getId(), gameDate, gameLotterySucc);
+            }
         }catch (Exception e){
             e.printStackTrace();
             System.out.printf("game one 接收数据异常[" + e.getMessage() + "]");

+ 6 - 1
game-business/src/main/resources/mapper/business/AppGameClassifyMapper.xml

@@ -7,19 +7,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <resultMap type="com.game.business.domain.AppGameClassify" id="AppGameClassifyResult">
         <result property="id"    column="id"    />
         <result property="name"    column="name"    />
+        <result property="code"    column="code"    />
         <result property="logoUrl"    column="logo_url"    />
         <result property="status"    column="status"    />
         <result property="orderno"    column="orderno"    />
     </resultMap>
 
     <sql id="selectAppGameClassifyVo">
-        select id, name, logo_url, status, orderno from app_game_classify
+        select id, name, code, logo_url, status, orderno from app_game_classify
     </sql>
 
     <select id="selectAppGameClassifyList" parameterType="com.game.business.domain.AppGameClassify" resultMap="AppGameClassifyResult">
         <include refid="selectAppGameClassifyVo"/>
         <where>  
             <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
+            <if test="code != null  and code != ''"> and code like concat('%', #{code}, '%')</if>
             <if test="logoUrl != null  and logoUrl != ''"> and logo_url = #{logoUrl}</if>
             <if test="status != null "> and status = #{status}</if>
             <if test="orderno != null "> and orderno = #{orderno}</if>
@@ -36,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="id != null">id,</if>
             <if test="name != null">name,</if>
+            <if test="code != null">code,</if>
             <if test="logoUrl != null">logo_url,</if>
             <if test="status != null">status,</if>
             <if test="orderno != null">orderno,</if>
@@ -43,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
             <if test="name != null">#{name},</if>
+            <if test="code != null">#{code},</if>
             <if test="logoUrl != null">#{logoUrl},</if>
             <if test="status != null">#{status},</if>
             <if test="orderno != null">#{orderno},</if>
@@ -53,6 +57,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update app_game_classify
         <trim prefix="SET" suffixOverrides=",">
             <if test="name != null">name = #{name},</if>
+            <if test="code != null">code = #{code},</if>
             <if test="logoUrl != null">logo_url = #{logoUrl},</if>
             <if test="status != null">status = #{status},</if>
             <if test="orderno != null">orderno = #{orderno},</if>

+ 11 - 1
game-business/src/main/resources/mapper/business/AppGameMapper.xml

@@ -7,7 +7,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <resultMap type="com.game.business.domain.AppGame" id="AppGameResult">
         <result property="id"    column="id"    />
         <result property="name"    column="name"    />
+        <result property="code"    column="code"    />
         <result property="classifyId"    column="classify_id"    />
+        <result property="gameDate"    column="game_date"    />
+        <result property="gameTime"    column="game_time"    />
         <result property="logoUrl"    column="logo_url"    />
         <result property="gamePath"    column="game_path"    />
         <result property="status"    column="status"    />
@@ -20,13 +23,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectAppGameVo">
-        select id, name, classify_id, logo_url, game_path, status, create_time, orderno, game_expand1, game_expand2, game_expand3, game_expand4 from app_game
+        select id, name, code, classify_id, game_date, game_time, logo_url, game_path, status, create_time, orderno, game_expand1, game_expand2, game_expand3, game_expand4 from app_game
     </sql>
 
     <select id="selectAppGameList" parameterType="com.game.business.domain.AppGame" resultMap="AppGameResult">
         <include refid="selectAppGameVo"/>
         <where>  
             <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
+            <if test="code != null  and code != ''"> and code like concat('%', #{code}, '%')</if>
+            <if test="gameDate != null  and gameDate != ''"> and game_date like concat('%', #{gameDate}, '%')</if>
             <if test="classifyId != null "> and classify_id = #{classifyId}</if>
             <if test="logoUrl != null  and logoUrl != ''"> and logo_url = #{logoUrl}</if>
             <if test="gamePath != null  and gamePath != ''"> and game_path = #{gamePath}</if>
@@ -49,6 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="id != null">id,</if>
             <if test="name != null">name,</if>
+            <if test="code != null">code,</if>
             <if test="classifyId != null">classify_id,</if>
             <if test="logoUrl != null">logo_url,</if>
             <if test="gamePath != null">game_path,</if>
@@ -63,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
             <if test="name != null">#{name},</if>
+            <if test="code != null">#{code},</if>
             <if test="classifyId != null">#{classifyId},</if>
             <if test="logoUrl != null">#{logoUrl},</if>
             <if test="gamePath != null">#{gamePath},</if>
@@ -80,7 +87,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update app_game
         <trim prefix="SET" suffixOverrides=",">
             <if test="name != null">name = #{name},</if>
+            <if test="code != null">code = #{code},</if>
             <if test="classifyId != null">classify_id = #{classifyId},</if>
+            <if test="gameDate != null">game_date = #{gameDate},</if>
+            <if test="gameTime != null">game_time = #{gameTime},</if>
             <if test="logoUrl != null">logo_url = #{logoUrl},</if>
             <if test="gamePath != null">game_path = #{gamePath},</if>
             <if test="status != null">status = #{status},</if>