|
@@ -20,6 +20,9 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.websocket.*;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
|
@ClientEndpoint
|
|
@@ -39,20 +42,20 @@ public class GameOneClient {
|
|
|
|
|
|
@OnOpen
|
|
|
public void onOpen(Session session) throws Exception{
|
|
|
- System.out.printf("game one 游戏已连接 server");
|
|
|
+ System.out.println("game one 游戏已连接 server");
|
|
|
// 发送游戏编码
|
|
|
session.getBasicRemote().sendText("{\"code\":\"" + Common.GAME_ONE_CODE + "\"}");
|
|
|
}
|
|
|
|
|
|
@OnClose
|
|
|
public void onClose(Session session) throws Exception{
|
|
|
- System.out.printf("game on 游戏已断开 server");
|
|
|
+ System.out.println("game on 游戏已断开 server");
|
|
|
connect();
|
|
|
}
|
|
|
|
|
|
@OnError
|
|
|
public void onError(Session session, Throwable throwable) throws Exception{
|
|
|
- System.out.printf("game one 连接异常 [" + throwable.getMessage() + "]");
|
|
|
+ System.out.println("game one 连接异常 [" + throwable.getMessage() + "]");
|
|
|
connect();
|
|
|
}
|
|
|
|
|
@@ -61,7 +64,7 @@ public class GameOneClient {
|
|
|
try {
|
|
|
GameOneConfig.webSocketConnent.connect();
|
|
|
}catch (Exception e){
|
|
|
- System.out.printf("连接 game on [socket] 异常" + e.getMessage());
|
|
|
+ System.out.println("连接 game on [socket] 异常" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -121,7 +124,7 @@ public class GameOneClient {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(time == null){
|
|
|
+ if(time == null || time.isEmpty()){
|
|
|
System.out.println("游戏socket推送倒计时,time为空。");
|
|
|
return;
|
|
|
}
|
|
@@ -129,7 +132,15 @@ public class GameOneClient {
|
|
|
AppGameClassify appGameClassify = appGameClassifyService.getByCode(classCode);
|
|
|
if(appGameClassify == null){
|
|
|
System.out.println("开奖游戏平台不存在:" + classCode);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AppGame> appGameList = appGameService.selectAppGameByClassId(appGameClassify.getId());
|
|
|
+ if(appGameList == null || appGameList.isEmpty()){
|
|
|
+ System.out.println("开奖游戏平台没有游戏:" + classCode);
|
|
|
+ return;
|
|
|
}
|
|
|
+ Map<String, List<AppGame>> codeGameMap = appGameList.stream().collect(Collectors.groupingBy(AppGame::getCode));
|
|
|
|
|
|
for (int i = 0; i < gameDataArry.size(); i++) {
|
|
|
JSONObject jsonObject = gameDataArry.getJSONObject(i);
|
|
@@ -138,11 +149,11 @@ public class GameOneClient {
|
|
|
System.out.println("游戏socket推送倒计时,游戏id为空。");
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- AppGame appGame = appGameService.selectAppGameByClassIdAndCode(appGameClassify.getId(), gameCode);
|
|
|
- if(appGame == null){
|
|
|
+ if(!codeGameMap.containsKey(gameCode)){
|
|
|
System.out.println("开奖游戏不存在:" + gameCode);
|
|
|
+ continue;
|
|
|
}
|
|
|
+ AppGame appGame = codeGameMap.get(gameCode).get(0);
|
|
|
appGame.setGameTime(time);
|
|
|
appGameService.updateAppGame(appGame);
|
|
|
}
|
|
@@ -158,7 +169,7 @@ public class GameOneClient {
|
|
|
for (int i = 0; i < dataArry.size(); i++) {
|
|
|
JSONObject jsonObject = dataArry.getJSONObject(i);
|
|
|
if(jsonObject.containsKey("gameTypeSortArrayVOS")){
|
|
|
- gameArry = jsonObject.getJSONArray("data");
|
|
|
+ gameArry = jsonObject.getJSONArray("gameTypeSortArrayVOS");
|
|
|
}
|
|
|
if(jsonObject.containsKey("id")){
|
|
|
classCode = jsonObject.getString("id");
|
|
@@ -180,6 +191,13 @@ public class GameOneClient {
|
|
|
System.out.println("开奖游戏平台不存在:" + classCode);
|
|
|
}
|
|
|
|
|
|
+ List<AppGame> appGameList = appGameService.selectAppGameByClassId(appGameClassify.getId());
|
|
|
+ if(appGameList == null || appGameList.isEmpty()){
|
|
|
+ System.out.println("开奖游戏平台没有游戏:" + classCode);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, List<AppGame>> codeGameMap = appGameList.stream().collect(Collectors.groupingBy(AppGame::getCode));
|
|
|
+
|
|
|
for (int i = 0; i < gameArry.size(); i++) {
|
|
|
JSONObject gameLotteryObject = gameArry.getJSONObject(i);
|
|
|
String gameCode = gameLotteryObject.getString("id");
|
|
@@ -189,13 +207,13 @@ public class GameOneClient {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- AppGame appGame = appGameService.selectAppGameByClassIdAndCode(appGameClassify.getId(), gameCode);
|
|
|
- if(appGame == null){
|
|
|
+ if(!codeGameMap.containsKey(gameCode)){
|
|
|
System.out.println("开奖游戏不存在:" + gameCode);
|
|
|
+ continue;
|
|
|
}
|
|
|
+ AppGame appGame = codeGameMap.get(gameCode).get(0);
|
|
|
|
|
|
String gameDate = gameLotteryObject.getString("gameDate");
|
|
|
-
|
|
|
if(gameDate == null){
|
|
|
System.out.println("游戏socket推送期号或开奖,期号为空。");
|
|
|
return;
|
|
@@ -220,6 +238,7 @@ public class GameOneClient {
|
|
|
// 保存开奖记录
|
|
|
AppGameLottery appGameLottery = new AppGameLottery();
|
|
|
appGameLottery.setGameId(appGame.getId());
|
|
|
+ appGameLottery.setClassId(appGame.getClassifyId());
|
|
|
appGameLottery.setGameDate(gameDate);
|
|
|
appGameLottery.setIsLottery(isLottery);
|
|
|
appGameLottery.setGameRecordDate(new Date());
|
|
@@ -234,7 +253,7 @@ public class GameOneClient {
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
- System.out.printf("game one 接收数据异常[" + e.getMessage() + "]");
|
|
|
+ System.out.println("game one 接收数据异常[" + e.getMessage() + "]");
|
|
|
}
|
|
|
}
|
|
|
}
|