添加礼薄详情导出PDF功能
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-bom common依赖项
|
giftBook-common-bom common依赖项
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-core</artifactId>
|
<artifactId>giftBook-common-core</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-core 核心模块
|
giftBook-common-core 核心模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-doc</artifactId>
|
<artifactId>giftBook-common-doc</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-doc 系统接口
|
giftBook-common-doc 系统接口
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-encrypt</artifactId>
|
<artifactId>giftBook-common-encrypt</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-encrypt 数据加解密模块
|
giftBook-common-encrypt 数据加解密模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-excel</artifactId>
|
<artifactId>giftBook-common-excel</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-excel
|
giftBook-common-excel
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-idempotent</artifactId>
|
<artifactId>giftBook-common-idempotent</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-idempotent 幂等功能
|
giftBook-common-idempotent 幂等功能
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-job</artifactId>
|
<artifactId>giftBook-common-job</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-job 定时任务
|
giftBook-common-job 定时任务
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-json</artifactId>
|
<artifactId>giftBook-common-json</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-json 序列化模块
|
giftBook-common-json 序列化模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-log</artifactId>
|
<artifactId>giftBook-common-log</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-log 日志记录
|
giftBook-common-log 日志记录
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-mail</artifactId>
|
<artifactId>giftBook-common-mail</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-mail 邮件模块
|
giftBook-common-mail 邮件模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-mybatis</artifactId>
|
<artifactId>giftBook-common-mybatis</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-mybatis 数据库服务
|
giftBook-common-mybatis 数据库服务
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-oss</artifactId>
|
<artifactId>giftBook-common-oss</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-oss oss服务
|
giftBook-common-oss oss服务
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-ratelimiter</artifactId>
|
<artifactId>giftBook-common-ratelimiter</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-ratelimiter 限流功能
|
giftBook-common-ratelimiter 限流功能
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-redis</artifactId>
|
<artifactId>giftBook-common-redis</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-redis 缓存服务
|
giftBook-common-redis 缓存服务
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-security</artifactId>
|
<artifactId>giftBook-common-security</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-security 安全模块
|
giftBook-common-security 安全模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-sensitive</artifactId>
|
<artifactId>giftBook-common-sensitive</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-sensitive 脱敏模块
|
giftBook-common-sensitive 脱敏模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-sms</artifactId>
|
<artifactId>giftBook-common-sms</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-sms 短信模块
|
giftBook-common-sms 短信模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-social</artifactId>
|
<artifactId>giftBook-common-social</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-social 授权认证
|
giftBook-common-social 授权认证
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-sse</artifactId>
|
<artifactId>giftBook-common-sse</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-sse 模块
|
giftBook-common-sse 模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-tenant</artifactId>
|
<artifactId>giftBook-common-tenant</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-tenant 租户模块
|
giftBook-common-tenant 租户模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-translation</artifactId>
|
<artifactId>giftBook-common-translation</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-translation 通用翻译功能
|
giftBook-common-translation 通用翻译功能
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-web</artifactId>
|
<artifactId>giftBook-common-web</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-web web服务
|
giftBook-common-web web服务
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<artifactId>giftBook-common-websocket</artifactId>
|
<artifactId>giftBook-common-websocket</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-common-websocket 模块
|
giftBook-common-websocket 模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -59,5 +59,17 @@
|
|||||||
<groupId>cn.xxzhx.giftBook</groupId>
|
<groupId>cn.xxzhx.giftBook</groupId>
|
||||||
<artifactId>giftBook-common-tenant</artifactId>
|
<artifactId>giftBook-common-tenant</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- iText 9 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.itextpdf</groupId>
|
||||||
|
<artifactId>kernel</artifactId>
|
||||||
|
<version>9.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.itextpdf</groupId>
|
||||||
|
<artifactId>layout</artifactId>
|
||||||
|
<version>9.1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package cn.xxzhx.giftBook.main.controller;
|
package cn.xxzhx.giftBook.main.controller;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cn.xxzhx.giftBook.common.excel.core.ExcelResult;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.constraints.*;
|
import jakarta.validation.constraints.*;
|
||||||
@@ -88,7 +89,7 @@ public class TGiftBookDetailsController extends BaseController {
|
|||||||
@SaCheckPermission("main:giftBookDetails:query")
|
@SaCheckPermission("main:giftBookDetails:query")
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public R<TGiftBookDetailsVo> getInfo(@NotNull(message = "主键不能为空")
|
public R<TGiftBookDetailsVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
@PathVariable Long id) {
|
@PathVariable Long id) {
|
||||||
return R.ok(tGiftBookDetailsService.queryById(id));
|
return R.ok(tGiftBookDetailsService.queryById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,4 +127,23 @@ public class TGiftBookDetailsController extends BaseController {
|
|||||||
@PathVariable Long[] ids) {
|
@PathVariable Long[] ids) {
|
||||||
return toAjax(tGiftBookDetailsService.deleteWithValidByIds(List.of(ids), true));
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,5 @@ public interface TGiftBookDetailsMapper extends BaseMapperPlus<TGiftBookDetails,
|
|||||||
|
|
||||||
Page<TGiftBookDetailsVo> selectPageList(@Param("bo") TGiftBookDetailsBo bo, IPage<TGiftBookDetailsVo> page);
|
Page<TGiftBookDetailsVo> selectPageList(@Param("bo") TGiftBookDetailsBo bo, IPage<TGiftBookDetailsVo> page);
|
||||||
|
|
||||||
List<TGiftBookDetailsVo> queryList(TGiftBookDetailsBo bo);
|
List<TGiftBookDetailsVo> queryList(@Param("bo") TGiftBookDetailsBo bo,@Param("pageQuery") PageQuery pageQuery);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.xxzhx.giftBook.main.domain.vo.TGiftBookDetailsVo;
|
|||||||
import cn.xxzhx.giftBook.main.domain.bo.TGiftBookDetailsBo;
|
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.TableDataInfo;
|
||||||
import cn.xxzhx.giftBook.common.mybatis.core.page.PageQuery;
|
import cn.xxzhx.giftBook.common.mybatis.core.page.PageQuery;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -68,4 +69,5 @@ public interface ITGiftBookDetailsService {
|
|||||||
|
|
||||||
String importData(List<TGiftBookDetailsVo> tGiftBookDetailsVos);
|
String importData(List<TGiftBookDetailsVo> tGiftBookDetailsVos);
|
||||||
|
|
||||||
|
byte[] exportPDF(TGiftBookDetailsBo bo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.MapstructUtils;
|
||||||
import cn.xxzhx.giftBook.common.core.utils.StreamUtils;
|
import cn.xxzhx.giftBook.common.core.utils.StreamUtils;
|
||||||
import cn.xxzhx.giftBook.common.core.utils.StringUtils;
|
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.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.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.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 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.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
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.ConstraintViolation;
|
||||||
import jakarta.validation.ConstraintViolationException;
|
import jakarta.validation.ConstraintViolationException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.stereotype.Service;
|
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.io.IOException;
|
||||||
import java.util.List;
|
import java.math.BigDecimal;
|
||||||
import java.util.Map;
|
import java.math.RoundingMode;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,7 +98,8 @@ public class TGiftBookDetailsServiceImpl implements ITGiftBookDetailsService {
|
|||||||
public List<TGiftBookDetailsVo> queryList(TGiftBookDetailsBo bo) {
|
public List<TGiftBookDetailsVo> queryList(TGiftBookDetailsBo bo) {
|
||||||
// LambdaQueryWrapper<TGiftBookDetails> lqw = buildQueryWrapper(bo);
|
// LambdaQueryWrapper<TGiftBookDetails> lqw = buildQueryWrapper(bo);
|
||||||
// return baseMapper.selectVoList(lqw);
|
// return baseMapper.selectVoList(lqw);
|
||||||
return baseMapper.queryList(bo);
|
PageQuery pageQuery = new PageQuery(-1, 0);
|
||||||
|
return baseMapper.queryList(bo, pageQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LambdaQueryWrapper<TGiftBookDetails> buildQueryWrapper(TGiftBookDetailsBo bo) {
|
private LambdaQueryWrapper<TGiftBookDetails> buildQueryWrapper(TGiftBookDetailsBo bo) {
|
||||||
@@ -197,4 +215,139 @@ public class TGiftBookDetailsServiceImpl implements ITGiftBookDetailsService {
|
|||||||
return successMsg.toString();
|
return successMsg.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] exportPDF(TGiftBookDetailsBo bo) {
|
||||||
|
PageQuery pageQuery = new PageQuery(-1, 0);
|
||||||
|
pageQuery.setOrderByColumn("name");
|
||||||
|
pageQuery.setIsAsc("asc");
|
||||||
|
List<TGiftBookDetailsVo> tGiftBookDetailsVos = baseMapper.queryList(bo, pageQuery);
|
||||||
|
try {
|
||||||
|
return createPdf(tGiftBookDetailsVos);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("导出PDF失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] createPdf(List<TGiftBookDetailsVo> 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<Integer, Set<String>> 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<Table> tableList = new ArrayList<>();
|
||||||
|
// 拼接
|
||||||
|
List<String> 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<Integer, Set<String>> 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -35,21 +35,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<where>
|
<where>
|
||||||
and tgb.del_flag = 0
|
and tgb.del_flag = 0
|
||||||
and tgbd.del_flag = 0
|
and tgbd.del_flag = 0
|
||||||
<if test="null != giftBookId">
|
<if test="null != bo.giftBookId">
|
||||||
and tgb.id = #{giftBookId}
|
and tgb.id = #{bo.giftBookId}
|
||||||
</if>
|
</if>
|
||||||
<if test="null != name">
|
<if test="null != bo.name">
|
||||||
and tgbd.name like concat('%', #{name}, '%')
|
and tgbd.name like concat('%', #{bo.name}, '%')
|
||||||
</if>
|
</if>
|
||||||
<if test="null != eventType">
|
<if test="null != bo.eventType">
|
||||||
and tgbd.event_type = #{eventType}
|
and tgbd.event_type = #{bo.eventType}
|
||||||
</if>
|
</if>
|
||||||
<if test="null != address">
|
<if test="null != bo.address">
|
||||||
and tgbd.address like concat('%', #{address}, '%')
|
and tgbd.address like concat('%', #{bo.address}, '%')
|
||||||
</if>
|
</if>
|
||||||
<if test="null != eventName">
|
<if test="null != bo.eventName">
|
||||||
and tgbd.event_name like concat('%', #{eventName}, '%')
|
and tgbd.event_name like concat('%', #{bo.eventName}, '%')
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
|
order by
|
||||||
|
<choose>
|
||||||
|
<when test="null != pageQuery.isAsc and pageQuery.isAsc.length() > 0">
|
||||||
|
tgbd.${pageQuery.orderByColumn} ${pageQuery.isAsc}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
tgbd.update_time desc
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
ruoyi-modules 业务模块
|
giftBook-modules 业务模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
Reference in New Issue
Block a user