| @@ -22,8 +22,10 @@ public class WxCouponPassword extends BaseEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | ||||
| private String tenantId; | private String tenantId; | ||||
| @io.swagger.annotations.ApiModelProperty(value="卡ID",name="couponId") | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡券ID",name="couponId") | |||||
| private Long couponId; | private Long couponId; | ||||
| @io.swagger.annotations.ApiModelProperty(value="卡券短ID",name="couponShort") | |||||
| private String couponShort; | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户名称",name="password") | @io.swagger.annotations.ApiModelProperty(value="商户名称",name="password") | ||||
| private String password; | private String password; | ||||
| @io.swagger.annotations.ApiModelProperty(value="卡密状态: 0初始1信息发出中2信息已发出3已使用",name="status") | @io.swagger.annotations.ApiModelProperty(value="卡密状态: 0初始1信息发出中2信息已发出3已使用",name="status") | ||||
| @@ -36,6 +38,8 @@ public class WxCouponPassword extends BaseEntity { | |||||
| private Date createDate; | private Date createDate; | ||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | ||||
| private Date updateDate; | private Date updateDate; | ||||
| @io.swagger.annotations.ApiModelProperty(value="过期时间",name="expireDate") | |||||
| private Date expireDate; | |||||
| } | } | ||||
| @@ -3,16 +3,17 @@ package com.iformall.enums; | |||||
| /** | /** | ||||
| * Created by Stormeye on 2019/09/17. | * Created by Stormeye on 2019/09/17. | ||||
| */ | */ | ||||
| public enum EnumCardPasswordStatus { | |||||
| public enum EnumCouponPasswordStatus { | |||||
| INIT(0, "初始"), | INIT(0, "初始"), | ||||
| MSG_SENDING(1, "消息发送中"), | MSG_SENDING(1, "消息发送中"), | ||||
| MSG_SENDED(2, "消息已发送"), | MSG_SENDED(2, "消息已发送"), | ||||
| USED(3, "已使用"); | |||||
| USED(3, "已使用"), | |||||
| CANCEL(4, "已作废"); | |||||
| public static EnumCardPasswordStatus getEnum(Integer code) { | |||||
| for (EnumCardPasswordStatus value : values()) { | |||||
| public static EnumCouponPasswordStatus getEnum(Integer code) { | |||||
| for (EnumCouponPasswordStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | if (value.getCode().equals(code)) { | ||||
| return value; | return value; | ||||
| } | } | ||||
| @@ -23,7 +24,7 @@ public enum EnumCardPasswordStatus { | |||||
| private Integer code; | private Integer code; | ||||
| private String message; | private String message; | ||||
| EnumCardPasswordStatus(Integer code, String message) { | |||||
| EnumCouponPasswordStatus(Integer code, String message) { | |||||
| this.code = code; | this.code = code; | ||||
| this.message = message; | this.message = message; | ||||
| } | } | ||||
| @@ -7,9 +7,9 @@ import com.iformall.domain.po.WxCouponPassword; | |||||
| public interface WxCouponPasswordMapper extends CommonMapper<WxCouponPassword, Long> { | public interface WxCouponPasswordMapper extends CommonMapper<WxCouponPassword, Long> { | ||||
| List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword); | List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword); | ||||
| int updateStatusByCouponId(Long couponId); | |||||
| List<WxCouponPassword> findCouponGroupList(WxCouponPassword wxCouponPassword); | |||||
| @@ -9,6 +9,10 @@ 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 java.util.ArrayList; | |||||
| import java.util.List; | |||||
| import java.util.Random; | |||||
| @Service | @Service | ||||
| public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | ||||
| @@ -42,8 +46,52 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxCouponPasswordMapper.deleteByPrimaryKey(id); | wxCouponPasswordMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| public void mkPasswords(String tenantId, Long couponId, Integer inventory) { | |||||
| // 获取 coupon short 1 | |||||
| int couponShort = 0; | |||||
| // 随机字符 | |||||
| String strAll = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |||||
| Random rand = new Random(); | |||||
| List<String> pwList = new ArrayList<>(); | |||||
| while (true) { | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| for (int j = 0; j < 9; j++) { | |||||
| int f = (int) (Math.random() * 62); | |||||
| sb.append(strAll.charAt(f)); | |||||
| if (j == 4) { | |||||
| sb.append(strAll.charAt(couponShort)); | |||||
| } | |||||
| } | |||||
| String pwd = sb.toString(); | |||||
| if (!pwList.stream().anyMatch(oPwd->oPwd.equals(pwd))) { | |||||
| pwList.add(pwd); | |||||
| } else { | |||||
| continue; | |||||
| } | |||||
| if (pwList.size() >= inventory) { | |||||
| break; | |||||
| } | |||||
| } | |||||
| // save to db | |||||
| for (int i=0;i<pwList.size();i++) { | |||||
| System.out.println(pwList.get(i)); | |||||
| } | |||||
| } | |||||
| public static void main(String[] args) { | |||||
| WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); | |||||
| long startTime = System.currentTimeMillis(); | |||||
| System.out.println(startTime); | |||||
| ll.mkPasswords("456", 12345L, 100); | |||||
| long endTime = System.currentTimeMillis(); | |||||
| System.out.println(endTime); | |||||
| long usedTime = (endTime-startTime)/1000; | |||||
| System.out.println("耗时:" + usedTime + "s"); | |||||
| } | |||||
| @@ -65,6 +65,7 @@ import java.util.stream.Collectors; | |||||
| WxCardInfoMapper wxCardInfoMapper; | WxCardInfoMapper wxCardInfoMapper; | ||||
| @Autowired | @Autowired | ||||
| WxCouponPasswordMapper couponPasswordMapper; | |||||
| @Override | @Override | ||||
| public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | ||||
| @@ -328,6 +329,11 @@ import java.util.stream.Collectors; | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| } | } | ||||
| if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||||
| // 如果用户启用卡密,生成数据并保存 | |||||
| } | |||||
| record.setCreateDate(new Date()); | record.setCreateDate(new Date()); | ||||
| record.setUpdateDate(new Date()); | record.setUpdateDate(new Date()); | ||||
| wxCouponMapper.insertSelective(record); | wxCouponMapper.insertSelective(record); | ||||
| @@ -410,11 +416,10 @@ import java.util.stream.Collectors; | |||||
| wxScreenAdService.updateStatusByCouponId(record.getId(), record.getTenantId(), EnumScreenAdStatus.INVALID.getCode()); | wxScreenAdService.updateStatusByCouponId(record.getId(), record.getTenantId(), EnumScreenAdStatus.INVALID.getCode()); | ||||
| //下架拼团券 | //下架拼团券 | ||||
| wxOrderService.updateOrderGroupStatusByCouponId(record.getId(), record.getTenantId(), EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); | wxOrderService.updateOrderGroupStatusByCouponId(record.getId(), record.getTenantId(), EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); | ||||
| //修改卡状态 | |||||
| // 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠 | |||||
| wxCardInfoMapper.updateTransferStatusByCouponId(record.getId()); | wxCardInfoMapper.updateTransferStatusByCouponId(record.getId()); | ||||
| // 下架相关卡密 | |||||
| // 卡券下架,未使用的卡密要下架 | |||||
| couponPasswordMapper.updateStatusByCouponId(record.getId()); | |||||
| } | } | ||||
| record.setUpdateDate(new Date()); | record.setUpdateDate(new Date()); | ||||
| wxCouponMapper.updateByPrimaryKeySelective(record); | wxCouponMapper.updateByPrimaryKeySelective(record); | ||||
| @@ -5,16 +5,18 @@ | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | <id column="id" jdbcType="BIGINT" property="id" /> | ||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | ||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | ||||
| <result column="coupon_short" jdbcType="VARCHAR" property="couponShort" /> | |||||
| <result column="password" jdbcType="VARCHAR" property="password" /> | <result column="password" jdbcType="VARCHAR" property="password" /> | ||||
| <result column="status" jdbcType="INTEGER" property="status" /> | <result column="status" jdbcType="INTEGER" property="status" /> | ||||
| <result column="sended_phone" jdbcType="VARCHAR" property="sendedPhone" /> | <result column="sended_phone" jdbcType="VARCHAR" property="sendedPhone" /> | ||||
| <result column="card_id" jdbcType="BIGINT" property="cardId" /> | <result column="card_id" jdbcType="BIGINT" property="cardId" /> | ||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | ||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | ||||
| <result column="expire_date" jdbcType="TIMESTAMP" property="expireDate" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`coupon_id`,`password`,`status`,`sended_phone`,`card_id`,`create_date`,`update_date` | |||||
| `id`,`tenant_id`,`coupon_id`,`coupon_short`,`password`,`status`,`sended_phone`,`card_id`,`create_date`,`update_date`,`expire_date` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -23,11 +25,14 @@ | |||||
| and `id` = #{id} | and `id` = #{id} | ||||
| </if> | </if> | ||||
| <if test=" null != tenantId "> | <if test=" null != tenantId "> | ||||
| and `tenant_id` like concat('%', #{tenantId},'%') | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | </if> | ||||
| <if test=" null != couponId "> | <if test=" null != couponId "> | ||||
| and `coupon_id` = #{couponId} | and `coupon_id` = #{couponId} | ||||
| </if> | |||||
| </if> | |||||
| <if test=" null != couponShort "> | |||||
| and `coupon_short` = #{couponShort} | |||||
| </if> | |||||
| <if test=" null != password "> | <if test=" null != password "> | ||||
| and `password` like concat('%', #{password},'%') | and `password` like concat('%', #{password},'%') | ||||
| </if> | </if> | ||||
| @@ -45,7 +50,10 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != updateDate "> | <if test=" null != updateDate "> | ||||
| and `update_date` = #{updateDate} | and `update_date` = #{updateDate} | ||||
| </if> | |||||
| </if> | |||||
| <if test=" null != expireDate "> | |||||
| and `expire_date` = #{expireDate} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -59,10 +67,17 @@ | |||||
| select <include refid="allColumns" /> from wx_card_password | select <include refid="allColumns" /> from wx_card_password | ||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <update id="updateStatusByCouponId" parameterType="Long"> | |||||
| update wx_card_password set status=4, update_date=now() | |||||
| where status != 3 and tenant_id = #{tenantId} and coupon_id=#{couponId} | |||||
| </update> | |||||
| <select id="findCouponGroupList" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap"> | |||||
| select `coupon_id`,`coupon_short` from wx_card_password | |||||
| where `tenant_id` = #{tenantId} | |||||
| group by `coupon_id`,`coupon_short` | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||