| @@ -0,0 +1,71 @@ | |||
| package com.iformall.controller; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.util.Assert; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.service.WxGameService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| @RestController | |||
| @RequestMapping("wxGame") | |||
| public class WxGameController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxGameService wxGameService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||
| public ResultData list(@ModelAttribute WxGame wxGame,Integer pageNum, Integer pageSize) { | |||
| if (null == wxGame) wxGame = new WxGame(); | |||
| final PageInfo<WxGame> page = wxGameService.listAsPage(wxGame, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxGame wxGame) { | |||
| //Assert.notNull(wxGame.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| wxGameService.saveOrUpdate(wxGame); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id更新接口") | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxGame wxGame) { | |||
| wxGameService.saveOrUpdate(wxGame); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @GetMapping("/del") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData delete(Long id) { | |||
| wxGameService.deleteById(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @ApiOperation("根据id查询接口") | |||
| @GetMapping("/findById") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxGameService.getById(id)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,67 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxGameTemplate; | |||
| import com.iformall.service.WxGameTemplateService; | |||
| 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.*; | |||
| @RestController | |||
| @RequestMapping("wxGameTemplate") | |||
| public class WxGameTemplateController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxGameTemplateService wxGameTemplateService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData list(@ModelAttribute WxGameTemplate wxGameTemplate, Integer pageNum, Integer pageSize) { | |||
| if (null == wxGameTemplate) wxGameTemplate = new WxGameTemplate(); | |||
| final PageInfo<WxGameTemplate> page = wxGameTemplateService.listAsPage(wxGameTemplate, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("新增接口") | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxGameTemplate wxGameTemplate) { | |||
| //Assert.notNull(wxGameTemplate.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| wxGameTemplateService.saveOrUpdate(wxGameTemplate); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id更新接口") | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxGameTemplate wxGameTemplate) { | |||
| wxGameTemplateService.saveOrUpdate(wxGameTemplate); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @GetMapping("/del") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData delete(Long id) { | |||
| wxGameTemplateService.deleteById(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @ApiOperation("根据id查询接口") | |||
| @GetMapping("/findById") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData findById(Long id) { | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxGameTemplateService.getById(id)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,69 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.domain.po.WxGameTemplate; | |||
| import com.iformall.enums.EnumGameStatus; | |||
| import com.iformall.service.WxGameService; | |||
| import com.iformall.service.WxGameTemplateService; | |||
| 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 java.util.HashMap; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/game") | |||
| public class WxGameController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxGameService wxGameService; | |||
| @Autowired | |||
| private WxGameTemplateService wxGameTemplateService; | |||
| @ApiOperation("蒙层/游戏入口获取游戏信息") | |||
| @GetMapping("getOne") | |||
| public ResultData getOne() { | |||
| WxGame wxGame = new WxGame(); | |||
| wxGame.setTenantId(getTenantId()); | |||
| wxGame.setStatus(EnumGameStatus.STATUS_THROW_IN.getCode()); | |||
| // 因为有算法要求,分成两步获取 | |||
| WxGame wxGame1 = wxGameService.getOne(wxGame); | |||
| if (wxGame1 != null) { | |||
| WxGameTemplate gameTemplate = wxGameTemplateService.getById(wxGame1.getGameId()); | |||
| if (gameTemplate != null) { | |||
| Map map = new HashMap(); | |||
| map.put("id", wxGame1.getId()); | |||
| map.put("gameId", wxGame1.getGameId()); | |||
| map.put("imgUrl", gameTemplate.getImgUrl()); | |||
| map.put("url", gameTemplate.getUrl()); | |||
| return new ResultData(map); | |||
| } | |||
| } | |||
| return new ResultData(ErrorCode.GAME_NOT_FOUND); | |||
| } | |||
| @ApiOperation("获取游戏参数(id,gameId必填)") | |||
| @GetMapping("getParams") | |||
| public ResultData getOne(@ModelAttribute WxGame wxGame) { | |||
| if (null == wxGame) wxGame = new WxGame(); | |||
| wxGame.setTenantId(getTenantId()); | |||
| wxGame.setStatus(EnumGameStatus.STATUS_THROW_IN.getCode()); | |||
| WxGame wxGame1 = wxGameService.getParams(wxGame); | |||
| if (wxGame1 != null) { | |||
| return new ResultData(wxGame1); | |||
| } | |||
| return new ResultData(ErrorCode.GAME_NOT_FOUND); | |||
| } | |||
| } | |||
| @@ -113,7 +113,10 @@ public enum ErrorCode{ | |||
| TJD_STOP_FEE_FAIL(2062, "TJD停车费失败"), | |||
| TJD_DEDUCE_FEE_FAIL(2063, "TJD停车费抵扣失败"), | |||
| /** | |||
| * 券 | |||
| */ | |||
| GAME_NOT_FOUND(2070, "游戏未找到"), | |||
| /** | |||
| * 订单 | |||
| @@ -0,0 +1,119 @@ | |||
| package com.iformall.domain.po; | |||
| import lombok.Data; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @Table(name = "wx_game") | |||
| @Data | |||
| public class WxGame implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| /** | |||
| * 租户ID | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") | |||
| private String tenantId; | |||
| /** | |||
| * 游戏模板ID | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "游戏模板ID", name = "gameId") | |||
| private Long gameId; | |||
| /** | |||
| * 游戏状态(0:上架,1:下架) | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "游戏状态(0:上架,1:下架)", name = "status") | |||
| private Integer status; | |||
| /** | |||
| * 券列表 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "券列表", name = "couponIds") | |||
| private String couponIds; | |||
| /** | |||
| * 有效日期-开始 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "有效日期-开始", name = "validStartDate") | |||
| private Date validStartDate; | |||
| /** | |||
| * 有效日期-结束 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "有效日期-结束", name = "validEndDate") | |||
| private Date validEndDate; | |||
| /** | |||
| * 触发条件(-1:不受限制,1:登录触发) | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "触发条件(-1:不受限制,1:登录触发)", name = "triggleAction") | |||
| private Integer triggleAction; | |||
| @Transient | |||
| protected List<Object> CouponIdsList; | |||
| 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"), 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"); | |||
| 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(WxGame.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(","); | |||
| java.util.List<Field> fList = new java.util.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,104 @@ | |||
| package com.iformall.domain.po; | |||
| import lombok.Data; | |||
| import javax.persistence.*; | |||
| import javax.persistence.Transient; | |||
| import java.util.List; | |||
| import javax.persistence.Id; | |||
| import java.io.Serializable; | |||
| @Table(name = "wx_game_template") | |||
| @Data | |||
| public class WxGameTemplate implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| /**游戏名称*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="游戏名称",name="name") | |||
| private String name; | |||
| /**游戏链接*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="游戏链接",name="url") | |||
| private String url; | |||
| /**游戏logo,c端游戏入口使用*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="游戏logo,c端游戏入口使用",name="imgUrl") | |||
| private String imgUrl; | |||
| /**选项限制(-1:不做限制)*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="选项限制(-1:不做限制)",name="optionLimit") | |||
| private Integer optionLimit; | |||
| /**游戏规则说明*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="游戏规则说明",name="rules") | |||
| private String rules; | |||
| /**游戏类型(1:卡牌),目前无用*/ | |||
| @io.swagger.annotations.ApiModelProperty(value="游戏类型(1:卡牌),目前无用",name="type") | |||
| private Integer type; | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | |||
| ,Url_ASC("`url` ASC"),Url_DESC("`url` DESC") | |||
| ,ImgUrl_ASC("`img_url` ASC"),ImgUrl_DESC("`img_url` DESC") | |||
| ,OptionLimit_ASC("`option_limit` ASC"),OptionLimit_DESC("`option_limit` DESC") | |||
| ,Rules_ASC("`rules` ASC"),Rules_DESC("`rules` DESC") | |||
| ,Type_ASC("`type` ASC"),Type_DESC("`type` 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(WxGameTemplate.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(","); | |||
| java.util.List<Field> fList = new java.util.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)); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,9 +7,8 @@ public enum EnumCouponChannelType { | |||
| COUPON_CHANNEL_ID_LIST(1, "列表"), | |||
| COUPON_CHANNEL_ID_TIMED(2, "限时抢购"), | |||
| COUPON_CHANNEL_ID_CAMPAIN(3, "幻灯片") // banner图, 宣传页,轮播图,走马灯 | |||
| ; | |||
| COUPON_CHANNEL_ID_CAMPAIN(3, "幻灯片"), // banner图, 宣传页,轮播图,走马灯 | |||
| COUPON_CHANNEL_ID_GAME(4, "游戏") | |||
| ; | |||
| public static EnumCouponChannelType getEnum(Integer code) { | |||
| @@ -0,0 +1,38 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumGameStatus { | |||
| // 0-已上架;1-已下架; | |||
| STATUS_THROW_IN(0, "已上架"), | |||
| STATUS_TAKE_OFFF(1, "已下架"), | |||
| ; | |||
| public static EnumGameStatus getEnum(Integer code) { | |||
| for (EnumGameStatus value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumGameStatus(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| package com.iformall.mapper; | |||
| import java.util.*; | |||
| import com.iformall.common.CommonMapper; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import com.iformall.domain.po.WxGame; | |||
| public interface WxGameMapper extends CommonMapper<WxGame, Long> { | |||
| List<WxGame> findList(WxGame wxGame); | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| package com.iformall.mapper; | |||
| import java.util.*; | |||
| import com.iformall.common.CommonMapper; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import com.iformall.domain.po.WxGameTemplate; | |||
| public interface WxGameTemplateMapper extends CommonMapper<WxGameTemplate, Long> { | |||
| List<WxGameTemplate> findList(WxGameTemplate wxGameTemplate); | |||
| } | |||
| @@ -0,0 +1,61 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxGame; | |||
| public interface WxGameService { | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param pageIndex | |||
| * @param pageSize | |||
| * @return | |||
| */ | |||
| PageInfo<WxGame> listAsPage(WxGame record, Integer pageIndex, Integer pageSize); | |||
| /** | |||
| * 获取用户要玩的游戏信息 | |||
| * @param record | |||
| * @return | |||
| */ | |||
| WxGame getOne(WxGame record); | |||
| /** | |||
| * 获取用户要玩的游戏参数 | |||
| * @param record | |||
| * @return | |||
| */ | |||
| WxGame getParams(WxGame record); | |||
| /** | |||
| * 根据Id获得实体 | |||
| * | |||
| * @param id | |||
| * @return | |||
| */ | |||
| WxGame getById(Long id); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxGame record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| * | |||
| * @param id | |||
| */ | |||
| void deleteById(Long id); | |||
| } | |||
| @@ -0,0 +1,47 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxGameTemplate; | |||
| public interface WxGameTemplateService { | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param pageIndex | |||
| * @param pageSize | |||
| * @return | |||
| */ | |||
| PageInfo<WxGameTemplate> listAsPage(WxGameTemplate record, Integer pageIndex, Integer pageSize); | |||
| /** | |||
| * 根据Id获得实体 | |||
| * | |||
| * @param id | |||
| * @return | |||
| */ | |||
| WxGameTemplate getById(Long id); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxGameTemplate record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| * | |||
| * @param id | |||
| */ | |||
| void deleteById(Long id); | |||
| } | |||
| @@ -0,0 +1,137 @@ | |||
| package com.iformall.service.impl; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.mapper.WxCouponChannelMapper; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import org.slf4j.Logger; | |||
| 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; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.common.IdWorker; | |||
| @Service | |||
| public class WxGameServiceImpl implements WxGameService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxGameMapper wxGameMapper; | |||
| @Autowired | |||
| WxCouponChannelMapper wxCouponChannelMapper; | |||
| @Autowired | |||
| WxCouponChannelService wxCouponChannelService; | |||
| @Override | |||
| public PageInfo<WxGame> listAsPage(WxGame record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxGameMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public WxGame getOne(WxGame record) { | |||
| WxGame wxGame = null; | |||
| // get game's count | |||
| int countOfGame = wxGameMapper.selectCount(record); | |||
| if (countOfGame == 1){ | |||
| wxGame = wxGameMapper.selectOne(record); | |||
| } else if (countOfGame > 1){ | |||
| // random | |||
| 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); | |||
| } | |||
| if (wxGame != null) { | |||
| return wxGame; | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| public WxGame getParams(WxGame record) { | |||
| WxGame wxGame = null; | |||
| try { | |||
| wxGame = wxGameMapper.selectOne(record); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return null; | |||
| } | |||
| // get game's coupon | |||
| List couponIdsList = new ArrayList(); | |||
| JSONArray couponChannelIds = JSON.parseArray(wxGame.getCouponIds()); | |||
| for(int i=0; i<couponChannelIds.size();i++) { | |||
| JSONObject couponChanObj = (JSONObject) couponChannelIds.get(i); | |||
| Long id = couponChanObj.getLong("couponChannelId"); | |||
| WxCouponChannel couponChannelQ = new WxCouponChannel(); | |||
| couponChannelQ.setId(id); | |||
| couponChannelQ.setTenantId(record.getTenantId()); | |||
| couponChannelQ.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_GAME.getCode()); | |||
| couponChannelQ.setSubTargetId(wxGame.getId()); | |||
| couponChannelQ.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| try { | |||
| List<WxCouponChannelVo> couponChannelVoList = wxCouponChannelService.listAPI(couponChannelQ); | |||
| if (couponChannelVoList.size() > 0) { | |||
| WxCouponChannelVo couponChannelVo = couponChannelVoList.get(0); | |||
| if (couponChannelVo != null) { | |||
| couponChanObj.put("couponId", couponChannelVo.getCouponId()); | |||
| couponChanObj.put("couponName", couponChannelVo.getTitle()); | |||
| couponChanObj.put("coverImg", couponChannelVo.getCoverImg()); | |||
| couponIdsList.add(couponChanObj); | |||
| } | |||
| } | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| if (couponIdsList.size() > 0) { | |||
| wxGame.setCouponIdsList(couponIdsList); | |||
| return wxGame; | |||
| } | |||
| return null; | |||
| } | |||
| @Override | |||
| public WxGame getById(Long id) { | |||
| return wxGameMapper.selectByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxGame record) { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| wxGameMapper.insertSelective(record); | |||
| } else { | |||
| wxGameMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| } | |||
| @Override | |||
| public void deleteById(Long id) { | |||
| wxGameMapper.deleteByPrimaryKey(id); | |||
| } | |||
| } | |||
| @@ -0,0 +1,49 @@ | |||
| package com.iformall.service.impl; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.domain.po.WxGameTemplate; | |||
| import com.iformall.mapper.WxGameTemplateMapper; | |||
| import com.iformall.service.WxGameTemplateService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @Service | |||
| public class WxGameTemplateServiceImpl implements WxGameTemplateService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxGameTemplateMapper wxGameTemplateMapper; | |||
| @Override | |||
| public PageInfo<WxGameTemplate> listAsPage(WxGameTemplate record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxGameTemplateMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public WxGameTemplate getById(Long id) { | |||
| return wxGameTemplateMapper.selectByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxGameTemplate record) { | |||
| if (record.getId() == null) { | |||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| wxGameTemplateMapper.insertSelective(record); | |||
| } else { | |||
| wxGameTemplateMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| } | |||
| @Override | |||
| public void deleteById(Long id) { | |||
| wxGameTemplateMapper.deleteByPrimaryKey(id); | |||
| } | |||
| } | |||
| @@ -0,0 +1,60 @@ | |||
| <?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.WxGameMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxGame"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="game_id" jdbcType="INTEGER" property="gameId" /> | |||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||
| <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" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`game_id`,`status`,`valid_start_date`,`valid_end_date`,`triggle_action` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` like concat('%', #{tenantId},'%') | |||
| </if> | |||
| <if test=" null != gameId "> | |||
| and `game_id` = #{gameId} | |||
| </if> | |||
| <if test=" null != status "> | |||
| and `status` = #{status} | |||
| </if> | |||
| <if test=" null != validStartDate "> | |||
| and `valid_start_date` = #{validStartDate} | |||
| </if> | |||
| <if test=" null != validEndDate "> | |||
| and `valid_end_date` = #{validEndDate} | |||
| </if> | |||
| <if test=" null != triggleAction "> | |||
| and `triggle_action` = #{triggleAction} | |||
| </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.WxGame" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_game | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||
| @@ -0,0 +1,60 @@ | |||
| <?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.WxGameTemplateMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxGameTemplate"> | |||
| <id column="id" jdbcType="INTEGER" property="id" /> | |||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||
| <result column="url" jdbcType="VARCHAR" property="url" /> | |||
| <result column="img_url" jdbcType="VARCHAR" property="imgUrl" /> | |||
| <result column="option_limit" jdbcType="INTEGER" property="optionLimit" /> | |||
| <result column="rules" jdbcType="VARCHAR" property="rules" /> | |||
| <result column="type" jdbcType="INTEGER" property="type" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`name`,`url`,`img_url`,`option_limit`,`rules`,`type` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != name "> | |||
| and `name` like concat('%', #{name},'%') | |||
| </if> | |||
| <if test=" null != url "> | |||
| and `url` like concat('%', #{url},'%') | |||
| </if> | |||
| <if test=" null != imgUrl "> | |||
| and `img_url` like concat('%', #{imgUrl},'%') | |||
| </if> | |||
| <if test=" null != optionLimit "> | |||
| and `option_limit` = #{optionLimit} | |||
| </if> | |||
| <if test=" null != rules "> | |||
| and `rules` like concat('%', #{rules},'%') | |||
| </if> | |||
| <if test=" null != type "> | |||
| and `type` = #{type} | |||
| </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.WxGameTemplate" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_game_template | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||