From 1624b1697c8cefd782290ed76cdbbfe720a7627e Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Thu, 11 Oct 2018 16:55:47 +0800 Subject: [PATCH] =?UTF-8?q?[C=E7=AB=AF=E6=B8=B8=E6=88=8F=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=94=AF=E6=8C=81][=E6=96=B0=E5=A2=9E]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/controller/WxGameController.java | 71 +++++++++ .../controller/WxGameTemplateController.java | 67 +++++++++ .../iformall/controller/WxGameController.java | 69 +++++++++ .../java/com/iformall/common/ErrorCode.java | 5 +- .../java/com/iformall/domain/po/WxGame.java | 119 +++++++++++++++ .../iformall/domain/po/WxGameTemplate.java | 104 +++++++++++++ .../iformall/enums/EnumCouponChannelType.java | 5 +- .../com/iformall/enums/EnumGameStatus.java | 38 +++++ .../com/iformall/mapper/WxGameMapper.java | 17 +++ .../iformall/mapper/WxGameTemplateMapper.java | 17 +++ .../com/iformall/service/WxGameService.java | 61 ++++++++ .../service/WxGameTemplateService.java | 47 ++++++ .../service/impl/WxGameServiceImpl.java | 137 ++++++++++++++++++ .../impl/WxGameTemplateServiceImpl.java | 49 +++++++ .../main/resources/mapper/WxGameMapper.xml | 60 ++++++++ .../resources/mapper/WxGameTemplateMapper.xml | 60 ++++++++ 16 files changed, 922 insertions(+), 4 deletions(-) create mode 100644 mallinkAdmin/src/main/java/com/iformall/controller/WxGameController.java create mode 100644 mallinkAdmin/src/main/java/com/iformall/controller/WxGameTemplateController.java create mode 100644 mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java create mode 100644 mallinkService/src/main/java/com/iformall/domain/po/WxGame.java create mode 100644 mallinkService/src/main/java/com/iformall/domain/po/WxGameTemplate.java create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumGameStatus.java create mode 100644 mallinkService/src/main/java/com/iformall/mapper/WxGameMapper.java create mode 100644 mallinkService/src/main/java/com/iformall/mapper/WxGameTemplateMapper.java create mode 100644 mallinkService/src/main/java/com/iformall/service/WxGameService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/WxGameTemplateService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java create mode 100644 mallinkService/src/main/java/com/iformall/service/impl/WxGameTemplateServiceImpl.java create mode 100644 mallinkService/src/main/resources/mapper/WxGameMapper.xml create mode 100644 mallinkService/src/main/resources/mapper/WxGameTemplateMapper.xml diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxGameController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxGameController.java new file mode 100644 index 000000000..73ebd4701 --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxGameController.java @@ -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 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)); + } + + + +} diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxGameTemplateController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxGameTemplateController.java new file mode 100644 index 000000000..80cdfe946 --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxGameTemplateController.java @@ -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 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)); + } + + +} diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java new file mode 100644 index 000000000..214125e0e --- /dev/null +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxGameController.java @@ -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); + } + +} diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 1b9e71aee..3c776942c 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -113,7 +113,10 @@ public enum ErrorCode{ TJD_STOP_FEE_FAIL(2062, "TJD停车费失败"), TJD_DEDUCE_FEE_FAIL(2063, "TJD停车费抵扣失败"), - + /** + * 券 + */ + GAME_NOT_FOUND(2070, "游戏未找到"), /** * 订单 diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxGame.java b/mallinkService/src/main/java/com/iformall/domain/po/WxGame.java new file mode 100644 index 000000000..03341f53d --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxGame.java @@ -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 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 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 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)); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxGameTemplate.java b/mallinkService/src/main/java/com/iformall/domain/po/WxGameTemplate.java new file mode 100644 index 000000000..fba59d1ca --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxGameTemplate.java @@ -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 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 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)); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java b/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java index 32e9fe06d..8ea8f36b5 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCouponChannelType.java @@ -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) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumGameStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumGameStatus.java new file mode 100644 index 000000000..5823ed638 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumGameStatus.java @@ -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; + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxGameMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxGameMapper.java new file mode 100644 index 000000000..0a8aa3374 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxGameMapper.java @@ -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 { + + List findList(WxGame wxGame); + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxGameTemplateMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxGameTemplateMapper.java new file mode 100644 index 000000000..baa60269d --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxGameTemplateMapper.java @@ -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 { + + List findList(WxGameTemplate wxGameTemplate); + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxGameService.java b/mallinkService/src/main/java/com/iformall/service/WxGameService.java new file mode 100644 index 000000000..72c70d969 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxGameService.java @@ -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 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); + + + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxGameTemplateService.java b/mallinkService/src/main/java/com/iformall/service/WxGameTemplateService.java new file mode 100644 index 000000000..430da2680 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxGameTemplateService.java @@ -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 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); + + + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java new file mode 100644 index 000000000..bfd4f708b --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java @@ -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 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 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 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); + } + + + + + + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxGameTemplateServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxGameTemplateServiceImpl.java new file mode 100644 index 000000000..6beae8fd9 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxGameTemplateServiceImpl.java @@ -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 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); + } + +} diff --git a/mallinkService/src/main/resources/mapper/WxGameMapper.xml b/mallinkService/src/main/resources/mapper/WxGameMapper.xml new file mode 100644 index 000000000..58cc52467 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxGameMapper.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + `id`,`tenant_id`,`game_id`,`status`,`valid_start_date`,`valid_end_date`,`triggle_action` + + + + where 1 = 1 + + and `id` = #{id} + + + and `tenant_id` like concat('%', #{tenantId},'%') + + + and `game_id` = #{gameId} + + + and `status` = #{status} + + + and `valid_start_date` = #{validStartDate} + + + and `valid_end_date` = #{validEndDate} + + + and `triggle_action` = #{triggleAction} + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + + + diff --git a/mallinkService/src/main/resources/mapper/WxGameTemplateMapper.xml b/mallinkService/src/main/resources/mapper/WxGameTemplateMapper.xml new file mode 100644 index 000000000..3f9428fd6 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxGameTemplateMapper.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + `id`,`name`,`url`,`img_url`,`option_limit`,`rules`,`type` + + + + where 1 = 1 + + and `id` = #{id} + + + and `name` like concat('%', #{name},'%') + + + and `url` like concat('%', #{url},'%') + + + and `img_url` like concat('%', #{imgUrl},'%') + + + and `option_limit` = #{optionLimit} + + + and `rules` like concat('%', #{rules},'%') + + + and `type` = #{type} + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + + +