From 78ac43791ac9e9d75ce4c33e9dddbdffa88fec2f Mon Sep 17 00:00:00 2001
From: 涂煌豪 <tuhuanghao@prec-tech.com>
Date: 星期一, 23 五月 2022 19:00:04 +0800
Subject: [PATCH] 客户人员重复判断

---
 force-app/main/default/classes/NFM624Rest.cls |  476 ++++++++++++++++++++++++----------------------------------
 1 files changed, 197 insertions(+), 279 deletions(-)

diff --git a/force-app/main/default/classes/NFM624Rest.cls b/force-app/main/default/classes/NFM624Rest.cls
index e1cb52f..6af9655 100644
--- a/force-app/main/default/classes/NFM624Rest.cls
+++ b/force-app/main/default/classes/NFM624Rest.cls
@@ -7,7 +7,7 @@
         
     }
 *************************************************************************/
-
+ 
 @RestResource(urlMapping = '/NFM624/*')
 global with sharing class NFM624Rest {
     //add to AWS 鍥炲 start sushanhu 20220225 
@@ -23,7 +23,7 @@
         public NFMUtil.Monitoring Monitoring;
         public GeData[] GeData;
     }
-
+ 
     global class GeData {
         public String ContactId; //缁熶竴骞冲彴ID//Update to aws 瀛樺偍鐨凙WSContactId 20220225 SUSHANHU
         public String ServiceUserId; //鏈嶅姟骞冲彴鐢ㄦ埛ID
@@ -51,31 +51,31 @@
         public String ApproverID; //瀹℃牳浜哄憳鍛樺伐缂栫爜
         public String DataId;//aws瀛樺偍鍑嵁
     }
-
+ 
     @HttpPost
     global static void execute() {
-
+ 
         // 鍙栧緱鎺ュ彛浼犺緭鍐呭
         String strData = RestContext.request.requestBody.toString();
         GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class);
         system.debug('ges---'+ges);
-
+ 
         if (ges == null) {
             return;
         }
-
+ 
         NFMUtil.Monitoring Monitoring = ges.Monitoring;
         if (Monitoring == null) {
             return;
         }
-
+ 
         BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, LOG_TYPE, ges.GeData);
         system.debug('String.isBlank(rowData.Log__c) == false?');
         if (String.isBlank(rowData.Log__c) == false) {
             System.debug('杩涘叆if鏂规硶锛屾垚鍔熻皟鐢╡xecutefuture');
             executefuture(rowData.Id);
         }
-
+ 
         // JSON銈掓埢銇�
         RestResponse res = RestContext.response;
         res.addHeader('Content-Type', 'application/json');
@@ -92,19 +92,22 @@
          //updata response toAWS 20220225 sushanhu end
         return;
     }
-
-
+ 
+ 
     @future
     global static void executefuture(String rowData_Id) {
         system.debug('杩涘叆executefuture鏂规硶' + rowData_Id);
         main(rowData_Id);
     }
-
+ 
     global static void main(String rowData_Id) {
-
         // Map<String,String> RecordTypeMap = new Map<String,String>();
         // RecordTypeMap.put('','')
+//List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName IN ('Department_OTH','Department_GI', 'Department_BF','Department_GYN','Department_GS','Department_URO','Department_ENT','Department_Class_ET') order by DeveloperName desc];        
         Map < string, string > RecordTypeMap = new Map < string, string > (); //瀛樻斁璁板綍绫诲瀷Id 
+        //for(ID temp : rectDpt){
+        //
+        //}        
         RecordTypeMap.put('鍛煎惛绉�', '01210000000QfmR');
         RecordTypeMap.put('鍏朵粬', '01210000000Qfmb');
         RecordTypeMap.put('濡囩', '01210000000QfmM');
@@ -122,7 +125,7 @@
         iflog.Log__c = logstr;
         iflog.ErrorLog__c = '';
         insert iflog;
-
+ 
         String rowDataStr = NFMUtil.getRowDataStr(rowData);
         List < GeData > GeDataList = (List < GeData > ) JSON.deserialize(rowDataStr, List < GeData > .class);
         if (GeDataList == null || GeDataList.size() == 0) {
@@ -136,7 +139,7 @@
         //         continue;
         //     }
         // }
-
+ 
         Savepoint sp = Database.setSavepoint();
         List<string> ApproverIDList = new List <string>();//
         List < string > PersonManagementCodeList = new List < String > (); //浜哄憳绠$悊缂栫爜List
@@ -144,17 +147,16 @@
         List < String > ManagementList = new List < String > (); //鍖婚櫌銆佺瀹ゅ钩鍙扮紪鐮丩ist
         List < String > StateList = new List < String > ();
         List < String > CityList = new List < String > ();
+        List < String > NameList = new List < String >();
         try { //鏍规嵁浼犺繃鏉ョ殑绠$悊缂栫爜鏌ヨ濡傛灉鍙互鏌ヨ寰楀埌缁撴灉鍒欐洿鏂帮紝鏌ヨ涓嶅埌鍒欐柊澧�
             List < Gedata > newGeDataList = new List < Gedata > ();
             for (Gedata gedata: GeDataList) {
-                //for test
-                gedata.AgentFlag=false;
-                // string dataComplete = verify(gedata);
-                string dataComplete =null;
-                // test  end  for pi
+                string dataComplete = verify(gedata);
+                
                 if (!String.isBlank(dataComplete)) {
                     logstr += dataComplete;
                     rowData.Is_Error__c = 1;
+                    rowData.retry_cnt__c = 0;
                     continue;
                 }
                 if (!gedata.AgentFlag) {
@@ -178,6 +180,9 @@
                 if (string.isnotblank(gedata.PersonManagementCode)) {
                     PersonManagementCodeList.add(gedata.PersonManagementCode);
                 }
+                if(String.isnotBlank(gedata.NameEncrypted)){
+                    NameList.add(gedata.NameEncrypted);
+                }
                 newGeDataList.add(gedata);
                 System.debug('ManagementList'+ManagementList);
                 System.debug('SFDCCodeList'+SFDCCodeList);
@@ -190,62 +195,79 @@
                 for (Address_Level__c temp: statetempList) {
                     StateMap.put(temp.Name, temp.Id);
                 }
-                system.debug('StateMap----->'+StateMap);
                 //鏌ヨ甯傚尯Id 
                 Map < String, String > CityMap = new Map < String, String > (); //甯侻ap
                 List < Address_Level2__c > citytempList = [select Id, Name from Address_Level2__c where Name IN: CityList];
                 for (Address_Level2__c temp: citytempList) {
                     CityMap.put(temp.Name, temp.Id);
                 }
-                system.debug('CityMap----->'+CityMap);
+ 
                 //鏌ヨ鍖婚櫌鎵�鏈変汉
                 Map<string,String> ownerMap = new Map<string,String>();
                 List<User> ownerList = [select Id,Employee_No__c from User where Employee_No__c  IN:ApproverIDList];
                 for(User temp : ownerList){
                     ownerMap.put(temp.Employee_No__c,temp.Id);
                 }
-
+ 
                 //鏌ヨOCSM钀ヤ笟绐楀彛
                 Map<string,Id> OCSMMap = new Map<string,Id>();
                 List<OCM_Management_Province__c> OCSMList = [select Id,Name,Window1__c from OCM_Management_Province__c];
                 for(OCM_Management_Province__c ocsm : OCSMList){
                     OCSMMap.put(ocsm.name,ocsm.Window1__c);
                 }
-
+ 
                 //鏌ヨ鑱旂郴浜�
                 Map < String, Map < String, Contact >> nameMap = new Map < String, Map < String, Contact >> (); //澶栧眰鎴樼暐绉戝锛屽唴灞傜瀹ゅ悕+鑱旂郴浜哄悕
                 List < Contact > peopleList = [select Id, 
-                                                      Account.Name, 
+                                                      Account.Name,
                                                       Department__c, 
+                                                      UnifiedI_Contact_ID__c,
                                                       Account.parent.Name, 
                                                       Account.PlatformCode__c, 
                                                       Account.Management_Code__c, 
                                                       Account.parent.Department_Class_Label__c, 
-                                                      Name,
+                                                      Name,LastName_Encrypted__c,
                                                       Account.Parent_Management_Code__c, 
                                                       Account.Parent_PlatformCode__c, 
-                                                      CManageCode__c,
-                                                      AccountId 
+                                                      CManageCode__c, 
+                                                      AccountId,
+                                                      // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
+                                                      MobilePhone_Encrypted__c
+                                                      // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
                                                       from Contact 
                                                       where CManageCode__c IN: PersonManagementCodeList 
-                                                      OR Account.PlatformCode__c IN: ManagementList
-                                                      OR Account.Management_Code__c IN: SFDCCodeList
-                                                      OR Account.Parent_PlatformCode__c IN: ManagementList 
-                                                      OR Account.Parent_Management_Code__c IN: SFDCCodeList]; //鏍规嵁浜哄憳绠$悊缂栫爜妫�绱㈣仈绯讳汉
+                                                      OR (Account.Parent_PlatformCode__c IN: ManagementList AND LastName_Encrypted__c IN:NameList)
+                                                      OR (Account.Parent_Management_Code__c IN: SFDCCodeList AND LastName_Encrypted__c IN:NameList )
+                                                      ORDER BY  MobilePhone ASC,CManageCode__c ASC]; //鏍规嵁浜哄憳绠$悊缂栫爜妫�绱㈣仈绯讳汉
                 Map < String, Contact > peopleMap = new Map < String, Contact > (); //鑱旂郴浜�
                 system.debug('peopleList  '+peopleList);
                 for (Contact ct: peopleList) {
                     if (string.isnotblank(ct.Account.parent.Name)) {
                         Map < String, Contact > snameMap = new Map < String, Contact > ();
-                        string Name = ct.Name.replaceAll(' ','');
-                        string namekey = ct.Account.Name + ' ' + Name;
+                        string namekey;
+                        string nameKey2;
+                        if(String.isBlank(ct.MobilePhone_Encrypted__c)){
+                           namekey = ct.Account.Name + ' ' + ct.LastName_Encrypted__c.trim();
+                           nameKey2 = ct.Account.Management_Code__c + ' ' + ct.LastName_Encrypted__c.trim();
+                        } else{
+                           namekey = ct.Account.Name + ' ' + ct.LastName_Encrypted__c.trim() + ' ' + ct.MobilePhone_Encrypted__c.trim();
+                           nameKey2 = ct.Account.Management_Code__c + ' ' + ct.LastName_Encrypted__c.trim() + ' ' + ct.MobilePhone_Encrypted__c.trim();
+                        }
                         // snameMap.put(namekey,ct);
                         if (nameMap.containsKey(ct.Account.parent.Name)) {
                             snameMap = nameMap.get(ct.Account.parent.Name);
                         }
                         snameMap.put(namekey, ct);
-                        snameMap.put(ct.Name, ct);
+                        snameMap.put(nameKey2,ct);
+                        // // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
+                        // if(String.isBlank(ct.MobilePhone_Encrypted__c)){
+                        //     snameMap.put(ct.LastName_Encrypted__c.trim(), ct);
+                        // } else{
+                        //     snameMap.put(ct.LastName_Encrypted__c.trim() + ct.MobilePhone_Encrypted__c.trim(), ct);
+                        // }
+                        // // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
                         nameMap.put(ct.Account.parent.Name, snameMap);
+                        system.debug('snameMap'+snameMap);
                     }
                     peopleMap.put(ct.CManageCode__c, ct);
                     System.debug('peopleMap'+peopleMap);
@@ -253,7 +275,7 @@
                     //string temp = ct.Name + ct.Account.parent.Department_Class_Label__c;
                     // peopleMap.put(temp, ct);
                 }
-
+ 
                 //鏌ヨ鍖婚櫌绉戝
                 //List<Account> AccountList = [select Id,PlatformCode__c,PlatformCode__c,Department_Class_Label__c,Name,Management_Code__c,Is_Active__c,AgentCode_Ext__c,ParentId,Parent.ParentId from Account where PlatformCode__c IN :HpCodeList OR parent.PlatformCode__c IN :HpCodeList OR PlatformCode__c IN :HpCodeList OR  Management_Code__c IN :RelatedHospitalList OR Parent_Management_Code__c IN :RelatedHospitalList];
                 //List < Account > AccountList = [select Id, PlatformCode__c, Department_Class_Label__c, Name, Management_Code__c, Is_Active__c, AgentCode_Ext__c, ParentId, Parent.ParentId from Account where Management_Code__c IN :AccountCodeList OR Parent_Management_Code__c IN :AccountCodeList OR PlatformCode__c IN :AccountCodeList OR Parent.Parent.PlatformCode__c IN :AccountCodeList];
@@ -264,16 +286,12 @@
                                                        OCM_man_province_HP__c, 
                                                        Name, Management_Code__c, 
                                                        Is_Active__c, AgentCode_Ext__c, 
-                                                       RelatedMessageGroupNumber__c,
                                                        ParentId, 
                                                        Parent.ParentId, 
                                                        OwnerId
                                                        from Account 
                                                        where Parent_PlatformCode__c IN: ManagementList 
-                                                       OR Parent_Management_Code__c IN: SFDCCodeList
-                                                       OR PlatformCode__c IN: ManagementList
-                                                       OR Management_Code__c IN: SFDCCodeList
-                                                       OR (State_Master__c IN:StateMap.Values()  AND City_Master__c IN:CityMap.Values())];
+                                                       OR Parent_Management_Code__c IN: SFDCCodeList];
                 Map <String,Account> DepartmentClassMap = new Map <String,Account>();//鎴樼暐绉戝Map
                 Map < String, Account > AccountMap = new Map < String, Account > (); //鍖婚櫌绉戝
                 for (Account ac: AccountList) {
@@ -284,60 +302,66 @@
                     if (string.isNotBlank(ac.PlatformCode__c)) {
                         AccountMap.put(ac.PlatformCode__c, ac);
                     }
-                    if(string.isNotBlank(ac.Name) && ac.ParentId == null && ac.Parent.ParentId == null){
-                        AccountMap.put(ac.name,ac);
-                    }
                 }
                 system.debug('AccountMap       '+AccountMap);
                 System.debug('DepartmentClassMap     '+DepartmentClassMap);
-
-
+ 
+ 
                 //瀹㈡埛List锛堟洿鏂扮敤锛�
                 List < Account > upsertAccountList = new List < Account > ();
                 //鑱旂郴浜篖ist锛堟洿鏂扮敤锛� 
                 List < Contact > upsertContactList = new List < Contact > ();
-
+ 
                 for (Gedata gedata: newGeDataList) {
                     logstr += gedata.Name;
                     logstr += gedata.AccountName;
                     logstr += gedata.DepartmentClass;
                     logstr += gedata.DepartmentName;
-
-
-                    string comefrom = gedata.RegSource == '1' ? '鏅烘収鍖荤枟' : '鏈嶅姟瀹㈡埛绔�'; //骞冲彴鏉ユ簮
-
+ 
+ 
+                    string comefrom = gedata.RegSource == '1' ? '鏅烘収鍖荤枟' : (gedata.RegSource == '2' ? '鏈嶅姟瀹㈡埛绔�' :'鍖绘嫇缃�'); //骞冲彴鏉ユ簮
+ 
                     //鏂板缓鍖婚櫌
                     Account hp = new Account();
-
+ 
                     //鏂板缓鑱旂郴浜�
                     Contact ct = new Contact();
-                    ct.LastName = gedata.Name;
-                    ct.FirstName = '';
-                    ct.Type__c = gedata.Type;
-                    ct.Type_Encrypted__c = gedata.TypeEncrypted;//add for pipl sushanhu 20220316
-                    ct.MobilePhone = gedata.Mobile;
-                    ct.RegSource__c = comefrom;
-                    ct.UnifiedI_Contact_ID__c = gedata.ContactId; //缁熶竴骞冲彴Id
-                    // //UPDATE TO AWS 瀛樺偍鐨勭粺涓�骞冲彴id
-                    // ct.AWS_UnifiedI_Contact_ID__c=gedata.ContactId; //缁熶竴骞冲彴Id
-                    ct.ServicePlatformCode__c = gedata.ServiceUserId; //鏈嶅姟骞冲彴鐢ㄦ埛Id
-                    ct.Contact_address__c = gedata.ContactAddress;//鑱旂郴鍦板潃
-                    ct.Contact_address_Encrypted__c=gedata.ContactAddressEncrypted;//鑱旂郴鍦板潃瀵嗘枃 add 20220215
-                    ct.Platform_disabled_representation__c = gedata.ForbiddenStatus;//骞冲彴绂佺敤鏍囪瘑
-                    //ct.IsFromPlatform__c = true; //鏉ヨ嚜鏅烘収鍖荤枟鍒涘缓
-                    ct.Ignore_Same_Name__c = true; //涓嶆槸閲嶅鐨勫鎴峰悕 
-                    //ct.SendToComPlat__c = true;
-                    ct.AWS_Data_Id__c =gedata.DataId;//add 20220215 aws瀛樺偍鍑瘉
-                    ct.MobilePhone_Encrypted__c =gedata.MobileEncrypted;//add 20220215 鎵嬫満瀵嗘枃
-                    ct.LastName_Encrypted__c =gedata.NameEncrypted;//add 20220215 濮撳悕瀵嗘枃
-
+                    if(gedata.AgentFlag){
+                        //ct.FirstName = ''; 2022-4-7 yjk 娉ㄩ噴鎺�
+                        ct.UnifiedI_Contact_ID__c = gedata.ContactId; //缁熶竴骞冲彴Id
+                        ct.ServicePlatformCode__c = gedata.ServiceUserId; //鏈嶅姟骞冲彴鐢ㄦ埛Id
+                        //ct.CManageCode__c = gedata.PersonManagementCode;//浜哄憳绠$悊缂栫爜
+                    }else{
+                        ct.LastName = gedata.Name;
+                        ct.FirstName = '';
+                        ct.Type__c = gedata.Type;
+                        ct.Type_Encrypted__c = gedata.TypeEncrypted;//add for pipl sushanhu 20220316
+                        ct.MobilePhone = gedata.Mobile;
+                        ct.RegSource__c = comefrom;
+                        ct.UnifiedI_Contact_ID__c = gedata.ContactId; //缁熶竴骞冲彴Id
+                        // //UPDATE TO AWS 瀛樺偍鐨勭粺涓�骞冲彴id
+                        // ct.AWS_UnifiedI_Contact_ID__c=gedata.ContactId; //缁熶竴骞冲彴Id
+                        ct.ServicePlatformCode__c = gedata.ServiceUserId; //鏈嶅姟骞冲彴鐢ㄦ埛Id
+                        ct.Contact_address__c = gedata.ContactAddress;//鑱旂郴鍦板潃
+                        ct.Contact_address_Encrypted__c=gedata.ContactAddressEncrypted;//鑱旂郴鍦板潃瀵嗘枃 add 20220215
+                        ct.Platform_disabled_representation__c = gedata.ForbiddenStatus;//骞冲彴绂佺敤鏍囪瘑
+                        //ct.IsFromPlatform__c = true; //鏉ヨ嚜鏅烘収鍖荤枟鍒涘缓
+                        ct.Ignore_Same_Name__c = true; //涓嶆槸閲嶅鐨勫鎴峰悕 
+                        //ct.SendToComPlat__c = true;
+                        ct.AWS_Data_Id__c =gedata.DataId;//add 20220215 aws瀛樺偍鍑瘉
+                        ct.MobilePhone_Encrypted__c =gedata.MobileEncrypted;//add 20220215 鎵嬫満瀵嗘枃
+                        ct.LastName_Encrypted__c =gedata.NameEncrypted;//add 20220215 濮撳悕瀵嗘枃
+                    }
+                    
+ 
                     String personCode = gedata.PersonManagementCode;
-
+ 
                     Map < String, Contact > contactMap = new Map < String, Contact > ();//鐢ㄤ簬鏆傚瓨鏇存柊鑱旂郴浜�
                     //1缁忛攢鍟唗rue
                     if (gedata.AgentFlag == true) {
                         //鏇存柊缁忛攢鍟嗚仈绯讳汉
                         if (!peopleMap.containsKey(personCode)) {
+                            rowData.Is_Error__c = 1;
                             logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃';
                             continue;
                         }
@@ -355,14 +379,15 @@
                             dpt.Hospital__c = hospital.Id;
                             
                             //鍒ゆ柇鍖婚櫌鏄惁鏈夋晥
-                            if ('鏈夋晥'.equals(hospital.Is_Active_Formula__c) || '鏃犳晥'.equals(hospital.Is_Active_Formula__c)) { 
+                            if ('鏈夋晥'.equals(hospital.Is_Active_Formula__c)) { 
                                 string DepartmentCode = string.isNotBlank(gedata.RelatedDepartment) ? gedata.RelatedDepartment : gedata.DepartmentManagementCode2;
                                 string DepartmentClasskey = gedata.AccountName + ' ' + gedata.DepartmentClass;
+                                system.debug('DepartmentClasskey------->'+DepartmentClasskey);
                                 //绉戝瀛樺湪
                                 if (AccountMap.containsKey(DepartmentCode)) {
                                     //浜哄憳绠$悊缂栫爜瀛樺湪
                                     ct.AccountId = AccountMap.get(DepartmentCode).id;//绉戝纭畾锛屽皢鑱旂郴浜烘寕鍦ㄨ绉戝涓�
-                                    ct.OwnerId = AccountMap.get(DepartmentCode).OwnerId;//绉戝纭畾锛屽皢灏嗚仈绯讳汉鎵�鏈変汉鐨勫�艰祴涓虹瀹ゆ墍鏈変汉
+                                    ct.OwnerId = AccountMap.get(DepartmentCode).OwnerId;//鍙槸纭畾锛屽皢灏嗚仈绯讳汉鎵�鏈変汉鐨勫�艰祴涓虹瀹ゆ墍鏈変汉
                                     system.debug('personCode' + personCode);
                                     if (string.isnotblank(personCode)) {
                                         system.debug('浜哄憳绠$悊缂栫爜瀛樺湪');
@@ -373,21 +398,33 @@
                                             upsertContactList.add(ct);
                                         } else { //鑱旂郴浜轰笉瀛樺湪 2 瀹屾垚
                                             system.debug('2閫昏緫 鏈夊尰闄� 鏈夌瀹� 鏈変汉鍛樼鐞嗙紪鐮佷絾鏌ユ壘鏃犳浜� 鍔ㄤ綔锛氭姤閿�');
+                                            rowData.Is_Error__c = 1;
                                             logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃';
                                             continue;
                                         }
                                     } else { //浜哄憳绠$悊缂栫爜涓嶅瓨鍦�
                                         //鎼滅储浜哄悕/涓斿湪褰撳墠鎴樼暐绉戝绉戝涓�
                                         System.debug('浜哄憳绠$悊缂栫爜涓嶅瓨鍦�');
-                                        string namekey =  gedata.Name;
+                                        string namekey = gedata.RelatedDepartment + ' ' + gedata.NameEncrypted + ' ' + gedata.MobileEncrypted;
+                                        string namekey1 = gedata.RelatedDepartment + ' ' + gedata.NameEncrypted;
                                         system.debug('DepartmentClasskey     =    '+DepartmentClasskey);
                                         system.debug('nameMap22222222    '+nameMap);
                                         if (nameMap.containskey(DepartmentClasskey)) { // 6 瀹屾垚 鏇存柊鎿嶄綔
                                             Map < String, Contact > sMap = nameMap.get(DepartmentClasskey);
+                                            System.debug('sMap'+sMap);
+                                            System.debug('sMap.containsKey(namekey)'+sMap.containsKey(namekey));
+                                            System.debug('sMap.containsKey(gedata.NameEncrypted)'+sMap.containsKey(gedata.NameEncrypted));
                                             if (sMap.containsKey(namekey)) {
                                                 system.debug('Id璧嬪��'+sMap);
                                                 ct.id = sMap.get(namekey).id;
-                                            } else { // 7 瀹屾垚
+                                            } else if (sMap.containsKey(namekey1) && sMap.get(namekey1).UnifiedI_Contact_ID__c == null) {
+                                                ct.id = sMap.get(namekey1).id;
+                                            
+                                            // // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
+                                            // } else if(sMap.containsKey(gedata.NameEncrypted + gedata.MobileEncrypted) && sMap.get(gedata.NameEncrypted + gedata.MobileEncrypted).UnifiedI_Contact_ID__c == null){
+                                            //     ct.id = sMap.get(gedata.NameEncrypted + gedata.MobileEncrypted).id;
+                                            // // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
+                                            }else { // 7 瀹屾垚
                                                 system.debug('7閫昏緫 鏃犱汉鍛樼鐞嗙紪鐮� 鏈夊尰闄� 鏈夌瀹� 浜哄悕鏌ユ壘鏃� 鍔ㄤ綔锛氭柊寤鸿仈绯讳汉 ');
                                             }
                                         }
@@ -413,12 +450,13 @@
                                             //upsertContactList.add(ct);
                                         } else { //浜哄憳绠$悊缂栫爜鏌ユ壘鏃犲�� 4 瀹屾垚
                                             system.debug('4閫昏緫');
+                                            rowData.Is_Error__c = 1;
                                             logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃';
                                             continue;
                                         }
                                     } else { //浜哄憳绠$悊缂栫爜涓嶅瓨鍦�
                                         system.debug('浜哄憳绠$悊缂栫爜涓嶅瓨鍦�');
-                                        string namekey = gedata.DepartmentName+ ' ' + gedata.Name;
+                                        string namekey = gedata.DepartmentName + ' ' + gedata.NameEncrypted + ' ' + gedata.MobileEncrypted;
                                         //string namekey = gedata.AccountName + ' ' + gedata.DepartmentName + ' ' + gedata.DepartmentClass + ' ' + gedata.Name;
                                         system.debug('DepartmentClasskey'+DepartmentClasskey);
                                         system.debug('351nameMap     '+nameMap);
@@ -426,23 +464,31 @@
                                             System.debug('浜哄憳绠$悊缂栫爜涓嶅瓨鍦ㄧ殑鎯呭喌涓嬫垬鐣ョ瀹ゅ瓨鍦�');
                                             system.debug('鎴樼暐绉戝瀛樺湪' + nameMap.get(DepartmentClasskey));
                                             Map < String, Contact > sMap = nameMap.get(DepartmentClasskey);
+                                            system.debug('namekey'+namekey);
+                                            system.debug('sMap.containsKey(namekey)'+sMap.containsKey(namekey));
                                             if (sMap.containsKey(namekey)) { //鏌ユ壘瀛樺湪 8 瀹屾垚
                                                 system.debug('8閫昏緫');
                                                 system.debug('璇ヨ仈绯讳汉瀛樺湪');
                                                 ct.id = sMap.get(namekey).id;
-                                                upsertAccountList.add(dpt);
+                                                //upsertAccountList.add(dpt);//鍙互娉ㄩ噴
                                                 upsertContactList.add(ct);
                                                 // if(sMap.containsKey(gedata.Name)){
                                                 //     ct.Id = sMap.get(gedata.Name).Id;
                                                 // }
-                                            }else if(sMap.containsKey(gedata.Name)){
-                                                system.debug('1234567890');
-                                                ct.Id = sMap.get(gedata.Name).Id;
-                                                //upsertAccountList.add(dpt);
                                             }
+                                            // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
+                                            // else if(sMap.containsKey(gedata.NameEncrypted + gedata.MobileEncrypted) && sMap.get(gedata.NameEncrypted + gedata.MobileEncrypted).UnifiedI_Contact_ID__c == null){
+                                            //     system.debug('1234567890');
+                                            //     ct.Id = sMap.get(gedata.NameEncrypted + gedata.MobileEncrypted).Id;
+                                            //     //upsertAccountList.add(dpt);
+                                            //     upsertContactList.add(ct);
+                                            // }
+                                            // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
                                             system.debug('contactMap        '  +  contactMap);
                                             System.debug('9閫昏緫');
                                             contactMap.put(Gedata.DepartmentManagementCode2, ct);
+                                            system.debug('contactMap        '  +  contactMap);
+                                            //upsertContactList.add(ct);
                                         }
                                         system.debug('鍒涘缓鑱旂郴浜哄拰绉戝');
                                         dpt.Department_Name__c = gedata.DepartmentName;
@@ -450,142 +496,30 @@
                                         contactMap.put(Gedata.DepartmentManagementCode2, ct);
                                     }
                                 }
+                            }else if('鏃犳晥'.equals(hospital.Is_Active_Formula__c)){
+                                rowData.Is_Error__c = 1;
+                                logstr += 'error:璇ュ尰闄㈡棤鏁堬紝姝ゆ潯鏁版嵁璺宠繃';
+                                continue;
                             }else{
-                                logstr += '璇ュ尰闄㈠浜庤崏妗堜腑/鐢宠涓紝璇风瓑寰呭鎵瑰畬鎴�';
-                                //鐘舵��------>鑽夋涓�/鐢宠涓�------->绛夊緟锛宲lan1:鎶婂尰闄d鍐欏埌鏃ュ織琛ㄤ笂锛堝悗缁绱㈡牴鎹尰闄d妫�绱㈡湭澶勭悊杩囩殑鏃ュ織锛�,plan2:鎶奙essageGroupNumber瀛樺埌鍖婚櫌涓� 
+                                logstr += '璇ュ尰闄㈠浜庤崏妗堜腑锛岃绛夊緟瀹℃壒瀹屾垚';
                                 rowData.NFM624_Secondary_processing__c = false;
                                 continue;
                             }
-                        } else { //鍖婚櫌涓嶅瓨鍦� 鍒欓渶瑕佸鍔犲垽鏂牴鎹悕鍒ら噸
-                            if(accountMap.containskey(gedata.AccountName)){//濡傛灉鏍规嵁鍚嶅瓧鍒ゆ柇鏈夐噸澶嶅垯鏁版嵁鏂板缓鎸囧悜杩欎釜鍖婚櫌
-                                Account dpt = new Account(); 
-                                Account hospital = AccountMap.get(gedata.AccountName);
-                                dpt.PlatformCode__c = gedata.DepartmentManagementCode2;
-                                dpt.Hospital__c = hospital.Id;
-                                //鍖婚櫌瀛樺湪鈫撳彇鐘舵��,鏈夋晥鏃犳晥閮芥柊寤�
-                                if ('鏈夋晥'.equals(hospital.Is_Active_Formula__c) || '鏃犳晥'.equals(hospital.Is_Active_Formula__c)) { 
-                                    string DepartmentCode = string.isNotBlank(gedata.RelatedDepartment) ? gedata.RelatedDepartment : gedata.DepartmentManagementCode2;
-                                    string DepartmentClasskey = gedata.AccountName + ' ' + gedata.DepartmentClass;
-                                    //绉戝瀛樺湪
-                                    if (AccountMap.containsKey(DepartmentCode)) {//鍥犱负SOQL娌℃湁妫�绱㈠埌绉戝鎵�浠ユ病鏈夊垽瀹氫负娌℃湁绉戝
-                                        //浜哄憳绠$悊缂栫爜瀛樺湪
-                                        ct.AccountId = AccountMap.get(DepartmentCode).id;//绉戝纭畾锛屽皢鑱旂郴浜烘寕鍦ㄨ绉戝涓�
-                                        ct.OwnerId = AccountMap.get(DepartmentCode).OwnerId;//鍙槸纭畾锛屽皢灏嗚仈绯讳汉鎵�鏈変汉鐨勫�艰祴涓虹瀹ゆ墍鏈変汉
-                                        system.debug('personCode' + personCode);
-                                        if (string.isnotblank(personCode)) {
-                                            system.debug('浜哄憳绠$悊缂栫爜瀛樺湪');
-                                            //鑱旂郴浜哄瓨鍦� 11 鍖婚櫌鍚嶅瓧鎺掗噸瀛樺湪锛岀瀹ゅ瓨鍦紝鏇存柊鑱旂郴浜猴紝 瀹屾垚
-                                            if (peopleMap.containsKey(personCode)) {
-                                                system.debug('11閫昏緫 鍚嶅瓧鏌ラ噸鍖婚櫌 鏈夌瀹� 鏈変汉鍛樼鐞嗙紪鐮佷笖鏌ユ壘鏈夋浜� 鍔ㄤ綔锛氭洿鏂�');
-                                                ct.Id = peopleMap.get(personCode).Id;
-                                                upsertContactList.add(ct);
-                                            } else { //鑱旂郴浜轰笉瀛樺湪 12 瀹屾垚 
-                                                system.debug('12閫昏緫 鍚嶅瓧鏌ラ噸鍖婚櫌 鏈夌瀹� 鏈変汉鍛樼鐞嗙紪鐮佷絾鏌ユ壘鏃犳浜� 鍔ㄤ綔锛氭姤閿�');
-                                                logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃';
-                                                continue;
-                                            }
-                                        } else { //浜哄憳绠$悊缂栫爜涓嶅瓨鍦�
-                                            //鎼滅储浜哄悕/涓斿湪褰撳墠鎴樼暐绉戝绉戝涓�
-                                            System.debug('浜哄憳绠$悊缂栫爜涓嶅瓨鍦�');
-                                            string namekey =  gedata.Name;
-                                            system.debug('DepartmentClasskey     =    '+DepartmentClasskey);
-                                            system.debug('nameMap22222222    '+nameMap);
-                                            if (nameMap.containskey(DepartmentClasskey)) { // 16 瀹屾垚 鏇存柊鎿嶄綔
-                                                Map < String, Contact > sMap = nameMap.get(DepartmentClasskey);
-                                                if (sMap.containsKey(namekey)) {
-                                                    system.debug('Id璧嬪��'+sMap);
-                                                    ct.id = sMap.get(namekey).id;
-                                                    system.debug('16閫昏緫 鏃犱汉鍛樼鐞嗙紪鐮� 鍖婚櫌鏌ラ噸瀛樺湪 鏈夌瀹� 浜哄悕鏌ユ壘鏈� 鍔ㄤ綔锛氭洿鏂拌仈绯讳汉 ');
-                                                } else { // 17 瀹屾垚
-                                                    system.debug('17閫昏緫 鏃犱汉鍛樼鐞嗙紪鐮� 鍖婚櫌鏌ラ噸瀛樺湪 鏈夌瀹� 浜哄悕鏌ユ壘鏃� 鍔ㄤ綔锛氭柊寤鸿仈绯讳汉 ');
-                                                }
-                                            }
-                                            upsertContactList.add(ct);
-                                        }
-                                        dpt.Id = AccountMap.get(DepartmentCode).Id;
-                                        upsertAccountList.add(dpt);
-                                    } else { //绉戝涓嶅瓨鍦� 
-                                        //涓虹瀹よ祴鍊�
-                                        dpt.Name = gedata.DepartmentName;
-                                        dpt.RecordTypeId = RecordTypeMap.get(gedata.DepartmentClass);
-                                        //鍥犱负娌℃湁鍖婚櫌绠$悊缂栫爜锛屾棤娉曟绱㈠埌鎴樼暐绉戝锛屾墍浠ュ湪缁欑瀹ょ殑鎴樼暐绉戝瀛楁璧嬪�兼椂绌烘寚閽�
-                                        //dpt.Department_Class__c = DepartmentClassMap.get(gedata.DepartmentClass).Id;
-                                        //dpt.ParentId = DepartmentClassMap.get(gedata.DepartmentClass).Id;
-                                        dpt.Department_Class__c = DepartmentClassMap.get(gedata.DepartmentClass).Id;
-                                        dpt.ParentId = DepartmentClassMap.get(gedata.DepartmentClass).Id;
-                                        if (string.isnotblank(personCode)) { //浜哄憳绠$悊缂栫爜瀛樺湪
-                                            if (peopleMap.containsKey(personCode)) { //浜哄憳绠$悊缂栫爜鏌ユ壘鏈夊�� 13 瀹屾垚
-                                                System.debug('13閫昏緫');
-                                                //鏂板缓绉戝+鏂板缓鑱旂郴浜�, 
-                                                ct.id = peopleMap.get(personCode).id;
-                                                contactMap.put(Gedata.DepartmentManagementCode2, ct);
-                                                system.debug('contactMap        '  +  contactMap);
-                                                dpt.Department_Name__c = gedata.DepartmentName;
-                                                upsertAccountList.add(dpt);
-                                                //upsertContactList.add(ct);
-                                            } else { //浜哄憳绠$悊缂栫爜鏌ユ壘鏃犲�� 14 瀹屾垚
-                                                system.debug('14閫昏緫');
-                                                logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃';
-                                                continue;
-                                            }
-                                        } else { //浜哄憳绠$悊缂栫爜涓嶅瓨鍦�
-                                            system.debug('浜哄憳绠$悊缂栫爜涓嶅瓨鍦�');
-                                            string namekey = gedata.DepartmentName+ ' ' + gedata.Name;
-                                            //string namekey = gedata.AccountName + ' ' + gedata.DepartmentName + ' ' + gedata.DepartmentClass + ' ' + gedata.Name;
-                                            system.debug('DepartmentClasskey'+DepartmentClasskey);
-                                            system.debug('351nameMap     '+nameMap);
-                                            if (nameMap.containsKey(DepartmentClasskey)) { //鏌ユ壘鏄惁瀛樺湪璇ユ垬鐣ョ瀹� 
-                                                System.debug('浜哄憳绠$悊缂栫爜涓嶅瓨鍦ㄧ殑鎯呭喌涓嬫垬鐣ョ瀹ゅ瓨鍦�');
-                                                system.debug('鎴樼暐绉戝瀛樺湪' + nameMap.get(DepartmentClasskey));
-                                                Map < String, Contact > sMap = nameMap.get(DepartmentClasskey);
-                                                if (sMap.containsKey(namekey)) { //鏌ユ壘瀛樺湪 18 瀹屾垚
-                                                    system.debug('18閫昏緫');
-                                                    system.debug('璇ヨ仈绯讳汉瀛樺湪');
-                                                    ct.id = sMap.get(namekey).id;
-                                                    upsertAccountList.add(dpt);
-                                                    upsertContactList.add(ct);
-                                                    // if(sMap.containsKey(gedata.Name)){
-                                                    //     ct.Id = sMap.get(gedata.Name).Id;
-                                                    // }
-                                                }else if(sMap.containsKey(gedata.Name)){
-                                                    system.debug('1234567890');
-                                                    ct.Id = sMap.get(gedata.Name).Id;
-                                                    //upsertAccountList.add(dpt);
-                                                }
-                                                system.debug('contactMap        '  +  contactMap);
-                                                System.debug('19閫昏緫');
-                                                contactMap.put(Gedata.DepartmentManagementCode2, ct);
-                                            }
-                                            system.debug('鍒涘缓鑱旂郴浜哄拰绉戝');
-                                            dpt.Department_Name__c = gedata.DepartmentName;
-                                            upsertAccountList.add(dpt);
-                                            contactMap.put(Gedata.DepartmentManagementCode2, ct);
-                                        }
-                                    }
-                                }else{
-                                    logstr += '璇ュ尰闄㈠浜庤崏妗堜腑/鐢宠涓紝璇风瓑寰呭鎵瑰畬鎴�';
-                                    //鐘舵��------>鑽夋涓�/鐢宠涓�------->绛夊緟锛宲lan1:鎶婂尰闄d鍐欏埌鏃ュ織琛ㄤ笂锛堝悗缁绱㈡牴鎹尰闄d妫�绱㈡湭澶勭悊杩囩殑鏃ュ織锛�,plan2:鎶奙essageGroupNumber瀛樺埌鍖婚櫌涓� 
-                                    hospital.RelatedMessageGroupNumber__c += iflog.MessageGroupNumber__c + ';';
-                                    rowData.NFM624_Secondary_processing__c = false;
-                                    upsertAccountList.add(hospital);
-                                }
-                            }else{
-                                //鈫撴柊寤哄尰闄�
-                                system.debug('鏂板缓鍖婚櫌 閫昏緫5閫昏緫10閫昏緫15閫昏緫20 鏃犺浜哄憳绠$悊缂栫爜鏄惁鏈夊�奸兘闇�瑕佹柊寤哄尰闄�');
-                                hp.Name = gedata.AccountName; //鍖婚櫌鍚嶈祴鍊�  
-                                if(ownerMap.containsKey(gedata.ApproverID)){
-                                    hp.OwnerId = ownerMap.get(gedata.ApproverID);//瀹℃牳浜哄憳鍛樺伐缂栫爜璧嬪�肩粰鐢ㄦ埛鎵�鏈変汉
-                                }
-                                hp.RecordTypeId = '01210000000QemG';    
-                                hp.OCM_Category__c = 'L';
-                                hp.PlatformCode__c = gedata.HospitalManagementCode2;
-                                hp.State_Master__c = StateMap.get(gedata.State); //  鐪�
-                                hp.City_Master__c = CityMap.get(gedata.City); //     甯�
-                                hp.Hospital_Source__c = '鏅烘収鍖荤枟';
-                                upsertAccountList.add(hp);
-                                System.debug('upsertAccountList'+upsertAccountList);
-                                rowData.NFM624_Secondary_processing__c = false;//鏁版嵁闇�瑕佷簩娆″鐞嗘爣璁�
+                        } else { //鍖婚櫌涓嶅瓨鍦�
+                            system.debug('鏂板缓鍖婚櫌 閫昏緫5閫昏緫10 鏃犺浜哄憳绠$悊缂栫爜鏄惁鏈夊�奸兘闇�瑕佹柊寤哄尰闄�');
+                            hp.Name = gedata.AccountName; //鍖婚櫌鍚嶈祴鍊�  
+                            if(ownerMap.containsKey(gedata.ApproverID)){
+                                hp.OwnerId = ownerMap.get(gedata.ApproverID);//瀹℃牳浜哄憳鍛樺伐缂栫爜璧嬪�肩粰鐢ㄦ埛鎵�鏈変汉
                             }
+                            hp.RecordTypeId = '01210000000QemG';    
+                            hp.OCM_Category__c = 'L';
+                            hp.PlatformCode__c = gedata.HospitalManagementCode2;
+                            hp.State_Master__c = StateMap.get(gedata.State); //  鐪�
+                            hp.City_Master__c = CityMap.get(gedata.City); //     甯�
+                            hp.Hospital_Source__c = '鏅烘収鍖荤枟';
+                            upsertAccountList.add(hp);
+                            System.debug('upsertAccountList'+upsertAccountList);
+                            rowData.NFM624_Secondary_processing__c = false;//鏁版嵁闇�瑕佷簩娆″鐞嗘爣璁�
                         }
                     }
                     system.debug('upsertContactList      ' + upsertContactList);
@@ -595,10 +529,16 @@
                         StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
                         system.debug('upsertAccountList                           ' + upsertAccountList);
                         upsert upsertAccountList;
+                        system.debug('SFDCCodeList'+SFDCCodeList);
+                        system.debug('SFDCCodeList'+ManagementList);
                         List < Account > List1 = [select Id,RecordTypeId,Is_Active__c,PlatformCode__c,OCM_man_province_HP__c,OwnerId from Account where PlatformCode__c In: SFDCCodeList OR PlatformCode__c IN: ManagementList];//瀹㈡埛鎵�鏈変汉淇敼11.18 11.35 鏈畬鎴�
+                        system.debug('List1'+List1);
                         List<Account> updateHPList = new  List<Account>(); 
                         for (Account ac: List1) {
                             Contact c = new contact();
+                            system.debug('ac.PlatformCode__c'+ac.PlatformCode__c);
+                            system.debug('ContactMap'+ContactMap);
+                            system.debug('ContactMap.containsKey(ac.PlatformCode__c)'+ContactMap.containsKey(ac.PlatformCode__c));
                             if(ContactMap.containsKey(ac.PlatformCode__c)){
                                 c = contactMap.get(ac.PlatformCode__c);
                                 if(string.isblank(c.Id)|| c.AccountId != ac.Id){
@@ -609,7 +549,7 @@
                                 system.debug('OwnerId'+ac.OwnerId);
                                 system.debug('upsertContactList'+upsertContactList);
                             }
-
+ 
                             if(ac.RecordTypeId == '01210000000QemGAAS' && ac.Is_Active__c == '鑽夋涓�' && string.isNotBlank( OCSMMap.get(ac.OCM_man_province_HP__c))){
                                 ac.OwnerId = OCSMMap.get(ac.OCM_man_province_HP__c);
                                 updateHPList.add(ac);
@@ -661,42 +601,37 @@
         }
         update iflog;
     }
-
+ 
     private static String verify(GeData gda) {
         String result = '';
-        if (string.isblank(gda.ContactId)) {
-            result += 'DataError: ContactId 缁熶竴骞冲彴ID涓虹┖\n';
-        }
-        if (gda.AgentFlag == null) {
-            result += 'DataError:缁忛攢鍟嗘爣璇嗕负绌篭n';
-        }
-        if (string.isblank(gda.Name)) {
-            result += 'DataError锛氬鍚嶄负绌篭n';
-        }
-        if (string.isblank(gda.NameEncrypted)) {
-            result += 'DataError锛氬鍚嶅瘑鏂囦负绌篭n';
-        }
-        if (string.isblank(gda.Mobile)) {
-            result += 'DataError锛氭墜鏈哄彿涓虹┖\n';
-        }
-        if (string.isblank(gda.MobileEncrypted)) {
-            result += 'DataError锛氭墜鏈哄彿瀵嗘枃涓虹┖\n';
-        }
-        if (string.isblank(gda.RegSource)) {
-            result += 'DataError锛氭敞鍐屽钩鍙版潵婧愪负绌篭n';
-        }if (string.isblank(gda.DataId)) {
-            result += 'DataError锛欰WS鍔犲瘑鍑嵁涓虹┖\n';
-        }
         if (gda.AgentFlag) {
+            if (string.isblank(gda.ContactId)) {
+                result += 'DataError: ContactId 缁熶竴骞冲彴ID涓虹┖\n';
+            }
             if (string.isblank(gda.PersonManagementCode)) {
                 result += 'DataError锛歅ersonManagementCode 浜哄憳绠$悊缂栫爜涓虹┖\n';
             }
-        } else {
-            // if (string.isnotblank(gda.PersonManagementCode) && string.isBlank(gda.RelatedHospital)) {
-            //     result += 'DataError: 鍏宠仈鍖婚櫌缂栫爜涓虹┖\n';
-            // }
-            if(string.isBlank(gda.RelatedDepartment) && String.isBlank(gda.ApproverID)){
-                result += 'DataError: 鍦ㄥ叧鑱擲FDC绉戝[RelatedDepartment]涓虹┖鏃讹紝瀹℃牳浜哄憳鍛樺伐缂栫爜[ApproverID]蹇呭~\n';
+            if (string.isblank(gda.ServiceUserId)) {
+                result += 'ServiceUserId 鏈嶅姟骞冲彴鐢ㄦ埛Id涓虹┖\n';
+            }
+        }else{
+            if (string.isblank(gda.ContactId)) {
+                result += 'DataError: ContactId 缁熶竴骞冲彴ID涓虹┖\n';
+            }
+            if (gda.AgentFlag == null) {
+                result += 'DataError:缁忛攢鍟嗘爣璇嗕负绌篭n';
+            }
+            if (string.isblank(gda.Name)) {
+                result += 'DataError锛氬鍚嶄负绌篭n';
+            }
+            if (string.isblank(gda.Mobile)) {
+                result += 'DataError锛氭墜鏈哄彿涓虹┖\n';
+            }
+            if (string.isblank(gda.RegSource)) {
+                result += 'DataError锛氭敞鍐屽钩鍙版潵婧愪负绌篭n';
+            }
+            if(string.isBlank(gda.RelatedHospital) && String.isBlank(gda.HospitalManagementCode2) && String.isBlank(gda.ApproverID)){
+                result += 'DataError: 鏂板缓鍖婚櫌鏃讹紝瀹℃牳浜哄憳鍛樺伐缂栫爜[ApproverID]蹇呭~\n';
             }
             if (string.isblank(gda.HospitalManagementCode2)) {
                 result += 'DataError锛氬尰闄㈠钩鍙扮紪鐮佷负绌篭n';
@@ -735,26 +670,34 @@
         //鏍规嵁缁熶竴鐢ㄦ埛Id鏌ヨ鑱旂郴浜�
         List<Contact> contactList = [select Id,Name,UnifiedI_Contact_ID__c,Account.Id,Strategic_dept_Class__c,AccountId,Account.Name,Strategic_dept_Class__r.OwnerId from Contact where UnifiedI_Contact_ID__c = :ContactId];
         system.debug('contactList' + contactList);
-
+ 
         if(InquiryList.size()>0){
             //缁熶竴鐢ㄦ埛ID瀛樺叆List銆佽闂崟ID瀛楳ap
             Map<String, String> inquiryMap = new Map<String, String>();
             //List<String> contactIdList = new List<String>();
             for (Inquiry_form__c inquiryInfo : inquiryList) {
                 //contactIdList.add(inquiryInfo.ContactId__c);
-                inquiryMap.put(inquiryInfo.ContactId__c, inquiryInfo.Id);
+                // map鐨刱-v鏀归�� thh 20220517 start
+                inquiryMap.put(inquiryInfo.Id, inquiryInfo.ContactId__c);
+                // map鐨刱-v鏀归�� thh 20220517 end
             }
-            if (contactList.size() >0 ) {
-                for (Contact contactInfo : contactList) {
+            // map鐨刱-v鏀归�� thh 20220517 start
+            if (contactList.size() >0 && inquiryMap.size() > 0) {
+                for(String Id : inquiryMap.keySet()){
                     Inquiry_form__c inquiry = new Inquiry_form__c();
-                    inquiry.Id = inquiryMap.get(contactInfo.UnifiedI_Contact_ID__c);      //ID
-                    inquiry.Hospital_Name__c = contactInfo.Account.Id;                    //绉戝鍚�   
-                    inquiry.Department_Class__c = contactInfo.Strategic_dept_Class__c;    //鎴樼暐绉戝鍒嗙被
-                    inquiry.Contact_Name__c = contactInfo.Id;                             //瀹㈡埛濮撳悕
-                    inquiry.OwnerId = contactInfo.Strategic_dept_Class__r.OwnerId;        //鎵�鏈変汉
-                    inquiryFormList.add(inquiry);
+                    for (Contact contactInfo : contactList) {
+                        if(inquiryMap.get(Id) == contactInfo.UnifiedI_Contact_ID__c){
+                            inquiry.Id = Id;      //ID
+                            inquiry.Hospital_Name__c = contactInfo.Account.Id;                    //绉戝鍚�   
+                            inquiry.Department_Class__c = contactInfo.Strategic_dept_Class__c;    //鎴樼暐绉戝鍒嗙被
+                            inquiry.Contact_Name__c = contactInfo.Id;                             //瀹㈡埛濮撳悕
+                            inquiry.OwnerId = contactInfo.Strategic_dept_Class__r.OwnerId;        //鎵�鏈変汉
+                            inquiryFormList.add(inquiry);
+                        }
+                    }
                 }
             }
+            // map鐨刱-v鏀归�� thh 20220517 end  
             system.debug('inquiryFormList=========>'+inquiryFormList);
             if(inquiryFormList.size()>0){
                 update inquiryFormList;
@@ -795,29 +738,4 @@
         }
         //琛ュ厖瀛︿細閮ㄥ垎 end
     }
-    //鍓嶇疆鏉′欢锛屽尰闄㈢鐞嗙紪鐮佷笉瀛樺湪鐨勬椂鍊欐墽琛岃繖涓搷浣�
-//     private static Account duplicate_removal (Map<String,ACcount> accountNameMap,Gedate ged,BatchIF_Log__c iflog){//鍖婚櫌鍚峂ap,鎺ュ彛鏁版嵁锛屾棩蹇楄〃
-//         //鏌ヨ鍖婚櫌鏄柊澧炴潯浠禣R 锛堢渷 = 浼犲叆鐪� AND 甯� = 浼犲叆甯傦級锛屽鍔犱竴涓竴鍚嶅瓧涓簁ey鐨刴ap锛屾牴鎹紶鍏ユ暟鎹殑鍚嶅瓧鍒ゆ柇鏄惁瀛樺湪
-//         //涓嶅瓨鍦ㄢ�斺�斺��>鏂板缓
-//         //瀛樺湪鈥斺��>鍙栫姸鎬�
-//         //鐘舵��------>鑽夋涓�/鐢宠涓�------->绛夊緟锛宲lan1:鎶婂尰闄d鍐欏埌鏃ュ織琛ㄤ笂锛堝悗缁绱㈡牴鎹尰闄d妫�绱㈡湭澶勭悊杩囩殑鏃ュ織锛�,plan2:鎶奙essageGroupNumber瀛樺埌鍖婚櫌涓�
-//         //鐘舵��------>鏈夋晥锛屾暟鎹柊寤哄埌璇ュ尰闄笅,鍙戦�佽仈绯讳汉淇℃伅
-//         //鐘舵��------>鏃犳晥锛屾暟鎹柊寤哄埌璇ュ尰闄笅,鍏堝彂閫佽仈绯讳汉淇℃伅锛屽啀鍙戦�佸尰闄俊鎭�
-//         if(accountNameMap.containskey(ged.AccountName)){//鏍规嵁鍖婚櫌鍚嶅垽鏂尰闄㈡槸鍚﹀瓨鍦�
-//             //鍖婚櫌瀛樺湪
-//             Account tempHp = accountNameMap.get(ged.AccountName);
-//             if('鑽夋涓�'.equals(tempHp.Is_Active_Formula__c) || '鐢宠涓�'.equals(tempHp.Is_Active_Formula__c)){//鍒ゆ柇鍖婚櫌鐘舵��
-//                 //鑽夋涓�/鐢宠涓姸鎬�
-//                 tempHp.RelatedMessageGroupNumber__c += iflog.MessageGroupNumber__c + ';';
-//                 //continue;
-//                 return tempHp;
-//             }else{
-
-//             }
-//         }else{
-//             //鍖婚櫌涓嶅瓨鍦�
-           
-//             return hp;
-//         }
-//     }
 }
\ No newline at end of file

--
Gitblit v1.9.1