From 2d4a8d2dcad5a17127d2c73c48ddc4b67ec79448 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期三, 06 四月 2022 11:51:58 +0800
Subject: [PATCH] PIPLDeploy0405

---
 force-app/main/default/classes/NFM203Rest.cls |  128 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 117 insertions(+), 11 deletions(-)

diff --git a/force-app/main/default/classes/NFM203Rest.cls b/force-app/main/default/classes/NFM203Rest.cls
index 21b14e3..bbb2c9b 100644
--- a/force-app/main/default/classes/NFM203Rest.cls
+++ b/force-app/main/default/classes/NFM203Rest.cls
@@ -1,6 +1,9 @@
 @RestResource(urlMapping = '/NFM203/*')
 global with sharing class NFM203Rest {
-
+    //add Response to aws 20220221 add sushanhu
+   
+    static Boolean SFStatus=true;
+    static String SFMessage='';
     global class GeDatas {
         public NFMUtil.Monitoring Monitoring;
         public GeData[] Partners;
@@ -78,7 +81,7 @@
         public String BusinessAddress;          //缁忚惀鍦烘墍锛堢瓑鍚屽姙鍏湴鍧�锛�
         //WLIG-CA48WC pk start 2022-1-7
         public String RegisterAddress;          //浣忔墍鍦板潃
-        //WLIG-CA48WC pk end 2022-1-7
+        //WLIG-CA48WC pk end 2022-1-7       
         public String WarehouseAddress;         //搴撴埧鍦板潃
         public String BusinessScope;            //缁忚惀浜岀被鑼冨洿
         public String BusinessScope1;           //缁忚惀涓夌被鑼冨洿
@@ -93,10 +96,16 @@
     // 鏀惰揣浜哄眰绾�
     global class Consignee_Info {
         public String ContactName;
+        public String ContactNameEncrypted;//add 20220221
         public String ContactPhone;
+        public String ContactPhoneEncrypted;//add 20220221 
         public String PostalCode;
+        public String PostalCodeEncrypted;//add 20220221
         public String ContactAddress;
+        public String ContactAddressEncrypted;//add 20220221
         public String ContactCity; //鏈夋晥鏀惰揣浜哄煄甯�
+        public String ContactDataId;// add  20220221 CONTACT aws 瀛樺偍id
+        public String AddressDataId;// add 2020221 adress aws 瀛樺偍id
     }
 
     // 閿�鍞汉灞傜骇
@@ -154,13 +163,18 @@
         // 鍙栧緱鎺ュ彛浼犺緭鍐呭
         String strData = RestContext.request.requestBody.toString();
         GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class);
+        NFMUtil.NFMResponse result = NFMUtil.getNFMResponse();
 
         if (ges == null ) {
+            SFMessage+='鍙傛暟涓虹┖';
+            system.debug('SFMessage---'+SFMessage);
             return;
         }
 
         NFMUtil.Monitoring Monitoring = ges.Monitoring;
         if (Monitoring == null) {
+            SFMessage+='Monitoring涓虹┖';
+            system.debug('SFMessage---'+SFMessage);
             return;
         }
 
@@ -173,7 +187,12 @@
         res.addHeader('Content-Type', 'application/json');
         res.statusCode = 200;
         //String jsonResponse = '{"status": "Success", "Message":'  + gedata + '}';
-        String jsonResponse = '{"status": "Success", "Message":""}';
+        // String jsonResponse = '{"status": "Success", "Message":""}';
+        //updata response toAWS
+        result.SFStatus=SFStatus;
+        result.SFMessage=SFMessage;
+        String jsonResponse =JSON.serialize(result);
+        system.debug('result---'+jsonResponse);
         res.responseBody = blob.valueOf(jsonResponse);
         return;
     }
@@ -263,6 +282,11 @@
 
                     if (String.isNotBlank(result.split('/')[0])) {
                         iflog.ErrorLog__c += result.split('/')[0];
+                        //add response to aws 2022022 sushanhu start
+                        SFMessage=iflog.ErrorLog__c;
+                        system.debug('ErrorLog__c--'+iflog.ErrorLog__c);
+                        system.debug('SFMessage---'+SFMessage);
+                        //add response to aws 20220222 sushanhu end  
                     } else {
                         logstr += result.split('/')[1];
                     }
@@ -270,7 +294,13 @@
                 }
                 //WYAN-BS8B2A -XHL -20200925 -End
                 if (String.isBlank(gda.BPType)) {
+                    
+                  
                     iflog.ErrorLog__c += 'BPCode[ ' + gda.BPCode + ' ] of BPType is required,This data is skipped.\n';
+                    //add response to aws 20220221 sushanhu start
+                    SFMessage=iflog.ErrorLog__c;
+                    system.debug('SFMessage--'+SFMessage);
+                    //add response to aws 20220221 sushanhu end    
                     continue;
                 }
                 if (gda.BPType != '02' && gda.BPType != '03' && gda.BPType != '04' && gda.BPType != '05') {
@@ -278,16 +308,28 @@
                 }
                 if (String.isBlank(gda.BPCode)) {
                     iflog.ErrorLog__c += 'BPCode is required,This data is skipped.\n';
+                    //add response to aws 20220221 sushanhu start
+                    SFMessage=iflog.ErrorLog__c;
+                    system.debug('SFMessage---'+SFMessage);
+                    //add response to aws 20220221 sushanhu end  
                     continue;
                 }
                 if (gda.BPType == '02') {
                     // 缁忛攢鍟嗙殑鍦哄悎
                     if (String.isBlank(gda.CompanyName)) {
                         iflog.ErrorLog__c += 'BPCode[ ' + gda.BPCode + ' ] of CompanyName is required,This data is skipped.\n';
+                        //add response to aws 20220221 sushanhu start
+                        SFMessage=iflog.ErrorLog__c;
+                        system.debug('SFMessage---'+SFMessage);
+                        //add response to aws 20220221 sushanhu end  
                         continue;
                     }
                     if (String.isBlank(gda.AgentType)) {
                         iflog.ErrorLog__c += 'BPCode[ ' + gda.BPCode + ' ] of AgentType is required,This data is skipped.\n';
+                        //add response to aws 20220221 sushanhu start
+                        SFMessage=iflog.ErrorLog__c;
+                        system.debug('SFMessage---'+SFMessage);
+                        //add response to aws 20220221 sushanhu end  
                         continue;
                     }
                     //褰撶粡閿�鍟嗙殑鍒嗙被涓衡�滅壒绾︾粡閿�鍟嗭紙鍖哄煙锛夆�濄�佲�滅壒绾︾粡閿�鍟嗭紙浜у搧锛夆�濄��"鐗圭害缁忛攢鍟嗭紙鍖哄煙+浜у搧锛�"銆�"闆嗛噰缁忛攢鍟�"鏃讹紝楠岃瘉濂戠害鐨勫繀濉瓧娈�
@@ -298,6 +340,10 @@
                             //CHAN-BF8CCU ---XHL---updateEnd---20190821
                             if (String.isBlank(contractInfos.TermContractNo)) {
                                 iflog.ErrorLog__c += 'BPCode[ ' + gda.BPCode + ' ] of TermContractNo is required ,This data is skipped.\n';
+                               //add response to aws 20220221 sushanhu start
+                                SFMessage=iflog.ErrorLog__c;
+                                system.debug('SFMessage---'+SFMessage);
+                                //add response to aws 20220221 sushanhu end  
                                 flg = true;
                                 continue;
                             }
@@ -321,6 +367,10 @@
 
                     applyTypeMap.put(gda.BPCode, gda.ApplyType);
                 }
+                //add result message 20220222 sushanhu satrt
+                    SFMessage=iflog.ErrorLog__c;
+                    system.debug('SFMessage---'+SFMessage);
+                //add result message 20220222 sushanhu end
 
                 bPCodeList.add(gda.BPCode);
                 nfmgd.add(gda);
@@ -403,6 +453,10 @@
                     //鍒ゆ柇BPCode鏄惁宸茬粡瀛樺湪,涓嶅瓨鍦ㄧ殑璇濅細鎻愮ず涓嶅瓨鍦紝骞朵笖璺宠繃
                     if (!accsMap.containsKey(gda.BPCode)) {
                         iflog.ErrorLog__c += ' This BPCode[' + gda.BPCode + '] is not exist,This data is skipped .\n';
+                        //add response to aws 20220221 sushanhu start
+                        SFMessage=iflog.ErrorLog__c;
+                        system.debug('SFMessage---'+SFMessage);
+                        //add response to aws 20220221 sushanhu end  
                         continue;
                     }
                 }
@@ -497,6 +551,9 @@
                     accountInfo.SPO_ApplicationNo__c = GetApplicationNo(gda);
                 }
                 accountUpsertList.add(accountInfo);
+                // //add response to aws 20220221 sushanhu start
+                // SFMessage=iflog.ErrorLog__c;
+                // //add response to aws 20220221 sushanhu end
             }
             // 鏂板缓/鏇存柊瀹㈡埛涓绘暟鎹�
             if (accountUpsertList.size() > 0) {
@@ -580,6 +637,10 @@
                                     } 
                                 } else {
                                     iflog.ErrorLog__c += 'This Contract[ ' + contractInfos.TermContractNo + ' ] not exist,The Data Not  Cancel';
+                                     //add response to aws 20220221 sushanhu start
+                                    SFMessage=iflog.ErrorLog__c;
+                                    system.debug('SFMessage---'+SFMessage);
+                                    //add response to aws 20220221 sushanhu end
                                     continue ;
                                 }
 
@@ -640,6 +701,9 @@
 
                                 if (cdcErrorMap.size() > 0) {
                                     iflog.ErrorLog__c += ' This BPCode[' + gda.BPCode + '] of ContractDepartmentClass [' + cdcErrorMap.values() + '] noneffective, [' + cdcErrorMap.values() + '] skipped .\n';
+                                     //add response to aws 20220221 sushanhu start
+                                    SFMessage=iflog.ErrorLog__c;
+                                    //add response to aws 20220221 sushanhu end
                                 }
                                 contractInfoAcc.Contract_Start_Date__c = NFMUtil.parseStr2Date(contractInfos.ContractStartDate);
                                 contractInfoAcc.Contract_End_Date__c = NFMUtil.parseStr2Date(contractInfos.ContractEndDate);
@@ -805,6 +869,10 @@
 
                     if (String.isBlank(gdds.LicenseType)) {
                         iflog.ErrorLog__c += 'BPCode[ ' + gda.BPCode + ' ] of LicenseType is required ,This data is skipped.\n';
+                        //add response to aws 20220221 sushanhu start
+                        SFMessage=iflog.ErrorLog__c;
+                        system.debug('SFMessage---'+SFMessage);
+                        //add response to aws 20220221 sushanhu end
                         continue;
                     }
                     if (gdds.LicenseType == '23' || gdds.LicenseType == '24') { //3PL鐩稿叧璇�
@@ -812,6 +880,10 @@
                     }
                     if (String.isBlank(gdds.BusLicenseNo)) {
                         iflog.ErrorLog__c += 'BPCode[ ' + gda.BPCode + ' ] of BusLicenseNo is required,This data is skipped .\n';
+                        //add response to aws 20220221 sushanhu start
+                        SFMessage=iflog.ErrorLog__c;
+                        system.debug('SFMessage---'+SFMessage);
+                        //add response to aws 20220221 sushanhu end
                         continue;
                     }
                     geDataDetailsMap.put(gdds.LicenseType, gdds);
@@ -847,6 +919,7 @@
                     licenseInfo.IsFromSPO__c = true;
                     licenseInfo.Scope__c = gdds.BusinessScope;
                     licenseInfo.Scope3__c = gdds.BusinessScope1;
+
                     licenseInfoUpsertList.add(licenseInfo);
 
                     //瀵�"缁忛攢鍟�"涓绘暟鎹腑鐨�"钀ヤ笟璁稿彲璇佷功鐘跺喌"鐨勭浉鍏冲瓧娈佃繘琛岃祴鍊�
@@ -960,11 +1033,20 @@
             logstr += '\nend';
             rowData.retry_cnt__c = 0;
 
+            //add response to AWS 20220221 start
+            SFStatus =true;
+            SFMessage+=logstr;
+            system.debug('SFMessage---'+SFMessage);
+             //add response to AWS 20220221 end
         } catch (Exception ex) {
             Database.rollback(sp);
             System.debug(Logginglevel.ERROR, 'NFM203_' + rowData.MessageGroupNumber__c + ':' + ex.getMessage());
             System.debug(Logginglevel.ERROR, 'NFM203_' + rowData.MessageGroupNumber__c + ':' + ex.getStackTraceString());
             logstr += '\n' + ex.getMessage();
+            //add response to AWS 20220221 start
+            SFMessage+=ex.getMessage();
+            system.debug('SFMessage---'+SFMessage);
+            //add response to AWS 20220221 end
             iflog.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + iflog.ErrorLog__c;
 
             if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0;
@@ -1069,9 +1151,9 @@
             
         for (Consignee_Info consigneeInfo : gda.Consignee_Info) {
             // 鑱旂郴浜哄悕绉�
-            if (String.isBlank(consigneeInfo.ContactName)) {
-                continue;
-            }
+            // if (String.isBlank(consigneeInfo.ContactName)) {
+            //     continue;
+            // }
             // 鑱旂郴浜哄湴鍧�
             if (String.isBlank(consigneeInfo.ContactAddress)) {
                 continue;
@@ -1148,10 +1230,14 @@
                 if (complianceDataMap.containsKey(accountCode)) {
                     // 鑾峰彇瀹㈡埛Id
                     for(Consignee_Info info:complianceDataMap.get(accountCode)){
-                        String accountId = tempAccountMap.get(accountCode).Id;
+                        // add  sushanhu for pi '000000'涓篊onsignee_Info婧愭暟鎹负绌�
+                        if (!'000000'.equals(info.ContactDataId)) {
+                            String accountId = tempAccountMap.get(accountCode).Id;
                         String contactPhone = info.ContactPhone;
                         String contactName = info.ContactName;
-                        String contactAllName = contactAllName(contactName);
+                        // String contactAllName = contactAllName(contactName);
+                        //update to aws contactName 20220221 sushanhu
+                        String contactAllName=info.contactName;
 
                         // 鑱旂郴浜哄瓧娈佃祴鍊�
                         Contact contact  = new Contact();
@@ -1160,27 +1246,47 @@
                         contact.Phone = contactPhone;
                         contact.MobilePhone = contactPhone;
                         contact.LastName = contactAllName.split('_')[0];
-                        contact.FirstName = contactAllName.split('_')[1];
+                        // contact.FirstName = contactAllName.split('_')[1];//delete for pi 20220304 
                         contact.IsFromSPO__c = true;
+                        // SFDC鐢佃瘽閲嶅浜哄憳鍒涘缓淇℃伅纭  pk 2022-2-28 start
+                        contact.RecordTypeId = '01210000000QfWi';
+                        // SFDC鐢佃瘽閲嶅浜哄憳鍒涘缓淇℃伅纭  pk 2022-2-28 end
                         contact.Ignore_Same_Name__c = true;//涓嶆槸閲嶅鐨勫鎴峰悕 璺宠繃 瀹㈡埛浜哄憳鍚嶅瓧宸插瓨鍦� 楠岃瘉
+                        // add pi 瀵嗘枃 start 20220221 sushanhu
+                        contact.Phone_Encrypted__c = info.ContactPhoneEncrypted;
+                        contact.MobilePhone_Encrypted__c = info.ContactPhoneEncrypted;
+                        contact.LastName_Encrypted__c =info.ContactNameEncrypted;
+                        contact.AWS_Data_Id__c = info.ContactDataId;
+                        // add pi 瀵嗘枃 end 20220221 sushanhu
                         insertContactList.add(contact);
-                        
-                        // 鏀惰揣鍦板潃瀛楁璧嬪��
+                        if (!'000000'.equals(info.AddressDataId)) {
+                            // 鏀惰揣鍦板潃瀛楁璧嬪��
                         String contactCity = info.ContactCity;
 
                         Address__c addressData = new Address__c();
                         addressData.Customer__c = accountId;//瀹㈡埛
                         addressData.IsFromSPO__c = true;//鏄惁SPO鏉ユ簮
                         addressData.Telephone__c = contactPhone;//鐢佃瘽
+                        addressData.Telephone_Encrypted__c =info.ContactPhoneEncrypted;//鐢佃瘽瀵嗘枃 add sushanhu for pi 20220304
                         addressData.Address_Classification__c = '缁忛攢鍟�';//鍦板潃鍒嗙被
                         addressData.Detailed_Address__c = info.ContactAddress;//璇︾粏鍦板潃
                         // 鍥犳帴鍙d笉浼犺緭鐪侊紝瀵艰嚧淇濆瓨鏃舵姤閿欍�傚洜姝ゅ皢鍏舵敞鎺�,鍩庡競瀛楁涓嶈祴鍊� XHL 20210823
                         // if (cityMap.containsKey(contactCity)) {
                         //     addressData.City__c = cityMap.get(contactCity).Id;//甯�
                         // }
+                        // add pi 瀵嗘枃 start sushanhu 20220221
+                        addressData.AWS_Data_Id__c =info.AddressDataId;
+                        addressData.Detailed_Address_Encrypted__c =info.ContactAddressEncrypted;
+                        // add pi 瀵嗘枃 end sushanhu 20220221
+
                         String mapkey = accountCode + contactName;
                         insertAddressMap.put(mapkey,addressData);
                         accountCodeList.add(accountCode);
+                       }
+                       
+                        }
+                        
+                        
                     }
                     
                 }

--
Gitblit v1.9.1