|
|
|
@@ -3,6 +3,7 @@ package com.iformall.service.impl; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.domain.po.WxCouponPassword; |
|
|
|
import com.iformall.enums.EnumCouponPasswordStatus; |
|
|
|
import com.iformall.mapper.WxCouponPasswordMapper; |
|
|
|
import com.iformall.service.WxCouponPasswordService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
@@ -47,11 +49,18 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { |
|
|
|
wxCouponPasswordMapper.deleteByPrimaryKey(id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void mkPasswords(String tenantId, Long couponId, Integer inventory) { |
|
|
|
// 获取 coupon short 1 |
|
|
|
int couponShort = 0; |
|
|
|
// 随机字符 |
|
|
|
String strAll = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
|
|
// 1.获取 coupon short 1 |
|
|
|
int couponShort = 0; |
|
|
|
String couponShortStr = "0"; |
|
|
|
WxCouponPassword pwQ = new WxCouponPassword(); |
|
|
|
pwQ.setTenantId(tenantId); |
|
|
|
List<WxCouponPassword> pwgList = wxCouponPasswordMapper.findCouponGroupList(pwQ); |
|
|
|
couponShort = pwgList.size(); |
|
|
|
couponShortStr = String.valueOf(strAll.charAt(couponShort)); |
|
|
|
// 2.随机字符 |
|
|
|
Random rand = new Random(); |
|
|
|
List<String> pwList = new ArrayList<>(); |
|
|
|
while (true) { |
|
|
|
@@ -60,7 +69,7 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { |
|
|
|
int f = (int) (Math.random() * 62); |
|
|
|
sb.append(strAll.charAt(f)); |
|
|
|
if (j == 4) { |
|
|
|
sb.append(strAll.charAt(couponShort)); |
|
|
|
sb.append(couponShortStr); |
|
|
|
} |
|
|
|
} |
|
|
|
String pwd = sb.toString(); |
|
|
|
@@ -74,12 +83,26 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// save to db |
|
|
|
// 3. save to db |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
Date curDate = new Date(); |
|
|
|
List<WxCouponPassword> couponPasswords = new ArrayList<>(); |
|
|
|
for (int i=0;i<pwList.size();i++) { |
|
|
|
System.out.println(pwList.get(i)); |
|
|
|
WxCouponPassword newOne = new WxCouponPassword(); |
|
|
|
newOne.setId(idWorker.nextId()); |
|
|
|
newOne.setTenantId(tenantId); |
|
|
|
newOne.setCouponId(couponId); |
|
|
|
newOne.setCouponShort(couponShortStr); |
|
|
|
newOne.setPassword(pwList.get(i)); |
|
|
|
newOne.setStatus(EnumCouponPasswordStatus.INIT.getCode()); |
|
|
|
newOne.setCreateDate(curDate); |
|
|
|
newOne.setUpdateDate(curDate); |
|
|
|
couponPasswords.add(newOne); |
|
|
|
} |
|
|
|
wxCouponPasswordMapper.insertCouponPasswds(couponPasswords); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
public static void main(String[] args) { |
|
|
|
WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
@@ -90,12 +113,7 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { |
|
|
|
long usedTime = (endTime-startTime)/1000; |
|
|
|
System.out.println("耗时:" + usedTime + "s"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
} |