一些优化
This commit is contained in:
parent
8979f6449b
commit
a9a95c4d0d
|
|
@ -38,7 +38,6 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.ResourceUtils;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.thymeleaf.TemplateEngine;
|
import org.thymeleaf.TemplateEngine;
|
||||||
import org.thymeleaf.context.Context;
|
import org.thymeleaf.context.Context;
|
||||||
|
|
@ -51,7 +50,6 @@ import org.ttzero.excel.reader.Sheet;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
@ -338,8 +336,6 @@ public class StructuralPackageControllerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exportPdf(HttpServletResponse response, @Valid @NotNull Long id) throws Exception {
|
public void exportPdf(HttpServletResponse response, @Valid @NotNull Long id) throws Exception {
|
||||||
File file = ResourceUtils.getFile("classpath:template/StructuralPackage.html");
|
|
||||||
VUtil.trueThrowBusinessError(!file.exists()).throwMessage("模板文件不存在");
|
|
||||||
PackageVO vo = packageService.getInfo(id);
|
PackageVO vo = packageService.getInfo(id);
|
||||||
VUtil.trueThrowBusinessError(Objects.isNull(vo)).throwMessage("数据不存在");
|
VUtil.trueThrowBusinessError(Objects.isNull(vo)).throwMessage("数据不存在");
|
||||||
TemplateEngine templateEngine = new TemplateEngine();
|
TemplateEngine templateEngine = new TemplateEngine();
|
||||||
|
|
@ -353,6 +349,6 @@ public class StructuralPackageControllerService {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
context.setVariables(variables);
|
context.setVariables(variables);
|
||||||
String html = templateEngine.process("StructuralPackage", context);
|
String html = templateEngine.process("StructuralPackage", context);
|
||||||
PdfGeneratorUtil.generatePdf(vo.getNo() + "老鼠图", html, file.toURI().toURL().toString(), response);
|
PdfGeneratorUtil.generatePdf(vo.getNo() + "老鼠图", html, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,12 @@ package com.nflg.wms.admin.util;
|
||||||
|
|
||||||
import com.lowagie.text.pdf.BaseFont;
|
import com.lowagie.text.pdf.BaseFont;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.xhtmlrenderer.pdf.ITextRenderer;
|
import org.xhtmlrenderer.pdf.ITextRenderer;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
|
@ -13,10 +15,11 @@ public class PdfGeneratorUtil {
|
||||||
|
|
||||||
private static final String fontPath = "fonts/simsun.ttc";
|
private static final String fontPath = "fonts/simsun.ttc";
|
||||||
|
|
||||||
public static void generatePdf(String name,String html,String baseUrl, HttpServletResponse response) throws Exception {
|
public static void generatePdf(String name,String html, HttpServletResponse response) throws Exception {
|
||||||
ITextRenderer renderer = new ITextRenderer();
|
ITextRenderer renderer = new ITextRenderer();
|
||||||
renderer.getFontResolver().addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
|
renderer.getFontResolver().addFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
|
||||||
renderer.setDocumentFromString(html,baseUrl);
|
URL baseUrl = new ClassPathResource("template/").getURL();
|
||||||
|
renderer.setDocumentFromString(html,baseUrl.toString());
|
||||||
renderer.layout();
|
renderer.layout();
|
||||||
renderer.createPDF(response.getOutputStream());
|
renderer.createPDF(response.getOutputStream());
|
||||||
response.setContentType(MediaType.APPLICATION_PDF_VALUE);
|
response.setContentType(MediaType.APPLICATION_PDF_VALUE);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.nflg.wms.auth.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate() {
|
||||||
|
return new RestTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue