| @@ -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<WxCouponChannel> 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<String> ids, WxCampaign record) { | |||
| WxCouponChannel wxCouponChannelQuery = new WxCouponChannel(); | |||
| wxCouponChannelQuery.setTenantId(record.getTenantId()); | |||
| wxCouponChannelQuery.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); | |||
| wxCouponChannelQuery.setSubTargetId(record.getId()); | |||
| List<WxCouponChannel> 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<WxCouponChannel> 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<WxCouponChannel> 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()); | |||