高章伟
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
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
public with sharing class PAEDecisionRecordController {
    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 String RepairId {
        get;
        set;
    }
    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 或者
    //     QIS_Report__c中ComplaintStatus__c的字段值为待EtQ Response 将标记改为true
    // 影响至对应页面中的按钮是否可用
    public Boolean editFlag {
        get;
        set;
    }
    // 当前修理
    public Repair__c repa {
        get;
        set;
    }
    // 是否是OSH
    public Boolean isOSH {
        get;
        set;
    }
    //20200213
    public String QISReportId {
        get;
        set;
    }
    public String productIdx {
        get;
        set;
    }
    public Boolean updateIsPaeMap {
        get;
        set;
    }
    //页面的明细
    public List < PAE_DecisionRecordDetailInfo > paedRecordDetailView {
        get;
        set;
    }
    public Integer paedRecordDetailViewCount {
        get {
            return paedRecordDetailView == null ? 0 : paedRecordDetailView.size();
        }
    }
    public PAEDecisionRecordController(ApexPages.StandardController stdController) {
        Id = ApexPages.currentPage().getParameters().get('Id');
        RepairId = ApexPages.currentPage().getParameters().get('RepairId');
        // 判断Repair__c的DOJ_Status__c字段值是否为待EtQ Response 
        if (!String.isBlank(RepairId)) {
            List < Repair__c > res = [select id, name, CreatedDate, DOJ_Status__c, PAE_DetermineResults__c, Repair_ConfirmationDate__c,
                Repair_Authenticator__c, Repair_Determine__c, IISE_confirmed_day__c, Repair_Determine_result_ConfirmationUser__c,
                Repair_Determine_result__c, OSH_Affirmant__c, SAP_Transfer_time__c, Status__c, FSE_ApplyForRepair_time__c,
                PAE_reappear_confirm__c, IISE_confirmed_person__c, ifDeadHurt__c, IS_AE__c,
                if_Repair_Allowed__c, NotAllowedReason__c, OSHRAConfirmDate__c, OSHRAConfirmUser__c
                //add by rentx 2020-10-23 start 课题104
                , is_CNBuy__c, ETQ_UPLOAD_ERROR_GROUP__c
                from Repair__c
                where id = : RepairId
            ];
            if (res.size() > 0) {
                repa = res.get(0);
                if ('待EtQ Response'.equals(res.get(0).DOJ_Status__c)) {
                    editFlag = true;
                }
            }
        }
        System.debug('repa++' + repa);
        String profileId = UserInfo.getProfileId();
        // 当前用户是否在 OSH自定义标签中
        isOSH = System.label.OSH.contains(profileId);
        System.debug('isOSH+' + isOSH);
        // 判断QIS_Report__c的ComplaintStatus__c字段值是否为待EtQ Response
        QISReportId = ApexPages.currentPage().getParameters().get('QISReportId'); //20200213 ljh
        List < QIS_Report__c > QIS = [select id, name, ComplaintStatus__c, AsyncData__c from QIS_Report__c where id = : QISReportId];
        if (QIS.size() > 0 && '待EtQ Response'.equals(QIS.get(0).ComplaintStatus__c)) {
            editFlag = true;
        }
        paedRecordDetailView = new List < PAE_DecisionRecordDetailInfo > ();
        editAble = false;
        CancelineFlag = 2;
        // PAE_DecisionRecord__c 记录类型 ASRCDecision ASACDecision
        // ASRCDecision --> Intake
        // ASACDecision --> Final
        RecordTypeName = ApexPages.currentPage().getParameters().get('RecordTypeIds');
        productIdx = '';
        updateIsPaeMap = false;
    }
    public void init() {
        editAble = true;
        //当前登录着的ProfileId
        String profileId = UserInfo.getProfileId().substring(0, 15);
        //20200310  add start 
        //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)) {
            //if(UserInfo.getProfileId().substring(0,15).equals(System.Label.ProfileId_2F2CRCCording)|| UserInfo.getProfileId().equals(System.Label.ProfileId_SystemAdmin)){
            OCSM_Cording = '1';
        } else {
            OCSM_Cording = '0';
        }
        if (System.Label.ProfileId2F2B_2F4.contains(profileId) || UserInfo.getProfileId() == System.Label.ProfileId_SystemAdmin) {
            //if(UserInfo.getProfileId().substring(0,15).equals(System.Label.ProfileId_2F2CRCCording)|| UserInfo.getProfileId().equals(System.Label.ProfileId_SystemAdmin)){
            savebuton = true;
        } else {
            savebuton = false;
        }
        //20200310  add end 
        if (String.isNotBlank(RecordTypeName)) {
            RecordTypeId = Schema.SObjectType.PAE_DecisionRecord__c.getRecordTypeInfosByDeveloperName().get(RecordTypeName).getRecordTypeId();
        } else {
            List < PAE_DecisionRecord__c > paedRdList = [select Id, PAE_Repair__c, PAE_QIS__c, RecordTypeId, PAEDetail_DetermineResults__c, RecordType.DeveloperName from PAE_DecisionRecord__c where Id = : Id];
            if (paedRdList.size() > 0) {
                RecordTypeName = paedRdList[0].RecordType.DeveloperName;
                RepairId = paedRdList[0].PAE_Repair__c;
                //20100213 ljh add start 
                QISReportId = paedRdList[0].PAE_QIS__c;
                //20100213 ljh add end
                RecordTypeId = paedRdList[0].RecordTypeId;
            }
        }
        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();
        //20200213 ljh start
        //Repair__c  repair1 =[select id,PAE_codez__c,PAE_temp_final_code__c ,PAE_reappear_confirm__c from Repair__c where id = :RepairId];
        Repair__c repair1OrQIS1;
        QIS_Report__c repair1OrQIS2;
        if (!string.isBlank(RepairId)) {
            repair1OrQIS1 = [select id, PAE_codez__c, PAE_temp_final_code__c, PAE_reappear_confirm__c, IISE_confirmed_person__c from Repair__c where id = : RepairId];
        }
        if (!string.isBlank(QISReportId)) {
            repair1OrQIS2 = [select id, PAE_codez__c, PAE_temp_final_code__c, PAE_reappear_confirm__c from QIS_Report__c where id = : QISReportId];
        }
        //20200213 ljh end
        Map < String, PAE_DecisionRecordDetailInfo > MidMap = new Map < String, PAE_DecisionRecordDetailInfo > ();
        if (Id == NULL || Id == '') {
            //20200213 ljh start
            //rdRecord.PAE_reappear_confirm__c = repair1.PAE_reappear_confirm__c;//20200103 add
            if (string.isBlank(RepairId)) {
                rdRecord.PAE_reappear_confirm__c = repair1OrQIS2.PAE_reappear_confirm__c;
            } else {
                rdRecord.PAE_reappear_confirm__c = repair1OrQIS1.PAE_reappear_confirm__c;
            }
            //20200213 ljh end
            //20200106 预留一行 add start 
            PAE_DecisionRecordDetail__c paedrd = new PAE_DecisionRecordDetail__c();
            paedrd.PAED_Status__c = '有效';
            paedrd.RecordTypeId = RecordTypeIdD;
            paedRecordDetailView.add(new PAE_DecisionRecordDetailInfo(paedrd));
            //20200106 预留一行 add end
        } 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];
            }
            //20200213 ljh start
            //rdRecord.PAE_reappear_confirm__c = repair1.PAE_reappear_confirm__c;//20200103 add
            if (string.isBlank(RepairId)) {
                rdRecord.PAE_reappear_confirm__c = repair1OrQIS2.PAE_reappear_confirm__c; //20200103 add
            } else {
                rdRecord.PAE_reappear_confirm__c = repair1OrQIS1.PAE_reappear_confirm__c; //20200103 add
            }
            //20200213 ljh end
            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
            ];
            // Integer strNum = 0;
            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);
            }
        }
        // 2020/08/04 taoqz add start
        // if(String.isNotBlank(RepairId)){
        //     List<PAE_DecisionRecord__c> lastModifiedRecord = [select id,name,PAEDetail_reappear_confirm__c from PAE_DecisionRecord__c 
        //                                                     where PAE_Repair__c = :RepairId
        //                                                     and RecordType.DeveloperName = 'ASRCDecision' 
        //                                                     order by LastModifiedDate desc limit 1];
        //     if (lastModifiedRecord != null && lastModifiedRecord.size() > 0) {
        //         intakePAEReappearConfirm = lastModifiedRecord.get(0).PAEDetail_reappear_confirm__c;
        //     }                                                
        // }
        // if (String.isBlank(intakePAEReappearConfirm)) {
        //     intakePAEReappearConfirm = '';
        // }else{
        //     rdRecord.PAE_reappear_confirm__c = intakePAEReappearConfirm;
        // }
        // 2020/08/04 taoqz add end
    }
    //保存并关闭
    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 {
            //20191217 add start
            //明细有效状态此记录的总数量
            //明细有效状态此记录的PAE数量
            //明细有效状态此记录的Unknown数量
            //明细有效状态此记录的NonPAE数量
            // 20201204 如果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;
            }
            // 2020/08/04 taoqz modify
            // rdRecord.PAE_DetermineResults__c = PAE_DetermineResults;
            rdRecord.PAE_DetermineResults_Text__c = PAE_DetermineResults;
            //20191217 add end
            //新增PAE判定
            if (String.isBlank(Id)) {
                //检查明细的编码是否为空---20200107 add 检查明细的PAE判定是否必填
                if (IsEmptyManagementCode(paedRecordDetailView)) {
                    return null;
                }
                //paedRecord.PAE_DetermineResults__c = rdRecord.PAE_DetermineResults__c;
                // paedRecord.PAE_DetermineResults__c = PAE_DetermineResults;//202191216 modify
                //update by rentongxiao 2020-09-22 start
                // paedRecord.PAE_DetermineResults_Text__c = PAE_DetermineResults;//2020/08/04 modify
                //update by rentongxiao 2020-09-22 end
                paedRecord.PAE_Repair__c = RepairId;
                paedRecord.PAE_QIS__c = QISReportId; //20200213 ljh add
                paedRecord.PAE_reappear_confirm__c = rdRecord.PAE_reappear_confirm__c; // 20200908 Gzw Final 再现结果丢失问题 add
                paedRecord.RecordTypeId = RecordTypeId;
                insert paedRecord;
                // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'paedRecord ------ ' + paedRecord.PAE_reappear_confirm__c));
                // if (true) {
                //     return null;
                // }
                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);
                    }
                }
                if (paedRecordList.size() > 0) {
                    //PAE判定的Id
                    paedRecordId = paedRecordList[0].Id;
                    //PAE判定记录的状态不变
                    // prevDetermineResults = paedRecordList[0].PAE_DetermineResults__c;//20200107 add
                    prevDetermineResults = paedRecordList[0].PAE_DetermineResults_Text__c; //2020/08/04 modify
                    //if (paedRecordList[0].PAE_DetermineResults__c == rdRecord.PAE_DetermineResults__c) {
                    //2020/08/04 modify
                    // if (paedRecordList[0].PAE_DetermineResults__c == PAE_DetermineResults) {
                    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__c != rdRecord.PAE_DetermineResults__c ) {
                        //2020/08/04 modify
                        // } else if (paedRecordList[0].PAE_DetermineResults__c != PAE_DetermineResults ) {
                    } 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__c = rdRecord.PAE_DetermineResults__c;
                        //2020/08/04 modify
                        // paedRecord.PAE_DetermineResults__c = PAE_DetermineResults;//20191216 modify
                        paedRecord.PAE_DetermineResults_Text__c = PAE_DetermineResults; //20191216 modify
                        paedRecord.PAE_Repair__c = RepairId;
                        paedRecord.PAE_QIS__c = QISReportId; //20200213 ljh add
                        paedRecord.RecordTypeId = RecordTypeId;
                        insert paedRecord;
                        paedRecordId = paedRecord.Id;
                        UpsertPAE_DecisionRecordDetail(paedRecordStatusMap, paedRecordDetailView, paedRecordId, true, prevDetermineResults);
                    }
                }
            }
            // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'paedRecord ------ ' + paedRecord.PAE_reappear_confirm__c));
        } catch (Exception e) {
            ApexPages.addMessages(e);
            Database.rollback(sp);
            return null;
        }
        // return null;
        if (CancelineFlag != 2) {
            return RefreshOriginalInterface(paedRecordId);
        } else {
            return ReturnRepairInterface();
        }
    }
    //返回修理/QIS页面
    public PageReference ReturnRepairInterface() {
        //20200213 ljh start
        PageReference ref;
        if (String.isBlank(RepairId)) {
            ref = new Pagereference('/' + QISReportId);
        } else {
            ref = new Pagereference('/' + RepairId);
        }
        //PageReference ref = new Pagereference('/' + RepairId);
        //20200213 ljh end
        ref.setRedirect(true);
        return ref;
    }
    //留在当前页面
    public PageReference RefreshOriginalInterface(String paedRecordId) {
        //20200213 ljh start
        //PageReference ref = new Pagereference('/apex/PAEDecisionRecord?Id=' + paedRecordId + '&RepairId=' + RepairId);
        PageReference ref;
        if (String.isBlank(RepairId)) {
            ref = new Pagereference('/apex/PAEDecisionRecord?Id=' + paedRecordId + '&QISReportId=' + QISReportId + '&RecordTypeIds=' + RecordTypeName);
        } else {
            ref = new Pagereference('/apex/PAEDecisionRecord?Id=' + paedRecordId + '&RepairId=' + RepairId + '&RecordTypeIds=' + RecordTypeName);
        }
        ref.setRedirect(true);
        return ref;
    }
    //20200107 add 
    //返回修理Intake页面
    public PageReference toIntake() {
        String url = null;
        if (String.isBlank(RepairId)) {
            List < PAE_DecisionRecord__c > pAE_DecisionRecord = [SELECT LastModifiedDate, Id, Name, LastModifiedById, RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_QIS__c = : QISReportId And RecordType.DeveloperName = 'ASRCDecision'
                Order by LastModifiedDate desc
            ];
            if (pAE_DecisionRecord.size() > 0) {
                url = '/apex/PAEDecisionRecord?Id=' + pAE_DecisionRecord[0].Id + '&QISReportId=' + QISReportId + '&RecordTypeIds=ASRCDecision';
            } else {
                url = '/apex/PAEDecisionRecord?QISReportId=' + QISReportId + '&RecordTypeIds=ASRCDecision';
            }
        } else {
            List < PAE_DecisionRecord__c > pAE_DecisionRecord = [SELECT LastModifiedDate, Id, Name, LastModifiedById, RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_Repair__c = : RepairId And RecordType.DeveloperName = 'ASRCDecision'
                Order by LastModifiedDate desc
            ];
            if (pAE_DecisionRecord.size() > 0) {
                url = '/apex/PAEDecisionRecord?Id=' + pAE_DecisionRecord[0].Id + '&RepairId=' + RepairId + '&RecordTypeIds=ASRCDecision';
            } else {
                url = '/apex/PAEDecisionRecord?RepairId=' + RepairId + '&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 > ();
        // Integer strNum = paedRecordDetailView.size() - 1;
        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();
            /*if(pStatus=='有效' &&confirmationDate != null){
                codeList.add(managementCode);
            }*/
            // 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
                                //if(!codeList.contains(code)){
                                // bug fix gzw 已有的空code数据,数据数据时,会新建  20201214 start
                                PAE_DecisionRecordDetail__c paedrdtemp;
                                if (q == 1) {
                                    paedrdtemp = paedRDInfo.paedrdd;
                                } else {
                                    paedrdtemp = new PAE_DecisionRecordDetail__c();
                                }
                                // PAE_DecisionRecordDetail__c 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判定记录赋值
                                //codeList.add(code);
                                // paedRecordDetailViewTemporary.add(new PAE_DecisionRecordDetailInfo(paedrd));
                                /*}else{
                                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '包含无效数据:' +code+'已经存在'));
                                }*/
                                q++;
                            }
                        } else {
                            // 2021-12-08  zxk  精琢科技   手动赋值逻辑  start
                            PAE_DecisionRecordDetailInfo info = new PAE_DecisionRecordDetailInfo();
                            // 2021-12-08  zxk  精琢科技   手动赋值逻辑  end
                            //if(!codeList.contains(managementCode)){
                            // bug fix gzw 已有的空code数据,数据数据时,会新建  20201214 start
                            // PAE_DecisionRecordDetail__c paedrd = new PAE_DecisionRecordDetail__c();  
                            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判定记录赋值 
                            //codeList.add(managementCode);
                            // paedRecordDetailViewTemporary.add(new PAE_DecisionRecordDetailInfo(paedrd, strNum++));
                            /*}else{
                                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '包含无效数据:' + managementCode+'已经存在'));
                            }*/
                        }
                    } 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);
            //20200106 add start
            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));
            }
            //20200106 add end
        }
    }
    //检查编码是否为空
    /*public Boolean IsEmptyManagementCode ( List<PAE_DecisionRecordDetailInfo> paedRecordDetailView ) {
        String managementCodeIsEmpty = '';
        if(paedRecordDetailView.size()==0){
            return true;
        }
 
        for (PAE_DecisionRecordDetailInfo paedRDInfo : paedRecordDetailView) {
            if (paedRDInfo.paedrdd != null) {
                if (String.isBlank(paedRDInfo.paedrdd.PAED_ManagementCode__c)) {
                    managementCodeIsEmpty = 'PAE判定记录明细的编码为空';
                }
            } else {
                if (String.isBlank(paedRDInfo.paedrdd.PAED_ManagementCode__c)) {
                    managementCodeIsEmpty = 'PAE判定记录明细的编码为空';
                }
            }
        }
        if (String.isNotBlank(managementCodeIsEmpty)) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, '包含无效数据:' + managementCodeIsEmpty));
            return true;
        }
        return false;
 
    }*/
    //检查明细的编码是否为空---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) {
                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;
    }
    //
    public void UpsertPAE_DecisionRecordDetail(Map < Id, PAE_DecisionRecordDetail__c > paedRecordStatusMap, List < PAE_DecisionRecordDetailInfo > paedRecordDetailView, String paedRecordId, Boolean updateStatusFlag, String prevDetermineResults) {
        List < PAE_DecisionRecordDetail__c > upsertPaedrDetailList = new List < PAE_DecisionRecordDetail__c > ();
        String repair_PAED_ManagementCodes = '';
        String repair_PAED_ManagementCodesZ = ''; //20191217 add
        String PAE_codez = ''; //20191217 add
        String reappear_confirm = null;
        Integer PAED_Reappear_Result_noSelect_num = 0; //20200103 add
        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_Repair__c = RepairId;
                paedrd.PAED_QIS__c = QISReportId; //20200213 ljh add
                paedrd.PAED_RCAC__c = ASac_ASrc;
                paedrd.PAE_DecisionRecordD__c = paedRecordId;
                paedrd.RecordTypeId = RecordTypeIdD;
                paedrd.PAE_is_save__c = '1'; //20200319 add 
                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.PAE_Judge__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PAE_Judge__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.PAED_RCAC__c = paedRecordStatusMap.get(paedRDInfo.paedrdd.Id).PAED_RCAC__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();
                        //upsertPaedrDetailList.add(paedrd);//20191210  modify
                    } 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;
                        }
                        //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';
                            }
                            // PAE_codez = paedRDInfo.paedrdd.PAED_ManagementCode__c+'Z';
                            // WLIG-BWMB4S gzw end
                            if (String.isBlank(repair_PAED_ManagementCodesZ)) {
                                repair_PAED_ManagementCodesZ = PAE_codez;
                            } else {
                                repair_PAED_ManagementCodesZ += ',' + PAE_codez;
                            }
                        }
                        //20200103 add start 
                        valid_num++;
                        if (paedrd.PAED_Reappear_Result__c == null) {
                            PAED_Reappear_Result_noSelect_num++;
                        }
                        //20200103 add end 
                    } 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';
                            }
                            // PAE_codez = paedRDInfo.paedrdd.PAED_ManagementCode__c+'Z';
                            // WLIG-BWMB4S gzw end
                            if (String.isBlank(repair_PAED_ManagementCodesZ)) {
                                repair_PAED_ManagementCodesZ = PAE_codez;
                            } else {
                                repair_PAED_ManagementCodesZ += ',' + PAE_codez;
                            }
                        }
                        //20200103 add start 
                        valid_num++;
                        if (paedrd.PAED_Reappear_Result__c == null) {
                            PAED_Reappear_Result_noSelect_num++;
                        }
                        //20200103 add end
                    }
                    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) {
        //PAE_DecisionRecord__c paedRecord = new PAE_DecisionRecord__c();
        //20200319 add start
        // if(stitchingCode.contains(',')&& String.isNotBlank(stitchingCode)){
        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;
        }
        //20200319 add end
        if (!string.isBlank(RepairId)) {
            //修理相关
            //Repair__c  repair = new Repair__c();
            Repair__c repair = [select id, PAE_codez__c, PAE_temp_final_code__c, PAE_reappear_confirm__c, PAE_intakePrevDetermineResults__c,
                PAE_finalPrevDetermineResults__c, IISE_confirmed_person__c, Repair_Authenticator__c, OCSM_RC_CordingUser__c, PAE_DetermineAC__c, ETQ_UPLOAD_STATUS__c
                from Repair__c where id = : RepairId
            ];
            // repair.Id = RepairId;
            List < PAE_DecisionRecord__c > rdRecordList = [SELECT Id, Name, PAE_DetermineResults__c, PAE_DetermineResults_Text__c, PAE_ConfirmationDate__c,
                PAE_Authenticator__c, PAE_reappear_confirm__c
                FROM PAE_DecisionRecord__c where Id = : paedRecordId
            ];
            // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,  'reappear_confirm++++++ ' + reappear_confirm));
            // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,  'repair++++++ ' + repair.PAE_reappear_confirm__c));
            // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,  'PAE_reappear++++++ ' + rdRecordList[0].PAE_reappear_confirm__c));
            // if (true) {
            //     return;
            // }
            PAE_DecisionRecord__c paedRecord = new PAE_DecisionRecord__c();
            paedRecord.Id = paedRecordId;
            if (ASac_ASrc == 'Intake') {
                paedRecord.PAE_reappear_confirm__c = reappear_confirm;
                //add by rentx 2020-11-20 start doj34
                //update by rentx 2020-11-30
                //final判定后,ETQ同步失败,并且用户输入的为空 再现确认结果要清空
                // 20210512 gzw update reappear_confirm 空指针的情况对应
                if (String.isBlank(reappear_confirm)) {
                    if (repair.PAE_reappear_confirm__c == '已确认') {
                        reappear_confirm = '已确认';
                    } else {
                        reappear_confirm = '未确认';
                    }
                }
                if (repair.PAE_DetermineAC__c != null && repair.ETQ_UPLOAD_STATUS__c != '4' && reappear_confirm.equals('未确认')) {
                    repair.PAE_reappear_confirm__c = '';
                } else {
                    repair.PAE_reappear_confirm__c = reappear_confirm;
                }
                //add by rentx 2020-11-20 end
                // 2020/08/05 taoqz add start
                // 进行修理的判定结果
                // 进行修理的判定结果确认者
                // 进行修理的判定结果确认日
                // Gzw add
                // 有进行修理的判定结果时,记录记录进行修理的判定结果确认者
                if (String.isNotBlank(repa.Repair_Determine_result__c) && (repa.IS_AE__c == 'YES' && isOSH)) {
                    repair.Repair_Determine_result__c = repa.Repair_Determine_result__c;
                    repair.Repair_Determine_result_ConfirmationUser__c = UserInfo.getUserId();
                    repair.Repair_Determine_result_ConfirmationDate__c = Date.toDay();
                }
                // 是否可进行修理的判定时,记录OSH RA 确认者 和确认时间
                if (String.isNotBlank(repa.if_Repair_Allowed__c) && isOSH) {
                    repair.if_Repair_Allowed__c = repa.if_Repair_Allowed__c;
                    repair.NotAllowedReason__c = repa.NotAllowedReason__c;
                    repair.OSHRAConfirmUser__c = UserInfo.getUserId();
                    repair.OSHRAConfirmDate__c = Date.toDay();
                }
                // 2020/08/05 taoqz add end
            } else {
                paedRecord.PAE_reappear_confirm__c = repair.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;
            }
            //20191218 modify start 
            List < Repair__c > repairList;
            if (ASac_ASrc == 'Intake') {
                repairList = [select Id, Name, RC_PAED__c, AC_PAED__c, PAE_reappear_confirm__c, IISE_confirmed_person__c from Repair__c where RC_PAED__c = : paedRecordId];
                if (repairList.size() == 0) {
                    // 20201103 gzw 已经有Final  再现结果确认 时,Repair_Authenticator__c存在不更新 start
                    if (String.isBlank(repair.Repair_Authenticator__c)) {
                        repair.Repair_ConfirmationDate__c = Date.toDay();
                        repair.Repair_Authenticator__c = UserInfo.getUserId();
                    }
                    // 20201103 gzw 已经有Final  再现结果确认 时,Repair_Authenticator__c存在不更新 end
                    repair.RC_PAED__c = paedRecordId;
                } else {
                    //20191218 add
                    // 20201102 gzw 已经有Final  再现结果确认 时,Repair_Authenticator__c存在不更新 start
                    if (String.isBlank(repair.Repair_Authenticator__c)) {
                        repair.Repair_ConfirmationDate__c = rdRecord.PAE_ConfirmationDate__c;
                        repair.Repair_Authenticator__c = rdRecord.PAE_Authenticator__c;
                    }
                    // 20201102 gzw 已经有Final  再现结果确认 时,Repair_Authenticator__c存在不更新 end
                    repair.RC_PAED__c = paedRecordId;
                    //20191218 end
                }
            } else {
                repairList = [select Id, Name, RC_PAED__c, AC_PAED__c, PAE_reappear_confirm__c, IISE_confirmed_person__c from Repair__c where AC_PAED__c = : paedRecordId];
                if (repairList.size() == 0) {
                    if (String.isBlank(repair.OCSM_RC_CordingUser__c)) {
                        repair.OCSM_RC_CordingDate__c = Date.toDay();
                        repair.OCSM_RC_CordingUser__c = UserInfo.getUserId();
                    }
                    repair.AC_PAED__c = paedRecordId;
                } else {
                    //20191218 add
                    if (String.isBlank(repair.OCSM_RC_CordingUser__c)) {
                        repair.OCSM_RC_CordingDate__c = rdRecord.PAE_ConfirmationDate__c;
                        repair.OCSM_RC_CordingUser__c = rdRecord.PAE_Authenticator__c;
                    }
                    repair.AC_PAED__c = paedRecordId;
                    //20191218 end
                }
            }
            //20191218 modify end
            if (String.isNotBlank(stitchingCode)) {
                if (ASac_ASrc == 'Intake') {
                    repair.ASReportedCode__c = stitchingCode;
                    // 2020/08/04 taoqz modify
                    // repair.PAE_Determine__c = rdRecord.PAE_DetermineResults__c;
                    repair.PAE_Determine__c = rdRecord.PAE_DetermineResults_Text__c;
                    repair.PAE_intakePrevDetermineResults__c = prevDetermineResults; //20200107 add
                    //20191217 add
                    //如果有不在现 则更新repair.ASReportedCodeAC__c 
                    if (String.isNotBlank(stitchingCodeZ)) {
                        //20191217 modify start
                        if (String.isNotBlank(repair.PAE_temp_final_code__c)) {
                            repair.ASReportedCodeAC__c = repair.PAE_temp_final_code__c + ',' + stitchingCodeZ;
                        } else {
                            repair.ASReportedCodeAC__c = stitchingCodeZ;
                        }
                        repair.PAE_codez__c = stitchingCodeZ;
                    } else {
                        //202003224 add 如果没有有不在现 则更新repair.ASReportedCodeAC__c
                        repair.ASReportedCodeAC__c = repair.PAE_temp_final_code__c;
                        repair.PAE_codez__c = stitchingCodeZ;
                    }
                    //20191217 modify end                  
                } else {
                    //20191217  modify start
                    //repair.ASReportedCodeAC__c = stitchingCode;//20191217  modify
                    if (String.isNotBlank(repair.PAE_codez__c)) {
                        repair.ASReportedCodeAC__c = stitchingCode + ',' + repair.PAE_codez__c;
                    } else {
                        repair.ASReportedCodeAC__c = stitchingCode;
                    }
                    repair.PAE_temp_final_code__c = stitchingCode;
                    //20191217 modify end
                    // 2020/08/04 taoqz modify
                    // repair.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults__c;
                    repair.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults_Text__c;
                    repair.PAE_finalPrevDetermineResults__c = prevDetermineResults; //20200107 add
                }
            } else {
                if (ASac_ASrc == 'Intake') {
                    repair.ASReportedCode__c = stitchingCode;
                    repair.PAE_codez__c = stitchingCodeZ; //20191218 add
                    repair.ASReportedCodeAC__c = repair.PAE_temp_final_code__c; //20191218 add
                    // 2020/08/04 taoqz modify
                    // repair.PAE_Determine__c = rdRecord.PAE_DetermineResults__c; //20191218 add 
                    repair.PAE_Determine__c = rdRecord.PAE_DetermineResults_Text__c; //20191218 add 
                    repair.PAE_intakePrevDetermineResults__c = prevDetermineResults; //20200107 add  
                    repair.Repair_ConfirmationDate__c = null; //20200416
                    repair.Repair_Authenticator__c = null; //20200416
                } else {
                    repair.ASReportedCodeAC__c = stitchingCode;
                    repair.PAE_temp_final_code__c = stitchingCode; //20191218 add
                    // 2020/08/04 taoqz modify
                    // repair.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults__c;//20191218 add
                    repair.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults_Text__c; //20191218 add
                    repair.PAE_finalPrevDetermineResults__c = prevDetermineResults; //20200107 add
                    repair.OCSM_RC_CordingDate__c = null; //20200416
                    repair.OCSM_RC_CordingUser__c = null; //20200416
                }
            }
            update repair;
        } else {
            //QIS相关
            QIS_Report__c qisReport = [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, QIS_Authenticator__c, OCSM_RC_CordingUser__c
                from QIS_Report__c where id = : QISReportId
            ];
            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;
                qisReport.PAE_reappear_confirm__c = reappear_confirm;
            } else {
                paedRecord.PAE_reappear_confirm__c = qisReport.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();
            }
            /*else{
                if(String.isNotBlank(prevDetermineResults)&&String.isNotBlank(rdRecord.PAE_DetermineResults__c)){
                    if(prevDetermineResults.equals(rdRecord.PAE_DetermineResults__c)){
                        //最新一条数据的确认日和确认者
                        List<PAE_DecisionRecordDetail__c> DetailList = [SELECT Id, Name,PAED_Status__c, PAED_ConfirmationDate__c,PAED_Affirmant__c,PAED_CancellationDate__c, PAED_Nullifier__c
                                                                            FROM PAE_DecisionRecordDetail__c  WHERE PAE_DecisionRecordD__c = :paedRecordId  Order by PAED_ConfirmationDate__c desc  ];
                        paedRecord.Id = paedRecordId;
                        paedRecord.PAE_ConfirmationDate__c = DetailList[0].PAED_ConfirmationDate__c !=NULL?DetailList[0].PAED_ConfirmationDate__c: Date.toDay();
                        paedRecord.PAE_Authenticator__c = String.isNotBlank(DetailList[0].PAED_Affirmant__c)?DetailList[0].PAED_Affirmant__c:UserInfo.getUserId();
                    }
                }    
            }*/
            if (paedRecord != null) {
                update paedRecord;
            }
            //20191218 modify start 
            List < QIS_Report__c > qisList;
            if (ASac_ASrc == 'Intake') {
                qisList = [select Id, Name, RC_PAED__c, AC_PAED__c from QIS_Report__c where RC_PAED__c = : paedRecordId];
                if (qisList.size() == 0) {
                    if (String.isBlank(qisReport.QIS_Authenticator__c)) {
                        qisReport.QIS_ConfirmationDate__c = Date.toDay();
                        qisReport.QIS_Authenticator__c = UserInfo.getUserId();
                    }
                    qisReport.RC_PAED__c = paedRecordId;
                } else {
                    //20191218 add
                    if (String.isBlank(qisReport.QIS_Authenticator__c)) {
                        qisReport.QIS_ConfirmationDate__c = rdRecord.PAE_ConfirmationDate__c;
                        qisReport.QIS_Authenticator__c = rdRecord.PAE_Authenticator__c;
                    }
                    qisReport.RC_PAED__c = paedRecordId;
                    //20191218 end
                }
            } else {
                qisList = [select Id, Name, RC_PAED__c, AC_PAED__c from QIS_Report__c where AC_PAED__c = : paedRecordId];
                if (qisList.size() == 0) {
                    if (String.isBlank(qisReport.OCSM_RC_CordingUser__c)) {
                        qisReport.OCSM_RC_CordingDate__c = Date.toDay();
                        qisReport.OCSM_RC_CordingUser__c = UserInfo.getUserId();
                    }
                    qisReport.AC_PAED__c = paedRecordId;
                } else {
                    //20191218 add
                    if (String.isBlank(qisReport.OCSM_RC_CordingUser__c)) {
                        qisReport.OCSM_RC_CordingDate__c = rdRecord.PAE_ConfirmationDate__c;
                        qisReport.OCSM_RC_CordingUser__c = rdRecord.PAE_Authenticator__c;
                    }
                    qisReport.AC_PAED__c = paedRecordId;
                    //20191218 end
                }
            }
            //20191218 modify end
            if (String.isNotBlank(stitchingCode)) {
                if (ASac_ASrc == 'Intake') {
                    qisReport.ASReportedCode__c = stitchingCode;
                    // 2020/08/04 taoqz modify
                    // qisReport.PAE_Determine__c = rdRecord.PAE_DetermineResults__c;
                    qisReport.PAE_Determine__c = rdRecord.PAE_DetermineResults_Text__c;
                    qisReport.PAE_intakePrevDetermineResults__c = prevDetermineResults; //20200107 add
                    //20191217 add
                    //如果有不在现 则更新repair.ASReportedCodeAC__c 
                    if (String.isNotBlank(stitchingCodeZ)) {
                        //20191217 modify start
                        if (String.isNotBlank(qisReport.PAE_temp_final_code__c)) {
                            qisReport.ASReportedCodeAC__c = qisReport.PAE_temp_final_code__c + ',' + stitchingCodeZ;
                        } else {
                            qisReport.ASReportedCodeAC__c = stitchingCodeZ;
                        }
                        qisReport.PAE_codez__c = stitchingCodeZ;
                    } else {
                        //202003224 add 如果没有有不在现 则更新repair.ASReportedCodeAC__c
                        qisReport.ASReportedCodeAC__c = qisReport.PAE_temp_final_code__c;
                        qisReport.PAE_codez__c = stitchingCodeZ;
                    }
                    //20191217 modify end                    
                } else {
                    //20191217  modify start
                    if (String.isNotBlank(qisReport.PAE_codez__c)) {
                        qisReport.ASReportedCodeAC__c = stitchingCode + ',' + qisReport.PAE_codez__c;
                    } else {
                        qisReport.ASReportedCodeAC__c = stitchingCode;
                    }
                    qisReport.PAE_temp_final_code__c = stitchingCode;
                    //20191217 modify end
                    // 2020/08/04 taoqz modify
                    // qisReport.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults__c;
                    qisReport.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults_Text__c;
                    qisReport.PAE_finalPrevDetermineResults__c = prevDetermineResults; //20200107 add
                }
            } else {
                if (ASac_ASrc == 'Intake') {
                    qisReport.ASReportedCode__c = stitchingCode;
                    qisReport.PAE_codez__c = stitchingCodeZ; //20191218 add
                    qisReport.ASReportedCodeAC__c = qisReport.PAE_temp_final_code__c; //20191218 add
                    // 2020/08/04 taoqz modify
                    // qisReport.PAE_Determine__c = rdRecord.PAE_DetermineResults__c; //20191218 add 
                    qisReport.PAE_Determine__c = rdRecord.PAE_DetermineResults_Text__c; //20191218 add 
                    qisReport.PAE_intakePrevDetermineResults__c = prevDetermineResults; //20200107 add  
                    qisReport.QIS_ConfirmationDate__c = null; //20200416
                    qisReport.QIS_Authenticator__c = null; //20200416       
                } else {
                    qisReport.ASReportedCodeAC__c = stitchingCode;
                    qisReport.PAE_temp_final_code__c = stitchingCode; //20191218 add
                    // 2020/08/04 taoqz modify
                    // qisReport.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults__c;//20191218 add
                    qisReport.PAE_DetermineAC__c = rdRecord.PAE_DetermineResults_Text__c; //20191218 add
                    qisReport.PAE_finalPrevDetermineResults__c = prevDetermineResults; //20200107 add
                    qisReport.OCSM_RC_CordingDate__c = null; //20200416
                    qisReport.OCSM_RC_CordingUser__c = null; //20200416
                }
            }
            // System.debug('程序走到了1068行,qis的PAE_DetermineAC__c为:'+qisReport.PAE_DetermineAC__c+'qis的PAE_Determine__c为:'+qisReport.PAE_Determine__c);
            update qisReport;
        }
    }
    //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.Id = paedRDInfo.paedrdd.Id;
            paedrd.PAED_Reappear_Result__c = '不再現';
            paedrd.PAED_ResultAffirmant__c = UserInfo.getUserId();
            paedrd.PAED_ResultConfirmationDate__c = Date.toDay();
        } else {
            //paedrd.Id = paedRDInfo.paedrdd.Id;
            paedrd.PAED_Reappear_Result__c = paedRDInfo.paedrdd.PAED_Reappear_Result__c;
            paedrd.PAED_ResultAffirmant__c = null;
            paedrd.PAED_ResultConfirmationDate__c = null;
        }
        return paedrd;
    }
    // 如果是确定并SAP按钮会触发该方法
    // tqz 2020/06/19 start
    // 非AE的修理在Intake编辑画面点击【确定并SAP申请】后,记录进行修理的判定结果确认者
    public Pagereference sendToSAP() {
        //如果触发了错误 则不更新字段 明细的错误 DOJ_ 课题95 add by rentongxiao 2020-10-13 start
        if (IsEmptyManagementCode(paedRecordDetailView)) {
            return null;
        }
        //如果触发了错误 则不更新字段 明细的错误 DOJ_ 课题95 add by rentongxiao 2020-10-13 end 
        Savepoint sp = Database.setSavepoint();
        try {
            // Gzw 20200907 【确定并SAP申请】后,记录进行修理的判定结果确认者
            // SaveAndClose();
            // isSentSAP__c,
            // List<Repair__c> res = [select id,name,DOJ_Status__c,PAE_DetermineResults__c,Repair_ConfirmationDate__c,
            //         Repair_Authenticator__c,SAP_ApplyForRepair_time__c,Repair_Determine__c,
            //         Repair_Determine_result__c,OSH_Affirmant__c,
            //         SAP_Transfer_time__c,Repair_Ordered_Date__c,status__c,CreatedDate,IISE_confirmed_person_en__c,SAP_ApplyForRepair_day__c
            //         from Repair__c 
            //         where id = :RepairId];
            // if(res.size() > 0){
            //     Repair__c re = res.get(0);
            //     re.SAP_ApplyForRepair_day__c = Date.today();
            //     re.SAP_ApplyForRepair_time__c = DateTime.now();
            //     update re;
            // }          
            // repa.SAP_ApplyForRepair_day__c = Date.today();
            repa.status__c = '1.受理完毕';
            repa.SAP_Transfer_time__c = DateTime.now();
            // Gzw 非AE的修理在Intake编辑画面点击【确定并SAP申请】后,记录进行修理的判定结果确认者 start
            // 有进行修理的判定结果时,记录记录进行修理的判定结果确认者
            if (String.isNotBlank(repa.Repair_Determine_result__c) && (repa.IS_AE__c == 'YES' && isOSH)) {
                repa.Repair_Determine_result_ConfirmationDate__c = Date.today();
                repa.Repair_Determine_result_ConfirmationUser__c = UserInfo.getUserId();
            }
            // Gzw 非AE的修理在Intake编辑画面点击【确定并SAP申请】后,记录进行修理的判定结果确认者 end
            update repa;
            return SaveAndClose();
        } catch (Exception e) {
            Database.rollback(sp);
            return null;
        }
    }
    // tqz 2020/06/19 end
    // 正则表达式 判断是否包含汉字
    // 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;
        }
        // Pattern p = Pattern.compile('\\p{IsHan}');
        // Matcher m = p.matcher( InputString );
        // return m.find();
    }
    // 精琢科技   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;
        }
    }
}