|
...
|
...
|
@@ -35,6 +35,9 @@ import org.springframework.validation.annotation.Validated; |
|
35
|
35
|
import org.springframework.web.bind.annotation.*;
|
|
36
|
36
|
|
|
37
|
37
|
import javax.validation.Valid;
|
|
|
38
|
+import java.io.File;
|
|
|
39
|
+import java.io.FileInputStream;
|
|
|
40
|
+import java.io.FileOutputStream;
|
|
38
|
41
|
import java.io.InputStream;
|
|
39
|
42
|
import java.time.format.DateTimeFormatter;
|
|
40
|
43
|
import java.util.ArrayList;
|
|
...
|
...
|
@@ -113,7 +116,7 @@ public class SampleResultFeedbackController extends DefaultBaseController { |
|
113
|
116
|
*/
|
|
114
|
117
|
@ApiOperation("规格变更打印")
|
|
115
|
118
|
@GetMapping("/export")
|
|
116
|
|
- public void export(@NotBlank(message = "id不能为空") String id, @NotBlank(message = "导出类型不能为空") String exportType
|
|
|
119
|
+ public void export(@NotBlank(message = "id不能为空") String id, String exportType
|
|
117
|
120
|
, HttpServletResponse response) {
|
|
118
|
121
|
SampleResultFeedback data = sampleResultFeedbackService.findById(id);
|
|
119
|
122
|
if (data == null) {
|
|
...
|
...
|
@@ -123,7 +126,6 @@ public class SampleResultFeedbackController extends DefaultBaseController { |
|
123
|
126
|
try (InputStream inputStream = templateResource.getStream();
|
|
124
|
127
|
Workbook workbook = new XSSFWorkbook(inputStream)) {
|
|
125
|
128
|
Sheet sheet = workbook.getSheetAt(0);
|
|
126
|
|
- ResponseUtil.setExcelResponseHead(response, data.getOrderNo() + "-试样结果反馈单.xlsx");
|
|
127
|
129
|
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
128
|
130
|
List<SampleFeedbackTrackingDetail> detailList = data.getDetailList();
|
|
129
|
131
|
// ========== 起始行:5==========
|
|
...
|
...
|
@@ -174,8 +176,25 @@ public class SampleResultFeedbackController extends DefaultBaseController { |
|
174
|
176
|
|
|
175
|
177
|
ExcelUtil.processTemplate(workbook, dataMap);
|
|
176
|
178
|
if ("PDF".equals(exportType)) {
|
|
|
179
|
+ ResponseUtil.setPDFResponseHead(response, data.getOrderNo() + "-试样结果反馈单.xlsx");
|
|
177
|
180
|
// 输出为PDF文档
|
|
|
181
|
+ // === 写入临时 .xls 文件 ===
|
|
|
182
|
+ File tempExcel = File.createTempFile("sample_feedback_" + data.getOrderNo(), ".xls");
|
|
|
183
|
+ try (FileOutputStream fos = new FileOutputStream(tempExcel)) {
|
|
|
184
|
+ workbook.write(fos);
|
|
|
185
|
+ }
|
|
|
186
|
+ File pdfFile = ExcelUtil.convertExcelToPdf(tempExcel, "/usr/bin/libreoffice --headless --convert-to pdf --outdir %s %s");
|
|
|
187
|
+ // === 输出 PDF 到浏览器 ===
|
|
|
188
|
+ try (InputStream pdfIn = new FileInputStream(pdfFile)) {
|
|
|
189
|
+ byte[] buffer = new byte[8192];
|
|
|
190
|
+ int len;
|
|
|
191
|
+ while ((len = pdfIn.read(buffer)) != -1) {
|
|
|
192
|
+ response.getOutputStream().write(buffer, 0, len);
|
|
|
193
|
+ }
|
|
|
194
|
+ response.getOutputStream().flush();
|
|
|
195
|
+ }
|
|
178
|
196
|
} else {
|
|
|
197
|
+ ResponseUtil.setExcelResponseHead(response, data.getOrderNo() + "-试样结果反馈单.xlsx");
|
|
179
|
198
|
// 输出
|
|
180
|
199
|
workbook.write(response.getOutputStream());
|
|
181
|
200
|
response.getOutputStream().flush();
|
...
|
...
|
|