From 0f9e37b1a8b6e6cb3a78915ecd8ad38ef44989b5 Mon Sep 17 00:00:00 2001 From: lcj <2331845269@qq.com> Date: Mon, 7 Jul 2025 20:01:05 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 15 +- .../test/java/org/dromara/test/PDFTest.java | 39 +++++ .../ruoyi-common/ruoyi-common-doc/pom.xml | 11 ++ .../ruoyi-common/ruoyi-common-mybatis/pom.xml | 5 + .../handler/MybatisExceptionHandler.java | 2 + .../ruoyi-common/ruoyi-common-redis/pom.xml | 5 + .../redis/handler/RedisExceptionHandler.java | 2 + .../ruoyi-common/ruoyi-common-satoken/pom.xml | 5 + .../handler/SaTokenExceptionHandler.java | 2 + .../ruoyi-common/ruoyi-common-sms/pom.xml | 5 + .../sms/handler/SmsExceptionHandler.java | 2 + .../ruoyi-common/ruoyi-common-web/pom.xml | 5 + .../web/handler/GlobalExceptionHandler.java | 2 + .../ruoyi-modules/ruoyi-system/pom.xml | 28 +++- .../interceptor/ValidProjectInterceptor.java | 27 ++++ .../common/utils/PdfBoxQrCodeGenerator.java | 142 ++++++++++++++++++ .../BusContactformtemplateController.java | 41 ++--- .../domain/bo/BusContactformtemplateBo.java | 23 ++- .../BusContactformtemplateServiceImpl.java | 9 +- .../org/dromara/design/domain/DesDrawing.java | 5 + .../design/service/IDesDrawingService.java | 9 ++ .../service/impl/DesDrawingServiceImpl.java | 67 +++++++++ .../impl/DesSpecialSchemeServiceImpl.java | 6 +- .../system/service/ISysOssService.java | 18 ++- .../service/impl/SysOssServiceImpl.java | 35 ++++- 25 files changed, 464 insertions(+), 46 deletions(-) create mode 100644 xinnengyuan/ruoyi-admin/src/test/java/org/dromara/test/PDFTest.java create mode 100644 xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/interceptor/ValidProjectInterceptor.java create mode 100644 xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/PdfBoxQrCodeGenerator.java diff --git a/xinnengyuan/ruoyi-admin/src/main/resources/application.yml b/xinnengyuan/ruoyi-admin/src/main/resources/application.yml index a2e81426..96b49636 100644 --- a/xinnengyuan/ruoyi-admin/src/main/resources/application.yml +++ b/xinnengyuan/ruoyi-admin/src/main/resources/application.yml @@ -187,13 +187,14 @@ api-decrypt: privateKey: MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y= springdoc: + swagger-ui: + path: /swagger-ui.html + tags-sorter: alpha + operations-sorter: alpha api-docs: # 是否开启接口文档 enabled: true - swagger-ui: - path: /swagger-ui.html # 明确Swagger UI路径 - # 持久化认证数据 - persistAuthorization: false + path: /v3/api-docs info: # 标题 title: '标题:${ruoyi.name}多租户管理系统_接口文档' @@ -245,7 +246,11 @@ springdoc: packages-to-scan: org.dromara.cory - group: 20.代码生成模块 packages-to-scan: org.dromara.generator - +# knife4j的增强配置,不需要增强可以不配 +knife4j: + enable: true + setting: + language: zh_cn # 防止XSS攻击 xss: diff --git a/xinnengyuan/ruoyi-admin/src/test/java/org/dromara/test/PDFTest.java b/xinnengyuan/ruoyi-admin/src/test/java/org/dromara/test/PDFTest.java new file mode 100644 index 00000000..c8398e70 --- /dev/null +++ b/xinnengyuan/ruoyi-admin/src/test/java/org/dromara/test/PDFTest.java @@ -0,0 +1,39 @@ +package org.dromara.test; + +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.utils.PdfBoxQrCodeGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author lcj + * @date 2025/7/7 10:13 + */ +@Slf4j +@SpringBootTest +public class PDFTest { + + @Test + void test() { + String srcPdf = "http://58.17.134.85:9000/xinnengyuan-dev/2025/07/07/146cb913cb4841eb9944463b762cba53.pdf"; // 原始PDF + String destPdf = "output.pdf"; // 输出PDF + Map params = new HashMap<>(); + params.put("版本:", "1.0"); + params.put("文件名:", "绝对哦啊手机号丢啊"); + params.put("文件类型:", "蓝图"); + String qrText = "fdas:1.0 das:asd sad:dsa"; + String qrPath = "qrcode.png"; + + byte[] bytes = PdfBoxQrCodeGenerator.generateQRCodeBytes(qrText, 200, 200); + try { + PdfBoxQrCodeGenerator.addQRCodeToPDF(srcPdf, destPdf, bytes, 1, 1510, 900); // 页码从1开始,坐标单位是 pt(约1/72英寸) + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("二维码添加成功!"); + } +} diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-doc/pom.xml b/xinnengyuan/ruoyi-common/ruoyi-common-doc/pom.xml index c6199a17..2f0b5838 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-doc/pom.xml +++ b/xinnengyuan/ruoyi-common/ruoyi-common-doc/pom.xml @@ -26,6 +26,11 @@ springdoc-openapi-starter-webmvc-api + + org.springdoc + springdoc-openapi-starter-webmvc-ui + + com.github.therapi therapi-runtime-javadoc @@ -36,6 +41,12 @@ jackson-module-kotlin + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + 4.4.0 + + diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/pom.xml b/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/pom.xml index d79ba284..2d4dc74a 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/pom.xml +++ b/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/pom.xml @@ -26,6 +26,11 @@ ruoyi-common-satoken + + org.dromara + ruoyi-common-doc + + com.baomidou diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java b/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java index 518d52d2..d802bf8e 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/handler/MybatisExceptionHandler.java @@ -1,5 +1,6 @@ package org.dromara.common.mybatis.handler; +import io.swagger.v3.oas.annotations.Hidden; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.R; @@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; * @author Lion Li */ @Slf4j +@Hidden @RestControllerAdvice public class MybatisExceptionHandler { diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-redis/pom.xml b/xinnengyuan/ruoyi-common/ruoyi-common-redis/pom.xml index d7d99cac..c8280f9c 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-redis/pom.xml +++ b/xinnengyuan/ruoyi-common/ruoyi-common-redis/pom.xml @@ -22,6 +22,11 @@ ruoyi-common-core + + org.dromara + ruoyi-common-doc + + org.redisson diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/handler/RedisExceptionHandler.java b/xinnengyuan/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/handler/RedisExceptionHandler.java index 5e904f37..4db33eb3 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/handler/RedisExceptionHandler.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/handler/RedisExceptionHandler.java @@ -2,6 +2,7 @@ package org.dromara.common.redis.handler; import cn.hutool.http.HttpStatus; import com.baomidou.lock.exception.LockFailureException; +import io.swagger.v3.oas.annotations.Hidden; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.R; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; * @author AprilWind */ @Slf4j +@Hidden @RestControllerAdvice public class RedisExceptionHandler { diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-satoken/pom.xml b/xinnengyuan/ruoyi-common/ruoyi-common-satoken/pom.xml index 4df7d4de..2a6c6670 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-satoken/pom.xml +++ b/xinnengyuan/ruoyi-common/ruoyi-common-satoken/pom.xml @@ -24,6 +24,11 @@ ruoyi-common-redis + + org.dromara + ruoyi-common-doc + + cn.dev33 diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/handler/SaTokenExceptionHandler.java b/xinnengyuan/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/handler/SaTokenExceptionHandler.java index a45af89d..ad4c21b0 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/handler/SaTokenExceptionHandler.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/handler/SaTokenExceptionHandler.java @@ -4,6 +4,7 @@ import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.NotPermissionException; import cn.dev33.satoken.exception.NotRoleException; import cn.hutool.http.HttpStatus; +import io.swagger.v3.oas.annotations.Hidden; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.R; @@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; * @author Lion Li */ @Slf4j +@Hidden @RestControllerAdvice public class SaTokenExceptionHandler { diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-sms/pom.xml b/xinnengyuan/ruoyi-common/ruoyi-common-sms/pom.xml index 932cb9d5..941afe76 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-sms/pom.xml +++ b/xinnengyuan/ruoyi-common/ruoyi-common-sms/pom.xml @@ -28,6 +28,11 @@ ruoyi-common-redis + + org.dromara + ruoyi-common-doc + + diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-sms/src/main/java/org/dromara/common/sms/handler/SmsExceptionHandler.java b/xinnengyuan/ruoyi-common/ruoyi-common-sms/src/main/java/org/dromara/common/sms/handler/SmsExceptionHandler.java index 2c619a36..84617893 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-sms/src/main/java/org/dromara/common/sms/handler/SmsExceptionHandler.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-sms/src/main/java/org/dromara/common/sms/handler/SmsExceptionHandler.java @@ -1,6 +1,7 @@ package org.dromara.common.sms.handler; import cn.hutool.http.HttpStatus; +import io.swagger.v3.oas.annotations.Hidden; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.R; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; * @author AprilWind */ @Slf4j +@Hidden @RestControllerAdvice public class SmsExceptionHandler { diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-web/pom.xml b/xinnengyuan/ruoyi-common/ruoyi-common-web/pom.xml index b250fa9d..81b8e04a 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-web/pom.xml +++ b/xinnengyuan/ruoyi-common/ruoyi-common-web/pom.xml @@ -26,6 +26,11 @@ ruoyi-common-redis + + org.dromara + ruoyi-common-doc + + org.springframework.boot diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java b/xinnengyuan/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java index d35df39a..777233b0 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java @@ -3,6 +3,7 @@ package org.dromara.common.web.handler; import cn.hutool.core.text.AntPathMatcher; import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.HttpStatus; +import io.swagger.v3.oas.annotations.Hidden; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.ConstraintViolation; @@ -34,6 +35,7 @@ import java.io.IOException; * @author Lion Li */ @Slf4j +@Hidden @RestControllerAdvice public class GlobalExceptionHandler { diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/pom.xml b/xinnengyuan/ruoyi-modules/ruoyi-system/pom.xml index d2e4c00b..f94e10e4 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/pom.xml +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/pom.xml @@ -16,8 +16,6 @@ - - @@ -62,12 +60,38 @@ 2.0.29 + com.deepoove poi-tl 1.12.2 + + + + com.itextpdf + itext-asian + 5.2.0 + + + + com.itextpdf + itextpdf + 5.5.13.3 + + + + com.google.zxing + core + 3.5.2 + + + com.google.zxing + javase + 3.5.2 + + org.dromara diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/interceptor/ValidProjectInterceptor.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/interceptor/ValidProjectInterceptor.java new file mode 100644 index 00000000..0e14de28 --- /dev/null +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/interceptor/ValidProjectInterceptor.java @@ -0,0 +1,27 @@ +package org.dromara.common.interceptor; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +/** + * @author lcj + * @date 2025/7/7 19:57 + */ +@Slf4j +@Aspect +@Component +public class ValidProjectInterceptor implements HandlerInterceptor { + + // 请求前执行 + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + System.out.println("请求拦截器 preHandle:URI = " + request.getRequestURI()); + // 返回 true 表示继续执行;false 则请求被终止 + return true; + } + +} diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/PdfBoxQrCodeGenerator.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/PdfBoxQrCodeGenerator.java new file mode 100644 index 00000000..36b65cc5 --- /dev/null +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/PdfBoxQrCodeGenerator.java @@ -0,0 +1,142 @@ +package org.dromara.common.utils; + +import cn.hutool.core.img.ImgUtil; +import cn.hutool.extra.qrcode.QrCodeUtil; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import com.itextpdf.text.DocumentException; +import com.itextpdf.text.Image; +import com.itextpdf.text.pdf.PdfContentByte; +import com.itextpdf.text.pdf.PdfReader; +import com.itextpdf.text.pdf.PdfStamper; + +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * @author lcj + * @date 2025/7/7 9:56 + */ +public class PdfBoxQrCodeGenerator { + + /** + * 生成二维码图片并返回路径 + * + * @param text 二维码文本 + * @param width 二维码宽度 + * @param height 二维码高度 + * @param outputPath 二维码图片保存路径 + * @return 二维码图片保存路径 + */ + public static String generateQRCodeImage(String text, int width, int height, String outputPath) throws Exception { + BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height); + MatrixToImageWriter.writeToPath(bitMatrix, "PNG", new File(outputPath).toPath()); + return outputPath; + } + + /** + * 获取二维码图片字节数组 + * + * @param text 二维码文本 + * @param width 二维码宽度 + * @param height 二维码高度 + * @return 二维码图片字节数组 + */ + public static byte[] generateQRCodeBytes(String text, int width, int height) { + BufferedImage image = QrCodeUtil.generate(text, width, height); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ImgUtil.write(image, ImgUtil.IMAGE_TYPE_PNG, out); + return out.toByteArray(); + } + + /** + * 获取二维码图片字节数组 + * + * @param text 二维码文本 + * @return 二维码图片字节数组 + */ + public static byte[] generateQRCodeBytes(String text) { + return generateQRCodeBytes(text, 200, 200); + } + + /** + * 在PDF指定位置添加二维码 + * + * @param srcPdf 原PDF文件路径 + * @param destPdf 新PDF文件路径 + * @param qrImagePath 二维码图片路径 + * @param pageNum 页码 + * @param x 坐标 + * @param y 坐标 + */ + public static void addQRCodeToPDF(String srcPdf, String destPdf, String qrImagePath, int pageNum, float x, float y) throws IOException, DocumentException { + PdfReader reader = new PdfReader(srcPdf); + PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(destPdf)); + PdfContentByte content = stamper.getOverContent(pageNum); + Image image = Image.getInstance(qrImagePath); + image.setAbsolutePosition(x, y); // 坐标:左下角为原点 + image.scaleAbsolute(100, 100); // 设置二维码大小 + + content.addImage(image); + stamper.close(); + reader.close(); + } + + /** + * 在PDF指定位置添加二维码 + * + * @param srcPdf 原PDF文件路径 + * @param destPdf 新PDF文件路径 + * @param qrCodeBytes 二维码图片字节数组 + * @param pageNum 页码 + * @param x 坐标 + * @param y 坐标 + */ + public static void addQRCodeToPDF(String srcPdf, String destPdf, byte[] qrCodeBytes, int pageNum, float x, float y) throws IOException, DocumentException { + PdfReader reader = new PdfReader(srcPdf); + PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(destPdf)); + PdfContentByte content = stamper.getOverContent(pageNum); + + Image image = Image.getInstance(qrCodeBytes); + image.setAbsolutePosition(x, y); // 坐标:左下角为原点 + image.scaleAbsolute(100, 100); // 设置二维码大小 + + content.addImage(image); + stamper.close(); + reader.close(); + } + + /** + * 在PDF指定位置添加二维码并返回数据流 + * + * @param srcPdf 原PDF文件路径 + * @param qrCodeBytes 二维码图片字节数组 + * @param pageNum 页码 + * @param x 坐标 + * @param y 坐标 + * @return 插入二维码后的PDF文件流 + */ + public static ByteArrayOutputStream addQRCodeToPDF(String srcPdf, byte[] qrCodeBytes, int pageNum, float x, float y) throws IOException, DocumentException { + + PdfReader reader = new PdfReader(srcPdf); + ByteArrayOutputStream pdfOut = new ByteArrayOutputStream(); + PdfStamper stamper = new PdfStamper(reader, pdfOut); + + PdfContentByte content = stamper.getOverContent(pageNum); + Image image = Image.getInstance(qrCodeBytes); + image.setAbsolutePosition(x, y); // 坐标:左下角为原点 + image.scaleAbsolute(100, 100); // 设置二维码大小 + + content.addImage(image); + stamper.close(); + reader.close(); + + return pdfOut; + } + +} diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/controller/BusContactformtemplateController.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/controller/BusContactformtemplateController.java index ae2a8512..705d96d8 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/controller/BusContactformtemplateController.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/controller/BusContactformtemplateController.java @@ -1,28 +1,29 @@ package org.dromara.cory.controller; -import java.util.List; - -import lombok.RequiredArgsConstructor; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; -import org.springframework.web.bind.annotation.*; -import org.springframework.validation.annotation.Validated; +import cn.dev33.satoken.annotation.SaMode; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; +import org.dromara.common.core.domain.R; +import org.dromara.common.core.validate.EditGroup; +import org.dromara.common.excel.utils.ExcelUtil; import org.dromara.common.idempotent.annotation.RepeatSubmit; import org.dromara.common.log.annotation.Log; -import org.dromara.common.web.core.BaseController; -import org.dromara.common.mybatis.core.page.PageQuery; -import org.dromara.common.core.domain.R; -import org.dromara.common.core.validate.AddGroup; -import org.dromara.common.core.validate.EditGroup; import org.dromara.common.log.enums.BusinessType; -import org.dromara.common.excel.utils.ExcelUtil; -import org.dromara.cory.domain.vo.BusContactformtemplateVo; -import org.dromara.cory.domain.bo.BusContactformtemplateBo; -import org.dromara.cory.service.IBusContactformtemplateService; +import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.web.core.BaseController; +import org.dromara.cory.domain.bo.BusContactformtemplateBo; +import org.dromara.cory.domain.vo.BusContactformtemplateVo; +import org.dromara.cory.service.IBusContactformtemplateService; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + /** * 联系单模板 * @@ -47,9 +48,9 @@ public class BusContactformtemplateController extends BaseController { } /** - * 查询联系单模板列表 + * 查询联系单模板列表(不分页) */ - @SaCheckPermission("cory:contactformtemplate:listNoPage") + @SaCheckPermission(value = {"cory:contactformtemplate:listNoPage", "cory:contactformtemplate:list"}, mode = SaMode.OR) @GetMapping("/listNoPage") public R> listNoPage(BusContactformtemplateBo bo) { return R.ok(busContactformtemplateService.queryList(bo)); @@ -75,7 +76,7 @@ public class BusContactformtemplateController extends BaseController { @SaCheckPermission("cory:contactformtemplate:query") @GetMapping("/{id}") public R getInfo(@NotNull(message = "主键不能为空") - @PathVariable Long id) { + @PathVariable Long id) { return R.ok(busContactformtemplateService.queryById(id)); } @@ -89,7 +90,7 @@ public class BusContactformtemplateController extends BaseController { public R add( BusContactformtemplateBo bo, @RequestPart("file") MultipartFile file) { - return toAjax(busContactformtemplateService.insertByBo(bo,file)); + return toAjax(busContactformtemplateService.insertByBo(bo, file)); } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/domain/bo/BusContactformtemplateBo.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/domain/bo/BusContactformtemplateBo.java index 04b9f2ef..df8e8959 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/domain/bo/BusContactformtemplateBo.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/domain/bo/BusContactformtemplateBo.java @@ -1,16 +1,13 @@ package org.dromara.cory.domain.bo; -import org.dromara.cory.domain.BusContactformtemplate; -import org.dromara.common.mybatis.core.domain.BaseEntity; -import org.dromara.common.core.validate.AddGroup; -import org.dromara.common.core.validate.EditGroup; +import com.baomidou.mybatisplus.annotation.TableId; import io.github.linpeilie.annotations.AutoMapper; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.validation.constraints.*; -import org.dromara.common.translation.annotation.Translation; -import org.dromara.common.translation.constant.TransConstant; -import org.springframework.web.multipart.MultipartFile; +import org.dromara.common.mybatis.core.domain.BaseEntity; +import org.dromara.cory.domain.BusContactformtemplate; + +import java.util.List; /** * 联系单模板业务对象 bus_contactformtemplate @@ -22,6 +19,12 @@ import org.springframework.web.multipart.MultipartFile; @EqualsAndHashCode(callSuper = true) @AutoMapper(target = BusContactformtemplate.class, reverseConvertGenerate = false) public class BusContactformtemplateBo extends BaseEntity { + /** + * 自增ID + */ + @TableId(value = "id") + private Long id; + /** * 项目ID @@ -49,4 +52,8 @@ public class BusContactformtemplateBo extends BaseEntity { */ private String remark; + /** + * 根据ids查询数据(in) + */ + private List ids; } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/service/impl/BusContactformtemplateServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/service/impl/BusContactformtemplateServiceImpl.java index 8a82bcfa..d8d470d7 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/service/impl/BusContactformtemplateServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/cory/service/impl/BusContactformtemplateServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.cory.service.impl; +import cn.hutool.core.collection.CollUtil; import jakarta.annotation.Resource; import org.docx4j.openpackaging.exceptions.Docx4JException; import org.dromara.common.core.utils.MapstructUtils; @@ -92,6 +93,7 @@ public class BusContactformtemplateServiceImpl implements IBusContactformtemplat LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); lqw.orderByAsc(BusContactformtemplate::getId); lqw.like(StringUtils.isNotBlank(bo.getName()), BusContactformtemplate::getName, bo.getName()); + lqw.in(CollUtil.isNotEmpty(bo.getIds()), BusContactformtemplate::getId, bo.getIds()); // lqw.eq(StringUtils.isNotBlank(bo.getPath()), BusContactformtemplate::getPath, bo.getPath()); // lqw.eq(StringUtils.isNotBlank(bo.getThumbnail()), BusContactformtemplate::getThumbnail, bo.getThumbnail()); return lqw; @@ -135,9 +137,10 @@ public class BusContactformtemplateServiceImpl implements IBusContactformtemplat */ @Override public Boolean updateByBo(BusContactformtemplateBo bo) { - BusContactformtemplate update = MapstructUtils.convert(bo, BusContactformtemplate.class); - validEntityBeforeSave(update); - return baseMapper.updateById(update) > 0; + BusContactformtemplate busContactformtemplate = new BusContactformtemplate(); + busContactformtemplate.setId(bo.getId()); + busContactformtemplate.setName(bo.getName()); + return baseMapper.updateById(busContactformtemplate) > 0; } /** diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/DesDrawing.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/DesDrawing.java index 63e7d078..2a5d47a7 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/DesDrawing.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/domain/DesDrawing.java @@ -69,6 +69,11 @@ public class DesDrawing extends BaseEntity { */ private String originalName; + /** + * 原文件id + */ + private Long originalFileId; + /** * 是否最新(0否 1是) */ diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/IDesDrawingService.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/IDesDrawingService.java index 6bfe0ddd..e2a5d657 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/IDesDrawingService.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/IDesDrawingService.java @@ -13,6 +13,7 @@ import org.dromara.design.domain.vo.drawing.DesDrawingVo; import java.util.Collection; import java.util.List; +import java.util.concurrent.CompletableFuture; /** * 图纸管理Service接口 @@ -94,4 +95,12 @@ public interface IDesDrawingService extends IService { * @return 图纸管理对象视图 */ Page getVoPage(Page drawingPage); + + /** + * 异步添加二维码到PDF + * + * @param drawing 图纸管理对象 + * @return 是否添加成功 + */ + CompletableFuture addQRCodeToPDF(DesDrawing drawing); } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesDrawingServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesDrawingServiceImpl.java index 2c49c799..a03778c8 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesDrawingServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesDrawingServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.itextpdf.text.DocumentException; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.constant.HttpStatus; @@ -20,6 +21,7 @@ import org.dromara.common.core.utils.ObjectUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.utils.PdfBoxQrCodeGenerator; import org.dromara.design.domain.DesDrawing; import org.dromara.design.domain.dto.drawing.DesDrawingCreateReq; import org.dromara.design.domain.dto.drawing.DesDrawingQueryReq; @@ -33,11 +35,19 @@ import org.dromara.project.service.IBusProjectService; import org.dromara.system.domain.vo.SysOssVo; import org.dromara.system.service.ISysOssService; import org.springframework.beans.BeanUtils; +import org.springframework.context.annotation.Lazy; import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.FileNameMap; +import java.net.URLConnection; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; /** @@ -60,6 +70,10 @@ public class DesDrawingServiceImpl extends ServiceImpl log.info("图纸[{}-{}]添加二维码成功", drawing.getFileName(), drawing.getId())) + .exceptionally(ex -> { + log.error("图纸[{}-{}]添加二维码失败", drawing.getFileName(), drawing.getId(), ex); + return null; + }); + } } /** @@ -328,4 +363,36 @@ public class DesDrawingServiceImpl extends ServiceImpl addQRCodeToPDF(DesDrawing drawing) { + Long fileUrl = drawing.getOriginalFileId(); + if (fileUrl == null) { + return CompletableFuture.completedFuture(false); + } + SysOssVo ossVo = ossService.getById(fileUrl); + // 整合二维码需要显示的数据 + String params = "ID:[" + drawing.getId() + "] finish"; + byte[] bytes = PdfBoxQrCodeGenerator.generateQRCodeBytes(params); + try { + ByteArrayOutputStream baos = PdfBoxQrCodeGenerator.addQRCodeToPDF(ossVo.getUrl(), bytes, 1, 1510, 900); + FileNameMap fileNameMap = URLConnection.getFileNameMap(); + String originalName = drawing.getOriginalName(); + String contentType = fileNameMap.getContentTypeFor(originalName); + SysOssVo upload = ossService.upload(new ByteArrayInputStream(baos.toByteArray()), originalName, contentType, baos.size()); + drawing.setFileUrl(upload.getOssId()); + } catch (IOException | DocumentException e) { + log.error("图纸管理 => 审核结束,向文件添加二维码失败", e); + return CompletableFuture.completedFuture(false); + } + this.updateById(drawing); + return CompletableFuture.completedFuture(true); + } + } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSpecialSchemeServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSpecialSchemeServiceImpl.java index f1c477ab..e2b3cb70 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSpecialSchemeServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSpecialSchemeServiceImpl.java @@ -258,7 +258,7 @@ public class DesSpecialSchemeServiceImpl extends ServiceImpl