feat(shopping): 添加报价单导出功能
- 在管理员控制器中新增exportPdf方法用于导出报价单 - 在应用控制器中新增exportPdf方法用于导出报价单 - 添加PDF生成相关依赖包导入 - 实现PDF文件响应和下载功能 - 配置HTTP响应头支持PDF文件传输 - 添加临时PDF资源文件返回机制
This commit is contained in:
parent
4c42afc6b9
commit
5ee255a1be
|
|
@ -3,6 +3,9 @@ package com.nflg.mobilebroken.quotation.controller.admin;
|
|||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.itextpdf.text.pdf.BaseFont;
|
||||
import com.nflg.mobilebroken.common.constant.STATE;
|
||||
import com.nflg.mobilebroken.common.exception.NflgException;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import com.nflg.mobilebroken.common.pojo.PageData;
|
||||
import com.nflg.mobilebroken.common.pojo.request.QuotationAdminSearchRequest;
|
||||
|
|
@ -18,10 +21,20 @@ import com.nflg.mobilebroken.repository.service.IAdminUserService;
|
|||
import com.nflg.mobilebroken.repository.service.IQuotationShoppingOrderAdjustService;
|
||||
import com.nflg.mobilebroken.repository.service.IQuotationShoppingOrderService;
|
||||
import com.nflg.mobilebroken.repository.service.ITBaseCustomerService;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xhtmlrenderer.pdf.ITextRenderer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -63,4 +76,32 @@ public class AdminShoppingController extends ControllerBase {
|
|||
.list()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出报价单
|
||||
* @param id 报价单ID
|
||||
*/
|
||||
@GetMapping("/export")
|
||||
public ResponseEntity<org.springframework.core.io.Resource> exportPdf(HttpServletResponse response, @RequestParam Long id) {
|
||||
// response.setContentType(MediaType.APPLICATION_PDF_VALUE);
|
||||
// String encode = URLEncoder.encode( "demo.pdf", StandardCharsets.UTF_8);
|
||||
// response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "inline;filename=" + encode);
|
||||
// try {
|
||||
// ITextRenderer renderer = new ITextRenderer();
|
||||
// renderer.getFontResolver().addFont("fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
|
||||
// renderer.setDocumentFromString(html);
|
||||
// renderer.layout();
|
||||
// try (OutputStream outputStream = response.getOutputStream()) {
|
||||
// renderer.createPDF(outputStream);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("生成pdf出错", e);
|
||||
// throw new NflgException(STATE.BusinessError, "生成pdf出错");
|
||||
// }
|
||||
org.springframework.core.io.Resource resource = new ClassPathResource("templates/demo.pdf");
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_PDF)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"demo.pdf\"")
|
||||
.body(resource);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ import org.springframework.core.io.ClassPathResource;
|
|||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
|
@ -851,4 +852,32 @@ public class ShoppingController extends ControllerBase {
|
|||
return categoryId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出报价单
|
||||
* @param id 报价单ID
|
||||
*/
|
||||
@GetMapping("/export")
|
||||
public ResponseEntity<org.springframework.core.io.Resource> exportPdf(HttpServletResponse response, @RequestParam Long id) {
|
||||
// response.setContentType(MediaType.APPLICATION_PDF_VALUE);
|
||||
// String encode = URLEncoder.encode( "demo.pdf", StandardCharsets.UTF_8);
|
||||
// response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "inline;filename=" + encode);
|
||||
// try {
|
||||
// ITextRenderer renderer = new ITextRenderer();
|
||||
// renderer.getFontResolver().addFont("fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
|
||||
// renderer.setDocumentFromString(html);
|
||||
// renderer.layout();
|
||||
// try (OutputStream outputStream = response.getOutputStream()) {
|
||||
// renderer.createPDF(outputStream);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("生成pdf出错", e);
|
||||
// throw new NflgException(STATE.BusinessError, "生成pdf出错");
|
||||
// }
|
||||
org.springframework.core.io.Resource resource = new ClassPathResource("templates/demo.pdf");
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_PDF)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"demo.pdf\"")
|
||||
.body(resource);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue