高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
public with sharing class EquipmentRentalExtendController {
    // 检索条件
    public Rental_Apply__c searchCondition { get; set; } // 其他定值条件
    public Rental_Apply_Equipment_Set__c finalDay { get; set; } // 适用
    public User finalDayFrom { get; set; } // 最终期限开始
    public User finalDayTo { get; set; }   // 最终期限结束
    public String ownerSearch { get; set; } // 所有者
    public String returnIMFupdate {get; set;}
    public String userProfileName {get; set;}
    public boolean isStockUser {get; set;}
 
    // 分页用 SWAG-B9UBDP start
    public Integer currPage { get; set; } // 当前页
    public Integer totalPage { get; set; } // 总页数
    public Integer selctRecordNum { get { return Integer.valueOf(selRecordOption); } } // 选择的每页记录数
    public Integer totalRecords { get; set; }  // 总记录数
    public String selRecordOption { get; set; }
    public static List<SelectOption> recordNum { get; private set; } // 选择每页记录数List
    // 分页用 SWAG-B9UBDP end
    // 分页用 SWAG-B9UBDP start
    // 翻页到首页
    public void firstPage() {
        currPage = 1;
    }
 
    // 向前翻页
    public void previousPage() {
        currPage --;
    }
 
    // 向后翻页
    public void nextPage() {
        currPage ++;
    }
 
    // 翻页到尾页
    public void endPage() {
        currPage = totalPage;
    }
 
    // 每页显示记录数变更
    public void recordNumChange() {
        currPage = 1;
        totalPage = (totalRecords / selctRecordNum) + (Math.mod(totalRecords, selctRecordNum) > 0 ? 1 : 0);
        setupRaesInfoList(raesInfoList);
    }
 
    static {
        recordNum = new List<SelectOption>();
        recordNum.add(new SelectOption('10', '10'));
        recordNum.add(new SelectOption('20', '20'));
        recordNum.add(new SelectOption('50', '50'));
        recordNum.add(new SelectOption('100', '100'));
        recordNum.add(new SelectOption('200', '200'));
    }
    // 分页用 SWAG-B9UBDP end
 
    public static List<SelectOption> textOpts { get; private set; }
    static {
        textOpts = new List<SelectOption>();
        textOpts.add(new SelectOption('', '-无-'));
        textOpts.add(new SelectOption('S:Rental_Apply__r.Name', Schema.SObjectType.Rental_Apply__c.fields.Name.label));
        textOpts.add(new SelectOption('S:Loaner_name_F__c', Schema.SObjectType.Rental_Apply_Equipment_Set__c.fields.Loaner_name_F__c.label));
        textOpts.add(new SelectOption('S:Loaner_code_F__c', Schema.SObjectType.Rental_Apply_Equipment_Set__c.fields.Loaner_code_F__c.label));
        textOpts.add(new SelectOption('S:Rental_Apply__r.Hospital__r.Hospital_Name__c', Schema.SObjectType.Account.fields.Hospital_Name__c.label));
        textOpts.add(new SelectOption('S:SerialNumber_F__c', Schema.SObjectType.Rental_Apply_Equipment_Set__c.fields.Rental_Asset_SerialNumber__c.label));
    }
    public static List<SelectOption> equalOpts { get; private set; }
    static {
        equalOpts = new List<SelectOption>();
        equalOpts.add(new SelectOption('equals', '等于'));
        equalOpts.add(new SelectOption('contains', '包含'));
    }
    public String text1 { get; set; } // 对象
    public String cond1 { get; set; } // 条件
    public String val1 { get; set; }  // 值
 
    /*****************ソートキー******************/
    public String sortKey { get; set; }
    public String preSortKey { get; private set; }
    public Boolean sortOrderAsc { get; private set; }
    public String[] sortOrder { get; private set; }
    private String[] columus = new String[] { 'Rental_Apply__c', 'RAES_Status__c', 'Demo_purpose2__c', 'Loaner_code_F__c', 'Rental_Apply__r.Hospital__r.Hospital_Name__c', 'Final_reply_day__c', 'Demo_purpose1__c', 'Bollow_Date__c'};
 
    private Boolean isSoft;
    private boolean isSearchAll;
    // 20210831 ljh SFDC-C4BBFH
    public String ExceedOrWeekDayFrom;  // 预定归还日开始
    public String ExceedOrWeekDayEnd; // 预定归还日结束  
    private boolean IsExceed;//超过中
    private boolean IsWeek;// 1周以内回收预定
    // 20210831 ljh SFDC-C4BBFH end
 
    /*****************ソート時再検索条件(画面からの入力条件を無視するため)******************/
    private String text1ForSort = null;
    private String cond1ForSort = null;
    private String val1ForSort = null;
    private String purpose1ForSort = null;
    private Date fromDateForSort = null;
    private Date toDateForSort = null;
    private String ownerIdForSort = null;
 
    // 明细结果
    public List<RaesInfo> raesInfoList { get; set; }
 
    // 明细条数
    public Integer getRaesInfoListSize() {
        return raesInfoList.size();
    }
 
    private String loginName; // 用户ID
    // 分页用 SWAG-B9UBDP start
    //private Integer Select_Limit = 200;
    // 显示数据条数限制
 
    private Integer Select_Limit = 600;
 
    public List<List<RaesInfo>> raesInfoListList { get; set; }
 
    // 分页用 SWAG-B9UBDP end
 
    public EquipmentRentalExtendController(ApexPages.StandardController controller) {
        // 分页用 SWAG-B9UBDP start
        this();
        // 分页用 SWAG-B9UBDP end
    }
 
    public EquipmentRentalExtendController() {
        // 分页用 SWAG-B9UBDP start
        currPage = 1;
        totalPage = 1;
        selRecordOption = '20';
        totalRecords = 0;
        raesInfoListList = new List<List<RaesInfo>>();
        raesInfoListList.add(new List<RaesInfo>());
 
        // 分页用 SWAG-B9UBDP end
    }
 
    // 画面初始化
    public void init() {
 
        returnIMFupdate = 'None';
        searchCondition = new Rental_Apply__c();
        finalDay = new Rental_Apply_Equipment_Set__c();
        finalDayFrom = [select id, Birth_Date__c from User where id = :Userinfo.getUserId()];
        finalDayFrom.Birth_Date__c = null;
        finalDayTo = [select id, Birth_Date__c from User where id = :Userinfo.getUserId()];
        finalDayTo.Birth_Date__c = null;
         
        text1 = '';
        cond1 = 'equals';
        val1 = null;
        userProfileName = UserInfo.getProfileId();
        if (userProfileName == System.Label.Profile_2B2)isStockUser = true;
        isSoft = false;
        isSearchAll = false;
        IsExceed = false;//20210816 ljh SFDC-C4BBFH 超过中
        IsWeek = false;//20210816 ljh SFDC-C4BBFH 1周以内回收预定
 
        loginName = null;
 
        // 获得用户ID
        String uidParam = System.currentPageReference().getParameters().get('uid');
        if (uidParam != null) {
            // URL传入用户
            User u = [select Id, FirstName, LastName from User where Id = :uidParam];
            ownerSearch = u.LastName + ' ' + u.FirstName;
            loginName = ownerSearch;
        } else {
            // 当前登陆用户
            User u = [Select Id, FirstName, LastName From User Where Id = :UserInfo.getUserId()];
            ownerSearch = u.LastName + ' ' + u.FirstName;
            loginName = ownerSearch;
        }
 
        raesInfoList = new List<RaesInfo>();
        // 获取借出备品set一览
        // 20210901 ljh SFDC-C4BBFH update start
        // List<Rental_Apply_Equipment_Set__c> raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch);
        List<Rental_Apply_Equipment_Set__c> raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch, ExceedOrWeekDayFrom,ExceedOrWeekDayEnd);
        // 20210901 ljh SFDC-C4BBFH update end
        // 作成明细行
        getRaesInfoList(raesList);
        // 生成犯规信息
        for (Rental_Apply_Equipment_Set__c rase : raesList) {
 
        }
        // 默认排序
        this.sortKey = '0';
        this.preSortKey = '0';
        this.sortOrderAsc = true;
        this.sortOrder = new String[7];
        this.sortOrder = new String[] {'↑', ' ', ' ', ' ', ' ', ' ', ' ', ' '};
        // 排序用检索条件退避
        text1ForSort = '';
        cond1ForSort = 'equals';
        val1ForSort = null;
        purpose1ForSort = null;
        fromDateForSort = null;
        toDateForSort = null;
        ownerIdForSort = ownerSearch;
    }
 
    // 检索按钮
    public PageReference searchBtn() {
        // 获取借出备品set一览
        // List<Rental_Apply_Equipment_Set__c> raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch);
        List<Rental_Apply_Equipment_Set__c> raesList = getData(text1, cond1, val1, searchCondition.Demo_purpose1__c, finalDayFrom.Birth_Date__c, finalDayTo.Birth_Date__c, ownerSearch , ExceedOrWeekDayFrom,ExceedOrWeekDayEnd);
        // 20210827 ljh SFDC-C4BBFH add start
        List<Rental_Apply_Equipment_Set__c> raesListNew = New List<Rental_Apply_Equipment_Set__c>();
        if(IsExceed || IsWeek){
            for(Rental_Apply_Equipment_Set__c raes:raesList){
                //Wei_Return_Finish__c
                if(raes.Wei_Return_Finish__c > 0){
                    raesListNew.add(raes);
                }else{
                    if(IsExceed && raes.Final_reply_day__c < raes.Return_Time_Day__c){
                        raesListNew.add(raes);
                    }
                    if(IsWeek && raes.Final_reply_day__c >= raes.Return_Time_Day__c){
                        raesListNew.add(raes);
                    }
                }
            }
        }else{
            raesListNew = raesList;
        }
        // 20210827 ljh SFDC-C4BBFH add end
        // 分页用 SWAG-B9UBDP start
        currPage = 1;
        // 分页用 SWAG-B9UBDP end
        // 作成明细行
        // getRaesInfoList(raesList);
        getRaesInfoList(raesListNew);
        // 排序用检索条件退避
        text1ForSort = text1;
        cond1ForSort = cond1;
        val1ForSort = val1;
        purpose1ForSort = searchCondition.Demo_purpose1__c;
        fromDateForSort = finalDayFrom.Birth_Date__c;
        toDateForSort = finalDayTo.Birth_Date__c;
        ownerIdForSort = ownerSearch;
 
 
 
        return null;
    }
 
    // 对明细行进行分页
    private void setupRaesInfoList(List<RaesInfo> raesInfoList) {
        list<List<RaesInfo>> tempraesInfoListList = new list<List<RaesInfo>>();
        List<RaesInfo> tempraesInfoList = new List<RaesInfo>();
        for (RaesInfo tempRaesInfo : raesInfoList) {
            if (tempraesInfoList.size() >= selctRecordNum) {
                tempraesInfoListList.add(tempraesInfoList);
                tempraesInfoList = new List<RaesInfo>();
            }
            tempraesInfoList.add(tempRaesInfo);
        }
        tempraesInfoListList.add(tempraesInfoList);
        totalPage = tempraesInfoListList.size();
        if (tempraesInfoList.size() == 0) {
            totalPage --;
        }
        totalRecords = raesInfoList.size();
        currPage = 1;
        raesInfoListList = tempraesInfoListList.clone();
    }
 
    // 作成明细行
    private void getRaesInfoList(List<Rental_Apply_Equipment_Set__c> raesList) {
        Boolean overLimit = false;
        Set<String> unReturnCompletely = new Set<String>();
        // 已经延期申请中的备品借出申请
        Map<Id, Id> rentalApplyMap = new Map<Id, Id>();
        for (Rental_Apply_Equipment_Set__c raes : raesList) {
            if (raes.Extend_Status__c == '申请中' && !rentalApplyMap.containsKey(raes.Rental_Apply__c)) {
                rentalApplyMap.put(raes.Rental_Apply__c, raes.Rental_Apply__c);
            }
            if (raes.Rental_Apply__r.Local_Borrow_Foul__c > 0) {
                unReturnCompletely.add(raes.Rental_Apply__r.Name);
            }
        }
        List<id> raesIdList = new List<id>();
        // 已经打勾的明细保留并提前,但是要刷新最新状态
        Map<String, Rental_Apply_Equipment_Set__c> raesMap = new Map<String, Rental_Apply_Equipment_Set__c>();
        for (Rental_Apply_Equipment_Set__c raes : raesList) {
            raesMap.put(raes.Id, raes);
            raesIdList.add(raes.Id);
        }
        // 已经选择的明细
        Map<Id, Rental_Apply_Equipment_Set__c> selectedMap = new Map<Id, Rental_Apply_Equipment_Set__c>();
        for (RaesInfo info : raesInfoList) {
            // 打勾并且备品借出申请不是申请中的,或者刚刚进行延期申请的(特殊处理),视为优先显示明细
            if ((info.check && !rentalApplyMap.containsKey(info.raes.Rental_Apply__c)) || info.isExtend) {
                selectedMap.put(info.raes.Id, raesMap.containsKey(info.raes.Id) ? raesMap.get(info.raes.Id) : info.raes);
            }
        }
 
        Map<String, List<Rental_Apply_Equipment_Set_Detail__c>> resultRaesdMap = new Map<String, List<Rental_Apply_Equipment_Set_Detail__c>>();
 
        List<Rental_Apply_Equipment_Set_Detail__c> RaasedList = [
                    select id
                    , Rental_Apply_Equipment_Set__r.Id, Rental_Apply_Equipment_Set__r.SerialNumber_F__c
                    , Rental_Apply_Equipment_Set__r.Fixture_Set__r.Loaner_code__c, Rental_Apply_Equipment_Set__r.Fixture_Set__r.Name
                    //, Asset__r.OwnershipMachine_No__c
                    //, Asset__r.Name,Asset__r.Loaner_accsessary__c
                    , OwnershipMachine_No_c__c
                    , Asset__r.Name, Loaner_accsessary_F__c
                    from Rental_Apply_Equipment_Set_Detail__c
                    where Rental_Apply_Equipment_Set__r.Id in :raesIdList
                    and Cancel_Select__c = False];
 
        if (RaasedList != null) {
            for (Rental_Apply_Equipment_Set_Detail__c RaesdInfo : RaasedList) {
                if (resultRaesdMap.containsKey(RaesdInfo.Rental_Apply_Equipment_Set__r.Id)) {
                    resultRaesdMap.get(RaesdInfo.Rental_Apply_Equipment_Set__r.Id).add(RaesdInfo);
                } else {
                    List<Rental_Apply_Equipment_Set_Detail__c> raList = New List<Rental_Apply_Equipment_Set_Detail__c>();
                    raList.add(RaesdInfo);
                    resultRaesdMap.put(RaesdInfo.Rental_Apply_Equipment_Set__r.Id, raList);
                }
            }
        }
 
 
        // 优先显示明细放在最前面
        raesInfoList = new List<RaesInfo>();
        List<Rental_Apply_Equipment_Set_Detail__c> raesdList = New List<Rental_Apply_Equipment_Set_Detail__c>();
        for (Rental_Apply_Equipment_Set__c raes : selectedMap.values()) {
            raesdList = resultRaesdMap.get(raes.Id);
            RaesInfo raesinfo = new RaesInfo(true, raes, true, raesdList);
            raesInfoList.add(raesinfo);
        }
        raesInfoList.sort();
        Integer selectCnt = raesInfoList.size();
        // 其他明细作成
        for (Integer i = 0; i < raesList.size(); i++) {
            // 201を超えた場合前200のみを出す
            if (selectCnt + i >= Select_Limit) {overLimit = true; break;}
            raesdList = resultRaesdMap.get(raesList[i].Id);
            // 作成明细行
            if (!selectedMap.containsKey(raesList[i].Id)) {
                if (rentalApplyMap.containsKey(raesList[i].Rental_Apply__c)) {
                    // 延长申请中的备品借出申请,不能操作
                    RaesInfo raesinfo = new RaesInfo(false, raesList[i], false, raesdList);
                    raesInfoList.add(raesinfo);
                } else {
                    // 其他备品借出申请,可以操作
                    RaesInfo raesinfo = new RaesInfo(false, raesList[i], true, raesdList);
                    raesInfoList.add(raesinfo);
                }
            }
        }
 
        // 显示数据条数信息
        if (returnIMFupdate != 'None') {
            //for(String Str : unReturnCompletely){
            //    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, Str ));
            //}
            //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '以上备品申请未整单归还,计入违规' ));
        }
        if (overLimit) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '数据超过' + Select_Limit + '条,只显示前' + Select_Limit + '条'));
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, '共有' + getRaesInfoListSize() + '条数据'));
        }
        // 分页用 SWAG-B9UBDP start
        setupRaesInfoList(raesInfoList);
        // 分页用 SWAG-B9UBDP end
    }
 
    // 貸出中全部
    public void searchsp1Btn() {
        isSearchAll = false;
        IsExceed = false;//20210816 ljh SFDC-C4BBFH 超过中
        IsWeek = false;//20210816 ljh SFDC-C4BBFH 1周以内回收预定
        // 设定对应检索条件
        text1 = '';
        cond1 = 'equals';
        val1 = null;
        searchCondition.Demo_purpose1__c = null;
        finalDayFrom.Birth_Date__c = null;
        finalDayTo.Birth_Date__c = null;
        // 检索
        searchBtn();
    }
 
    // 超過中
    public void searchsp2Btn() {
        isSearchAll = false;
        // 设定对应检索条件
        text1 = '';
        cond1 = 'equals';
        val1 = null;
        searchCondition.Demo_purpose1__c = null;
        finalDayFrom.Birth_Date__c = null;
        // 20210628 ljh update SFDC-C4BBFH start
        // finalDayTo.Birth_Date__c = Date.today();
        finalDayTo.Birth_Date__c = null;
        ExceedOrWeekDayFrom = null; // 开始
        ExceedOrWeekDayEnd = String.valueOf(Date.today());// 结束
        IsExceed = true;
        IsWeek = false;
        // 20210628 ljh update SFDC-C4BBFH end
        // 检索
        searchBtn();
    }
 
    // 1週間以内
    public void searchsp3Btn() {
        isSearchAll = false;
        // 设定对应检索条件
        text1 = '';
        cond1 = 'equals';
        val1 = null;
        searchCondition.Demo_purpose1__c = null;
        // 20210628 ljh update SFDC-C4BBFH start
        // finalDayFrom.Birth_Date__c = Date.today();
        // finalDayTo.Birth_Date__c = Date.today().adddays(7);
        ExceedOrWeekDayFrom = String.valueOf(Date.today()); // 开始
        ExceedOrWeekDayEnd = String.valueOf(Date.today().adddays(7)); // 结束
        finalDayFrom.Birth_Date__c = null;
        finalDayTo.Birth_Date__c = null;
        IsExceed = false; //【超过中】
        IsWeek = true; // 【1周以内回收预定】
        // 20210628 ljh update SFDC-C4BBFH end
        // 检索
        searchBtn();
    }
 
    // 全部
    public void searchsp4Btn() {
        isSearchAll = true;
        IsExceed = false;//20210816 ljh SFDC-C4BBFH 超过中
        IsWeek = false;//20210816 ljh SFDC-C4BBFH 1周以内回收预定
        // 设定对应检索条件
        text1 = '';
        cond1 = 'equals';
        val1 = null;
        searchCondition.Demo_purpose1__c = null;
        finalDayFrom.Birth_Date__c = null;
        finalDayTo.Birth_Date__c = null;
        // 检索
        searchBtn();
    }
 
    // 明细排序
    public void sortTable() {
        // 排序
        if (this.sortKey == this.preSortKey) {
            // 方向が変わるのみ
            this.sortOrderAsc = !this.sortOrderAsc;
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        } else {
            if (preSortKey == '') {
                preSortKey = '0';
            }
            this.sortOrderAsc = true;
            this.sortOrder[Integer.valueOf(this.preSortKey)] = ' ';
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        }
        this.preSortKey = this.sortKey;
        // 获取排序后借出备品set一览
        isSoft = true;
        system.debug('IsExceed:'+IsExceed+'~'+IsWeek);
        // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, 'IsExceed。IsWeek' + IsExceed+IsWeek));
        // 20210901 ljh SFDC-C4BBFH update start
        // List<Rental_Apply_Equipment_Set__c> raesList = getData(text1ForSort, cond1ForSort, val1ForSort, purpose1ForSort, fromDateForSort, toDateForSort, ownerIdForSort);
        List<Rental_Apply_Equipment_Set__c> raesList = getData(text1ForSort, cond1ForSort, val1ForSort, purpose1ForSort, fromDateForSort, toDateForSort, ownerIdForSort, ExceedOrWeekDayFrom,ExceedOrWeekDayEnd);
        List<Rental_Apply_Equipment_Set__c> raesListNew = New List<Rental_Apply_Equipment_Set__c>();
        if(IsExceed || IsWeek){
            for(Rental_Apply_Equipment_Set__c raes:raesList){
                //Wei_Return_Finish__c
                if(raes.Wei_Return_Finish__c > 0){
                    raesListNew.add(raes);
                }else{
                    if(IsExceed && raes.Final_reply_day__c < raes.Return_Time_Day__c){
                        raesListNew.add(raes);
                    }
                    if(IsWeek && raes.Final_reply_day__c >= raes.Return_Time_Day__c){
                        raesListNew.add(raes);
                    }
                }
            }
        }else{
            raesListNew = raesList;
        }
        // 作成明细行
        // getRaesInfoList(raesList);
        getRaesInfoList(raesListNew);
        // 20210827 ljh SFDC-C4BBFH add end
    }
 
    // 适用按钮
    public void setDate() {
        // 检索,选择的明细优先显示
        searchBtn();
        // 打勾的明细自动填入适用的值
        for (RaesInfo info : raesInfoList) {
            if (info.check == true) {
                info.raes.Request_extend_day__c = finalDay.Request_extend_day__c;
                info.raes.Extend_request_reason__c = finalDay.Extend_request_reason__c;
            }
        }
    }
 
    // 保存按钮
    public PageReference saveBtn() {
        // 回寄物流信息检查
        boolean errflg = false;
        //bp2        for (RaesInfo info : raesInfoList) {
        //
        //            if (info.check && (info.raes.Return_Fedex_number2__c != null && info.raes.Return_Fedex_number2__c != '' ||
        //                                info.raes.Return_delivery_company2__c != null ||
        //                                info.raes.Return_Distributor_method2__c != null ||
        //                                info.raes.Received_confirmation_staff2__c != null)
        //            ) {
        //                if (info.raes.Return_Fedex_number2__c == null ||
        //                    info.raes.Return_Fedex_number2__c == '') {
        //                    info.raes.Return_Fedex_number2__c.addError('请补全回寄物流信息');
        //                    errflg = true;
        //                }
        //                if (info.raes.Return_delivery_company2__c == null) {
        //                    info.raes.Return_delivery_company2__c.addError('请补全回寄物流信息');
        //                    errflg = true;
        //                }
        //                if (info.raes.Return_Distributor_method2__c == null) {
        //                    info.raes.Return_Distributor_method2__c.addError('请补全回寄物流信息');
        //                    errflg = true;
        //                }
        //                if (info.raes.Received_confirmation_staff2__c == null) {
        //                    info.raes.Received_confirmation_staff2__c.addError('请补全回寄物流信息');
        //                    errflg = true;
        //                }
        //            }
        //        }
        //        if (errflg == true) {
        //            return null;
        //        }
        // 打勾的明细,保存延期时间和延期理由
        List<Rental_Apply_Equipment_Set__c> updateList = new List<Rental_Apply_Equipment_Set__c>();
        //bp2        List<Equipment_Set__c> updateList2 = new List<Equipment_Set__c>();
        for (RaesInfo info : raesInfoList) {
            if (info.check) {
                Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(Id = info.raes.Id);
                //bp2
                //                raes.Request_extend_day__c = info.raes.Request_extend_day__c;
                //                raes.Extend_request_reason__c = info.raes.Extend_request_reason__c;
                raes.Received_Confirm__c = info.raes.Received_Confirm__c;
                raes.Received_ng_detail__c = info.raes.Received_ng_detail__c;
                // OLY_OCM-460 Loaner_received_time__c的设置移动到Trigger
                //bp2
                //                raes.Return_delivery_company2__c = info.raes.Return_delivery_company2__c;
                //                raes.Return_Fedex_number2__c = info.raes.Return_Fedex_number2__c;
                //                raes.Return_Distributor_method2__c = info.raes.Return_Distributor_method2__c;
                //                raes.Received_confirmation_staff2__c = info.raes.Received_confirmation_staff2__c;
                //                if (info.raes.Return_Fedex_number2__c == null) {
                //                    raes.Asset_return_time__c = null;
                //                }
                updateList.add(raes);
                //bp2
                //                Equipment_Set__c es = new Equipment_Set__c(Id=info.raes.Equipment_Set__c);
                //                es.Return_delivery_company__c = info.raes.Return_delivery_company2__c;
                //                es.Return_Fedex_number__c = info.raes.Return_Fedex_number2__c;
                //                es.Return_Distributor_method__c = info.raes.Return_Distributor_method2__c;
                //                es.Received_confirmation_staff__c = info.raes.Received_confirmation_staff2__c;
                //                if (info.raes.Return_Fedex_number2__c == null) {
                //                    es.Received_loaner_time__c = null;
                //                }
                //                updateList2.add(es);
            }
        }
        System.debug('raes is' + updateList);
        // 更新
        if (updateList.size() > 0) {
            try {
                //update updateList;//2017/1/12之前,该更新操作位于Savepoint内部,但发现会导致个别工作流无法出发
                FixtureUtil.withoutUpdate(updateList);
            } catch (Exception e) {
                //故将其外移,注此说明,以备后查
                ApexPages.addMessages(e);
                return null;
            }
            //bp2
            //            Savepoint sp = Database.setSavepoint();
            //            try {
            //                ControllerUtil.updEquipmentSetList(updateList2);
 
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, '保存完了'));
            //bp2
            //            } catch (Exception e) {
            //                system.debug('=====' + e.getMessage());
            //                ApexPages.addMessages(e);
            //                Database.rollback(sp);
            //                return null;
            //            }
        }
 
        // 检索,选择的明细优先显示
        searchBtn();
 
        return null;
    }
 
//bp2
//    // 延期申请按钮
//    public PageReference extendBtn() {
//        // 检索,选择的明细优先显示
//        searchBtn();
//        // 选择的明细中第一条的备品借出申请ID
////        String raid = '';
////        if (raesInfoList.size() > 0) {
////            raid = raesInfoList[0].raes.Rental_Apply__c;
////        }
//        // 每次只能对一个备品借出申请进行延期
////        for (RaesInfo info : raesInfoList) {
////            if (info.check && raid != info.raes.Rental_Apply__c) {
////                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, '每次只能对一个备品借出申请进行延期'));
////                return null;
////            }
////        }
//        // 打勾的明细,保存延期时间和延期理由
//        List<Rental_Apply_Equipment_Set__c> updateList = new List<Rental_Apply_Equipment_Set__c>();
//        for (RaesInfo info : raesInfoList) {
//            if (info.check) {
//                Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(Id=info.raes.Id);
//                raes.Request_extend_day__c = info.raes.Request_extend_day__c;
//                raes.Extend_request_reason__c = info.raes.Extend_request_reason__c;
//                raes.Extend_Status__c = '填写完毕';
//                updateList.add(raes);
//                // 填入延长时间的,标记为延长申请的对象
//                if (info.raes.Request_extend_day__c != null) {
//                    info.isExtend = true;
//                }
//            }
//        }
//        // 更新备品借出申请的承认申请状态
////        Rental_Apply__c ra = new Rental_Apply__c(Id=raid);
////        ra.ApprovalProcess_Status__c = '已填写延长申请';
//        // 更新
//        if (updateList.size() > 0) {
//            Savepoint sp = Database.setSavepoint();
//            try {
//                update updateList;
////                update ra;
//                Approval.ProcessSubmitRequest[] psrList = new List<Approval.ProcessSubmitRequest>();
//                for (Rental_Apply_Equipment_Set__c raes : updateList) {
//                    // 开始承认流程
//                    Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
//                    psr.setObjectId(raes.Id);
//                    psrList.add(psr);
//                }
//                Approval.ProcessResult[] submitResult = Approval.process(psrList);
//                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, '延长申请完了。'));
//            } catch (Exception e) {
//                system.debug('=====' + e.getMessage());
//                ApexPages.addMessages(e);
//                Database.rollback(sp);
//                return null;
//            }
//        }
//        // 更新后,刷新明细行
//        searchBtn();
//        for (RaesInfo info : raesInfoList) {
//            // 刚刚延期申请的明细特殊处理
//            if (info.check) {
//                info.check = false;
//                info.canChange = false;
//                info.status = 'Blue';
//            }
//        }
 
//        return null;
//    }
 
    // 获取借出备品set一览
    // 20210901 ljh SFDC-C4BBFH update start
    // private List<Rental_Apply_Equipment_Set__c> getData(String txt, String con, String val, String pur, Date fd, Date td, String uname) {
    private List<Rental_Apply_Equipment_Set__c> getData(String txt, String con, String val, String pur, Date fd, Date td, String uname , String fdEW, String tdEW) {
    // 20210901 ljh SFDC-C4BBFH update end
        String soql = '';
        //  注释掉不再使用的数据 SWAG-B9UBDP start
        soql += 'select Id,Name,Demo_purpose1__c,Demo_purpose2__c,Final_reply_day__c, Return_Time_Day__c, Wei_Return_Finish__c, RetalFSetDetail_Cnt__c, ' + 
        //'Request_extend_day__c, Extend_request_reason__c, ' + 
        'Extend_Status__c,';
        soql += '       Rental_Apply__c,' + 
        //'Rental_Apply__r.Foul_Points__c,Rental_Apply__r.Hospital__c, Loaner_code_text__c,'+
        'Wei_loaner_arranged__c, First_RAESD_Model_No_F__c, ';
        soql += '       Rental_Apply__r.Hospital__r.Hospital_Name__c,'+ 
        'Fixture_Set__c,'+
        'Loaner_name_F__c,Loaner_code_F__c,RAES_Status__c,SerialNumber_F__c,Rental_Apply__r.name, ';
        soql += ' Rental_Apply__r.Bollow_Date__c,Bollow_Date__c,'+
        //'Rental_Apply__r.Person_In_Charge__c,' +
        'Rental_Apply__r.Person_In_Charge__r.Name,Rental_Apply__r.Local_Borrow_Foul__c,';
 
        soql += ' Received_Confirm__c,Received_ng_detail__c,';
        soql += ' Rental_Apply__r.RecordType.Name,';
        //'Return_delivery_company2__c,Return_Fedex_number2__c,Return_Distributor_method2__c,Received_confirmation_staff2__c,'+
        // '';
        soql += 'Rental_Apply__r.Received_Confirm_NG_Not_Return__c, '+ 
        //' Rental_Apply__r.faraway__c, Rental_Apply__r.RequestOrderPoint_sum__c, ' +
        ' Rental_Apply__r.UnSign_Foul_point__c, Rental_Apply__r.Not_Create_Repair_Ordered_Date__c, Rental_Apply__r.Borrow_Date_Fouls__c, ';
        
        soql += ' First_RAESD__r.DeliverySlip__c, First_RAESD__r.Return_DeliverySlip__c';
        //  注释掉不再使用的数据  SWAG-B9UBDP end
        soql += '  from Rental_Apply_Equipment_Set__c';
        soql += ' where Rental_Apply__r.OwnerId != null';
        //soql += ' and Cancel_Select__c = false';
        // soql += ' and Shippment_loaner_time__c != null';
        // soql += ' and Lost_product_check__c != \'OK\'';
        soql += ' and Yi_loaner_arranged__c > 0';
        soql += ' and Wei_Arrival_in_wh__c > 0';
        // 欠品确认数 欠品确认未完了数,欠品确认不为OK的,因为消耗的已被未回库件数排出了,所以只看欠品中的和欠品未确认数
        soql += ' and (Lost_product_cnt__c > 0 or Lost_item_check_not_finish__c > 0)';
        if (!String.isBlank(uname)) {
            String[] vals = uname.split(' ');
            for (String v : vals) {
                soql += ' and Rental_Apply__r.Owner.Name like \'%' + String.escapeSingleQuotes(v.replaceAll('%', '\\%')) + '%\'';
            }
        }
        if (!isSearchAll) {
            //soql += '   and Shippment_loaner_time__c <> null';
            //soql += '   and Received_loaner_time__c = null';
            //soql += '   and Equipment_Set__r.Asset_Set_status2__c = \'2.借出中\'';
            //bp2       soql += '   and RAES_Status__c in (\'出库完了\',\'申请者收到确认完了\',\'申请者收货NG\',\'医院收到确认完了\',\'归还发送完了\',\'欠品中\',\'归还后CDS完了\',\'归还后检查完了\',\'回收后检测NG\',\'归还后检查完了(附属品NG)\')';
            soql += '   and RAES_Status__c in ('
                    + '\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Chu_Ku.ordinal()) + '\''
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Shen_Qing_Zhe_Yi_Shou_Huo.ordinal()) + '\''
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Shen_Qing_Zhe_Shou_Huo_NG.ordinal()) + '\''
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Yuan_Yi_Zhuang_Ji_Que_Ren.ordinal()) + '\''
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Hui_Ji.ordinal()) + '\''
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Qian_Pin_Zhong.ordinal()) + '\''
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Yi_Hui_Shou.ordinal()) + '\''
                    //bp2 TODO \'欠品中\'
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Hui_Shou_Hou_Yi_CDS.ordinal()) + '\''
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Hui_Shou_Hou_Jian_Ce_NG.ordinal()) + '\''
                    //bp2 toDO \'归还后检查完了(附属品NG)\'
                    + ',\'' + FixtureUtil.raesStatusMap.get(FixtureUtil.RaesStatus.Hui_Shou_Hou_Yi_Jian_Ce.ordinal()) + '\''
                    + ')';
        }
        // 借出设备机身号码特别处理
        if (txt == 'S:SerialNumber_F__c' && con == 'equals' && String.isNotBlank(val)) {
            String[] vals = val.split(',');
            if (vals.size() > 0) {
                String txt1 = txt.substring(2);     // S:Name 、最初の2文字がタイプです
                soql += ' and ( ';
                for (String v : vals) {
                    soql += txt1 + ' like \'%' + String.escapeSingleQuotes(v.replaceAll('%', '\\%')) + '%\' or ';
                }
                soql = soql.substring(0, soql.length() - 4);
                soql += ')';
            }
        } else {
            soql += makeTextSql(txt, con, val);
        }
 
        if (pur != null) {
            soql += ' and Demo_purpose1__c = :pur ';
        }
        if (fd != null) {
            soql += ' and Final_reply_day__c >= :fd ';
        }
        if (td != null) {
            soql += ' and Final_reply_day__c <= :td ';
        }
        //20210816 ljh SFDC-C4BBFH start
        if(IsExceed || IsWeek){
            soql += ' and Extend_Status__c != \'批准\' and Extend_Status__c != \'申请中\' ';
            // 超过中
            if(IsExceed){
                soql += ' and ((Wei_Return_Finish__c > 0 ';
                soql += ' and Final_reply_day__c < '+tdEW;
                soql += ') OR Wei_Return_Finish__c = 0)';
                // Return_Time_Day__c
            }
            // 一周以内
            if(IsWeek){
                // Date.today().adddays(7)
                soql += ' and ((Wei_Return_Finish__c > 0 ';
                soql += ' and Final_reply_day__c >= '+fdEW;
                soql += ' and Final_reply_day__c < '+tdEW;
                soql += ') OR (Wei_Return_Finish__c = 0 ';
                // soql += ' and Final_reply_day__c >= Return_Time_Day__c';
                soql += ' and Final_reply_day__c < '+tdEW;
                soql += '))';
            }
        }
        //20210816 ljh SFDC-C4BBFH end
        if (isSoft) {
            soql += ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last ');
        } else {
            soql += ' order by Rental_Apply__c,Name ';
        }
        soql += ' limit ' + (Select_Limit + 1);
        // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info, 'soql。' + tdEW+soql));
        system.debug('====soql:' + soql);
        return Database.query(soql);
    }
 
    // 拼接检索条件sql文
    private String makeTextSql(String txt1, String con, String val) {
        String soql = '';
        if (String.isBlank(con)) {
            con = 'equals';
        }
        // containsの場合、日報画面の病院検索を真似し、spaceで分けて、and検索
        // equalsの場合、SF標準の検索を真似し、「,」で分けて、or検索
        if (!String.isBlank(txt1)) {
            if ((con == 'contains' || con == 'notcontains') && val.contains(' ')) {
                String[] vals = val.split(' ');
                String cSql = '';
                for (String v : vals) {
                    cSql += this.makeTextSqlStr(txt1, con, v);
                }
                if (con == 'contains') {
                    soql += cSql;
                } else {
                    // notcontains
                    cSql = cSql.replaceAll(' and ', ') and (NOT ');
                    soql += cSql.substring(1) + ') ';
                }
            } else if ((con == 'equals' || con == 'notequals') && val.contains(',')) {
                String[] vals = val.split(',');
                if (vals.size() > 0) {
                    String txt = txt1.substring(2);     // S:Name 、最初の2文字がタイプです
                    soql += ' and ( ';
                    for (String v : vals) {
                        if (con == 'equals') {
                            soql += txt + ' = \'' + v + '\' or ';
                        } else {
                            // notequals
                            soql += txt + ' <> \'' + v + '\' and ';
                        }
                    }
                    soql = soql.substring(0, soql.length() - 4);
                    soql += ')';
                }
            } else {
                String cSql = this.makeTextSqlStr(txt1, con, val);
                if (con != 'notcontains') {
                    soql += this.makeTextSqlStr(txt1, con, val);
                } else {
                    // notcontains
                    if (!String.isBlank(cSql)) {
                        cSql = cSql.substring(5);       // ' and ' の5文字を外す
                        soql += ' and (NOT ' + cSql + ') ';
                    }
                }
            }
        }
        return soql;
    }
 
    /**
     * 文字列検索文を作成
     */
    private String makeTextSqlStr(String txt1, String con, String val) {
        String soql = '';
        if (!String.isBlank(txt1)) {
            String txt = txt1.substring(2);
            String colType = txt1.substring(0, 2);
            String tmpVal = val;
            // 空白の場合''にする
            if (String.isBlank(tmpVal)) {
                if (con == 'equals') {
                    //soql += ' and ' + txt + ' = ' + tmpVal;
                    soql += ' and ' + txt + ' = null';
                } else if (con == 'notequals') {
                    soql += ' and ' + txt + ' <> null';
                } else {
                    // 空白の場合、contains, notcontains と starts withは無視
                }
            } else {
                soql += ' and ' + txt;
                if (con == 'equals') {
                    if (colType == 'S:') {
                        soql += ' = \'' + tmpVal + '\'';
                    } else {
                        soql += ' = ' + tmpVal + ' ';
                    }
                } else if (con == 'notequals') {
                    if (colType == 'S:') {
                        soql += ' <> \'' + tmpVal + '\'';
                    } else {
                        soql += ' <> ' + tmpVal + ' ';
                    }
                } else if (con == 'contains' || con == 'notcontains') {
                    soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
                } else if (con == 'starts with') {
                    soql += ' like \'' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
                } else {
                    if (colType == 'S:') {
                        soql += ' ' + con + '\'' + tmpVal + '\'';
                    } else {
                        soql += ' ' + con + ' ' + tmpVal + ' ';
                    }
                }
            }
        }
        return soql;
    }
 
    @TestVisible
    class RaesInfo implements Comparable {
        public Boolean check { get; set; } // 是否选择
        public Rental_Apply_Equipment_Set__c raes { get; set; } // 借出备品set一览
        //public Equipment_Set__c es { get; set; } // 备品set
        public String esName { get; private set; } // 备品名称
        public String esCode { get; private set; } // 备品型号
        public String hpName { get; private set; } // 借用医院名
        public String rentalPerson { get; private set; } //申请人
        public Date bollowDate { get; private set; } //发货日期
        public Boolean canChange { get; set; } // 是否可编辑
        public String status { get; private set; } // 明细状态
        public Boolean isExtend { get; private set; } // 延长申请标记
        public String DetailsLine { get; private set; }//附属品明细
        public String serialNumber {get; private set; }//机身编号
        public String recordTypeName {get; private set; }//レコードタイプ名
        public String FoulReasonStr {get; set;} //犯规理由
        public RaesInfo(Boolean incheck, Rental_Apply_Equipment_Set__c inraes, Boolean incan, List<Rental_Apply_Equipment_Set_Detail__c> raasedList) {
            check = incheck;
            raes = inraes;
            //es = inraes.Equipment_Set__r;
            esName = inraes.Loaner_name_F__c;
 
            hpName = inraes.Rental_Apply__r.Hospital__r.Hospital_Name__c;
            rentalPerson = inraes.Rental_Apply__r.Person_In_Charge__r.Name;
            bollowDate = inraes.Rental_Apply__r.Bollow_Date__c;
            canChange = incan;
            Map<String, Object> result = new Map<String, Object>();
            result = getAppendage(raasedList);
            DetailsLine = (String)result.get('DetailsLine');
            Boolean LotFlag = (Boolean)result.get('LotFlag');
            if (LotFlag) {
                serialNumber = ' ';
                esCode = ' ';
            } else {
                serialNumber = inraes.SerialNumber_F__c;
                esCode = inraes.First_RAESD_Model_No_F__c;
            }
            recordTypeName = inraes.Rental_Apply__r.RecordType.Name;
            //*******************************增加生成犯规原因的功能*************************************************
            FoulReasonStr = '';
            if (inraes.Rental_Apply__r.Not_Create_Repair_Ordered_Date__c > 0) {
                FoulReasonStr += '未生成RC受理日犯规     ';
            }
            if (inraes.Rental_Apply__r.UnSign_Foul_point__c > 0) {
                FoulReasonStr += '未签字确认犯规     ';
            }
            if (inraes.Rental_Apply__r.Received_Confirm_NG_Not_Return__c > 0) {
                FoulReasonStr += '现场收货NG未寄回犯规     ';
            }
            if (inraes.Rental_Apply__r.Borrow_Date_Fouls__c  > 0) {
                FoulReasonStr += '借出日期犯规';
            }
            if (inraes.Rental_Apply__r.Local_Borrow_Foul__c > 0) {
                FoulReasonStr += '未整单归还犯规';
            }
            //*******************************增加生成犯规原因的功能*************************************************
            Date now = Date.today();
 
            // OLY_OCM-610 对应
            Date redDate = Date.today();
            // 如果 未回寄未完了件数 == 0 说明都链上了运输单 这样的话就看最新回寄日和最新预定归还日最对比
            if (inraes.Wei_Return_Finish__c == 0) {
                redDate = inraes.Return_Time_Day__c;
            }
 
            if (inraes.Extend_Status__c == '批准') {
                // 灰色 延長申請完了
                status = 'Gray';
                canChange = false;
            } else if (inraes.Extend_Status__c == '申请中') {
                // 青色 延長申請中
                status = 'Blue';
            } else if (inraes.Final_reply_day__c < redDate) {
                // 赤色 超過
                status = 'Red';            
            } else if (inraes.Final_reply_day__c < now.adddays(7)) {
                // 黄色 一週間以内
                status = 'Yellow';
            } else {
                // 其他,正常颜色
                status = 'Normal';
            }
            isExtend = false;
        }
 
        private Map<String, Object> getAppendage(List<Rental_Apply_Equipment_Set_Detail__c> raasedList) {
            Map<String, Object> resultMap = new Map<String, Object>();
            String DetailsLine = '';
            boolean LotFlag = true;
            if (raasedList != null) {
                Map<String, integer> DLSM = new Map<String, integer>();
                Set<String> AllSet = new Set<String>();
                for (Rental_Apply_Equipment_Set_Detail__c Ec : raasedList) {
                    if (DLSM.containsKey(Ec.OwnershipMachine_No_c__c)) {
                        integer i = DLSM.get(Ec.OwnershipMachine_No_c__c) + 1;
                        DLSM.put(Ec.OwnershipMachine_No_c__c, i);
                    } else {
                        DLSM.put(Ec.OwnershipMachine_No_c__c, 1);
                    }
                    if (Ec.Loaner_accsessary_F__c == false) {
                        //有主机
                        LotFlag = false;
                    }
 
                    //去掉主机
                    if (Ec.Loaner_accsessary_F__c == true) {
                        AllSet.add(Ec.OwnershipMachine_No_c__c);
                    }
                }
                system.debug('DLSM:::::' + DLSM);
                system.debug('AllSet:::::' + AllSet);
                for (String Ecc : AllSet) {
                    //然后做成字符串
                    if (DLSM.get(Ecc) == 1) {
                        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);
                }
 
            }
            resultMap.put('DetailsLine', DetailsLine);
            resultMap.put('LotFlag', LotFlag);
            return resultMap;
        }
 
        // 默认排序 Rental_Apply__c,Name
        public Integer compareTo(Object compareTo) {
            RaesInfo info = (RaesInfo)compareTo;
            if (check == info.check) {
                if (raes.Rental_Apply__c == info.raes.Rental_Apply__c) {
                    if (raes.Name == info.raes.Name) {
                        return 0;
                    }
                    if (raes.Name > info.raes.Name) {
                        return 1;
                    }
                    return -1;
                }
                if (raes.Rental_Apply__c > info.raes.Rental_Apply__c) {
                    return 1;
                }
                return -1;
            }
            if (check) {
                return 1;
            }
            return -1;
        }
    }
}