Commit b14a7162 authored by hezhuozhi's avatar hezhuozhi

压力管道安装告知告知书打印调整

parent 907d7e55
......@@ -170,10 +170,27 @@ public class IdxBizJgProjectContraptionServiceImpl extends BaseService<IdxBizJgP
);
record.setCanEdit(this.checkContraptionIsCanEdit(record.getSequenceNbr()));
record.setCanDelete(this.checkContraptionIsCanDelete(record.getSequenceNbr()));
//判断是否有检验结果录入
judgeCheckResult(record);
});
return pageList;
}
/**
* 此处判断是否有检验结果 所有的管道信息都需要有检验结果才可以展示
* @param record
*/
private void judgeCheckResult(IdxBizJgProjectContraption record) {
record.setDisableBasicButton(true);
if("8200".equals(record.getEquCategory()) || "8100".equals(record.getEquCategory())){
int notNullCount = this.baseMapper.selectCheckCountByNotNull(String.valueOf(record.getSequenceNbr()));
long total = this.baseMapper.selectEquipCount(String.valueOf(record.getSequenceNbr()));
if(total==notNullCount && total !=0){
record.setDisableBasicButton(false);
}
}
}
private Boolean checkContraptionIsCanEdit(Long projectContraptionId) {
Integer inUseTime = this.baseMapper.countContraptionInUseTimesForEdit(projectContraptionId);
return inUseTime <= 0;
......
......@@ -65,6 +65,7 @@ import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import io.seata.tm.api.GlobalTransactionContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
......@@ -85,12 +86,18 @@ import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static com.alibaba.fastjson.JSON.parseArray;
......@@ -183,6 +190,8 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
private IdxBizJgProjectContraptionMapper projectContraptionMapper;
@Autowired
EventPublisher eventPublisher;
@Autowired
private JgUseRegistrationServiceImpl jgUseRegistrationService;
/**
* 安装改造维修单位吱资质类型:1234-安改维、1236-制造单位
......@@ -656,7 +665,68 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
// jgInstallationNotice.setNoticeReportUrl(url);
// this.updateById(jgInstallationNotice);
map.put("equipBasicInfoList", maps);
WordTemplateUtils.templateToPdfDownload(tempFileName, "installation-notification-report.ftl", map, response);
// WordTemplateUtils.templateToPdfDownload(tempFileName, "installation-notification-report.ftl", map, response);
byte[] templateToPdfData = WordTemplateUtils.getTemplateToPdfData(tempFileName, "installation-notification-report.ftl", map);
//获取管道和气瓶的基本信息汇总表
List<CompletableFuture<byte[]>> exportSummaryBasicInfoData = jgUseRegistrationService.getExportSummaryBasicInfoData(Collections.singletonList(Long.valueOf(sequenceNbr)), jgInstallationNotice.getEquCategoryCode(),"安装告知");
//压缩包名称
String customFileName="";
//将安装告知单和汇总表压缩到zip中
toZipFileByData(response, exportSummaryBasicInfoData, templateToPdfData, customFileName,jgInstallationNotice.getEquCategoryCode());
}
/**
* 将数据全部压缩成zip
* @param response
* @param exportSummaryBasicInfoData
* @param templateToPdfData
* @param customFileName
* @param category
*/
private void toZipFileByData(HttpServletResponse response, List<CompletableFuture<byte[]>> exportSummaryBasicInfoData, byte[] templateToPdfData, String customFileName, String category) {
String filePrefix ="汇总表";
if ("8300".equals(category) || "8200".equals(category) || "8100".equals(category)) {
// 文件名前缀
filePrefix= "压力管道基本信息汇总表_";
}else if ("2300".equals(category)) {
// 文件名前缀
filePrefix = "气瓶基本信息汇总表_";
}
// 打包zip
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream)) {
for (int i = 0; i < exportSummaryBasicInfoData.size(); i++) {
try {
zip.putNextEntry(new ZipEntry(filePrefix + "第" + (i + 1) + "页" + ".pdf"));
IOUtils.write(exportSummaryBasicInfoData.get(i).join(), zip);
zip.closeEntry(); // 每个条目结束后关闭
} catch (IOException e) {
log.error("打包zip失败:" + e.getMessage());
throw new BadRequest("打包zip失败");
}
}
//添加安装告知单到zip中
try {
String tempFileName = "安装告知单_" + System.currentTimeMillis() + "_temp";
zip.putNextEntry(new ZipEntry(tempFileName + ".pdf"));
IOUtils.write(templateToPdfData, zip);
zip.closeEntry();
} catch (IOException e) {
log.error("打包zip失败:" + e.getMessage());
throw new BadRequest("打包zip失败");
}
// 所有条目写入完成后关闭 ZipOutputStream
zip.finish();
// 设置响应头并将压缩文件写入 HttpServletResponse
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/zip");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(customFileName, "UTF-8"));
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
IOUtils.write(outputStream.toByteArray(), response.getOutputStream());
} catch (IOException e) {
throw new RuntimeException("导出异常:", e);
}
}
public Map<String, Object> fullFillTemplateObj(List<Map<String, Object>> informationList, String businessType) {
......
......@@ -152,6 +152,27 @@ public class WordTemplateUtils {
return url;
}
public static byte[] getTemplateToPdfData(String pdfName, String wordPath, Map<String, Object> placeholders){
// word转pdf
File pdfFile;
try {
pdfFile = wordToPdf(pdfName, wordPath, placeholders);
} catch (Exception e) {
log.error("模板转pdf失败:", e);
throw new BadRequest("模板转pdf失败");
}
try {
return file2byte(pdfFile);
} finally {
try {
Files.deleteIfExists(pdfFile.toPath());
} catch (Exception e) {
log.error("文件找不到,删除失败:", e);
}
}
}
public static void templateToPdfDownload(String pdfName, String wordPath, Map<String, Object> placeholders, HttpServletResponse response) {
// word转pdf
File pdfFile;
......
......@@ -274,4 +274,10 @@ public class IdxBizJgProjectContraption extends BaseEntity {
*/
@TableField("is_first_merge")
private Boolean isFirstMerge;
/**
* 是否禁用打印汇总表按钮
*/
@TableField(exist = false)
private Boolean disableBasicButton;
}
......@@ -74,4 +74,9 @@ public interface IdxBizJgProjectContraptionMapper extends BaseMapper<IdxBizJgPro
* @return
*/
List<Map<String, Object>> selectEquipListByExport(@Param("sequenceNbr") String sequenceNbr);
/**
* 获取不为空的检验信息个数
*/
int selectCheckCountByNotNull(@Param("sequenceNbr") String sequenceNbr);
}
......@@ -242,4 +242,24 @@
WHERE ibjui.project_contraption_id = #{sequenceNbr}
ORDER BY ibjtpp.REC_DATE ASC
</select>
<select id="selectCheckCountByNotNull" resultType="int">
SELECT COUNT(1)
FROM
(
SELECT
( SELECT INSPECT_ORG_NAME FROM idx_biz_jg_inspection_detection_info WHERE "RECORD" = ibjui."RECORD" ORDER BY INSPECT_DATE DESC LIMIT 1 ) inspectOrgName,
( SELECT INSPECT_CONCLUSION FROM idx_biz_jg_inspection_detection_info WHERE "RECORD" = ibjui."RECORD" ORDER BY INSPECT_DATE DESC LIMIT 1 ) inspectConclusion,
( SELECT NEXT_INSPECT_DATE FROM idx_biz_jg_inspection_detection_info WHERE "RECORD" = ibjui."RECORD" ORDER BY INSPECT_DATE DESC LIMIT 1 ) nextInspectDate
FROM
idx_biz_jg_use_info ibjui
LEFT JOIN idx_biz_jg_tech_params_pipeline ibjtpp ON ibjui.RECORD = ibjtpp.RECORD
LEFT JOIN idx_biz_jg_design_info ibjdi ON ibjui.RECORD = ibjdi.RECORD
WHERE
ibjui.project_contraption_id = #{sequenceNbr}
) A
WHERE
A.inspectOrgName != NULL AND A.inspectOrgName != '' AND A.inspectConclusion!=NULL and A.inspectConclusion!=''
and A.nextInspectDate != NULL
</select>
</mapper>
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