diff --git a/server/src/main/java/cn/keking/service/ContractService.java b/server/src/main/java/cn/keking/service/ContractService.java index e663804..5b39011 100644 --- a/server/src/main/java/cn/keking/service/ContractService.java +++ b/server/src/main/java/cn/keking/service/ContractService.java @@ -237,7 +237,7 @@ public class ContractService { * @throws Exception */ - public File download(String templateName, Map dataMap) throws Exception { + public File download(String templateName, Map dataMap,String type) throws Exception { OutputStream os = null; try { File outFile = new File(Consts.uploadAbsDir()); @@ -266,10 +266,12 @@ public class ContractService { xwpfDocument.write(os); String outFilePath = Consts.uploadAbsDir()+ File.separator+ pdfName; officeToPdfService.openOfficeToPDF(pathFile, outFilePath); - //返回pdf - return new File(outFilePath); + if("pdf".equals(type)){ + //返回pdf + return new File(outFilePath); + } //返回word - //return new File(pathFile); + return new File(pathFile); } finally { if (os != null) { os.close(); diff --git a/server/src/main/java/cn/keking/web/controller/ContractController.java b/server/src/main/java/cn/keking/web/controller/ContractController.java index 75dc33e..22e9048 100644 --- a/server/src/main/java/cn/keking/web/controller/ContractController.java +++ b/server/src/main/java/cn/keking/web/controller/ContractController.java @@ -5,6 +5,7 @@ import cn.keking.service.ContractService; import cn.keking.utils.Consts; import cn.keking.utils.ServiceResponse; import com.alibaba.fastjson2.JSON; +import com.github.xiaoymin.knife4j.core.util.StrUtil; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -119,17 +120,21 @@ public class ContractController { @ApiParam(value = "模板名称: 销售合同: sellContract ; 销售框架合同: frameContract", required = true) @PathVariable String templateName, @io.swagger.v3.oas.annotations.parameters.RequestBody() @RequestBody Map dataMap, - HttpServletResponse response + HttpServletResponse response, + @RequestParam(value = "type", required = false) String type ) { try { log.error(JSON.toJSONString(dataMap)); OutputStream outstream = null; + if (type == null) { + type="pdf"; + } - File file = contractService.download(templateName, dataMap); + File file = contractService.download(templateName, dataMap,type); outstream = response.getOutputStream(); response.setCharacterEncoding("utf-8"); response.setContentType("application/octet-stream"); - String filename = dataMap.get("conCode") + ".pdf"; + String filename = dataMap.get("conCode") + "."+type; response.reset(); // 设置response的Header response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));