黄千龙
2023-08-07 aa7cab63bcc29d8a1cb4667bc982814fc28970e5
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
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 Date Posting_Date;
        @AuraEnabled
        public Date Extend_Gurantee_DateTo;
        @AuraEnabled
        public Date CurrentContract_End_Date;
 
 
        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;
            Hospital = psl.Hospital__r.id;
            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;
            }
            SerialNumber= psl.SerialNumber;
            HP_Name = psl.HP_Name__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 StatusC;
        @AuraEnabled
        public String OwnerId;
        @AuraEnabled
        public String Repair_Detail;
        @AuraEnabled
        public Date FaultTime;
        @AuraEnabled
        public String RepairApplicantName;
        @AuraEnabled
        public String HPname;
        @AuraEnabled
        public String DepName;
        @AuraEnabled
        public Date RepairsReportDate;
        @AuraEnabled
        public Date ReceiverTime;
        @AuraEnabled
        public Date PlannedVisitDay;
        @AuraEnabled
        public Date ActualVisitDateFirst;
         @AuraEnabled
        public Date ActualVisitDateSecon;
         @AuraEnabled
        public Date ActualVisitDateThird;
         @AuraEnabled
        public Date ApplicationTime;
     }
 
     public class AssData{
        @AuraEnabled
        public String canRepair;
     }
 
     @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 
                        from Product2 where 
                        ID = :ass[0].Product_ID__c];
        if (p2[0].Can_Repair__c != null) {
            res.canRepair = p2[0].Can_Repair__c;
        }
        return res;
    }
    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try{
            RepairSubOrder__c report =  [SELECT Id,ApplicationTime__c,ActualVisitDateThird__c,ActualVisitDateSecon__c,ActualVisitDateFirst__c,PlannedVisitDay__c,ReceiverTime__c,RepairsReportDate__c,Status__c,Department__r.Name,Hospital__r.name,RepairApplicantName__c,OwnerId,ResponseResultDesc__c,FaultTime__c FROM RepairSubOrder__c WHERE Id =: recordId LIMIT 1];
            System.debug(LoggingLevel.INFO, '*** opp: ' + report);
            res.Id = report.Id;
            res.StatusC = report.Status__c;
            res.OwnerId = report.OwnerId;
            res.Repair_Detail = report.ResponseResultDesc__c;
            if (report.FaultTime__c!=null) {
                res.FaultTime = report.FaultTime__c.date();
            }
            res.RepairApplicantName = report.RepairApplicantName__c;
            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;
            if (report.ApplicationTime__c!=null) {
                  res.ApplicationTime = report.ApplicationTime__c.date();
            }
            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, 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  ';
    String whereSql = '';
 
    if(SearchName != null && SearchName != ''){
      whereSql += 'and HP_Name__c Like ' + '\'%' + SearchName + '%\' ';
    }
 
    if(SearchNo != null && SearchNo != ''){
      whereSql += 'and OwnershipMachine_No__c =\'' + SearchNo + '\'';
    }
 
    if(SearchSN != null && SearchSN != ''){
      whereSql += 'and SerialNumber like ' + '\'%' + SearchSN + '%\' ';
    }
    searchSql = searchSql + whereStr + whereSql;
 
    searchSql += ' order by Posting_Date__c 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;
  }
 
 
}