Li Jun
2022-04-19 2f183a6b0a83ec3f7d35375d5d25d200efc2a3e1
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
public without sharing class FixtureRentalPDFController {
 
    private static Integer MAXLINEHRIGHT = 25;
    private static Integer MAXPAGECOUNT = 22; //32
 
    private String rentalApplyIdIMG;
    // private String rentalApplyId;//20201120 ljh 
 
    private List<String> rentalApplyId;
    // private List<String> raesidList;  確認
 
    public List<PDFInfo> records { get; set; }
    public Integer pageCnt { get; set; }
    public Integer pageNum { get; set; }
    public integer AllSum {get;set;}
    public String RentalApplyName  { get; set; }
    public String BorrowTimeString { get; set; }
    public Rental_Apply__c ApplyHeadShow { get; set; }
    public List<lineInfo> DetailsAllList { get; set;}
    public Map<String,String> AssetModelNoMap {get;set;}
    public List<PDFInfoIMG> recordsIMG { get; set; }
    public List<PDFInfoIMG> recordsIMGfist { get; set; }
    public Integer pageCntIMG { get; set; }
    public String headerLength {get;set;}
    public List<List<String>> PageCutList { get; set; }
    public String HospitalName { get; set;}//医疗机构
    public String Shippmentadress { get; set;}//发货地址
    public Integer mainCnt { get; private set;}//主体件数
    public Integer accessoryCnt { get; private set;}//附属品件数
    public String centreAddress { get; set; }
    public Boolean IsShowLU { get; set; } //是否显示签收单左上角文字 true显示 20201119 LJH OCSM_BP5-61 add
    public Boolean IsMain; //是否是现地分配的主单 20201120 LJH OCSM_BP5-61 add
    
    public string staticResource { get; private set; }
    public string staticResourceFile { get; private set; }
    public Boolean addFlag { get; private set; }//敏感地址使用标记
    public String qrcode { get; private set; }
    public String barcode { get; private set; }
    // 20220413 ljh 抬头显示 add start
    public String AgencyAddressName { get; private set; } 
    public Boolean isAgencyOrCenter { get; private set; } 
    public String AgencyOrCenterAddress { get; private set; }
    // 20220413 ljh 抬头显示 add end
 
    public FixtureRentalPDFController() {
        pageNum = Integer.valueOf(ApexPages.currentPage().getParameters().get('page'));
        rentalApplyIdIMG = ApexPages.currentPage().getParameters().get('raid');
        //Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
        // rentalApplyId = ApexPages.currentPage().getParameters().get('raid');//20201120 ljh 
        String tempStr = ApexPages.currentPage().getParameters().get('raid');
        
        addFlag = false;
        rentalApplyId = new List<String>();
        if(tempStr != null){
           rentalApplyId.add(tempStr); 
        }
        
        ApplyHeadShow = new Rental_Apply__c();
        IsShowLU = true;//20201119 LJH OCSM_BP5-61 add
        IsMain = false;//20201123 LJH OCSM_BP5-61 add
    }
 
    // 画面初始化
    public void init() {
        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Rental_Apply__c'));
        staticResourceFile = JSON.serialize(PIHelper.getPIIntegrationInfo('Document'));
        // 新规奥林巴斯备品签收单PDF画面初始化
        PageCutList = new List<List<String>>();
        List<Rental_Apply__c> ApplyList = new List<Rental_Apply__c>();
        Map<String,String>  AgencyAddressIdMap = new Map<String,String>(); //20201124 LJH OCSM_BP5-61 add 出借Id,地址Id
        if(rentalApplyId!=null){
            ApplyList = [select id,
                                name,
                                Name_No__c, // 20211209 ljh SFDC-C923SR add 
                                Shippment_loaner_time__c,
                                WorkPlace__c,
                                Salesdept__c,
                                Demo_purpose1__c,
                                Demo_purpose2__c,
                                Bollow_Date__c,
                                Campaign__r.EndDate,
                                Follow_UP_Opp__c,
                                Repair__r.Repair_Shipped_Date__c,
                                Return_dadeline_final__c,
                                Shipment_address__r.Post_Code__c,
                                Person_In_Charge__r.Name,Post_Code__c,
                                Shippment_adress_detail__c,
                                Person_In_Charge__r.Phone,
                                Phone_number__c,
                                Hospital__r.Name,Account__r.Department_name__c,
                                Account__r.Name,
                                Direct_shippment_address__c,
                                Dealer__r.Postal_Code__c,
                                ApplyUser__r.Name,
                                applyUser__r.Phone,
                                Loaner_medical_Staff__r.Name,
                                Loaner_medical_Staff__r.Phone,
                                Loaner_received_staff__c,
                                Loaner_received_staff_phone__c,
                                Asset_loaner_start_date__c,
                                Asset_loaner_start_day__c,
                                ApplyPerson_Phone__c,
                                Loaner_centre_mail_address__c,
                              // Main_Cnt__c,
                              // Accessory_Cnt__c,
                                Old_Rental_Apply__c,//20201120 LJH OCSM_BP5-61 add
                                Split_Apply_Reason__c,//20201120 LJH OCSM_BP5-61 add
                                RecordType.DeveloperName,//20201120 LJH OCSM_BP5-61 add
                                Request_shipping_day__c,//20201120 LJH OCSM_BP5-61 add
                                ToAgency__c,//20201123 LJH OCSM_BP5-61 add
                                Agency_Address_Id__c,//20201124 LJH OCSM_BP5-61 add
                                Root_Rental_Apply__c,//20210617 ljh 1732 add
                                BRId__c, // 20211209 ljh SFDC-C923SR add 
                                 direct_send__c,
                                QRImg__c,
                                QRId__c,
                                AWS_Data_Id__c,//20220304 
                                Direct_Shippment_Address_Encrypt__c,//20220304
                                Phone_Number_Encrypt__c//20220304
                        from  Rental_Apply__c
                        where id = :rentalApplyId];
        }
 
        if(ApplyList.size()>0){
            ApplyHeadShow = ApplyList[0];
            qrcode = ConsumTrialPDFController.GetImageBase64(ApplyHeadShow.QRId__c);
            barcode = ConsumTrialPDFController.GetImageBase64(ApplyHeadShow.BRId__c);
        }
        //增加借出备品SET一览List,为了获取借出备品SET一览明细
        List<String> RAESSearchList = New List<String>();
        //20201201 ljh  OCSM_BP5-76 add start
        String centerAddressInfo;
        bp3_Setting__c conf = bp3_Setting__c.getOrgDefaults();
        //20201201 ljh  OCSM_BP5-76 add end
        //根据备品中心邮箱判断备品中心
        if(ApplyHeadShow.Loaner_centre_mail_address__c=='OCM_Asset@olympus.com.cn'){
          centreAddress = '请将备品回寄至北京备品中心';
          centerAddressInfo = 'BeiJingCenter';
        }else if(ApplyHeadShow.Loaner_centre_mail_address__c=='OCM_AssetSH@olympus.com.cn'){
          centreAddress = '请将备品回寄至上海备品中心';
          centerAddressInfo = 'ShangHaiCenter';
        }else if(ApplyHeadShow.Loaner_centre_mail_address__c=='OCM_AssetGZ@olympus.com.cn'){
          centreAddress = '请将备品回寄至广州备品中心';
          centerAddressInfo = 'GuangZhouCenter';
        }
        //20201120 LJH OCSM_BP5-61 add start
        //现地管理分单 主单&从单
        //20210617 ljh 1732 update start
        if(ApplyHeadShow.RecordType.DeveloperName == 'AgencyRequest'){
            //记录类型办事处
            IsShowLU = false;
            String tempStr = ApplyHeadShow.Agency_Address_Id__c;
            if(String.isNotBlank(tempStr)){
                AgencyAddressIdMap.put(ApplyHeadShow.Id,tempStr.substring(0,15));
            }
            if(String.isBlank(ApplyHeadShow.Old_Rental_Apply__c)){
                List<Rental_Apply__c> ApplyCopyList = [select Id, Name from  Rental_Apply__c where Root_Rental_Apply__c = :ApplyHeadShow.id  and Split_Apply_Reason__c = '现地管理分单']; //20210611 ljh 1732 update Root_Rental_Apply__c
                if(ApplyCopyList.size()>0){
                    for(Rental_Apply__c ac:ApplyCopyList){
                        String tempId = ac.Id;
                        rentalApplyId.add(tempId);
                    }  
                }
 
            }else{
                List<Rental_Apply__c> ApplyCopyList = [select Id, Name from  Rental_Apply__c where ((Root_Rental_Apply__c = :ApplyHeadShow.Root_Rental_Apply__c and id != :ApplyHeadShow.id and Split_Apply_Reason__c = '现地管理分单')  OR id = :ApplyHeadShow.Root_Rental_Apply__c) ]; //20210611 ljh 1732 update Root_Rental_Apply__c
                if(ApplyCopyList.size()>0){
                    for(Rental_Apply__c ac:ApplyCopyList){
                        String tempId = ac.Id;
                        rentalApplyId.add(tempId); 
                    }   
                }
            }
        }else{
            if(String.isBlank(ApplyHeadShow.Old_Rental_Apply__c)){
                //是否 现地管理分单 主单
                List<Rental_Apply__c> ApplyCopyList = [select Id, Name from  Rental_Apply__c where Root_Rental_Apply__c = :ApplyList[0].id  and Split_Apply_Reason__c = '现地管理分单']; //20210611 ljh 1732 update Root_Rental_Apply__c
                if(ApplyCopyList.size()>0){
                    IsShowLU = false;
                    IsMain = true;
                    for(Rental_Apply__c ac:ApplyCopyList){
                        String tempId = ac.Id;
                        rentalApplyId.add(tempId);
                    }    
                }
            }
        }
        List<Shipment_address__c> ShipmentAddressList = [select Id,Name,Address__c from Shipment_address__c where Id in :AgencyAddressIdMap.values()];
        Map<String,String> ShipmentAddressMap = new Map<String,String>();
        for(Shipment_address__c sa : ShipmentAddressList){
            String tempStr = sa.Id;
            ShipmentAddressMap.put(tempStr.substring(0,15),sa.Address__c);
        }
        Set<String> keySet = AgencyAddressIdMap.keySet();
        for(String ks:keySet){
            AgencyAddressIdMap.put(ks,ShipmentAddressMap.get(AgencyAddressIdMap.get(ks)));
        }
        //20201120 LJH OCSM_BP5-61 add end
        //医疗机构名分行显示
        if(ApplyHeadShow.Hospital__r.Name != null){
            String HospOrgan = ApplyHeadShow.Hospital__r.Name;
            Integer HospSize = HospOrgan == null ? 0 : HospOrgan.length();
            if(HospSize <=19){
                HospitalName = HospOrgan;
            }else{
                HospitalName = HospOrgan.substring(0,19)+'\n'+HospOrgan.substring(19,HospSize);
            }
        }
 
        //发货地址分行显示
        String ShippMentAdr = null;
        if (ApplyHeadShow.Shippment_adress_detail__c != null) {
            ShippMentAdr = ApplyHeadShow.Shippment_adress_detail__c;
        } else {
            ShippMentAdr = ApplyHeadShow.Direct_shippment_address__c;
            addFlag = true;
        }
 
        Integer ShipAdrSize = ShippMentAdr == null ? 0 : ShippMentAdr.length();
        if (ShipAdrSize <= 26) {
            Shippmentadress = ShippMentAdr;
        } else if (ShipAdrSize > 26 && ShipAdrSize <= 52) {
            Shippmentadress = ShippMentAdr.substring(0,26)+ '\n' +ShippMentAdr.substring(26,ShipAdrSize);
        } else {
            Shippmentadress = ShippMentAdr.substring(0,26)+'\n'+ShippMentAdr.substring(26,52) + '\n'+ShippMentAdr.substring(52,ShipAdrSize);
        }
 
        // 增加医院借用期限,输出字段格式化
        if (ApplyHeadShow.Asset_loaner_start_date__c != null) {
            if (ApplyHeadShow.Demo_purpose2__c      == '产品试用'
                ||  ApplyHeadShow.Demo_purpose2__c  ==  '新产品评价'
                ||  ApplyHeadShow.Demo_purpose2__c  ==  FixtureUtil.raDemo_purpose2MAP.get('shiyongwuxunjia')
                ||  ApplyHeadShow.Demo_purpose2__c  ==  FixtureUtil.raDemo_purpose2MAP.get('shiyongyouxunjia')
                ||  ApplyHeadShow.Demo_purpose2__c  ==  '其他'
                ||  ApplyHeadShow.Demo_purpose2__c  ==  '协议借用') {
                BorrowTimeString = String.valueOf(ApplyHeadShow.Asset_loaner_start_date__c) + ' ~ '
                                 + String.valueOf(ApplyHeadShow.Return_dadeline_final__c)
                                 + '前到达奥林巴斯备品中心';
            } else if (ApplyHeadShow.Demo_purpose2__c == '学会展会') {
                if (ApplyHeadShow.Campaign__r.EndDate != null){
                    BorrowTimeString = String.valueOf(ApplyHeadShow.Asset_loaner_start_date__c) + ' ~ '
                                     + String.valueOf(ApplyHeadShow.Campaign__r.EndDate.addDays(5))
                                     + '前到达奥林巴斯备品中心';
                                     // 2018年7月31日 SWAG-B36CY6 by 张玉山 start
                    } else if (ApplyHeadShow.Campaign__r.EndDate == null) {
                       // 2018年7月31日 SWAG-B36CY6 by 张玉山 end
                        BorrowTimeString = '学会结束日为空,无法确定医院借用期限';
                    }else{
                        BorrowTimeString = 'ApexClass104:无法获取数据,请联系开发组';
                    }
 
            } else if (ApplyHeadShow.Demo_purpose2__c == '已购待货') {
                BorrowTimeString = String.valueOf(ApplyHeadShow.Asset_loaner_start_date__c) + ' ~ '
                                 + '新品发货日起14天内'
                                 + '到达奥林巴斯备品中心';
            } else if (ApplyHeadShow.Demo_purpose2__c == '故障排查') {
                BorrowTimeString = '判定有故障时,' + String.valueOf(ApplyHeadShow.Asset_loaner_start_date__c)
                                 + '~修理品返送日起14天内到达奥林巴斯备品中心\n'
                                 + '判定无故障时,' + String.valueOf(ApplyHeadShow.Asset_loaner_start_date__c)
                                 + '~出库日起10个工作日内到达奥林巴斯备品中心';
            } else if (ApplyHeadShow.Demo_purpose1__c == '维修代用') {
                BorrowTimeString = String.valueOf(ApplyHeadShow.Asset_loaner_start_date__c) + ' ~ '
                                 + '修理品返送日起14天内'
                                 + '到达奥林巴斯备品中心';
            } else {
                BorrowTimeString = '未设定归还期限';
            }
 
        } else {
            BorrowTimeString = '备品预计出货日为空,无法确定医院借用期限';
        }
 
        system.debug(' ApplyHeadShow.Demo_purpose1__c'+ ApplyHeadShow.Demo_purpose1__c);
 
        // 增加医院借用期限,输出字段格式化
        // system.debug('测试位置1+raesidList'+raesidList);
        records = new List<PDFInfo>();
        List<Rental_Apply_Equipment_Set__c> raesList = new List<Rental_Apply_Equipment_Set__c>();
        // List<String> esidList = new List<String>();
        //ToDo Where 確認
        String soql =  'select Id, Name, Rental_Apply__c, Fixture_Set__r.Name'
               + ', Rental_Apply__r.Name, Request_owner__c, Rental_Apply__r.Salesdept__c'
               + ', Rental_Apply__r.WorkPlace__c, Account__c, Rental_Apply__r.Campaign__r.Name'
               + ', Rental_Apply__r.Request_shipping_day__c, Rental_Apply__r.Loaner_received_staff__c'
               + ', Rental_Apply__r.Loaner_received_staff_phone__c, Rental_Apply__r.Shippment_adress_detail__c'
               + ', Rental_End_Date__c, Rental_Apply__r.direct_shippment_address__c'
               + ' from Rental_Apply_Equipment_Set__c'
               + ' where Rental_Apply__c = :rentalApplyId'
               + ' AND Cancel_Select__c = false'
               + ' AND Yi_Shipment_request__c > 0';
 
        //ToDo条件確認
        //soql += 'and RAES_Status__c != \'引当済\' and RAES_Status__c != \'取消分配\'';
 
        //今回個別の表示はしないのでコメントアウトします
        // if (raesidListIMG.size() > 0) {
        //     soql += ' AND Id in : raesidListIMG ';
        // }
 
        // if(ApplyHeadShow.Shippment_loaner_time__c != null) {
        //     soql += ' AND Shippment_loaner_time__c != null';
        // }
 
        soql += ' order by Name';
        raesList = Database.query(soql);
        //20201120 LJH OCSM_BP5-61 add start
        //申请单-申请一览List
        Map<Id,List<Rental_Apply_Equipment_Set__c>> raRaesMap = new  Map<Id,List<Rental_Apply_Equipment_Set__c>>();
        //20201120 LJH OCSM_BP5-61 add end
        if (raesList.size() > 0) {
            for (Rental_Apply_Equipment_Set__c raes : raesList) {
                //ToDo RentalApplyName取り方が変
                //RentalApplyName = raes.Rental_Apply__r.Name;
                //循环获得RAES_id
                RAESSearchList.add(raes.id);
                //20201120 LJH OCSM_BP5-61 add start
                if(!raRaesMap.containsKey(raes.Rental_Apply__c)){
                    raRaesMap.put(raes.Rental_Apply__c,new Rental_Apply_Equipment_Set__c[]{raes});
                }else{
                    raRaesMap.get(raes.Rental_Apply__c).add(raes);
                }
                //20201120 LJH OCSM_BP5-61 add end
            }
            RentalApplyName = raesList[0].Rental_Apply__r.Name;
        }
 
        Map<String, List<Rental_Apply_Equipment_Set_Detail__c>> raesdMap = new Map<String, List<Rental_Apply_Equipment_Set_Detail__c>>();
 
        String NextName = '';
        if(RAESSearchList.size()>0){
            List<Rental_Apply_Equipment_Set_Detail__c> RAESDLine = New List<Rental_Apply_Equipment_Set_Detail__c>();
            RAESDLine = [
                    select id, Equipment_SetD_Borrowed__c,
                        EquipmentSet_Managment_Code_formula__c,
                        Rental_Apply_Equipment_Set__c,
                        Rental_Apply_Equipment_Set__r.Name,
                        Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name,
                        Rental_Apply_Equipment_Set__r.Loaner_code__c,
                        FSD_Name_CHN__c,
                        Fixture_Name_text__c,
                        Fixture_Model_No_F__c,
                        Fixture_Model_No_text__c,
                        Loaner_asset_no__c,
                        Internal_Asset_number_c__c,
                        ProductName__c,
                        Asset__r.Product2.Image_DocumentID__c,
                        Asset__r.OwnershipMachine_No__c,
                        Asset__r.Name,
                        Asset__r.Loaner_accsessary__c,
                        Asset__r.WH_location__c,
                        SerialNumber__c,
                        SerialNumber_text__c,
                        Is_Body__c,
                        // Rental_Apply_Equipment_Set__r.SerialNumber_text__c,
                        Rental_Apply_Equipment_Set__r.Loaner_code_text__c
                    from Rental_Apply_Equipment_Set_Detail__c
                    where Rental_Apply_Equipment_Set__r.Id in :RAESSearchList
                and Cancel_Select__c = False
                AND asset__c != null
                AND Cancel_Select__c = false
                AND Shipment_request_time2__c != null
                    order by Rental_Apply_Equipment_Set__c, Name, ProductName__c asc nulls last, Asset__r.Loaner_accsessary__c];
            mainCnt = 0;
            accessoryCnt = 0;
            for (Rental_Apply_Equipment_Set_Detail__c ra : RAESDLine) {
                if (ra.Is_Body__c) {
                    mainCnt += 1;
                } else {
                    accessoryCnt += 1;
                }
                if (raesdMap.containsKey(ra.Rental_Apply_Equipment_Set__c)) {
                    raesdMap.get(ra.Rental_Apply_Equipment_Set__c).add(ra);
                } else {
                    List<Rental_Apply_Equipment_Set_Detail__c> rsd = new List<Rental_Apply_Equipment_Set_Detail__c>();
                    rsd.add(ra);
                    raesdMap.put(ra.Rental_Apply_Equipment_Set__c,rsd);
                }
            }
            //20201125 LJH OCSM_BP5-61 add start
            raesList = null;
            raesList = raRaesMap.get(rentalApplyId[0]);
            //20201125 LJH OCSM_BP5-61 add end
        }
        DetailsAllList = new List<lineInfo>();
        recordsIMG = new List<PDFInfoIMG>();
        //计算行高总数,用于分页
        integer LineNum = 0;
 
        System.debug('raesListsize is' + raesList.size());
 
        for (Integer i = 0; i < raesList.size(); i++) {
            Rental_Apply_Equipment_Set__c raes = raesList[i];
            Map<String,integer> DLSM = new Map<String,integer>();
            Map<String,String> LoanerCodeSM = new Map<String,String>();
            Map<String,String> DetailsLineMap = new Map<String,String>();
            Set<String> AllSet = new Set<String>();
            String DetailsLine = '';
            List<Rental_Apply_Equipment_Set_Detail__c> LineOrderList = raesdMap.get(raes.Id);
            // system.debug('LineOrderList测试'+LineOrderList.size());
 
            if (LineOrderList!=null) {
                boolean LotFlag = true;
                for (Rental_Apply_Equipment_Set_Detail__c Ec : LineOrderList) {
                    // LoanerCodeSM.put(Ec.Equipment_Set__r.Loaner_code__c, Ec.Equipment_Set__r.Loaner_code__c);
                    system.debug('LoanerCodeSM显示'+LoanerCodeSM);
                    //先数出来有多少重复的
                    //DetailsLine = DetailsLine + Ec.Asset__r.OwnershipMachine_No__c+' ; ';
                    if (DLSM.containsKey(Ec.Asset__r.OwnershipMachine_No__c)) {
                       //OCM内部产品型号 OwnershipMachine_No__c
                       integer j = DLSM.get(Ec.Asset__r.OwnershipMachine_No__c)+1;
                       DLSM.put(Ec.Asset__r.OwnershipMachine_No__c, j);
                    } else {
                       DLSM.put(Ec.Asset__r.OwnershipMachine_No__c, 1);
                    }
 
                    if (Ec.Asset__r.Loaner_accsessary__c == false) {
                       //有主机
                       LotFlag = false;
                    }
 
                    //去掉重复的 ToDo条件确认
                    // if (Ec.Asset__r.Loaner_accsessary__c == true) {
                        //if(Ec.SerialNumber__c == ''||Ec.SerialNumber__c==null){
                       AllSet.add(Ec.Asset__r.OwnershipMachine_No__c);
                    // }
                }
 
                system.debug('DLSM:::::'+DLSM);
                system.debug('AllSet:::::'+AllSet);
                for (String Ecc : AllSet) {
                    //然后做成字符串
                    if (LotFlag) {
                        //都为附属品
                        if(DLSM.get(Ecc)==1) {
                            DetailsLine = DetailsLine + Ecc + ' ; ';
                        } else {
                            DetailsLine = DetailsLine + Ecc + '*' + DLSM.get(Ecc) + ' ; ';
                        }
                    } else {
                        if (DLSM.get(Ecc)==1&&!LoanerCodeSM.containsKey(Ecc)) {
                            DetailsLine = DetailsLine + Ecc+' ; ';
                        } else if (DLSM.get(Ecc)!=1) {
                            DetailsLine = DetailsLine + Ecc+'*'+DLSM.get(Ecc)+' ; ';
                        }
                    }
                }
 
                if (DetailsLine.length()>0) {
                    DetailsLine = DetailsLine.substring(0, DetailsLine.length()-2);
                }
 
                // List<Rental_Apply_Equipment_Set_Detail__c> LinJar = raesdMap.get(raes.Equipment_Set__c);
                // Rental_Apply_Equipment_Set_Detail__c LineOrder = new Rental_Apply_Equipment_Set_Detail__c();
                // if (LinJar.size()>0) {
                Integer k = i;
                for (Rental_Apply_Equipment_Set_Detail__c LineOrder : LineOrderList) {
                        // LineOrder = raesdMap.get(raes.Equipment_Set__c)[0];
                        // system.debug('LineOrder::::::'+LineOrder);
                        lineInfo Li = new lineInfo(LineOrder, LotFlag, k);
                        Li.AssetModelNo = DetailsLine;
                        //载入行高 每行44
                        if (DetailsLine.length() != 0) {
                            Li.LineHeight = (DetailsLine.length()/44) + (Math.mod(DetailsLine.length(), 44) > 0 ? 1 : 0);
                        } else {
                            Li.LineHeight = 1;
                        }
 
                        Li.height = Li.LineHeight * MAXLINEHRIGHT;
 
                        LineNum = LineNum + Li.LineHeight;
                        DetailsAllList.add(Li);
                        k = null;
                }
 
                // }
                // for (Rental_Apply_Equipment_Set_Detail__c raesd : LineOrderList) {
                    PDFInfoIMG infoIMG = new PDFInfoIMG(raes, LineOrderList);
                    recordsIMG.add(infoIMG);
                // }
            }
        }
 
  //      //分页 15行一页,实际显示14行,判断第14行是否为双倍高度
  //      //明细总页数
        integer PageAllNum = integer.valueOf(Math.ceil( LineNum / (MAXPAGECOUNT+1))+1+'');
 
        pageCnt = integer.valueOf(Math.ceil( DetailsAllList.size() / 17 ) +1+'');
        //for(Integer j = 0 ; j< PageAllNum ;j++){
        //新建一页
        
        PDFInfo info = new PDFInfo(new Rental_Apply__c(),New List<Rental_Apply_Equipment_Set_Detail__c>());
        // 20220413 ljh  抬头显示 update start
        //20201120 LJH OCSM_BP5-61 update start
        // if(!IsShowLU){
        //     if(!IsMain){
        //         info.isAgencyOrCenter = true;//办事处
        //         info.AgencyAddressName = '请将备品回寄至';
        //         info.AgencyAddressName += ApplyHeadShow.ToAgency__c == null ? '' : ApplyHeadShow.ToAgency__c;
        //         info.AgencyAddressName += '办事处';
        //         info.AgencyOrCenterAddress = AgencyAddressIdMap.get(ApplyHeadShow.Id);
        //     }else{
        //         info.isAgencyOrCenter = false;//备品中心
        //         info.AgencyOrCenterAddress = centerAddressInfo;
        //     }   
        // }else{
        //     info.isAgencyOrCenter = false;//备品中心
        //     info.AgencyOrCenterAddress = centerAddressInfo;
        // }
        //20201120 LJH OCSM_BP5-61 update  end
        if(!IsShowLU){
            if(!IsMain){
                isAgencyOrCenter = true;//办事处
                AgencyAddressName = '请将备品回寄至';
                AgencyAddressName += ApplyHeadShow.ToAgency__c == null ? '' : ApplyHeadShow.ToAgency__c;
                AgencyAddressName += '办事处';
                AgencyOrCenterAddress = AgencyAddressIdMap.get(ApplyHeadShow.Id);
            }else{
                isAgencyOrCenter = false;//备品中心
                AgencyOrCenterAddress = centerAddressInfo;
            }   
        }else{
            isAgencyOrCenter = false;//备品中心
            AgencyOrCenterAddress = centerAddressInfo;
        }
        // 20220413 ljh  抬头显示 update end
        integer PageCut = 0;
        if (PageAllNum>=7) {
           PageAllNum=7;
        }
 
        Integer count = DetailsAllList.size() / MAXPAGECOUNT;
        if (Math.mod(DetailsAllList.size(), MAXPAGECOUNT) > 0) {
        count += 1;
        }
 
 
        for (Integer K = 0; K < count*MAXPAGECOUNT ; K++) {
            if (DetailsAllList.size()>k) {
               info.lineList.add(DetailsAllList[K]);
               PageCut = PageCut +DetailsAllList[K].LineHeight-1;
 
            } else {
               info.lineList.add(new lineInfo(new Rental_Apply_Equipment_Set_Detail__c(), false, null));
            }
            System.debug('info.lineList is' + info.lineList);
            if (records.size() < PageAllNum) {
               PageCut = PageCut+1;
            }
            system.debug('PageCut[K]' + PageCut);
 
            if (info.lineList.size() >= MAXPAGECOUNT) {
               records.add(info);
               system.debug('records内容::::::::'+records);
               info = new PDFInfo(new Rental_Apply__c(),New List<Rental_Apply_Equipment_Set_Detail__c>());
               List<String> G = new List<String>();
               G.add('ANY element');
               PageCutList.add(G);
               PageCut=0;
            }
        }
 
       // for (Integer K = 0; K < PageAllNum*MAXPAGECOUNT ; K++) {
       //     if (DetailsAllList.size()>k) {
       //         info.lineList.add(DetailsAllList[K]);
       //         PageCut = PageCut +DetailsAllList[K].LineHeight-1;
 
       //     } else {
       //         info.lineList.add(new lineInfo(new Rental_Apply_Equipment_Set_Detail__c(), false, null));
       //     }
       //     System.debug('info.lineList is' + info.lineList);
       //     if (records.size() < PageAllNum) {
       //         PageCut = PageCut+1;
       //     }
       //     system.debug('PageCut[K]' + PageCut);
 
       //     if (PageCut >= MAXPAGECOUNT) {
       //         records.add(info);
       //         system.debug('records内容::::::::'+records);
       //         info = new PDFInfo(new Rental_Apply__c(),New List<Rental_Apply_Equipment_Set_Detail__c>());
       //         List<String> G = new List<String>();
       //         G.add('ANY element');
       //         PageCutList.add(G);
       //         PageCut=0;
       //     }
       // }
 
  //      system.debug('records内容'+records);
        pageCnt = records.size();
        AllSum = DetailsAllList.size();
  
  //      //pageNum
        recordsIMGfist = new List<PDFInfoIMG>();
 
        for (integer J = pageNum * 10; J<pageNum * 10 +10; J++) {
            if (J < recordsIMG.size()) {
               recordsIMGfist.add(recordsIMG.get(J));
            }
        }
 
        pageCntIMG = recordsIMGfist.size();
    }
    // Data Bean
    class PDFInfo {
        public String eSetName { get; private set; } //备品中心管理单号
        // 20220413 ljh  抬头显示 update start
        // public String AgencyAddressName { get; private set; } //回寄地址 20201123 LJH OCSM_BP5-61 add
        // public Boolean isAgencyOrCenter { get; private set; } //备品中心?办事处 20201123 LJH OCSM_BP5-61 add
        // public String AgencyOrCenterAddress { get; private set; }//20201124 LJH OCSM_BP5-61 add
        // 20220413 ljh  抬头显示 update end
        public String requestOwner { get; private set; } //申请人
        public String salesDept { get; private set; } //所属本部
        public String workPlace { get; private set; } //所属办事处
        public String acc { get; private set; } //借用单位
        public String shippingDay { get; private set; } //希望到货日
        public String receivedStaff { get; private set; } //收件人
        public String receivedStaffPhone { get; private set; } //收件人电话
        public String shippmentAdress { get; private set; } //发送地址
        public String HospitalEndDate { get; private set; } //在医院使用期限
        public String LoanerCode {get;private set;} //備品型番
        public List<lineInfo> lineList { get; private set; }
        public String AssetModelNo {get;private set;} //OCM内部产品型号(略称)
        public PDFInfo(Rental_Apply__c raes, List<Rental_Apply_Equipment_Set_Detail__c> raesdList) {
            eSetName = raes.Name;
            requestOwner = raes.Person_In_Charge__c;
            salesDept = raes.Salesdept__c;
            workPlace = raes.WorkPlace__c;
            acc = raes.Account__c == null && raes.Campaign__c != null ? raes.Campaign__c : raes.Account__c;
            shippingDay = raes.Request_shipping_day__c == null ? '' : raes.Request_shipping_day__c.format();
            receivedStaff = raes.Loaner_received_staff__c;
            receivedStaffPhone = raes.Loaner_received_staff_phone__c;
            shippmentAdress = raes.Shippment_adress_detail__c == null ? raes.direct_shippment_address__c : raes.Shippment_adress_detail__c;
            if (raesdList == null) {
                raesdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
            }
            lineList = new List<lineInfo>();
        }
    }
 
    class lineInfo {
        //bp2
        public String index { get; private set; }  //  序号
        public String setName { get; private set; }  //  备品set型号
        public String dModelNo { get; private set; }  //  备品配套明细型号
        public String dChinaName { get; private set; }  //  中文名称
        public String dSerialNumber { get; private set; }  //  机身号
        public String dLoaner_asset_no { get; private set; }  //  固定资产号码
        public String dManagementnumber { get; private set; }  //  管理号码
        public String dQRCode { get; private set; }  //  二维码
        private Integer maxLineContact;
        public String wh_location { get; private set; }  //  货位号
 
 
        public String name1 { get; private set; }
        public String productName1 { get; private set; }
        public String serialNumber1 { get; private set; }
        public String name2 { get; private set; }
        public String productName2 { get; private set; }
        public String serialNumber2 { get; private set; }
        public String LoanerCode {get;private set;} //備品型番
        public String AssetModelNo {get;private set;} //OCM内部产品型号(略称)
        public List<String> AssetModelNoList {get;private set;}//OCM内部产品型号(略称) 集合
        public integer LineHeight {get;private set;} //记录行高
        public integer height {get;private set;}
        // public lineInfo(Equipment_Set_Detail__c esd1, Equipment_Set_Detail__c esd2) {
        //    AssetModelNoList = new List<String>();
        //    name1 = esd1.Equipment_Set__r.Name == null ? ' ' : esd1.Equipment_Set__r.Name;
        //    productName1 = esd1.Asset__r.Name;
        //    serialNumber1 = esd1.SerialNumber__c;
        //    name2 = esd2.Name == null ? ' ' : esd2.Name;
        //    productName2 = esd2.Asset__r.Name;
        //    serialNumber2 = esd2.SerialNumber__c;
        //    height = height ==null ? 25: height;
        //    LoanerCode = esd1.Equipment_Set__r.Loaner_code__c;
        // }
// MAXINDEXCOUNT = 26;
// MAXDCHINNAMECOUNT = 2
// MAXDMODELNOCOUNT = 26
// MAXDSERIALNUMBERCOUNT
// MAXDLANCOUNT = 26;
// MAXDMMCOUNT = 26;
        public lineInfo(Rental_Apply_Equipment_Set_Detail__c raesd, boolean LotFlag, Integer inde) {
           AssetModelNoList = new List<String>();
            //bp2
            maxLineContact = 0;
            index = inde == null ? '' : String.valueOf(inde + 1);
            dChinaName = raesd.Fixture_Name_text__c;
            // dChinaName = '457100: 孔口探头,COTTLE型,带工业金刚石,20.5 cm(工业金刚石研磨表面取代了传统的钢纹,这使得操作省力,更简易,同时获得了更高的精确度。它能以极高的精准度切割或研磨较大骨组织)。';
            // dChinaName = '孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口探头孔口';
            dModelNo = raesd.Fixture_Model_No_text__c;
            dSerialNumber = raesd.SerialNumber_text__c;
            // dLoaner_asset_no = raesd.Loaner_asset_no__c;
            // OLY_OCM-321 发货确认单:固定资产号字段修改显示为固定资产编号(Key) _c__c?
            dLoaner_asset_no = raesd.Internal_Asset_number_c__c;
            dManagementnumber = raesd.EquipmentSet_Managment_Code_formula__c == null ? ' ' : raesd.EquipmentSet_Managment_Code_formula__c;
 
 
 
 
           name1 = raesd.Equipment_SetD_Borrowed__c == null ? ' ' : raesd.Equipment_SetD_Borrowed__c;
           productName1 = raesd.Asset__r.Name;
           setName = raesd.Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name;
           if(LotFlag){
               serialNumber1 = ' ';
               LoanerCode = ' ';
           }else{
               // serialNumber1 = raesd.Rental_Apply_Equipment_Set__r.SerialNumber_text__c;
               LoanerCode = raesd.Rental_Apply_Equipment_Set__r.Loaner_code_text__c;
           }
           //name2 = esd2.Name == null ? ' ' : esd2.Name;
           //productName2 = esd2.Asset__r.Name;
           //serialNumber2 = esd2.SerialNumber__c;
           height = height ==null ? MAXLINEHRIGHT: height;
           wh_location = raesd.Asset__r.WH_location__c;
        }
    }
    // Data Bean
    class PDFInfoIMG {
        public String eSetName { get; private set; }
        // public Equipment_Set__c es { get; private set; }
        public Fixture_Set__c es { get; private set; }
 
        public Rental_Apply_Equipment_Set__c raesc { get; private set; }
        public List<lineInfoIMG> lineList { get; private set; }
        public List<lineInfoIMGrase> lineListIMG { get; private set; }
 
        //public PDFInfoIMG(Rental_Apply_Equipment_Set__c raes, List<Equipment_Set_Detail__c> esdl) {
        //    eSetName = raes.Equipment_Set__r.Name;
        //    es = raes.Equipment_Set__r;
        //    raesc = raes;
        //    if (esdl == null) {
        //        esdl = new List<Equipment_Set_Detail__c>();
        //    }
        //    lineList = new List<lineInfoIMG>();
        //    if (esdl.Size() >= 20) {
        //        for (Integer i = 0; i < 5; i++) {
        //            lineList.add(new lineInfoIMG(esdl[i*4],esdl[i*4+1],esdl[i*4+2],esdl[i*4+3]));
        //        }
        //    } else {
        //        Integer size = esdl.Size();
        //        for (Integer i = 0; i < 20 - size; i++) {
        //            esdl.add(new Equipment_Set_Detail__c(Name=' '));
        //        }
        //        for (Integer i = 0; i < 5; i++) {
        //            lineList.add(new lineInfoIMG(esdl[i*4],esdl[i*4+1],esdl[i*4+2],esdl[i*4+3]));
        //        }
        //    }
        // }
        public PDFInfoIMG(Rental_Apply_Equipment_Set__c raes, List<Rental_Apply_Equipment_Set_Detail__c> raesdcl) {
           eSetName = raes.Fixture_Set__r.Name;
           es = raes.Fixture_Set__r;
           if (raesdcl == null) {
               raesdcl = new List<Rental_Apply_Equipment_Set_Detail__c>();
           }
           lineListIMG = new List<lineInfoIMGrase>();
           if (raesdcl.Size() >= 20) {
               for (Integer i = 0; i < 5; i++) {
                   lineListIMG.add(new lineInfoIMGrase(raesdcl[i*4],raesdcl[i*4+1],raesdcl[i*4+2],raesdcl[i*4+3]));
               }
           } else {
               Integer size = raesdcl.Size();
               for (Integer i = 0; i < 20 - size; i++) {
                   raesdcl.add(new Rental_Apply_Equipment_Set_Detail__c());
               }
               for (Integer i = 0; i < 5; i++) {
                   lineListIMG.add(new lineInfoIMGrase(raesdcl[i*4],raesdcl[i*4+1],raesdcl[i*4+2],raesdcl[i*4+3]));
               }
           }
        }
    }
 
    class lineInfoIMG {
        //public List<esdInfo> esdl { get; private set; }
 
        //public lineInfoIMG(Equipment_Set_Detail__c e1, Equipment_Set_Detail__c e2, Equipment_Set_Detail__c e3, Equipment_Set_Detail__c e4) {
        //    esdl = new List<esdInfo>();
        //    esdl.add(new esdInfo(e1));
        //    esdl.add(new esdInfo(e2));
        //    esdl.add(new esdInfo(e3));
        //    esdl.add(new esdInfo(e4));
        //    //esdl.add(e5);
        //}
    }
    class lineInfoIMGrase {
        public List<esdInfo> esdl { get; private set; }
 
        public lineInfoIMGrase(Rental_Apply_Equipment_Set_Detail__c e1, Rental_Apply_Equipment_Set_Detail__c e2, Rental_Apply_Equipment_Set_Detail__c e3, Rental_Apply_Equipment_Set_Detail__c e4) {
           esdl = new List<esdInfo>();
           esdl.add(new esdInfo(e1));
           esdl.add(new esdInfo(e2));
           esdl.add(new esdInfo(e3));
           esdl.add(new esdInfo(e4));
           //esdl.add(e5);
        }
    }
 
    class esdInfo {
        // public Rental_Apply_Equipment_Set_Detail__c esd { get; private set; }
        public Rental_Apply_Equipment_Set_Detail__c raesl { get; private set; }
        public Integer nameLength { get; private set; }
        public String ProductName { get; private set; }
 
 
        public esdInfo(Rental_Apply_Equipment_Set_Detail__c e) {
            raesl = e;
            String name = e.ProductName__c;
            nameLength = name == null ? 0 : name.length();
 
            if(nameLength <= 21){
               //一行
               ProductName = name;
            }else if(nameLength > 21 && nameLength <= 74){
               //两行
               if(nameLength <= 42){
                   //7px
                   //for(Integer i = 0; i < 2 ; i++){
                       ProductName = name.substring(0,21)+'<br/>'+name.substring(21,nameLength);
                   //}
               }else{
                   //4px
                   //for(Integer i = 0; i < 2 ; i++){
                       ProductName = name.substring(0,37)+'<br/>'+name.substring(37,nameLength);
                   //}
               }
                
            }else{
               //三行
               //for(Integer i = 0; i < 3 ; i++){
                       ProductName = name.substring(0,37)+'<br/>' + name.substring(37,74)+'<br/>'+name.substring(74,nameLength);
               //}
            }
        }
    }
}