黄千龙
2023-04-12 51f6dc7bc93a89c97ebc17e8c908f7f6be6566dc
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
public with sharing class QISReportController {
    // Final universal code编辑
   @AuraEnabled
    public static InitData initForQisUniversalFailureCodeButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public  static InitData sqlForPAE (String qisReportId){
        InitData res = new initData();
        
        String recordTypeId = LightingButtonConstant.DEVELOPER_NAME_ASAC_DECISION;
        try{
            PAE_DecisionRecord__c RCPAEDIdList = [SELECT LastModifiedDate, Id, Name, LastModifiedById,RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_QIS__c = :qisReportId  And RecordType.DeveloperName =  :recordTypeId limit 1]; 
            res.pAEid = RCPAEDIdList.id;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    //Intake universal code编辑
    @AuraEnabled
    public static InitData initForlexQISIntakeuniversalcodeButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public  static InitData sqlForPAE1 (String qisReportId){
        InitData res = new initData();
        
        String recordTypeId = LightingButtonConstant.DEVELOPER_NAME_ASRC_DECISION;
        try{
            PAE_DecisionRecord__c ASRCDIdList = [SELECT LastModifiedDate, Id, Name, LastModifiedById,RecordType.DeveloperName FROM PAE_DecisionRecord__c where PAE_QIS__c = :qisReportId  And RecordType.DeveloperName =  :recordTypeId Limit 1]; 
            res.pAEid = ASRCDIdList.id;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    //OSH现品收到
    @AuraEnabled
    public static InitData initForOSHRecievedButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id,QIS_Status__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.QIStatus = report.QIS_Status__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public static String updateQis (String recordId){
        String re = '成功';
        try{
            ID myUserID = UserInfo.getUserId();
            
            User tempUser = [select id,Alias,Email from user where id = : myUserID ];
            QIS_Report__c rac  = new QIS_Report__c();   
            rac.id = recordId;
            rac.QIS_Status__c = LightingButtonConstant.STATUS_QIS_OSH_TESTING;
            rac.OSHRecievedDate__c  = Date.today();
            rac.OSH_Receive_staff__c = tempUser.Alias;
            rac.OSH_staff__c = tempUser.Alias;
            rac.OSH_staff_email__c = tempUser.email;
            rac.Is_ProductGot__c = true;
            rac.OSH_GotProductPeople__c = tempUser.id;
            User resultSet = [SELECT Id, JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c FROM User WHERE Id = :myUserID];
            if (resultSet!=null && resultSet.JingliApprovalManager__c != null && resultSet.BuchangApprovalManager__c != null ) {
                rac.OSH_Manager__c = resultSet.JingliApprovalManager__c;
                rac.OSH_Buzhang__c = resultSet.BuchangApprovalManager__c;
            }else{
                rac.OSH_Manager__c= myUserID;
                rac.OSH_Buzhang__c= myUserID;
            }
            Oly_TriggerHandler.bypass('QIS_ReportTrigger');
            update rac;
            
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
 
    //提交待审批1
    @AuraEnabled
    public static InitData initForOSHSubmitButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id,QIS_Status__c,OSH_staff__c,OSH_staff_email__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.QIStatus = report.QIS_Status__c;
            res.OSHstaff = report.OSH_staff__c;
            res.OSHstaffEmail = report.OSH_staff_email__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    @AuraEnabled
    public static String updateQis1 (String recordId){
        String re = '成功';
        try{
            
            QIS_Report__c rac  = new QIS_Report__c();   
            rac.id = recordId;
            rac.QIS_Status__c = LightingButtonConstant.STATUS_QIS_OSH_COMPLATED;
            update rac;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
    //提交待审批
     @AuraEnabled
    public static InitData initForRCSubmitButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id,RC_problem_not_found__c,QIS_Reply_day__c,RC_inspection_date__c,QIS_Status__c,Cancel_QIS_Reason__c,OSH_staff__c,OSH_staff_email__c,RC__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.QIStatus = report.QIS_Status__c;
            res.OSHstaff = report.OSH_staff__c;
            res.OSHstaffEmail = report.OSH_staff_email__c;
            res.CancelQISReason = report.Cancel_QIS_Reason__c;
            res.RCid = report.RC__c;
            res.RCinspectionDate = report.RC_inspection_date__c;
            res.QISReplyDay = report.QIS_Reply_day__c;
            res.RCproblemnotfound = report.RC_problem_not_found__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public static String updateQisWithRC (String recordId,String type,String oldQIStatus){
        String re = '成功';
        
        ID myUserID = UserInfo.getUserId();
        User userinfo = [SELECT Id, JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c, BuchangApprovalManagerSales__c, SalesManager__c FROM User WHERE Id = :myUserID LIMIT 1];  
        QIS_Report__c rac  = new QIS_Report__c();  
        rac.id = recordId;
        if (type == '1') {
            QIS_Report__c report1 = [SELECT  id,RC_problem_not_found__c,RC_FixedJudgement__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            rac.QIS_Status__c = LightingButtonConstant.STATUS_QIS_RC_COMPLATED;
            if (report1.RC_problem_not_found__c == true && report1.RC_FixedJudgement__c == false) {
                QIS_Report__c qisreport = [SELECT Id, Reason_bloken__c, Special_follow__c, next_action__c, QIS_Reply_Comment__c, OCM_judgement__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];
                if (qisreport != null) {
                   rac.Reason_bloken1__c       = qisreport.Reason_bloken__c;
                   rac.Special_follow1__c      = qisreport.Special_follow__c;
                   rac.next_action1__c         = qisreport.next_action__c;
                   rac.QIS_Reply_Comment1__c   = qisreport.QIS_Reply_Comment__c;
                   rac.OCM_judgement1__c       = qisreport.OCM_judgement__c;
                }
            }
        }
        if (type == '2') {
            rac.QIS_Status__c = LightingButtonConstant.STATUS_QIS_CANCEL;
            rac.QIS_Cancel_Submit_day__c  = Date.today();
        }
        try{
            if (userinfo!=null && userinfo.BuchangApprovalManagerSales__c != null) {
                rac.RC_Manager__c = userinfo.BuchangApprovalManagerSales__c;
            }else{
                rac.RC_Manager__c = myUserID;
            }
            if (userinfo!=null) {
                if (oldQIStatus == LightingButtonConstant.STATUS_QIS_RC_CHECKING) {
                    rac.RC__c = myUserID;
                }
                if (userinfo.SalesManager__c != null ) {
                    rac.ApproveManager__c  = userinfo.SalesManager__c;
                }else{
                    rac.ApproveManager__c  = myUserID;
                }
                if (userinfo.BuchangApprovalManagerSales__c != null ) {
                    rac.ApproveBuZhang__c  = userinfo.BuchangApprovalManagerSales__c ;
                }else{
                    rac.ApproveBuZhang__c  = myUserID;
                }
                if (userinfo.ZongjianApprovalManager__c != null ) {
                    rac.AppeoveZongJian__c = userinfo.ZongjianApprovalManager__c  ;
                }else{
                    rac.AppeoveZongJian__c = myUserID;
                }
            }
            update rac; 
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
    // 提交
     @AuraEnabled
    public static InitData initForOCMSubmitButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id,is_aohui_product__c,QIS_Status__c,OCM_Manager_Mail_F__c,QISInstallDate__c,contract_number__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.QIStatus = report.QIS_Status__c;
            res.QISInstallDate = report.QISInstallDate__c;
            res.contractnumber = report.contract_number__c;
            res.isaohuiproduct = report.is_aohui_product__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public static String updateQisWithOCM (String recordId){
        String re = '成功';
        QIS_Report__c report = [SELECT  id,QIS_Status__c,QISInstallDate__c,contract_number__c,OCM_Manager_Mail_F__c
                                ,OCM_Member_Mail_F__c,OCM_Repair_Mail_F__c,OCM_Repair_Mail1_F__c,FSE_Special_Mail_F__c,FSE_Special_Manager_Mail_F__c
                                    ,WorkLocation_CC_Mail_F__c,is_aohui_product__c,QuolityApproveResult__c
                                FROM QIS_Report__c WHERE Id = :recordId LIMIT 1]; 
        try{
            QIS_Report__c rac  = new QIS_Report__c();   
            rac.id = recordId;
            rac.QIS_Status__c = LightingButtonConstant.STATUS_QIS_FSE_COMPLATED;
            rac.OCM_Manager_Mail__c = report.OCM_Manager_Mail_F__c;
            rac.OCM_Member_Mail__c = report.OCM_Member_Mail_F__c;
            rac.OCM_Repair_Mail__c = report.OCM_Repair_Mail_F__c;
            rac.OCM_Repair_Mail1__c = report.OCM_Repair_Mail1_F__c;
            rac.FSE_Special_Mail__c = report.FSE_Special_Mail_F__c;
            rac.FSE_Special_Manager_Mail__c = report.FSE_Special_Manager_Mail_F__c;
            rac.WorkLocation_CC_Mail__c = report.WorkLocation_CC_Mail_F__c;
            rac.Cancel_QIS_Reason__c = null;
            if (report.is_aohui_product__c == true) {
                    rac.OCM_judgement__c = '质量问题';
                    rac.next_action__c = '无偿维修';
                    rac.RecordTypeId = Schema.SObjectType.QIS_Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_OSH).getRecordTypeId();
                    rac.QIS_Status__c = LightingButtonConstant.STATUS_QIS_OSH_TESTING_APP;
            }
            if (report.QuolityApproveResult__c == null || report.QuolityApproveResult__c == '') {
                rac.QuolityApproveResult__c = '3.已审核,一般质量问题';
            }
            update rac;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
 
    // QIS结果跟进完毕
     @AuraEnabled
    public static InitData initForQisAgreeButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id ,OwnerId FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.ownerId = report.OwnerId;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public static String updateQisForQisAgree (String recordId){
        String re = '成功';
        ID myUserID = UserInfo.getUserId();
        
        String answerComp = Schema.SObjectType.QIS_Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_OSH_FINASH).getRecordTypeId();
        String fina = Schema.SObjectType.QIS_Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_FINAL).getRecordTypeId();
        String comp = Schema.SObjectType.QIS_Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_COMP).getRecordTypeId();
        // RecordType rectyp = [SELECT id ,name FROM RecordType where  id = '01210000000gFTH'];
        QIS_Report__c report = [SELECT  id,OwnerId,RecordTypeId FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];
        try{
            if (report.ownerid == myUserID) {
                QIS_Report__c rac  = new QIS_Report__c();   
                rac.id = recordId;
                rac.QIS_Status__c = LightingButtonConstant.STATUS_QIS_COMPLATED;
                if (report.RecordTypeId == answerComp) {
                    rac.RecordTypeId = fina;
                }else{
                    rac.RecordTypeId = comp;
                }
                rac.QIS_Complete_Day__c  = Date.today();
                update rac;
            }
            
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
    //OCSM服务本部CDS完毕
    @AuraEnabled
    public static InitData initForRCCDScompleteButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id ,CDS_date__c,QIS_Status__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.cdsdate = report.CDS_date__c;
            res.QIStatus = report.QIS_Status__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public static String updateQisForRCCDScomplete (String recordId){
        String re = '成功';
        ID myUserID = UserInfo.getUserId();
        User userinfo = [SELECT id,Alias__c FROM User WHERE Id = :myUserID LIMIT 1];  
        QIS_Report__c report = [SELECT  id FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];
        try{
                QIS_Report__c rac  = new QIS_Report__c();   
                rac.id = recordId;
                rac.CDS_date__c  = Date.today();
                rac.RC_CDS_staff__c  = userinfo.Alias__c;
                update rac;        
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
 
    //OCSM不要报告
    @AuraEnabled
    public static InitData initForlexOCSMNoToReportLightingButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id ,OCSMAdministrativeReportNumber__c,OCSMAdministrativeReportDate__c,Aware_date__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.oCSMAdministrativeReportNumber = report.OCSMAdministrativeReportNumber__c;
            res.oCSMAdministrativeReportDate = report.OCSMAdministrativeReportDate__c;
            res.Awaredate = report.Aware_date__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    @AuraEnabled
    public static String updateQisForlexOCSMNoToReportLighting (String recordId){
        String re = '成功'; 
        QIS_Report__c report = [SELECT  id FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];
        try{
                QIS_Report__c rac  = new QIS_Report__c();   
                rac.id = recordId;
                rac.OCSMAdministrativeReportStatus__c = '无需报告';
                update rac;        
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
    //OCSM要报告
    @AuraEnabled
    public static InitData initForlexOCSMToReportLightingButton (String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report = [SELECT  id ,OCSMAdministrativeReportStatus__c,Aware_date__c FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];  
            res.Id = report.Id;
            res.oCSMAdministrativeReportStatus = report.OCSMAdministrativeReportStatus__c;
            res.Awaredate = report.Aware_date__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
    @AuraEnabled
    public static String updateQisForlexOCSMToReportLighting (String recordId){
        String re = '成功'; 
        QIS_Report__c report = [SELECT  id FROM QIS_Report__c WHERE Id = :recordId LIMIT 1];
        try{
                QIS_Report__c rac  = new QIS_Report__c();   
                rac.id = recordId;
                rac.OCSMAdministrativeReportStatus__c  = '待报告';
                update rac;        
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            re = e.getMessage();
        }
         return re;
    }
    public class InitData{
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public String ownerId;
        @AuraEnabled
        public String qisRecordTypeId;
        @AuraEnabled
        public String qisRecordName;
        @AuraEnabled
        public String profileName;
        @AuraEnabled
        public String isAEProfile;
        @AuraEnabled
        public String isPAEProfile;
        @AuraEnabled
        public String isCNBuy;
        @AuraEnabled
        public String pAEid;
        @AuraEnabled
        public String oCSMAdministrativeReportNumber;
        @AuraEnabled
        public String oCSMAdministrativeReportStatus;
        @AuraEnabled
        public String qIStatus;
        @AuraEnabled
        public String oSHstaff;
        @AuraEnabled
        public String oSHstaffEmail;
        @AuraEnabled
        public String cancelQISReason;
        @AuraEnabled
        public String rCid;
        @AuraEnabled
        public String contractnumber;
        @AuraEnabled
        public Date rCinspectionDate;
        @AuraEnabled
        public Date qISReplyDay;
        @AuraEnabled
        public Date qISInstallDate;
        @AuraEnabled
        public Date cdsdate;
        @AuraEnabled
        public Date awaredate;
        @AuraEnabled
        public Date oCSMAdministrativeReportDate;
        @AuraEnabled
        public Boolean rCproblemnotfound;
        @AuraEnabled
        public Boolean isaohuiproduct;
        @AuraEnabled
        public Boolean isSendQIS;
    }
 
}