zhaowenxuan
8 小时以前 6a4e3a5c4c34fdef0accc93d8a077ab016d15250
pdf以及登记身份证人像处理
4个文件已修改
1个文件已添加
158 ■■■■ 已修改文件
ltkj-admin/src/main/java/com/ltkj/web/controller/his/HisPDFUtil.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/java/com/ltkj/web/controller/service/UtilsService.java 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjCustomerController.java 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjOrderController.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-hosp/src/main/java/com/ltkj/hosp/domain/TjOrder.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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();
        // 将修改后的PDF内容写入
ltkj-admin/src/main/java/com/ltkj/web/controller/service/UtilsService.java
New file
@@ -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);
            }
        }
    }
}
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) {
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");
        }
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