AppGameBettingTask.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. package com.game.business.task;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson2.JSONArray;
  4. import com.alibaba.fastjson2.JSONObject;
  5. import com.baomidou.dynamic.datasource.annotation.DSTransactional;
  6. import com.game.business.domain.*;
  7. import com.game.business.dto.AppItemCountDTO;
  8. import com.game.business.service.*;
  9. import com.game.business.util.Common;
  10. import com.game.business.util.im.TencentCloudImUtil;
  11. import com.game.business.vo.AppGameItemBettingVO;
  12. import com.game.common.constant.CacheConstants;
  13. import com.game.common.constant.finance.FinTranType1;
  14. import com.game.common.constant.finance.FinTranType2;
  15. import com.game.common.constant.finance.FinTranType3;
  16. import com.game.common.core.domain.HttpRet;
  17. import com.game.common.core.redis.RedisCache;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.scheduling.annotation.Async;
  21. import org.springframework.stereotype.Component;
  22. import java.math.BigDecimal;
  23. import java.math.RoundingMode;
  24. import java.util.*;
  25. import java.util.stream.Collectors;
  26. @Component
  27. public class AppGameBettingTask {
  28. @Autowired
  29. private IAppGameBettingService appGameBettingService;
  30. @Autowired
  31. private IAppUserService appUserService;
  32. @Autowired
  33. private IFinTranRecordService finTranRecordService;
  34. @Autowired
  35. private IAppGameLotteryService appGameLotteryService;
  36. @Autowired
  37. private IAppGameService appGameService;
  38. @Autowired
  39. private IAppGameClassifyService appGameClassifyService;
  40. @Autowired
  41. private IAppGameItemService appGameItemService;
  42. @Autowired
  43. private RedisCache redisCache;
  44. @Autowired
  45. private IAppUserCountService appUserCountService;
  46. @Autowired
  47. private AppUserCountTask appUserCountTask;
  48. @Autowired
  49. private IAppGameItemMultipleService appGameItemMultipleService;
  50. @Autowired
  51. private AppGameLotteryAutoTask appGameLotteryAutoTask;
  52. @Async("asyncExecutor")
  53. public void gameDataTask(String message, String gameCodeFinal) throws Exception {
  54. JSONArray dataArry = JSONArray.parseArray(message);
  55. Integer type = null;
  56. for (int i = 0; i < dataArry.size(); i++) {
  57. JSONObject jsonObject = dataArry.getJSONObject(i);
  58. if(jsonObject.containsKey("type")){
  59. type = jsonObject.getInteger("type");
  60. break;
  61. }
  62. }
  63. if(type == null){
  64. // System.out.println("游戏socket推送类型为空。");
  65. return;
  66. }
  67. // 修改倍数
  68. if(type == 4){
  69. String gameCode = null;
  70. String gameDate = null;
  71. String gameLotteryBet = null;
  72. for (int i = 0; i < dataArry.size(); i++) {
  73. JSONObject jsonObject = dataArry.getJSONObject(i);
  74. if(jsonObject.containsKey("id")){
  75. gameCode = jsonObject.getString("id");
  76. }
  77. if(jsonObject.containsKey("gameDate")){
  78. gameDate = jsonObject.getString("gameDate");
  79. }
  80. if(jsonObject.containsKey("gameLotteryBet")){
  81. gameLotteryBet = jsonObject.getString("gameLotteryBet");
  82. }
  83. }
  84. if(StringUtils.isBlank(gameCode)){
  85. return;
  86. }
  87. if(StringUtils.isBlank(gameDate)){
  88. return;
  89. }
  90. if(StringUtils.isBlank(gameLotteryBet)){
  91. return;
  92. }
  93. AppGame appGame = appGameService.selectAppGameByCode(gameCode);
  94. if(appGame == null){
  95. return;
  96. }
  97. String redisKey = CacheConstants.GAME_LOTTERY_ITEM_MULTIPLE.concat(appGame.getId() + ":" + gameCode);
  98. if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey, 1)){
  99. return;
  100. }
  101. try {
  102. gameLotteryBet = gameLotteryBet.replace(" ", "").trim();
  103. JSONArray items = JSONArray.parseArray(gameLotteryBet);
  104. if(items == null || items.isEmpty()){
  105. return;
  106. }
  107. AppGameItem appGameItem = new AppGameItem();
  108. appGameItem.setGameId(appGame.getId());
  109. List<AppGameItem> itemList = appGameItemService.selectAppGameItemList(appGameItem);
  110. if(itemList == null || itemList.isEmpty()){
  111. return;
  112. }
  113. if(itemList.size() != items.size()){
  114. return;
  115. }
  116. AppGameItemMultiple appGameItemMultiple = appGameItemMultipleService.getAppGameItemMultiple(appGame.getId(), gameDate);
  117. if(appGameItemMultiple != null){
  118. appGameItemMultiple.setItemMultiple(gameLotteryBet.substring(1, gameLotteryBet.length() - 1));
  119. appGameItemMultipleService.updateById(appGameItemMultiple);
  120. }else{
  121. appGameItemMultiple = new AppGameItemMultiple();
  122. appGameItemMultiple.setGameId(appGame.getId());
  123. appGameItemMultiple.setGameDate(gameDate);
  124. appGameItemMultiple.setItemMultiple(gameLotteryBet.substring(1, gameLotteryBet.length() - 1));
  125. appGameItemMultipleService.save(appGameItemMultiple);
  126. }
  127. for (int j = 0; j < itemList.size(); j++) {
  128. AppGameItem gameItem = itemList.get(j);
  129. gameItem.setItemMultiple(items.getDouble(j));
  130. appGameItemService.updateAppGameItem(gameItem);
  131. }
  132. }catch (Exception e){
  133. e.printStackTrace();
  134. }finally {
  135. redisCache.redisTemplate.delete(redisKey);
  136. }
  137. return;
  138. }
  139. // 更新倒计时
  140. if(type == 1){
  141. // JSONArray gameDataArry = null;
  142. String gameCode = null;
  143. String time = null;
  144. String classCode = null;
  145. Integer state = null;
  146. for (int i = 0; i < dataArry.size(); i++) {
  147. JSONObject jsonObject = dataArry.getJSONObject(i);
  148. if(jsonObject.containsKey("data")){
  149. gameCode = jsonObject.getString("id");
  150. }
  151. if(jsonObject.containsKey("time")){
  152. time = jsonObject.getString("time");
  153. }
  154. if(jsonObject.containsKey("id")){
  155. classCode = jsonObject.getString("id");
  156. }
  157. if(jsonObject.containsKey("state")){
  158. state = jsonObject.getInteger("state");
  159. }
  160. }
  161. if(classCode == null){
  162. // System.out.println("游戏socket推送倒计时,平台ID为空。");
  163. return;
  164. }
  165. if(gameCode == null){
  166. // System.out.println("游戏socket推送倒计时,data对象为空。");
  167. return;
  168. }
  169. if(time == null || time.trim().isEmpty()){
  170. // System.out.println("游戏socket推送倒计时,time为空。");
  171. return;
  172. }
  173. if(gameCode.equals(Common.GAME_FOUR_CODE)){
  174. if(state == null || state != 0){
  175. return;
  176. }
  177. }
  178. if(gameCode.equals(Common.GAME_FIVE_CODE)){
  179. if(state == null || state != 1){
  180. return;
  181. }
  182. }
  183. AppGameClassify appGameClassify = appGameClassifyService.getByCode(classCode);
  184. if(appGameClassify == null){
  185. // System.out.println("开奖游戏平台不存在:" + classCode);
  186. return;
  187. }
  188. List<AppGame> appGameList = appGameService.selectAppGameByClassId(appGameClassify.getId());
  189. if(appGameList == null || appGameList.isEmpty()){
  190. // System.out.println("开奖游戏平台没有游戏:" + classCode);
  191. return;
  192. }
  193. Map<String, List<AppGame>> codeGameMap = appGameList.stream().collect(Collectors.groupingBy(AppGame::getCode));
  194. if(!gameCodeFinal.equals(gameCode)){
  195. return;
  196. }
  197. if(!codeGameMap.containsKey(gameCode)){
  198. // System.out.println("开奖游戏不存在:" + gameCode);
  199. return;
  200. }
  201. AppGame appGame = codeGameMap.get(gameCode).get(0);
  202. appGame.setGameTime(time);
  203. appGameService.updateAppGame(appGame);
  204. return;
  205. }
  206. JSONArray gameArry = null;
  207. String classCode = null;
  208. for (int i = 0; i < dataArry.size(); i++) {
  209. JSONObject jsonObject = dataArry.getJSONObject(i);
  210. if(jsonObject.containsKey("gameTypeSortArrayVOS")){
  211. gameArry = jsonObject.getJSONArray("gameTypeSortArrayVOS");
  212. }
  213. if(jsonObject.containsKey("id")){
  214. classCode = jsonObject.getString("id");
  215. }
  216. }
  217. if(gameArry == null){
  218. // System.out.println("游戏socket推送期号或开奖,gameTypeSortArrayVOS对象为空。");
  219. return;
  220. }
  221. if(classCode == null){
  222. // System.out.println("游戏socket推送期号或开奖,平台ID为空。");
  223. return;
  224. }
  225. AppGameClassify appGameClassify = appGameClassifyService.getByCode(classCode);
  226. if(appGameClassify == null){
  227. // System.out.println("开奖游戏平台不存在:" + classCode);
  228. return;
  229. }
  230. List<AppGame> appGameList = appGameService.selectAppGameByClassId(appGameClassify.getId());
  231. if(appGameList == null || appGameList.isEmpty()){
  232. // System.out.println("开奖游戏平台没有游戏:" + classCode);
  233. return;
  234. }
  235. Map<String, List<AppGame>> codeGameMap = appGameList.stream().collect(Collectors.groupingBy(AppGame::getCode));
  236. for (int i = 0; i < gameArry.size(); i++) {
  237. JSONObject gameLotteryObject = gameArry.getJSONObject(i);
  238. String gameCode = gameLotteryObject.getString("id");
  239. if(gameCode == null){
  240. // System.out.println("游戏socket推送期号或开奖,游戏ID为空。");
  241. continue;
  242. }
  243. if(!gameCodeFinal.equals(gameCode)){
  244. continue;
  245. }
  246. if(!codeGameMap.containsKey(gameCode)){
  247. // System.out.println("开奖游戏不存在:" + gameCode);
  248. continue;
  249. }
  250. AppGame appGame = codeGameMap.get(gameCode).get(0);
  251. String gameDate = gameLotteryObject.getString("gameDate");
  252. if(gameDate == null){
  253. // System.out.println("游戏socket推送期号或开奖,期号为空。");
  254. continue;
  255. }
  256. if(type == 3){
  257. String redisKey = CacheConstants.GAME_LOTTERY_TASK_CREATE.concat(appGame.getId() + ":" + gameCode);
  258. if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey, 1)){
  259. continue;
  260. }
  261. try {
  262. AppGameLottery appGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), gameDate);
  263. if(appGameLottery == null){
  264. appGame.setGameDate(gameDate);
  265. appGameService.updateAppGame(appGame);
  266. appGameLottery = new AppGameLottery();
  267. appGameLottery.setGameId(appGame.getId());
  268. appGameLottery.setClassId(appGame.getClassifyId());
  269. appGameLottery.setGameDate(gameDate);
  270. appGameLottery.setIsLottery(0);
  271. appGameLottery.setGameRecordDate(new Date());
  272. appGameLotteryService.save(appGameLottery);
  273. }
  274. }catch (Exception e){
  275. e.printStackTrace();
  276. }finally {
  277. redisCache.redisTemplate.delete(redisKey);
  278. }
  279. continue;
  280. }
  281. Integer isLottery = gameLotteryObject.getInteger("isLottery");
  282. String gameLotterySucc = gameLotteryObject.getString("gameLotterySucc");
  283. if(isLottery != 1){
  284. continue;
  285. }
  286. if(gameLotterySucc == null || gameLotterySucc.trim().isEmpty()){
  287. // System.out.println("游戏socket推送倒计时,time为空。");
  288. continue;
  289. }
  290. String redisKey = CacheConstants.GAME_LOTTERY_TASK.concat(appGame.getId() + ":" + gameDate);
  291. if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey, 1)){
  292. continue;
  293. }
  294. try {
  295. AppGameLottery appGameLottery = appGameLotteryService.selectLottery(appGame.getClassifyId(), appGame.getId(), gameDate);
  296. // if(gameCode.equals("6")){
  297. // gameLotterySucc = appGameLotteryAutoTask.autoTask(appGame, gameDate);
  298. // }
  299. if(appGameLottery == null){
  300. // 保存开奖记录
  301. appGameLottery = new AppGameLottery();
  302. appGameLottery.setGameId(appGame.getId());
  303. appGameLottery.setClassId(appGame.getClassifyId());
  304. appGameLottery.setGameDate(gameDate);
  305. appGameLottery.setIsLottery(isLottery);
  306. appGameLottery.setGameRecordDate(new Date());
  307. appGameLottery.setGameLotterySucc(gameLotterySucc);
  308. appGameLotteryService.save(appGameLottery);
  309. }else{
  310. if(appGameLottery.getIsLottery() == 1){
  311. // redisCache.redisTemplate.delete(redisKey);
  312. // System.out.println("游戏socket推送开奖,当前期已开过将,游戏编码:" + gameCode + ",期号:" + gameDate);
  313. continue;
  314. }
  315. AppGameLottery updateAppGameLottery = new AppGameLottery();
  316. updateAppGameLottery.setId(appGameLottery.getId());
  317. updateAppGameLottery.setIsLottery(isLottery);
  318. updateAppGameLottery.setGameRecordDate(new Date());
  319. updateAppGameLottery.setGameLotterySucc(gameLotterySucc);
  320. appGameLotteryService.updateById(updateAppGameLottery);
  321. }
  322. lotteryTask(appGame, appGameClassify, gameLotterySucc, gameDate);
  323. }catch (Exception e){
  324. e.printStackTrace();
  325. }finally {
  326. redisCache.redisTemplate.delete(redisKey);
  327. }
  328. }
  329. }
  330. public void lotteryTask(AppGame appGame, AppGameClassify appGameClassify, String gameLotterySucc, String gameDate) throws Exception {
  331. this.updateItme(appGame.getId(), gameLotterySucc);
  332. List<String> userIds = this.gameBettingTask(appGameClassify.getId(), appGame.getId(), gameDate, gameLotterySucc);
  333. appUserCountService.staticsUserCount(appGame.getId(),null, appGame.getGameDate());
  334. // 给中奖人发送刷新余额通知
  335. sendMsg(userIds);
  336. //更新可提现余额
  337. for(String userId : userIds) {
  338. appUserCountTask.updateWithdrawAble(Long.parseLong(userId));
  339. }
  340. }
  341. public void updateItme(Long gameId, String gameLotterySucc){
  342. // 获取上次开奖结果
  343. List<AppItemCountDTO> itemCountList = new ArrayList<>();
  344. String gameLotterySuccCache = redisCache.getCacheObject("G:GameCount:" + gameId);
  345. if(gameLotterySuccCache != null && !gameLotterySuccCache.trim().isEmpty()){
  346. itemCountList = JSONArray.parseArray(gameLotterySuccCache, AppItemCountDTO.class);
  347. }
  348. // 修改游戏选项
  349. String [] bettingItems = gameLotterySucc.split(",");
  350. List<AppItemCountDTO> nowItemCountList = new ArrayList<>();
  351. for(int j = 0; j < bettingItems.length; j++) {
  352. String bettingItemStr = bettingItems[j];
  353. AppItemCountDTO appItemCountDTO = new AppItemCountDTO();
  354. appItemCountDTO.setGameId(gameId);
  355. appItemCountDTO.setItemLocation(bettingItemStr);
  356. appItemCountDTO.setConsecutive(1);
  357. AppGameItem appGameItem = new AppGameItem();
  358. appGameItem.setGameId(gameId);
  359. appGameItem.setItemLocation(bettingItemStr);
  360. // 开奖次数
  361. appGameItemService.updateLotteryCount(appGameItem);
  362. if(!itemCountList.isEmpty()){
  363. for (AppItemCountDTO appItemCount : itemCountList){
  364. if(appItemCount.getItemLocation().equals(bettingItemStr)){
  365. appItemCountDTO.setConsecutive(appItemCount.getConsecutive() + 1);
  366. }
  367. }
  368. }
  369. // 更新连中
  370. appGameItemService.updateConsecutive(appItemCountDTO);
  371. nowItemCountList.add(appItemCountDTO);
  372. }
  373. redisCache.setCacheObject("G:GameCount:" + gameId, JSON.toJSONString(nowItemCountList));
  374. }
  375. @DSTransactional
  376. public List<String> gameBettingTask(Long classId, Long gameId, String gameDate, String bettingItem) throws Exception {
  377. List<String> userIds = new ArrayList<>();
  378. List<AppGameBetting> list = appGameBettingService.getIsWinning(classId, gameId, gameDate, 0);
  379. if(list == null || list.isEmpty()){
  380. return userIds;
  381. }
  382. for (int i = 0; i < list.size(); i++) {
  383. AppGameBetting appGameBetting = list.get(i);
  384. appGameBetting.setUpdateTime(new Date());
  385. String [] bettingItems = bettingItem.split(",");
  386. List<String> bettingItemsList = Arrays.asList(bettingItems);
  387. double bettingAmount = appGameBetting.getBettingAmount() * appGameBetting.getBettingMultiple();
  388. bettingAmount = new BigDecimal(bettingAmount + "").setScale(4, RoundingMode.DOWN).doubleValue();
  389. if(appGameBetting.getBettingGameType() == 0){
  390. if(!bettingItemsList.contains(appGameBetting.getBettingItem())){
  391. appGameBetting.setIsWinning(2);
  392. appGameBettingService.updateById(appGameBetting);
  393. continue;
  394. }
  395. }else if(appGameBetting.getBettingGameType() == 1 || appGameBetting.getBettingGameType() == 2){
  396. List<AppGameItemBettingVO> itemList = JSON.parseArray(appGameBetting.getBettingItem(), AppGameItemBettingVO.class);
  397. if(itemList == null || itemList.isEmpty()){
  398. appGameBetting.setIsWinning(2);
  399. appGameBettingService.updateById(appGameBetting);
  400. continue;
  401. }
  402. List<String> bettingItemList = itemList.stream().map(AppGameItemBettingVO::getBettingItem).collect(Collectors.toList());
  403. boolean isWinning = false;
  404. for (int j = 0; j < bettingItemList.size(); j++) {
  405. String bettingItemStr = bettingItemList.get(j);
  406. if(bettingItemsList.contains(bettingItemStr)){
  407. isWinning = true;
  408. break;
  409. }
  410. }
  411. if(!isWinning){
  412. appGameBetting.setIsWinning(2);
  413. appGameBettingService.updateById(appGameBetting);
  414. continue;
  415. }
  416. if(appGameBetting.getBettingGameType() == 2){
  417. for (int k = 0; k < itemList.size(); k++) {
  418. AppGameItemBettingVO appGameItemBettingVO = itemList.get(k);
  419. if(bettingItemsList.contains(appGameItemBettingVO.getBettingItem())){
  420. bettingAmount = appGameBetting.getBettingAmount() * appGameItemBettingVO.getBettingMultiple();
  421. bettingAmount = new BigDecimal(bettingAmount + "").setScale(4, RoundingMode.DOWN).doubleValue();
  422. break;
  423. }
  424. }
  425. }
  426. }
  427. AppUser appUser = appUserService.selectAppUserByUserid(appGameBetting.getUserId());
  428. if(appUser == null){
  429. appGameBetting.setIsWinning(1);
  430. appGameBettingService.updateById(appGameBetting);
  431. continue;
  432. }
  433. // 添加推送消息用户
  434. String userId = appUser.getUserid() + "";
  435. if(!userIds.contains(userId)){
  436. userIds.add(userId);
  437. }
  438. // 更新用户余额
  439. //if(appGameBetting.getBettingType() == 0){
  440. // appUser.setDiamondCoin(appUser.getDiamondCoin() + bettingAmount );
  441. // appUser.setDiamondCoinTotal(appUser.getDiamondCoinCashTotal() + bettingAmount);
  442. // appUser.setDiamondCoinCash(appUser.getDiamondCoinCash() + bettingAmount);
  443. // 更新用户金币
  444. //}else{
  445. // appUser.setCoin(appUser.getCoin() + bettingAmount);
  446. // if(appUser.getRole() == 1){
  447. // appUser.setCoinCash(appUser.getCoinCash() + bettingAmount);
  448. // }
  449. //}
  450. //appUserService.updateAppUser(appUser);
  451. //redisCache.deleteObject("U:UserInfo:" + appUser.getUserid());
  452. appGameBetting.setIsWinning(1);
  453. appGameBettingService.updateById(appGameBetting);
  454. FinTranRecord finTranRecord = new FinTranRecord();
  455. //finTranRecord.setAfterCoin(appUser.getCoin());
  456. //finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
  457. if(appGameBetting.getBettingType() == 0){
  458. finTranRecord.setCurrencyType(4);
  459. finTranRecord.setDiamondCoinChange(bettingAmount);
  460. finTranRecord.setCoinChange(0.00);
  461. }else{
  462. finTranRecord.setCurrencyType(2);
  463. finTranRecord.setCoinChange(bettingAmount);
  464. finTranRecord.setDiamondCoinChange(0.00);
  465. }
  466. finTranRecord.setAfterMoney(0.00);
  467. finTranRecord.setMoneyChange(0.00);
  468. finTranRecord.setAfterTicket(0.00);
  469. finTranRecord.setTicketChange(0.00);
  470. finTranRecord.setToUid(appUser.getUserid());
  471. finTranRecord.setUid(appUser.getUserid());
  472. finTranRecord.setSceneId1(0L);
  473. finTranRecord.setSceneId2(null);
  474. finTranRecord.setSceneType(0L);
  475. finTranRecord.setTranGroupId(appGameBetting.getId());
  476. if(appGameBetting.getBettingType() == 0){
  477. finTranRecord.setTranType1(FinTranType1.U_Income_Coin_Balance.getType());
  478. }else{
  479. finTranRecord.setTranType1(FinTranType1.U_Income_Coin.getType());
  480. }
  481. finTranRecord.setTranType2(FinTranType2.GAME_REWARD.getType());
  482. finTranRecord.setTranType3(FinTranType3.CHARGE_WIN_GAME.getType());
  483. finTranRecord.setRemarks(gameDate + "期,游戏中奖");
  484. finTranRecord.setConsumptionCoin(appGameBetting.getBettingAmount());
  485. finTranRecord.setConsumptionMoney(0.00);
  486. finTranRecord.setCommissionRelatedUid(0L);
  487. finTranRecord.setAgentId(appUser.getAgentId());
  488. finTranRecord.setCreateTime(new Date());
  489. finTranRecord.setFromUid(appGameBetting.getUserId());
  490. finTranRecord.setGoodsId(0L);
  491. finTranRecord.setGuildId(0L);
  492. finTranRecord.setManagerCoId(0L);
  493. finTranRecord.setManagerId(0L);
  494. finTranRecord.setPerc(0.00);
  495. finTranRecord.setProId(0L);
  496. finTranRecord.setProCount(0L);
  497. finTranRecord.setOrderId(appGameBetting.getId());
  498. //finTranRecordService.insertFinTranRecord(finTranRecord);
  499. appUserService.updateUserAmount(finTranRecord,false);
  500. }
  501. return userIds;
  502. }
  503. public void sendMsg(List<String> userIdList){
  504. if(userIdList == null || userIdList.isEmpty()){
  505. return;
  506. }
  507. JSONObject paramJson = new JSONObject();
  508. paramJson.put("type", "UserSystemNotify");
  509. paramJson.put("subType", "UserRefreshBalance");
  510. paramJson.put("content", JSONObject.parseObject("{'msg':'刷新余额'}"));
  511. List<String> sendUsers = new ArrayList<>();
  512. if(userIdList.size() > 500){
  513. for(String userId : userIdList){
  514. if(sendUsers.size() >= 500){
  515. TencentCloudImUtil.imPushBatchSendMsg(sendUsers, paramJson.toString());
  516. sendUsers.clear();
  517. }
  518. sendUsers.add(userId);
  519. }
  520. // 剩余不超过500
  521. if(!sendUsers.isEmpty()){
  522. TencentCloudImUtil.imPushBatchSendMsg(sendUsers, paramJson.toString());
  523. }
  524. }else{
  525. TencentCloudImUtil.imPushBatchSendMsg(userIdList, paramJson.toString());
  526. }
  527. }
  528. }