Просмотр исходного кода

[卡券][修改]:卡密批量生成

release_toaliyun_real
Stormeye Wu 6 лет назад
Родитель
Сommit
960ca22db0
6 измененных файлов: 60 добавлений и 16 удалений
  1. +1
    -0
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java
  2. +1
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCouponPasswordMapper.java
  3. +8
    -0
      mallinkService/src/main/java/com/iformall/service/WxCouponPasswordService.java
  4. +30
    -12
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java
  5. +4
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java
  6. +16
    -3
      mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml

+ 1
- 0
mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java Просмотреть файл

@@ -79,6 +79,7 @@ public class WxCouponController extends BaseController {
@SystemControllerLog(description = "券投放-新增")
public ResultData add(@RequestBody WxCoupon wxCoupon) {
logger.debug("[" + getIpAddr() + "] WxCouponController::add");
wxCoupon.setTenantId(getTenantId());

ResultData resultData = wxCouponService.saveOrUpdate(wxCoupon);
if(resultData.code != 200){


+ 1
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCouponPasswordMapper.java Просмотреть файл

@@ -8,6 +8,7 @@ public interface WxCouponPasswordMapper extends CommonMapper<WxCouponPassword, L

List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword);

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


+ 8
- 0
mallinkService/src/main/java/com/iformall/service/WxCouponPasswordService.java Просмотреть файл

@@ -36,6 +36,14 @@ public interface WxCouponPasswordService {
* @param id
*/
void deleteById(Long id);

/**
* 生产卡密
* @param tenantId
* @param couponId
* @param inventory
*/
void mkPasswords(String tenantId, Long couponId, Integer inventory);


+ 30
- 12
mallinkService/src/main/java/com/iformall/service/impl/WxCouponPasswordServiceImpl.java Просмотреть файл

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


*/
}

+ 4
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java Просмотреть файл

@@ -67,6 +67,9 @@ import java.util.stream.Collectors;
@Autowired
WxCouponPasswordMapper couponPasswordMapper;

@Autowired
WxCouponPasswordService couponPasswordService;

@Override
public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) {
if (null == wxCoupon) wxCoupon = new WxCoupon();
@@ -331,7 +334,7 @@ import java.util.stream.Collectors;

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

record.setCreateDate(new Date());


+ 16
- 3
mallinkService/src/main/resources/mapper/WxCouponPasswordMapper.xml Просмотреть файл

@@ -64,17 +64,30 @@
</sql>
<select id="findList" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap">
select <include refid="allColumns" /> from wx_card_password
select <include refid="allColumns" /> from wx_coupon_password
<include refid="dynamicWhereConditions" />
</select>

<insert id="insertCouponPasswds" parameterType="java.util.List">
INSERT INTO wx_coupon_password (`id`,`tenant_id`,`coupon_id`,`coupon_short`,`password`,`status`,`create_date`,`update_date`)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.id},#{item.tenantId},#{item.couponId},#{item.couponShort},#{item.password},#{item.status},
#{item.createDate},#{item.updateDate}
)
</foreach>
</insert>

<update id="updateStatusByCouponId" parameterType="Long">
update wx_card_password set status=4, update_date=now()
update wx_coupon_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
select `coupon_id`,`coupon_short`
from wx_coupon_password
where `tenant_id` = #{tenantId}
group by `coupon_id`,`coupon_short`
</select>


Загрузка…
Отмена
Сохранить