| @@ -1,20 +1,25 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.Page; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.domain.po.WxGameActionLog; | |||
| import com.iformall.domain.po.WxGameTemplate; | |||
| import com.iformall.enums.EnumGameStatus; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.service.WxGameService; | |||
| import com.iformall.service.WxGameTemplateService; | |||
| import com.iformall.service.WxOrderService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @@ -28,7 +33,7 @@ public class WxGameController extends BaseController { | |||
| private WxGameService wxGameService; | |||
| @Autowired | |||
| private WxGameTemplateService wxGameTemplateService; | |||
| private WxCouponOrderService wxCouponOrderService; | |||
| @ApiOperation("蒙层/游戏入口获取游戏信息") | |||
| @GetMapping("getOne") | |||
| @@ -45,4 +50,52 @@ public class WxGameController extends BaseController { | |||
| return new ResultData(record); | |||
| } | |||
| @ApiOperation("添加游戏参与记录") | |||
| @PostMapping("addActionLog") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "gameId", value = "游戏ID", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData addActionLog(String gameId, String orderId) { | |||
| Long gameIdL = null; | |||
| Long orderIdL = null; | |||
| Long couponOrderIdL = null; | |||
| try { | |||
| gameIdL = Long.valueOf(gameId); | |||
| if (orderId != null) { | |||
| orderIdL = Long.valueOf(orderId); | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setCUserId(getUserId()); | |||
| wxCouponOrder.setOrderId(orderIdL); | |||
| PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(wxCouponOrder,1,1); | |||
| if (page.getList().size()>0) { | |||
| couponOrderIdL = page.getList().get(0).getId(); | |||
| } | |||
| } | |||
| } catch (Exception e){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| WxGameActionLog wxGameActionLog = new WxGameActionLog(); | |||
| wxGameActionLog.setUserId(getUserId()); | |||
| wxGameActionLog.setTenantId(getTenantId()); | |||
| wxGameActionLog.setGameId(gameIdL); | |||
| wxGameActionLog.setCouponOrderId(couponOrderIdL); | |||
| wxGameService.addActionLog(wxGameActionLog); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("添加游戏参与记录") | |||
| @PostMapping("checkLimit") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "gameId", value = "游戏ID", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData checkLimit(String gameId) { | |||
| Long gameIdL = null; | |||
| try { | |||
| gameIdL = Long.valueOf(gameId); | |||
| } catch (Exception e){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| return wxGameService.checkLimit(gameIdL,getUserId()); | |||
| } | |||
| } | |||
| @@ -118,10 +118,10 @@ public enum ErrorCode{ | |||
| TJD_DEDUCE_FEE_FAIL(2063, "TJD停车费抵扣失败"), | |||
| /** | |||
| * 券 | |||
| * 游戏 | |||
| */ | |||
| GAME_NOT_FOUND(2070, "游戏未找到"), | |||
| GAME_HAS_BEEN_LIMITED(2071, "游戏次数以达到上限"), | |||
| /** | |||
| * 订单 | |||
| */ | |||
| @@ -57,6 +57,12 @@ public class WxGame implements Serializable { | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "触发条件(-1:不受限制,1:登录触发)", name = "triggleAction") | |||
| private Integer triggleAction; | |||
| /** | |||
| * 玩次数限制 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "触发条件(0:不受限制,n:限玩次数)", name = "playLimit") | |||
| private Integer playLimit; | |||
| @Transient | |||
| @io.swagger.annotations.ApiModelProperty(value = "已投放券信息") | |||
| @@ -167,6 +173,14 @@ public class WxGame implements Serializable { | |||
| this.triggleAction = triggleAction; | |||
| } | |||
| public Integer getPlayLimit() { | |||
| return playLimit; | |||
| } | |||
| public void setPlayLimit(Integer playLimit) { | |||
| this.playLimit = playLimit; | |||
| } | |||
| public List<Object> getCouponIdsList() { | |||
| return couponIdsList; | |||
| } | |||
| @@ -175,6 +189,7 @@ public class WxGame implements Serializable { | |||
| this.couponIdsList = couponIdsList; | |||
| } | |||
| public void setGameTemplate(WxGameTemplate gameTemplate) { | |||
| if (gameTemplate != null) { | |||
| this.imgUrl = gameTemplate.getImgUrl(); | |||
| @@ -193,7 +208,8 @@ public class WxGame implements Serializable { | |||
| , Status_ASC("`status` ASC"), Status_DESC("`status` DESC") | |||
| , ValidStartDate_ASC("`valid_start_date` ASC"), ValidStartDate_DESC("`valid_start_date` DESC") | |||
| , ValidEndDate_ASC("`valid_end_date` ASC"), ValidEndDate_DESC("`valid_end_date` DESC") | |||
| , TriggleAction_ASC("`triggle_action` ASC"), TriggleAction_DESC("`triggle_action` DESC"); | |||
| , TriggleAction_ASC("`triggle_action` ASC"), TriggleAction_DESC("`triggle_action` DESC") | |||
| , PlayLimit_ASC("`play_limit` ASC"), PlayLimit_DESC("`play_limit` DESC"); | |||
| private String value; | |||
| Field(String value) { | |||
| @@ -0,0 +1,183 @@ | |||
| package com.iformall.domain.po; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Table(name = "wx_game_action_log") | |||
| public class WxGameActionLog implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| @Transient | |||
| protected Date startTime; | |||
| @Transient | |||
| protected Date endTime; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public String getSortColumns() { | |||
| return sortColumns; | |||
| } | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<Long> ids) { | |||
| this.ids = ids; | |||
| } | |||
| public Date getStartTime() { | |||
| return startTime; | |||
| } | |||
| public void setStartTime(Date startTime) { | |||
| this.startTime = startTime; | |||
| } | |||
| public Date getEndTime() { | |||
| return endTime; | |||
| } | |||
| public void setEndTime(Date endTime) { | |||
| this.endTime = endTime; | |||
| } | |||
| /*租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| private String tenantId; | |||
| /*coupon id**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="游戏ID",name="gameId") | |||
| private Long gameId; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="couponOrderId") | |||
| private Long couponOrderId; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="userId") | |||
| private Long userId; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="createTime") | |||
| private Date createTime; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String _tenantId) { | |||
| tenantId = _tenantId; | |||
| } | |||
| public Long getCouponOrderId() { | |||
| return couponOrderId; | |||
| } | |||
| public void setCouponOrderId(Long _couponOrderId) { | |||
| couponOrderId = _couponOrderId; | |||
| } | |||
| public Long getGameId() { | |||
| return gameId; | |||
| } | |||
| public void setGameId(Long gameId) { | |||
| this.gameId = gameId; | |||
| } | |||
| public Long getUserId() { | |||
| return userId; | |||
| } | |||
| public void setUserId(Long userId) { | |||
| this.userId = userId; | |||
| } | |||
| public Date getCreateTime() { | |||
| return createTime; | |||
| } | |||
| public void setCreateTime(Date createTime) { | |||
| this.createTime = createTime; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,TenantId_ASC("`tenant_id` ASC"),TenantId_DESC("`tenant_id` DESC") | |||
| ,GameId_ASC("`game_id` ASC"),GameId_DESC("`game_id` DESC") | |||
| ,UserId_ASC("`user_id` ASC"),UserId_DESC("`user_id` DESC") | |||
| ,CouponOrderId_ASC("`coupon_order_id` ASC"),CouponOrderId_DESC("`coupon_order_id` DESC") | |||
| ,CreateTime_ASC("`create_time` ASC"),CreateTime_DESC("`create_time` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| this.value = value; | |||
| } | |||
| public String getValue() { | |||
| return value; | |||
| } | |||
| public void setCol(String value) { | |||
| this.value = value; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return this.getValue(); | |||
| } | |||
| } | |||
| public void setSortColumns(WxGameActionLog.Field... fields) | |||
| { | |||
| if (fields == null || fields.length == 0) { | |||
| return; | |||
| } | |||
| for (int k = 0; k < fields.length; k++) { | |||
| if (fields[k] == null) { | |||
| return; | |||
| } | |||
| } | |||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||
| for (int k = 1; k < fields.length; k++) { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| this.sortColumns = sb.toString(); | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| return; | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| List<Field> fList = new ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(Field.valueOf(cols[k])); | |||
| } | |||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||
| } else { | |||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxGameActionLog; | |||
| import java.util.List; | |||
| public interface WxGameActionLogMapper extends CommonMapper<WxGameActionLog, String> { | |||
| List<WxGameActionLog> findList(WxGameActionLog wxGameActionLog); | |||
| int getCount(WxGameActionLog wxGameActionLog); | |||
| } | |||
| @@ -1,7 +1,9 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.domain.po.WxGameActionLog; | |||
| public interface WxGameService { | |||
| @@ -22,6 +24,10 @@ public interface WxGameService { | |||
| */ | |||
| WxGame getOne(WxGame record); | |||
| void addActionLog(WxGameActionLog wxGameActionLog); | |||
| ResultData checkLimit(Long gameId, Long userId); | |||
| /** | |||
| * 根据Id获得实体 | |||
| * | |||
| @@ -4,8 +4,8 @@ import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| @@ -13,6 +13,7 @@ import com.iformall.enums.EnumCouponStatus; | |||
| import com.iformall.enums.EnumGameStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.mapper.WxGameActionLogMapper; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxGameTemplateService; | |||
| @@ -21,7 +22,6 @@ import org.slf4j.LoggerFactory; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.mapper.WxGameMapper; | |||
| import com.iformall.service.WxGameService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -49,6 +49,10 @@ public class WxGameServiceImpl implements WxGameService { | |||
| @Autowired | |||
| WxGameTemplateService wxGameTemplateService; | |||
| @Autowired | |||
| WxGameActionLogMapper wxGameActionLogMapper; | |||
| @Override | |||
| public PageInfo<WxGame> listAsPage(WxGame record, Integer pageIndex, Integer pageSize) { | |||
| PageInfo<WxGame> page = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxGameMapper.findList(record)); | |||
| @@ -76,6 +80,28 @@ public class WxGameServiceImpl implements WxGameService { | |||
| return record; | |||
| } | |||
| @Override | |||
| public void addActionLog(WxGameActionLog wxGameActionLog) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| wxGameActionLog.setId(idWorker.nextId()); | |||
| wxGameActionLog.setCreateTime(new Date()); | |||
| wxGameActionLogMapper.insertSelective(wxGameActionLog); | |||
| } | |||
| @Override | |||
| public ResultData checkLimit(Long gameId, Long userId) { | |||
| WxGameActionLog wxGameActionLog = new WxGameActionLog(); | |||
| wxGameActionLog.setUserId(userId); | |||
| wxGameActionLog.setGameId(gameId); | |||
| if (wxGameActionLogMapper.getCount(wxGameActionLog) | |||
| > wxGameMapper.selectByPrimaryKey(gameId).getPlayLimit()) | |||
| return new ResultData(ErrorCode.GAME_HAS_BEEN_LIMITED); | |||
| return new ResultData(); | |||
| } | |||
| private List<Object> getParams(WxGame record) { | |||
| // 获取已上架的CouponChannel | |||
| WxCouponChannel couponChannelQ = new WxCouponChannel(); | |||
| @@ -0,0 +1,76 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.WxGameActionLogMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxGameActionLog"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="game_id" jdbcType="BIGINT" property="gameId" /> | |||
| <result column="user_id" jdbcType="BIGINT" property="userId" /> | |||
| <result column="coupon_order_id" jdbcType="BIGINT" property="couponOrderId" /> | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`coupon_id`,`coupon_order_id`,`channel_type`,`channel_id`,`create_time` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != gameId "> | |||
| and `game_id` = #{gameId} | |||
| </if> | |||
| <if test=" null != userId "> | |||
| and `user_id` = #{userId} | |||
| </if> | |||
| <if test=" null != couponOrderId "> | |||
| and `coupon_order_id` = #{couponOrderId} | |||
| </if> | |||
| <if test=" null != createTime "> | |||
| and `create_time` = #{createTime} | |||
| </if> | |||
| <if test=" null != startTime "> | |||
| and `create_time` >= #{startTime} | |||
| </if> | |||
| <if test=" null != endTime "> | |||
| and `create_time` <= #{endTime} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxGameActionLog" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_game_action_log | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <select id="getCount" resultType="java.lang.Integer" parameterType="com.iformall.domain.po.WxGameActionLog"> | |||
| select COUNT(*) FROM wx_game_action_log a | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||
| @@ -10,10 +10,11 @@ | |||
| <result column="valid_start_date" jdbcType="TIMESTAMP" property="validStartDate" /> | |||
| <result column="valid_end_date" jdbcType="TIMESTAMP" property="validEndDate" /> | |||
| <result column="triggle_action" jdbcType="INTEGER" property="triggleAction" /> | |||
| <result column="play_limit" jdbcType="INTEGER" property="playLimit" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`game_id`,`status`,`coupon_ids`,`valid_start_date`,`valid_end_date`,`triggle_action` | |||
| `id`,`tenant_id`,`game_id`,`status`,`coupon_ids`,`valid_start_date`,`valid_end_date`,`triggle_action`,`play_limit` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -38,7 +39,10 @@ | |||
| </if> | |||
| <if test=" null != triggleAction "> | |||
| and `triggle_action` = #{triggleAction} | |||
| </if> | |||
| </if> | |||
| <if test=" null != playLimit "> | |||
| and `play_limit` = #{playLimit} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -52,10 +56,6 @@ | |||
| select <include refid="allColumns" /> from wx_game | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||