|
@@ -9,10 +9,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.usky.dxtop.common.constant.UserConstants;
|
|
import com.usky.dxtop.common.constant.UserConstants;
|
|
import com.usky.dxtop.common.core.page.CommonPage;
|
|
import com.usky.dxtop.common.core.page.CommonPage;
|
|
import com.usky.dxtop.common.exception.CustomException;
|
|
import com.usky.dxtop.common.exception.CustomException;
|
|
-import com.usky.dxtop.common.utils.QRCodeUtil;
|
|
|
|
import com.usky.dxtop.common.utils.SecurityUtils;
|
|
import com.usky.dxtop.common.utils.SecurityUtils;
|
|
import com.usky.dxtop.common.utils.StringUtils;
|
|
import com.usky.dxtop.common.utils.StringUtils;
|
|
-import com.usky.dxtop.common.utils.sign.Base64;
|
|
|
|
import com.usky.dxtop.mapper.QrCodeMapper;
|
|
import com.usky.dxtop.mapper.QrCodeMapper;
|
|
import com.usky.dxtop.model.QrCode;
|
|
import com.usky.dxtop.model.QrCode;
|
|
import com.usky.dxtop.model.TopChannel;
|
|
import com.usky.dxtop.model.TopChannel;
|
|
@@ -22,12 +20,10 @@ import com.usky.dxtop.service.TopChannelService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
-import org.springframework.util.FastByteArrayOutputStream;
|
|
|
|
|
|
|
|
-import javax.imageio.ImageIO;
|
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
|
+import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -50,27 +46,12 @@ public class QrCodeServiceImpl extends ServiceImpl<QrCodeMapper, QrCode> impleme
|
|
@Override
|
|
@Override
|
|
public boolean add(QrCode qrCode) {
|
|
public boolean add(QrCode qrCode) {
|
|
try {
|
|
try {
|
|
- String s = sysConfigService.selectConfigByKey("app.pay.path");
|
|
|
|
Optional.ofNullable(qrCode.getTopChannelId())
|
|
Optional.ofNullable(qrCode.getTopChannelId())
|
|
|
|
+ .filter(cId -> 0L != cId)
|
|
.orElseThrow(() ->new CustomException("渠道编号不能为空"));
|
|
.orElseThrow(() ->new CustomException("渠道编号不能为空"));
|
|
TopChannel topChannel = topChannelService.getById(qrCode.getTopChannelId());
|
|
TopChannel topChannel = topChannelService.getById(qrCode.getTopChannelId());
|
|
Optional.ofNullable(topChannel)
|
|
Optional.ofNullable(topChannel)
|
|
.orElseThrow(() ->new CustomException("渠道不能为空"));
|
|
.orElseThrow(() ->new CustomException("渠道不能为空"));
|
|
- String payPath = String.format("%s%s",s,topChannel.getId());
|
|
|
|
- //生成二维码
|
|
|
|
- BufferedImage image = QRCodeUtil.encode(payPath, null, true);
|
|
|
|
- // 转换流信息写出
|
|
|
|
- FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- ImageIO.write(image, "jpg", os);
|
|
|
|
- }
|
|
|
|
- catch (IOException e)
|
|
|
|
- {
|
|
|
|
- throw new CustomException("接口异常"+e.getMessage());
|
|
|
|
- }
|
|
|
|
- String encode = Base64.encode(os.toByteArray());
|
|
|
|
- qrCode.setQrPath(encode);
|
|
|
|
qrCode.setCreateBy(SecurityUtils.getUsername());
|
|
qrCode.setCreateBy(SecurityUtils.getUsername());
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
throw new CustomException("生成二维码图片失败");
|
|
throw new CustomException("生成二维码图片失败");
|
|
@@ -94,9 +75,14 @@ public class QrCodeServiceImpl extends ServiceImpl<QrCodeMapper, QrCode> impleme
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public CommonPage<QrCode> list(Integer current,Integer size,String name) {
|
|
public CommonPage<QrCode> list(Integer current,Integer size,String name) {
|
|
|
|
+ String payPath = sysConfigService.selectConfigByKey("app.pay.path");
|
|
IPage<QrCode> page = new Page<>(current, size);
|
|
IPage<QrCode> page = new Page<>(current, size);
|
|
page = baseMapper.list(page,name);
|
|
page = baseMapper.list(page,name);
|
|
- return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
|
|
|
|
|
|
+ List<QrCode> collect = page.getRecords()
|
|
|
|
+ .stream()
|
|
|
|
+ .peek(qrCode -> qrCode.setQrPath(String.format("%s%s", payPath, qrCode.getTopChannelId())))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ return new CommonPage<>(collect,page.getTotal(),page.getCurrent(),page.getSize());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|