Commit 5e08ef36 authored by xixinzhao's avatar xixinzhao

fix(jg): 安装告知打印告知单改为下载

parent b9c554b1
......@@ -7,6 +7,7 @@ import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.module.jg.api.dto.JgInstallationNoticeDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgInstallationNotice;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
......@@ -65,5 +66,5 @@ public interface IJgInstallationNoticeService extends IService<JgInstallationNot
* @param sequenceNbr 主键
* @return pdf文件路径
*/
String generateInstallationNoticeReport(Long sequenceNbr);
void generateInstallationNoticeReport(Long sequenceNbr, HttpServletResponse response);
}
......@@ -107,7 +107,8 @@
ei.legal_person AS safetyManager,
ei.legal_phone AS safetyManagerPhone,
ei.address AS address,
ei.use_code AS useCode
ei.use_code AS useCode,
isn.install_unit_credit_code AS installUnitCreditCode
FROM
tzs_jg_installation_notice isn
LEFT JOIN tzs_jg_installation_notice_eq re ON re.equip_transfer_id = isn.sequence_nbr
......
......@@ -18,6 +18,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -141,7 +142,7 @@ public class JgInstallationNoticeController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "安装告知列表全部数据查询", notes = "安装告知列表全部数据查询")
@GetMapping(value = "/generate-report")
public ResponseModel<String> generateReport(@RequestParam("sequenceNbr") Long sequenceNbr) {
return ResponseHelper.buildResponse(iJgInstallationNoticeService.generateInstallationNoticeReport(sequenceNbr));
public void generateReport(HttpServletResponse response, @RequestParam("sequenceNbr") Long sequenceNbr) {
iJgInstallationNoticeService.generateInstallationNoticeReport(sequenceNbr, response);
}
}
......@@ -65,6 +65,7 @@ import java.nio.file.Files;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -310,7 +311,7 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
* @return pdf文件路径
*/
@Override
public String generateInstallationNoticeReport(Long sequenceNbr) {
public void generateInstallationNoticeReport(Long sequenceNbr, HttpServletResponse response) {
if (Objects.isNull(sequenceNbr)) {
throw new IllegalArgumentException("参数不能为空");
}
......@@ -322,7 +323,7 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
}
Map<String, Object> installation = informationList.get(0);
String useCode = String.valueOf(installation.get("useCode"));
String useCode = String.valueOf(installation.get("installUnitCreditCode"));
LambdaQueryWrapper<TzBaseUnitLicence> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(TzBaseUnitLicence::getUnitCode, useCode);
List<TzBaseUnitLicence> list = baseUnitLicenceMapper.selectList(wrapper);
......@@ -372,13 +373,15 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
String qrCode = ImageUtils.generateQRCode(getValue.apply("applyNo"), 300, 300);
placeholders.put("qrCode", qrCode);
String url = WordTemplateUtils.templateToPdf("installation-notification-report.ftl", placeholders);
// String url = WordTemplateUtils.templateToPdf("installation-notification-report.ftl", placeholders);
// 更新到数据库
jgInstallationNotice.setNoticeReportUrl(url);
this.updateById(jgInstallationNotice);
return url;
// jgInstallationNotice.setNoticeReportUrl(url);
// this.updateById(jgInstallationNotice);
//
// return url;
String tempFileName = "安装告知单_" + System.currentTimeMillis() + "_temp";
WordTemplateUtils.templateToPdfDownload(tempFileName, "installation-notification-report.ftl", placeholders, response);
}
@Override
......@@ -776,12 +779,12 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
useInfoService.saveOrUpdateData(useInfo);
}
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
generateInstallationNoticeReport(jgInstallationNotice.getSequenceNbr());
}
});
// TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
// @Override
// public void afterCommit() {
// generateInstallationNoticeReport(jgInstallationNotice.getSequenceNbr());
// }
// });
} else {
jgInstallationNotice.setNextExecuteIds(String.join(",", roleList));
if (!ObjectUtils.isEmpty(jgInstallationNotice.getInstanceStatus())) {
......
......@@ -318,7 +318,8 @@ public class JgMaintainNoticeServiceImpl extends BaseService<JgMaintainNoticeDto
placeholders.put("qrCode", qrCode);
placeholders.put("installLicenseNoList", installLicenseNoList);//许可证编号
placeholders.put("installLicenseExpirationDateList", installLicenseExpirationDateList);//许可证有效期
String url = WordTemplateUtils.templateToPdf("installation-notification-report.ftl", placeholders);
String tempFileName = "安装告知单_" + System.currentTimeMillis() + "_temp";
String url = WordTemplateUtils.templateToPdf(tempFileName, "installation-notification-report.ftl", placeholders);
// 更新到数据库
JgMaintainNotice.setNoticeReportUrl(url);
this.updateById(JgMaintainNotice);
......
......@@ -344,7 +344,8 @@ public class JgReformNoticeServiceImpl extends BaseService<JgReformNoticeDto, Jg
placeholders.put("installLicenseNoList", installLicenseNoList);
placeholders.put("installLicenseExpirationDateList", installLicenseExpirationDateList);
log.info("改造告知单 => {}", JSON.toJSONString(placeholders));
String url = WordTemplateUtils.templateToPdf("installation-notification-report.ftl", placeholders);
String tempFileName = "安装告知单_" + System.currentTimeMillis() + "_temp";
String url = WordTemplateUtils.templateToPdf(tempFileName, "installation-notification-report.ftl", placeholders);
// 更新到数据库
JgReformNotice.setNoticeReportUrl(url);
......
......@@ -175,7 +175,7 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
}
Map<String, Object> maintain = informationList.get(0);
String useCode = String.valueOf(maintain.get("useCode"));
String useCode = String.valueOf(maintain.get("installUnitCreditCode"));
LambdaQueryWrapper<TzBaseUnitLicence> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(TzBaseUnitLicence::getUnitCode, useCode);
List<TzBaseUnitLicence> list = baseUnitLicenceMapper.selectList(wrapper);
......@@ -223,8 +223,8 @@ public class JgTransferNoticeServiceImpl extends BaseService<JgTransferNoticeDto
placeholders.put("installLicenseNoList", installLicenseNoList);
placeholders.put("installLicenseExpirationDateList", installLicenseExpirationDateList);
String url = WordTemplateUtils.templateToPdf("installation-notification-report.ftl", placeholders);
String tempFileName = "安装告知单_" + System.currentTimeMillis() + "_temp";
String url = WordTemplateUtils.templateToPdf(tempFileName, "installation-notification-report.ftl", placeholders);
// 更新到数据库
jgTransferNotice.setNoticeReportUrl(url);
......
......@@ -13,7 +13,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
......@@ -131,11 +133,11 @@ public class WordTemplateUtils {
return result;
}
public static String templateToPdf(String wordPath, Map<String, Object> placeholders) {
public static String templateToPdf(String pdfName, String wordPath, Map<String, Object> placeholders) {
// word转pdf
File pdfFile;
try {
pdfFile = wordToPdf(wordPath, placeholders);
pdfFile = wordToPdf(pdfName, wordPath, placeholders);
} catch (Exception e) {
throw new RuntimeException(e);
}
......@@ -152,7 +154,33 @@ public class WordTemplateUtils {
return url;
}
public static byte[] file2byte(File file) {
public static void templateToPdfDownload(String pdfName, String wordPath, Map<String, Object> placeholders, HttpServletResponse response) {
// word转pdf
File pdfFile;
try {
pdfFile = wordToPdf(pdfName, wordPath, placeholders);
} catch (Exception e) {
log.error("模板转pdf失败:", e);
throw new BadRequest("模板转pdf失败");
}
try {
byte[] bytes = file2byte(pdfFile);
String docTitle = pdfFile.getName();
FileExporter.exportFile(FileExporter.FileType.valueOf("pdf"), docTitle, bytes, response);
} catch (Exception e) {
log.error("文档导出失败:", e);
} finally {
try {
Files.deleteIfExists(pdfFile.toPath());
} catch (Exception e) {
log.error("文件找不到,删除失败:", e);
}
}
}
private static byte[] file2byte(File file) {
try {
FileInputStream in = new FileInputStream(file);
//当文件没有结束时,每次读取一个字节显示
......@@ -191,13 +219,11 @@ public class WordTemplateUtils {
*
* @param wordPath word文件路径
*/
private static File wordToPdf(String wordPath, Map<String, Object> placeholders) throws Exception {
private static File wordToPdf(String pdfName, String wordPath, Map<String, Object> placeholders) throws Exception {
Assert.hasText(wordPath, "word文件路径不能为空");
String tempFileName = "安装告知单_" + System.currentTimeMillis() + "_temp.pdf";
WordTemplateUtils instance = WordTemplateUtils.getInstance();
return instance.fillAndConvertDocFile(wordPath, tempFileName, placeholders, SaveFormat.PDF);
return instance.fillAndConvertDocFile(wordPath, pdfName, placeholders, SaveFormat.PDF);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment