Browse Source

游戏记录与任务关联

master
zhangye 5 years ago
parent
commit
cab8876cf7
  1. 10
      game/src/main/java/com/ccsens/game/api/ClientController.java
  2. 2
      game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java
  3. 11
      game/src/main/java/com/ccsens/game/bean/po/GameRecord.java
  4. 60
      game/src/main/java/com/ccsens/game/bean/po/GameRecordExample.java
  5. 9
      game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java
  6. 2
      game/src/main/java/com/ccsens/game/service/IScreenService.java
  7. 39
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  8. 4
      game/src/main/resources/application.yml
  9. 37
      game/src/main/resources/mapper_raw/GameRecordMapper.xml
  10. 4
      game/src/main/resources/mbg.xml

10
game/src/main/java/com/ccsens/game/api/ClientController.java

@ -91,4 +91,14 @@ public class ClientController {
List<ScreenVo.Group> groupList = screenService.getGroupByRecordId(recordId);
return JsonResponse.newInstance().ok(groupList);
}
@ApiOperation(value = "根据任务id获取游戏记录id", notes = "")
@ApiImplicitParams({
})
@RequestMapping(value = "task", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
public JsonResponse<ScreenVo.RecordInfo> getRecordByTaskId(@ApiParam @RequestParam Long taskId) throws Exception {
log.info("根据游戏id获取分组信息:{}",taskId);
ScreenVo.RecordInfo recordInfo = screenService.getRecordByTaskId(taskId);
return JsonResponse.newInstance().ok(recordInfo);
}
}

2
game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java

@ -17,6 +17,8 @@ public class ScreenDto {
@NotNull
@ApiModelProperty("要创建的小游戏的类型 例如:SQ:数钱 SP:赛跑 BH:拔河")
private String gameType;
@ApiModelProperty("任务id")
private Long taskId;
@ApiModelProperty("队名1")
private String firstTeam = "红队";
@ApiModelProperty("队名2")

11
game/src/main/java/com/ccsens/game/bean/po/GameRecord.java

@ -8,6 +8,8 @@ public class GameRecord implements Serializable {
private Long userPayId;
private Long taskId;
private String url;
private String qrCodeUrl;
@ -44,6 +46,14 @@ public class GameRecord implements Serializable {
this.userPayId = userPayId;
}
public Long getTaskId() {
return taskId;
}
public void setTaskId(Long taskId) {
this.taskId = taskId;
}
public String getUrl() {
return url;
}
@ -124,6 +134,7 @@ public class GameRecord implements Serializable {
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", userPayId=").append(userPayId);
sb.append(", taskId=").append(taskId);
sb.append(", url=").append(url);
sb.append(", qrCodeUrl=").append(qrCodeUrl);
sb.append(", timeDifference=").append(timeDifference);

60
game/src/main/java/com/ccsens/game/bean/po/GameRecordExample.java

@ -225,6 +225,66 @@ public class GameRecordExample {
return (Criteria) this;
}
public Criteria andTaskIdIsNull() {
addCriterion("task_id is null");
return (Criteria) this;
}
public Criteria andTaskIdIsNotNull() {
addCriterion("task_id is not null");
return (Criteria) this;
}
public Criteria andTaskIdEqualTo(Long value) {
addCriterion("task_id =", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotEqualTo(Long value) {
addCriterion("task_id <>", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdGreaterThan(Long value) {
addCriterion("task_id >", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdGreaterThanOrEqualTo(Long value) {
addCriterion("task_id >=", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdLessThan(Long value) {
addCriterion("task_id <", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdLessThanOrEqualTo(Long value) {
addCriterion("task_id <=", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdIn(List<Long> values) {
addCriterion("task_id in", values, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotIn(List<Long> values) {
addCriterion("task_id not in", values, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdBetween(Long value1, Long value2) {
addCriterion("task_id between", value1, value2, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotBetween(Long value1, Long value2) {
addCriterion("task_id not between", value1, value2, "taskId");
return (Criteria) this;
}
public Criteria andUrlIsNull() {
addCriterion("url is null");
return (Criteria) this;

9
game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java

@ -154,4 +154,13 @@ public class ScreenVo {
private int totalMembers;
}
@Data
@ApiModel("分组的信息")
public static class RecordInfo{
@ApiModelProperty("游戏记录id")
private Long id;
@ApiModelProperty("游戏状态 0未开始 1准备中 2进行中 3已结束")
private Byte gameStatus;
}
}

2
game/src/main/java/com/ccsens/game/service/IScreenService.java

@ -39,4 +39,6 @@ public interface IScreenService {
Long getGameTypeId(Long recordId);
List<ScreenVo.Group> getGroupByRecordId(Long recordId);
ScreenVo.RecordInfo getRecordByTaskId(Long taskId);
}

39
game/src/main/java/com/ccsens/game/service/ScreenService.java

@ -108,26 +108,38 @@ public class ScreenService implements IScreenService{
gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600*24*30));
gameUserPayDao.insertSelective(gameUserPay);
}
//查询该任务下的游戏记录信息
GameRecordExample recordExample = new GameRecordExample();
recordExample.createCriteria().andTaskIdEqualTo(memberGame.getTaskId());
recordExample.setOrderByClause("created_at DESC");
List<GameRecord> recordList = gameRecordDao.selectByExample(recordExample);
if(CollectionUtil.isNotEmpty(recordList)){
GameRecord record = recordList.get(0);
if(record.getGameStatus() != GameConstant.GAME_COMPLETED){
throw new BaseException(CodeEnum.GAME_NO_END);
}
}
//3、根据用户购买的记录,添加一场新的游戏记录
GameRecord gameRecord = new GameRecord();
gameRecord.setId(snowflake.nextId());
gameRecord.setUserPayId(gameUserPay.getId());
gameRecord.setTaskId(memberGame.getTaskId());
gameRecord.setUrl(WebConstant.TEST_URL_GAME + gameType.getScreenUrl() + "?id="+gameRecord.getId());
gameRecord.setQrCodeUrl(WebConstant.TEST_URL_GAME + gameRecord.getId() + File.separator + gameType.getClientUrl());
gameRecordDao.insertSelective(gameRecord);
//4、 判断是否有分组,如果是分组游戏,添加两条分组信息
if(gameType.getIsGroup() == 1){
GameGroup gameGroupBlue = new GameGroup();
gameGroupBlue.setId(snowflake.nextId());
gameGroupBlue.setRecordId(gameRecord.getId());
gameGroupBlue.setName("蓝队");
gameGroupDao.insertSelective(gameGroupBlue);
GameGroup gameGroupRed = new GameGroup();
gameGroupRed.setId(snowflake.nextId());
gameGroupRed.setRecordId(gameRecord.getId());
gameGroupRed.setName("红队");
gameGroupRed.setName(memberGame.getFirstTeam());
gameGroupDao.insertSelective(gameGroupRed);
GameGroup gameGroupBlue = new GameGroup();
gameGroupBlue.setId(snowflake.nextId());
gameGroupBlue.setRecordId(gameRecord.getId());
gameGroupBlue.setName(memberGame.getFirstTeam());
gameGroupDao.insertSelective(gameGroupBlue);
}
//5、查询该游戏的规则
@ -849,4 +861,19 @@ public class ScreenService implements IScreenService{
}
return groupList;
}
@Override
public ScreenVo.RecordInfo getRecordByTaskId(Long taskId) {
ScreenVo.RecordInfo recordInfo = new ScreenVo.RecordInfo();
GameRecordExample recordExample = new GameRecordExample();
recordExample.createCriteria().andTaskIdEqualTo(taskId);
recordExample.setOrderByClause("created_at DESC");
List<GameRecord> gameRecordList = gameRecordDao.selectByExample(recordExample);
if(CollectionUtil.isNotEmpty(gameRecordList)){
recordInfo.setId(gameRecordList.get(0).getId());
recordInfo.setGameStatus(gameRecordList.get(0).getGameStatus());
}
return recordInfo;
}
}

4
game/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: test
include: common, util-test
active: dev
include: common, util-dev

37
game/src/main/resources/mapper_raw/GameRecordMapper.xml

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="com.ccsens.game.bean.po.GameRecord">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="user_pay_id" jdbcType="BIGINT" property="userPayId" />
<result column="task_id" jdbcType="BIGINT" property="taskId" />
<result column="url" jdbcType="VARCHAR" property="url" />
<result column="QR_code_url" jdbcType="VARCHAR" property="qrCodeUrl" />
<result column="time_difference" jdbcType="INTEGER" property="timeDifference" />
@ -73,8 +74,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, user_pay_id, url, QR_code_url, time_difference, start_time, end_time, game_status,
created_at, updated_at, rec_status
id, user_pay_id, task_id, url, QR_code_url, time_difference, start_time, end_time,
game_status, created_at, updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.game.bean.po.GameRecordExample" resultMap="BaseResultMap">
select
@ -107,14 +108,16 @@
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.game.bean.po.GameRecord">
insert into t_game_record (id, user_pay_id, url,
QR_code_url, time_difference, start_time,
end_time, game_status, created_at,
updated_at, rec_status)
values (#{id,jdbcType=BIGINT}, #{userPayId,jdbcType=BIGINT}, #{url,jdbcType=VARCHAR},
#{qrCodeUrl,jdbcType=VARCHAR}, #{timeDifference,jdbcType=INTEGER}, #{startTime,jdbcType=BIGINT},
#{endTime,jdbcType=BIGINT}, #{gameStatus,jdbcType=TINYINT}, #{createdAt,jdbcType=TIMESTAMP},
#{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT})
insert into t_game_record (id, user_pay_id, task_id,
url, QR_code_url, time_difference,
start_time, end_time, game_status,
created_at, updated_at, rec_status
)
values (#{id,jdbcType=BIGINT}, #{userPayId,jdbcType=BIGINT}, #{taskId,jdbcType=BIGINT},
#{url,jdbcType=VARCHAR}, #{qrCodeUrl,jdbcType=VARCHAR}, #{timeDifference,jdbcType=INTEGER},
#{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT}, #{gameStatus,jdbcType=TINYINT},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
)
</insert>
<insert id="insertSelective" parameterType="com.ccsens.game.bean.po.GameRecord">
insert into t_game_record
@ -125,6 +128,9 @@
<if test="userPayId != null">
user_pay_id,
</if>
<if test="taskId != null">
task_id,
</if>
<if test="url != null">
url,
</if>
@ -160,6 +166,9 @@
<if test="userPayId != null">
#{userPayId,jdbcType=BIGINT},
</if>
<if test="taskId != null">
#{taskId,jdbcType=BIGINT},
</if>
<if test="url != null">
#{url,jdbcType=VARCHAR},
</if>
@ -204,6 +213,9 @@
<if test="record.userPayId != null">
user_pay_id = #{record.userPayId,jdbcType=BIGINT},
</if>
<if test="record.taskId != null">
task_id = #{record.taskId,jdbcType=BIGINT},
</if>
<if test="record.url != null">
url = #{record.url,jdbcType=VARCHAR},
</if>
@ -240,6 +252,7 @@
update t_game_record
set id = #{record.id,jdbcType=BIGINT},
user_pay_id = #{record.userPayId,jdbcType=BIGINT},
task_id = #{record.taskId,jdbcType=BIGINT},
url = #{record.url,jdbcType=VARCHAR},
QR_code_url = #{record.qrCodeUrl,jdbcType=VARCHAR},
time_difference = #{record.timeDifference,jdbcType=INTEGER},
@ -259,6 +272,9 @@
<if test="userPayId != null">
user_pay_id = #{userPayId,jdbcType=BIGINT},
</if>
<if test="taskId != null">
task_id = #{taskId,jdbcType=BIGINT},
</if>
<if test="url != null">
url = #{url,jdbcType=VARCHAR},
</if>
@ -292,6 +308,7 @@
<update id="updateByPrimaryKey" parameterType="com.ccsens.game.bean.po.GameRecord">
update t_game_record
set user_pay_id = #{userPayId,jdbcType=BIGINT},
task_id = #{taskId,jdbcType=BIGINT},
url = #{url,jdbcType=VARCHAR},
QR_code_url = #{qrCodeUrl,jdbcType=VARCHAR},
time_difference = #{timeDifference,jdbcType=INTEGER},

4
game/src/main/resources/mbg.xml

@ -57,8 +57,8 @@
</javaClientGenerator>
<!-- <table tableName="t_game_type" domainObjectName="GameType"></table>-->
<!--<table tableName="t_game_user_pay" domainObjectName="GameUserPay"></table>-->
<!--<table tableName="t_game_record" domainObjectName="GameRecord"></table>-->
<table tableName="t_game_user_join" domainObjectName="GameUserJoin"></table>
<table tableName="t_game_record" domainObjectName="GameRecord"></table>
<!-- <table tableName="t_game_user_join" domainObjectName="GameUserJoin"></table>-->
<!--<table tableName="t_game_score_log" domainObjectName="GameScoreLog"></table>-->
<!--<table tableName="t_game_activity_rule" domainObjectName="GameActivityRule"></table>-->
<!--<table tableName="t_game_activity_prize" domainObjectName="GameActivityPrize"></table>-->

Loading…
Cancel
Save