liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
/* 
用于给lwc的js初始化数据和对记录进行dml操作,此controller属于报告书
*/
public with sharing class ReportController {
 
    @AuraEnabled
    public static InitData initForOPDReportConsumButton(String recordId){
        InitData res = new initData();
        try {
            Consum_Apply__c con = [select RA_Status__c,Product_category__c,Id,Hospital__c,Strategic_dept__c,Account__c from Consum_Apply__c where Id =: recordId];
            res.raStatus = con.RA_Status__c;
            res.productCategory = con.Product_category__c;
            res.consumApplyId = con.Id;
            res.hospital = con.Hospital__c;
            res.strategicDept = con.Strategic_dept__c;
            res.account = con.Account__c;
            res.recordTypeId1 = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(lexLightingButtonConstant.RECORD_TYPE_NAME_BY_SIS_ENG).getRecordTypeId();
            res.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(lexLightingButtonConstant.RECORD_TYPE_NAME_BY_SIS_ET).getRecordTypeId();
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForOPDReportButton(String recordId){
        InitData res = new initData();
        try {
            Rental_Apply__c rent = [select RA_Status__c,Asset_return_day2__c,Hospital__c,Strategic_dept__c,Account__c,OPDPlan__c,Follow_UP_Opp__c,demo_purpose2__c from Rental_Apply__c where Id =: recordId];
            res.raStatus = rent.RA_Status__c;
            res.assetReturnDay2 = rent.Asset_return_day2__c;
            res.hospitalId = rent.Hospital__c;
            res.strategicDeptId = rent.Strategic_dept__c;
            res.accountId = rent.Account__c;
            res.demoPurpose2 = rent.demo_purpose2__c;
            res.followUPOpp = rent.Follow_UP_Opp__c;
            res.opdPlan = rent.OPDPlan__c;
            res.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(lexLightingButtonConstant.RECORD_TYPE_NAME_BY_OPD).getRecordTypeId();
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    //给VOC完毕相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForVOCFinishButton (String recordId) {
        InitData res = new initData();
        try {
            Report__c report = [select Status__c from Report__c where Id = :recordId];
            res.status = report.Status__c;
            res.profileId = UserInfo.getProfileId();
            res.userId = UserInfo.getUserId();
            res.luShengId = getUserIdByName(LightingButtonConstant.LU_SHENG_NAME);
            res.huDiAnId = getUserIdByName(LightingButtonConstant.HU_DI_AN_NAME);
            res.systemProfileId = getProfileIdByName(LightingButtonConstant.SYSTEM_PROFILE_NAME);
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        } 
        return res;
    }
    //给VOC判定相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForVOCCheckButton (String recordId) {
        InitData res = new initData();
        try {
            Report__c report = [select Status__c,IsVOC__c,Responsible_Person__r.Id from Report__c where Id = :recordId];
            res.status = report.Status__c;
            res.isVOC = report.IsVOC__c;
            res.personId = report.Responsible_Person__r.Id;
            res.profileId = UserInfo.getProfileId();
            res.userId = UserInfo.getUserId();
            res.luShengId = getUserIdByName(LightingButtonConstant.LU_SHENG_NAME);
            // res.huDiAnId = getUserIdByName(LightingButtonConstant.HU_DI_AN_NAME);
            res.systemProfileId = getProfileIdByName(LightingButtonConstant.SYSTEM_PROFILE_NAME);
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        } 
        return res;
    }
    //给VOC提出相应的js提供初始化数据
    @AuraEnabled
    public static Initdata initForVOCSubmitButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select Status__c,Owner.Id,CreatedBy.Id from Report__c where Id = :recordId];
            res.status = report.Status__c;
            res.ownerId = report.Owner.Id;
            res.createdById = report.CreatedBy.Id;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
 
    //给VOC回答相应的js提供初始化数据
    @AuraEnabled
    public static Initdata initForVOCAnswerButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select Status__c from Report__c where Id = :recordId];
            res.status = report.Status__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    //给VOC结果确认相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForVOCConfirmButton (String recordId) {
        InitData res = new initData();
        try {
            Report__c report = [select Status__c,VOC_Satisfy__c,VOC_Satisfy1__c from Report__c where Id = :recordId];
            res.status = report.Status__c;
            res.satisfy = report.VOC_Satisfy__c;
            res.satisfy1 = report.VOC_Satisfy1__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        } 
        return res;
    }
 
    //给取消相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForCancelButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select Status__c from Report__c where Id = :recordId];
            res.status = report.Status__c;
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    //给OCSM不要报告相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForOCSMNoToReportButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select OCSMAdministrativeReportNumber__c,OCSMAdministrativeReportDate__c,Aware_date__c from Report__c where Id = :recordId];
            res.theOCSMAdministrativeReportDate = report.OCSMAdministrativeReportDate__c;
            res.theOCSMAdministrativeReportNumber = report.OCSMAdministrativeReportNumber__c;
            res.awareDate = report.Aware_date__c;
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    //给SIStoOPD相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForSIStoOPDButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select Status__c,Owner.Id from Report__c where Id = :recordId];
            res.status = report.Status__c;
            res.ownerId = report.Owner.Id;
            res.userId = UserInfo.getUserId();
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    //给OCSM要报告相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForOCSMToReportButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select OCSMAdministrativeReportStatus__c,AwareDate__C from Report__c where Id = :recordId];
            res.theOCSMAdministrativeReportStatus = report.OCSMAdministrativeReportStatus__c;
            res.awareDate = report.AwareDate__C;
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    //给完毕相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForCompleteButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select Status__c from Report__c where Id = :recordId];
            res.status = report.Status__c;
            res.profileId = UserInfo.getProfileId();
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    //给Intake universal code编辑相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForASRCEditorButton(String recordId){
        InitData res = new InitData();
        String developerName = LightingButtonConstant.DEVELOPER_NAME_ASRC_DECISION;
        try {
            PAE_DecisionRecord__c[] report = [SELECT LastModifiedDate, Id, Name, LastModifiedById,RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_Report__c =  :recordId  And RecordType.DeveloperName = :developerName Order by LastModifiedDate desc];
            if (report != null && !report.isEmpty()) {
                res.lastModifiedDate = report[0].LastModifiedDate;
                res.id = report[0].Id;
                res.name = report[0].Name;
                res.lastModifiedById = report[0].LastModifiedById;
                res.developerName = report[0].RecordType.DeveloperName;
            }
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
 
    //给Final universal code编辑相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForASACEditorButton(String recordId){
        InitData res = new InitData();
        String recordTypeId = LightingButtonConstant.DEVELOPER_NAME_ASAC_DECISION;
        try {
            PAE_DecisionRecord__c[] report = [SELECT LastModifiedDate, Id, Name, LastModifiedById,RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_Report__c =  :recordId  And RecordType.DeveloperName = :recordTypeId Order by LastModifiedDate desc];
            if (report != null && !report.isEmpty()) {
                res.lastModifiedDate = report[0].LastModifiedDate;
                res.id = report[0].Id;
                res.name = report[0].Name;
                res.lastModifiedById = report[0].LastModifiedById;
                res.developerName = report[0].RecordType.DeveloperName;
            }
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
 
    //给OPDtoSIS相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForOPDtoSISButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c report = [select Status__c,Owner.Id from Report__C where Id = :recordId];
            res.status = report.Status__c;
            res.ownerId = report.Owner.Id;
            res.userId = UserInfo.getUserId();
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    //给提交(对手活动报告)相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForSubmitCompetitorReportButton(String recordId){
        InitData res = null;
        try {
           res =  new InitData();
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForNewOnLineSurveyButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c re = [
                select
                Date__c,
                Practitioner1__c,
                OwnerId
                from Report__c where Id =: recordId
            ];
            res.ownerId = re.OwnerId;
            res.datec = re.Date__c;
            res.practitioner1 = re.Practitioner1__c;
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    //给提交相应的js提供初始化数据
    @AuraEnabled
    public static String updateForSubmitButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.Status__c = LightingButtonConstant.RECORD_TYPE_NAME_BY_SUBMIT;
            rac.Submit_time__c = Datetime.now();
            rac.Submit_report_day__c = Date.today();
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    //OPDtoSIS操作更新相应数据
    @AuraEnabled
    public static String updateForOPDtoSISButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_OPD).getRecordTypeId();
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
 
    //取消提交操作更新相应数据
    @AuraEnabled
    public static String updateForCancelSubmitReportButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.Status__c = LightingButtonConstant.STATUS_DRAFT;
            rac.Submit_report_day__c = null;
            rac.Submit_time__c = null;
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    //完毕操作更新相应数据
    @AuraEnabled
    public static String updateForCompleteButton(String recordId){
        Report__c rac = new Report__c();
        try {
            rac.Id = recordId;
            rac.Status__c = LightingButtonConstant.STATUS_COMPLETE;
            rac.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.VOC_NAME).getRecordTypeId();
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    //OCSM要报告操作更新相应数据
    @AuraEnabled
    public static String updateForOCSMToReportButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.OCSMAdministrativeReportStatus__c = LightingButtonConstant.STATUS_TO_BE_REPORTED;
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
 
    //SIStoOPD操作更新相应数据
    @AuraEnabled
    public static String updateForSIStoOPDButton(String recordId){
        Report__c rac = new Report__c();
        try {
            rac.Id = recordId;
            rac.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_FOLLOW_THE_STAGE).getRecordTypeId();
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    //DispatchOCSMQARA操作更新相应数据
    @AuraEnabled
    public static String updateForDispatchOCSMQARAButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.Dispatch_OCSM_QARA__c = true;
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    //OCSM不要报告操作更新相应数据
    @AuraEnabled
    public static String updateForOCSMNoToReportButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.OCSMAdministrativeReportStatus__c  = LightingButtonConstant.STATUS_TO_NOT_REPORT;
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
 
    //取消操作更新相应数据
    @AuraEnabled
    public static String updateForCancelButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.Status__c = LightingButtonConstant.STATUS_CANCEL;
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    
    //VOC结果确认更新相应数据
    @AuraEnabled
    public static String updateForVOCConfirmButton(String recordId,String satisfy,String satisfy1){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            if (satisfy == LightingButtonConstant.CN_YES) {
                rac.Status__c = LightingButtonConstant.STATUS_VOC_CONFIRMED;
                } else if (satisfy == LightingButtonConstant.CN_NO) {
                // 対応結果(一回目)に値なければ、一回目の「否」と見なす
                if (satisfy1 != LightingButtonConstant.CN_NO) {
                Report__c[] records = [SELECT Id, VOC_Satisfy__c, VOC_Unsatisfy_Reason__c, VOC_follow_up_result__c, VOC_solution_category__c FROM Report__c WHERE Id = :recordId];
                rac.VOC_Satisfy__c = null;
                rac.VOC_Unsatisfy_Reason__c = null;
                rac.VOC_follow_up_result__c = null;
                rac.VOC_solution_category__c = null;
                rac.VOC_Satisfy1__c= records[0].VOC_Satisfy__c;
                rac.VOC_Unsatisfy_Reason1__c = records[0].VOC_Unsatisfy_Reason__c;
                rac.VOC_follow_up_result1__c = records[0].VOC_follow_up_result__c;
                rac.VOC_solution_category1__c = records[0].VOC_solution_category__c;
                rac.Status__c = LightingButtonConstant.STATUS_DRAFT;
                }
                // 対応結果(一回目)に値あれば、二回目の「否」と見なす
                else {
                rac.Status__c = LightingButtonConstant.STATUS_VOC_CONFIRMED;
                }
                }
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
 
   
    //VOC回答更新相应数据
    @AuraEnabled
    public static String updateForVOCAnswerButton(String recordId){
        try {
            Report__c rac = [select Status__c from Report__c where Id = :recordId];
            rac.Status__c = LightingButtonConstant.STATUS_VOC_END_OF_ANSWER;
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            } 
            // return e.getDmlMessage(0);
        }
    }
 
    //提交竞争对手报告更新相应数据
    @AuraEnabled
    public static String updateForSubmitCompetitorReportButton(String recordId){
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.Status__c = LightingButtonConstant.STATUS_VOC_APPLYING;
            rac.Submit_time__c = Datetime.now();
            rac.Submit_report_day__c = Date.today();
            rac.Date__c = Date.today();
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    //VOC回答更新相应数据
    @AuraEnabled
    public static String updateForVOCSubmitButton(String recordId ,String createdById){
        try {
            Report__c rac = [select Status__c,JingliApprovalManager__r.Id,BuchangApprovalManager__r.Id,SalesManager__r.Id,BuchangApprovalManagerSales__r.Id,ZongjianApprovalManager__c,Submit_time__c,Submit_report_day__c,Owner.Id from Report__c where Id = :recordId];
            // share
            User[] records = [SELECT  Job_Category__c FROM User WHERE Id = :createdById];
            List<String> userAccess = new List<String>();
            if (records[0].Job_Category__c == LightingButtonConstant.TYPE_OF_SALES_SERVICES) {
            if(rac.JingliApprovalManager__c != null){
                userAccess.add(rac.JingliApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
                rac.VOC_CreatedBy_jingli__c = rac.JingliApprovalManager__c;
            }
            if(rac.BuchangApprovalManager__c != null){
                userAccess.add(rac.BuchangApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
                rac.VOC_CreatedBy_buzhang__c = rac.BuchangApprovalManager__c;
            }
            
            
            } else {
                if(rac.SalesManager__c != null){
                    userAccess.add(rac.SalesManager__c + LightingButtonConstant.USER_ACCESS_READ);
                    rac.VOC_CreatedBy_jingli__c = rac.SalesManager__c;
                }
                if(rac.BuchangApprovalManagerSales__c != null){
                    userAccess.add(rac.BuchangApprovalManagerSales__c + LightingButtonConstant.USER_ACCESS_READ);
                    rac.VOC_CreatedBy_buzhang__c = rac.BuchangApprovalManagerSales__c;
                }
           
            
            
            
            }
            if(rac.ZongjianApprovalManager__c != null){
                userAccess.add(rac.ZongjianApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
            }
            String rtn = ControllerUtil.setSObjectShare(LightingButtonConstant.SOBJECT_NAME_OF_REPORT_SHARE,LightingButtonConstant.SOBJECT_NAME_OF_VOC_SHARE,recordId,userAccess,rac.Owner.Id);
            if (rtn != LightingButtonConstant.OK) {
            return rtn;
            }
            rac.Status__c = LightingButtonConstant.STATUS_VOC_WRITE_OVER;
            rac.Submit_time__c = Date.today();
            rac.Submit_report_day__c = Date.today();
            update rac;
            return null;
        } catch (Exception e) {
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
            // return e.getDmlMessage(0);
        }
    }
    //VOC判定更新相应数据
    @AuraEnabled
    public static String updateForVOCCheckButton (String recordId,String isVOC,String personId) {          
        try {
            Report__c rac = [select Owner.Id,VOC_jingli__r.Id,VOC_buzhang__r.Id,VOC_zongjian__r.Id,VOC_Finish__c,VOC_share_date__c,Responsible_Person__r.Id from Report__c where Id = :recordId];
            if (isVOC == LightingButtonConstant.VOC_NAME) {
                // VOC対応者の経理部長総監を設定
                User[] records = [SELECT Id, Job_Category__c, JingliApprovalManager__c, SalesManager__c, BuchangApprovalManager__c, BuchangApprovalManagerSales__c, ZongjianApprovalManager__c FROM User WHERE Id = :personId];
                if (records[0].job_Category__c == LightingButtonConstant.TYPE_OF_SALES_SERVICES) {
                    rac.VOC_jingli__c = records[0].JingliApprovalManager__c == null ? null : records[0].JingliApprovalManager__c;
                    rac.VOC_buzhang__c = records[0].BuchangApprovalManager__c == null ? null : records[0].BuchangApprovalManager__c;
                } else {
                    rac.VOC_jingli__c = records[0].SalesManager__c == null ? null : records[0].SalesManager__c;
                    rac.VOC_buzhang__c = records[0].BuchangApprovalManagerSales__c == null ? null : records[0].BuchangApprovalManagerSales__c;
                }
                rac.VOC_zongjian__c = records[0].ZongjianApprovalManager__c == null ? null : records[0].ZongjianApprovalManager__c;
                rac.Status__c = LightingButtonConstant.STATUS_VOC_CHECK_OVER;
                rac.VOC_Finish__c = false;
                Date serverTimestamp = Date.today();
                rac.VOC_share_date__c = serverTimestamp;
                // share
                List<String> userAccess = new List<String>();
                if(rac.Responsible_Person__c != null){
                    userAccess.add(rac.Responsible_Person__c + LightingButtonConstant.USER_ACCESS_EDIT);
                }
                if(rac.VOC_jingli__c != null){
                    userAccess.add(rac.VOC_jingli__c + LightingButtonConstant.USER_ACCESS_READ);
                }
                if(rac.VOC_buzhang__c != null){
                    userAccess.add(rac.VOC_buzhang__c + LightingButtonConstant.USER_ACCESS_READ);
                }
                if(rac.VOC_zongjian__c != null){
                    userAccess.add(rac.VOC_zongjian__c + LightingButtonConstant.USER_ACCESS_READ);
                }
                String rtn = ControllerUtil.setSObjectShare(LightingButtonConstant.SOBJECT_NAME_OF_REPORT_SHARE,LightingButtonConstant.SOBJECT_NAME_OF_VOC_SHARE,recordId,userAccess,rac.Owner.Id);
                if (rtn != LightingButtonConstant.OK) {
                    return rtn;
                }
                update rac;
                } else {
                    rac.Status__c = LightingButtonConstant.STATUS_VOC_FINISH;
                    rac.VOC_Finish__c = true;
                    update rac;
                }
                return null;
        } catch (Exception e) {
            return e.getMessage();
        }
    }
    //VOC完毕操作更新相应数据
    @AuraEnabled
    public static String updateForVOCFinishButton (String recordId) {
        try {
            Report__c report = [select Id,Status__C from Report__c where Id = :recordId];
            report.Status__c = LightingButtonConstant.STATUS_VOC_FINISH;
            update report;
            return null;
        } catch (Exception e) {
            // return e.getDmlMessage(0);
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
        }
    }
    @AuraEnabled
    public static string getUserIdByName(String name){
        User user = null;
        try {
            user = [select Id from User where Name =:name]; 
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return user.Id;
    }
    @AuraEnabled
    public static string getProfileIdByName(String name){
        Profile profile = null;
        try {
            profile = [select Id from Profile where Name =:name];
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return profile.Id;
    }
    
    public class InitData{
        @AuraEnabled
        public String status;
        @AuraEnabled
        public String isVOC;
        @AuraEnabled
        public String personId;
        @AuraEnabled
        public String createdById;
        @AuraEnabled
        public String ownerId;
        @AuraEnabled
        public String satisfy;
        @AuraEnabled
        public String satisfy1;
        @AuraEnabled
        public String profileId;
        @AuraEnabled
        public String theOCSMAdministrativeReportNumber;
        @AuraEnabled
        public Date theOCSMAdministrativeReportDate;
        @AuraEnabled
        public Date awareDate;
        @AuraEnabled
        public String theOCSMAdministrativeReportStatus;
        @AuraEnabled
        public Datetime lastModifiedDate;
        @AuraEnabled
        public String id;
        @AuraEnabled
        public String name;
        @AuraEnabled
        public String lastModifiedById;
        @AuraEnabled
        public String developerName;
        @AuraEnabled
        public String userId;
        @AuraEnabled
        public String luShengId;
        @AuraEnabled
        public String huDiAnId;
        @AuraEnabled
        public String systemProfileId;
        @AuraEnabled
        public String raStatus;
        @AuraEnabled
        public String productCategory;
        @AuraEnabled
        public String hospitalId;
        @AuraEnabled
        public String hospital;
        @AuraEnabled
        public String strategicDeptId;
        @AuraEnabled
        public String strategicDept;
        @AuraEnabled
        public String accountId;
        @AuraEnabled
        public String account;
        @AuraEnabled
        public String rentalApplyId;
        @AuraEnabled
        public String consumApplyId;
        @AuraEnabled
        public String recordTypeId;
        @AuraEnabled
        public String recordTypeId1;
        @AuraEnabled
        public Date assetReturnDay2;
        @AuraEnabled
        public String followUPOpp;
        @AuraEnabled
        public String demoPurpose2;
        @AuraEnabled
        public String opdPlan;
        @AuraEnabled
        public Date datec;
        @AuraEnabled
        public String practitioner1;
    }
}