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
public with sharing class buttonQISReportCtl {
    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try{
            QIS_Report__c report =  [SELECT Source_OnCall__r.Id,nonyushohin__r.Id,Hospital_Department__r.Id,Hospital__r.Id,source_for_repair__c,Trable_occur_daY_collect__c,nonyushohin__c,Hospital_Department__c,Department_Class__c,Department_Class__r.Id,Source_OnCall__c,HP_ID__c,Special_follow__c,next_action__c,Hospital__c,is_CNBuy__c,isPAE_Profile__c,isAE_Profile__c,Name,QIS_Status__c,PAE_DetermineAC__c,AE_DetermineResult__c,ETQ_UPLOAD_STATUS__c,QIS_final_judgement__c,OCM_judgement__c,PAE_Determine__c,Id FROM QIS_Report__c WHERE Id =: recordId LIMIT 1];
            res.Hospital = report.Hospital__c;
            res.HospitalId = report.Hospital__r.Id;
            res.nextAction = report.next_action__c;
            res.SpecialFollow = report.Special_follow__c;
            res.HPID = report.HP_ID__c;
            res.SourceOnCallId = report.Source_OnCall__r.Id;
            res.SourceOnCall = report.Source_OnCall__c;
            res.DepartmentClassId = report.Department_Class__r.Id;
            res.DepartmentClass = report.Department_Class__c;
            res.HospitalDepartment = report.Hospital_Department__c;
            res.HospitalDepartmentId = report.Hospital_Department__r.Id;
            res.nonyushohin = report.nonyushohin__c;
            res.nonyushohinId = report.nonyushohin__r.Id;
            res.TrableOccurDaYCollect = report.Trable_occur_daY_collect__c;
            res.sourceForRepair = report.source_for_repair__c;
        
            
            res.PAEDetermineC = report.PAE_Determine__c;
            res.PAEDetermineACC = report.PAE_DetermineAC__c;
            res.OCMJudgementC = report.OCM_judgement__c;
            res.QISFinalJudgementC = report.QIS_final_judgement__c;
            res.ETQUPLOADSTATUSC = report.ETQ_UPLOAD_STATUS__c;
            res.AEDetermineResultC = report.AE_DetermineResult__c;
            res.Id = report.Id;
            res.Name = report.Name;
            res.QISStatusC = report.QIS_Status__c;
 
            res.isAEProfileC = report.isAE_Profile__c;
            res.isCNBuyC = report.is_CNBuy__c;
            res.isPAEProfileC = report.isPAE_Profile__c;
            res.userId = UserInfo.getUserId();
            res.email = UserInfo.getUserEmail();
            res.profileId = UserInfo.getProfileId();
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }   
 
     // 根据ID修理报价提交
     @AuraEnabled
     public static String updateOSHNogoods(String Id,String email,String userId){
        List<User> user = new List<User>();
        user = [SELECT Id,Alias,Alias__c from User where id = :userId];
 
        String res ='';
        try {
           QIS_Report__c rac = new QIS_Report__c();
           rac.Id = Id;
           rac.QIS_Status__c = 'OSH检测中';
           rac.OSHRecievedDate__c = Date.today(); 
           rac.OSH_Receive_staff__c = user[0].Alias;
           rac.OSH_staff__c = user[0].Alias;
           rac.OSH_staff_email__c = email;
           rac.Is_ProductGot__c = true;
           rac.OSH_GotProductPeople__c = userId;
          
           List<User> records = new List<User>();
           records = [SELECT Id, JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c FROM User WHERE Id=: userId ];
           if (records != null && records.size() > 0 && records[0].JingliApprovalManager__c != null&& records[0].BuchangApprovalManager__c != null) {
           rac.OSH_Manager__c= records[0].JingliApprovalManager__c;
           rac.OSH_Buzhang__c= records[0].BuchangApprovalManager__c;
           } else {
           rac.OSH_Manager__c= userId;
           rac.OSH_Buzhang__c= userId;
           }
           rac.OSHInspectionDate__c = Date.today(); 
           rac.OSH_Nogoods__c = true;
            update rac;
        } catch (Exception e) {
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
            if (e.getMessage().contains(':')){
                String eMessage = e.getMessage();
                Integer left = eMessage .indexof(',')+1 ;
                Integer right = eMessage.indexof('[')-2;
                res =  eMessage.substring(left,right);
            }else {
                res  = e.getMessage();
            }
            // res = e.getDmlMessage(0);
        }
        return res;
     }
 
     @AuraEnabled
     public static  String sendToETQ(String iflog_Id,BatchIF_Log__c rowDataSFDC, List<String> repairIds,String statu){
        List<QIS_Report__c> temp = [select id from QIS_Report__c where id in :repairIds ];
        if(temp != null && temp.size() > 0){
            try {
                if (!Test.isRunningTest()) {
                    Database.executeBatch(new QISToPDFBatch(iflog_Id, rowDataSFDC,repairIds,statu),50); //生成PDF
                }
            }
            catch (Exception e) {
                return '更新QIS报错:'+ e.getMessage();
            }
        }else{
            BatchIF_Log__c iflog = new BatchIF_Log__c();
            iflog.Type__c = 'sendToETQ';
            iflog.ErrorLog__c = '';
            iflog.Log__c = 'NFM401WebService start--';
 
            Repair__c updateRe = new Repair__c();
            updateRe.Id = repairIds[0];
            updateRe.INTERFACE_RECORD_ID__c = null; 
            updateRe.ETQ_UPLOAD_STATUS__c = null; 
            updateRe.ETQ_UPLOAD_MESSAGE__c = null; 
            updateRe.OSH_ConfirmationDate__c = Date.today(); 
            updateRe.OSH_Affirmant__c = UserInfo.getUserId(); 
            updateRe.AWS_Interface_Time__c = Datetime.now();
            updateRe.AsyncData__c = true; 
            try{
                update updateRe;
                if (!Test.isRunningTest()) {
                    Database.executeBatch(new RepairToPDFBatch(iflog_Id, rowDataSFDC,repairIds,statu)); //生成PDF
                }
                iflog.Log__c += '\n修理:'+updateRe+' 更新成功';
                iflog.Log__c = '\nNFM401WebService end--';
                insert iflog;
            }catch(Exception ex){
                iflog.ErrorLog__c += '修理:'+updateRe+' 更新失败,因为::'+ex.getMessage();
                iflog.Log__c = '\nNFM401WebService end--';
                insert iflog;
                return '更新修理报错:'+ ex.getMessage();
            }
        }
        return '发送成功!';
    }
 
     // 根据ID修理报价提交
     @AuraEnabled
     public static String updateQISReportC(String QId,String uid){
        try {
            QIS_Report__c rac = new QIS_Report__c();
            rac.Id = QId;
            rac.INTERFACE_RECORD_ID__c = null;
            rac.ETQ_UPLOAD_STATUS__c = null;
            rac.ETQ_UPLOAD_MESSAGE__c = null;
            rac.AsyncData__c = true;
            rac.AWS_Interface_Time__c = Datetime.now();
            rac.OSH_ConfirmationDate__c = Date.today(); 
            rac.OSH_Affirmant__c = uid;
             update rac;
            return '更新成功!';
         } catch (Exception e) {
             if (e.getMessage().contains(':')){
                String eMessage = e.getMessage();
                Integer left = eMessage .indexof(',')+1 ;
                Integer right = eMessage.indexof('[')-2;
                return eMessage.substring(left,right);
            }else {
                return  e.getMessage();
            }
            // return e.getDmlMessage(0);
         }
     }
 
     // 根据ID修理报价提交
     @AuraEnabled
     public static List<QIS_Report__c> selectQISReportC(String QId){
        List<QIS_Report__c> res = new List<QIS_Report__c>();
        try {
            res = [SELECT Id,AsyncData__c,Complaint_Number__c,ETQ_UPLOAD_STATUS__c from QIS_Report__c where Id=: QId ];          
         } catch (Exception e) {
             System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
         return res;
     }
 
        // 根据ID修理报价提交
        @AuraEnabled
        public static String updateQisForRCRecieved(String QId,String uid){
            String res='';
           try {
                List<User> user = new List<User>();
                user = [SELECT Id,Alias,Alias__c from User];
 
                System.debug('The value of user is: ' + user);
 
               QIS_Report__c rac = new QIS_Report__c();
               rac.Id = QId;
                rac.QIS_Status__c = 'RC检测中';
                rac.OCM_RC_RecievedDate__c = Date.today();
                rac.RC__c = uid;
                rac.RC_Receive_staff__c = user[0].Alias;
                List<User> records = new List<User>();
                records = [SELECT  Id, BuchangApprovalManagerSales__c,JingliApprovalManager__c, BuchangApprovalManager__c, ZongjianApprovalManager__c FROM User WHERE Id=: uid ];
                if (records != null && records.size() > 0 && records[0].BuchangApprovalManagerSales__c != null) {
                    rac.RC_Manager__c = records[0].BuchangApprovalManagerSales__c;
                } else {
                    rac.RC_Manager__c = uid;
                }
                rac.CDS_date__c = Date.today();
                rac.RC_CDS_staff__c = user[0].Alias__c;
                rac.OCSM_Nogoods__c = true;
                update rac;
            } catch (Exception e) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
               if (e.getMessage().contains(':')){
                    String eMessage = e.getMessage();
                    Integer left = eMessage .indexof(',')+1 ;
                    Integer right = eMessage.indexof('[')-2;
                    res =  eMessage.substring(left,right);
                }else {
                    res  = e.getMessage();
                }
                // res =  e.getDmlMessage(0);
            }
            return res;
        }
 
         // 查找简档
     @AuraEnabled
     public static String initSelectProfile(String profileId){    //update 20240218 by DTT-亚楠  List<Profile>——>String
         List<Profile> res = new List<Profile>();  
        String profileName = '';  //update 20240218 by DTT-亚楠  
         try{
            res = [SELECT Id,name FROM Profile WHERE Id=: profileId ];
            if (res.size() > 0) {
                profileName = res[0].Name;
            }
         }catch(Exception e){
             System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
        //  return res;
        return profileName; //update 20240218 by DTT-亚楠  
     }
 
      @AuraEnabled
    public static List<Account> selecctAccountByAccountId(String HospitalDepartmentId){
        try {
          List<Account> accounts = [SELECT ParentId,Parent.RecordTypeId, Parent.RecordType_DeveloperName__c,RecordType_DeveloperName__c ,Parent.Parent.FSE_GI_Main_Leader__c, Parent.Parent.FSE_GI_Main_Leader__r.Name,Parent.Parent.FSE_SP_Main_Leader__r.Name,Parent.Parent.FSE_SP_Main_Leader__c,Parent.Parent.FSE_GI_Main_Leader__r.Work_Location__c,Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c FROM Account WHERE ID=: HospitalDepartmentId];
          return accounts;
      } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
         }
     }
 
      // 查找UserName
    @AuraEnabled
    public static List<User> initUserName(String userId){
        List<User> res = new List<User>();
        try{
            res = [SELECT Id,name,RepairSalesPoint_Province_China__c FROM User WHERE Id=: userId ];
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
 
     public class InitData{
        @AuraEnabled
        public String SourceOnCallId;
        @AuraEnabled
        public String nonyushohinId;
        @AuraEnabled
        public String Hospital;
        @AuraEnabled
        public String HospitalId;
        @AuraEnabled
        public String nextAction;
        @AuraEnabled
        public Boolean SpecialFollow;
        @AuraEnabled
        public String HPID;
        @AuraEnabled
        public String SourceOnCall;
        @AuraEnabled
        public String DepartmentClassId;
        @AuraEnabled
        public String DepartmentClass;
        @AuraEnabled
        public String HospitalDepartment;
        @AuraEnabled
        public String nonyushohin;
        @AuraEnabled
        public Date TrableOccurDaYCollect;
        @AuraEnabled
        public String sourceForRepair;
        @AuraEnabled
        public String HospitalDepartmentId;
 
        @AuraEnabled
        public String isAEProfileC;
         @AuraEnabled
        public String isCNBuyC;
         @AuraEnabled
        public String isPAEProfileC;
 
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public String Name;
        @AuraEnabled
        public String QISStatusC;
        @AuraEnabled
        public String userId;
        @AuraEnabled
        public String email;
        @AuraEnabled
        public String profileId;
         @AuraEnabled
        public String PAEDetermineC;
         @AuraEnabled
        public String PAEDetermineACC;
         @AuraEnabled
        public String OCMJudgementC;
         @AuraEnabled
        public String QISFinalJudgementC;
         @AuraEnabled
        public String ETQUPLOADSTATUSC;
         @AuraEnabled
        public String AEDetermineResultC;
 
     }
}