Showing
1 changed file
with
38 additions
and
24 deletions
| ... | ... | @@ -40,6 +40,7 @@ import com.lframework.xingyun.sc.service.customer.CustomerCreditService; |
| 40 | 40 | import com.lframework.xingyun.sc.service.customer.CustomerDevelopPlanService; |
| 41 | 41 | import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService; |
| 42 | 42 | import com.lframework.xingyun.sc.utils.LatexFormulaExcelExporterUtil; |
| 43 | +import com.lframework.xingyun.sc.utils.ResponseUtil; | |
| 43 | 44 | import com.lframework.xingyun.sc.vo.contract.createVo.CreateContractDistributorStandardVo; |
| 44 | 45 | import com.lframework.xingyun.sc.vo.contract.queryVo.QueryContractDistributorStandardVo; |
| 45 | 46 | import com.lframework.xingyun.sc.vo.contract.updateVo.UpdateContractDistributorStandardVo; |
| ... | ... | @@ -1132,7 +1133,8 @@ public class ContractDistributorStandardController extends DefaultBaseController |
| 1132 | 1133 | "contract-manage:processed-standard-contract:query" |
| 1133 | 1134 | }) |
| 1134 | 1135 | @GetMapping("/printStandardContract") |
| 1135 | - public void printStandardContract(@NotBlank(message = "合同不可为空") String id, HttpServletResponse response) throws IOException { | |
| 1136 | + public void printStandardContract(@NotBlank(message = "合同不可为空") String id, String exportType, | |
| 1137 | + HttpServletResponse response) throws IOException { | |
| 1136 | 1138 | InvokeResult<GetContractDistributorStandardBo> result = get(id); |
| 1137 | 1139 | GetContractDistributorStandardBo data = result.getData(); |
| 1138 | 1140 | |
| ... | ... | @@ -1306,31 +1308,43 @@ public class ContractDistributorStandardController extends DefaultBaseController |
| 1306 | 1308 | } |
| 1307 | 1309 | } |
| 1308 | 1310 | |
| 1309 | - // === 5. 调用 LibreOffice 转 PDF === | |
| 1310 | - pdfFile = convertExcelToPdf(tempExcel); | |
| 1311 | + if ("EXCEL".equalsIgnoreCase(exportType)) { | |
| 1312 | + ResponseUtil.setExcelResponseHead(response, data.getCode() + "_" + data.getBuyerName() + "-合同打印.xls"); | |
| 1313 | + try (InputStream excelIn = new FileInputStream(tempExcel)) { | |
| 1314 | + byte[] buffer = new byte[8192]; | |
| 1315 | + int len; | |
| 1316 | + while ((len = excelIn.read(buffer)) != -1) { | |
| 1317 | + response.getOutputStream().write(buffer, 0, len); | |
| 1318 | + } | |
| 1319 | + response.getOutputStream().flush(); | |
| 1320 | + } | |
| 1321 | + } else { | |
| 1322 | + // === 5. 调用 LibreOffice 转 PDF === | |
| 1323 | + pdfFile = convertExcelToPdf(tempExcel); | |
| 1311 | 1324 | |
| 1312 | - // === 6. 设置 PDF 响应头 === | |
| 1313 | - String fileName = data.getCode() + "_" + data.getBuyerName() + "-合同打印.pdf"; | |
| 1314 | - String encodedFileName; | |
| 1315 | - try { | |
| 1316 | - encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); | |
| 1317 | - } catch (UnsupportedEncodingException e) { | |
| 1318 | - // UTF-8 是标准编码,理论上不会抛出,但 Java 8 要求处理 | |
| 1319 | - throw new RuntimeException("UTF-8 encoding not supported", e); | |
| 1320 | - } | |
| 1321 | - response.setContentType("application/pdf"); | |
| 1322 | - response.setCharacterEncoding("UTF-8"); | |
| 1323 | - response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName); | |
| 1324 | - response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | |
| 1325 | - | |
| 1326 | - // === 7. 输出 PDF 到浏览器 === | |
| 1327 | - try (InputStream pdfIn = new FileInputStream(pdfFile)) { | |
| 1328 | - byte[] buffer = new byte[8192]; | |
| 1329 | - int len; | |
| 1330 | - while ((len = pdfIn.read(buffer)) != -1) { | |
| 1331 | - response.getOutputStream().write(buffer, 0, len); | |
| 1325 | + // === 6. 设置 PDF 响应头 === | |
| 1326 | + String fileName = data.getCode() + "_" + data.getBuyerName() + "-合同打印.pdf"; | |
| 1327 | + String encodedFileName; | |
| 1328 | + try { | |
| 1329 | + encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); | |
| 1330 | + } catch (UnsupportedEncodingException e) { | |
| 1331 | + // UTF-8 是标准编码,理论上不会抛出,但 Java 8 要求处理 | |
| 1332 | + throw new RuntimeException("UTF-8 encoding not supported", e); | |
| 1333 | + } | |
| 1334 | + response.setContentType("application/pdf"); | |
| 1335 | + response.setCharacterEncoding("UTF-8"); | |
| 1336 | + response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName); | |
| 1337 | + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | |
| 1338 | + | |
| 1339 | + // === 7. 输出 PDF 到浏览器 === | |
| 1340 | + try (InputStream pdfIn = new FileInputStream(pdfFile)) { | |
| 1341 | + byte[] buffer = new byte[8192]; | |
| 1342 | + int len; | |
| 1343 | + while ((len = pdfIn.read(buffer)) != -1) { | |
| 1344 | + response.getOutputStream().write(buffer, 0, len); | |
| 1345 | + } | |
| 1346 | + response.getOutputStream().flush(); | |
| 1332 | 1347 | } |
| 1333 | - response.getOutputStream().flush(); | |
| 1334 | 1348 | } |
| 1335 | 1349 | |
| 1336 | 1350 | } catch (Exception e) { | ... | ... |