5 changed files with 98 additions and 2 deletions
@ -1,9 +1,65 @@ |
|||
package com.ccsens.game.service; |
|||
|
|||
import cn.hutool.core.collection.CollectionUtil; |
|||
import com.ccsens.game.bean.dto.ClientDto; |
|||
import com.ccsens.game.bean.po.GameMemberJoin; |
|||
import com.ccsens.game.bean.po.GameMemberJoinExample; |
|||
import com.ccsens.game.bean.po.GameRecord; |
|||
import com.ccsens.game.bean.vo.ClientVo; |
|||
import com.ccsens.game.persist.dao.GameMemberJoinDao; |
|||
import com.ccsens.game.persist.dao.GameRecordDao; |
|||
import com.ccsens.game.util.GameConstant; |
|||
import com.ccsens.util.CodeEnum; |
|||
import com.ccsens.util.exception.BaseException; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Propagation; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: wuHuiJuan |
|||
* @create: 2019/12/26 15:01 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|||
public class ClientService implements IClientService { |
|||
|
|||
@Autowired |
|||
private GameMemberJoinDao gameMemberJoinDao; |
|||
@Autowired |
|||
private GameRecordDao gameRecordDao; |
|||
|
|||
@Override |
|||
public ClientVo.Join join(ClientDto.Join join, Long userId) { |
|||
log.info("加入游戏:{}, userId:{}", join, userId); |
|||
ClientVo.Join joinVo = new ClientVo.Join(); |
|||
//根据游戏ID和用户ID查询用户是否加入
|
|||
GameMemberJoinExample example = new GameMemberJoinExample(); |
|||
example.createCriteria().andRecordIdEqualTo(join.getUrlId()).andMemberIdEqualTo(userId); |
|||
List<GameMemberJoin> gameMemberJoins = gameMemberJoinDao.selectByExample(example); |
|||
if (CollectionUtil.isNotEmpty(gameMemberJoins)) { |
|||
Long localStartTime = gameMemberJoins.get(0).getLocalStartTime(); |
|||
log.info("用户已加入该游戏,直接返回开始时间{}", localStartTime); |
|||
joinVo.setStartLocalTime(localStartTime); |
|||
return joinVo; |
|||
} |
|||
//获取游戏信息
|
|||
GameRecord gameRecord = gameRecordDao.selectByPrimaryKey(join.getUrlId()); |
|||
log.info("游戏信息:{}", gameRecord); |
|||
if (gameRecord == null) { |
|||
log.info("未找到游戏信息"); |
|||
throw new BaseException(CodeEnum.PARAM_ERROR); |
|||
} |
|||
|
|||
//判断游戏状态
|
|||
gameRecord.getGameStatus().byteValue() == GameConstant.GAME_END |
|||
|
|||
|
|||
return null; |
|||
} |
|||
} |
|||
|
@ -0,0 +1,21 @@ |
|||
package com.ccsens.game.util; |
|||
|
|||
/** |
|||
* @description: |
|||
* @author: wuHuiJuan |
|||
* @create: 2019/12/26 17:32 |
|||
*/ |
|||
public class GameConstant { |
|||
|
|||
/**游戏状态:未开始*/ |
|||
public static final byte GAME_NO_START = 0; |
|||
/**游戏状态:准备中*/ |
|||
public static final byte GAME_PREPARATION = 1; |
|||
/**游戏状态:进行中*/ |
|||
public static final byte GAME_STARTED = 2; |
|||
/**游戏状态:已结束*/ |
|||
public static final byte GAME_END = 3; |
|||
|
|||
|
|||
|
|||
} |
Loading…
Reference in new issue