|
|
|
@@ -3,6 +3,7 @@ package com.iformall.service.impl; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
@@ -11,10 +12,12 @@ 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.WxMerchant; |
|
|
|
import com.iformall.domain.vo.WxCouponCVo; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.mapper.WxCouponMapper; |
|
|
|
import com.iformall.mapper.WxCouponMerchantMapper; |
|
|
|
import com.iformall.mapper.WxMerchantMapper; |
|
|
|
import com.iformall.service.WxCouponChannelService; |
|
|
|
import com.iformall.service.WxCouponSendService; |
|
|
|
import com.iformall.service.WxCouponService; |
|
|
|
@@ -24,6 +27,8 @@ import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import org.springframework.transaction.annotation.Isolation; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
@Service |
|
|
|
@@ -36,6 +41,9 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
@Autowired |
|
|
|
WxCouponMerchantMapper wxCouponMerchantMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxMerchantMapper wxMerchantMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCouponChannelService wxCouponChannelService; |
|
|
|
|
|
|
|
@@ -59,72 +67,82 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public Long saveOrUpdate(WxCoupon record) { |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
if (record.getId() == null) { |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
wxCouponMapper.insertSelective(record); |
|
|
|
|
|
|
|
if (record.getType().equals(EnumCouponType.COUPON_MULTIMCH) |
|
|
|
&& !record.getMerchantIds().isEmpty()) |
|
|
|
if (record.getType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) |
|
|
|
&& !record.getMerchantParams().isEmpty()) |
|
|
|
{ |
|
|
|
String[] ids = StringUtils.split(record.getMerchantIds(),","); |
|
|
|
List<WxCouponMerchant> cmList = new ArrayList<>(); |
|
|
|
|
|
|
|
Arrays.stream(ids).forEach(id -> { |
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
List<WxCouponMerchant> couponMerchantList = new ArrayList<>(); |
|
|
|
List<Integer> businessList= new ArrayList<>(); |
|
|
|
merchantParamList.forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.setMerchantId(Long.valueOf(id)); |
|
|
|
cm.setMerchantId(merchantParam.getLong("id")); |
|
|
|
cm.setParameter(merchantParam.getString("param")); |
|
|
|
cm.setCouponId(record.getId()); |
|
|
|
cm.setCreateDate(new Date()); |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
//param.put("",record.get); |
|
|
|
cm.setParameter(param.toString()); |
|
|
|
cmList.add(cm); |
|
|
|
couponMerchantList.add(cm); |
|
|
|
businessList.add(merchantParam.getInteger("business")); |
|
|
|
}); |
|
|
|
wxCouponMerchantMapper.insertList(cmList); |
|
|
|
if (businessList.stream().distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_NULL.getCode()); |
|
|
|
} else { |
|
|
|
record.setBusiness(businessList.get(0)); |
|
|
|
} |
|
|
|
|
|
|
|
wxCouponMerchantMapper.insertList(couponMerchantList); |
|
|
|
|
|
|
|
}else { |
|
|
|
WxMerchant wxMerchant = wxMerchantMapper.selectByPrimaryKey(record.getMerchantId()); |
|
|
|
if (wxMerchant != null){ |
|
|
|
record.setBusiness(wxMerchant.getBusinessId()); |
|
|
|
} |
|
|
|
} |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
record.setCreateDate(new Date()); |
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
wxCouponMapper.insertSelective(record); |
|
|
|
|
|
|
|
} else { |
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
wxCouponMapper.updateByPrimaryKeySelective(record); |
|
|
|
if (record.getType().equals(EnumCouponType.COUPON_MULTIMCH) |
|
|
|
&& !record.getMerchantIds().isEmpty()) |
|
|
|
|
|
|
|
if (record.getType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()) |
|
|
|
&& !record.getMerchantParams().isEmpty()) |
|
|
|
{ |
|
|
|
String[] ids = StringUtils.split(record.getMerchantIds(),","); |
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
|
|
|
|
WxCouponMerchant cmParam = new WxCouponMerchant(); |
|
|
|
cmParam.setCouponId(record.getId()); |
|
|
|
List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); |
|
|
|
|
|
|
|
Arrays.stream(ids).forEach(id -> { |
|
|
|
List<Integer> businessList= new ArrayList<>(); |
|
|
|
merchantParamList.stream().forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
cm.setMerchantId(Long.valueOf(id)); |
|
|
|
cm.setMerchantId(merchantParam.getLong("id")); |
|
|
|
cm.setCouponId(record.getId()); |
|
|
|
WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(cm); |
|
|
|
if (rcm != null) { |
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
//param.put("",record.get); |
|
|
|
rcm.setMerchantId(merchantParam.getLong("id")); |
|
|
|
rcm.setParameter(merchantParam.getString("param")); |
|
|
|
rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
rcm.setParameter(param.toString()); |
|
|
|
rcm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.updateByPrimaryKeySelective(rcm); |
|
|
|
}else { |
|
|
|
cm.setId(idWorker.nextId()); |
|
|
|
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
cm.setParameter(merchantParam.getString("param")); |
|
|
|
cm.setCreateDate(new Date()); |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
//param.put("",record.get); |
|
|
|
cm.setParameter(param.toString()); |
|
|
|
wxCouponMerchantMapper.insertSelective(cm); |
|
|
|
} |
|
|
|
businessList.add(merchantParam.getInteger("business")); |
|
|
|
oldList.removeIf( |
|
|
|
old->old.getCouponId().equals(record.getId()) && |
|
|
|
old.getMerchantId().equals(Long.valueOf(id))); |
|
|
|
old.getMerchantId().equals(merchantParam.getLong("id"))); |
|
|
|
}); |
|
|
|
|
|
|
|
oldList.stream().forEach(old->{ |
|
|
|
@@ -132,7 +150,24 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
old.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.updateByPrimaryKeySelective(old); |
|
|
|
}); |
|
|
|
|
|
|
|
if (businessList.stream().distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_NULL.getCode()); |
|
|
|
} else { |
|
|
|
record.setBusiness(businessList.get(0)); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
if (record.getMerchantId() != null) { |
|
|
|
WxMerchant wxMerchant = wxMerchantMapper.selectByPrimaryKey(record.getMerchantId()); |
|
|
|
if (wxMerchant != null) { |
|
|
|
record.setBusiness(wxMerchant.getBusinessId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
record.setUpdateDate(new Date()); |
|
|
|
wxCouponMapper.updateByPrimaryKeySelective(record); |
|
|
|
} |
|
|
|
return record.getId(); |
|
|
|
} |
|
|
|
@@ -141,8 +176,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
public void deleteById(Long id) { |
|
|
|
wxCouponMapper.deleteByPrimaryKey(id); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public WxCouponCVo selectDetailForCUser(WxCouponChannel record) { |
|
|
|
return wxCouponMapper.selectDetailForCUser(record); |
|
|
|
@@ -156,7 +190,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
if (query.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) |
|
|
|
&& wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { |
|
|
|
|
|
|
|
//作废所有投放频道 |
|
|
|
//下架所有投放频道 |
|
|
|
wxCouponChannelService |
|
|
|
.updateStatusByCouponId(wxCoupon.getId(), query.getTenantId(), EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); |
|
|
|
wxCouponSendService |
|
|
|
|