| @@ -0,0 +1,94 @@ | |||
| package com.simple.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxCampaign; | |||
| import com.simple.domain.po.WxCoupon; | |||
| import com.simple.service.WxCampaignService; | |||
| import com.simple.service.WxCouponService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import static com.simple.domain.po.WxCampaign.Field.SortNum_ASC; | |||
| @RestController | |||
| @RequestMapping("wxCampaign") | |||
| @Api(description="促销和banner接口") | |||
| public class WxCampaignController extends BaseController | |||
| { | |||
| @Autowired | |||
| private WxCampaignService wxCampaignService; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| private Logger logger = Logger.getLogger(WxCampaignController.class); | |||
| @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 WxCampaign wxCampaign, Integer pageNum, Integer pageSize) { | |||
| if (null == wxCampaign) wxCampaign = new WxCampaign(); | |||
| if(wxCampaign.getStatus()!=null&&wxCampaign.getStatus()==-1){ | |||
| wxCampaign.setStatus(null); | |||
| } | |||
| wxCampaign.setTenantId(getTenantId()); | |||
| wxCampaign.setSortColumns(SortNum_ASC); | |||
| final PageInfo<WxCampaign> page = wxCampaignService.listAsPage(wxCampaign, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("根据id查询接口") | |||
| @GetMapping("/findById") | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData findById(Long id) { | |||
| WxCampaign wxCampaign = wxCampaignService.getById(id); | |||
| if (wxCampaign != null) { | |||
| List<Long> list = new ArrayList<>(); | |||
| List<String> templist = JSON.parseArray(wxCampaign.getCouponIds(), String.class); | |||
| for (String temp : templist | |||
| ) { | |||
| list.add(Long.parseLong(temp)); | |||
| } | |||
| WxCoupon wxCoupon = new WxCoupon(); | |||
| wxCoupon.setTenantId(getTenantId()); | |||
| wxCoupon.setIds(list); | |||
| wxCoupon.setStatus(1); | |||
| List<WxCoupon> couponlist = wxCouponService.findList(wxCoupon); | |||
| wxCampaign.setCoupons(couponlist); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxCampaign); | |||
| } | |||
| @ApiOperation("调整顺序") | |||
| @GetMapping("/move") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name="sourceId",value="",dataType="Long", paramType = "query",required=true), | |||
| @ApiImplicitParam(name="targetId",value="",dataType="Long", paramType = "query",required=true)}) | |||
| public ResultData move(Long sourceId,Long targetId) { | |||
| WxCampaign source = wxCampaignService.getById(sourceId); | |||
| WxCampaign target = wxCampaignService.getById(targetId); | |||
| if(source==null||target==null){ | |||
| return new ResultData(Result.ERROR, "调整顺序失败", null); | |||
| } | |||
| int temp =source.getSortNum(); | |||
| source.setSortNum(target.getSortNum()); | |||
| target.setSortNum(temp); | |||
| wxCampaignService.saveOrUpdate(source); | |||
| wxCampaignService.saveOrUpdate(target); | |||
| return new ResultData(Result.SUCCESS, "调整顺序成功", null); | |||
| } | |||
| } | |||