|
@@ -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() + "]");
|