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
public with sharing class buttonAssetCtl {
    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try{
            Asset report =  [SELECT Product2Id,Order_No__c,SerialNumber,Asset_day__c,Posting_Date__c,InstallDate,Asset_Owner__c,AssetMark__c,Id,NoPartRiskDate_F__c,Product_ID__c,AccountId,HP_Id__c,Hospital__c,Hospital__r.Id,Hospital__r.name,Department_Class__c,Department_Class__r.Id,Name
            //WYL 贸易合规2期 add start
            ,Hospital__r.TradeComplianceStatus__c,Product2.Asset_Model_No__c
            //WYL 贸易合规2期 add end
             FROM Asset WHERE Id =: recordId LIMIT 1];
            //20231108 ymh add strat
            Product2 product =[SELECT id,PartSupplyFinishDate__c
              //WYL 贸易合规2期 add start
                ,USRatio_US_OUT10__c,CountryOfOrigin__c,ProTradeComplianceStatus__c 
                //WYL 贸易合规2期 add end 
                 from Product2 WHERE Id =: report.Product2Id];
             //20231108 ymh add end
            System.debug(LoggingLevel.INFO, '*** opp: ' + report);
 
            res.AssetMarkC = report.AssetMark__c;
            res.AssetOwnerC = report.Asset_Owner__c;
            res.InstallDate = report.InstallDate;
            res.PostingDateC = report.Posting_Date__c;
            res.AssetDayC = report.Asset_day__c;
            res.SerialNumber = report.SerialNumber;
            res.OrderNoC = report.Order_No__c;
 
 
            res.Id = report.Id;
            res.Name = report.Name;
            res.NoPartRiskDateFC = report.NoPartRiskDate_F__c;
            res.ProductIDC = report.Product_ID__c;
            res.AccountId = report.AccountId;
            res.HPIdC = report.HP_Id__c;
            res.HospitalC = report.Hospital__c;
            res.HospitalN = report.Hospital__r.name;
            res.DepartmentClassC = report.Department_Class__c;
            res.HospitalId = report.Hospital__r.Id;
            res.DepartmentClassId = report.Department_Class__r.Id;
            //20231108 ymh add strat
            res.partSupplyFinishDate = product.PartSupplyFinishDate__c;
            //20231108 ymh add end
            //WYL 贸易合规2期 add start
            res.hosTradeComplianceStatus = report.Hospital__r.TradeComplianceStatus__c;
            res.ProductCompliance = product.ProTradeComplianceStatus__c;
            res.Asset_Model_No = report.Product2.Asset_Model_No__c;
            res.state = report.Hospital__r.TradeComplianceStatus__c;
            //WYL 贸易合规2期 add end
            res.userID = UserInfo.getUserId();
 
            res.day = Date.today();
            res.day1 = Date.today().addDays(-10);
            res.day2 = Date.today().addDays(+365);
         res.notCreateRepairFromAssetButton=   System.Label.notCreateRepairFromAssetButton;
         res.notCreateRepairFromAssetButton02=   System.Label.notCreateRepairFromAssetButton02;
 
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
            if (System.Test.isrunningTest()) {
                throw new ControllerUtil.myException('test。');
            }
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }   
 
    // 查找UserName
    @AuraEnabled
    public static List<User> initUserName(String userId){
        List<User> res = new List<User>();
        try{
            res = [SELECT Id,name,RepairSalesPoint_Province_China__c,Employee_No__c FROM User WHERE Id=: userId ];
            if (System.Test.isrunningTest()) {
                throw new ControllerUtil.myException('test。');
            }
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }
    
     //查询Account修理画面“修理品返送地”问题调查-后续 
     @AuraEnabled
     public static List<Account> selecctAccountBySegmentId(String segmentId){
         try {
           List<Account> accounts = [SELECT id,ParentId,Parent.RecordTypeId, Parent.Parent.FSE_GI_Main_Leader__r.Work_Location__c,Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c FROM Account WHERE Id=:segmentId];
           return accounts;
           
       } catch (Exception e) {
             throw new AuraHandledException(e.getMessage());
          }
      }
 
      //查询Product2
    @AuraEnabled
    public static List<Product2> selecctProduct2ById(String Id){
        try {
          List<Product2> accounts = [SELECT id,Name,Can_Repair__c from Product2 where ID=:Id];
          return accounts;
          
      } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
         }
     }
 
     //查询QIS_Report__c
    @AuraEnabled
    public static List<QIS_Report__c> selecctQISReportByFomatToday(String AssetId,Date fomatToday){
        try {
          List<QIS_Report__c> accounts = [SELECT id,Name,QIS_Submit_day__c from QIS_Report__c where nonyushohin__c=:AssetId and QIS_Submit_day__c != null and QIS_Submit_day__c >=:fomatToday];
          return accounts;
          
      } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
         }
     }
 
     //查询Repair__c
    @AuraEnabled
    public static List<Repair__c> selecctRepairByFomatToday(String AssetId, Date fomatToday){
        try {
          List<Repair__c> accounts = [SELECT Name from Repair__c where Delivered_Product__c =:AssetId and Status2__c!='00.删除' and Status2__c!='00.取消' and FSE_ApplyForRepair_Day__c >=: fomatToday order by FSE_ApplyForRepair_Day__c desc limit 1];
          return accounts;
          
      } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
         }
     }
 
     @AuraEnabled
     public static List<QIS_Report__c> selecctQISReportrByFomatToday(String AssetId, Date fomatToday){
         try {
           List<QIS_Report__c> accounts = [SELECT id,QIS_Submit_day__c from QIS_Report__c where nonyushohin__c=:AssetId and QIS_Submit_day__c != null and QIS_Submit_day__c >=: fomatToday];
           return accounts;
           
       } catch (Exception e) {
             throw new AuraHandledException(e.getMessage());
          }
      }
 
         //查询Repair__c
    @AuraEnabled
    public static List<Account> selecctAccountByAccountId(String AccountId){
        try {
          List<Account> accounts = [SELECT id,Parent.RecordTypeId, Parent.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=: AccountId];
          return accounts;
          
      } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
         }
     }
 
     @AuraEnabled
     public static String  selectCASE(String AssetOwnerC){
        String res='';
        if(AssetOwnerC.equals('病院資産')){
            res='病院資産';
        }else if(AssetOwnerC.equals('购买')){
            res='购买';
        }
        else if(AssetOwnerC.equals('Olympus')){
            res='Olympus';
        }
        else if(AssetOwnerC.equals('备品')){
            res='备品';
        }
        else if(AssetOwnerC.equals('リース会社')){
            res='リース会社';
        }
        else if(AssetOwnerC.equals('其他')){
            res='其他';
        }
        else if(AssetOwnerC.equals('经销商资产')){
            res='经销商资产';
        }else{
            res='';
        }
        return res;
      }
 
      @AuraEnabled
      public static String selectNullvalue(String InstallDate,String PostingDateC,String AssetDayC){
        String res='';
        if(InstallDate!=null){
            res=InstallDate;
        }else {
            if(PostingDateC!=null){
                res=PostingDateC;
            }else {
                res=AssetDayC;
            }
        }
        return res;
       }
    // WYL 贸易合规2期 发送邮件 add  start
     //邮件通知人员:恽经理、FSE担当
    @AuraEnabled
    public static Boolean accSendEmailFW(String accname,String mcid,String type,String state,String Asset_Model_No,String useremail,String FseEmail) {
        //发送邮件
        List<Messaging.SingleEmailMessage> sendMails = new List<Messaging.SingleEmailMessage>();
        List<String>  MailsList = new List<String>();
        String myUserID = UserInfo.getUserId();
        User currentUser = [SELECT email,Name FROM user Where Id = :myUserID];
 
        MailsList.add('olympus@prec-tech.com');
        // MailsList.add('Lina_Yun@olympus.com.cn');
        MailsList.add(System.Label.LegalDepartmentEmail);
 
        if (useremail!= null && useremail != '') {
            MailsList.add(useremail);
        }
        // fse 担当
        String fseName = '';
 
        if (FseEmail!= null && FseEmail != '') {
            User FseUser = [SELECT email,Name FROM user Where id = :FseEmail limit 1];
            fseName = FseUser.name;
            MailsList.add(FseUser.email);
        }else {
            MailsList.add(currentUser.email);
            fseName = currentUser.name;
        }
 
        if (MailsList!=null&&MailsList.size()>0){
            String title = '';
            String body = '';
            //title = '医院/经销商涉及黑名单';
            String accname1 = accname==null ? '' :accname; // 医院
            if (type == '1') {
                title = '【贸易合规】'+accname1+'涉及'+state;
                body += state+'的客户为:' + accname1 + '<br/>';
                body += '<a href="' + System.Label.Environment_Url + mcid + '">'
                        + System.Label.Environment_Url+ mcid +'</a><br/>'; 
                body += '谢谢!';
            }else {
                body += '医院或经销商名称:'+accname1+'<br/>';
                body += '医院或经销商状态:'+state+'<br/>';
                User currentUser2 = null;
                if(useremail!= null && useremail != ''){
                     currentUser2 = [SELECT email,Name FROM user Where email = :useremail limit 1];
                }else {
                    currentUser2 = [SELECT email,Name FROM user Where id = :myUserID limit 1];
                }
                if (type == '2' ) {
                    title = '【贸易合规】--保有设备新建QIS涉及警示产品';
                    body += 'FSE担当(操作人):'+fseName+'<br/>';
                }else if (type == '3') {
                    title = '【贸易合规】--提交QIS涉及警示产品';
                    body += 'FSE担当(操作人):'+fseName+'<br/>';
                }else if (type == '4') {
                    title = '【贸易合规】--OCSM判定提交待审批涉及警示产品';
                    body += 'OCSM判定担当(操作人):'+currentUser2.name+'<br/>';
                }else if (type == '5') {
                    title = '【贸易合规】--OSH判定提交待审批1涉及警示产品';
                    body += 'OSH判定担当(操作人):'+currentUser2.name+'<br/>';
                }else if (type == '6') {
                    title = '【贸易合规】--发送QIS至SPO涉及警示产品';
                    body += 'FSE担当(操作人):'+fseName+'<br/>';
                }else if (type == '7') {
                    title = '【贸易合规】--QIS新建修理涉及警示产品';
                    body += 'OCSM判定担当(操作人):'+currentUser2.name+'<br/>';
                } else if (type == '8') {
                    title = '【贸易合规】--申请修理涉及警示产品';
                    body += 'FSE担当(操作人):'+fseName+'<br/>';
                }  else if (type == '9') {
                    title = '【贸易合规】--报修子单申请修理涉及警示产品';
                    body += 'FSE担当(操作人):'+fseName+'<br/>';
                } 
                
               
                body += '涉及的警示产品型号:'+Asset_Model_No+'<br/>';
                
            }
            
  
            Messaging.SingleEmailMessage messageNEW = new Messaging.SingleEmailMessage();
            messageNEW.setSubject(title);
            messageNEW.setHtmlBody(body);
            messageNEW.setCharset('UTF-8');
            messageNEW.setToAddresses(MailsList); 
            
            sendMails.add(messageNEW);
 
        }
        boolean rs = true;
        if (sendMails.size() > 0) {
            Messaging.Email[] allMails = new Messaging.Email[]{};
            for(Integer j = 0; j < sendMails.size(); j++) {
                allMails.add(sendMails.get(j));
            }
            system.debug('222===:'+allMails);
        
            Messaging.SendEmailResult[] results = Messaging.sendEmail(allMails);
            System.debug('results 结果 :'+results);
            for (Integer i = 0; i < results.size(); i++) {
                if (results[i].success == false) {
                    system.debug('=====send mail error:' + results[i].errors[0].message);
                    rs = false;
                }   
            }
        }
        return rs;      
    }
     // WYL 贸易合规2期 发送邮件 add  end
    public class InitData{
        @AuraEnabled
        public String AssetMarkC;
        @AuraEnabled
        public String AssetOwnerC;
        @AuraEnabled
        public Date InstallDate;
        @AuraEnabled
        public Date PostingDateC;
        @AuraEnabled
        public Date AssetDayC;
        @AuraEnabled
        public String SerialNumber;
        @AuraEnabled
        public String OrderNoC;
 
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public String userID;
        @AuraEnabled
        public Date day;
        @AuraEnabled
        public Date day2;
        @AuraEnabled
        public Date day1;
        @AuraEnabled
        public String Name;
        @AuraEnabled
        public Date NoPartRiskDateFC;
        @AuraEnabled
        public String ProductIDC;
        @AuraEnabled
        public String AccountId;
        @AuraEnabled
        public String HPIdC;
        @AuraEnabled
        public String HospitalC;
        @AuraEnabled
        public String DepartmentClassC;
        @AuraEnabled
        public String HospitalId;
        @AuraEnabled
        public String DepartmentClassId;
        @AuraEnabled
        public String notCreateRepairFromAssetButton;
        @AuraEnabled
        public String notCreateRepairFromAssetButton02;
         //20231108 ymh add strat
         @AuraEnabled
        public Date partSupplyFinishDate;
         //20231108 ymh add end
        //WYL 贸易合规2期 start
         @AuraEnabled
         public String hosTradeComplianceStatus;
         @AuraEnabled
         public String ProductCompliance;
         @AuraEnabled
         public String HospitalN;
         @AuraEnabled
         public String Asset_Model_No;
         @AuraEnabled
         public String state;
          //WYL 贸易合规2期 end
     }
}