赵文轩
2024-06-12 89e13d18f95a42ac75f46845165c7fbbc665d09a
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
package com.ltkj.web.controller.his;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.itextpdf.text.pdf.draw.LineSeparator;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.core.domain.entity.SysDictData;
import com.ltkj.common.utils.DateUtils;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import com.ltkj.system.service.ISysDictDataService;
import com.ltkj.system.service.ISysUserService;
import com.ltkj.web.config.pdfutils.PdfUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
 
@Slf4j
@RestController
@RequestMapping("/his/getData")
public class TestGetController {
    @Autowired
    private HisApiGetMethodService apiGetMethodService;
    @Autowired
    private ITjOrderService tjOrderService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private ITjReportTemplateService reportTemplateService;
    @Autowired
    private ITjCustomerService tjCustomerService;
    @Autowired
    private IDictCompService dictCompService;
    @Autowired
    private ITjProjectService tjProjectService;
    @Autowired
    private ITjOrderDetailService tjOrderDetailService;
    @Autowired
    private ITjReportService tjReportService;
    @Autowired
    private ITjBigPositiveService tjBigPositiveService;
    @Autowired
    private ITjProjectService projectService;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private ITjOrderRemarkService tjOrderRemarkService;
    @Autowired
    private ITjStandardService tjStandardService;
 
    @PostMapping("test")
    public AjaxResult test(@RequestBody String json){
        HashMap<String, Object> pdfInfoMap = new HashMap<>();
        JSONObject jsonObject = JSONUtil.parseObj(json);
        HashMap<String, Object> hashMap = new HashMap<>();
        // 2.4.2    -----   2.4.7
                // 由前面的接口生成 20240604000160
        hashMap.put("his_registration_id",jsonObject.getStr("his_registration_id"));
        hashMap.put("ksbm","0101");
        // 由前面的接口生成 20220427000227
        hashMap.put("pationid",jsonObject.getStr("pationid"));
        hashMap.put("ksrq",jsonObject.getStr("ksrq"));
        hashMap.put("jsrq",jsonObject.getStr("jsrq"));
        hashMap.put("pagecount",jsonObject.getInt("pagecount"));
        hashMap.put("page",jsonObject.getInt("page"));
        // 获取检验报告记录信息
        AjaxResult getlabreportinfo = apiGetMethodService.getHISDataNew("Getlabreportinfo", hashMap);
        log.info("getlabreportinfo ->{}",getlabreportinfo);
        if (getlabreportinfo.get("code").toString().equals("200")){
            makePDFInfo(pdfInfoMap,getlabreportinfo,"检验报告记录信息");
            List<Map<String ,Object>> data = (List<Map<String, Object>>) getlabreportinfo.get("data");
            Map<String, Object> resultMap = data.get(0);
            String jybgid = (String) resultMap.get("JYBGID");
            // 获取检验结果记录信息
            hashMap = new HashMap<>();
            hashMap.put("jybgid",jybgid);
            AjaxResult getlabdetailinfo = apiGetMethodService.getHISDataNew("Getlabdetailinfo", hashMap);
            makePDFInfo(pdfInfoMap,getlabdetailinfo,"检验结果记录");
            // 获取微生物报告记录信息
            AjaxResult getlabgermrepinfo = apiGetMethodService.getHISDataNew("Getlabgermrepinfo", hashMap);
            makePDFInfo(pdfInfoMap,getlabgermrepinfo,"微生物报告记录");
            // 获取微生物药敏信息
            AjaxResult getlabgermdetailinfo = apiGetMethodService.getHISDataNew("Getlabgermdetailinfo", hashMap);
            makePDFInfo(pdfInfoMap,getlabgermdetailinfo,"微生物药敏信息");
            // 获取危急值信息
            AjaxResult getlaburgentinfo = apiGetMethodService.getHISDataNew("Getlaburgentinfo", hashMap);
            makePDFInfo(pdfInfoMap,getlaburgentinfo,"危机值信息");
        }
        return AjaxResult.success();
    }
    // TODO 从2.3.1开始到2.4.7获取报告信息 然后生成pdf
    // his_registration_id 和 ksbm
 
    public List<Map<String ,Object>> makePDFInfo(HashMap<String ,Object> map,AjaxResult ajaxResult,String key){
        List<Map<String ,Object>> data = null;
        if (Integer.parseInt(ajaxResult.get("code").toString()) == 200) {
            data = (List<Map<String, Object>>) ajaxResult.get("data");
            List<Map<String, Object>> parent = (List<Map<String, Object>>) map.get(key);
            if (parent!=null){
                parent.addAll(data);
            }else {
                map.put(key,data);
            }
        }
        return data;
    }
 
 
    // hisID
    /*
    2024-06-01 08:00:00 2024-06-11 19:00:00
    * 2024013998
    * 2024014026
    * 2024014066
    * 2024014112
    * */
    @PostMapping("test_all")
    public AjaxResult testALL(@RequestBody String json){
        // pdf信息集合
        HashMap<String, Object> pdfInfoMap = new HashMap<>();
        JSONObject jsonObject = JSONUtil.parseObj(json);
        // 第一次请求 必填his_registration_id、ksbm科室编码、ksrq开始日期、jsrq结束日期
        // mzorzy业务类型:门诊、住院、体检、其他、cardtype卡类型, 1 电子健康卡 2 身份证 3诊疗卡 4患者ID 5就诊流水号 默认4 患者ID
//        String hisRegistrationId = jsonObject.getStr("his_registration_id");
//        String ksbm = jsonObject.getStr("ksbm");
        Map<String, Object> params = BeanUtil.beanToMap(jsonObject);
        String hisRegistrationId = params.get("his_registration_id").toString();
        String ksrq = params.get("ksrq").toString();
        String jsrq = params.get("jsrq").toString();
        String mzorzy = params.get("mzorzy").toString();
        String cardtype = params.get("cardtype").toString();
        String ksbm = params.get("ksbm").toString();
        String pationid = "";
        // 获取检查申请信息
//        AjaxResult getexamapplyinfo = apiGetMethodService.getHISDataNew("Getexamapplyinfo", params);
        List<Map<String ,Object>> list;
//        List<Map<String, Object>> list = makePDFInfo(pdfInfoMap, getexamapplyinfo, "获取检查申请信息");
//        if (list != null){
//            pationid = list.get(0).get("pationid").toString();
//            params.clear();
//            // 获取检查报告信息
//            params.put("pationid",pationid);
//            params.put("his_registration_id",hisRegistrationId);
//            params.put("page",1);
//            params.put("pagecount",10);
//            AjaxResult getexamreportinfo = apiGetMethodService.getHISDataNew("Getexamreportinfo", params);
//            makePDFInfo(pdfInfoMap,getexamreportinfo,"获取检查报告信息");
//        }else {
//            return AjaxResult.error("未获取到检查申请信息");
//        }
//        params.clear();
        // 获取检查危急值信息
//        params.put("his_registration_id",hisRegistrationId);
//        params.put("ksrq",ksrq);
//        params.put("jsrq",jsrq);
//        params.put("pagecount",10);
//        params.put("page",1);
//        AjaxResult getexamurgentinfo = apiGetMethodService.getHISDataNew("Getexamurgentinfo", params);
//        makePDFInfo(pdfInfoMap,getexamurgentinfo,"获取检查危急值信息");
        // 获取检验申请信息
//        params.clear();
//        params.put("mzorzy",mzorzy);
//        params.put("ksbm",ksbm);
//        params.put("cardtype",cardtype);
//        params.put("his_registration_id",hisRegistrationId);
//        AjaxResult getlabapplyinfo = apiGetMethodService.getHISDataNew("Getlabapplyinfo", params);
//        makePDFInfo(pdfInfoMap,getlabapplyinfo,"获取检验申请信息");
        // 获取检验报告记录信息
        params.clear();
        params.put("his_registration_id",hisRegistrationId);
        params.put("ksbm",ksbm);
        params.put("pationid",pationid);
        params.put("ksrq",ksrq);
        params.put("jsrq",jsrq);
        params.put("pagecount",10);
        params.put("page",1);
        AjaxResult getlabreportinfo = apiGetMethodService.getHISDataNew("Getlabreportinfo", params);
        list = makePDFInfo(pdfInfoMap,getlabreportinfo,"获取检验报告记录信息");
        JSONArray jsonArray = JSONUtil.createArray();
        if (list != null){
            params.clear();
            for (Map<String, Object> stringObjectMap : list) {
                JSONObject obj = JSONUtil.createObj();
                obj.putOpt("报告记录",stringObjectMap);
                String jybgid = stringObjectMap.get("JYBGID").toString();
                params.put("jybgid",jybgid);
                // 获取检验结果记录信息
                AjaxResult getlabdetailinfo = apiGetMethodService.getHISDataNew("Getlabdetailinfo", params);
                if (Integer.parseInt(getlabdetailinfo.get("code").toString()) == 200) {
                    List<Map<String, Object>> data = (List<Map<String, Object>>) getlabdetailinfo.get("data");
                    obj.putOpt("检验结果记录", data);
                }
                // 获取微生物报告记录信息
                AjaxResult getlabgermrepinfo = apiGetMethodService.getHISDataNew("Getlabgermrepinfo", params);
                if (Integer.parseInt(getlabgermrepinfo.get("code").toString()) == 200) {
                    List<Map<String, Object>> data = (List<Map<String, Object>>) getlabgermrepinfo.get("data");
                    obj.putOpt("微生物报告记录", data);
                }
                // 获取微生物药敏信息
                AjaxResult getlabgermdetailinfo = apiGetMethodService.getHISDataNew("Getlabgermdetailinfo", params);
                if (Integer.parseInt(getlabgermdetailinfo.get("code").toString()) == 200) {
                    List<Map<String, Object>> data = (List<Map<String, Object>>) getlabgermdetailinfo.get("data");
                    obj.putOpt("微生物药敏信息", data);
                }
                // 获取危急值信息
                AjaxResult getlaburgentinfo = apiGetMethodService.getHISDataNew("Getlaburgentinfo", params);
                if (Integer.parseInt(getlaburgentinfo.get("code").toString()) == 200) {
                    List<Map<String, Object>> data = (List<Map<String, Object>>) getlaburgentinfo.get("data");
                    obj.putOpt("危机值信息", data);
                }
                jsonArray.put(obj);
            }
//            System.out.println(JSONUtil.toJsonStr(pdfInfoMap));
            System.out.println(JSONUtil.toJsonStr(jsonArray));
            // 返回中文字段替换
            // {"获取检验报告记录信息":[{"床位号":"3","报告类别代码":"null","门诊住院标志":"1","申请日期时间":"2024-05-22T10:38:00","西医诊断代码":"","病房号":"","检验报告单号":"240522000899","报告单类别":"微生物检验报告单","报告医生代码":"02172","门诊急诊号":"0","申请医生姓名":"袁小海","检验报告 ID":"240522000899","患者姓名":"张海涛","档案保存机构名称":"泾川县人民医院","档案保存机构地址":"泾川县人民医院","医疗机构代码":"43899007-X","个人标识号":"20240522000046","电话号码":"15294040899","采样日期时间":"2024-05-22T11:09:16.51","修改标志":"0","打印日期":"2024-06-03T10:28:28.743","文件链接":"-","审核人员姓名":"王惠惠","申请日期":"2024-05-22T10:38:00","记录医生代码":"02172","检验项目名称":"普通细菌培养+药敏(痰)","审核人员代码":"02172","患者类型代码":"1","标本类型":"痰液","审核人员姓名":"王芳","标本状态":"已采样","标本代码":"null","检验项目代码":"600","报告科室代码":"0016","报告科室名称":"生化室","检验报告结果":"已审","检验备注":"-","报告日期":"2024-06-03T10:28:28.743","报告医生姓名":"王惠惠","申请机构名称":"泾川县人民医院","记录医生姓名":"王芳","申请机构代码":"43899007-X","送检时间":"2024-06-03T10:28:20.203","档案保存机构代码":"43899007-X","行数":"1","年龄":"82","申请科室名称":"内七科","标本编号":"2024060302","申请科室代码":"0072","患者科室名称":"内七科","检验样本编号":"yl2024052200000622","报告医生代码":"02188","申请医生代码":"00123"},{"床位号":"4","报告类别代码":"null","门诊住院标志":"1","申请日期时间":"2024-06-02T09:56:00","西医诊断代码":"","病房号":"","检验报告单号":"240602000236","报告单类别":"微生物检验报告单","报告医生代码":"03089","门诊急诊号":"0","申请医生姓名":"蔺芳芳","检验报告 ID":"240602000236","患者姓名":"张海涛","档案保存机构名称":"泾川县人民医院","档案保存机构地址":"泾川县人民医院","医疗机构代码":"43899007-X","个人标识号":"20240522000046","电话号码":"15294040899","采样日期时间":"2024-06-02T09:58:50","修改标志":"0","打印日期":"2024-06-03T08:34:15.843","文件链接":"-","审核人员姓名":"鲁红娟","申请日期":"2024-06-02T09:56:00","记录医生代码":"03089","检验项目名称":"普通细菌培养+药敏(痰)","审核人员代码":"03089","患者类型代码":"1","标本类型":"痰液","审核人员姓名":"王芳","标本状态":"未采样","标本代码":"null","检验项目代码":"600","报告科室代码":"0016","报告科室名称":"生化室","检验报告结果":"已审","检验备注":"-","报告日期":"2024-06-03T08:34:15.843","报告医生姓名":"鲁红娟","申请机构名称":"泾川县人民医院","记录医生姓名":"王芳","申请机构代码":"43899007-X","送检时间":"2024-06-03T08:34:14.26","档案保存机构代码":"43899007-X","行数":"2","年龄":"82","申请科室名称":"内七科","标本编号":"2024060301","申请科室代码":"0072","患者科室名称":"内七科","检验样本编号":"yl2024060200000185","报告医生代码":"02188","申请医生代码":"00337"}]}
            // TODO 生成PDF 展示信息 PDF每项信息不换新页 直接连续生成 后期pdf会有排序 比如先输出心电图再是血常规等等...
            // TODO 不再使用makePDFInfo方法
            // 用户信息
            // select o.*,c.* from tj_order o,tj_customer c where o.user_id = c.cus_id and o.card_id = 'hisID';
//            makePDF(hisRegistrationId);
            makePDF(hisRegistrationId,jsonArray);
            return AjaxResult.success();
        }else {
            return AjaxResult.error("未获取到检验报告记录信息");
        }
    }
 
    public AjaxResult makePDF(String cardId,JSONArray jsonArray){
        LambdaQueryWrapper<TjOrder> tjOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tjOrderLambdaQueryWrapper.eq(TjOrder::getCardId,cardId);
        TjOrder tjOrder = tjOrderService.getOne(tjOrderLambdaQueryWrapper);
        String tjNumber = tjOrder.getTjNumber();
        if (null != tjOrder){
            LambdaQueryWrapper<TjReportTemplate> tjReportTemplateLambdaQueryWrapper = new LambdaQueryWrapper<>();
            TjReportTemplate reportTemplate = null;
            if (tjOrder.getTjCategory() != null) {
                //查询字典
                LambdaQueryWrapper<SysDictData> wqq = new LambdaQueryWrapper<>();
                wqq.eq(SysDictData::getDictType, "dict_tjtype");
                wqq.eq(SysDictData::getDictValue, tjOrder.getTjCategory());
                SysDictData one = dictDataService.getOne(wqq);
                if (one != null) {
                    //查询字典
                    LambdaQueryWrapper<SysDictData> wqq1 = new LambdaQueryWrapper<>();
                    wqq1.eq(SysDictData::getDictType, "report_template_type");
                    wqq1.eq(SysDictData::getDictLabel, one.getDictLabel());
                    SysDictData one1 = dictDataService.getOne(wqq1);
                    if (one1 != null) {
                        tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getFlag, one1.getDictValue());
                    } else {
                        tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getFlag, 1);
                    }
                } else {
                    tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getFlag, 1);
                }
                tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getOpen, 0);
                reportTemplate = reportTemplateService.getOne(tjReportTemplateLambdaQueryWrapper);
            } else {
                tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getOpen, 0);
                reportTemplate = reportTemplateService.list(tjReportTemplateLambdaQueryWrapper).get(2);
            }
            String template = reportTemplate.getTemplate();
 
            // 生成模版
            byte[] decodedBytes = Base64.getDecoder().decode(template);
            try (FileOutputStream fos = new FileOutputStream("/Users/chacca/开发相关/代码/template.pdf")) {
                // 将字节数组写入文件
                fos.write(decodedBytes);
                System.out.println("PDF file saved successfully.");
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("Failed to save PDF file.");
            }
 
            LambdaQueryWrapper<TjCustomer> wq1 = new LambdaQueryWrapper<>();
            wq1.eq(TjCustomer::getCusId, tjOrder.getUserId());
            TjCustomer tjCustomer = tjCustomerService.getOne(wq1);
            Long userId = tjCustomer.getCusId();
            // 生成pdf
            try {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                PdfReader reader = new PdfReader(new ByteArrayInputStream(Base64.getDecoder().decode(template)));
                PdfStamper pdfStamper = new PdfStamper(reader, byteArrayOutputStream);
                // 获取pdf表单
                AcroFields acroFields = pdfStamper.getAcroFields();
                BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
                acroFields.addSubstitutionFont(bf);
                HashMap<String, Object> data = new HashMap<>();
                // 设置用户信息
                setUserInfo(tjNumber,tjOrder,tjCustomer,data);
                //异常项目
                // 遍历data 给pdf表单表格赋值
                for (String key : data.keySet()) {
                    acroFields.setField(key, data.get(key).toString());
                }
                //设置为无法编辑
                pdfStamper.setFormFlattening(true);
                pdfStamper.close();
                reader.close();
                // 将修改后的PDF内容写入
                byte[] bytes = byteArrayOutputStream.toByteArray();
                // 创建新的PDF文档
                Document document = new Document(PageSize.A4);
                ByteArrayOutputStream finalOutPut = new ByteArrayOutputStream();
                PdfCopy copy = new PdfCopy(document, finalOutPut);
                document.open();
                reader = new PdfReader(bytes);
                int numberOfPages = reader.getNumberOfPages();
                for (int i = 1; i <= numberOfPages; i++) {
                    PdfImportedPage page = copy.getImportedPage(reader, i);
                    copy.addPage(page);
                }
                // 添加详情页
                document.newPage();
                ByteArrayOutputStream byteArrayOutputStream1 = new ByteArrayOutputStream();
                Document document1 = new Document(PageSize.A4);
                PdfWriter pdfWriter = PdfWriter.getInstance(document1, byteArrayOutputStream1);
                document1.setMargins(70, 70, 40, 40);
                document1.open();
                for (Object o : jsonArray) {
                    JSONObject jsonObject = (JSONObject) o;
                    JSONObject reportInfo = jsonObject.getJSONObject("报告记录");
                    String titleName = reportInfo.getStr("JYXMMC").trim();
                    JSONArray reportDetails = jsonObject.getJSONArray("检验结果记录");
                    ArrayList<TjPdfVO> list = new ArrayList<>();
                    for (Object reportDetail : reportDetails) {
                        JSONObject detail = (JSONObject) reportDetail;
                        TjPdfVO tjPdfVO = new TjPdfVO();
                        tjPdfVO.setProName(detail.getStr("JCZBMC"));
                        tjPdfVO.setProResult(detail.getStr("JCZBJG"));
                        tjPdfVO.setCompany(detail.getStr("JLDW"));
                        tjPdfVO.setStandardValue(detail.getStr("CKZFW"));
                        list.add(tjPdfVO);
                    }
                    String[] titles = {"体检项目", "体检结果", "单位", "参考范围"};
                    float[] titlesWidth = {120, 120, 120, 120};
                    addTable(document1,titleName,titles,titlesWidth,list);
                    // 主检医师
                    String bgysqm = reportInfo.getStr("BGYSQM");
                    String doctorName = "主检医师:"+bgysqm;
                    Font doctorFonts = PdfUtils.setFont(9);
                    Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName);
                    df.setAlignment(Element.ALIGN_RIGHT);
                    document1.add(df);
                    //分割线
                    LineSeparator objectName = new LineSeparator();
                    document1.add(objectName);
                }
                document1.close();
                pdfWriter.close();
                reader = new PdfReader(byteArrayOutputStream1.toByteArray());
                int numberOfPages1 = reader.getNumberOfPages();
                for (int i = 1; i <= numberOfPages1 ; i++) {
                    PdfImportedPage page = copy.getImportedPage(reader, i);
                    copy.addPage(page);
                }
                byteArrayOutputStream1.close();
                document.close();
                copy.close();
                String outputPath1 = "/Users/chacca/开发相关/代码/";
                String outputFileName1 = userId + tjNumber + tjCustomer.getCusName() + "_报告.pdf";
                File file = new File(outputPath1 + outputFileName1);
                BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
                outputStream.write(finalOutPut.toByteArray());
                outputStream.flush();
                outputStream.close();
                finalOutPut.close();
                reader.close();
            } catch (IOException | DocumentException e) {
                throw new RuntimeException(e);
            }
            return AjaxResult.success();
        }else {
            return AjaxResult.error("未查询到体检信息");
        }
    }
 
    /**
     * 设置用户信息
     * @param tjNumber
     * @param tjOrder
     * @param tjCustomer
     * @param data
     */
    private void setUserInfo(String tjNumber, TjOrder tjOrder, TjCustomer tjCustomer, Map<String, Object> data) {
        //填充性别:判断男女
        Long cusSex = tjCustomer.getCusSex();
        String sex;
        String name1;
        String tjtype;
        if (cusSex == 0) {
            sex = "男";
            name1 = tjCustomer.getCusName() + "先生";
        } else {
            sex = "女";
            name1 = tjCustomer.getCusName() + "女士";
        }
        data.put("name", tjCustomer.getCusName());
        data.put("cusId", tjCustomer.getCusId());
        data.put("name1", name1);
        if ("1".equals(tjOrder.getTjType())) {
            tjtype = "团队";
            data.put("tjtype", tjtype);
        } else {
            tjtype = "个人";
            data.put("tjtype", tjtype);
        }
        data.put("dstype", "统一");
        data.put("sex", sex);
        data.put("age", DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
        data.put("tjnumber", tjNumber);
        data.put("tjdate", DateUtils.parseDateToStr("yyyy/MM/dd", tjOrder.getCreateTime()));
        data.put("phone", tjCustomer.getCusPhone());
        data.put("idcard", MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
        data.put("num2", 0);
        data.put("num3", 4);
    }
 
    private static void addTable(Document document,String titleName,String[] titles,float[] titlesWidth,ArrayList<TjPdfVO> list) throws DocumentException {
        Font titleFont = PdfUtils.setFont(9);
        Paragraph paragraph = new Paragraph(titleName, titleFont);
        // 设置文字居中
        paragraph.setAlignment(Element.ALIGN_LEFT);
        // 行间距
//        paragraph.setLeading(5f);
        // 设置段落上空白
        paragraph.setSpacingBefore(10f);
        // 设置段落下空白
        paragraph.setSpacingAfter(10f);
        document.add(paragraph);
        // 创建一个表格并添加到文档
        Font headFont = PdfUtils.setFont(9);
        Font textFont = PdfUtils.setFont(9);
        PdfPTable table = new PdfPTable(titlesWidth);
        table.setTotalWidth(PageSize.A4.getWidth() - 100); // 设置表格总宽度
        table.setLockedWidth(true); // 锁定表格宽度
        for (String title : titles) {
            PdfPCell cell = new PdfPCell(new Paragraph(title, headFont));
            cell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
            table.addCell(cell);
        }
        for (TjPdfVO item : list) {
            PdfPCell nameCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getProName()) && !item.getProName().equals("null")?item.getProName():"", textFont));
            nameCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
            table.addCell(nameCell);
 
            PdfPCell resultCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getProResult()) && !item.getProResult().equals("null") ?item.getProResult():"", textFont));
            resultCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
            table.addCell(resultCell);
 
            PdfPCell companyCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getCompany()) && !item.getCompany().equals("null") ?item.getCompany():"", textFont));
            companyCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
            table.addCell(companyCell);
 
            PdfPCell standardValueCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getStandardValue()) && !item.getStandardValue().equals("null") ?item.getStandardValue():"", textFont));
            standardValueCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框
            table.addCell(standardValueCell);
        }
        // 将表格添加到文档
        document.add(table);
    }
 
}