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); } } } }