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
public with sharing class LexChoiceAssetController {
    public class SSPLine {
        @AuraEnabled
        public Boolean isSelected;
        @AuraEnabled
        public String setProductid ;
        @AuraEnabled
        public String Assetid;
        @AuraEnabled
        public String Accountid;
        @AuraEnabled
        public String Hospital;
         @AuraEnabled
        public String WorkLocation;
        @AuraEnabled
        public Asset theObject;
        @AuraEnabled
        public String Name;      
        @AuraEnabled
        public String SerialNumber;
        @AuraEnabled
        public String HP_Name;
        @AuraEnabled
        public String Department_Name;
        @AuraEnabled
        public String DepartmentClass;
        @AuraEnabled
        public Date Posting_Date;
        @AuraEnabled
        public Date Extend_Gurantee_DateTo;
        @AuraEnabled
        public Date CurrentContract_End_Date;
        @AuraEnabled
        public Date NoPartRiskDate;
 
 
        public SSPLine(Asset psl) {
          isSelected = false;
          setProductid = psl.id;
            setProductid = setProductid.substring(0,15);
            Assetid = psl.id;
            if (psl.Account.id !=null) {
                Accountid = psl.Account.id;
            }
            Name = psl.Name;
            NoPartRiskDate = psl.product2.PartSupplyFinishDate__c;
            Hospital = psl.Hospital__r.id;
            if (psl.Account.RecordType.DeveloperName !=null && psl.Account.RecordType.DeveloperName!='') {
                if (psl.Account.RecordType.DeveloperName == 'Department_Class_GI' || 
                    psl.Account.RecordType.DeveloperName == 'Department_Class_ET' ||
                    psl.Account.RecordType.DeveloperName == 'Department_Class_BF' ||
                    psl.Account.RecordType.DeveloperName == 'Department_Class_GS' ||
                    psl.Account.RecordType.DeveloperName == 'Department_Class_URO' ||
                    psl.Account.RecordType.DeveloperName == 'Department_Class_GYN' ||
                    psl.Account.RecordType.DeveloperName == 'Department_Class_ENT' ||
                    psl.Account.RecordType.DeveloperName == 'Department_Class_OTH' ||
                    psl.Account.RecordType.DeveloperName == 'RecordType_8' ) {
                        if (psl.Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c !=null) {
                            WorkLocation = psl.Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c;
                        }
                }
                if (psl.Account.RecordType.DeveloperName == 'Department_ENT' || 
                    psl.Account.RecordType.DeveloperName == 'Department_GI' ||
                    psl.Account.RecordType.DeveloperName == 'Department_BF' ||
                    psl.Account.RecordType.DeveloperName == 'Department_GS' ||
                    psl.Account.RecordType.DeveloperName == 'Department_URO' ||
                    psl.Account.RecordType.DeveloperName == 'Department_GYN' ||
                    psl.Account.RecordType.DeveloperName == 'Department_OTH' ) {
                        if (psl.Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c !=null) {
                            WorkLocation = psl.Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c;
                        }
                }
            }
            
            
            SerialNumber= psl.SerialNumber;
            HP_Name = psl.HP_Name__c;
            DepartmentClass = psl.Department_Class__c;
            Department_Name = psl.Department_Name__c;
            Posting_Date = psl.Posting_Date__c;
            Extend_Gurantee_DateTo = psl.Extend_Gurantee_DateTo__c;
            CurrentContract_End_Date = psl.CurrentContract_End_Date__c;
        }
    }
    public class InitData{
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public String AssetCode;
        @AuraEnabled
        public String StatusC;
        @AuraEnabled
        public String OwnerId;
        @AuraEnabled
        public String Repair_Detail;
        @AuraEnabled
        public Date FaultTime;
        @AuraEnabled
        public String RepairApplicantName;
        //2023 08 21 Zhang Heyang PIPL按钮改造 strat
        //@AuraEnabled
        //public String AWSId;      //deloitte-zhj 20231205 PIPL还原
        //2023 08 21 Zhang Heyang PIPL按钮改造 end
        @AuraEnabled
        public String HPname;
        @AuraEnabled
        public String DepName;
        @AuraEnabled
        public String IfDeadHurt;
        @AuraEnabled
        public String ReturnWayType;
        @AuraEnabled
        public String ProblemOccurred;
 
 
        @AuraEnabled
        public String ProblemOccurredSelect;
        // hql 20231213 添加贸易合规 start
        @AuraEnabled
        public String accDealerBlacklist;
        // hql 20231213 添加贸易合规 end
        @AuraEnabled
        public String SupportingProducts;
        @AuraEnabled
        public String ReportAdverseEvents;
        @AuraEnabled
        public String WhatProject;
        @AuraEnabled
        public String OperationOrExaminationName;
        @AuraEnabled
        public String BreakORFallOff;
        @AuraEnabled
        public String UseFailProductFinish;
        @AuraEnabled
        public String AfterFailureInformation;
        @AuraEnabled
        public String Delay15Min;
        @AuraEnabled
        public String InformationFrom;
        @AuraEnabled
        public String FailureQInHospital;
        @AuraEnabled
        public String DelayReportReason;
        @AuraEnabled
        public String ProductFailureRelated;
        @AuraEnabled
        public String DeliveryLogisticsNo;
        @AuraEnabled
        public Date engineerSendDate;
        @AuraEnabled
        public String engineerSendDateStr;// lwt 20240301 避免js自动计算时差
 
//deloitte-zhj 20231129 PIPL还原
        @AuraEnabled
        public DateTime engineerSendDateTime;
 
 
        @AuraEnabled
        public Date RepairsReportDate;
        @AuraEnabled
        public Date ReceiverTime;
        @AuraEnabled
        public Date DateReceiptQuestions;
        @AuraEnabled
        public Date PlannedVisitDay;
        @AuraEnabled
        public Date ActualVisitDateFirst;
         @AuraEnabled
        public Date ActualVisitDateSecon;
         @AuraEnabled
        public Date ActualVisitDateThird;
         @AuraEnabled
        public Date ApplicationTime;
        @AuraEnabled
        public Date currentDate;
 
        //deloitte-zhj 20231206 PIPL还原带上直返地址信息
        @AuraEnabled
        public String ReturnedPersonName;
        @AuraEnabled
        public String ReturnedPersonPhone;
        @AuraEnabled
        public String ReturnedCustomer;
        @AuraEnabled
        public String ReturnedCity;
        @AuraEnabled
        public String ReturnedAddress;
        @AuraEnabled
        public String ReturnedZipCode;
        
        @AuraEnabled
        public String AccountName; // WYL 贸易合规2期 add
        @AuraEnabled
        public String state; // WYL 贸易合规2期 add
     }
 
     public class AssData{
        @AuraEnabled
        public String canRepair;
        @AuraEnabled
        public String proTradeComplianceStatus;//WYl 贸易合规二期修改  add
        @AuraEnabled
        public String Asset_Model_No;//WYl 贸易合规二期修改  add
     }
 
     @AuraEnabled
    public static AssData searchAss(String recordId){
        AssData res = new AssData();
        List<Asset> ass = [select id,Product_ID__c from Asset where ID = :recordId];
        List<Product2> p2 = [select id,Name,Can_Repair__c,
                          // WYL 贸易合规二期修改  start
                          ProTradeComplianceStatus__c,Asset_Model_No__c
                           // WYL 贸易合规二期修改  end
                        from Product2 where 
                        ID = :ass[0].Product_ID__c];
        if (p2[0].Can_Repair__c != null) {
            res.canRepair = p2[0].Can_Repair__c;
            //20231218  sx 贸易合规二期修改  start
            res.proTradeComplianceStatus = p2[0].ProTradeComplianceStatus__c;
            res.Asset_Model_No = p2[0].Asset_Model_No__c;
            //20231218  sx 贸易合规二期修改  end
        }
        return res;
    }
    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try{
            //2023 08 21 Zhang Heyang PIPL按钮改造 strat --- 添加查询中字段AWS_Data_Id__c
//deloitte-zhj 20231122 PIPL还原 去掉AWS_Data_Id__c
            //deloitte-zhj 20231206 PIPL还原带上直返地址信息
            RepairSubOrder__c report =  [SELECT Id,ProblemOccurred__c,ReturnWayType__c,IfDeadHurt__c,SupportingProducts__c,
                                            AirframeCodeEngineer__c,AssetCode__c ,ApplicationTime__c,ActualVisitDateThird__c,ActualVisitDateSecon__c,
                                            ActualVisitDateFirst__c,PlannedVisitDay__c,ReceiverTime__c,RepairsReportDate__c,Status__c,Department__r.Name,
                                            ProblemOccurredSelect__c,ReportAdverseEvents__c,WhatProject__c,OperationOrExaminationName__c,BreakORFallOff__c,
                                            // hql 20231213 添加贸易合规 start
                                            AccBlacklist__c,
                                            // hql 20231213 添加贸易合规 end
                                            // WYL 贸易合规2期 start
                                            Hospital__r.TradeComplianceStatus__c,
                                             // WYL 贸易合规2期 start
                                            UseFailProductFinish__c,AfterFailureInformation__c,Delay15Min__c,InformationFrom__c,FailureQInHospital__c,
                                            DelayReportReason__c,IsProductFaultRelated__c,LogisticsSendDate__c,OrderNumber__c,DateReceiptQuestions__c,
                                            Hospital__r.name,RepairApplicantName__c,OwnerId,ResponseResultDesc__c,FaultTime__c,
                                            ReturnedPersonName__c,ReturnedPersonPhone__c,ReturnedCustomer__c,ReturnedCity__c,ReturnedAddress__c,ReturnedZipCode__c FROM RepairSubOrder__c WHERE Id =: recordId LIMIT 1];
            //2023 08 21 Zhang Heyang PIPL按钮改造 End
            System.debug(LoggingLevel.INFO, '*** opp: ' + report);
            res.Id = report.Id;
            res.StatusC = report.Status__c;
            res.OwnerId = report.OwnerId;
            res.AssetCode = report.AirframeCodeEngineer__c;
            // hql 20231213 添加贸易合规 start
            res.accDealerBlacklist = report.AccBlacklist__c;
            // hql 20231213 添加贸易合规 start
            res.Repair_Detail = report.ResponseResultDesc__c;
            if (report.FaultTime__c!=null) {
                res.FaultTime = report.FaultTime__c.date();
            }
            res.RepairApplicantName = report.RepairApplicantName__c;
            //2023 08 21 Zhang Heyang PIPL按钮改造 strat
            //res.AWSId = report.AWS_Data_Id__c;   //deloitte-zhj 20231122 PIPL还原 去掉AWS_Data_Id__c
            //2023 08 21 Zhang Heyang PIPL按钮改造 end
            if (report.Hospital__r.name!=null) {
                res.HPname = report.Hospital__r.name;
            }
            if (report.Department__r.Name!=null) {
                res.DepName = report.Department__r.Name;
            }
            res.RepairsReportDate = report.RepairsReportDate__c;
            if (report.ReceiverTime__c!=null) {
                res.ReceiverTime = report.ReceiverTime__c.date();
            }
            if (report.PlannedVisitDay__c!=null) {
                res.PlannedVisitDay = report.PlannedVisitDay__c.date();
            }
            res.ActualVisitDateFirst = report.ActualVisitDateFirst__c;
            res.ActualVisitDateSecon = report.ActualVisitDateSecon__c;
            res.ActualVisitDateThird = report.ActualVisitDateThird__c;
            res.SupportingProducts = report.SupportingProducts__c;
            res.ProblemOccurredSelect = report.ProblemOccurredSelect__c;
            res.ReportAdverseEvents = report.ReportAdverseEvents__c;
            res.WhatProject = report.WhatProject__c;
            res.OperationOrExaminationName = report.OperationOrExaminationName__c;
            res.BreakORFallOff = report.BreakORFallOff__c;
            res.UseFailProductFinish = report.UseFailProductFinish__c;
            res.AfterFailureInformation = report.AfterFailureInformation__c;
            res.Delay15Min = report.Delay15Min__c;
            res.InformationFrom = report.InformationFrom__c;
            res.FailureQInHospital = report.FailureQInHospital__c;
            res.DelayReportReason = report.DelayReportReason__c;
            res.ProductFailureRelated = report.IsProductFaultRelated__c;
//deloitte-zhj 20231129 PIPL还原 start
            res.engineerSendDateTime = DateTime.newInstance(report.LogisticsSendDate__c, Time.newInstance(0, 0, 0, 0));
            //deloitte-zhj 20231129 PIPL还原 end
            res.engineerSendDate = report.LogisticsSendDate__c;
            //lwt 20240301 避免js自动计算时差 start
            if(report.LogisticsSendDate__c!=null){
                res.engineerSendDateStr = report.LogisticsSendDate__c.year()+'-'+ report.LogisticsSendDate__c.month()+'-'+report.LogisticsSendDate__c.day();
            }
            //lwt 20240301 避免js自动计算时差 end
            res.DeliveryLogisticsNo = report.OrderNumber__c;
            res.IfDeadHurt = report.IfDeadHurt__c;
            res.ReturnWayType = report.ReturnWayType__c;
            res.ProblemOccurred = report.ProblemOccurred__c;
            res.DateReceiptQuestions = report.DateReceiptQuestions__c;
            res.AccountName =  report.Hospital__r.name; // WYL 贸易合规2期 add
            res.state = report.Hospital__r.TradeComplianceStatus__c; // WYL 贸易合规2期 add
            res.currentDate = Date.today();
            if (report.ApplicationTime__c!=null) {
                  res.ApplicationTime = report.ApplicationTime__c.date();
            }
 
            //deloitte-zhj 20231206 PIPL还原带上直返地址信息
            res.ReturnedPersonName = report.ReturnedPersonName__c;
            res.ReturnedPersonPhone = report.ReturnedPersonPhone__c;
            res.ReturnedCustomer = report.ReturnedCustomer__c;
            res.ReturnedCity = report.ReturnedCity__c;
            res.ReturnedAddress = report.ReturnedAddress__c;
            res.ReturnedZipCode = report.ReturnedZipCode__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }  
 
    @AuraEnabled
    public static String getNeedParm1(){
        String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
        return baseUrl;
    }
 
  //   @AuraEnabled
  //   public static String init(){
  //       String reportid;
  //       Report r = new Report();
  //       List<Report> rs = new List<Report>();
  //       rs=[Select id,DeveloperName,Name,NamespacePrefix from Report Where DeveloperName='Set_Product_Detail'];
  //       if (rs.size()>0){
  //           //system.debug('DeveloperName=' + rs[0].DeveloperName);
  //           //system.debug('Name=' + rs[0].Name);
  //           //system.debug('NamespacePrefix=' + rs[0].NamespacePrefix);
  //           reportid = rs[0].id;
  //           reportid = reportid.substring(0,15);
  //       }
  //       return reportid;
  // }
 
  @AuraEnabled
  public static List<SSPLine> getData(String SearchName , String SearchNo , String SearchSN){
    String searchSql = 'Select id,Account.RecordType.DeveloperName, product2.PartSupplyFinishDate__c,Department_Class__c,name,Account.id,Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c,Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c,Hospital__r.id, SerialNumber,HP_Name__c,Department_Name__c,Posting_Date__c,Extend_Gurantee_DateTo__c,CurrentContract_End_Date__c from Asset ';
    String whereStr = 'Where  id !=null AND Repairing_Count__c = 0  ';
    String whereSql = '';
    String SearchNameTrim;
    String SearchNoTrim;
    String SearchSNTrim;
    if (String.isNotBlank(SearchName)) {
         SearchNameTrim = SearchName.trim();
    }
    if (String.isNotBlank(SearchNo)) {
         SearchNoTrim = SearchNo.trim();
    }
    if (String.isNotBlank(SearchSN)) {
         SearchSNTrim = SearchSN.trim();
    }
    if(SearchNameTrim != null && SearchNameTrim != ''){
      whereSql += 'and HP_Name__c Like ' + '\'%' + SearchNameTrim + '%\' ';
    }
 
    if(SearchNoTrim != null && SearchNoTrim != ''){
      whereSql += 'and OwnershipMachine_No__c Like' + '\'%' + SearchNoTrim + '\'';
    }
 
    if(SearchSNTrim != null && SearchSNTrim != ''){
      whereSql += 'and SerialNumber like ' + '\'%' + SearchSNTrim + '%\' ';
    }
    searchSql = searchSql + whereStr + whereSql;
    //查询太久
    // searchSql += ' order by Posting_Date__c limit 30';
    if (whereSql !=null && whereSql !='') {
        searchSql += ' limit 10';
    }else{
        searchSql += ' limit 100';
    }
    
 
 
    List<Asset> cl = new List<Asset>();
 
    cl = Database.query(searchSql);
    List<SSPLine> activities = New List<SSPLine>();
 
    for(Asset psl : cl){
        SSPLine a = new SSPLine(psl);
        activities.add(a);
        
    }
    return activities;
  }
 
  @AuraEnabled
  public static List<SSPLine> getDatainit(String SearchName , String SearchNo , String SearchSN){
    String searchSql = 'Select id,Account.RecordType.DeveloperName, product2.PartSupplyFinishDate__c,Department_Class__c,name,Account.id,Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c,Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c,Hospital__r.id, SerialNumber,HP_Name__c,Department_Name__c,Posting_Date__c,Extend_Gurantee_DateTo__c,CurrentContract_End_Date__c from Asset ';
    String whereStr = 'Where  id !=null AND Repairing_Count__c >= 0  ';
    String whereSql = '';
    String SearchNameTrim;
    String SearchNoTrim;
    String SearchSNTrim;
    if (String.isNotBlank(SearchName)) {
         SearchNameTrim = SearchName.trim();
    }
    if (String.isNotBlank(SearchNo)) {
         SearchNoTrim = SearchNo.trim();
    }
    if (String.isNotBlank(SearchSN)) {
         SearchSNTrim = SearchSN.trim();
    }
    if(SearchNameTrim != null && SearchNameTrim != ''){
      whereSql += 'and HP_Name__c Like ' + '\'%' + SearchNameTrim + '%\' ';
    }
 
    if(SearchNoTrim != null && SearchNoTrim != ''){
      whereSql += 'and OwnershipMachine_No__c Like' + '\'%' + SearchNoTrim + '\'';
    }
 
    if(SearchSNTrim != null && SearchSNTrim != ''){
      whereSql += 'and SerialNumber like ' + '\'%' + SearchSNTrim + '%\' ';
    }
    searchSql = searchSql + whereStr + whereSql;
    //查询太久
    // searchSql += ' order by Posting_Date__c limit 30';
    if (whereSql !=null && whereSql !='') {
        searchSql += ' limit 10';
    }else{
        searchSql += ' limit 100';
    }
    
 
 
    List<Asset> cl = new List<Asset>();
 
    cl = Database.query(searchSql);
    List<SSPLine> activities = New List<SSPLine>();
 
    for(Asset psl : cl){
        SSPLine a = new SSPLine(psl);
        activities.add(a);
        
    }
    return activities;
  }
 
  @AuraEnabled
  public static List<SSPLine> getDataNone(String SearchName , String SearchNo , String SearchSN){
    String searchSql = 'Select id, Account.RecordType.DeveloperName,Account.Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c,product2.PartSupplyFinishDate__c,Department_Class__c,name,Account.id,Account.Parent.FSE_SP_Main_Leader__r.Work_Location__c,Hospital__r.id, SerialNumber,HP_Name__c,Department_Name__c,Posting_Date__c,Extend_Gurantee_DateTo__c,CurrentContract_End_Date__c from Asset ';
    String whereStr = 'Where  id !=null AND Repairing_Count__c >= 0  ';
    String whereSql = '';
    String SearchNameTrim;
    String SearchNoTrim;
    String SearchSNTrim;
    if (String.isNotBlank(SearchName)) {
         SearchNameTrim = SearchName.trim();
    }
    if (String.isNotBlank(SearchNo)) {
         SearchNoTrim = SearchNo.trim();
    }
    if (String.isNotBlank(SearchSN)) {
         SearchSNTrim = SearchSN.trim();
    }
    if(SearchNameTrim != null && SearchNameTrim != ''){
      whereSql += 'and HP_Name__c Like ' + '\'%' + SearchNameTrim + '%\' ';
    }
 
    if(SearchNoTrim != null && SearchNoTrim != ''){
      whereSql += 'and OwnershipMachine_No__c like' + '\'%'+ SearchNoTrim + '\'';
    }
 
    if(SearchSNTrim != null && SearchSNTrim != ''){
      whereSql += 'and SerialNumber like ' + '\'%' + SearchSNTrim + '%\' ';
    }
    searchSql = searchSql + whereStr + whereSql;
    //查询太久
    // searchSql += ' order by Posting_Date__c limit 30';
    searchSql += ' limit 10';
    
 
 
    List<Asset> cl = new List<Asset>();
 
    cl = Database.query(searchSql);
    List<SSPLine> activities = New List<SSPLine>();
 
    for(Asset psl : cl){
        SSPLine a = new SSPLine(psl);
        activities.add(a);
        
    }
    return activities;
  }
 
 
}