From 6d858562073c702158f099cffc71c3554b0e6485 Mon Sep 17 00:00:00 2001 From: mashuai Date: Tue, 27 Aug 2024 17:14:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=B4=AD=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../purchase/domain/BackstageApplication.java | 63 +++++ .../mapper/BpmPurchaseBindMapper.java | 11 +- .../impl/BpmPurchaseBindServiceImpl.java | 244 +++++++++++------- .../com/bonus/purchase/utils/Constants.java | 5 + .../com/bonus/purchase/utils/QrCodeUtils.java | 171 ++++++++---- .../bonus/purchase/vo/PurchaseAcceptVo.java | 3 + .../java/com/bonus/purchase/vo/QrUrlVo.java | 27 ++ .../mapper/BpmPurchaseAcceptMapper.xml | 3 +- .../mapper/BpmPurchaseBindMapper.xml | 30 ++- 9 files changed, 417 insertions(+), 140 deletions(-) create mode 100644 bonus-modules/bonus-task/src/main/java/com/bonus/purchase/domain/BackstageApplication.java create mode 100644 bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/QrUrlVo.java diff --git a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/domain/BackstageApplication.java b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/domain/BackstageApplication.java new file mode 100644 index 0000000..21f3dc0 --- /dev/null +++ b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/domain/BackstageApplication.java @@ -0,0 +1,63 @@ +package com.bonus.purchase.domain; + +/** + * 二维码类路径 + * @Author ma_sh + * @create 2024/8/27 13:56 + */ +public class BackstageApplication { + + private final static String CS_LOGIN_PATH = "ahjj.jypxks.com:9988"; + // private final static String CS_LOGIN_PATH = "112.30.107.201:9988"; + //测试环境 + //private final static String CS_LOGIN_PATH = "192.168.0.14:2011"; + + private final static String CS_USER_NAME = "root"; + + private final static String CS_PASSWORD = "bonusadmin"; + + private final static String CS_EP_ID = "system"; + + private final static String url = "http://ahjj.jypxks.com:9988/imw/"; + // private final static String url = "http://192.168.0.6:18082/imt_cs/"; + //private final static String url = "http://192.168.0.14:2011/imw_cs/"; + + + + private final static String imageUrlPrefix = "http://ahjj.jypxks.com:9988/imw/images/"; + + //测试环境 + //private final static String imageUrlPrefix = "http://192.168.0.14:2011/imt_cs/images/"; + + private final static String fileUrlPrefix = "http://ahjj.jypxks.com:9988/imw/maTypeFile/"; + //测试环境 + // private final static String fileUrlPrefix = "http://192.168.0.14:2011/imt_cs/maTypeFile/"; + + public static String getCsLoginPath() { + return CS_LOGIN_PATH; + } + + public static String getCsUserName() { + return CS_USER_NAME; + } + + public static String getCsPassword() { + return CS_PASSWORD; + } + + public static String getCsEpId() { + return CS_EP_ID; + } + + public static String getUrl() { + return url; + } + + public static String getImageUrlPrefix(){ + return imageUrlPrefix; + } + + public static String getFileurlprefix() { + return fileUrlPrefix; + } +} diff --git a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/mapper/BpmPurchaseBindMapper.java b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/mapper/BpmPurchaseBindMapper.java index 3a302fb..e5eb6b9 100644 --- a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/mapper/BpmPurchaseBindMapper.java +++ b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/mapper/BpmPurchaseBindMapper.java @@ -4,7 +4,9 @@ import com.bonus.purchase.dto.PurchaseBindDto; import com.bonus.purchase.dto.PurchaseDto; import com.bonus.purchase.vo.PurchaseAcceptVo; import com.bonus.purchase.vo.PurchaseVo; +import com.bonus.purchase.vo.QrUrlVo; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -40,7 +42,7 @@ public interface BpmPurchaseBindMapper { * 更新状态 * @param id */ - void updateStatus(String id); + void updateStatus(@Param("id") String id, @Param("purchaseId") String purchaseId); /** * 查询状态 @@ -48,4 +50,11 @@ public interface BpmPurchaseBindMapper { * @return */ List selectStatus(PurchaseDto purchaseDto); + + /** + * 根据任务id查询二维码 + * @param purchaseDto + * @return + */ + List selectQrCode(PurchaseDto purchaseDto); } diff --git a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/service/impl/BpmPurchaseBindServiceImpl.java b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/service/impl/BpmPurchaseBindServiceImpl.java index 127ddfa..ec7e4b1 100644 --- a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/service/impl/BpmPurchaseBindServiceImpl.java +++ b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/service/impl/BpmPurchaseBindServiceImpl.java @@ -2,29 +2,26 @@ package com.bonus.purchase.service.impl; import com.alibaba.nacos.common.utils.CollectionUtils; import com.bonus.common.core.utils.DateTimeHelper; +import com.bonus.purchase.domain.BackstageApplication; import com.bonus.purchase.dto.PurchaseBindDto; import com.bonus.purchase.dto.PurchaseDto; import com.bonus.purchase.mapper.BpmPurchaseAcceptMapper; import com.bonus.purchase.mapper.BpmPurchaseBindMapper; import com.bonus.purchase.service.BpmPurchaseBindService; +import com.bonus.purchase.utils.Constants; import com.bonus.purchase.utils.QrCodeUtils; import com.bonus.purchase.vo.PurchaseAcceptVo; import com.bonus.purchase.vo.PurchaseVo; +import com.bonus.purchase.vo.QrUrlVo; import com.google.zxing.WriterException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.io.*; import java.util.List; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -78,65 +75,139 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService { @Transactional(rollbackFor = Exception.class) public void downloadQrCode(HttpServletResponse response, PurchaseDto purchaseDto) { //生成二维码 - if (purchaseDto.getId() != null) { - isDownLoad(purchaseDto); - String genMonth = DateTimeHelper.getNowMonth(); - //根据月份查找code - List codeList = mapper.select(genMonth); - int num = 0; - if (CollectionUtils.isNotEmpty(codeList)) { - PurchaseBindDto purchaseBindDto = codeList.get(0); - num = Integer.parseInt(purchaseBindDto.getMaCode().split("-")[1]); + if (purchaseDto.getId() == null && purchaseDto.getPurchaseId() == null) { + throw new RuntimeException("外层id和内层id不能同时为空"); + } + String genMonth = DateTimeHelper.getNowMonth(); + List codeList = mapper.select(genMonth); + try (OutputStream os = response.getOutputStream(); + ZipOutputStream zos = new ZipOutputStream(os)) { + List statusList = mapper.selectStatus(purchaseDto); + if (CollectionUtils.isEmpty(statusList)) { + return; } + if (purchaseDto.getId() != null) { + //外层二维码下载 + handlePurchaseDto(purchaseDto, codeList, statusList, zos, genMonth); + } else if (purchaseDto.getPurchaseId() != null) { + //内层二维码下载 + handlePurchaseId(purchaseDto, codeList, statusList, zos, genMonth); + } + zos.flush(); + } catch (WriterException | IOException e) { + e.printStackTrace(); + } + } + + /** + * 外层二维码下载 + * @param purchaseDto + * @param codeList + * @param statusList + * @param zos + * @param genMonth + * @throws IOException + * @throws WriterException + */ + private void handlePurchaseDto(PurchaseDto purchaseDto, List codeList, List statusList, ZipOutputStream zos, String genMonth) throws IOException, WriterException { + for (Integer status : statusList) { + if (status == 1) { + Select(purchaseDto, zos); + } else if (status == 0) { + processNotDownloadedDetails(purchaseDto, codeList, zos, genMonth); + } + } + } + + /** + * 内层二维码下载 + * @param purchaseDto + * @param codeList + * @param statusList + * @param zos + * @param genMonth + * @throws IOException + * @throws WriterException + */ + private void handlePurchaseId(PurchaseDto purchaseDto, List codeList, List statusList, ZipOutputStream zos, String genMonth) throws IOException, WriterException { + if (statusList.get(0) == 1) { + Select(purchaseDto, zos); + } else { + int num = getInitialNum(codeList); List details = acceptMapper.getDetails(purchaseDto); - try { - Path downloadDir = Paths.get("qr_codes"); - Files.createDirectories(downloadDir); - ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); - if (CollectionUtils.isNotEmpty(details)) { - for (int i = 0; i < details.size(); i++) { - String materialModel = details.get(i).getMaterialModel(); - String materialName = details.get(i).getMaterialName(); - Integer typeId = details.get(i).getTypeId(); - Integer checkNum = details.get(i).getCheckNum(); - getString(purchaseDto, genMonth, num, downloadDir, zos, materialModel, materialName, typeId, checkNum); - num = num + checkNum; - } - zos.flush(); - zos.close(); - } - } catch (WriterException | IOException e) { - e.printStackTrace(); + if (CollectionUtils.isNotEmpty(details)) { + PurchaseAcceptVo detail = details.get(0); + purchaseDto.setId(detail.getTaskId()); + getString(purchaseDto, genMonth, num, zos, detail.getMaterialModel(), detail.getMaterialName(), detail.getTypeId(), detail.getCheckNum()); + extractedUpStatus(purchaseDto); } - }else if (purchaseDto.getPurchaseId() != null) { - isDownLoad(purchaseDto); - String genMonth = DateTimeHelper.getNowMonth(); - //根据月份查找code - List codeList = mapper.select(genMonth); - int num = 0; - if (CollectionUtils.isNotEmpty(codeList)) { - PurchaseBindDto purchaseBindDto = codeList.get(0); - num = Integer.parseInt(purchaseBindDto.getMaCode().split("-")[1]); + } + } + + /** + * 获取初始化num + * @param codeList + * @return + */ + private int getInitialNum(List codeList) { + if (CollectionUtils.isNotEmpty(codeList)) { + PurchaseBindDto purchaseBindDto = codeList.get(0); + return Integer.parseInt(purchaseBindDto.getMaCode().split("-")[1]); + } + return 0; + } + + /** + * 外层二维码下载详情处理 + * @param purchaseDto + * @param codeList + * @param zos + * @param genMonth + * @throws IOException + * @throws WriterException + */ + private void processNotDownloadedDetails(PurchaseDto purchaseDto, List codeList, ZipOutputStream zos, String genMonth) throws IOException, WriterException { + int num = getInitialNum(codeList); + List details = acceptMapper.getDetails(purchaseDto); + if (CollectionUtils.isNotEmpty(details)) { + List notDownloadedDetails = details.stream() + .filter(detail -> detail.getIsDownload() == 0) + .collect(Collectors.toList()); + for (PurchaseAcceptVo detail : notDownloadedDetails) { + getString(purchaseDto, genMonth, num, zos, detail.getMaterialModel(), detail.getMaterialName(), detail.getTypeId(), detail.getCheckNum()); + num += detail.getCheckNum() / Constants.CARDINAL_NUMBER; } - List details = acceptMapper.getDetails(purchaseDto); - try { - Path downloadDir = Paths.get("qr_codes"); - Files.createDirectories(downloadDir); - ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); - if(CollectionUtils.isNotEmpty(details)) { - String materialModel = details.get(0).getMaterialModel(); - String materialName = details.get(0).getMaterialName(); - Integer typeId = details.get(0).getTypeId(); - Integer checkNum = details.get(0).getCheckNum(); - purchaseDto.setId(details.get(0).getTaskId()); - getString(purchaseDto, genMonth, num, downloadDir, zos, materialModel, materialName, typeId, checkNum); - zos.flush(); - zos.close(); - } - } catch (WriterException | IOException e) { - e.printStackTrace(); + extractedUpStatus(purchaseDto); + } + } + + /** + * 查询方法抽取 + * @param purchaseDto + * @param zos + * @throws IOException + */ + private void Select(PurchaseDto purchaseDto, ZipOutputStream zos) throws IOException { + List list = mapper.selectQrCode(purchaseDto); + if (CollectionUtils.isNotEmpty(list)) { + for (QrUrlVo qrUrlVo : list) { + String materialModel = qrUrlVo.getMaterialModel(); + String materialName = qrUrlVo.getMaterialName(); + String path = qrUrlVo.getQrUrl(); + String qrCode = qrUrlVo.getQrCode(); + path = path.replace("filePath", "/data/imw"); + extracted(zos, materialModel, materialName, qrCode, path); } - } + } + } + + /** + * 修改任务表方法抽取 + * @param purchaseDto + */ + private void extractedUpStatus(PurchaseDto purchaseDto) { + //修改任务表的是否下载状态 + mapper.updateStatus(purchaseDto.getId(), purchaseDto.getPurchaseId()); } /** @@ -144,7 +215,6 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService { * @param purchaseDto * @param genMonth * @param num - * @param downloadDir * @param zos * @param materialModel * @param materialName @@ -153,48 +223,48 @@ public class BpmPurchaseBindServiceImpl implements BpmPurchaseBindService { * @throws WriterException * @throws IOException */ - private void getString(PurchaseDto purchaseDto, String genMonth, int num, Path downloadDir, ZipOutputStream zos, String materialModel, String materialName, Integer typeId, Integer checkNum) throws WriterException, IOException { - for (int j = 1; j <= checkNum / 1000; j++) { + private void getString(PurchaseDto purchaseDto, String genMonth, int num, ZipOutputStream zos, String materialModel, String materialName, Integer typeId, Integer checkNum) throws WriterException, IOException { + for (int j = 1; j <= checkNum / Constants.CARDINAL_NUMBER; j++) { genMonth = genMonth.replace("-", ""); String code = genMonth + "-" + String.format("%5d", num + j).replace(" ", "0"); // 新购管理-二维码打印-新增 - String qrUrl = "D://files/" + "images" + "/" + code + ".jpg"; - String Path = "[" + materialModel + "-" + materialName + "]" + code + ".jpg"; - String baseText = "QR Code " + j; - BufferedImage qrCodeImage = QrCodeUtils.generateQRCodeImage(baseText, 300, 300); - java.nio.file.Path filePath = downloadDir.resolve(Path); - QrCodeUtils.saveQRCodeImage(qrCodeImage, filePath); + String url = BackstageApplication.getUrl() + "backstage/machine/qrCodePage?qrcode=" + code; + // // 二维码的图片格式 + String format = "jpg"; + //设置路径 + String mkdirsName = "images"; + // linux 系统路径 + String saveDirectory = "/data/imw/" + mkdirsName + "/"; + String os = System.getProperty("os.name"); + if (os.toLowerCase().startsWith("win")) { + //本地路径 + saveDirectory = "D://files/" + mkdirsName + "/"; + } + // 生成二维码 + File files = new File(saveDirectory); + if (!files.exists()) { + files.mkdirs(); + } + QrCodeUtils.generateQRImage(url, saveDirectory, code + ".jpg", format); + String qrUrl = saveDirectory + code + ".jpg"; PurchaseDto dto = PurchaseDto.builder().id(purchaseDto.getId()).typeId(typeId).qrCode(code).qrUrl(qrUrl).build(); mapper.insert(dto); - //修改任务表的是否下载状态 - mapper.updateStatus(purchaseDto.getId()); extracted(zos, materialModel, materialName, code, qrUrl); } } - /** - * 是否下载方法抽取 - * @param purchaseDto - */ - private void isDownLoad(PurchaseDto purchaseDto) { - List statusList =mapper.selectStatus(purchaseDto); - if (CollectionUtils.isNotEmpty(statusList) && statusList.contains(1)) { - throw new RuntimeException("该采购单二维码已生成,无法再次生成!"); - } - } - /** * 二维码下载方法抽取 * @param zos * @param materialModel * @param materialName * @param code - * @param qrUrl + * @param path * @throws IOException */ - private void extracted(ZipOutputStream zos, String materialModel, String materialName, String code, String qrUrl) throws IOException { + private void extracted(ZipOutputStream zos, String materialModel, String materialName, String code, String path) throws IOException { // 判断路径是否存在 - File imageFile = new File(qrUrl); + File imageFile = new File(path); if (!imageFile.exists()) { return; } diff --git a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/Constants.java b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/Constants.java index a342d14..81c9463 100644 --- a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/Constants.java +++ b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/Constants.java @@ -81,4 +81,9 @@ public class Constants { * 不通过 */ public static final Integer PURCHASE_NO_PASSED = 59; + + /** + * 数量基数 + */ + public static final Integer CARDINAL_NUMBER = 1000; } diff --git a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/QrCodeUtils.java b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/QrCodeUtils.java index e1e2682..4dc9cf2 100644 --- a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/QrCodeUtils.java +++ b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/utils/QrCodeUtils.java @@ -1,20 +1,24 @@ package com.bonus.purchase.utils; import com.google.zxing.BarcodeFormat; -import com.google.zxing.WriterException; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.client.j2se.MatrixToImageConfig; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; -import com.google.zxing.qrcode.QRCodeWriter; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import javax.imageio.ImageIO; +import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Hashtable; /** * 二维码生成,保存,压缩包工具类 @@ -23,34 +27,122 @@ import java.nio.file.Path; */ public class QrCodeUtils { + /** 二维码宽度 */ + private static int width = 280; + + /** 二维码高度 */ + private static int height = 280; + + /** 前景色 */ + private static int onColor = 0xFF000000; + + /** 背景色 */ + private static int offColor = 0xFFFFFFFF; + + /** 白边大小,取值范围0~4 */ + private static int margin = 0; + + /** 二维码容错率 */ + private static ErrorCorrectionLevel level = ErrorCorrectionLevel.L; + /** - * 生成二维码图片 - * @param text 二维码内容 - * @param width 图片宽度 - * @param height 图片高度 - * @return 生成的二维码图片 - * @throws WriterException 如果二维码生成失败 + * 生成带logo的二维码图片 + * + * @param txt //二维码内容 + * @param logoPath //logo绝对物理路径 + * @param imgPath //二维码保存绝对物理路径 + * @param imgName //二维码文件名称 + * @param suffix //图片后缀名 + * @throws Exception */ - public static BufferedImage generateQRCodeImage(String text, int width, int height) throws WriterException { - QRCodeWriter qrCodeWriter = new QRCodeWriter(); - BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); - return MatrixToImageWriter.toBufferedImage(bitMatrix); + public static void generateQRImage(String txt, String logoPath, String imgPath, String imgName, String suffix) + throws Exception { + File filePath = new File(imgPath); + if (!filePath.exists()) { + filePath.mkdirs(); + } + if (imgPath.endsWith("/")) { + imgPath += imgName; + } else { + imgPath += "/" + imgName; + } + Hashtable hints = new Hashtable(); + hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); + hints.put(EncodeHintType.ERROR_CORRECTION, level); + // 设置白边 + hints.put(EncodeHintType.MARGIN, margin); + BitMatrix bitMatrix = new MultiFormatWriter().encode(txt, BarcodeFormat.QR_CODE, width, height, hints); + File qrcodeFile = new File(imgPath); + writeToFile(bitMatrix, suffix, qrcodeFile, logoPath); } /** - * 将二维码图片保存到文件 - * @param qrCodeImage 二维码图片 - * @param filePath 文件路径 - * @throws IOException 如果保存文件失败 + * 生成二维码 + * + * @param txt //二维码内容 + * @param imgPath //二维码保存物理路径 + * @param imgName //二维码文件名称 + * @param suffix //图片后缀名 */ - public static void saveQRCodeImage(BufferedImage qrCodeImage, Path filePath) throws IOException { - File outputFile = filePath.toFile(); - ImageIO.write(qrCodeImage, "jpg", outputFile); + public static void generateQRImage(String txt, String imgPath, String imgName, String suffix) { + + File filePath = new File(imgPath); + if (!filePath.exists()) { + filePath.mkdirs(); + } + File imageFile = new File(imgPath, imgName); + Hashtable hints = new Hashtable<>(); + // 指定纠错等级 + hints.put(EncodeHintType.ERROR_CORRECTION, level); + // 指定编码格式 + hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + // 设置白边 + hints.put(EncodeHintType.MARGIN, margin); + try { + MatrixToImageConfig config = new MatrixToImageConfig(onColor, offColor); + BitMatrix bitMatrix = new MultiFormatWriter().encode(txt, BarcodeFormat.QR_CODE, width, height, hints); + // bitMatrix = deleteWhite(bitMatrix); + MatrixToImageWriter.writeToPath(bitMatrix, suffix, imageFile.toPath(), config); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * @param matrix 二维码矩阵相关 + * @param format 二维码图片格式 + * @param file 二维码图片文件 + * @param logoPath logo路径 + * @throws IOException + */ + public static void writeToFile(BitMatrix matrix, String format, File file, String logoPath) throws IOException { + BufferedImage image = toBufferedImage(matrix); + Graphics2D gs = image.createGraphics(); + + int ratioWidth = image.getWidth() * 2 / 10; + int ratioHeight = image.getHeight() * 2 / 10; + // 载入logo + Image img = ImageIO.read(new File(logoPath)); + int logoWidth = img.getWidth(null) > ratioWidth ? ratioWidth : img.getWidth(null); + int logoHeight = img.getHeight(null) > ratioHeight ? ratioHeight : img.getHeight(null); + + int x = (image.getWidth() - logoWidth) / 2; + int y = (image.getHeight() - logoHeight) / 2; + + gs.drawImage(img, x, y, logoWidth, logoHeight, null); + gs.setColor(Color.black); + gs.setBackground(Color.WHITE); + gs.dispose(); + img.flush(); + if (!ImageIO.write(image, format, file)) { + throw new IOException("Could not write an image of format " + format + " to " + file); + } } /** * 压缩目录中的图片到ZIP文件 - * @param sourceDir 源目录 + * + * @param sourceDir 源目录 * @param zipFilePath ZIP文件路径 * @throws IOException 如果压缩过程失败 */ @@ -73,38 +165,17 @@ public class QrCodeUtils { } } - /*public static void main(String[] args) { - try { - Path downloadDir = Paths.get("qr_codes"); - Files.createDirectories(downloadDir); + public static BufferedImage toBufferedImage(BitMatrix matrix) { + int width = matrix.getWidth(); + int height = matrix.getHeight(); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); - int width = 300; - int height = 300; - String baseText = "QR Code "; - - // 生成二维码 - for (int i = 1; i <= 2; i++) { - String text = baseText + i; - BufferedImage qrCodeImage = QRCodeUtils.generateQRCodeImage(text, width, height); - Path filePath = downloadDir.resolve("QRCode_" + i + ".jpg"); - QRCodeUtils.saveQRCodeImage(qrCodeImage, filePath); - System.out.println("Generated: " + filePath); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, matrix.get(x, y) ? onColor : offColor); } - - // 压缩二维码图片 - Path zipFilePath = Paths.get("qr_codes.zip"); - zipImages(downloadDir, zipFilePath); - System.out.println("Images zipped to: " + zipFilePath); - - // 清理 - Files.walk(downloadDir) - .map(Path::toFile) - .forEach(File::delete); - Files.deleteIfExists(downloadDir); - - } catch (WriterException | IOException e) { - e.printStackTrace(); } - }*/ + return image; + } } diff --git a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/PurchaseAcceptVo.java b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/PurchaseAcceptVo.java index 7662bc1..bd4438e 100644 --- a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/PurchaseAcceptVo.java +++ b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/PurchaseAcceptVo.java @@ -101,4 +101,7 @@ public class PurchaseAcceptVo { @ApiModelProperty(value = "任务id") private String taskId; + + @ApiModelProperty(value = "是否下载") + private Integer isDownload; } diff --git a/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/QrUrlVo.java b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/QrUrlVo.java new file mode 100644 index 0000000..6d38448 --- /dev/null +++ b/bonus-modules/bonus-task/src/main/java/com/bonus/purchase/vo/QrUrlVo.java @@ -0,0 +1,27 @@ +package com.bonus.purchase.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 二维码返回详情vo + * @Author ma_sh + * @create 2024/8/26 17:45 + */ +@Data +public class QrUrlVo { + + private Integer id; + + @ApiModelProperty("物资名称") + private String materialName; + + @ApiModelProperty("规格型号") + private String materialModel; + + @ApiModelProperty(value = "二维码code") + private String qrCode; + + @ApiModelProperty(value = "二维码curl") + private String qrUrl; +} diff --git a/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseAcceptMapper.xml b/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseAcceptMapper.xml index 637667c..4a97524 100644 --- a/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseAcceptMapper.xml +++ b/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseAcceptMapper.xml @@ -77,7 +77,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bp.product_date AS productDate, bp.`status` AS STATUS, - sda1.dict_label AS statusName + sda1.dict_label AS statusName, + bp.is_download AS isDownload FROM bpm_purchase_info bp LEFT JOIN bpm_task bt ON bp.task_id = bt.id diff --git a/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseBindMapper.xml b/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseBindMapper.xml index 2f83c2c..292d188 100644 --- a/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseBindMapper.xml +++ b/bonus-modules/bonus-task/src/main/resources/mapper/BpmPurchaseBindMapper.xml @@ -89,7 +89,13 @@ UPDATE bpm_purchase_info SET is_download = '1' - WHERE task_id = #{id} + WHERE is_active = '1' + + and task_id = #{id} + + + and id = #{purchaseId} + @@ -187,4 +193,26 @@ and id = #{purchaseId} +