diff --git a/giftBook-common/giftBook-common-bom/pom.xml b/giftBook-common/giftBook-common-bom/pom.xml index bac3ec6..8b1d529 100644 --- a/giftBook-common/giftBook-common-bom/pom.xml +++ b/giftBook-common/giftBook-common-bom/pom.xml @@ -10,7 +10,7 @@ pom - ruoyi-common-bom common依赖项 + giftBook-common-bom common依赖项 diff --git a/giftBook-common/giftBook-common-core/pom.xml b/giftBook-common/giftBook-common-core/pom.xml index 4b77a2b..b29a2d0 100644 --- a/giftBook-common/giftBook-common-core/pom.xml +++ b/giftBook-common/giftBook-common-core/pom.xml @@ -12,7 +12,7 @@ giftBook-common-core - ruoyi-common-core 核心模块 + giftBook-common-core 核心模块 diff --git a/giftBook-common/giftBook-common-doc/pom.xml b/giftBook-common/giftBook-common-doc/pom.xml index 892b2f2..c9c985d 100644 --- a/giftBook-common/giftBook-common-doc/pom.xml +++ b/giftBook-common/giftBook-common-doc/pom.xml @@ -12,7 +12,7 @@ giftBook-common-doc - ruoyi-common-doc 系统接口 + giftBook-common-doc 系统接口 diff --git a/giftBook-common/giftBook-common-encrypt/pom.xml b/giftBook-common/giftBook-common-encrypt/pom.xml index 4513c25..dab95a3 100644 --- a/giftBook-common/giftBook-common-encrypt/pom.xml +++ b/giftBook-common/giftBook-common-encrypt/pom.xml @@ -12,7 +12,7 @@ giftBook-common-encrypt - ruoyi-common-encrypt 数据加解密模块 + giftBook-common-encrypt 数据加解密模块 diff --git a/giftBook-common/giftBook-common-excel/pom.xml b/giftBook-common/giftBook-common-excel/pom.xml index c803f2f..eea2bae 100644 --- a/giftBook-common/giftBook-common-excel/pom.xml +++ b/giftBook-common/giftBook-common-excel/pom.xml @@ -12,7 +12,7 @@ giftBook-common-excel - ruoyi-common-excel + giftBook-common-excel diff --git a/giftBook-common/giftBook-common-idempotent/pom.xml b/giftBook-common/giftBook-common-idempotent/pom.xml index 483f3d3..7813f93 100644 --- a/giftBook-common/giftBook-common-idempotent/pom.xml +++ b/giftBook-common/giftBook-common-idempotent/pom.xml @@ -12,7 +12,7 @@ giftBook-common-idempotent - ruoyi-common-idempotent 幂等功能 + giftBook-common-idempotent 幂等功能 diff --git a/giftBook-common/giftBook-common-job/pom.xml b/giftBook-common/giftBook-common-job/pom.xml index 22f13e9..d5765ca 100644 --- a/giftBook-common/giftBook-common-job/pom.xml +++ b/giftBook-common/giftBook-common-job/pom.xml @@ -12,7 +12,7 @@ giftBook-common-job - ruoyi-common-job 定时任务 + giftBook-common-job 定时任务 diff --git a/giftBook-common/giftBook-common-json/pom.xml b/giftBook-common/giftBook-common-json/pom.xml index 9af0917..2a5772c 100644 --- a/giftBook-common/giftBook-common-json/pom.xml +++ b/giftBook-common/giftBook-common-json/pom.xml @@ -12,7 +12,7 @@ giftBook-common-json - ruoyi-common-json 序列化模块 + giftBook-common-json 序列化模块 diff --git a/giftBook-common/giftBook-common-log/pom.xml b/giftBook-common/giftBook-common-log/pom.xml index 0fffd89..52fa906 100644 --- a/giftBook-common/giftBook-common-log/pom.xml +++ b/giftBook-common/giftBook-common-log/pom.xml @@ -12,7 +12,7 @@ giftBook-common-log - ruoyi-common-log 日志记录 + giftBook-common-log 日志记录 diff --git a/giftBook-common/giftBook-common-mail/pom.xml b/giftBook-common/giftBook-common-mail/pom.xml index de812fb..5871170 100644 --- a/giftBook-common/giftBook-common-mail/pom.xml +++ b/giftBook-common/giftBook-common-mail/pom.xml @@ -12,7 +12,7 @@ giftBook-common-mail - ruoyi-common-mail 邮件模块 + giftBook-common-mail 邮件模块 diff --git a/giftBook-common/giftBook-common-mybatis/pom.xml b/giftBook-common/giftBook-common-mybatis/pom.xml index bb3e1da..bdbb748 100644 --- a/giftBook-common/giftBook-common-mybatis/pom.xml +++ b/giftBook-common/giftBook-common-mybatis/pom.xml @@ -12,7 +12,7 @@ giftBook-common-mybatis - ruoyi-common-mybatis 数据库服务 + giftBook-common-mybatis 数据库服务 diff --git a/giftBook-common/giftBook-common-oss/pom.xml b/giftBook-common/giftBook-common-oss/pom.xml index 68dcbcb..92c7842 100644 --- a/giftBook-common/giftBook-common-oss/pom.xml +++ b/giftBook-common/giftBook-common-oss/pom.xml @@ -12,7 +12,7 @@ giftBook-common-oss - ruoyi-common-oss oss服务 + giftBook-common-oss oss服务 diff --git a/giftBook-common/giftBook-common-ratelimiter/pom.xml b/giftBook-common/giftBook-common-ratelimiter/pom.xml index c59b5bf..a4ae4c0 100644 --- a/giftBook-common/giftBook-common-ratelimiter/pom.xml +++ b/giftBook-common/giftBook-common-ratelimiter/pom.xml @@ -12,7 +12,7 @@ giftBook-common-ratelimiter - ruoyi-common-ratelimiter 限流功能 + giftBook-common-ratelimiter 限流功能 diff --git a/giftBook-common/giftBook-common-redis/pom.xml b/giftBook-common/giftBook-common-redis/pom.xml index bb7c53a..82f33bc 100644 --- a/giftBook-common/giftBook-common-redis/pom.xml +++ b/giftBook-common/giftBook-common-redis/pom.xml @@ -12,7 +12,7 @@ giftBook-common-redis - ruoyi-common-redis 缓存服务 + giftBook-common-redis 缓存服务 diff --git a/giftBook-common/giftBook-common-security/pom.xml b/giftBook-common/giftBook-common-security/pom.xml index 89ec964..2c30934 100644 --- a/giftBook-common/giftBook-common-security/pom.xml +++ b/giftBook-common/giftBook-common-security/pom.xml @@ -12,7 +12,7 @@ giftBook-common-security - ruoyi-common-security 安全模块 + giftBook-common-security 安全模块 diff --git a/giftBook-common/giftBook-common-sensitive/pom.xml b/giftBook-common/giftBook-common-sensitive/pom.xml index 194b13d..b2f026f 100644 --- a/giftBook-common/giftBook-common-sensitive/pom.xml +++ b/giftBook-common/giftBook-common-sensitive/pom.xml @@ -12,7 +12,7 @@ giftBook-common-sensitive - ruoyi-common-sensitive 脱敏模块 + giftBook-common-sensitive 脱敏模块 diff --git a/giftBook-common/giftBook-common-sms/pom.xml b/giftBook-common/giftBook-common-sms/pom.xml index b114a3a..896fe45 100644 --- a/giftBook-common/giftBook-common-sms/pom.xml +++ b/giftBook-common/giftBook-common-sms/pom.xml @@ -12,7 +12,7 @@ giftBook-common-sms - ruoyi-common-sms 短信模块 + giftBook-common-sms 短信模块 diff --git a/giftBook-common/giftBook-common-social/pom.xml b/giftBook-common/giftBook-common-social/pom.xml index e8e121d..96f5b5a 100644 --- a/giftBook-common/giftBook-common-social/pom.xml +++ b/giftBook-common/giftBook-common-social/pom.xml @@ -12,7 +12,7 @@ giftBook-common-social - ruoyi-common-social 授权认证 + giftBook-common-social 授权认证 diff --git a/giftBook-common/giftBook-common-sse/pom.xml b/giftBook-common/giftBook-common-sse/pom.xml index 04f6cce..c9a45ae 100644 --- a/giftBook-common/giftBook-common-sse/pom.xml +++ b/giftBook-common/giftBook-common-sse/pom.xml @@ -12,7 +12,7 @@ giftBook-common-sse - ruoyi-common-sse 模块 + giftBook-common-sse 模块 diff --git a/giftBook-common/giftBook-common-tenant/pom.xml b/giftBook-common/giftBook-common-tenant/pom.xml index 2f82de4..a0bbaad 100644 --- a/giftBook-common/giftBook-common-tenant/pom.xml +++ b/giftBook-common/giftBook-common-tenant/pom.xml @@ -12,7 +12,7 @@ giftBook-common-tenant - ruoyi-common-tenant 租户模块 + giftBook-common-tenant 租户模块 diff --git a/giftBook-common/giftBook-common-translation/pom.xml b/giftBook-common/giftBook-common-translation/pom.xml index 252fb0a..ce1250f 100644 --- a/giftBook-common/giftBook-common-translation/pom.xml +++ b/giftBook-common/giftBook-common-translation/pom.xml @@ -12,7 +12,7 @@ giftBook-common-translation - ruoyi-common-translation 通用翻译功能 + giftBook-common-translation 通用翻译功能 diff --git a/giftBook-common/giftBook-common-web/pom.xml b/giftBook-common/giftBook-common-web/pom.xml index ee406d2..fe6cf26 100644 --- a/giftBook-common/giftBook-common-web/pom.xml +++ b/giftBook-common/giftBook-common-web/pom.xml @@ -12,7 +12,7 @@ giftBook-common-web - ruoyi-common-web web服务 + giftBook-common-web web服务 diff --git a/giftBook-common/giftBook-common-websocket/pom.xml b/giftBook-common/giftBook-common-websocket/pom.xml index 0c207fc..60738a3 100644 --- a/giftBook-common/giftBook-common-websocket/pom.xml +++ b/giftBook-common/giftBook-common-websocket/pom.xml @@ -12,7 +12,7 @@ giftBook-common-websocket - ruoyi-common-websocket 模块 + giftBook-common-websocket 模块 diff --git a/giftBook-modules/giftBook-main/pom.xml b/giftBook-modules/giftBook-main/pom.xml index a6ba39c..a2aed14 100644 --- a/giftBook-modules/giftBook-main/pom.xml +++ b/giftBook-modules/giftBook-main/pom.xml @@ -59,5 +59,17 @@ cn.xxzhx.giftBook giftBook-common-tenant + + + + com.itextpdf + kernel + 9.1.0 + + + com.itextpdf + layout + 9.1.0 + diff --git a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/controller/TGiftBookDetailsController.java b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/controller/TGiftBookDetailsController.java index f54dab3..1f0301f 100644 --- a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/controller/TGiftBookDetailsController.java +++ b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/controller/TGiftBookDetailsController.java @@ -1,9 +1,10 @@ package cn.xxzhx.giftBook.main.controller; +import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import cn.xxzhx.giftBook.common.excel.core.ExcelResult; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; @@ -88,7 +89,7 @@ public class TGiftBookDetailsController extends BaseController { @SaCheckPermission("main:giftBookDetails:query") @GetMapping("/{id}") public R getInfo(@NotNull(message = "主键不能为空") - @PathVariable Long id) { + @PathVariable Long id) { return R.ok(tGiftBookDetailsService.queryById(id)); } @@ -126,4 +127,23 @@ public class TGiftBookDetailsController extends BaseController { @PathVariable Long[] ids) { return toAjax(tGiftBookDetailsService.deleteWithValidByIds(List.of(ids), true)); } + + /** + * 导出礼薄详情pdf + * + * @return + */ + @SaCheckPermission("main:giftBookDetails:export") + @Log(title = "礼薄详情", businessType = BusinessType.EXPORT) + @PostMapping("/exportPDF") + public void exportPDF(TGiftBookDetailsBo bo, HttpServletResponse response) throws IOException { + // 设置响应头 + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "attachment; filename=\"giftBookDetails.pdf\""); + + // 生成PDF并写入响应流 + byte[] pdfBytes = tGiftBookDetailsService.exportPDF(bo); + response.getOutputStream().write(pdfBytes); + response.getOutputStream().flush(); + } } diff --git a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/mapper/TGiftBookDetailsMapper.java b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/mapper/TGiftBookDetailsMapper.java index a20fd6c..2c34617 100644 --- a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/mapper/TGiftBookDetailsMapper.java +++ b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/mapper/TGiftBookDetailsMapper.java @@ -21,5 +21,5 @@ public interface TGiftBookDetailsMapper extends BaseMapperPlus selectPageList(@Param("bo") TGiftBookDetailsBo bo, IPage page); - List queryList(TGiftBookDetailsBo bo); + List queryList(@Param("bo") TGiftBookDetailsBo bo,@Param("pageQuery") PageQuery pageQuery); } diff --git a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/ITGiftBookDetailsService.java b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/ITGiftBookDetailsService.java index 4e67ede..4faebb1 100644 --- a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/ITGiftBookDetailsService.java +++ b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/ITGiftBookDetailsService.java @@ -4,6 +4,7 @@ import cn.xxzhx.giftBook.main.domain.vo.TGiftBookDetailsVo; import cn.xxzhx.giftBook.main.domain.bo.TGiftBookDetailsBo; import cn.xxzhx.giftBook.common.mybatis.core.page.TableDataInfo; import cn.xxzhx.giftBook.common.mybatis.core.page.PageQuery; +import jakarta.servlet.http.HttpServletResponse; import java.util.Collection; import java.util.List; @@ -68,4 +69,5 @@ public interface ITGiftBookDetailsService { String importData(List tGiftBookDetailsVos); + byte[] exportPDF(TGiftBookDetailsBo bo); } diff --git a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/impl/TGiftBookDetailsServiceImpl.java b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/impl/TGiftBookDetailsServiceImpl.java index f81ad18..c1b517e 100644 --- a/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/impl/TGiftBookDetailsServiceImpl.java +++ b/giftBook-modules/giftBook-main/src/main/java/cn/xxzhx/giftBook/main/service/impl/TGiftBookDetailsServiceImpl.java @@ -6,29 +6,46 @@ import cn.xxzhx.giftBook.common.core.exception.ServiceException; import cn.xxzhx.giftBook.common.core.utils.MapstructUtils; import cn.xxzhx.giftBook.common.core.utils.StreamUtils; import cn.xxzhx.giftBook.common.core.utils.StringUtils; -import cn.xxzhx.giftBook.common.mybatis.core.page.TableDataInfo; import cn.xxzhx.giftBook.common.mybatis.core.page.PageQuery; +import cn.xxzhx.giftBook.common.mybatis.core.page.TableDataInfo; +import cn.xxzhx.giftBook.main.domain.TGiftBookDetails; import cn.xxzhx.giftBook.main.domain.bo.TGiftBookBo; +import cn.xxzhx.giftBook.main.domain.bo.TGiftBookDetailsBo; +import cn.xxzhx.giftBook.main.domain.vo.TGiftBookDetailsVo; import cn.xxzhx.giftBook.main.domain.vo.TGiftBookVo; +import cn.xxzhx.giftBook.main.mapper.TGiftBookDetailsMapper; +import cn.xxzhx.giftBook.main.service.ITGiftBookDetailsService; import cn.xxzhx.giftBook.main.service.ITGiftBookService; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.itextpdf.io.font.PdfEncodings; +import com.itextpdf.io.source.ByteArrayOutputStream; +import com.itextpdf.kernel.font.PdfFont; +import com.itextpdf.kernel.font.PdfFontFactory; +import com.itextpdf.kernel.geom.PageSize; +import com.itextpdf.kernel.pdf.PdfDocument; +import com.itextpdf.kernel.pdf.PdfPage; +import com.itextpdf.kernel.pdf.PdfWriter; +import com.itextpdf.kernel.pdf.canvas.PdfCanvas; +import com.itextpdf.layout.Document; +import com.itextpdf.layout.element.AreaBreak; +import com.itextpdf.layout.element.Cell; +import com.itextpdf.layout.element.Paragraph; +import com.itextpdf.layout.element.Table; +import com.itextpdf.layout.properties.TextAlignment; +import com.itextpdf.layout.properties.UnitValue; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.ConstraintViolation; import jakarta.validation.ConstraintViolationException; import lombok.RequiredArgsConstructor; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import cn.xxzhx.giftBook.main.domain.bo.TGiftBookDetailsBo; -import cn.xxzhx.giftBook.main.domain.vo.TGiftBookDetailsVo; -import cn.xxzhx.giftBook.main.domain.TGiftBookDetails; -import cn.xxzhx.giftBook.main.mapper.TGiftBookDetailsMapper; -import cn.xxzhx.giftBook.main.service.ITGiftBookDetailsService; -import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Collection; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; import java.util.stream.Collectors; /** @@ -81,7 +98,8 @@ public class TGiftBookDetailsServiceImpl implements ITGiftBookDetailsService { public List queryList(TGiftBookDetailsBo bo) { // LambdaQueryWrapper lqw = buildQueryWrapper(bo); // return baseMapper.selectVoList(lqw); - return baseMapper.queryList(bo); + PageQuery pageQuery = new PageQuery(-1, 0); + return baseMapper.queryList(bo, pageQuery); } private LambdaQueryWrapper buildQueryWrapper(TGiftBookDetailsBo bo) { @@ -197,4 +215,139 @@ public class TGiftBookDetailsServiceImpl implements ITGiftBookDetailsService { return successMsg.toString(); } } + + @Override + public byte[] exportPDF(TGiftBookDetailsBo bo) { + PageQuery pageQuery = new PageQuery(-1, 0); + pageQuery.setOrderByColumn("name"); + pageQuery.setIsAsc("asc"); + List tGiftBookDetailsVos = baseMapper.queryList(bo, pageQuery); + try { + return createPdf(tGiftBookDetailsVos); + } catch (IOException e) { + throw new RuntimeException("导出PDF失败!"); + } + } + + public byte[] createPdf(List list) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PdfWriter writer = new PdfWriter(baos); + // 创建 PDF 文档 + PdfDocument pdfDoc = new PdfDocument(writer); + Document document = new Document(pdfDoc, PageSize.A4, false); + + // 设置字体 + ClassPathResource fontResource = new ClassPathResource("/fonts/MicrosoftYaHei.ttf"); + PdfFont font = PdfFontFactory.createFont(fontResource.getFile().getAbsolutePath(), PdfEncodings.IDENTITY_H); + document.setFont(font); + pdfDoc.addNewPage(); + + // 4. 统计每页姓氏 + Map> pageSurnameMap = new LinkedHashMap<>(); + + // 5. 生成数据页(先不创建目录页) + Table table = new Table(new float[]{2, 2, 2, 2}); // 多列表格 + table.setWidth(UnitValue.createPercentValue(100)).setFont(font).setFontSize(17).setTextAlignment(TextAlignment.CENTER); + + List tableList = new ArrayList<>(); + // 拼接 + List cellList; + BigDecimal totalAmount = new BigDecimal(0); + for (int i = 0; i < list.size(); i++) { + if (i % 21 == 0 && i != 0) { // 每 22 行换页 + table.addCell(new Cell(1, 4).add(new Paragraph("总计:" + totalAmount.intValue()))); + totalAmount = new BigDecimal(0); + tableList.add(table); + table = new Table(new float[]{2, 2, 2, 2}); // 多列表格 + table.setWidth(UnitValue.createPercentValue(100)).setFont(font).setFontSize(17).setTextAlignment(TextAlignment.CENTER); + } + + TGiftBookDetailsVo tGiftBookDetailsVo = list.get(i); + table.addCell(new Cell().add(new Paragraph(tGiftBookDetailsVo.getYear() + "年")).setWidth(100)); + table.addCell(new Cell().add(new Paragraph(tGiftBookDetailsVo.getName())).setWidth(100)); + String amount = null == tGiftBookDetailsVo.getAmount() ? "0" : String.valueOf(tGiftBookDetailsVo.getAmount()); + table.addCell(new Cell().add(new Paragraph(amount)).setWidth(100)); + totalAmount = totalAmount.add(new BigDecimal(amount)); + // 拼接 + cellList = new ArrayList<>(); + if (StringUtils.isNotBlank(tGiftBookDetailsVo.getAddress())) { + cellList.add(tGiftBookDetailsVo.getAddress()); + } + if (StringUtils.isNotBlank(tGiftBookDetailsVo.getGiftName())) { + cellList.add(tGiftBookDetailsVo.getGiftName()); + } + if (StringUtils.isNotBlank(tGiftBookDetailsVo.getEventName())) { + cellList.add(tGiftBookDetailsVo.getEventName()); + } + if (StringUtils.isNotBlank(tGiftBookDetailsVo.getRemark())) { + cellList.add(tGiftBookDetailsVo.getRemark()); + } + if (StringUtils.isNotBlank(tGiftBookDetailsVo.getIsReturn()) && "1".equals(tGiftBookDetailsVo.getIsReturn())) { + cellList.add("已还"); + } + + table.addCell(new Cell().add(new Paragraph(String.join("/", cellList)))); + + // 记录姓氏 + String surname = tGiftBookDetailsVo.getName().substring(0, 1); + pageSurnameMap.computeIfAbsent((tableList.size() + 1), k -> new LinkedHashSet<>()).add(surname); + } + // 最后一页 + tableList.add(table); + table.addCell(new Cell(1, 4).add(new Paragraph("总计:" + totalAmount.intValue()))); + + // 最后插入目录页 + Document directoryDoc = new Document(pdfDoc); + + for (Map.Entry> entry : pageSurnameMap.entrySet()) { + int pageNum = entry.getKey(); + String surnames = String.join("、", entry.getValue()); + directoryDoc.add(new Paragraph("第 " + pageNum + " 页 ------ " + surnames).setFont(font).setFontSize(17)); + } + BigDecimal size = new BigDecimal(pageSurnameMap.size()); + BigDecimal section = new BigDecimal(20); + BigDecimal bigDecimal = size.divide(section, 2, RoundingMode.HALF_UP); + int num = 0; + // 是否是整数 + num = bigDecimal.intValue(); + String string = bigDecimal.toString(); + String[] split = string.split("\\."); + if (Integer.parseInt(split[1]) > 0) { + num = bigDecimal.intValue() + 1; + } + for (int i = 0; i < num; i++) { + document.add(new AreaBreak()); // 换页 + } + + for (int i = 0; i < tableList.size(); i++) { + Table table1 = tableList.get(i); + document.add(table1); + if (i != tableList.size() - 1) { + document.add(new AreaBreak()); // 换页 + } + } + + + // 7. 添加页码(从第二页开始) + // 1. 先给 PDF 添加页码 + int totalPages = pdfDoc.getNumberOfPages(); + for (int i = num + 1; i <= totalPages; i++) { + PdfPage page = pdfDoc.getPage(i); + PdfCanvas canvas = new PdfCanvas(page); + String pageText = "第 " + (i - num) + " 页"; // 目录是第一页,所以 -1 + float x = page.getPageSize().getWidth() / 2 - 20; // 居中 + float y = 20; // 页脚高度 20px + + canvas.beginText() + .setFontAndSize(font, 16) + .moveText(x, y) + .showText(pageText) + .endText() + .release(); + } + + // 8. 关闭文档 + document.close(); + return baos.toByteArray(); + } } diff --git a/giftBook-modules/giftBook-main/src/main/resources/fonts/MicrosoftYaHei.ttf b/giftBook-modules/giftBook-main/src/main/resources/fonts/MicrosoftYaHei.ttf new file mode 100644 index 0000000..865c35b Binary files /dev/null and b/giftBook-modules/giftBook-main/src/main/resources/fonts/MicrosoftYaHei.ttf differ diff --git a/giftBook-modules/giftBook-main/src/main/resources/mapper/main/TGiftBookDetailsMapper.xml b/giftBook-modules/giftBook-main/src/main/resources/mapper/main/TGiftBookDetailsMapper.xml index 746538e..0b054be 100644 --- a/giftBook-modules/giftBook-main/src/main/resources/mapper/main/TGiftBookDetailsMapper.xml +++ b/giftBook-modules/giftBook-main/src/main/resources/mapper/main/TGiftBookDetailsMapper.xml @@ -35,21 +35,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and tgb.del_flag = 0 and tgbd.del_flag = 0 - - and tgb.id = #{giftBookId} + + and tgb.id = #{bo.giftBookId} - - and tgbd.name like concat('%', #{name}, '%') + + and tgbd.name like concat('%', #{bo.name}, '%') - - and tgbd.event_type = #{eventType} + + and tgbd.event_type = #{bo.eventType} - - and tgbd.address like concat('%', #{address}, '%') + + and tgbd.address like concat('%', #{bo.address}, '%') - - and tgbd.event_name like concat('%', #{eventName}, '%') + + and tgbd.event_name like concat('%', #{bo.eventName}, '%') + order by + + + tgbd.${pageQuery.orderByColumn} ${pageQuery.isAsc} + + + tgbd.update_time desc + + diff --git a/giftBook-modules/pom.xml b/giftBook-modules/pom.xml index c6d1b03..c53d04e 100644 --- a/giftBook-modules/pom.xml +++ b/giftBook-modules/pom.xml @@ -22,7 +22,7 @@ pom - ruoyi-modules 业务模块 + giftBook-modules 业务模块