| @@ -79,6 +79,7 @@ public class WxCouponController extends BaseController { | |||||
| @SystemControllerLog(description = "券投放-新增") | @SystemControllerLog(description = "券投放-新增") | ||||
| public ResultData add(@RequestBody WxCoupon wxCoupon) { | public ResultData add(@RequestBody WxCoupon wxCoupon) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::add"); | logger.debug("[" + getIpAddr() + "] WxCouponController::add"); | ||||
| wxCoupon.setTenantId(getTenantId()); | |||||
| ResultData resultData = wxCouponService.saveOrUpdate(wxCoupon); | ResultData resultData = wxCouponService.saveOrUpdate(wxCoupon); | ||||
| if(resultData.code != 200){ | if(resultData.code != 200){ | ||||
| @@ -8,6 +8,7 @@ public interface WxCouponPasswordMapper extends CommonMapper<WxCouponPassword, L | |||||
| List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword); | List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword); | ||||
| void insertCouponPasswds(List<WxCouponPassword> pwdlist); | |||||
| int updateStatusByCouponId(Long couponId); | int updateStatusByCouponId(Long couponId); | ||||
| List<WxCouponPassword> findCouponGroupList(WxCouponPassword wxCouponPassword); | List<WxCouponPassword> findCouponGroupList(WxCouponPassword wxCouponPassword); | ||||
| @@ -36,6 +36,14 @@ public interface WxCouponPasswordService { | |||||
| * @param id | * @param id | ||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| /** | |||||
| * 生产卡密 | |||||
| * @param tenantId | |||||
| * @param couponId | |||||
| * @param inventory | |||||
| */ | |||||
| void mkPasswords(String tenantId, Long couponId, Integer inventory); | |||||
| @@ -3,6 +3,7 @@ package com.iformall.service.impl; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.domain.po.WxCouponPassword; | import com.iformall.domain.po.WxCouponPassword; | ||||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||||
| import com.iformall.mapper.WxCouponPasswordMapper; | import com.iformall.mapper.WxCouponPasswordMapper; | ||||
| import com.iformall.service.WxCouponPasswordService; | import com.iformall.service.WxCouponPasswordService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -10,6 +11,7 @@ import org.springframework.stereotype.Service; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Random; | import java.util.Random; | ||||
| @@ -47,11 +49,18 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| wxCouponPasswordMapper.deleteByPrimaryKey(id); | wxCouponPasswordMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public void mkPasswords(String tenantId, Long couponId, Integer inventory) { | public void mkPasswords(String tenantId, Long couponId, Integer inventory) { | ||||
| // 获取 coupon short 1 | |||||
| int couponShort = 0; | |||||
| // 随机字符 | |||||
| String strAll = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | 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(); | Random rand = new Random(); | ||||
| List<String> pwList = new ArrayList<>(); | List<String> pwList = new ArrayList<>(); | ||||
| while (true) { | while (true) { | ||||
| @@ -60,7 +69,7 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| int f = (int) (Math.random() * 62); | int f = (int) (Math.random() * 62); | ||||
| sb.append(strAll.charAt(f)); | sb.append(strAll.charAt(f)); | ||||
| if (j == 4) { | if (j == 4) { | ||||
| sb.append(strAll.charAt(couponShort)); | |||||
| sb.append(couponShortStr); | |||||
| } | } | ||||
| } | } | ||||
| String pwd = sb.toString(); | String pwd = sb.toString(); | ||||
| @@ -74,12 +83,26 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| break; | 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++) { | 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) { | public static void main(String[] args) { | ||||
| WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); | WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); | ||||
| long startTime = System.currentTimeMillis(); | long startTime = System.currentTimeMillis(); | ||||
| @@ -90,12 +113,7 @@ public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| long usedTime = (endTime-startTime)/1000; | long usedTime = (endTime-startTime)/1000; | ||||
| System.out.println("耗时:" + usedTime + "s"); | System.out.println("耗时:" + usedTime + "s"); | ||||
| } | } | ||||
| */ | |||||
| } | } | ||||
| @@ -67,6 +67,9 @@ import java.util.stream.Collectors; | |||||
| @Autowired | @Autowired | ||||
| WxCouponPasswordMapper couponPasswordMapper; | WxCouponPasswordMapper couponPasswordMapper; | ||||
| @Autowired | |||||
| WxCouponPasswordService couponPasswordService; | |||||
| @Override | @Override | ||||
| public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | ||||
| if (null == wxCoupon) wxCoupon = new WxCoupon(); | 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())) { | if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | ||||
| // 如果用户启用卡密,生成数据并保存 | // 如果用户启用卡密,生成数据并保存 | ||||
| couponPasswordService.mkPasswords(record.getTenantId(), record.getId(), record.getInventory()); | |||||
| } | } | ||||
| record.setCreateDate(new Date()); | record.setCreateDate(new Date()); | ||||
| @@ -64,17 +64,30 @@ | |||||
| </sql> | </sql> | ||||
| <select id="findList" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap"> | <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" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </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 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} | where status != 3 and tenant_id = #{tenantId} and coupon_id=#{couponId} | ||||
| </update> | </update> | ||||
| <select id="findCouponGroupList" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap"> | <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} | where `tenant_id` = #{tenantId} | ||||
| group by `coupon_id`,`coupon_short` | group by `coupon_id`,`coupon_short` | ||||
| </select> | </select> | ||||