礼品卡生成规则
This commit is contained in:
@@ -23,6 +23,7 @@ public class LpkGiftCard {
|
|||||||
private String remarks;
|
private String remarks;
|
||||||
private String isEnable;
|
private String isEnable;
|
||||||
private String giftbagSid;
|
private String giftbagSid;
|
||||||
|
private String serialNumber;
|
||||||
private String code;
|
private String code;
|
||||||
private String codeKey;
|
private String codeKey;
|
||||||
private String state;
|
private String state;
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ import lombok.Data;
|
|||||||
@ApiModel(value = "礼品卡信息 数据传输对象", description = "礼品卡信息 数据传输对象")
|
@ApiModel(value = "礼品卡信息 数据传输对象", description = "礼品卡信息 数据传输对象")
|
||||||
@Data
|
@Data
|
||||||
public class LpkGiftCardDto implements Dto {
|
public class LpkGiftCardDto implements Dto {
|
||||||
|
private String giftbagSid;
|
||||||
|
private String num;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,4 +38,8 @@ public interface LpkGiftCardMapper extends BaseMapper<LpkGiftCard> {
|
|||||||
" LEFT JOIN lpk_giftbag bag on card.giftbagSid=bag.sid" +
|
" LEFT JOIN lpk_giftbag bag on card.giftbagSid=bag.sid" +
|
||||||
" where card.sid=#{sid}")
|
" where card.sid=#{sid}")
|
||||||
AppletVo getGifCardBySid(@Param("sid")String sid);
|
AppletVo getGifCardBySid(@Param("sid")String sid);
|
||||||
|
|
||||||
|
|
||||||
|
String selctMaxSerNum();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,9 @@
|
|||||||
${ew.sqlSegment}
|
${ew.sqlSegment}
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selctMaxSerNum" resultType="java.lang.String">
|
||||||
|
SELECT MAX(lpk_giftcard.serialNumber) as sNo FROM lpk_giftcard
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -3,6 +3,7 @@ package com.yxt.yyth.biz.lpkgiftcard;
|
|||||||
import com.yxt.common.core.query.PagerQuery;
|
import com.yxt.common.core.query.PagerQuery;
|
||||||
import com.yxt.common.core.result.ResultBean;
|
import com.yxt.common.core.result.ResultBean;
|
||||||
import com.yxt.yyth.api.lpkgiftcard.BindCardDto;
|
import com.yxt.yyth.api.lpkgiftcard.BindCardDto;
|
||||||
|
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCardDto;
|
||||||
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCardQuery;
|
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCardQuery;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -28,19 +29,28 @@ public class LpkGiftCardRest {
|
|||||||
public ResultBean wxBindMobile(@RequestBody BindCardDto bindCardDto) {
|
public ResultBean wxBindMobile(@RequestBody BindCardDto bindCardDto) {
|
||||||
return lpkGiftCardService.bindCard(bindCardDto);
|
return lpkGiftCardService.bindCard(bindCardDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/gifCardByCustomerSid")
|
@PostMapping("/gifCardByCustomerSid")
|
||||||
@ApiOperation(value = "获取客户绑定的礼包卡")
|
@ApiOperation(value = "获取客户绑定的礼包卡")
|
||||||
public ResultBean gifCardByCustomerSid(@RequestBody PagerQuery<LpkGiftCardQuery> query) {
|
public ResultBean gifCardByCustomerSid(@RequestBody PagerQuery<LpkGiftCardQuery> query) {
|
||||||
return lpkGiftCardService.getGifCardByCustomerSid(query);
|
return lpkGiftCardService.getGifCardByCustomerSid(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getGifCardBySid/{sid}")
|
@GetMapping("/getGifCardBySid/{sid}")
|
||||||
@ApiOperation(value = "获取礼包卡的详情信息")
|
@ApiOperation(value = "获取礼包卡的详情信息")
|
||||||
public ResultBean getGifCardBySid(@PathVariable("sid") String sid) {
|
public ResultBean getGifCardBySid(@PathVariable("sid") String sid) {
|
||||||
return lpkGiftCardService.getGifCardBySid(sid);
|
return lpkGiftCardService.getGifCardBySid(sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getReservationBySid/{sid}")
|
@GetMapping("/getReservationBySid/{sid}")
|
||||||
@ApiOperation(value = "查询可预约取货的详情")
|
@ApiOperation(value = "查询可预约取货的详情")
|
||||||
public ResultBean getReservationBySid(@PathVariable("sid") String sid) {
|
public ResultBean getReservationBySid(@PathVariable("sid") String sid) {
|
||||||
return lpkGiftCardService.getReservationBySid(sid);
|
return lpkGiftCardService.getReservationBySid(sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/generateCard")
|
||||||
|
@ApiOperation(value = "生成礼包卡信息")
|
||||||
|
public ResultBean generateCard(@RequestBody LpkGiftCardDto dto) {
|
||||||
|
return lpkGiftCardService.generateCard(dto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.yxt.yyth.biz.lpkgiftcard;
|
package com.yxt.yyth.biz.lpkgiftcard;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@@ -13,6 +14,7 @@ import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoodsVo;
|
|||||||
import com.yxt.yyth.api.lpkgiftcard.*;
|
import com.yxt.yyth.api.lpkgiftcard.*;
|
||||||
import com.yxt.yyth.api.lpkreserveordergoods.LpkReserveOrderGoods;
|
import com.yxt.yyth.api.lpkreserveordergoods.LpkReserveOrderGoods;
|
||||||
import com.yxt.yyth.api.lpkstore.StoreSelect;
|
import com.yxt.yyth.api.lpkstore.StoreSelect;
|
||||||
|
import com.yxt.yyth.biz.lpkgiftcard.generateRule.UniqueIdGenerator;
|
||||||
import com.yxt.yyth.biz.lpkreserveordergoods.LpkReserveOrderGoodsService;
|
import com.yxt.yyth.biz.lpkreserveordergoods.LpkReserveOrderGoodsService;
|
||||||
import com.yxt.yyth.biz.lpkstore.LpkStoreService;
|
import com.yxt.yyth.biz.lpkstore.LpkStoreService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -22,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wangpengfei
|
* @author wangpengfei
|
||||||
@@ -50,6 +53,7 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
baseMapper.updateById(lpkGiftCard);
|
baseMapper.updateById(lpkGiftCard);
|
||||||
return rb.success().setMsg("绑定成功");
|
return rb.success().setMsg("绑定成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultBean getGifCardByCustomerSid(PagerQuery<LpkGiftCardQuery> pq) {
|
public ResultBean getGifCardByCustomerSid(PagerQuery<LpkGiftCardQuery> pq) {
|
||||||
ResultBean rb = new ResultBean().fail();
|
ResultBean rb = new ResultBean().fail();
|
||||||
LpkGiftCardQuery query = pq.getParams();
|
LpkGiftCardQuery query = pq.getParams();
|
||||||
@@ -63,6 +67,7 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
return rb.success().setData(p);
|
return rb.success().setData(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultBean getGifCardBySid(String sid) {
|
public ResultBean getGifCardBySid(String sid) {
|
||||||
ResultBean rb = new ResultBean().fail();
|
ResultBean rb = new ResultBean().fail();
|
||||||
AppletVo vo = baseMapper.getGifCardBySid(sid);
|
AppletVo vo = baseMapper.getGifCardBySid(sid);
|
||||||
@@ -103,6 +108,7 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
vo.setGoodsVos(goodsVos);
|
vo.setGoodsVos(goodsVos);
|
||||||
return rb.success().setData(vo);
|
return rb.success().setData(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultBean getReservationBySid(String sid) {
|
public ResultBean getReservationBySid(String sid) {
|
||||||
ResultBean rb = new ResultBean().fail();
|
ResultBean rb = new ResultBean().fail();
|
||||||
AppletVo vo = baseMapper.getGifCardBySid(sid);
|
AppletVo vo = baseMapper.getGifCardBySid(sid);
|
||||||
@@ -132,4 +138,39 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
return rb.success().setData(vo);
|
return rb.success().setData(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResultBean generateCard(LpkGiftCardDto dto) {
|
||||||
|
ResultBean rb = ResultBean.fireFail();
|
||||||
|
if (StringUtils.isBlank(dto.getGiftbagSid())) {
|
||||||
|
return rb.setMsg("请添加礼包");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(dto.getNum())) {
|
||||||
|
return rb.setMsg("请输入生成卡片的数量");
|
||||||
|
}
|
||||||
|
int i = Integer.parseInt(dto.getNum());
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
LpkGiftCard card = new LpkGiftCard();
|
||||||
|
card.setState("1");
|
||||||
|
card.setCreateTime(new DateTime());
|
||||||
|
card.setGiftbagSid(dto.getGiftbagSid());
|
||||||
|
int randomNumber = new Random().nextInt(900000) + 100000;
|
||||||
|
card.setCodeKey(String.valueOf(randomNumber));
|
||||||
|
card.setCode(UniqueIdGenerator.generateUniqueID());
|
||||||
|
String maxSerNum = baseMapper.selctMaxSerNum();
|
||||||
|
if (StringUtils.isBlank(maxSerNum)) {
|
||||||
|
card.setSerialNumber("00000001");
|
||||||
|
} else {
|
||||||
|
int i1 = Integer.parseInt(maxSerNum);
|
||||||
|
int finNum = i1 + 1;
|
||||||
|
int length = String.valueOf(finNum).length();
|
||||||
|
int len = 8 - length;
|
||||||
|
String num = String.valueOf(finNum);
|
||||||
|
for (int a = 0; a < len; a++) {
|
||||||
|
num = "0" + num;
|
||||||
|
}
|
||||||
|
card.setSerialNumber(num);
|
||||||
|
}
|
||||||
|
baseMapper.insert(card);
|
||||||
|
}
|
||||||
|
return rb.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.yxt.yyth.biz.lpkgiftcard.generateRule;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class UniqueIdGenerator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成一个20位的唯一ID字符串,纯数字
|
||||||
|
*
|
||||||
|
* @return String 唯一的ID
|
||||||
|
*/
|
||||||
|
// 一个常见的方法是使用当前的时间戳再加上一些随机数。但是,时间戳通常只有14位(年月日时分秒),所以需要额外增加6位随机数(随机数是在时间戳的右边拼接的)。
|
||||||
|
|
||||||
|
public static String generateUniqueID() {
|
||||||
|
// 创建Calendar对象
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
|
||||||
|
// 获取当前时间
|
||||||
|
int year = calendar.get(Calendar.YEAR);
|
||||||
|
int month = calendar.get(Calendar.MONTH) + 1;
|
||||||
|
int day = calendar.get(Calendar.DATE);
|
||||||
|
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||||
|
int minute = calendar.get(Calendar.MINUTE);
|
||||||
|
int second = calendar.get(Calendar.SECOND);
|
||||||
|
|
||||||
|
// 拆分时间,去除分隔符,补0格式化
|
||||||
|
String time = String.format("%04d", year)
|
||||||
|
+ String.format("%02d", month)
|
||||||
|
+ String.format("%02d", day)
|
||||||
|
+ String.format("%02d", hour)
|
||||||
|
+ String.format("%02d", minute)
|
||||||
|
+ String.format("%02d", second);
|
||||||
|
|
||||||
|
// 生成6位的随机数
|
||||||
|
int randomNumber = new Random().nextInt(900000) + 100000;
|
||||||
|
|
||||||
|
// 合并时间和随机数,生成20位的唯一ID
|
||||||
|
String uniqueID = time + randomNumber;
|
||||||
|
return uniqueID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 生成一个唯一ID并打印
|
||||||
|
String uniqueID = generateUniqueID();
|
||||||
|
int randomNumber = new Random().nextInt(900000) + 100000;
|
||||||
|
System.out.println(randomNumber);
|
||||||
|
System.out.println("生成的唯一ID: " + uniqueID);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user