涂煌豪
2022-05-23 78ac43791ac9e9d75ce4c33e9dddbdffa88fec2f
force-app/main/default/classes/NFM624Rest.cls
@@ -18,7 +18,7 @@
    // global class GeDatasRest {
    //     public GeDatas GeDatas;
    // }
    global class GeDatas {
        public NFMUtil.Monitoring Monitoring;
        public GeData[] GeData;
@@ -101,7 +101,6 @@
    }
 
    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];        
@@ -222,6 +221,7 @@
                List < Contact > peopleList = [select Id, 
                                                      Account.Name,
                                                      Department__c, 
                                                      UnifiedI_Contact_ID__c,
                                                      Account.parent.Name, 
                                                      Account.PlatformCode__c, 
                                                      Account.Management_Code__c, 
@@ -230,7 +230,10 @@
                                                      Account.Parent_Management_Code__c, 
                                                      Account.Parent_PlatformCode__c, 
                                                      CManageCode__c, 
                                                      AccountId
                                                      AccountId,
                                                      // 通过姓名+手机号判断人员是否重复 thh 20220518 start
                                                      MobilePhone_Encrypted__c
                                                      // 通过姓名+手机号判断人员是否重复 thh 20220518 end
                                                      from Contact 
                                                      where CManageCode__c IN: PersonManagementCodeList 
                                                      OR (Account.Parent_PlatformCode__c IN: ManagementList AND LastName_Encrypted__c IN:NameList)
@@ -241,15 +244,28 @@
                for (Contact ct: peopleList) {
                    if (string.isnotblank(ct.Account.parent.Name)) {
                        Map < String, Contact > snameMap = new Map < String, Contact > ();
                        string namekey = ct.Account.Name + ' ' + ct.LastName_Encrypted__c.trim();
                        string nameKey2 = ct.Account.Management_Code__c + ' ' + ct.LastName_Encrypted__c.trim();
                        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(nameKey2,ct);
                        snameMap.put(ct.LastName_Encrypted__c.trim(), 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);
                    }
@@ -389,18 +405,25 @@
                                    } else { //人员管理编码不存在
                                        //搜索人名/且在当前战略科室科室下
                                        System.debug('人员管理编码不存在');
                                        string namekey = gedata.RelatedDepartment + ' ' + gedata.NameEncrypted;
                                        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 if(sMap.containsKey(gedata.NameEncrypted)){
                                                ct.id = sMap.get(gedata.NameEncrypted).id;
                                            } 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逻辑 无人员管理编码 有医院 有科室 人名查找无 动作:新建联系人 ');
                                            }
@@ -433,7 +456,7 @@
                                        }
                                    } else { //人员管理编码不存在
                                        system.debug('人员管理编码不存在');
                                        string namekey = gedata.DepartmentName+ ' ' + gedata.NameEncrypted;
                                        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);
@@ -452,11 +475,15 @@
                                                // if(sMap.containsKey(gedata.Name)){
                                                //     ct.Id = sMap.get(gedata.Name).Id;
                                                // }
                                            }else if(sMap.containsKey(gedata.NameEncrypted)){
                                                system.debug('1234567890');
                                                ct.Id = sMap.get(gedata.NameEncrypted).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);
@@ -650,19 +677,27 @@
            //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的k-v改造 thh 20220517 start
                inquiryMap.put(inquiryInfo.Id, inquiryInfo.ContactId__c);
                // map的k-v改造 thh 20220517 end
            }
            if (contactList.size() >0 ) {
                for (Contact contactInfo : contactList) {
            // map的k-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的k-v改造 thh 20220517 end
            system.debug('inquiryFormList=========>'+inquiryFormList);
            if(inquiryFormList.size()>0){
                update inquiryFormList;