From 6a4e3a5c4c34fdef0accc93d8a077ab016d15250 Mon Sep 17 00:00:00 2001 From: zhaowenxuan <chacca165@163.com> Date: 星期二, 15 七月 2025 18:01:23 +0800 Subject: [PATCH] pdf以及登记身份证人像处理 --- ltkj-admin/src/main/java/com/ltkj/web/controller/service/UtilsService.java | 80 ++++++++++++++++++++++++++ ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java | 5 + ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java | 38 ++++++++++++ ltkj-hosp/src/main/java/com/ltkj/hosp/domain/TjOrder.java | 2 ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCustomerController.java | 33 +--------- 5 files changed, 130 insertions(+), 28 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java index 2b95727..bb465d7 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java @@ -1847,6 +1847,44 @@ acroFields.setField(key, hashMap.get(key)); } pdfStamper.setFormFlattening(true); + + String isOpenSfzImg = sysConfigService.selectConfigByKey("pdf_isOpenSfzImg"); + String pathSfzfilePath = sysConfigService.selectConfigByKey("path_sfzfilePath"); + if (StrUtil.isNotBlank(isOpenSfzImg) && isOpenSfzImg.equalsIgnoreCase("y")){ + if (StrUtil.isNotBlank(pathSfzfilePath)){ + String key = DataSourceContextHolder.getDataSourceKey(); + key = key.replace("ltkjpeis10_",""); + if (new File(pathSfzfilePath + File.separator + key + File.separator+customer.getCusId()+".png").exists()) { + String pdfSfzimgwidth = sysConfigService.selectConfigByKey("pdf_sfzimgwidth"); + String pdfSfzimgheight = sysConfigService.selectConfigByKey("pdf_sfzimgheight"); + String pdfSfzimgy = sysConfigService.selectConfigByKey("pdf_sfzimgy"); + String pdfSfzimgx = sysConfigService.selectConfigByKey("pdf_sfzimgx"); + int width = 100,height = 100,x = 90,y = 180; + if (StrUtil.isNotBlank(pdfSfzimgwidth)) { + width = Integer.parseInt(pdfSfzimgwidth); + } + if (StrUtil.isNotBlank(pdfSfzimgheight)) { + height = Integer.parseInt(pdfSfzimgheight); + } + if (StrUtil.isNotBlank(pdfSfzimgy)) { + y = Integer.parseInt(pdfSfzimgy); + } + if (StrUtil.isNotBlank(pdfSfzimgx)) { + x = Integer.parseInt(pdfSfzimgx); + } + Image image = Image.getInstance(pathSfzfilePath + File.separator + key + File.separator+customer.getCusId()+".png"); + // 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏� + // image.setAbsolutePosition(90, 190); // 琛ㄥ崟宸﹁竟 + // image.setAbsolutePosition(495, 742); // 鍙充笂瑙� + // image.setAbsolutePosition(250, 50); // 涓笅 + image.setAbsolutePosition(x, y); + image.scaleAbsolute(width, height); // 璁剧疆鍥剧墖瀹藉害鍜岄珮搴� + PdfContentByte content = pdfStamper.getOverContent(1); + content.addImage(image); + } + } + } + pdfStamper.close(); reader4.close(); // 灏嗕慨鏀瑰悗鐨凱DF鍐呭鍐欏叆 diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/service/UtilsService.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/service/UtilsService.java new file mode 100644 index 0000000..f1f7cf3 --- /dev/null +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/service/UtilsService.java @@ -0,0 +1,80 @@ +package com.ltkj.web.controller.service; + +import cn.hutool.core.util.StrUtil; +import com.ltkj.hosp.domain.TjCustomer; +import com.ltkj.hosp.domain.TjOrder; +import com.ltkj.system.service.ISysConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.util.Base64; + +/** + * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 + * @Author: zhaowenxuan + * @Date: 2025/7/15 10:50 + */ +@Slf4j +@Component +public class UtilsService { + + @Autowired + private ISysConfigService sysConfigService; + + public void saveCustomerSfzImg(TjCustomer tjCustomer, String hospId){ + if (StrUtil.isNotBlank(tjCustomer.getSfzImg())){ + hospId = hospId.replace("ltkjpeis10_",""); + String value = sysConfigService.selectConfigByKey("path_sfzfilePath"); + String outputPath = value + File.separator + hospId + File.separator+tjCustomer.getCusId()+".png"; + File outFile = new File(outputPath); + File parentDir = outFile.getParentFile(); + if (!parentDir.exists()) { + parentDir.mkdirs(); + } + try { + String base64Str = tjCustomer.getSfzImg(); + if (base64Str.contains(",")) { + base64Str = base64Str.split(",")[1]; + } + byte[] imageBytes = Base64.getDecoder().decode(base64Str); + try (OutputStream out = new FileOutputStream(outFile)) { + out.write(imageBytes); + out.flush(); + } + } catch (Exception e) { + log.error("淇濆瓨韬唤璇佷汉鍍忓浘鐗囧け璐�",e); + } + } + } + + public void saveCustomerSfzImg(String imgBase, String hospId,String cusId){ + if (StrUtil.isNotBlank(imgBase)){ + hospId = hospId.replace("ltkjpeis10_",""); + String value = sysConfigService.selectConfigByKey("path_sfzfilePath"); + String outputPath = value + File.separator + hospId + File.separator+cusId+".png"; + File outFile = new File(outputPath); + File parentDir = outFile.getParentFile(); + if (!parentDir.exists()) { + parentDir.mkdirs(); + } + try { + String base64Str = imgBase; + if (base64Str.contains(",")) { + base64Str = base64Str.split(",")[1]; + } + byte[] imageBytes = Base64.getDecoder().decode(base64Str); + try (OutputStream out = Files.newOutputStream(outFile.toPath())) { + out.write(imageBytes); + out.flush(); + } + } catch (Exception e) { + log.error("淇濆瓨韬唤璇佷汉鍍忓浘鐗囧け璐�",e); + } + } + } +} diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCustomerController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCustomerController.java index d0c659a..d4a0e91 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCustomerController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCustomerController.java @@ -33,6 +33,7 @@ import com.ltkj.web.controller.his.HisApiGetMethodService; import com.ltkj.web.controller.his.HisApiMethod; import com.ltkj.web.controller.his.HisApiMethodService; +import com.ltkj.web.controller.service.UtilsService; import com.ltkj.web.wxUtils.HttpClientUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -93,6 +94,8 @@ private HisApiMethod hisApiMethod; @Autowired private HisApiMethodService controller; + @Autowired + private UtilsService utilsService; //灏嗘柟娉曡繑鍥炲�艰В鏋愭垚json鏍煎紡 @@ -548,44 +551,18 @@ TjCustomer requestCommonHisApi = isRequestCommonHisApi(tjCustomer); if (null !=requestCommonHisApi){ if (tjCustomerService.save(requestCommonHisApi)) { - saveCustomerSfzImg(tjCustomer,dataSourceType); + utilsService.saveCustomerSfzImg(tjCustomer,dataSourceType); return AjaxResult.success(requestCommonHisApi); } } }else { if (tjCustomerService.save(tjCustomer)) { - saveCustomerSfzImg(tjCustomer,dataSourceType); + utilsService.saveCustomerSfzImg(tjCustomer,dataSourceType); return AjaxResult.success(tjCustomer); } } } return AjaxResult.error(); - } - - private void saveCustomerSfzImg(TjCustomer tjCustomer,String hospId){ - if (StrUtil.isNotBlank(tjCustomer.getSfzImg())){ - hospId = hospId.replace("ltkjpeis10_",""); - String value = sysConfigService.selectConfigByKey("path_sfzfilePath"); - String outputPath = value + File.separator + hospId + File.separator+tjCustomer.getCusId()+".jpg"; - File outFile = new File(outputPath); - File parentDir = outFile.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); - } - try { - String base64Str = tjCustomer.getSfzImg(); - if (base64Str.contains(",")) { - base64Str = base64Str.split(",")[1]; - } - byte[] imageBytes = Base64.getDecoder().decode(base64Str); - try (OutputStream out = new FileOutputStream(outFile)) { - out.write(imageBytes); - out.flush(); - } - } catch (Exception e) { - log.error("淇濆瓨韬唤璇佷汉鍍忓浘鐗囧け璐�",e); - } - } } private TjCustomer isRequestCommonHisApi(TjCustomer tjCustomer) { diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java index 30e626a..019a71c 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java @@ -46,6 +46,7 @@ import com.ltkj.common.core.redis.RedisCache; import com.ltkj.common.enums.DataSourceType; import com.ltkj.common.utils.*; +import com.ltkj.db.DataSourceContextHolder; import com.ltkj.framework.config.MatchUtils; import com.ltkj.framework.config.ThreadPoolConfig; import com.ltkj.framework.config.UserHoder; @@ -81,6 +82,7 @@ import com.ltkj.web.controller.lis.LisApiMethod; import com.ltkj.web.controller.pacs.PacsApiMethodService; import com.ltkj.web.controller.service.TjSysAsyncServiceImpl; +import com.ltkj.web.controller.service.UtilsService; import com.ltkj.web.wxUtils.HttpClientUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -242,6 +244,8 @@ private TjOrderYcxmService ycxmService; @Autowired private TbTransitionMapper tbTransitionMapper; + @Autowired + private UtilsService utilsService; private static final String TJH = "tjhs:tjh"; @@ -1046,6 +1050,7 @@ // tjOrder.setTjType("2"); // } } + utilsService.saveCustomerSfzImg(tjOrder.getSfzImg(), DataSourceContextHolder.getDataSourceKey(), String.valueOf(tjCustomer.getCusId())); if (StringUtil.isBlank(tjOrder.getFirmId())) { tjOrder.setFirmId("0"); } diff --git a/ltkj-hosp/src/main/java/com/ltkj/hosp/domain/TjOrder.java b/ltkj-hosp/src/main/java/com/ltkj/hosp/domain/TjOrder.java index fa48657..0827ead 100644 --- a/ltkj-hosp/src/main/java/com/ltkj/hosp/domain/TjOrder.java +++ b/ltkj-hosp/src/main/java/com/ltkj/hosp/domain/TjOrder.java @@ -513,6 +513,8 @@ private String sjJyr; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date sjJysj; + @TableField(exist = false) + private String sfzImg; @Override -- Gitblit v1.8.0