From cc6c1a12c1e466f5d5c722e15bb7386776108fcf Mon Sep 17 00:00:00 2001 From: hupeng Date: Thu, 30 Aug 2018 12:41:34 +0800 Subject: [PATCH] =?UTF-8?q?[A=E7=AB=AF][=E4=BF=AE=E6=94=B9]:=E9=A6=96?= =?UTF-8?q?=E9=A1=B5banner=E5=9B=BE=E5=88=B8=E9=80=89=E6=8B=A9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/WxCampaignServiceImpl.java | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java index cebe23097..fdba3537e 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCampaignServiceImpl.java @@ -60,6 +60,7 @@ public class WxCampaignServiceImpl implements WxCampaignService { } else { wxCampaignMapper.updateByPrimaryKeySelective(record); } + record = wxCampaignMapper.selectByPrimaryKey(record); if (record.getStatus() == 0) addOrUpdateBatch(JSONArray.parseArray(record.getCouponIds(),String.class),record); else @@ -75,21 +76,36 @@ public class WxCampaignServiceImpl implements WxCampaignService { List wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQuery); if (wxCouponChannels.size() > 0) { for (WxCouponChannel ch : wxCouponChannels) { - ch.setStatus(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); - wxCouponChannelMapper.updateByPrimaryKeySelective(ch); + ch.setStatus(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); + wxCouponChannelMapper.updateByPrimaryKeySelective(ch); } } } public void addOrUpdateBatch(List ids, WxCampaign record) { + WxCouponChannel wxCouponChannelQuery = new WxCouponChannel(); + wxCouponChannelQuery.setTenantId(record.getTenantId()); + wxCouponChannelQuery.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); + wxCouponChannelQuery.setSubTargetId(record.getId()); + List wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQuery); + for (String couponIdStr:ids) { Long couponId = Long.parseLong(couponIdStr); - saveOrUpdateCouponChannel(couponId,record); + saveOrUpdateCouponChannel(couponId, wxCouponChannels, record); + } + + if (wxCouponChannels.size() > 0) + { + for (int i = 0; i < wxCouponChannels.size(); i++) { + wxCouponChannels.get(i).setStatus(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); + wxCouponChannelMapper.updateByPrimaryKeySelective(wxCouponChannels.get(i)); + } + } } - public void saveOrUpdateCouponChannel(Long couponId, WxCampaign record){ + public void saveOrUpdateCouponChannel(Long couponId, List wxCouponChannels, WxCampaign record){ WxCoupon wxCoupon = wxCouponService.getById(couponId); if (wxCoupon == null) { @@ -98,26 +114,25 @@ public class WxCampaignServiceImpl implements WxCampaignService { if (wxCoupon.getStatus() != EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) { throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF); } - if (wxCoupon.getValidEndDate() != null && wxCoupon.getValidEndDate().after(new Date())) { + if (wxCoupon.getValidEndDate() != null && wxCoupon.getValidEndDate().before(new Date())) { throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF); } - WxCouponChannel wxCouponChannelQuery = new WxCouponChannel(); - wxCouponChannelQuery.setTenantId(record.getTenantId()); - wxCouponChannelQuery.setCouponId(couponId); - wxCouponChannelQuery.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); - wxCouponChannelQuery.setSubTargetId(record.getId()); - List wxCouponChannels = wxCouponChannelMapper.findList(wxCouponChannelQuery); - if(wxCouponChannels.size()>0){ - if(wxCouponChannels.get(0).getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { - wxCouponChannels.get(0).setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); - wxCouponChannelMapper.updateByPrimaryKeySelective(wxCouponChannels.get(0)); + if(wxCouponChannels.size()>0) { + for (int i = 0; i < wxCouponChannels.size(); i++) { + + wxCouponChannels.get(i).setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); + wxCouponChannels.get(i).setBeginTime(record.getValidStartDate()); + wxCouponChannels.get(i).setEndTime(record.getValidEndDate()); + wxCouponChannelMapper.updateByPrimaryKeySelective(wxCouponChannels.get(i)); + wxCouponChannels.remove(i); } } else { WxCouponChannel 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());