Parcourir la source

修改中奖逻辑

kk il y a 3 mois
Parent
commit
ea02689a0d

+ 22 - 0
game-business/src/main/java/com/game/business/config/GameFourConfig.java

@@ -0,0 +1,22 @@
+package com.game.business.config;
+
+import com.game.business.util.Common;
+import com.game.business.websocket.WebSocketConnent;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.stereotype.Component;
+
+@Component
+@EnableAsync
+public class GameFourConfig implements CommandLineRunner {
+
+    public static WebSocketConnent webSocketConnent;
+
+    @Override
+    @Async
+    public void run(String... args) throws Exception {
+//        webSocketConnent = new WebSocketConnent(Common.WS_GAME_FOUR_URL, Common.WS_GAME_FOUR_REMARK_URL, Common.GAME_FOUR_NAME);
+//        webSocketConnent.connect();
+    }
+}

+ 2 - 2
game-business/src/main/java/com/game/business/config/GameOneConfig.java

@@ -16,7 +16,7 @@ public class GameOneConfig implements CommandLineRunner {
     @Override
     @Async
     public void run(String... args) throws Exception {
-        webSocketConnent = new WebSocketConnent(Common.WS_GAME_ONE_URL, Common.WS_GAME_ONE_REMARK_URL, Common.GANME_ONE_NAME);
-        webSocketConnent.connect();
+//        webSocketConnent = new WebSocketConnent(Common.WS_GAME_ONE_URL, Common.WS_GAME_ONE_REMARK_URL, Common.GANME_ONE_NAME);
+//        webSocketConnent.connect();
     }
 }

+ 22 - 0
game-business/src/main/java/com/game/business/config/GameThreesConfig.java

@@ -0,0 +1,22 @@
+package com.game.business.config;
+
+import com.game.business.util.Common;
+import com.game.business.websocket.WebSocketConnent;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.stereotype.Component;
+
+@Component
+@EnableAsync
+public class GameThreesConfig implements CommandLineRunner {
+
+    public static WebSocketConnent webSocketConnent;
+
+    @Override
+    @Async
+    public void run(String... args) throws Exception {
+//        webSocketConnent = new WebSocketConnent(Common.WS_GAME_THREES_URL, Common.WS_GAME_THREES_REMARK_URL, Common.GAME_THREES_NAME);
+//        webSocketConnent.connect();
+    }
+}

+ 103 - 95
game-business/src/main/java/com/game/business/task/AppGameBettingTask.java

@@ -297,135 +297,143 @@ public class AppGameBettingTask {
             appGameBetting.setUpdateTime(new Date());
 
             String [] bettingItems = bettingItem.split(",");
-            for(int j = 0; j < bettingItems.length; j++){
-                String bettingItemStr = bettingItems[j];
+            List<String> bettingItemsList = Arrays.asList(bettingItems);
 
-                double bettingAmount = appGameBetting.getBettingAmount() * appGameBetting.getBettingMultiple();
+            double bettingAmount = appGameBetting.getBettingAmount() * appGameBetting.getBettingMultiple();
 
-                if(appGameBetting.getBettingGameType() == 0){
-                    if(!appGameBetting.getBettingItem().equals(bettingItemStr)){
-                        appGameBetting.setIsWinning(2);
-                        appGameBettingService.updateById(appGameBetting);
-                        continue;
-                    }
-                }else if(appGameBetting.getBettingGameType() == 1 || appGameBetting.getBettingGameType() == 2){
-                    List<AppGameItemBettingVO> itemList = JSON.parseArray(appGameBetting.getBettingItem(), AppGameItemBettingVO.class);
-                    if(itemList == null || itemList.isEmpty()){
-                        appGameBetting.setIsWinning(2);
-                        appGameBettingService.updateById(appGameBetting);
-                        continue;
-                    }
-                    List<String> bettingItemList = itemList.stream().map(AppGameItemBettingVO::getBettingItem).collect(Collectors.toList());
-                    if(!bettingItemList.contains(bettingItemStr)){
-                        appGameBetting.setIsWinning(2);
-                        appGameBettingService.updateById(appGameBetting);
-                        continue;
-                    }
-
-                    if(appGameBetting.getBettingGameType() == 2){
-                        for (int k = 0; k < itemList.size(); k++) {
-                            AppGameItemBettingVO appGameItemBettingVO = itemList.get(k);
-                            if(appGameItemBettingVO.getBettingItem().equals(bettingItemStr)){
-                                bettingAmount = appGameBetting.getBettingAmount() * appGameItemBettingVO.getBettingMultiple();
-                            }
-                        }
+            if(appGameBetting.getBettingGameType() == 0){
+                if(!bettingItemsList.contains(appGameBetting.getBettingItem())){
+                    appGameBetting.setIsWinning(2);
+                    appGameBettingService.updateById(appGameBetting);
+                    continue;
+                }
+            }else if(appGameBetting.getBettingGameType() == 1 || appGameBetting.getBettingGameType() == 2){
+                List<AppGameItemBettingVO> itemList = JSON.parseArray(appGameBetting.getBettingItem(), AppGameItemBettingVO.class);
+                if(itemList == null || itemList.isEmpty()){
+                    appGameBetting.setIsWinning(2);
+                    appGameBettingService.updateById(appGameBetting);
+                    continue;
+                }
+                List<String> bettingItemList = itemList.stream().map(AppGameItemBettingVO::getBettingItem).collect(Collectors.toList());
+                boolean isWinning = false;
+                for (int j = 0; j < bettingItemList.size(); j++) {
+                    String bettingItemStr = bettingItemList.get(j);
+                    if(bettingItemsList.contains(bettingItemStr)){
+                        isWinning = true;
+                        break;
                     }
                 }
 
-                AppUser appUser = appUserService.selectAppUserByUserid(appGameBetting.getUserId());
-                if(appUser == null){
-                    appGameBetting.setIsWinning(1);
+                if(!isWinning){
+                    appGameBetting.setIsWinning(2);
                     appGameBettingService.updateById(appGameBetting);
                     continue;
                 }
 
-                // 添加推送消息用户
-                String userId = appUser.getUserid() + "";
-                if(!userIds.contains(userId)){
-                    userIds.add(userId);
+                if(appGameBetting.getBettingGameType() == 2){
+                    for (int k = 0; k < itemList.size(); k++) {
+                        AppGameItemBettingVO appGameItemBettingVO = itemList.get(k);
+                        if(bettingItemsList.contains(appGameItemBettingVO.getBettingItem())){
+                            bettingAmount = appGameBetting.getBettingAmount() * appGameItemBettingVO.getBettingMultiple();
+                            break;
+                        }
+                    }
                 }
+            }
+
+            AppUser appUser = appUserService.selectAppUserByUserid(appGameBetting.getUserId());
+            if(appUser == null){
+                appGameBetting.setIsWinning(1);
+                appGameBettingService.updateById(appGameBetting);
+                continue;
+            }
 
-                // 更新用户余额
-                if(appGameBetting.getBettingType() == 0){
-                    appUser.setDiamondCoin(appUser.getDiamondCoin() + bettingAmount );
-                    appUser.setDiamondCoinTotal(appUser.getDiamondCoinCashTotal() + bettingAmount);
-                    appUser.setDiamondCoinCash(appUser.getDiamondCoinCash() + bettingAmount);
+            // 添加推送消息用户
+            String userId = appUser.getUserid() + "";
+            if(!userIds.contains(userId)){
+                userIds.add(userId);
+            }
+
+            // 更新用户余额
+            if(appGameBetting.getBettingType() == 0){
+                appUser.setDiamondCoin(appUser.getDiamondCoin() + bettingAmount );
+                appUser.setDiamondCoinTotal(appUser.getDiamondCoinCashTotal() + bettingAmount);
+                appUser.setDiamondCoinCash(appUser.getDiamondCoinCash() + bettingAmount);
                 // 更新用户金币
-                }else{
-                    appUser.setCoin(appUser.getCoin() + bettingAmount);
+            }else{
+                appUser.setCoin(appUser.getCoin() + bettingAmount);
 //                    if(appUser.getRole() == 1){
 //                        appUser.setCoinCash(appUser.getCoinCash() + bettingAmount);
 //                    }
-                }
+            }
 
-                appUserService.updateAppUser(appUser);
+            appUserService.updateAppUser(appUser);
 
-                redisCache.deleteObject("U:UserInfo:" + appUser.getUserid());
+            redisCache.deleteObject("U:UserInfo:" + appUser.getUserid());
 
-                appGameBetting.setIsWinning(1);
-                appGameBettingService.updateById(appGameBetting);
+            appGameBetting.setIsWinning(1);
+            appGameBettingService.updateById(appGameBetting);
 
-                FinTranRecord finTranRecord = new FinTranRecord();
+            FinTranRecord finTranRecord = new FinTranRecord();
 
-                finTranRecord.setAfterCoin(appUser.getCoin());
-                finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
+            finTranRecord.setAfterCoin(appUser.getCoin());
+            finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
 
-                if(appGameBetting.getBettingType() == 0){
-                    finTranRecord.setCurrencyType(4);
-                    finTranRecord.setDiamondCoinChange(bettingAmount);
-                    finTranRecord.setCoinChange(0.00);
-                }else{
-                    finTranRecord.setCurrencyType(2);
-                    finTranRecord.setCoinChange(bettingAmount);
-                    finTranRecord.setDiamondCoinChange(0.00);
-                }
+            if(appGameBetting.getBettingType() == 0){
+                finTranRecord.setCurrencyType(4);
+                finTranRecord.setDiamondCoinChange(bettingAmount);
+                finTranRecord.setCoinChange(0.00);
+            }else{
+                finTranRecord.setCurrencyType(2);
+                finTranRecord.setCoinChange(bettingAmount);
+                finTranRecord.setDiamondCoinChange(0.00);
+            }
 
-                finTranRecord.setAfterMoney(0.00);
-                finTranRecord.setMoneyChange(0.00);
+            finTranRecord.setAfterMoney(0.00);
+            finTranRecord.setMoneyChange(0.00);
 
-                finTranRecord.setAfterTicket(0.00);
-                finTranRecord.setTicketChange(0.00);
+            finTranRecord.setAfterTicket(0.00);
+            finTranRecord.setTicketChange(0.00);
 
-                finTranRecord.setToUid(appUser.getUserid());
-                finTranRecord.setUid(appUser.getUserid());
+            finTranRecord.setToUid(appUser.getUserid());
+            finTranRecord.setUid(appUser.getUserid());
 
-                finTranRecord.setSceneId1(0L);
-                finTranRecord.setSceneId2(null);
-                finTranRecord.setSceneType(0L);
+            finTranRecord.setSceneId1(0L);
+            finTranRecord.setSceneId2(null);
+            finTranRecord.setSceneType(0L);
 
-                finTranRecord.setTranGroupId(appGameBetting.getId());
+            finTranRecord.setTranGroupId(appGameBetting.getId());
 
-                if(appGameBetting.getBettingType() == 0){
-                    finTranRecord.setTranType1(FinTranType1.U_Income_Coin_Balance.getType());
-                }else{
-                    finTranRecord.setTranType1(FinTranType1.U_Income_Coin.getType());
-                }
+            if(appGameBetting.getBettingType() == 0){
+                finTranRecord.setTranType1(FinTranType1.U_Income_Coin_Balance.getType());
+            }else{
+                finTranRecord.setTranType1(FinTranType1.U_Income_Coin.getType());
+            }
 
-                finTranRecord.setTranType2(FinTranType2.GAME_REWARD.getType());
-                finTranRecord.setTranType3(FinTranType3.CHARGE_WIN_GAME.getType());
+            finTranRecord.setTranType2(FinTranType2.GAME_REWARD.getType());
+            finTranRecord.setTranType3(FinTranType3.CHARGE_WIN_GAME.getType());
 
-                finTranRecord.setRemarks("游戏中奖");
+            finTranRecord.setRemarks("游戏中奖");
 
-                finTranRecord.setConsumptionCoin(appGameBetting.getBettingAmount());
-                finTranRecord.setConsumptionMoney(0.00);
-                finTranRecord.setCommissionRelatedUid(0L);
-                finTranRecord.setAgentId(appUser.getAgentId());
+            finTranRecord.setConsumptionCoin(appGameBetting.getBettingAmount());
+            finTranRecord.setConsumptionMoney(0.00);
+            finTranRecord.setCommissionRelatedUid(0L);
+            finTranRecord.setAgentId(appUser.getAgentId());
 
-                finTranRecord.setCreateTime(new Date());
+            finTranRecord.setCreateTime(new Date());
 
-                finTranRecord.setFromUid(appGameBetting.getUserId());
-                finTranRecord.setGoodsId(0L);
-                finTranRecord.setGuildId(0L);
-                finTranRecord.setManagerCoId(0L);
-                finTranRecord.setManagerId(0L);
+            finTranRecord.setFromUid(appGameBetting.getUserId());
+            finTranRecord.setGoodsId(0L);
+            finTranRecord.setGuildId(0L);
+            finTranRecord.setManagerCoId(0L);
+            finTranRecord.setManagerId(0L);
 
-                finTranRecord.setPerc(0.00);
-                finTranRecord.setProId(0L);
-                finTranRecord.setProCount(0L);
+            finTranRecord.setPerc(0.00);
+            finTranRecord.setProId(0L);
+            finTranRecord.setProCount(0L);
 
-                finTranRecord.setOrderId(appGameBetting.getId());
-                finTranRecordService.insertFinTranRecord(finTranRecord);
-            }
+            finTranRecord.setOrderId(appGameBetting.getId());
+            finTranRecordService.insertFinTranRecord(finTranRecord);
         }
         return userIds;
     }

+ 20 - 0
game-business/src/main/java/com/game/business/task/WebSokcetTask.java

@@ -32,5 +32,25 @@ public class WebSokcetTask {
                 session.getBasicRemote().sendText("ping");
             }
         }
+
+        if(Common.sessionMap.containsKey(Common.GAME_THREES_CODE)){
+            Session session = Common.sessionMap.get(Common.GAME_THREES_CODE);
+            if(!session.isOpen()){
+                Common.sessionMap.remove(Common.GAME_THREES_CODE);
+                session.close();
+            }else{
+                session.getBasicRemote().sendText("ping");
+            }
+        }
+
+        if(Common.sessionMap.containsKey(Common.GAME_FOUR_CODE)){
+            Session session = Common.sessionMap.get(Common.GAME_FOUR_CODE);
+            if(!session.isOpen()){
+                Common.sessionMap.remove(Common.GAME_FOUR_CODE);
+                session.close();
+            }else{
+                session.getBasicRemote().sendText("ping");
+            }
+        }
     }
 }

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

@@ -10,14 +10,19 @@ public class Common {
     public static final String GAME_ONE_CODE = "1";
     public static final String GANME_TWO_NAME = "two";
     public static final String GAME_TWO_CODE = "2";
-    public static final String GANME_THREES_NAME = "threes";
-    public static final String GANME_THREES_CODE = "3";
+    public static final String GAME_THREES_NAME = "threes";
+    public static final String GAME_THREES_CODE = "3";
+    public static final String GAME_FOUR_NAME = "four";
+    public static final String GAME_FOUR_CODE = "4";
 
     public static final String WS_GAME_ONE_URL = "ws://47.115.49.14:8000/ws";
     public static final String WS_GAME_ONE_REMARK_URL = "ws://47.238.102.31:8000/ws";
     public static final String WS_GAME_TWO_URL = "ws://47.115.54.173:8000/ws";
     public static final String WS_GAME_TWO_REMARK_URL = "ws://47.115.54.173:8000/ws";
-
+    public static final String WS_GAME_THREES_URL = "ws://43.154.162.11:8000/ws";
+    public static final String WS_GAME_THREES_REMARK_URL = "ws://43.154.162.11:8000/ws";
+    public static final String WS_GAME_FOUR_URL = "ws://43.154.162.11:8000/ws";
+    public static final String WS_GAME_FOUR_REMARK_URL = "ws://43.154.162.11:8000/ws";
 
     public static Map<String, Session> sessionMap = new HashMap<>();
 }

+ 11 - 0
game-business/src/main/java/com/game/business/websocket/WebSocketConnent.java

@@ -5,6 +5,7 @@ import com.game.business.config.GameTwoConfig;
 import com.game.business.config.SpringContextSetting;
 import com.game.business.util.Common;
 import com.game.business.websocket.client.GameOneClient;
+import com.game.business.websocket.client.GameThreesClient;
 import com.game.business.websocket.client.GameTwoClient;
 import org.apache.commons.lang3.StringUtils;
 
@@ -53,6 +54,16 @@ public class WebSocketConnent {
                     ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
                 }
 
+                if(Common.GAME_THREES_NAME.equals(this.WS_URL_NAME)){
+                    GameThreesClient client = SpringContextSetting.getBean(GameThreesClient.class);
+                    ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
+                }
+
+                if(Common.GAME_FOUR_NAME.equals(this.WS_URL_NAME)){
+                    GameThreesClient client = SpringContextSetting.getBean(GameThreesClient.class);
+                    ContainerProvider.getWebSocketContainer().connectToServer(client, new URI(this.WS_NOW_URL));
+                }
+
                 System.out.println(this.WS_URL_NAME + " 已成功连接Websocket[" + this.WS_NOW_URL + "]");
                 this.WS_CONNENT_NUM = 0;
                 break;

+ 71 - 0
game-business/src/main/java/com/game/business/websocket/client/GameFourClient.java

@@ -0,0 +1,71 @@
+package com.game.business.websocket.client;
+
+import com.game.business.config.GameFourConfig;
+import com.game.business.config.GameThreesConfig;
+import com.game.business.task.AppGameBettingTask;
+import com.game.business.util.Common;
+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
+public class GameFourClient {
+
+    @Autowired
+    private AppGameBettingTask appGameBettingTask;
+
+    @OnOpen
+    public void onOpen(Session session) throws Exception{
+        System.out.println("game four 游戏已连接 server");
+        session.getBasicRemote().sendText("ping");
+        Common.sessionMap.put(Common.GAME_FOUR_CODE, session);
+    }
+
+    @OnClose
+    public void onClose(Session session) throws Exception{
+        System.out.println("game four 游戏已断开 server:" + new Date());
+        connect();
+    }
+
+    @OnError
+    public void onError(Session session, Throwable throwable) throws Exception{
+        System.out.println("game four 连接异常 [" + throwable.getMessage() + "]");
+        connect();
+    }
+
+    public void connect(){
+        synchronized (this){
+            try {
+                GameFourConfig.webSocketConnent.connect();
+            }catch (Exception e){
+                System.out.println("连接 game four [socket] 异常" + e.getMessage());
+            }
+        }
+    }
+
+    @OnMessage
+    public void onMessage(Session session, String message){
+        try {
+            if(StringUtils.isBlank(message)){
+                System.out.println("game four 数据为空");
+                return;
+            }
+
+            System.out.println("game four 接收数据" + message);
+
+            if(message.equals("pong")){
+                return;
+            }
+
+            appGameBettingTask.gameDataTask(message, Common.GAME_FOUR_CODE);
+        }catch (Exception e){
+            e.printStackTrace();
+            System.out.println("game four 接收数据异常[" + e.getMessage() + "]");
+        }
+    }
+}

+ 0 - 1
game-business/src/main/java/com/game/business/websocket/client/GameOneClient.java

@@ -70,7 +70,6 @@ public class GameOneClient {
             System.out.println("game one 接收数据" + message);
 
             if(message.equals("pong")){
-//                session.getBasicRemote().sendText("ping");
                 return;
             }
 

+ 71 - 0
game-business/src/main/java/com/game/business/websocket/client/GameThreesClient.java

@@ -0,0 +1,71 @@
+package com.game.business.websocket.client;
+
+import com.game.business.config.GameThreesConfig;
+import com.game.business.config.GameTwoConfig;
+import com.game.business.task.AppGameBettingTask;
+import com.game.business.util.Common;
+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
+public class GameThreesClient {
+
+    @Autowired
+    private AppGameBettingTask appGameBettingTask;
+
+    @OnOpen
+    public void onOpen(Session session) throws Exception{
+        System.out.println("game threes 游戏已连接 server");
+        session.getBasicRemote().sendText("ping");
+        Common.sessionMap.put(Common.GAME_THREES_CODE, session);
+    }
+
+    @OnClose
+    public void onClose(Session session) throws Exception{
+        System.out.println("game threes 游戏已断开 server:" + new Date());
+        connect();
+    }
+
+    @OnError
+    public void onError(Session session, Throwable throwable) throws Exception{
+        System.out.println("game threes 连接异常 [" + throwable.getMessage() + "]");
+        connect();
+    }
+
+    public void connect(){
+        synchronized (this){
+            try {
+                GameThreesConfig.webSocketConnent.connect();
+            }catch (Exception e){
+                System.out.println("连接 game threes [socket] 异常" + e.getMessage());
+            }
+        }
+    }
+
+    @OnMessage
+    public void onMessage(Session session, String message){
+        try {
+            if(StringUtils.isBlank(message)){
+                System.out.println("game threes 数据为空");
+                return;
+            }
+
+            System.out.println("game threes 接收数据" + message);
+
+            if(message.equals("pong")){
+                return;
+            }
+
+            appGameBettingTask.gameDataTask(message, Common.GAME_THREES_CODE);
+        }catch (Exception e){
+            e.printStackTrace();
+            System.out.println("game threes 接收数据异常[" + e.getMessage() + "]");
+        }
+    }
+}

+ 1 - 2
game-business/src/main/java/com/game/business/websocket/client/GameTwoClient.java

@@ -59,14 +59,13 @@ public class GameTwoClient {
             System.out.println("game two 接收数据" + message);
 
             if(message.equals("pong")){
-//                session.getBasicRemote().sendText("ping");
                 return;
             }
 
             appGameBettingTask.gameDataTask(message, Common.GAME_TWO_CODE);
         }catch (Exception e){
             e.printStackTrace();
-            System.out.println("game one 接收数据异常[" + e.getMessage() + "]");
+            System.out.println("game two 接收数据异常[" + e.getMessage() + "]");
         }
     }
 }