| @@ -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") | |||
| @@ -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<Long> 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<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<Long> 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<Field> 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)); | |||
| } | |||
| } | |||
| } | |||
| @@ -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) { | |||
| @@ -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<WxCouponMerchant, Long> { | |||
| List<WxCouponMerchant> findList(WxCouponMerchant wxCouponMerchant); | |||
| } | |||
| @@ -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<WxCouponMerchant> 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(); | |||
| } | |||
| @@ -0,0 +1,60 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.WxCouponMerchantMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponMerchant"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | |||
| <result column="parameter" jdbcType="VARCHAR" property="parameter" /> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`coupon_id`,`merchant_id`,`parameter`,`create_date`,`update_date` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != couponId "> | |||
| and `coupon_id` = #{couponId} | |||
| </if> | |||
| <if test=" null != merchantId "> | |||
| and `merchant_id` = #{merchantId} | |||
| </if> | |||
| <if test=" null != createDate "> | |||
| and `create_date` = #{createDate} | |||
| </if> | |||
| <if test=" null != updateDate "> | |||
| and `update_date` = #{updateDate} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxCouponMerchant" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_user_channel | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||