diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java index fc9b8def4..5004fd20b 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java @@ -64,7 +64,7 @@ public class WxCoupon implements Serializable { @Transient - private String merchantIds; + private String merchantParams; /*租户ID**/ @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") @@ -339,12 +339,12 @@ public class WxCoupon implements Serializable { this.enddate = enddate; } - public String getMerchantIds() { - return merchantIds; + public String getMerchantParams() { + return merchantParams; } - public void setMerchantIds(String merchantIds) { - this.merchantIds = merchantIds; + public void setMerchantParams(String merchantParams) { + this.merchantParams = merchantParams; } diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java b/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java new file mode 100644 index 000000000..770388831 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java @@ -0,0 +1,42 @@ +package com.iformall.enums; + +/** + * Created by Stormeye on 2018/08/09. + */ +public enum EnumBusiness { + + // 1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券,6.多商户券 + BUSINESS_NULL(0, "无"), + BUSINESS_ID1(1, "餐饮"), + BUSINESS_ID2(2, "娱乐"), + BUSINESS_ID3(3, "服饰"), + BUSINESS_ID4(4, "亲子"), + BUSINESS_ID5(5, "超市"), + BUSINESS_ID6(6, "其他"), + ; + + public static EnumBusiness getEnum(Integer code) { + for (EnumBusiness value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumBusiness(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} 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 8c3624baf..74ae9d1ed 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -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 cmList = new ArrayList<>(); - - Arrays.stream(ids).forEach(id -> { + List merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); + List couponMerchantList = new ArrayList<>(); + List 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 merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); WxCouponMerchant cmParam = new WxCouponMerchant(); cmParam.setCouponId(record.getId()); List oldList = wxCouponMerchantMapper.findList(cmParam); - - Arrays.stream(ids).forEach(id -> { + List 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