| @@ -32,21 +32,17 @@ public class WxGameController extends BaseController { | |||||
| @ApiOperation("蒙层/游戏入口获取游戏信息") | @ApiOperation("蒙层/游戏入口获取游戏信息") | ||||
| @GetMapping("getOne") | @GetMapping("getOne") | ||||
| public ResultData getOne() { | |||||
| WxGame wxGame = new WxGame(); | |||||
| public ResultData getOne(@ModelAttribute WxGame wxGame) { | |||||
| if (wxGame == null) wxGame = new WxGame(); | |||||
| wxGame.setTenantId(getTenantId()); | wxGame.setTenantId(getTenantId()); | ||||
| wxGame.setStatus(EnumGameStatus.STATUS_THROW_IN.getCode()); | wxGame.setStatus(EnumGameStatus.STATUS_THROW_IN.getCode()); | ||||
| // 因为有算法要求,分成两步获取 | // 因为有算法要求,分成两步获取 | ||||
| WxGame wxGame1 = wxGameService.getOne(wxGame); | |||||
| if (wxGame1 != null) { | |||||
| WxGameTemplate gameTemplate = wxGameTemplateService.getById(wxGame1.getGameId()); | |||||
| if (gameTemplate != null) { | |||||
| wxGame1.setGameTemplate(gameTemplate); | |||||
| return new ResultData(wxGame1); | |||||
| } | |||||
| WxGame record = wxGameService.getOne(wxGame); | |||||
| if (record == null) { | |||||
| return new ResultData(ErrorCode.GAME_NOT_FOUND); | |||||
| } | } | ||||
| return new ResultData(ErrorCode.GAME_NOT_FOUND); | |||||
| return new ResultData(record); | |||||
| } | } | ||||
| } | } | ||||
| @@ -59,24 +59,26 @@ public class WxGameServiceImpl implements WxGameService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxGame getOne(WxGame record) { | |||||
| WxGame wxGame = null; | |||||
| public WxGame getOne(WxGame wxGame) { | |||||
| WxGame record = null; | |||||
| // get game's count | // get game's count | ||||
| int countOfGame = wxGameMapper.selectCount(record); | |||||
| int countOfGame = wxGameMapper.selectCount(wxGame); | |||||
| if (countOfGame == 1){ | if (countOfGame == 1){ | ||||
| wxGame = wxGameMapper.selectOne(record); | |||||
| record = wxGameMapper.selectOne(wxGame); | |||||
| } else if (countOfGame > 1){ | } else if (countOfGame > 1){ | ||||
| // random | // random | ||||
| int pageNum = (int)(1+Math.random()*(countOfGame-1+1)); | int pageNum = (int)(1+Math.random()*(countOfGame-1+1)); | ||||
| PageInfo<WxGame> gamePageInfo = PageHelper.startPage(pageNum, 1).doSelectPageInfo(() -> wxGameMapper.findList(record)); | |||||
| wxGame = gamePageInfo.getList().get(0); | |||||
| PageInfo<WxGame> gamePageInfo = | |||||
| PageHelper.startPage(pageNum, 1).doSelectPageInfo(() -> wxGameMapper.findList(wxGame)); | |||||
| record = gamePageInfo.getList().get(0); | |||||
| } | } | ||||
| if (wxGame != null) { | |||||
| wxGame.setCouponIdsList(getParams(wxGame)); | |||||
| return wxGame; | |||||
| if (record != null) { | |||||
| record.setGameTemplate(wxGameTemplateService.getById(record.getGameId())); | |||||
| record.setCouponIdsList(getParams(record)); | |||||
| } | } | ||||
| return null; | |||||
| return record; | |||||
| } | } | ||||
| private List<Object> getParams(WxGame record) { | private List<Object> getParams(WxGame record) { | ||||
| @@ -6,13 +6,14 @@ | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | ||||
| <result column="game_id" jdbcType="INTEGER" property="gameId" /> | <result column="game_id" jdbcType="INTEGER" property="gameId" /> | ||||
| <result column="status" jdbcType="INTEGER" property="status" /> | <result column="status" jdbcType="INTEGER" property="status" /> | ||||
| <result column="coupon_ids" jdbcType="VARCHAR" property="couponIds" /> | |||||
| <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate" /> | <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate" /> | ||||
| <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate" /> | <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate" /> | ||||
| <result column="triggle_action" jdbcType="INTEGER" property="triggleAction" /> | <result column="triggle_action" jdbcType="INTEGER" property="triggleAction" /> | ||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`game_id`,`status`,`valid_start_date`,`valid_end_date`,`triggle_action` | |||||
| `id`,`tenant_id`,`game_id`,`status`,`coupon_ids`,`valid_start_date`,`valid_end_date`,`triggle_action` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||