Merge branch 'dev' into beta

This commit is contained in:
huangsheng 2023-12-07 13:38:35 +08:00
commit c9f7c850f6
7 changed files with 99 additions and 40 deletions

View File

@ -1,5 +1,7 @@
FROM openjdk:8u181-jre-alpine
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 &&\
apk add tzdata &&\
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 fontconfig &&\
apk --update add unzip &&\
mkdir -p /usr/share/fonts/chinese &&\
cd /tmp &&\
wget http://kkfileview.keking.cn/fonts.zip &&\
unzip -d /usr/share/fonts/chinese fonts.zip &&\

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,6 +229,13 @@ public class ContractService {
return desc;
}
/**
* 返回 pdf 文件
* @param templateName
* @param dataMap
* @return
* @throws Exception
*/
public File download(String templateName, Map<String, Object> dataMap) throws Exception {
OutputStream os = null;
@ -269,4 +276,49 @@ public class ContractService {
}
}
}
/**
* 返回 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 {
if (os != null) {
os.close();
}
}
}
}

View File

@ -155,4 +155,49 @@ public class ContractController {
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
) {
try {
log.error(JSON.toJSONString(dataMap));
OutputStream outstream = null;
File file = contractService.downloadWord(templateName, dataMap);
outstream = response.getOutputStream();
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
String filename = dataMap.get("conCode") + ".docx";
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);
}
}
}