修改礼品卡生成序列号二维码
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -85,6 +85,13 @@
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>5.8.23</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>zxing-parent</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -32,7 +32,7 @@ public class LpkGiftCard {
|
||||
private Date grantDate;
|
||||
private String customerMobile;
|
||||
private String customerSid;
|
||||
|
||||
private String picUrl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yxt.yyth.api.lpkgiftcard;
|
||||
|
||||
import com.yxt.common.core.query.Query;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Fan
|
||||
* @description
|
||||
* @date 2023/11/24 10:07
|
||||
*/
|
||||
@Data
|
||||
public class LpkGiftCardListQuery implements Query {
|
||||
private String state;
|
||||
private String noStart; //序列号开始
|
||||
private String noEnd; //序列号结束
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.yxt.yyth.api.lpkgiftcard;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.yxt.common.core.vo.Vo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Fan
|
||||
* @description
|
||||
* @date 2023/11/24 10:04
|
||||
*/
|
||||
@Data
|
||||
public class LpkGiftCardListVo implements Vo {
|
||||
private String sid;
|
||||
private String createTime;
|
||||
private String remarks;
|
||||
private String giftbagSid;
|
||||
private String serialNumber;
|
||||
private String code;
|
||||
private String codeKey;
|
||||
private String state;
|
||||
private String grantName;
|
||||
private String grantDate;
|
||||
private String customerMobile;
|
||||
private String customerSid;
|
||||
private String picUrl;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.yxt.yyth.api.lpkgiftbag.LpkGiftBag;
|
||||
import com.yxt.yyth.api.lpkgiftcard.AppletVo;
|
||||
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCard;
|
||||
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCardListVo;
|
||||
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCardVo;
|
||||
import com.yxt.yyth.api.lpkstore.LpkStore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@@ -23,6 +24,7 @@ import java.util.List;
|
||||
public interface LpkGiftCardMapper extends BaseMapper<LpkGiftCard> {
|
||||
|
||||
IPage<AppletVo> getGifCardByCustomerSid(IPage<LpkGiftCard> page, @Param(Constants.WRAPPER) QueryWrapper<LpkGiftCard> qw);
|
||||
|
||||
@Select(" SELECT\n" +
|
||||
" card.*,\n" +
|
||||
" case card.state\n" +
|
||||
@@ -42,4 +44,5 @@ public interface LpkGiftCardMapper extends BaseMapper<LpkGiftCard> {
|
||||
|
||||
String selctMaxSerNum();
|
||||
|
||||
IPage<LpkGiftCardListVo> cardList(IPage<LpkGiftCard> page, @Param(Constants.WRAPPER) QueryWrapper<LpkGiftCard> qw);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,27 @@
|
||||
FROM lpk_giftcard
|
||||
WHERE LENGTH(serialNumber) = 8
|
||||
</select>
|
||||
<select id="cardList" resultType="com.yxt.yyth.api.lpkgiftcard.LpkGiftCardListVo">
|
||||
SELECT
|
||||
sid,
|
||||
date_format(createTime, '%Y-%m-%d') as createTime,
|
||||
remarks,
|
||||
giftbagSid,
|
||||
serialNumber,
|
||||
code,
|
||||
codeKey,
|
||||
`state`,
|
||||
grantName,
|
||||
date_format(grantDate, '%Y-%m-%d') as grantDate,
|
||||
customerMobile,
|
||||
customerSid,
|
||||
picUrl
|
||||
FROM
|
||||
lpk_giftcard
|
||||
<where>
|
||||
${ew.sqlSegment}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,15 +1,22 @@
|
||||
package com.yxt.yyth.biz.lpkgiftcard;
|
||||
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import com.yxt.common.core.query.PagerQuery;
|
||||
import com.yxt.common.core.result.ResultBean;
|
||||
import com.yxt.yyth.api.lpkgiftcard.BindCardDto;
|
||||
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCardDto;
|
||||
import com.yxt.yyth.api.lpkgiftcard.LpkGiftCardQuery;
|
||||
import com.yxt.common.core.vo.PagerVo;
|
||||
import com.yxt.yyth.api.lpkgiftcard.*;
|
||||
import com.yxt.yyth.api.lpkgoods.LpkGoodsVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author wangpengfei
|
||||
* @date 2023/11/21 15:03
|
||||
@@ -53,4 +60,11 @@ public class LpkGiftCardRest {
|
||||
public ResultBean generateCard(@RequestBody LpkGiftCardDto dto) {
|
||||
return lpkGiftCardService.generateCard(dto);
|
||||
}
|
||||
|
||||
@PostMapping("/cardList")
|
||||
@ApiOperation(value = "礼包卡信息列表")
|
||||
public ResultBean<PagerVo<LpkGiftCardListVo>> cardList(@RequestBody PagerQuery<LpkGiftCardListQuery> pq) {
|
||||
return lpkGiftCardService.cardList(pq);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.yxt.yyth.biz.lpkgiftcard;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.yxt.common.base.config.component.FileUploadComponent;
|
||||
import com.yxt.common.base.service.MybatisBaseService;
|
||||
import com.yxt.common.base.utils.PagerUtil;
|
||||
import com.yxt.common.base.utils.StringUtils;
|
||||
@@ -12,19 +15,25 @@ import com.yxt.common.core.result.ResultBean;
|
||||
import com.yxt.common.core.vo.PagerVo;
|
||||
import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoodsVo;
|
||||
import com.yxt.yyth.api.lpkgiftcard.*;
|
||||
import com.yxt.yyth.api.lpkgoods.LpkGoods;
|
||||
import com.yxt.yyth.api.lpkgoods.LpkGoodsQuery;
|
||||
import com.yxt.yyth.api.lpkgoods.LpkGoodsVo;
|
||||
import com.yxt.yyth.api.lpkreserveordergoods.LpkReserveOrderGoods;
|
||||
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.lpkstore.LpkStoreService;
|
||||
import org.bouncycastle.math.Primes;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author wangpengfei
|
||||
@@ -40,6 +49,8 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
LpkReserveOrderGoodsService lpkReserveOrderGoodsService;
|
||||
@Autowired
|
||||
LpkStoreService lpkStoreService;
|
||||
@Autowired
|
||||
private FileUploadComponent fileUploadComponent;
|
||||
|
||||
public ResultBean bindCard(BindCardDto bindCardDto) {
|
||||
ResultBean rb = new ResultBean().fail();
|
||||
@@ -152,10 +163,17 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
card.setState("1");
|
||||
card.setCreateTime(new DateTime());
|
||||
card.setGiftbagSid(dto.getGiftbagSid());
|
||||
String uuid = UniqueIdGenerator.generateUniqueID();
|
||||
int randomNumber = new Random().nextInt(900000) + 100000;
|
||||
card.setCodeKey(String.valueOf(randomNumber));
|
||||
card.setCode(UniqueIdGenerator.generateUniqueID());
|
||||
card.setCode(uuid);
|
||||
String maxSerNum = baseMapper.selctMaxSerNum();
|
||||
try {
|
||||
String s = genarateQRCode(uuid);
|
||||
card.setPicUrl(s);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (StringUtils.isBlank(maxSerNum)) {
|
||||
card.setSerialNumber("00000001");
|
||||
} else {
|
||||
@@ -173,4 +191,57 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
||||
}
|
||||
return rb.success();
|
||||
}
|
||||
|
||||
public ResultBean<PagerVo<LpkGiftCardListVo>> cardList(PagerQuery<LpkGiftCardListQuery> pq) {
|
||||
ResultBean rb = ResultBean.fireFail();
|
||||
LpkGiftCardListQuery query = pq.getParams();
|
||||
QueryWrapper<LpkGiftCard> qw = new QueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(query.getState())) {
|
||||
qw.eq("state", query.getState());
|
||||
}
|
||||
qw.eq("1", "1");
|
||||
String sNoStart = query.getNoStart();
|
||||
String sNoEnd = query.getNoEnd();
|
||||
qw.apply(StringUtils.isNotBlank(sNoStart), "serialNumber >=" + sNoStart).
|
||||
apply(StringUtils.isNotBlank(sNoEnd), "serialNumber <=" + sNoEnd
|
||||
);
|
||||
qw.orderByDesc("id");
|
||||
IPage<LpkGiftCard> page = PagerUtil.queryToPage(pq);
|
||||
IPage<LpkGiftCardListVo> pagging = baseMapper.cardList(page, qw);
|
||||
List<LpkGiftCardListVo> records = pagging.getRecords();
|
||||
if (!records.isEmpty()) {
|
||||
for (LpkGiftCardListVo record : records) {
|
||||
if (StringUtils.isNotBlank(record.getPicUrl())) {
|
||||
record.setPicUrl(fileUploadComponent.getUrlPrefix() + record.getPicUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
PagerVo<LpkGiftCardListVo> p = PagerUtil.pageToVo(pagging, null);
|
||||
return rb.success().setData(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成二维码
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public String genarateQRCode(String uuid) throws IOException {
|
||||
BufferedImage bufferedImage = QrCodeUtil.generate(uuid, 300, 300);
|
||||
byte[] bytes = ImgUtil.toBytes(bufferedImage, "JPG");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
//创建一个文件,待会儿将二维码写入
|
||||
String path = fileUploadComponent.getUploadPath() + sdf.format(new Date()) + "/" + uuid.substring(uuid.length() - 6) + ".jpg";
|
||||
File localFile = new File(path);
|
||||
if (!localFile.getParentFile().exists()) { //这里就判断了文件夹是否存在
|
||||
localFile.getParentFile().mkdirs(); //如果不存在就创建文件夹
|
||||
}
|
||||
if (!localFile.exists())
|
||||
localFile.createNewFile();
|
||||
//将二维码写入
|
||||
FileOutputStream out = new FileOutputStream(path);
|
||||
out.write(bytes);
|
||||
out.close();
|
||||
return sdf.format(new Date()) + "/" + uuid.substring(uuid.length() - 6) + ".jpg";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user