高章伟
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
public with sharing class RepPAEDecisionRecordController {
    public PAE_DecisionRecord__c rdRecord {
        get;
        set;
    }
    //PAE判定记录的Id
    public String Id {
        get;
        set;
    }
    //PAE判定记录的记录类型Id
    public String RecordTypeId;
    public String RecordTypeIdD;
    public String RecordTypeName {
        get;
        set;
    }
    public String ASac_ASrc;
    public Boolean editAble {
        get;
        set;
    }
    // 保存按钮 需要考虑再现/不再现的更新了。
    // 简档:2F4_技术推进部,2F4_技术推进部_非SSO,2F2B_服务管理,系统管理员的人操作的时候,需要允许操作【保存】。
    public Boolean savebuton {
        get;
        set;
    }
    public Integer CancelineFlag {
        get;
        set;
    }
    public String OCSM_QARA {
        get;
        set;
    } //20200310
    public String OCSM_Cording {
        get;
        set;
    } //20200310
    public String intakePAEReappearConfirm {
        get;
        set;
    }
    // 如果Repair__c     中DOJ_Status__c       的字段值为待EtQ Response 或者
    //     Report__c 中ComplaintStatus__c  的字段值为待EtQ Response 将标记改为true
    // 影响至对应页面中的按钮是否可用
    public Boolean editFlag {
        get;
        set;
    }
    // 当前报告书
    public Report__c repa {
        get;
        set;
    }
    // 是否是OSH
    public Boolean isOSH {
        get;
        set;
    }
    public String ReportId {
        get;
        set;
    }
    public String productIdx {
        get;
        set;
    }
    //页面的明细
    public List < PAE_DecisionRecordDetailInfo > paedRecordDetailView {
        get;
        set;
    }
    public Integer paedRecordDetailViewCount {
        get {
            return paedRecordDetailView == null ? 0 : paedRecordDetailView.size();
        }
    }
    public RepPAEDecisionRecordController(ApexPages.StandardController stdController) {
        Id = ApexPages.currentPage().getParameters().get('Id');
        String profileId = UserInfo.getProfileId();
        // 当前用户是否在 OSH自定义标签中
        isOSH = System.label.OSH.contains(profileId);
        System.debug('isOSH+' + isOSH);
        // 判断Report__c的ComplaintStatus__c字段值是否为待EtQ Response
        ReportId = ApexPages.currentPage().getParameters().get('ReportId');
        List < Report__c > Rep = [select id, name, ComplaintStatus__c, AsyncData__c from Report__c where id = : ReportId];
        //精琢科技  zxk  2021-11-03 根据修理进行的修改   start 
         if (Rep.size() > 0){
              repa = Rep.get(0);
              system.debug('+++++++++++++++++'+repa);
                if ('待EtQ Response'.equals(Rep.get(0).ComplaintStatus__c)) {
                    editFlag = true;
                }
            } 
        //精琢科技  zxk  2021-11-03 根据修理进行的修改   end 
 
        // if (Rep.size() > 0 && '待EtQ Response'.equals(Rep.get(0).ComplaintStatus__c)) {
        //     editFlag = true;
        // }
        paedRecordDetailView = new List < PAE_DecisionRecordDetailInfo > ();
        editAble = false;
        CancelineFlag = 2;
        productIdx = '';
        // PAE_DecisionRecord__c 记录类型 ASRCDecision ASACDecision
        // ASRCDecision --> Intake
        // ASACDecision --> Final
        RecordTypeName = ApexPages.currentPage().getParameters().get('RecordTypeIds');
    }
    public void init() {
        editAble = true;
        //当前登录着的ProfileId
        String profileId = UserInfo.getProfileId().substring(0, 15);
        //118_CFDA(质量法规本部)担当 简档ID和 118_CFDA(质量法规本部)窗口 简档ID和管理员
        if (profileId.equals(System.Label.ProfileId_OCSM_QARA1) || profileId.equals(System.Label.ProfileId_OCSM_QARA2) || UserInfo.getProfileId().equals(System.Label.ProfileId_SystemAdmin)) {
            OCSM_QARA = '1';
        } else {
            OCSM_QARA = '0';
        }
        //ProfileId 2F2B_2F4
        if (System.Label.ProfileId2F2B_2F4.contains(profileId)) {
            OCSM_Cording = '1';
        } else {
            OCSM_Cording = '0';
        }
        if (System.Label.ProfileId2F2B_2F4.contains(profileId) || UserInfo.getProfileId() == System.Label.ProfileId_SystemAdmin) {
            savebuton = true;
        } else {
            savebuton = false;
        }
        if (String.isNotBlank(RecordTypeName)) {
            RecordTypeId = Schema.SObjectType.PAE_DecisionRecord__c.getRecordTypeInfosByDeveloperName().get(RecordTypeName).getRecordTypeId();
        } else {
            List < PAE_DecisionRecord__c > paedRdList = [select Id, PAE_Report__c, RecordTypeId, PAEDetail_DetermineResults__c, RecordType.DeveloperName from PAE_DecisionRecord__c where Id = : Id];
            if (paedRdList.size() > 0) {
                RecordTypeName = paedRdList[0].RecordType.DeveloperName;
                RecordTypeId = paedRdList[0].PAE_Report__c;
            }
        }
        if ('ASRCDecision' == RecordTypeName) {
            ASac_ASrc = 'Intake';
            RecordTypeIdD = Schema.SObjectType.PAE_DecisionRecordDetail__c.getRecordTypeInfosByDeveloperName().get('intake').getRecordTypeId();
        } else if ('ASACDecision' == RecordTypeName) {
            ASac_ASrc = 'Final';
            RecordTypeIdD = Schema.SObjectType.PAE_DecisionRecordDetail__c.getRecordTypeInfosByDeveloperName().get('final').getRecordTypeId();
        }
        rdRecord = new PAE_DecisionRecord__c();
        Report__c repair1OrQIS1;
        if (!string.isBlank(ReportId)) {
            repair1OrQIS1 = [select id, PAE_codez__c, PAE_temp_final_code__c, PAE_reappear_confirm__c from Report__c where id = : ReportId];
        }
        Map < String, PAE_DecisionRecordDetailInfo > MidMap = new Map < String, PAE_DecisionRecordDetailInfo > ();
        if (Id == NULL || Id == '') {
            if (string.isnotBlank(ReportId)) {
                rdRecord.PAE_reappear_confirm__c = repair1OrQIS1.PAE_reappear_confirm__c;
            }
            //预留一行
            PAE_DecisionRecordDetail__c paedrd = new PAE_DecisionRecordDetail__c();
            paedrd.PAED_Status__c = '有效';
            paedrd.RecordTypeId = RecordTypeIdD;
            paedRecordDetailView.add(new PAE_DecisionRecordDetailInfo(paedrd));
            //预留一行
        } else {
            List < PAE_DecisionRecord__c > rdRecordList = new List < PAE_DecisionRecord__c > ();
            List < PAE_DecisionRecordDetail__c > rdRecordDetailList = new List < PAE_DecisionRecordDetail__c > ();
            rdRecordList = [SELECT Id, Name, CurrencyIsoCode, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById,
                SystemModstamp, PAE_DetermineResults__c, PAE_ConfirmationDate__c,
                PAE_Authenticator__c, PAE_reappear_confirm__c,
                PAEDetail_DetermineResults__c, PAE_DetermineResults_Text__c
                FROM PAE_DecisionRecord__c where Id = : Id
            ];
            if (rdRecordList.size() > 0) {
                rdRecord = rdRecordList[0];
            }
            //PAE_reappear_confirm__c  再现结果确认
            if (string.isnotBlank(ReportId)) {
                rdRecord.PAE_reappear_confirm__c = repair1OrQIS1.PAE_reappear_confirm__c;
            }
            rdRecordDetailList = [SELECT Id, IsDeleted, Name, CurrencyIsoCode, CreatedDate, CreatedById,
                LastModifiedDate, LastModifiedById, SystemModstamp, PAE_DecisionRecordD__c,
                PAED_ManagementCode__c, PAE_Judge__c, PAED_Reappear_Result__c, PAED_ResultAffirmant__r.Name,
                PAED_ResultConfirmationDate__c, Final_universal_code__c,
                PAED_Status__c, PAED_ConfirmationDate__c, PAED_Affirmant__c, PAE_is_save__c,
                PAED_Affirmant__r.Name, PAED_RCAC__c, PAED_CancellationDate__c, PAED_Nullifier__c,
                PAED_Nullifier__r.Name, isInterfaceCreate__c, Location__c, LocationGroup__c, FinalUniversalDesc__c,
                Phenomenon__c, IntakeUniversalDesc__c, PhenomenonDesc__c,
                // NFM109信息获取,Gzw add 20200826
                Description__c, Cause__c, EtqPart__c, EtqAsAnalyzed__c, EtqCause__c,
                InspectionCategory109__c, PAED_Affirmant_F__c, PAED_ConfirmationDate_F__c,
                //课题94 add by rentongxiao 2020-10-10 start
                PAED_ResultAffirmant_new__c
                //add by rentx 2020-11-04 
                , isedit__c, RecordTypeId
                // RVS005信息获取 gzw add 20201126 start
                , RVSDetailNo__c, RVS_Date__c, RVS_Time__c, RVS_Decision_Person__c, Monitor_PAE__c
                // RVS005信息获取 gzw add 20201126 end
                FROM PAE_DecisionRecordDetail__c
                where PAE_DecisionRecordD__c = : Id Order by PAED_Status__c, PAED_ManagementCode__c ASC
            ];      
            for (Integer i = 0; i < rdRecordDetailList.size(); i++) {
                MidMap.put(rdRecordDetailList[i].Id, new PAE_DecisionRecordDetailInfo(rdRecordDetailList[i]));
            }
            for (PAE_DecisionRecordDetailInfo paeDrd: MidMap.values()) {
                paedRecordDetailView.add(paeDrd);
            }
        }
    }
    //保存并关闭
    public PageReference SaveAndClose() {
        // 取消行
        if (CancelineFlag == 3) {
            Integer FLG = 0;
            Integer Count = 0;
            for (PAE_DecisionRecordDetailInfo CheckCount: paedRecordDetailView) {
                FLG = FLG + 1;
                if (CheckCount.check == false) {
                    Count = Count + 1;
                }
            }
            if (Count == FLG) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '请选择要取消的行'));
                return null;
            }
        }
        List < PAE_DecisionRecordDetail__c > insertPaeDRDList = new List < PAE_DecisionRecordDetail__c > ();
        Savepoint sp = Database.setSavepoint();
        PAE_DecisionRecord__c paedRecord = new PAE_DecisionRecord__c();
        String paedRecordId = '';
        //明细有效状态此记录的总数量
        //明细有效状态此记录的PAE数量
        //明细有效状态此记录的Unknown数量
        //明细有效状态此记录的NonPAE数量
        Integer PAE_Judge_num = 0;
        Integer PAE_Judge_num_PAE = 0;
        Integer PAE_Judge_num_Unknown = 0;
        Integer PAE_Judge_num_nonPAE = 0;
        String PAE_DetermineResults = null;
        String prevDetermineResults = null;
        // try {
            //明细有效状态此记录的总数量
            //明细有效状态此记录的PAE数量
            //明细有效状态此记录的Unknown数量
            //明细有效状态此记录的NonPAE数量
            //如果Code包含汉字或超过15字数的化,需要提醒。【Intake universal code不可以使用汉字,不可以超过15字数】
            for (PAE_DecisionRecordDetailInfo rdRecorddl: paedRecordDetailView) {
                if (!(rdRecorddl.check && CancelineFlag == 3) && rdRecorddl.paedrdd.PAED_Status__c != '取消') {
                    PAE_Judge_num++;
                    if (rdRecorddl.paedrdd.PAE_Judge__c == 'PAE') {
                        PAE_Judge_num_PAE++;
                    }
                    if (rdRecorddl.paedrdd.PAE_Judge__c == 'Unknown') {
                        PAE_Judge_num_Unknown++;
                    }
                    if (rdRecorddl.paedrdd.PAE_Judge__c == 'nonPAE') {
                        PAE_Judge_num_nonPAE++;
                    }
                    // gzw 20210409 修改参数为空时,表达式判断出错问题
                    if (Schema.SObjectType.PAE_DecisionRecordDetail__c.getRecordTypeInfosByDeveloperName().get('intake').getRecordTypeId() == rdRecorddl.paedrdd.RecordTypeId && (containsChineseCharacters(rdRecorddl.paedrdd.PAED_ManagementCode__c) || (String.isNotBlank(rdRecorddl.paedrdd.PAED_ManagementCode__c) && rdRecorddl.paedrdd.PAED_ManagementCode__c.length() > 15))) {
                        rdRecorddl.paedrdd.PAED_ManagementCode__c.adderror('Intake universal code不可以使用汉字,不可以超过15字数。');
                        return null;
                    }
                }
                System.debug('rdRecorddl.paedrdd.Location__c' + rdRecorddl.paedrdd.Location__c);
            }
            if (PAE_Judge_num_PAE > 0) {
                PAE_DetermineResults = 'PAE';
            } else if (PAE_Judge_num_Unknown > 0) {
                PAE_DetermineResults = 'Unknown';
            } else if (PAE_Judge_num_nonPAE == PAE_Judge_num && PAE_Judge_num_nonPAE > 0) {
                PAE_DetermineResults = 'nonPAE';
            } else {
                PAE_DetermineResults = null;
            }
            rdRecord.PAE_DetermineResults_Text__c = PAE_DetermineResults;
            //System.debug('-----------------------:' + PAE_DetermineResults);
            //新增PAE判定
            if (String.isBlank(Id)) {
                //检查明细的编码是否为空---20200107 add 检查明细的PAE判定是否必填
                if (IsEmptyManagementCode(paedRecordDetailView)) {
                    return null;
                }
                paedRecord.PAE_Report__c = ReportId;
                paedRecord.PAE_reappear_confirm__c = rdRecord.PAE_reappear_confirm__c; // 20200908 Gzw Final 再现结果丢失问题 add
                paedRecord.RecordTypeId = RecordTypeId;
                insert paedRecord;
                paedRecordId = paedRecord.Id;
                UpsertPAE_DecisionRecordDetail(null, paedRecordDetailView, paedRecordId, false, prevDetermineResults);
            } else {
                //修改PAE变更
                List < PAE_DecisionRecord__c > paedRecordList = [select Id, PAE_DetermineResults__c, PAE_DetermineResults_Text__c, PAE_reappear_confirm__c from PAE_DecisionRecord__c where Id = : Id];
                List < PAE_DecisionRecordDetail__c > rdRecordDetailList = new List < PAE_DecisionRecordDetail__c > ();
                //存在的明细Map
                Map < Id, PAE_DecisionRecordDetail__c > paedRecordStatusMap = new Map < Id, PAE_DecisionRecordDetail__c > ();
                rdRecordDetailList = [SELECT Id, IsDeleted, Name, CurrencyIsoCode, CreatedDate, CreatedById,
                    LastModifiedDate, LastModifiedById, SystemModstamp, PAE_DecisionRecordD__c,
                    PAED_ManagementCode__c, PAE_Judge__c, PAED_Reappear_Result__c, PAED_ResultAffirmant__r.Name,
                    PAED_ResultConfirmationDate__c, Final_universal_code__c,
                    PAED_Status__c, PAED_ConfirmationDate__c, PAED_Affirmant__c, PAE_is_save__c,
                    PAED_Affirmant__r.Name, PAED_RCAC__c, PAED_CancellationDate__c, PAED_Nullifier__c,
                    PAED_Nullifier__r.Name, isInterfaceCreate__c, Location__c, LocationGroup__c, FinalUniversalDesc__c,
                    Phenomenon__c, IntakeUniversalDesc__c, PhenomenonDesc__c,
                    // NFM109信息获取,Gzw add 20200826
                    Description__c, Cause__c, EtqPart__c, EtqAsAnalyzed__c, EtqCause__c,
                    InspectionCategory109__c, PAED_Affirmant_F__c, PAED_ConfirmationDate_F__c,
                    //课题94 add by rentongxiao 2020-10-10 start
                    PAED_ResultAffirmant_new__c
                    //add by rentx
                    , isedit__c, RecordTypeId
                    // RVS005信息获取 gzw add 20201126 start
                    , RVSDetailNo__c, RVS_Date__c, RVS_Time__c, RVS_Decision_Person__c, Monitor_PAE__c
                    // RVS005信息获取 gzw add 20201126 end
                    FROM PAE_DecisionRecordDetail__c
                    where PAE_DecisionRecordD__c = : Id Order by PAED_Status__c, PAED_ManagementCode__c
                ];
                if (rdRecordDetailList.size() > 0) {
                    for (PAE_DecisionRecordDetail__c paedrd: rdRecordDetailList) {
                        paedRecordStatusMap.put(paedrd.Id, paedrd);
                    }
                }
                system.debug('paedRecordStatusMap===========>'+paedRecordStatusMap);
                if (paedRecordList.size() > 0) {
                    //PAE判定的Id
                    paedRecordId = paedRecordList[0].Id;
                    //PAE判定记录的状态不变
                    prevDetermineResults = paedRecordList[0].PAE_DetermineResults_Text__c;
                    if (paedRecordList[0].PAE_DetermineResults_Text__c == PAE_DetermineResults) {
                        //检查明细的编码是否为空---20200107 add 检查明细的PAE判定是否必填
                        if (IsEmptyManagementCode(paedRecordDetailView)) {
                            return null;
                        }
                        UpsertPAE_DecisionRecordDetail(paedRecordStatusMap, paedRecordDetailView, paedRecordId, false, prevDetermineResults);
                    } else if (paedRecordList[0].PAE_DetermineResults_Text__c != PAE_DetermineResults) {
                        //PAE判定记录的状态改变
                        //检查明细的编码是否为空---20200107 add 检查明细的PAE判定是否必填
                        if (IsEmptyManagementCode(paedRecordDetailView)) {
                            return null;
                        }
                        insertPaeDRDList = new List < PAE_DecisionRecordDetail__c > ();
                        paedRecord.PAE_DetermineResults_Text__c = PAE_DetermineResults;
                        paedRecord.PAE_Report__c = ReportId;
                        paedRecord.RecordTypeId = RecordTypeId;
                        insert paedRecord;
                        paedRecordId = paedRecord.Id;
                        UpsertPAE_DecisionRecordDetail(paedRecordStatusMap, paedRecordDetailView, paedRecordId, true, prevDetermineResults);
                    }
                }
            }
        // } catch (Exception e) {
        //     ApexPages.addMessages(e);
        //     Database.rollback(sp);
        //     return null;
        // }
        if (CancelineFlag != 2) {
            return RefreshOriginalInterface(paedRecordId);
        } else {
            return ReturnReportInterface();
        }
    }
    //返回报告书页面
    public PageReference ReturnReportInterface() {
        PageReference ref;
        system.debug('啦啦啦ReportId1' + ReportId);
        if (String.isnotBlank(ReportId)) {
            ref = new Pagereference('/' + ReportId);
        }
        //PageReference ref = new Pagereference('/' + ReportId);
        ref.setRedirect(true);
        return ref;
    }
    //留在当前页面
    public PageReference RefreshOriginalInterface(String paedRecordId) {
        PageReference ref;
        if (String.isnotBlank(ReportId)) {
            ref = new Pagereference('/apex/RepPAEDecisionRecord?Id=' + paedRecordId + '&ReportId=' + ReportId + '&RecordTypeIds=' + RecordTypeName);
        }
        ref.setRedirect(true);
        return ref;
    }
    //返回Intake页面
    public PageReference toIntake() {
        String url = null;
        if (String.isnotBlank(ReportId)) {
            List < PAE_DecisionRecord__c > pAE_DecisionRecord = [SELECT LastModifiedDate, Id, Name, LastModifiedById, RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_Report__c = : ReportId And RecordType.DeveloperName = 'ASRCDecision'
                Order by LastModifiedDate desc
            ];
            if (pAE_DecisionRecord.size() > 0) {
                url = '/apex/RepPAEDecisionRecord?Id=' + pAE_DecisionRecord[0].Id + '&ReportId=' + ReportId + '&RecordTypeIds=ASRCDecision';
            } else {
                url = '/apex/RepPAEDecisionRecord?ReportId=' + ReportId + '&RecordTypeIds=ASRCDecision';
            }
        }
        PageReference ref = new Pagereference(url);
        ref.setRedirect(true);
        return ref;
    }
   //插入空行
    public PageReference InsertRow() {
        // 2021-12-08  zxk  精琢科技   手动赋值逻辑  start
        List < String > codeNumDataList = new List < String > ();
        for (PAE_DecisionRecordDetailInfo pdrdInFoCode: paedRecordDetailView) {
            String managementCodeStr = pdrdInFoCode.paedrdd.PAED_ManagementCode__c;
            if (String.isBlank(pdrdInFoCode.paedrdd.id) && String.isNotBlank(managementCodeStr)) {
                codeNumDataList.add(managementCodeStr);
            }
        }
        Map < String, String > strMapData = updateIsPae(codeNumDataList);
        for (PAE_DecisionRecordDetailInfo pdrdInFoCode: paedRecordDetailView) {
            String managementCodeStr = pdrdInFoCode.paedrdd.PAED_ManagementCode__c;
            if (String.isBlank(pdrdInFoCode.paedrdd.Id)) {
                if (String.isNotBlank(managementCodeStr)) {
                    if (pdrdInFoCode.paedrdd.PAE_Judge__c != strMapData.get(managementCodeStr) || String.isBlank(strMapData.get(managementCodeStr))) {
                        pdrdInFoCode.monitorPAE = true;
                    } else {
                        pdrdInFoCode.monitorPAE = false;
                    }
                }
            }
        }
        // 2021-12-08  zxk  精琢科技   手动赋值逻辑  end
        PAE_DecisionRecordDetail__c paedrd = new PAE_DecisionRecordDetail__c();
        paedrd.PAED_Status__c = '有效';
        paedrd.RecordTypeId = RecordTypeIdD;
        // Integer styNum = paedRecordDetailView.size();
        paedRecordDetailView.add(new PAE_DecisionRecordDetailInfo(paedrd));
        return null;
    }
    //批量插入空行字符串
    public void InsertMoreRows() {
        // 精琢科技   zxk  2021-10-21  start  给PAE判定记录赋值
        List < String > codeNumDataList = new List < String > ();
        for (PAE_DecisionRecordDetailInfo pdrdInFoCode: paedRecordDetailView) {
            String managementCodeStr = pdrdInFoCode.paedrdd.PAED_ManagementCode__c;
            if (String.isBlank(pdrdInFoCode.paedrdd.id) && String.isNotBlank(managementCodeStr)) {
                // && pdrdInFoCode.paedrdd.PAE_is_save__c != '1'
                for (String codeStr: managementCodeStr.split(',')) {
                    if (String.isNotBlank(codeStr)) {
                        codeNumDataList.add(codeStr);
                    }
                }
            }
        }
        Map < String, String > strMapData = updateIsPae(codeNumDataList);
        // 精琢科技   zxk  2021-10-21  end  给PAE判定记录赋值
        List < PAE_DecisionRecordDetailInfo > paedRecordDetailViewTemporary = new List < PAE_DecisionRecordDetailInfo > ();
        List < String > codeList = new List < String > ();
        for (PAE_DecisionRecordDetailInfo paedRDInfo: paedRecordDetailView) {
            String managementCode = paedRDInfo.paedrdd.PAED_ManagementCode__c;
            String finalUniversalCode = paedRDInfo.paedrdd.Final_universal_code__c;
            Date confirmationDate = paedRDInfo.paedrdd.PAED_ConfirmationDate__c;
            String pStatus = paedRDInfo.paedrdd.PAED_Status__c;
            PAE_DecisionRecordDetail__c paedrd = new PAE_DecisionRecordDetail__c();
            // 20210719 gzw LJPH-C4Y57Q start
            if (managementCode == '000' && paedRDInfo.paedrdd.PAE_Judge__c == null) {
                paedRDInfo.paedrdd.PAE_Judge__c = 'Unknown';
            }
            // 20210719 gzw LJPH-C4Y57Q end
            if (paedRDInfo.paedrdd.PAED_Status__c != '取消') {
                if (String.isBlank(finalUniversalCode) && confirmationDate == null) {
                    if (String.isNotBlank(managementCode)) {
                        if (managementCode.indexof(',') != -1) {
                            Integer q = 1;
                            for (String code: managementCode.split(',')) {
                                 // 2021-12-08  zxk  精琢科技   手动赋值逻辑  start
                                PAE_DecisionRecordDetailInfo info = new PAE_DecisionRecordDetailInfo();
                                // 2021-12-08  zxk  精琢科技   手动赋值逻辑  end
                                // bug fix gzw 已有的空code数据,数据数据时,会新建  20201214 start
                                PAE_DecisionRecordDetail__c paedrdtemp;
                                if (q == 1) {
                                    paedrdtemp = paedRDInfo.paedrdd;
                                } else {
                                    paedrdtemp = new PAE_DecisionRecordDetail__c();
                                }
                                paedrd = ReproduceResult(paedrdtemp, paedRDInfo); //20200106 add
                                // bug fix gzw 已有的空code数据,数据数据时,会新建  20201214 start
                                paedrd.PAED_Status__c = '有效';
                                paedrd.PAED_ManagementCode__c = code;
                                if (code == '000') {
                                    paedrd.PAE_Judge__c = 'Unknown';
                                }
                                paedrd.RecordTypeId = RecordTypeIdD;
                                paedrd.PAE_is_save__c = '';
                                  // 精琢科技   zxk  2021-10-21  start  给PAE判定记录赋值 
                                if (strMapData.containsKey(code)) {
                                    paedrd.PAE_Judge__c = strMapData.get(code);
                                    info.strJudge = strMapData.get(code);
                                    info.monitorPAE = false;
                                    paedrd.Monitor_PAE__c = false;
                                } else if (managementCode.indexof(code) != -1) {
                                        paedrd.PAE_Judge__c = null;
                                        info.strJudge = paedRDInfo.strJudge;
                                        info.monitorPAE = true;
                                }
                                if (paedrd.PAE_Judge__c == null || paedrd.PAE_Judge__c == '') {
                                    paedrd.Monitor_PAE__c = true;
                                    info.monitorPAE = true;
                                }
                                info.paedrdd = paedrd;
                                paedRecordDetailViewTemporary.add(info);
                                // 精琢科技   zxk  2021-10-21  end  给PAE判定记录赋值
                                q++;
                            }
                        } else {
                             // 2021-12-08  zxk  精琢科技   手动赋值逻辑  start
                            PAE_DecisionRecordDetailInfo info = new PAE_DecisionRecordDetailInfo();
                            // 2021-12-08  zxk  精琢科技   手动赋值逻辑  end
                            // bug fix gzw 已有的空code数据,数据数据时,会新建  20201214 start
                            PAE_DecisionRecordDetail__c paedrdtemp = paedRDInfo.paedrdd;
                            paedrd = ReproduceResult(paedrdtemp, paedRDInfo); //20200106 add
                            // bug fix gzw 已有的空code数据,数据数据时,会新建  20201214 end
                            paedrd.PAED_Status__c = '有效';
                            paedrd.RecordTypeId = RecordTypeIdD;
                            paedrd.PAED_ManagementCode__c = managementCode;
                             // 精琢科技   zxk  2021-10-21  start  给PAE判定记录赋值 
                            if (strMapData.containsKey(managementCode) && productIdx == managementCode) {
                                paedrd.PAE_Judge__c = strMapData.get(managementCode);
                                info.strJudge = strMapData.get(managementCode);
                                info.monitorPAE = false;
                                paedrd.Monitor_PAE__c = false;
                            } else {
                                 info.strJudge = paedRDInfo.strJudge;
                                if (strMapData.get(managementCode) != paedRDInfo.paedrdd.PAE_Judge__c || (paedrd.PAE_Judge__c == null || paedrd.PAE_Judge__c == '')) {
                                   
                                    info.monitorPAE = true;
                                }
                            }
                            if (paedrd.PAE_Judge__c == null || paedrd.PAE_Judge__c == '') {
                                paedrd.Monitor_PAE__c = true;
                                // info.monitorPAE = true;
                            }
                            info.paedrdd = paedrd;
                            paedRecordDetailViewTemporary.add(info);
                            // 精琢科技   zxk  2021-10-21  end  给PAE判定记录赋值 
                        }
                    } else {
                        // Gzw 20201215 编辑页面空白行失去焦点后行消失 对应
                        paedRecordDetailViewTemporary.add(paedRDInfo);
                    }
                } else {
                    paedRecordDetailViewTemporary.add(paedRDInfo);
                }
            } else {
                paedRecordDetailViewTemporary.add(paedRDInfo);
            }
        }
        if (paedRecordDetailViewTemporary != null) {
            paedRecordDetailView = new List < PAE_DecisionRecordDetailInfo > ();
            paedRecordDetailView.addAll(paedRecordDetailViewTemporary);
            if (paedRecordDetailView.size() == 0) {
                PAE_DecisionRecordDetail__c paedrd = new PAE_DecisionRecordDetail__c();
                paedrd.PAED_Status__c = '有效';
                paedrd.RecordTypeId = RecordTypeIdD;
                paedRecordDetailView.add(new PAE_DecisionRecordDetailInfo(paedrd));
            }
        }
    }
    //检查明细的编码是否为空---20200107 add 检查明细的PAE判定是否必填
    public Boolean IsEmptyManagementCode(List < PAE_DecisionRecordDetailInfo > paedRecordDetailView) {
        String isEmpty = '';
        if (paedRecordDetailView.size() == 0) {
            return true;
        }
        // gzw 20201215 取消时不需要判断编码和状态 追加 && CancelineFlag != 3
        for (PAE_DecisionRecordDetailInfo paedRDInfo: paedRecordDetailView) {
            // gzw 20201215 取消时,不判断报错
            if (paedRDInfo.paedrdd.PAED_Status__c == '取消') {
                continue;
            }
            if (paedRDInfo.paedrdd != null) {
                system.debug('paedRDInfo.paedrdd.PAED_ManagementCode__c==========>'+paedRDInfo.paedrdd.PAED_ManagementCode__c);
                system.debug('CancelineFlag=========>'+CancelineFlag);
                system.debug('paedRDInfo.paedrdd.PAE_Judge__c==========>'+paedRDInfo.paedrdd.PAE_Judge__c);
                
                if (String.isBlank(paedRDInfo.paedrdd.PAED_ManagementCode__c) && CancelineFlag != 3) {
                    isEmpty = 'PAE判定记录明细的编码不能为空';
                }
                if (String.isBlank(paedRDInfo.paedrdd.PAE_Judge__c) && CancelineFlag != 3) {
                    isEmpty = 'PAE判定记录明细的PAE判定不能为空';
                }
            } else {
                if (String.isBlank(paedRDInfo.paedrdd.PAED_ManagementCode__c) && CancelineFlag != 3) {
                    isEmpty = 'PAE判定记录明细的编码不能为空';
                }
                if (String.isBlank(paedRDInfo.paedrdd.PAE_Judge__c) && CancelineFlag != 3) {
                    isEmpty = 'PAE判定记录明细的PAE判定不能为空';
                }
            }
            // gzw 20210409 修改参数为空时,表达式判断出错问题
            if (Schema.SObjectType.PAE_DecisionRecordDetail__c.getRecordTypeInfosByDeveloperName().get('intake').getRecordTypeId() == paedRDInfo.paedrdd.RecordTypeId && (containsChineseCharacters(paedRDInfo.paedrdd.PAED_ManagementCode__c) || (String.isNotBlank(paedRDInfo.paedrdd.PAED_ManagementCode__c) && paedRDInfo.paedrdd.PAED_ManagementCode__c.length() > 15))) {
                isEmpty = 'Intake universal code不可以使用汉字,不可以超过15字数。';
                paedRDInfo.paedrdd.PAED_ManagementCode__c.adderror('Intake universal code不可以使用汉字,不可以超过15字数。');
                return true;
            }
        }
        if (String.isNotBlank(isEmpty)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '包含无效数据:' + isEmpty));
            return true;
        }
        return false;
    }
    //更新PAE明细
    public void UpsertPAE_DecisionRecordDetail(Map < Id, PAE_DecisionRecordDetail__c > paedRecordStatusMap, List < PAE_DecisionRecordDetailInfo > paedRecordDetailView, String paedRecordId, Boolean updateStatusFlag, String prevDetermineResults) {
         system.debug('paedRecordStatusMap.size()===============>'+paedRecordStatusMap);
        List < PAE_DecisionRecordDetail__c > upsertPaedrDetailList = new List < PAE_DecisionRecordDetail__c > ();
        String repair_PAED_ManagementCodes = '';
        String repair_PAED_ManagementCodesZ = '';
        String PAE_codez = '';
        String reappear_confirm = null;
        Integer PAED_Reappear_Result_noSelect_num = 0;
        Integer valid_num = 0;
         // 精琢科技   zxk  2021-10-21  start  给PAE判定记录赋值
        List < String > codeNumDataList = new List < String > ();
        for (PAE_DecisionRecordDetailInfo pdrdInFoCode: paedRecordDetailView) {
            String managementCodeStr = pdrdInFoCode.paedrdd.PAED_ManagementCode__c;
            if (String.isBlank(pdrdInFoCode.paedrdd.id) && String.isNotBlank(managementCodeStr)) {
                for (String codeStr: managementCodeStr.split(',')) {
                    if (String.isNotBlank(codeStr)) {
                        codeNumDataList.add(codeStr);
                    }
                }
            }
        }
        Map < String, String > strMapData = updateIsPae(codeNumDataList);
        // 精琢科技   zxk  2021-10-21  end  给PAE判定记录赋值
        System.debug('paedRecordDetailView ++++++++ ' + paedRecordDetailView.size());
        for (PAE_DecisionRecordDetailInfo paedRDInfo: paedRecordDetailView) {
            PAE_DecisionRecordDetail__c paedrd = new PAE_DecisionRecordDetail__c();
            if (paedRDInfo.paedrdd != null) {
                paedrd.PAED_Report__c = ReportId;
                paedrd.PAED_RCAC__c = ASac_ASrc;
                paedrd.PAE_DecisionRecordD__c = paedRecordId;
                paedrd.RecordTypeId = RecordTypeIdD;
                paedrd.PAE_is_save__c = '1'; //20200319 add 
                system.debug('paedRecordStatusMap.containsKey(paedRDInfo.paedrdd.Id)===============>'+paedRDInfo.paedrdd.Id);
               
 
                if (paedRecordStatusMap != null && paedRecordStatusMap.size() > 0 && paedRecordStatusMap.containsKey(paedRDInfo.paedrdd.Id)) {
                    // Gzw add 20200821 PAE结果变化时,保存接口信息字段 start
                    paedrd.isInterfaceCreate__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).isInterfaceCreate__c;
                    paedrd.LocationGroup__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).LocationGroup__c;
                    paedrd.Location__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).Location__c;
                    paedrd.Phenomenon__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).Phenomenon__c;
                    paedrd.Description__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).Description__c;
                    paedrd.Cause__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).Cause__c;
                    paedrd.EtqPart__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).EtqPart__c;
                    paedrd.EtqAsAnalyzed__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).EtqAsAnalyzed__c;
                    paedrd.EtqCause__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).EtqCause__c;
                    paedrd.FinalUniversalDesc__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).FinalUniversalDesc__c;
                    paedrd.InspectionCategory109__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).InspectionCategory109__c;
                    // Gzw add 20200821 PAE结果变化时,保存接口信息字段 end
                    // Gzw add 20200821 PAE结果变化时,保存RVS005接口信息字段 start
                    paedrd.RVSDetailNo__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).RVSDetailNo__c;
                    paedrd.PhenomenonDesc__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PhenomenonDesc__c;
                    paedrd.RVS_Date__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).RVS_Date__c;
                    paedrd.RVS_Time__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).RVS_Time__c;
                    paedrd.RVS_Decision_Person__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).RVS_Decision_Person__c;
                    // Gzw add 20200821 PAE结果变化时,保存RVS005接口信息字段 start
                    paedrd.PAED_Affirmant__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PAED_Affirmant__c;
                    paedrd.PAED_ConfirmationDate__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PAED_ConfirmationDate__c;
                     // 精琢科技  zxk  为Monitor_PAE__c赋值   start
                    paedrd.Monitor_PAE__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).Monitor_PAE__c;
                    // 精琢科技  zxk  为Monitor_PAE__c赋值   end
                    paedrd = ReproduceResult(paedrd, paedRDInfo);
                    if (CancelineFlag == 3 && paedRDInfo.check && paedRDInfo.paedrdd.PAED_Status__c != '取消') {
                        //有效变成取消
                        paedrd.PAED_ManagementCode__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PAED_ManagementCode__c;
                        paedrd.PAED_Status__c = '取消';
                        paedrd.PAED_CancellationDate__c = Date.toDay();
                        paedrd.PAED_Nullifier__c = UserInfo.getUserId();
                    } else if (paedRDInfo.paedrdd.PAED_Status__c == '有效') {
                        //有效PAE明细编码
                        paedrd.PAED_Status__c = '有效';
                        paedrd.PAED_ManagementCode__c = paedRDInfo.paedrdd.PAED_ManagementCode__c;
                        if (String.isBlank(repair_PAED_ManagementCodes)) {
                            repair_PAED_ManagementCodes = paedRDInfo.paedrdd.PAED_ManagementCode__c;
                        } else {
                            repair_PAED_ManagementCodes += ',' + paedRDInfo.paedrdd.PAED_ManagementCode__c;
                        }
                        if (paedRDInfo.paedrdd.PAED_Reappear_Result__c == '不再現' && !paedRDInfo.paedrdd.PAED_ManagementCode__c.equals('000')) {
                            // WLIG-BWMB4S gzw start
                            String pmcode = paedRDInfo.paedrdd.PAED_ManagementCode__c.trim();
                            if (pmcode.length() == 3 && (pmcode.endsWith('V') || pmcode.endsWith('W') || pmcode.endsWith('X') || pmcode.endsWith('Y'))) {
                                PAE_codez = pmcode.substring(0, pmcode.length() - 1) + 'Z';
                            } else {
                                PAE_codez = pmcode + 'Z';
                            }
                            // WLIG-BWMB4S gzw end
                            if (String.isBlank(repair_PAED_ManagementCodesZ)) {
                                repair_PAED_ManagementCodesZ = PAE_codez;
                            } else {
                                repair_PAED_ManagementCodesZ += ',' + PAE_codez;
                            }
                        }
                        valid_num++;
                        if (paedrd.PAED_Reappear_Result__c == null) {
                            PAED_Reappear_Result_noSelect_num++;
                        }
                    } else if (paedRDInfo.paedrdd.PAED_Status__c == '取消') {
                        paedrd.PAED_Status__c = '取消';
                        paedrd.PAED_ManagementCode__c = paedRDInfo.paedrdd.PAED_ManagementCode__c;
                        paedrd.PAED_Nullifier__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PAED_Nullifier__c; //UserInfo.getUserId();
                        paedrd.PAED_CancellationDate__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PAED_CancellationDate__c; //Date.toDay();
                    }
                } else if ((paedRecordStatusMap != null && paedRecordStatusMap.size() > 0 && !paedRecordStatusMap.containsKey(paedRDInfo.paedrdd.Id)) || paedRecordStatusMap == null) {
                    paedrd = ReproduceResult(paedrd, paedRDInfo);
                    if (paedRDInfo.check && CancelineFlag == 3) {
                        //新增取消PAE判定明细
                        paedrd.PAED_CancellationDate__c = Date.toDay();
                        paedrd.PAED_Nullifier__c = UserInfo.getUserId();
                        paedrd.PAED_Status__c = '取消';
                    } else {
                        paedrd.PAED_Affirmant__c = UserInfo.getUserId();
                        paedrd.PAED_ConfirmationDate__c = Date.toDay();
                        paedrd.PAED_Status__c = paedRDInfo.paedrdd.PAED_Status__c;
                        if (String.isBlank(repair_PAED_ManagementCodes)) {
                            repair_PAED_ManagementCodes = paedRDInfo.paedrdd.PAED_ManagementCode__c;
                        } else {
                            repair_PAED_ManagementCodes += ',' + paedRDInfo.paedrdd.PAED_ManagementCode__c;
                        }
                        //20191217 add 
                        if (paedRDInfo.paedrdd.PAED_Reappear_Result__c == '不再現' && !paedRDInfo.paedrdd.PAED_ManagementCode__c.equals('000')) {
                            // WLIG-BWMB4S gzw start
                            String pmcode = paedRDInfo.paedrdd.PAED_ManagementCode__c.trim();
                            if (pmcode.length() == 3 && (pmcode.endsWith('V') || pmcode.endsWith('W') || pmcode.endsWith('X') || pmcode.endsWith('Y'))) {
                                PAE_codez = pmcode.substring(0, pmcode.length() - 1) + 'Z';
                            } else {
                                PAE_codez = pmcode + 'Z';
                            }
                            // WLIG-BWMB4S gzw end
                            if (String.isBlank(repair_PAED_ManagementCodesZ)) {
                                repair_PAED_ManagementCodesZ = PAE_codez;
                            } else {
                                repair_PAED_ManagementCodesZ += ',' + PAE_codez;
                            }
                        }
                        valid_num++;
                        if (paedrd.PAED_Reappear_Result__c == null) {
                            PAED_Reappear_Result_noSelect_num++;
                        }
                    }
                    paedrd.PAED_ManagementCode__c = paedRDInfo.paedrdd.PAED_ManagementCode__c;
                    // 精琢科技   zxk   2021-11-15  为Monitor_PAE__c赋值   start
                    if (String.isBlank(strMapData.get(paedrd.PAED_ManagementCode__c))) {
                        paedrd.Monitor_PAE__c = true;
                    } else {
                        if (strMapData.get(paedrd.PAED_ManagementCode__c) != paedrd.PAE_Judge__c) {
                            paedrd.Monitor_PAE__c = true;
                        }
                    }
                    // 精琢科技   zxk   2021-11-15  为Monitor_PAE__c赋值   end
                    // Gzw add 20200821 PAE结果变化时,保存接口信息字段 start
                    paedrd.isInterfaceCreate__c = paedRDInfo.paedrdd.isInterfaceCreate__c;
                    paedrd.LocationGroup__c = paedRDInfo.paedrdd.LocationGroup__c;
                    paedrd.Location__c = paedRDInfo.paedrdd.Location__c;
                    paedrd.Phenomenon__c = paedRDInfo.paedrdd.Phenomenon__c;
                    paedrd.Description__c = paedRDInfo.paedrdd.Description__c;
                    paedrd.Cause__c = paedRDInfo.paedrdd.Cause__c;
                    // paedrd.PAE_Judge__c = paedRDInfo.paedrdd.PAE_Judge__c;
                    paedrd.EtqPart__c = paedRDInfo.paedrdd.EtqPart__c;
                    paedrd.EtqAsAnalyzed__c = paedRDInfo.paedrdd.EtqAsAnalyzed__c;
                    paedrd.EtqCause__c = paedRDInfo.paedrdd.EtqCause__c;
                    paedrd.FinalUniversalDesc__c = paedRDInfo.paedrdd.FinalUniversalDesc__c;
                    // paedrd.PAED_RCAC__c = paedRDInfo.paedrdd.PAED_RCAC__c;
                    paedrd.InspectionCategory109__c = paedRDInfo.paedrdd.InspectionCategory109__c;
                    // Gzw add 20200821 PAE结果变化时,保存接口信息字段 end
                }
                //20191216 ljh start
                //状态是否改变
                System.debug('+++++++++++++++++++++: ' + updateStatusFlag);
                if (updateStatusFlag) {
                    //改变状态--->复制新的更新需要更新的
                    upsertPaedrDetailList.add(paedrd);
                } else {
                    //更新需要更新的
                    paedrd.Id = paedRDInfo.paedrdd.Id;
                    upsertPaedrDetailList.add(paedrd);
                }
            }
        }
        if (upsertPaedrDetailList.size() > 0) {
            upsert upsertPaedrDetailList;
        }
        System.debug('PAED_Reappear_Result_noSelect_num' + PAED_Reappear_Result_noSelect_num);
        if (PAED_Reappear_Result_noSelect_num > 0) {
            reappear_confirm = '未确认';
        } else if (valid_num > 0 && PAED_Reappear_Result_noSelect_num == 0) {
            reappear_confirm = '已确认';
        }
        AssignValuesOtherObjects(repair_PAED_ManagementCodes, paedRecordId, repair_PAED_ManagementCodesZ, reappear_confirm, prevDetermineResults);
    }
    //为PAE判定和相关的修理赋值
    public void AssignValuesOtherObjects(String stitchingCode, String paedRecordId, String stitchingCodeZ, String reappear_confirm, String prevDetermineResults) {
        if (String.isNotBlank(stitchingCode) && stitchingCode.contains(',')) {
            String[] stitchingCodeArr = stitchingCode.split(',');
            stitchingCodeArr.sort();
            String stitchingCode1 = '';
            for (Integer i = 0; i < stitchingCodeArr.size(); i++) {
                if (i < (stitchingCodeArr.size() - 1)) {
                    stitchingCode1 += stitchingCodeArr[i] + ',';
                } else {
                    stitchingCode1 += stitchingCodeArr[i] + '';
                }
            }
            stitchingCode = stitchingCode1;
        }
        //报告书相关
        if (!string.isBlank(ReportId)) {
            Report__c Report = [select id, PAE_DetermineAC__c, PAE_Determine__c, PAE_codez__c, PAE_temp_final_code__c, PAE_reappear_confirm__c,
                PAE_intakePrevDetermineResults__c, PAE_finalPrevDetermineResults__c, Repair_Authenticator__c, OCSM_RC_CordingUser__c
                from Report__c where id = : ReportId
            ];
            List < PAE_DecisionRecord__c > rdRecordList = [SELECT Id, Name, PAE_DetermineResults__c, PAE_DetermineResults_Text__c, PAE_ConfirmationDate__c,
                PAE_Authenticator__c
                FROM PAE_DecisionRecord__c where Id = : paedRecordId
            ];
            PAE_DecisionRecord__c paedRecord = new PAE_DecisionRecord__c();
            paedRecord.Id = paedRecordId;
            if (ASac_ASrc == 'Intake') {
                paedRecord.PAE_reappear_confirm__c = reappear_confirm;
                Report.PAE_reappear_confirm__c = reappear_confirm;
            } else {
                paedRecord.PAE_reappear_confirm__c = Report.PAE_reappear_confirm__c;
            }
            if (rdRecordList[0].PAE_ConfirmationDate__c == null) {
                paedRecord.Id = paedRecordId;
                paedRecord.PAE_ConfirmationDate__c = Date.toDay();
                paedRecord.PAE_Authenticator__c = UserInfo.getUserId();
            }
            if (paedRecord != null) {
                update paedRecord;
            }
            List < Report__c > repList;
            if (ASac_ASrc == 'Intake') {
                repList = [select Id, Name, RC_PAED__c, AC_PAED__c from Report__c where RC_PAED__c = : paedRecordId];
                if (repList.size() == 0) {
                    if (String.isBlank(Report.Repair_Authenticator__c)) {
                        Report.Repair_ConfirmationDate__c = Date.toDay();
                        Report.Repair_Authenticator__c = UserInfo.getName();
                    }
                    Report.RC_PAED__c = paedRecordId;
                } else {
                    if (String.isBlank(Report.Repair_Authenticator__c)) {
                        Report.Repair_ConfirmationDate__c = rdRecord.PAE_ConfirmationDate__c;
                        Report.Repair_Authenticator__c = rdRecord.PAE_Authenticator__c;
                    }
                    Report.RC_PAED__c = paedRecordId;
                }
            } else {
                repList = [select Id, Name, RC_PAED__c, AC_PAED__c from Report__c where AC_PAED__c = : paedRecordId];
                if (repList.size() == 0) {
                    if (String.isBlank(Report.OCSM_RC_CordingUser__c)) {
                        Report.OCSM_RC_CordingDate__c = Date.toDay();
                        Report.OCSM_RC_CordingUser__c = UserInfo.getName();
                    }
                    Report.AC_PAED__c = paedRecordId;
                } else {
                    if (String.isBlank(Report.OCSM_RC_CordingUser__c)) {
                        Report.OCSM_RC_CordingDate__c = rdRecord.PAE_ConfirmationDate__c;
                        Report.OCSM_RC_CordingUser__c = rdRecord.PAE_Authenticator__c;
                    }
                    Report.AC_PAED__c = paedRecordId;
                }
            }
            if (String.isNotBlank(stitchingCode)) {
                if (ASac_ASrc == 'Intake') {
                    Report.ASReportedCode__c = stitchingCode;
                    // 2020/08/04 taoqz modify
                    Report.PAE_Determine__c = rdRecord.PAE_DetermineResults_Text__c;
                    Report.PAE_intakePrevDetermineResults__c = prevDetermineResults;
                    //如果有不在现 则更新repair.ASReportedCodeAC__c 
                    if (String.isNotBlank(stitchingCodeZ)) {
                        if (String.isNotBlank(Report.PAE_temp_final_code__c)) {
                            Report.ASReportedCodeAC__c = Report.PAE_temp_final_code__c + ',' + stitchingCodeZ;
                        } else {
                            Report.ASReportedCodeAC__c = stitchingCodeZ;
                        }
                        Report.PAE_codez__c = stitchingCodeZ;
                    } else {
                        //202003224 add 如果没有有不在现 则更新repair.ASReportedCodeAC__c
                        Report.ASReportedCodeAC__c = Report.PAE_temp_final_code__c;
                        Report.PAE_codez__c = stitchingCodeZ;
                    }
                } else {
                    if (String.isNotBlank(Report.PAE_codez__c)) {
                        Report.ASReportedCodeAC__c = stitchingCode + ',' + Report.PAE_codez__c;
                    } else {
                        Report.ASReportedCodeAC__c = stitchingCode;
                    }
                    Report.PAE_temp_final_code__c = stitchingCode;
                    // 2020/08/04 taoqz modify
                    Report.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults_Text__c;
                    Report.PAE_finalPrevDetermineResults__c = prevDetermineResults;
                }
            } else {
                if (ASac_ASrc == 'Intake') {
                    Report.ASReportedCode__c = stitchingCode;
                    Report.PAE_codez__c = stitchingCodeZ;
                    Report.ASReportedCodeAC__c = Report.PAE_temp_final_code__c;
                    // 2020/08/04 taoqz modify
                    Report.PAE_Determine__c = rdRecord.PAE_DetermineResults_Text__c;
                    Report.PAE_intakePrevDetermineResults__c = prevDetermineResults;
                } else {
                    Report.ASReportedCodeAC__c = stitchingCode;
                    Report.PAE_temp_final_code__c = stitchingCode;
                    // 2020/08/04 taoqz modify
                    Report.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults_Text__c;
                    Report.PAE_finalPrevDetermineResults__c = prevDetermineResults;
                    Report.OCSM_RC_CordingDate__c = null;
                    Report.OCSM_RC_CordingUser__c = null;
                }
            }
            update Report;
        }
    }
    //20191209 ljh 新字段添加 start
    public static PAE_DecisionRecordDetail__c ReproduceResult(PAE_DecisionRecordDetail__c paedrd, PAE_DecisionRecordDetailInfo paedRDInfo) {
        paedrd.PAE_Judge__c = paedRDInfo.paedrdd.PAE_Judge__c;
        // 20201126 gzw 获取RVS005接口信息数据 start
        paedrd.RVSDetailNo__c = paedRDInfo.paedrdd.RVSDetailNo__c;
        paedrd.LocationGroup__c = paedRDInfo.paedrdd.LocationGroup__c;
        paedrd.Location__c = paedRDInfo.paedrdd.Location__c;
        paedrd.PhenomenonDesc__c = paedRDInfo.paedrdd.PhenomenonDesc__c;
        paedrd.RVS_Date__c = paedRDInfo.paedrdd.RVS_Date__c;
        paedrd.RVS_Time__c = paedRDInfo.paedrdd.RVS_Time__c;
        paedrd.RVS_Decision_Person__c = paedRDInfo.paedrdd.RVS_Decision_Person__c;
        // 20201126 gzw 获取RVS005接口信息数据 end
        if (paedRDInfo.paedrdd.PAED_Reappear_Result__c == '不再現') {
            paedrd.PAED_Reappear_Result__c = '不再現';
            paedrd.PAED_ResultAffirmant__c = UserInfo.getUserId();
            paedrd.PAED_ResultConfirmationDate__c = Date.toDay();
        } else {
            paedrd.PAED_Reappear_Result__c = paedRDInfo.paedrdd.PAED_Reappear_Result__c;
            paedrd.PAED_ResultAffirmant__c = null;
            paedrd.PAED_ResultConfirmationDate__c = null;
        }
        return paedrd;
    }
    // 正则表达式 判断是否包含汉字
    // gzw 20210409 修改参数为空时,表达式判断出错问题
    public static Boolean containsChineseCharacters(String InputString) {
        if (String.isNotblank(InputString)) {
            Pattern p = Pattern.compile('\\p{IsHan}');
            Matcher m = p.matcher(InputString);
            return m.find();
        } else {
            return false;
        }
    }
    // 精琢科技   zxk  2021-10-21  start  给PAE判定记录赋值
    public Map < String, String > updateIsPae(List < String > codeNumDataList) {
        Map < String, String > paeStrMap = new Map < String, String > ();
        String sql = 'select RSS_CODE__C, IS_INTAKE_ESTIMATION__C, IS_PAE__c, IS_INACTIVE__C FROM RSA_master_data__c  WHERE RSS_CODE__C in: codeNumDataList AND IS_INACTIVE__C = \'No\'';
        if ('ASRCDecision' == RecordTypeName) {
            sql += ' AND IS_INTAKE_ESTIMATION__C like \'%Intake%\'';
        }
        if ('ASACDecision' == RecordTypeName) {
            sql += ' AND IS_INTAKE_ESTIMATION__C like \'%Estimation%\'';
        }
        List < RSA_master_data__c > rsaMasterDataSqlList = DataBase.query(sql);
        String result = null;
        for (RSA_master_data__c rsaMaster: rsaMasterDataSqlList) {
            if ('ASRCDecision' == RecordTypeName) {
                if (rsaMaster.IS_PAE__c == 'YES') {
                    result = 'PAE';
                }
                if (rsaMaster.IS_PAE__c == 'No') {
                    result = 'nonPAE';
                }
                if (rsaMaster.IS_PAE__c == 'Unknown') {
                    result = 'Unknown';
                }
            }
            if ('ASACDecision' == RecordTypeName) {
                if (rsaMaster.IS_PAE__c == 'YES') {
                    result = 'PAE';
                }
                if (rsaMaster.IS_PAE__c == 'No') {
                    result = 'nonPAE';
                }
                if (rsaMaster.IS_PAE__c == 'Unknown') {
                    result = 'Unknown';
                }
            }
            paeStrMap.put(rsaMaster.RSS_CODE__C, result);
        }
        return paeStrMap;
    }
    // 精琢科技   zxk  2021-10-21  start  给PAE判定记录赋值
 
    //20191209 ljh 新字段添加 end
    class PAE_DecisionRecordDetailInfo {
         public Boolean check {
            get;
            set;
        }
        public Boolean oldCheck {
            get;
            set;
        }
        public Boolean canSelect {
            get;
            set;
        }
        public String strJudge {
            get;
            set;
        }
        public Boolean monitorPAE {
            get;
            set;
        }
        public PAE_DecisionRecordDetail__c paedrdd {
            get;
            set;
        }
        public PAE_DecisionRecordDetailInfo() {
            paedrdd = new PAE_DecisionRecordDetail__c();
            check = false;
            oldCheck = false;
            canSelect = false;
        }
        public PAE_DecisionRecordDetailInfo(PAE_DecisionRecordDetail__c paedrd) {
            check = false;
            oldCheck = false;
            paedrdd = paedrd;
            if (String.isNotBlank(paedrd.Id)) {
                monitorPAE = paedrd.Monitor_PAE__c;
            }
            strJudge = paedrd.PAE_Judge__c;
            //IISE来的明细允许删除。
            canSelect = false;
        }
    }
}