From bf8005bf8c737b429ec1c3d2f226ec8bee796f4f Mon Sep 17 00:00:00 2001 From: hupeng Date: Thu, 14 Mar 2019 18:02:15 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8D=A1=E5=88=B8][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8D=A1=E5=88=B8A=E7=AB=AF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxCouponController.java | 73 ++++--------------- .../com/iformall/service/WxCouponService.java | 3 + .../service/impl/WxCouponServiceImpl.java | 59 +++++++++++++++ 3 files changed, 75 insertions(+), 60 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponController.java index ad50854f7..d55607012 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCouponController.java @@ -8,10 +8,7 @@ import com.iformall.common.ResultData; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.po.WxMerchant; -import com.iformall.enums.EnumCouponStatus; -import com.iformall.enums.EnumCouponType; -import com.iformall.enums.EnumCouponValidType; -import com.iformall.enums.EnumMerchantStatus; +import com.iformall.enums.*; import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponService; import com.iformall.service.WxMerchantService; @@ -39,58 +36,6 @@ public class WxCouponController extends BaseController { @Autowired private WxCouponService wxCouponService; - @Autowired - private WxCouponChannelService wxCouponChannelService; - - private ResultData listType(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize, Integer type) { - if (null == wxCoupon) wxCoupon = new WxCoupon(); - wxCoupon.setTenantId(getTenantId()); - wxCoupon.setSortColumns(WxCoupon.Field.Id_DESC); - PageInfo page = null; - if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) - wxCoupon.setStatus(null); - page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize, type); - - List wxCouponList = page.getList(); - - if (wxCouponList.isEmpty()) { - return new ResultData(page); - } - - List ids = wxCouponList.stream().map(p -> p.getId()).collect(Collectors.toList()); - WxCouponChannel wxCouponChannel = new WxCouponChannel(); - wxCouponChannel.setTenantId(getTenantId()); - wxCouponChannel.setCouponIds(ids); - wxCouponChannel.setStatus(0); - //上架状态 - List list = wxCouponChannelService.listAsPage(wxCouponChannel, 1, 10000).getList(); - if (!list.isEmpty()) { - Map> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId)); - for (WxCoupon temp : wxCouponList) { - - if (groupBy.get(temp.getId()) != null) { - List channels = new ArrayList<>(); - for (WxCouponChannel tempchannel : groupBy.get(temp.getId())) { - if (!channels.contains(tempchannel.getTargetAd())) { - channels.add(tempchannel.getTargetAd()); - } - } - String sss = JSON.toJSONString(channels); - temp.setChannels(sss); - } else { - temp.setChannels(""); - } - - } - } else { - for (WxCoupon temp : wxCouponList) { - temp.setChannels(""); - } - - } - return new ResultData(page); - } - @ApiOperation("分页列表接口") @GetMapping("listCoupon") @@ -99,7 +44,9 @@ public class WxCouponController extends BaseController { @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData listCoupon(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] WxCouponController::listCoupon"); - return listType(wxCoupon, pageNum, pageSize, 0); //券列表 + if (wxCoupon == null) wxCoupon = new WxCoupon(); + wxCoupon.setTenantId(getTenantId()); + return wxCouponService.listType(wxCoupon, pageNum, pageSize, 0); //券列表 } @ApiOperation("卡分页列表接口") @@ -109,7 +56,9 @@ public class WxCouponController extends BaseController { @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData listCard(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] WxCouponController::listCard"); - return listType(wxCoupon, pageNum, pageSize, EnumCouponType.CARD_MULTIMCH.getCode()); //卡列表 + if (wxCoupon == null) wxCoupon = new WxCoupon(); + wxCoupon.setTenantId(getTenantId()); + return wxCouponService.listType(wxCoupon, pageNum, pageSize, EnumCouponType.CARD_MULTIMCH.getCode()); //卡列表 } @ApiOperation("砍价分页列表接口") @@ -119,7 +68,9 @@ public class WxCouponController extends BaseController { @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData listPress(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] WxCouponController::listPress"); - return listType(wxCoupon, pageNum, pageSize, EnumCouponType.COUPON_PRESS.getCode()); //砍价列表 + if (wxCoupon == null) wxCoupon = new WxCoupon(); + wxCoupon.setTenantId(getTenantId()); + return wxCouponService.listType(wxCoupon, pageNum, pageSize, EnumCouponType.COUPON_PRESS.getCode()); //砍价列表 } @ApiOperation("分页列表接口") @@ -129,7 +80,9 @@ public class WxCouponController extends BaseController { @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData list(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] WxCouponController::list"); - return listType(wxCoupon, pageNum, pageSize, null); //全列表 + if (wxCoupon == null) wxCoupon = new WxCoupon(); + wxCoupon.setTenantId(getTenantId()); + return wxCouponService.listType(wxCoupon, pageNum, pageSize, null); //全列表 } @ApiOperation("新增接口") diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java index bdda8f34a..e9402d274 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java @@ -9,6 +9,9 @@ import com.iformall.domain.vo.WxCouponCVo; public interface WxCouponService { + + ResultData listType(WxCoupon wxCoupon, Integer pageNum, Integer pageSize, Integer type); + /** * 根据实体查询分页列表 * diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index ea15575de..0f48ea6a4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -3,17 +3,20 @@ package com.iformall.service.impl; import java.util.*; import java.util.stream.Collectors; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.WxCoupon; +import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.po.WxCouponMerchant; import com.iformall.domain.po.WxScreenAd; import com.iformall.domain.vo.WxCouponCVo; import com.iformall.domain.vo.WxMerchantVo; import com.iformall.enums.*; +import com.iformall.mapper.WxCouponChannelMapper; import com.iformall.mapper.WxCouponMapper; import com.iformall.mapper.WxCouponMerchantMapper; import com.iformall.mapper.WxMerchantMapper; @@ -28,6 +31,7 @@ import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; + @Service public class WxCouponServiceImpl implements WxCouponService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -53,6 +57,61 @@ public class WxCouponServiceImpl implements WxCouponService { @Autowired WxScreenAdService wxScreenAdService; + + @Autowired + WxCouponChannelMapper wxCouponChannelMapper; + + + public ResultData listType(WxCoupon wxCoupon, Integer pageNum, Integer pageSize, Integer type) { + if (null == wxCoupon) wxCoupon = new WxCoupon(); + wxCoupon.setSortColumns(WxCoupon.Field.Id_DESC); + PageInfo page = null; + if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) + wxCoupon.setStatus(null); + page = listAsPage(wxCoupon, pageNum, pageSize, type); + + List wxCouponList = page.getList(); + + if (wxCouponList.isEmpty()) { + return new ResultData(page); + } + + List ids = wxCouponList.stream().map(p -> p.getId()).collect(Collectors.toList()); + WxCouponChannel wxCouponChannel = new WxCouponChannel(); + wxCouponChannel.setTenantId(wxCoupon.getTenantId()); + wxCouponChannel.setCouponIds(ids); + wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); + //上架状态 + List list = wxCouponChannelMapper.findList(wxCouponChannel); + if (!list.isEmpty()) { + Map> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId)); + for (WxCoupon temp : wxCouponList) { + + if (groupBy.get(temp.getId()) != null) { + List channels = new ArrayList<>(); + for (WxCouponChannel tempchannel : groupBy.get(temp.getId())) { + if (!channels.contains(tempchannel.getTargetAd())) { + channels.add(tempchannel.getTargetAd()); + } + } + String sss = JSON.toJSONString(channels); + temp.setChannels(sss); + } else { + temp.setChannels(""); + } + + } + } else { + for (WxCoupon temp : wxCouponList) { + temp.setChannels(""); + } + + } + return new ResultData(page); + } + + + @Override public PageInfo listAsPage(WxCoupon record, Integer pageIndex, Integer pageSize, Integer type) { if (type == null) {