Merge pull request 'beta' (#4) from beta into master

Reviewed-on: crm/crm-print#4
This commit is contained in:
luobai 2023-12-24 16:20:40 +08:00
commit b995656323
7 changed files with 117 additions and 46 deletions

View File

@ -1,5 +1,7 @@
FROM openjdk:8u181-jre-alpine FROM openjdk:8u181-jre-alpine
ENV LANG en_US.UTF-8 ENV LANG en_US.UTF-8
RUN mkdir -p /usr/share/fonts/chinese
COPY fonts/* /usr/share/fonts/chinese/
RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories &&\ RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories &&\
apk add tzdata &&\ apk add tzdata &&\
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone &&\ ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone &&\
@ -10,7 +12,6 @@ RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk
apk add msttcorefonts-installer &&\ apk add msttcorefonts-installer &&\
apk add fontconfig &&\ apk add fontconfig &&\
apk --update add unzip &&\ apk --update add unzip &&\
mkdir -p /usr/share/fonts/chinese &&\
cd /tmp &&\ cd /tmp &&\
wget http://kkfileview.keking.cn/fonts.zip &&\ wget http://kkfileview.keking.cn/fonts.zip &&\
unzip -d /usr/share/fonts/chinese fonts.zip &&\ unzip -d /usr/share/fonts/chinese fonts.zip &&\
@ -18,6 +19,11 @@ RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk
mkfontscale &&\ mkfontscale &&\
mkfontdir &&\ mkfontdir &&\
fc-cache -fv &&\ fc-cache -fv &&\
COPY /usr/share/fonts/korean /usr/share/fonts &&\
cd /usr/share/fonts/korean &&\
mkfontscale &&\
mkfontdir &&\
fc-cache -fv &&\
rm -rf /var/cache/* rm -rf /var/cache/*
COPY ./server/target/crm-print-server-1.0.0.jar / COPY ./server/target/crm-print-server-1.0.0.jar /

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

BIN
fonts/(환)세고딕.TTF Executable file

Binary file not shown.

View File

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.7" level="project" />
<orderEntry type="library" name="Maven: org.openoffice:juh:3.2.1" level="project" />
<orderEntry type="library" name="Maven: org.openoffice:jurt:3.2.1" level="project" />
<orderEntry type="library" name="Maven: org.openoffice:ridl:3.2.1" level="project" />
<orderEntry type="library" name="Maven: org.openoffice:unoil:3.2.1" level="project" />
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.1" level="project" />
<orderEntry type="library" name="Maven: org.hyperic:sigar:1.6.5.132" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20090211" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.testng:testng:6.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.beanshell:bsh:2.0b4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.beust:jcommander:1.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.6" level="project" />
</component>
</module>

View File

@ -229,8 +229,15 @@ public class ContractService {
return desc; return desc;
} }
/**
* 返回 pdf 文件
* @param templateName
* @param dataMap
* @return
* @throws Exception
*/
public File download(String templateName, Map<String, Object> dataMap) throws Exception { public File download(String templateName, Map<String, Object> dataMap,String type) throws Exception {
OutputStream os = null; OutputStream os = null;
try { try {
File outFile = new File(Consts.uploadAbsDir()); File outFile = new File(Consts.uploadAbsDir());
@ -259,10 +266,57 @@ public class ContractService {
xwpfDocument.write(os); xwpfDocument.write(os);
String outFilePath = Consts.uploadAbsDir()+ File.separator+ pdfName; String outFilePath = Consts.uploadAbsDir()+ File.separator+ pdfName;
officeToPdfService.openOfficeToPDF(pathFile, outFilePath); officeToPdfService.openOfficeToPDF(pathFile, outFilePath);
//返回pdf if("pdf".equals(type)){
return new File(outFilePath); //返回pdf
return new File(outFilePath);
}
//返回word //返回word
//return new File(pathFile); return new File(pathFile);
} finally {
if (os != null) {
os.close();
}
}
}
/**
* 返回 word 文件
* @param templateName
* @param dataMap
* @return
* @throws Exception
*/
public File downloadWord(String templateName, Map<String, Object> dataMap) throws Exception {
OutputStream os = null;
try {
File outFile = new File(Consts.uploadAbsDir());
if (!outFile.exists()) {
outFile.mkdirs();
}
String templatePath = Consts.getTemplatePath();
String abTemplatePath = templatePath + File.separator + templateName + ".docx";
//判断模板是否存在
File file = new File(abTemplatePath);
if(!file.exists()){
throw new KkFileException("请先上传模板!");
}
XWPFDocument xwpfDocument = WordExportUtil.exportWord07(abTemplatePath, dataMap);
//如果是签收单则需要合并单元格
if (Consts.RECEIPT_FORM.equals(templateName)){
List<Object> invoiceResList = (List<Object>) MapUtils.getObject(dataMap, "invoiceResList");
mergeCell(xwpfDocument,0,7,7+invoiceResList.size()-1,Arrays.asList(5,6));
}
String docxFile = "/"+ UUID.randomUUID().toString().replace("-", "") + ".docx";
//通过填参 生产文件 并放到 upload 文件夹中
String path = Consts.uploadAbsDir();
String pathFile = path + docxFile;
os = new FileOutputStream(pathFile);
xwpfDocument.write(os);
//返回word
return new File(pathFile);
} finally { } finally {
if (os != null) { if (os != null) {
os.close(); os.close();

View File

@ -5,6 +5,7 @@ import cn.keking.service.ContractService;
import cn.keking.utils.Consts; import cn.keking.utils.Consts;
import cn.keking.utils.ServiceResponse; import cn.keking.utils.ServiceResponse;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.github.xiaoymin.knife4j.core.util.StrUtil;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -119,17 +120,66 @@ public class ContractController {
@ApiParam(value = "模板名称: 销售合同: sellContract ; 销售框架合同: frameContract", required = true) @PathVariable String templateName, @ApiParam(value = "模板名称: 销售合同: sellContract ; 销售框架合同: frameContract", required = true) @PathVariable String templateName,
@io.swagger.v3.oas.annotations.parameters.RequestBody() @io.swagger.v3.oas.annotations.parameters.RequestBody()
@RequestBody Map<String, Object> dataMap, @RequestBody Map<String, Object> dataMap,
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,type);
outstream = response.getOutputStream();
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
String filename = dataMap.get("conCode") + "."+type;
response.reset();
// 设置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
response.addHeader("Content-Length", "" + file.length());
// 刷新缓冲
response.flushBuffer();
FileInputStream fileInputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
byte[] b = new byte[bufferedInputStream.available()];
bufferedInputStream.read(b);
outstream.write(b);
bufferedInputStream.close();
outstream.flush();
outstream.close();
return new ServiceResponse<>("success",
ServiceResponse.RESULT_CODE_SUCCESS_CODE);
} catch (Exception e) {
log.error("生成错误:", e);
if (e instanceof KkFileException) {
KkFileException kkFileException = (KkFileException) e;
return new ServiceResponse<>(null, kkFileException.getMessage(), ServiceResponse.RESULT_CODE_ERROR_CODE);
}
return new ServiceResponse<>(null, "fail", ServiceResponse.RESULT_SERVER_ERR_CODE);
}
}
/**
* 下载 word 文件
*/
@ApiParam("下载word文件")
@PostMapping("/downloadWord/{templateName}")
public ServiceResponse downloadWord(
@PathVariable String templateName,
@RequestBody Map<String, Object> dataMap,
HttpServletResponse response HttpServletResponse response
) { ) {
try { try {
log.error(JSON.toJSONString(dataMap)); log.error(JSON.toJSONString(dataMap));
OutputStream outstream = null; OutputStream outstream = null;
File file = contractService.download(templateName, dataMap); File file = contractService.downloadWord(templateName, dataMap);
outstream = response.getOutputStream(); outstream = response.getOutputStream();
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");
String filename = dataMap.get("conCode") + ".pdf"; String filename = dataMap.get("conCode") + ".docx";
response.reset(); response.reset();
// 设置response的Header // 设置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes())); response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));