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