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