| | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.enumerates.*; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.MallUtils; |
| | | import cc.mrbird.febs.common.utils.ShareCodeUtil; |
| | | import cc.mrbird.febs.common.utils.*; |
| | | import cc.mrbird.febs.mall.dto.*; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | | import cc.mrbird.febs.mall.service.IMallMoneyFlowService; |
| | | import cc.mrbird.febs.mall.vo.*; |
| | | import cc.mrbird.febs.websocket.WebSocketRes; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | Integer partner = ObjectUtil.isEmpty(mallMember.getPartner()) ? 2 : mallMember.getPartner(); |
| | | if(AppContants.MEMBER_PARTNER_NO == partner){ |
| | | throw new FebsException("用户没有创建房间的权限!"); |
| | | } |
| | | |
| | | QueryWrapper<GameRoom> gameRoomQuery = new QueryWrapper<>(); |
| | | gameRoomQuery.eq("owner_member_id",memberId); |
| | | gameRoomQuery.ne("state",GameRoom.STATE_DONE); |
| | | List<GameRoom> gameRoomsExists = gameRoomMapper.selectList(gameRoomQuery); |
| | | if(CollUtil.isNotEmpty(gameRoomsExists)){ |
| | | throw new FebsException("房间已创建!房间码为:"+gameRoomsExists.get(0).getPassword()); |
| | | } |
| | | |
| | | Integer roomType = apiCreateRoomDto.getRoomType(); |
| | |
| | | /** |
| | | * 给房间里面的所有人发送一个开始的信息 |
| | | */ |
| | | this.sendMsgByRoomId(roomId,"START:"+gameGame.getId()); |
| | | WebSocketRes webSocketRes = new WebSocketRes(); |
| | | webSocketRes.setCode(200); |
| | | webSocketRes.setMsg(gameGame.getId().toString()); |
| | | this.sendMsgByRoomId(roomId, JSONUtil.parse(webSocketRes).toString()); |
| | | |
| | | ApiStartGameVo apiStartGameVo = new ApiStartGameVo(); |
| | | apiStartGameVo.setRoomType(gameRoom.getRoomType()); |
| | |
| | | /** |
| | | * 给房间里面的所有人发送一个开始的信息 |
| | | */ |
| | | this.sendMsgByRoomId(roomId,"TZ:"+gameGame.getId()); |
| | | |
| | | |
| | | WebSocketRes webSocketRes = new WebSocketRes(); |
| | | webSocketRes.setCode(200); |
| | | webSocketRes.setMsg(gameId.toString()); |
| | | this.sendMsgByRoomId(roomId, JSONUtil.parse(webSocketRes).toString()); |
| | | // this.sendMsgByRoomId(roomId,"TZ:"+gameGame.getId()); |
| | | |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | |
| | | if(GameRoom.STATE_DONE == gameRoom.getState()){ |
| | | throw new FebsException("房间已失效"); |
| | | } |
| | | |
| | | QueryWrapper<GameRoomChild> roomChildQueryWrapper = new QueryWrapper<>(); |
| | | roomChildQueryWrapper.eq("member_id",memberId); |
| | | List<GameRoomChild> roomChildExists = gameRoomChildMapper.selectList(roomChildQueryWrapper); |
| | | if(CollUtil.isNotEmpty(roomChildExists)){ |
| | | List<Long> roomIds = roomChildExists.stream().map(GameRoomChild::getRoomId).collect(Collectors.toList()); |
| | | |
| | | QueryWrapper<GameRoom> roomQuery = new QueryWrapper<>(); |
| | | roomQuery.in("id",roomIds); |
| | | List<GameRoom> gameRooms = gameRoomMapper.selectList(roomQuery); |
| | | List<GameRoom> collect = gameRooms.stream().filter(room -> room.getState() != GameRoom.STATE_DONE).collect(Collectors.toList()); |
| | | if(CollUtil.isNotEmpty(collect)){ |
| | | if(collect.size() > 1){ |
| | | throw new FebsException("请回到房间,房间码:"+collect.get(0).getPassword()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | ApiGamePlayerVo apiGamePlayerVo = new ApiGamePlayerVo(); |
| | | |
| | |
| | | apiGamePlayerVo.setPassword(gameRoom.getPassword()); |
| | | apiGamePlayerVo.setState(gameRoom.getState()); |
| | | apiGamePlayerVo.setGameTime(gameRoom.getGameTime()); |
| | | |
| | | Long ownerMemberId = gameRoom.getOwnerMemberId(); |
| | | MallMember mallMember = mallMemberMapper.selectById(ownerMemberId); |
| | | apiGamePlayerVo.setRoomOwner(mallMember.getAccountLogin()); |
| | | |
| | | QueryWrapper<GameGame> gameGameQueryWrapper = new QueryWrapper<>(); |
| | | gameGameQueryWrapper.eq("room_id",gameRoom.getId()); |
| | |
| | | //结算 todo 改成rabbitMq消息推送,注意游戏主表的状态变化 |
| | | this.perkGameGameChild(gameId,firstNum,secondNum); |
| | | |
| | | this.sendMsgByRoomId(roomId,"DONE:"+gameId); |
| | | WebSocketRes webSocketRes = new WebSocketRes(); |
| | | webSocketRes.setCode(200); |
| | | webSocketRes.setMsg(gameId.toString()); |
| | | this.sendMsgByRoomId(roomId, JSONUtil.parse(webSocketRes).toString()); |
| | | // this.sendMsgByRoomId(roomId,"DONE:"+gameId); |
| | | |
| | | ApiEndGameVo apiEndGameVo = new ApiEndGameVo(); |
| | | apiEndGameVo.setRoomId(roomId); |
| | |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | Long roomId = apiExistGameDto.getRoomId(); |
| | | /** |
| | | * 删除房间子表的数据 |
| | | * 更新房间子表的数据 |
| | | */ |
| | | MallMember mallMember = mallMemberMapper.selectById(memberId); |
| | | QueryWrapper<GameRoomChild> gameRoomChildQueryWrapper = new QueryWrapper<>(); |
| | |
| | | gameRoom.setState(GameRoom.STATE_DONE); |
| | | gameRoomMapper.updateById(gameRoom); |
| | | |
| | | this.sendMsgByRoomId(roomId,"OVER"); |
| | | WebSocketRes webSocketRes = new WebSocketRes(); |
| | | webSocketRes.setCode(200); |
| | | webSocketRes.setMsg("OVER"); |
| | | this.sendMsgByRoomId(roomId, JSONUtil.parse(webSocketRes).toString()); |
| | | // this.sendMsgByRoomId(roomId,"OVER"); |
| | | } |
| | | } |
| | | //断开websocket |
| | | WsSessionManager.remove(mallMember.getInviteId()); |
| | | WsSessionManager.removeAndClose(mallMember.getInviteId()); |
| | | |
| | | return new FebsResponse().success(); |
| | | } |