Sfoglia il codice sorgente

[ADMIN游戏配置接口][新增]

release_toaliyun_real
Stormeye.Wu 7 anni fa
parent
commit
88c17621bf
3 ha cambiato i file con 166 aggiunte e 61 eliminazioni
  1. +33
    -27
      mallinkAdmin/src/main/java/com/iformall/controller/WxGameController.java
  2. +7
    -4
      mallinkService/src/main/java/com/iformall/domain/po/WxGame.java
  3. +126
    -30
      mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java

+ 33
- 27
mallinkAdmin/src/main/java/com/iformall/controller/WxGameController.java Vedi File

@@ -1,46 +1,50 @@
package com.iformall.controller; 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.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.iformall.common.Result; import com.iformall.common.Result;
import com.iformall.common.ResultData; import com.iformall.common.ResultData;

import com.iformall.domain.po.WxGame; import com.iformall.domain.po.WxGame;
import com.iformall.enums.EnumGameStatus;
import com.iformall.service.WxGameService; import com.iformall.service.WxGameService;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController @RestController
@RequestMapping("wxGame") @RequestMapping("wxGame")
public class WxGameController extends BaseController { public class WxGameController extends BaseController {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());


@Autowired
@Autowired
private WxGameService wxGameService; private WxGameService wxGameService;
@ApiOperation("分页列表接口")
@ApiOperation("分页列表接口")
@GetMapping("list") @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();
wxGame.setTenantId(getTenantId());
@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();
wxGame.setTenantId(getTenantId());
final PageInfo<WxGame> page = wxGameService.listAsPage(wxGame, pageNum, pageSize); final PageInfo<WxGame> page = wxGameService.listAsPage(wxGame, pageNum, pageSize);
return new ResultData(page); return new ResultData(page);
} }


@ApiOperation("新增接口")
@ApiOperation("新增接口")
@PostMapping("add") @PostMapping("add")
public ResultData add(@RequestBody WxGame wxGame) { public ResultData add(@RequestBody WxGame wxGame) {
//Assert.notNull(wxGame.getName(), "角色名不能为空"); //Assert.notNull(wxGame.getName(), "角色名不能为空");
//Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
if (StringUtils.isBlank(wxGame.getCouponIds())) {
wxGame.setCouponIds(JSONArray.toJSONString(new String[0]));
}
wxGame.setStatus(EnumGameStatus.STATUS_THROW_IN.getCode());
wxGame.setTenantId(getTenantId()); wxGame.setTenantId(getTenantId());
wxGameService.saveOrUpdate(wxGame); wxGameService.saveOrUpdate(wxGame);
return new ResultData(); return new ResultData();
@@ -49,26 +53,28 @@ public class WxGameController extends BaseController {
@ApiOperation("根据id更新接口") @ApiOperation("根据id更新接口")
@PostMapping("update") @PostMapping("update")
public ResultData update(@RequestBody WxGame wxGame) { public ResultData update(@RequestBody WxGame wxGame) {
wxGame.setTenantId(getTenantId());
if (StringUtils.isBlank(wxGame.getCouponIds())) {
wxGame.setCouponIds(JSONArray.toJSONString(new String[0]));
}
wxGame.setTenantId(getTenantId());
wxGameService.saveOrUpdate(wxGame); wxGameService.saveOrUpdate(wxGame);
return new ResultData(); return new ResultData();
} }


@ApiOperation("根据id删除接口") @ApiOperation("根据id删除接口")
@GetMapping("/del") @GetMapping("/del")
@ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
@ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
public ResultData delete(Long id) { public ResultData delete(Long id) {
wxGameService.deleteById(id); wxGameService.deleteById(id);
return new ResultData(Result.SUCCESS, "删除成功", null); return new ResultData(Result.SUCCESS, "删除成功", null);
} }
@ApiOperation("根据id查询接口")
@GetMapping("/findById")
@ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true)
@ApiOperation("根据id查询接口")
@GetMapping("/findById")
@ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
public ResultData findById(Long id) { public ResultData findById(Long id) {
return new ResultData(Result.SUCCESS,"查询成功",wxGameService.getById(id));
return new ResultData(Result.SUCCESS, "查询成功", wxGameService.getById(id));
} }


} }

+ 7
- 4
mallinkService/src/main/java/com/iformall/domain/po/WxGame.java Vedi File

@@ -62,11 +62,14 @@ public class WxGame implements Serializable {
@io.swagger.annotations.ApiModelProperty(value = "已投放券信息") @io.swagger.annotations.ApiModelProperty(value = "已投放券信息")
protected List<Object> couponIdsList; // couponChannel protected List<Object> couponIdsList; // couponChannel


@Transient
private List<Long> couponIdList; // couponId List, 前端选券使用

public static enum Field { 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");
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; private String value;


Field(String value) { Field(String value) {


+ 126
- 30
mallinkService/src/main/java/com/iformall/service/impl/WxGameServiceImpl.java Vedi File

@@ -3,12 +3,18 @@ package com.iformall.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; 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.domain.po.WxCouponChannel;
import com.iformall.domain.vo.WxCouponChannelVo; import com.iformall.domain.vo.WxCouponChannelVo;
import com.iformall.enums.EnumCouponChannelStatus; import com.iformall.enums.EnumCouponChannelStatus;
import com.iformall.enums.EnumCouponChannelType; import com.iformall.enums.EnumCouponChannelType;
import com.iformall.enums.EnumCouponStatus;
import com.iformall.enums.EnumGameStatus;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxCouponChannelMapper; import com.iformall.mapper.WxCouponChannelMapper;
import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponChannelService;
import com.iformall.service.WxCouponService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.*; import java.util.*;
@@ -31,10 +37,12 @@ public class WxGameServiceImpl implements WxGameService {
@Autowired @Autowired
WxCouponChannelMapper wxCouponChannelMapper; WxCouponChannelMapper wxCouponChannelMapper;


@Autowired
WxCouponService wxCouponService;

@Autowired @Autowired
WxCouponChannelService wxCouponChannelService; WxCouponChannelService wxCouponChannelService;



@Override @Override
public PageInfo<WxGame> listAsPage(WxGame record, Integer pageIndex, Integer pageSize) { public PageInfo<WxGame> listAsPage(WxGame record, Integer pageIndex, Integer pageSize) {
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxGameMapper.findList(record)); return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxGameMapper.findList(record));
@@ -69,32 +77,31 @@ public class WxGameServiceImpl implements WxGameService {
logger.error(e.getMessage()); logger.error(e.getMessage());
return null; return null;
} }
// 获取已上架的CouponChannel
WxCouponChannel couponChannelQ = new WxCouponChannel();
couponChannelQ.setTenantId(record.getTenantId());
couponChannelQ.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_GAME.getCode());
couponChannelQ.setSubTargetId(record.getId());
couponChannelQ.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());
List<WxCouponChannelVo> wxCouponChannelVos = wxCouponChannelService.listAPI(couponChannelQ);
Map<Long, WxCouponChannelVo> wxCouponChannelsMap = new HashMap<Long, WxCouponChannelVo>();
for(WxCouponChannelVo wxCouponChannelVo: wxCouponChannelVos) {
wxCouponChannelsMap.put(wxCouponChannelVo.getCouponId(), wxCouponChannelVo);
}

// get game's coupon // get game's coupon
List couponIdsList = new ArrayList(); List couponIdsList = new ArrayList();
JSONArray couponChannelIds = JSON.parseArray(wxGame.getCouponIds()); JSONArray couponChannelIds = JSON.parseArray(wxGame.getCouponIds());
for(int i=0; i<couponChannelIds.size();i++) { for(int i=0; i<couponChannelIds.size();i++) {
JSONObject couponChanObj = (JSONObject) couponChannelIds.get(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());
Long couponId = couponChanObj.getLong("couponId");

WxCouponChannelVo couponChannelVo = wxCouponChannelsMap.get(couponId);
if (couponChannelVo != null) {
couponChanObj.put("couponId", couponChannelVo.getCouponId());
couponChanObj.put("couponName", couponChannelVo.getTitle());
couponChanObj.put("coverImg", couponChannelVo.getCoverImg());
couponIdsList.add(couponChanObj);
} }
} }
if (couponIdsList.size() > 0) { if (couponIdsList.size() > 0) {
@@ -120,18 +127,107 @@ public class WxGameServiceImpl implements WxGameService {
} else { } else {
wxGameMapper.updateByPrimaryKeySelective(record); wxGameMapper.updateByPrimaryKeySelective(record);
} }

record = wxGameMapper.selectByPrimaryKey(record);
if (record.getStatus().equals(EnumGameStatus.STATUS_THROW_IN.getCode())) {
addOrUpdateCouponChannelBatch(JSONArray.parseArray(record.getCouponIds()), record);
} else {
delCouponChannelBatch(record);
}
}

private void delCouponChannelBatch(WxGame record) {
// couponChannel 下架
WxCouponChannel wxCouponChannelQ = new WxCouponChannel();
wxCouponChannelQ.setTenantId(record.getTenantId());
wxCouponChannelQ.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_GAME.getCode());
wxCouponChannelQ.setSubTargetId(record.getId());
wxCouponChannelQ.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());
List<WxCouponChannel> wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQ);
if (wxCouponChannels.size() > 0) {
for (WxCouponChannel ch : wxCouponChannels) {
ch.setStatus(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode());
ch.setUpdateDate(new Date());
wxCouponChannelMapper.updateByPrimaryKeySelective(ch);
}
}
}

private void addOrUpdateCouponChannelBatch(List couponIds, WxGame record) {
// 获取已上架的CouponChannel
WxCouponChannel wxCouponChannelQ = new WxCouponChannel();
wxCouponChannelQ.setTenantId(record.getTenantId());
wxCouponChannelQ.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_GAME.getCode());
wxCouponChannelQ.setSubTargetId(record.getId());
wxCouponChannelQ.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());
List<WxCouponChannel> wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQ);
Map<Long, WxCouponChannel> wxCouponChannelsMap = new HashMap<Long, WxCouponChannel>();
for(WxCouponChannel wxCouponChannel: wxCouponChannels) {
wxCouponChannelsMap.put(wxCouponChannel.getCouponId(), wxCouponChannel);
}

// 上架 couponChannel 更新
for(int i=0; i<couponIds.size();i++) {
JSONObject obj = (JSONObject)couponIds.get(i);
Long couponId = obj.getLong("couponId");
int weight = obj.getIntValue("weight");
saveOrUpdateCouponChannel(couponId, wxCouponChannelsMap, record);
}

// 下架更新
if (!wxCouponChannelsMap.isEmpty()) {
for (WxCouponChannel wxCouponChannel : wxCouponChannelsMap.values()) {
wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode());
wxCouponChannel.setUpdateDate(new Date());
wxCouponChannelMapper.updateByPrimaryKeySelective(wxCouponChannel);
}
}
}

public void saveOrUpdateCouponChannel(Long couponId, Map<Long, WxCouponChannel> wxCouponChannelsMap, WxGame record){

WxCoupon wxCoupon = wxCouponService.getById(couponId);
if (wxCoupon == null) {
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}
if (wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) {
throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF);
}
if (wxCoupon.getValidEndDate() != null && wxCoupon.getValidEndDate().before(new Date())) {
throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF);
}

// 更新已有的couponChannel
WxCouponChannel wxCouponChannel = wxCouponChannelsMap.get(couponId);
if (wxCouponChannel != null) {
wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());
wxCouponChannel.setBeginTime(record.getValidStartDate());
wxCouponChannel.setEndTime(record.getValidEndDate());
wxCouponChannel.setUpdateDate(new Date());
wxCouponChannelMapper.updateByPrimaryKeySelective(wxCouponChannel);
wxCouponChannelsMap.remove(couponId);
} else {
// 不存在的新增
wxCouponChannel = new WxCouponChannel();
wxCouponChannel.setBeginTime(record.getValidStartDate());
wxCouponChannel.setEndTime(record.getValidEndDate());
wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());
wxCouponChannel.setCouponId(couponId);
wxCouponChannel.setMerchantId(wxCoupon.getMerchantId());
wxCouponChannel.setType(wxCoupon.getType());
wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_GAME.getCode());
wxCouponChannel.setTenantId(wxCoupon.getTenantId());
wxCouponChannel.setBusiness(wxCoupon.getBusiness());
wxCouponChannel.setTitle(wxCoupon.getTitle());
wxCouponChannel.setSubTargetId(record.getId());
final IdWorker idWorker = IdWorker.get();
wxCouponChannel.setId(idWorker.nextId());
wxCouponChannelMapper.insertSelective(wxCouponChannel);
}
} }


@Override @Override
public void deleteById(Long id) { public void deleteById(Long id) {
wxGameMapper.deleteByPrimaryKey(id); wxGameMapper.deleteByPrimaryKey(id);
} }
} }

Caricamento…
Annulla
Salva