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 7f07a9541..fc9b8def4 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java @@ -62,6 +62,10 @@ public class WxCoupon implements Serializable { @Transient private Date enddate; + + @Transient + private String merchantIds; + /*租户ID**/ @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") private String tenantId; @@ -335,6 +339,15 @@ public class WxCoupon implements Serializable { this.enddate = enddate; } + public String getMerchantIds() { + return merchantIds; + } + + public void setMerchantIds(String merchantIds) { + this.merchantIds = merchantIds; + } + + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCouponMerchant.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponMerchant.java new file mode 100644 index 000000000..abd83c253 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCouponMerchant.java @@ -0,0 +1,159 @@ +package com.iformall.domain.po; + +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +@Table(name = "wx_coupon_merchant") +public class WxCouponMerchant implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + protected Long id; + + @Transient + protected List ids; + @Transient + protected String sortColumns; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSortColumns() { + return sortColumns; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="couponId") + private Long couponId; + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="merchantId") + private Long merchantId; + /***/ + @io.swagger.annotations.ApiModelProperty(value="",name="parameter") + private String parameter; + + /*创建时间**/ + @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") + private Date createDate; + /*修改时间**/ + @io.swagger.annotations.ApiModelProperty(value="修改时间",name="updateDate") + private Date updateDate; + + public Long getCouponId() { + return couponId; + } + + public void setCouponId(Long couponId) { + this.couponId = couponId; + } + + public Long getMerchantId() { + return merchantId; + } + + public void setMerchantId(Long merchantId) { + this.merchantId = merchantId; + } + + public String getParameter() { + return parameter; + } + + public void setParameter(String parameter) { + this.parameter = parameter; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public Date getUpdateDate() { + return updateDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + + public static enum Field + { + Id_ASC("`id` ASC"),Id_DESC("`id` DESC") + ,CouponId_ASC("`coupon_id` ASC"),CouponId_DESC("`coupon_id` DESC") + ,MerchantId_ASC("`merchant_id` ASC"),MerchantId_DESC("`merchant_id` DESC") + ,Parameter_ASC("`parameter` ASC"),Parameter_DESC("`description` DESC") + ,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC") + ,UpdateDate_ASC("`update_date` ASC"),UpdateDate_DESC("`update_date` DESC") + ; + private String value; + Field(String value){ + this.value = value; + } + public String getValue() { + return value; + } + public void setCol(String value) { + this.value = value; + } + @Override + public String toString() { + return this.getValue(); + } + } + + public void setSortColumns(WxCouponMerchant.Field... fields) + { + if (fields == null || fields.length == 0) { + return; + } + for (int k = 0; k < fields.length; k++) { + if (fields[k] == null) { + return; + } + } + StringBuilder sb = new StringBuilder(fields[0].toString()); + for (int k = 1; k < fields.length; k++) { + sb.append(","); + sb.append(fields[k].toString()); + } + this.sortColumns = sb.toString(); + } + + public void setSortColumns(String sortColumns) + { + if (sortColumns == null || "".equals(sortColumns.trim())) { + return; + } + if (sortColumns.contains(",")) { + String[] cols = sortColumns.split(","); + List fList = new java.util.ArrayList(); + for (int k = 0; k < cols.length; k++) { + fList.add(Field.valueOf(cols[k])); + } + this.setSortColumns(fList.toArray(new Field[fList.size()])); + } else { + this.setSortColumns(Field.valueOf(sortColumns)); + } + } +} diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCouponType.java b/mallinkService/src/main/java/com/iformall/enums/EnumCouponType.java index 7f85ae902..70ac17427 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumCouponType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCouponType.java @@ -5,12 +5,13 @@ package com.iformall.enums; */ public enum EnumCouponType { - // 1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券 + // 1.满减券,2.代金券,3.团购券,4.礼品券,5.停车券,6.多商户券 COUPON_MANJIAN(1, "满减券"), COUPON_DAIJIN(2, "代金券"), COUPON_TUANGOU(3, "团购券"), COUPON_LIPIN(4, "礼品券"), COUPON_TINGCHE(5, "停车券"), + COUPON_MULTIMCH(6, "多商户券"), ; public static EnumCouponType getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponMerchantMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponMerchantMapper.java new file mode 100644 index 000000000..c32e33db4 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponMerchantMapper.java @@ -0,0 +1,13 @@ +package com.iformall.mapper; + + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxCouponMerchant; + +import java.util.List; + +public interface WxCouponMerchantMapper extends CommonMapper { + + List findList(WxCouponMerchant wxCouponMerchant); + +} 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 ca5bb4936..33bd99ef5 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -1,19 +1,27 @@ package com.iformall.service.impl; +import java.time.LocalDate; import java.util.*; + +import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.gson.JsonObject; 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.vo.WxCouponCVo; import com.iformall.enums.EnumCouponChannelStatus; import com.iformall.enums.EnumCouponSendStatus; import com.iformall.enums.EnumCouponStatus; +import com.iformall.enums.EnumCouponType; import com.iformall.mapper.WxCouponMapper; +import com.iformall.mapper.WxCouponMerchantMapper; import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponSendService; import com.iformall.service.WxCouponService; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +35,10 @@ public class WxCouponServiceImpl implements WxCouponService { @Autowired WxCouponMapper wxCouponMapper; + + @Autowired + WxCouponMerchantMapper wxCouponMerchantMapper; + @Autowired WxCouponChannelService wxCouponChannelService; @@ -50,15 +62,63 @@ public class WxCouponServiceImpl implements WxCouponService { } @Override + @Transactional public Long saveOrUpdate(WxCoupon record) { + final IdWorker idWorker = IdWorker.get(); if (record.getId() == null) { - //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); - final IdWorker idWorker = IdWorker.get(); record.setId(idWorker.nextId()); wxCouponMapper.insertSelective(record); + + if (record.getType().equals(EnumCouponType.COUPON_MULTIMCH) + && !record.getMerchantIds().isEmpty()) + { + String[] ids = StringUtils.split(record.getMerchantIds(),","); + List cmList = new ArrayList<>(); + + Arrays.stream(ids).forEach(id -> { + WxCouponMerchant cm = new WxCouponMerchant(); + cm.setId(idWorker.nextId()); + cm.setMerchantId(Long.valueOf(id)); + cm.setCouponId(record.getId()); + cm.setCreateDate(new Date()); + cm.setUpdateDate(new Date()); + JSONObject param = new JSONObject(); + //param.put("",record.get); + cm.setParameter(param.toString()); + cmList.add(cm); + }); + wxCouponMerchantMapper.insertList(cmList); + } + } else { record.setUpdateDate(new Date()); wxCouponMapper.updateByPrimaryKeySelective(record); + if (record.getType().equals(EnumCouponType.COUPON_MULTIMCH) + && !record.getMerchantIds().isEmpty()) + { + String[] ids = StringUtils.split(record.getMerchantIds(),","); + Arrays.stream(ids).forEach(id -> { + WxCouponMerchant cm = new WxCouponMerchant(); + cm.setMerchantId(Long.valueOf(id)); + cm.setCouponId(record.getId()); + WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(cm); + if (rcm != null) { + JSONObject param = new JSONObject(); + //param.put("",record.get); + rcm.setParameter(param.toString()); + rcm.setUpdateDate(new Date()); + wxCouponMerchantMapper.updateByPrimaryKeySelective(rcm); + }else { + cm.setId(idWorker.nextId()); + cm.setCreateDate(new Date()); + cm.setUpdateDate(new Date()); + JSONObject param = new JSONObject(); + //param.put("",record.get); + cm.setParameter(param.toString()); + wxCouponMerchantMapper.insertSelective(cm); + } + }); + } } return record.getId(); } diff --git a/mallinkService/src/main/resources/mapper/WxCouponMerchantMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponMerchantMapper.xml new file mode 100644 index 000000000..d29514d8e --- /dev/null +++ b/mallinkService/src/main/resources/mapper/WxCouponMerchantMapper.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + `id`,`coupon_id`,`merchant_id`,`parameter`,`create_date`,`update_date` + + + + where 1 = 1 + + + and `id` = #{id} + + + + + and `coupon_id` = #{couponId} + + + + + and `merchant_id` = #{merchantId} + + + + + and `create_date` = #{createDate} + + + + + and `update_date` = #{updateDate} + + + + + and id in + + #{idItem} + + + order by ${sortColumns} + + + + + +