瀏覽代碼

[卡券][修改]:卡密

release_toaliyun_real
Stormeye Wu 6 年之前
父節點
當前提交
bc161ff7fb
共有 6 個檔案被更改,包括 95 行新增22 行删除
  1. +5
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxCouponPassword.java
  2. +6
    -5
      mallinkService/src/main/java/com/iformall/enums/EnumCouponPasswordStatus.java
  3. +2
    -2
      mallinkService/src/main/java/com/iformall/mapper/WxCouponPasswordMapper.java
  4. +50
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java
  5. +9
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java
  6. +23
    -8
      mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml

+ 5
- 1
mallinkService/src/main/java/com/iformall/domain/po/WxCouponPassword.java 查看文件

@@ -22,8 +22,10 @@ public class WxCouponPassword extends BaseEntity {
@io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId")
private String tenantId;
@io.swagger.annotations.ApiModelProperty(value="卡ID",name="couponId")
@io.swagger.annotations.ApiModelProperty(value="卡ID",name="couponId")
private Long couponId;
@io.swagger.annotations.ApiModelProperty(value="卡券短ID",name="couponShort")
private String couponShort;
@io.swagger.annotations.ApiModelProperty(value="商户名称",name="password")
private String password;
@io.swagger.annotations.ApiModelProperty(value="卡密状态: 0初始1信息发出中2信息已发出3已使用",name="status")
@@ -36,6 +38,8 @@ public class WxCouponPassword extends BaseEntity {
private Date createDate;
@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate")
private Date updateDate;
@io.swagger.annotations.ApiModelProperty(value="过期时间",name="expireDate")
private Date expireDate;


}

mallinkService/src/main/java/com/iformall/enums/EnumCardPasswordStatus.java → mallinkService/src/main/java/com/iformall/enums/EnumCouponPasswordStatus.java 查看文件

@@ -3,16 +3,17 @@ package com.iformall.enums;
/**
* Created by Stormeye on 2019/09/17.
*/
public enum EnumCardPasswordStatus {
public enum EnumCouponPasswordStatus {


INIT(0, "初始"),
MSG_SENDING(1, "消息发送中"),
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)) {
return value;
}
@@ -23,7 +24,7 @@ public enum EnumCardPasswordStatus {
private Integer code;
private String message;

EnumCardPasswordStatus(Integer code, String message) {
EnumCouponPasswordStatus(Integer code, String message) {
this.code = code;
this.message = message;
}

+ 2
- 2
mallinkService/src/main/java/com/iformall/mapper/WxCouponPasswordMapper.java 查看文件

@@ -7,9 +7,9 @@ import com.iformall.domain.po.WxCouponPassword;
public interface WxCouponPasswordMapper extends CommonMapper<WxCouponPassword, Long> {

List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword);

int updateStatusByCouponId(Long couponId);
List<WxCouponPassword> findCouponGroupList(WxCouponPassword wxCouponPassword);


+ 50
- 2
mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java 查看文件

@@ -9,6 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class WxCouponPasswordServiceImpl implements WxCouponPasswordService {
@@ -42,8 +46,52 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService {
public void deleteById(Long 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");
}




+ 9
- 4
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java 查看文件

@@ -65,6 +65,7 @@ import java.util.stream.Collectors;
WxCardInfoMapper wxCardInfoMapper;

@Autowired
WxCouponPasswordMapper couponPasswordMapper;

@Override
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);
}

if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) {
// 如果用户启用卡密,生成数据并保存

}

record.setCreateDate(new Date());
record.setUpdateDate(new Date());
wxCouponMapper.insertSelective(record);
@@ -410,11 +416,10 @@ import java.util.stream.Collectors;
wxScreenAdService.updateStatusByCouponId(record.getId(), record.getTenantId(), EnumScreenAdStatus.INVALID.getCode());
//下架拼团券
wxOrderService.updateOrderGroupStatusByCouponId(record.getId(), record.getTenantId(), EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode());
//修改卡状态
// 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠
wxCardInfoMapper.updateTransferStatusByCouponId(record.getId());
// 下架相关卡密


// 卡券下架,未使用的卡密要下架
couponPasswordMapper.updateStatusByCouponId(record.getId());
}
record.setUpdateDate(new Date());
wxCouponMapper.updateByPrimaryKeySelective(record);


+ 23
- 8
mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml 查看文件

@@ -5,16 +5,18 @@
<id column="id" jdbcType="BIGINT" property="id" />
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
<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="status" jdbcType="INTEGER" property="status" />
<result column="sended_phone" jdbcType="VARCHAR" property="sendedPhone" />
<result column="card_id" jdbcType="BIGINT" property="cardId" />
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
<result column="expire_date" jdbcType="TIMESTAMP" property="expireDate" />
</resultMap>
<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 id="dynamicWhereConditions">
@@ -23,11 +25,14 @@
and `id` = #{id}
</if>
<if test=" null != tenantId ">
and `tenant_id` like concat('%', #{tenantId},'%')
and `tenant_id` = #{tenantId}
</if>
<if test=" null != couponId ">
and `coupon_id` = #{couponId}
</if>
</if>
<if test=" null != couponShort ">
and `coupon_short` = #{couponShort}
</if>
<if test=" null != password ">
and `password` like concat('%', #{password},'%')
</if>
@@ -45,7 +50,10 @@
</if>
<if test=" null != updateDate ">
and `update_date` = #{updateDate}
</if>
</if>
<if test=" null != expireDate ">
and `expire_date` = #{expireDate}
</if>
<if test=" null != ids ">
and id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
@@ -59,10 +67,17 @@
select <include refid="allColumns" /> from wx_card_password
<include refid="dynamicWhereConditions" />
</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>

Loading…
取消
儲存