Просмотр исходного кода

[A端][需求]:多商户通用券增加业态支持

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
039a6ff695
3 измененных файлов: 114 добавлений и 38 удалений
  1. +5
    -5
      mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java
  2. +42
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumBusiness.java
  3. +67
    -33
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java

+ 5
- 5
mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java Просмотреть файл

@@ -64,7 +64,7 @@ public class WxCoupon implements Serializable {




@Transient @Transient
private String merchantIds;
private String merchantParams;


/*租户ID**/ /*租户ID**/
@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
@@ -339,12 +339,12 @@ public class WxCoupon implements Serializable {
this.enddate = enddate; 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;
} }






+ 42
- 0
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;
}
}

+ 67
- 33
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.time.LocalDate;
import java.util.*; import java.util.*;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; 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.WxCoupon;
import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.po.WxCouponChannel;
import com.iformall.domain.po.WxCouponMerchant; import com.iformall.domain.po.WxCouponMerchant;
import com.iformall.domain.po.WxMerchant;
import com.iformall.domain.vo.WxCouponCVo; import com.iformall.domain.vo.WxCouponCVo;
import com.iformall.enums.*; import com.iformall.enums.*;
import com.iformall.mapper.WxCouponMapper; import com.iformall.mapper.WxCouponMapper;
import com.iformall.mapper.WxCouponMerchantMapper; import com.iformall.mapper.WxCouponMerchantMapper;
import com.iformall.mapper.WxMerchantMapper;
import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponChannelService;
import com.iformall.service.WxCouponSendService; import com.iformall.service.WxCouponSendService;
import com.iformall.service.WxCouponService; import com.iformall.service.WxCouponService;
@@ -24,6 +27,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker; import com.iformall.common.IdWorker;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;


@Service @Service
@@ -36,6 +41,9 @@ public class WxCouponServiceImpl implements WxCouponService {
@Autowired @Autowired
WxCouponMerchantMapper wxCouponMerchantMapper; WxCouponMerchantMapper wxCouponMerchantMapper;


@Autowired
WxMerchantMapper wxMerchantMapper;

@Autowired @Autowired
WxCouponChannelService wxCouponChannelService; WxCouponChannelService wxCouponChannelService;


@@ -59,72 +67,82 @@ public class WxCouponServiceImpl implements WxCouponService {
} }


@Override @Override
@Transactional
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public Long saveOrUpdate(WxCoupon record) { public Long saveOrUpdate(WxCoupon record) {
final IdWorker idWorker = IdWorker.get(); final IdWorker idWorker = IdWorker.get();
if (record.getId() == null) { 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(); WxCouponMerchant cm = new WxCouponMerchant();
cm.setId(idWorker.nextId()); cm.setId(idWorker.nextId());
cm.setMerchantId(Long.valueOf(id));
cm.setMerchantId(merchantParam.getLong("id"));
cm.setParameter(merchantParam.getString("param"));
cm.setCouponId(record.getId()); cm.setCouponId(record.getId());
cm.setCreateDate(new Date()); cm.setCreateDate(new Date());
cm.setUpdateDate(new Date()); cm.setUpdateDate(new Date());
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); 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 { } 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(); WxCouponMerchant cmParam = new WxCouponMerchant();
cmParam.setCouponId(record.getId()); cmParam.setCouponId(record.getId());
List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam);
Arrays.stream(ids).forEach(id -> {
List<Integer> businessList= new ArrayList<>();
merchantParamList.stream().forEach(merchantParam -> {
WxCouponMerchant cm = new WxCouponMerchant(); WxCouponMerchant cm = new WxCouponMerchant();
cm.setMerchantId(Long.valueOf(id));
cm.setMerchantId(merchantParam.getLong("id"));
cm.setCouponId(record.getId()); cm.setCouponId(record.getId());
WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(cm); WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(cm);
if (rcm != null) { 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.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
rcm.setParameter(param.toString());
rcm.setUpdateDate(new Date()); rcm.setUpdateDate(new Date());
wxCouponMerchantMapper.updateByPrimaryKeySelective(rcm); wxCouponMerchantMapper.updateByPrimaryKeySelective(rcm);
}else { }else {
cm.setId(idWorker.nextId()); cm.setId(idWorker.nextId());
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
cm.setParameter(merchantParam.getString("param"));
cm.setCreateDate(new Date()); cm.setCreateDate(new Date());
cm.setUpdateDate(new Date()); cm.setUpdateDate(new Date());
JSONObject param = new JSONObject();
//param.put("",record.get);
cm.setParameter(param.toString());
wxCouponMerchantMapper.insertSelective(cm); wxCouponMerchantMapper.insertSelective(cm);
} }
businessList.add(merchantParam.getInteger("business"));
oldList.removeIf( oldList.removeIf(
old->old.getCouponId().equals(record.getId()) && old->old.getCouponId().equals(record.getId()) &&
old.getMerchantId().equals(Long.valueOf(id)));
old.getMerchantId().equals(merchantParam.getLong("id")));
}); });


oldList.stream().forEach(old->{ oldList.stream().forEach(old->{
@@ -132,7 +150,24 @@ public class WxCouponServiceImpl implements WxCouponService {
old.setUpdateDate(new Date()); old.setUpdateDate(new Date());
wxCouponMerchantMapper.updateByPrimaryKeySelective(old); 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(); return record.getId();
} }
@@ -141,8 +176,7 @@ public class WxCouponServiceImpl implements WxCouponService {
public void deleteById(Long id) { public void deleteById(Long id) {
wxCouponMapper.deleteByPrimaryKey(id); wxCouponMapper.deleteByPrimaryKey(id);
} }


@Override @Override
public WxCouponCVo selectDetailForCUser(WxCouponChannel record) { public WxCouponCVo selectDetailForCUser(WxCouponChannel record) {
return wxCouponMapper.selectDetailForCUser(record); return wxCouponMapper.selectDetailForCUser(record);
@@ -156,7 +190,7 @@ public class WxCouponServiceImpl implements WxCouponService {
if (query.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) if (query.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())
&& wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { && wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) {


//作废所有投放频道
//下架所有投放频道
wxCouponChannelService wxCouponChannelService
.updateStatusByCouponId(wxCoupon.getId(), query.getTenantId(), EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); .updateStatusByCouponId(wxCoupon.getId(), query.getTenantId(), EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode());
wxCouponSendService wxCouponSendService


Загрузка…
Отмена
Сохранить