From de22a094170afc095e3df09dcff5d503896fdc35 Mon Sep 17 00:00:00 2001 From: hupeng Date: Fri, 18 Jan 2019 20:32:21 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=B8=B8=E6=88=8F][=E6=96=B0=E5=A2=9E]:?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=AC=A1=E6=95=B0=E9=99=90=E5=88=B6=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/controller/WxGameController.java | 63 +++++- .../java/com/iformall/common/ErrorCode.java | 4 +- .../java/com/iformall/domain/po/WxGame.java | 18 +- .../iformall/domain/po/WxGameActionLog.java | 183 ++++++++++++++++++ .../mapper/WxGameActionLogMapper.java | 13 ++ .../com/iformall/service/WxGameService.java | 6 + .../service/impl/WxGameServiceImpl.java | 32 ++- .../mapper/WxGameActionLogMapper.xml | 76 ++++++++ .../main/resources/mapper/WxGameMapper.xml | 14 +- 9 files changed, 391 insertions(+), 18 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/domain/po/WxGameActionLog.java create mode 100644 mallinkService/src/main/java/com/iformall/mapper/WxGameActionLogMapper.java create mode 100644 mallinkService/src/main/resources/mapper/WxGameActionLogMapper.xml diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java index dbecbf792..e1119fe71 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java @@ -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 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()); + } } diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 5519fbb47..536600212 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -118,10 +118,10 @@ public enum ErrorCode{ TJD_DEDUCE_FEE_FAIL(2063, "TJD停车费抵扣失败"), /** - * 券 + * 游戏 */ GAME_NOT_FOUND(2070, "游戏未找到"), - + GAME_HAS_BEEN_LIMITED(2071, "游戏次数以达到上限"), /** * 订单 */ diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxGame.java b/mallinkService/src/main/java/com/iformall/domain/po/WxGame.java index b33e21806..b060301e4 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxGame.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxGame.java @@ -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 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) { diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxGameActionLog.java b/mallinkService/src/main/java/com/iformall/domain/po/WxGameActionLog.java new file mode 100644 index 000000000..0a324cb07 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxGameActionLog.java @@ -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 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 getIds() { + return ids; + } + + public void setIds(List 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 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)); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxGameActionLogMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxGameActionLogMapper.java new file mode 100644 index 000000000..e11f8d43a --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxGameActionLogMapper.java @@ -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 { + + List findList(WxGameActionLog wxGameActionLog); + int getCount(WxGameActionLog wxGameActionLog); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxGameService.java b/mallinkService/src/main/java/com/iformall/service/WxGameService.java index 811d4226c..6615bf8c7 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxGameService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxGameService.java @@ -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获得实体 * diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java index a1b1d2b83..81c9c6ef1 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java @@ -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 listAsPage(WxGame record, Integer pageIndex, Integer pageSize) { PageInfo 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 getParams(WxGame record) { // 获取已上架的CouponChannel WxCouponChannel couponChannelQ = new WxCouponChannel(); diff --git a/mallinkService/src/main/resources/mapper/WxGameActionLogMapper.xml b/mallinkService/src/main/resources/mapper/WxGameActionLogMapper.xml new file mode 100644 index 000000000..27086d1f8 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxGameActionLogMapper.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + `id`,`tenant_id`,`coupon_id`,`coupon_order_id`,`channel_type`,`channel_id`,`create_time` + + + + where 1 = 1 + + + and `id` = #{id} + + + + + and `tenant_id` = #{tenantId} + + + + + and `game_id` = #{gameId} + + + + + and `user_id` = #{userId} + + + + + and `coupon_order_id` = #{couponOrderId} + + + + + and `create_time` = #{createTime} + + + + and `create_time` >= #{startTime} + + + + and `create_time` <= #{endTime} + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + + diff --git a/mallinkService/src/main/resources/mapper/WxGameMapper.xml b/mallinkService/src/main/resources/mapper/WxGameMapper.xml index b33066804..cc8f401eb 100644 --- a/mallinkService/src/main/resources/mapper/WxGameMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxGameMapper.xml @@ -10,10 +10,11 @@ + - `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` @@ -38,7 +39,10 @@ and `triggle_action` = #{triggleAction} - + + + and `play_limit` = #{playLimit} + and id in @@ -52,10 +56,6 @@ select from wx_game - - - - - +