zhaowenxuan
16 小时以前 6a4e3a5c4c34fdef0accc93d8a077ab016d15250
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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);
            }
        }
    }
}