高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/NFM624RestAbout.cls
@@ -16,10 +16,10 @@
    global class GeDatas {
        public NFMUtil.Monitoring Monitoring;
        public GeData[] GeData;
       }
   global class GeData{
      }
  global class GeData{
          public String PersonManagementCode; //人员管理编码
         public String PersonManagementCode; //人员管理编码
        public String HospitalManagementCode2; //医院平台编码  平台编码 PlatformCode__c
        public String DepartmentManagementCode2; //科室平台编码  平台编码 PlatformCode__c
        //public String Name; //姓名
@@ -29,7 +29,7 @@
        public String DepartmentName; //所属科室
        public String RelatedDepartment; //关联SFDC科室 客户管理编码(手写) AgentCode_Ext__c
        //public Boolean AgentFlag; //经销商标识
       public String dataId;
      public String dataId;
        public String AccountName; //医院名
        public String MobileEncrypted; //电话密文 add 20220519 thh
    }
@@ -39,11 +39,11 @@
    global class Response {
        public List<ResponseDetail> ResponseDetails {get;set;}
    }
    global class ResponseDetail{
       public String  dataId;
       public String  awsDataId; //=CONTACT.AWS_Data_Id__c
       public String  sfId;
      public String  dataId;
      public String  awsDataId; //=CONTACT.AWS_Data_Id__c
      public String  sfId;
    }  
 
    @HttpPost
@@ -51,6 +51,8 @@
 
        // 取得接口传输内容
        String strData = RestContext.request.requestBody.toString();
        system.debug('strData---'+strData );
        system.debug('strData2---'+RestContext.request.requestBody );
        GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class);
        system.debug('ges---'+JSON.serialize(ges) );
 
@@ -201,22 +203,47 @@
                                                       //AccountId 
                                                       from Contact 
                                                       where CManageCode__c IN: PersonManagementCodeList 
                                                      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 )
                                                      OR (Account.Parent_PlatformCode__c IN: ManagementList AND LastName_Encrypted__c IN:NameList AND UnifiedI_Contact_ID__c = null)
                                                      OR (Account.Parent_Management_Code__c IN: SFDCCodeList AND LastName_Encrypted__c IN:NameList AND UnifiedI_Contact_ID__c = null)
                                                      ORDER BY  MobilePhone ASC,CManageCode__c ASC]; //根据人员管理编码检索联系人
                // List < Contact > peopleList = [select Id,
                //                                        Account.Name,
                //                                        //Department__c,
                //                                        Account.parent.Name,
                //                                        UnifiedI_Contact_ID__c,
                //                                        //Account.PlatformCode__c,
                //                                        Account.Management_Code__c,
                //                                        //Account.parent.Department_Class_Label__c,
                //                                        Name,LastName_Encrypted__c,
                //                                        //Account.Parent_Management_Code__c,
                //                                        //Account.Parent_PlatformCode__c,
                //                                        CManageCode__c,AWS_Data_Id__c,
                //                                        // 通过姓名+手机号判断人员是否重复 thh 20220518 start
                //                                        MobilePhone_Encrypted__c
                //                                        // 通过姓名+手机号判断人员是否重复 thh 20220518 end
                //                                        //AccountId
                //                                        from Contact
                //                                        where CManageCode__c IN: PersonManagementCodeList
                //                                       OR (Account.Parent_PlatformCode__c IN: ManagementList AND UnifiedI_Contact_ID__c = null)
                //                                       OR (Account.Parent_Management_Code__c IN: SFDCCodeList AND UnifiedI_Contact_ID__c = null)
                //                                       ORDER BY  MobilePhone ASC,CManageCode__c ASC]; //根据人员管理编码检索联系人
                 Map < String, Contact > peopleMap = new Map < String, Contact > (); //联系人
                 system.debug('peopleList  '+peopleList);
                 system.debug('peopleList.size  '+peopleList.size());
                 for (Contact ct: peopleList) {
                     if (string.isnotblank(ct.Account.parent.Name)) {
                         Map < String, Contact > snameMap = new Map < String, Contact > ();
                         string namekey;
                         string nameKey2;
                         string nameKey3;
                         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();
                            nameKey3 = 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();
                            nameKey3 = ct.LastName_Encrypted__c.trim() + ' ' + ct.MobilePhone_Encrypted__c.trim();
                         }
                         snameMap.put(namekey,ct);
                         if (nameMap.containsKey(ct.Account.parent.Name)) {
@@ -224,6 +251,7 @@
                         }
                         snameMap.put(nameKey2,ct); 
                         snameMap.put(namekey, ct);
                         snameMap.put(namekey3, ct);
                         // // 通过姓名+手机号判断人员是否重复 thh 20220518 start
                         // System.System.debug('ct.MobilePhone_Encrypted__c1:' + ct.MobilePhone_Encrypted__c);
                         // if(String.isBlank(ct.MobilePhone_Encrypted__c)){
@@ -238,6 +266,7 @@
                     }
                     peopleMap.put(ct.CManageCode__c, ct);
                     System.debug('peopleMap'+peopleMap);
                     System.debug('nameMap111'+nameMap);
                 }
                 for (Gedata gedata: newGeDataList) {
                     String personCode = gedata.PersonManagementCode;
@@ -263,6 +292,8 @@
                        //无人员管理编码
                        string namekey = gedata.RelatedDepartment + ' ' + gedata.NameEncrypted + ' ' + gedata.MobileEncrypted;
                        string namekey1 = gedata.RelatedDepartment + ' ' + gedata.NameEncrypted;
                        string namekey2 = gedata.NameEncrypted + ' ' + gedata.MobileEncrypted;
                        string namekey3 = gedata.NameEncrypted;
                        system.debug('DepartmentClasskey     =    '+DepartmentClasskey);
                        system.debug('nameMap22222222    '+nameMap);
                        if (nameMap.containskey(DepartmentClasskey)) { 
@@ -271,31 +302,56 @@
                             System.debug('sMap'+sMap);
                             System.debug('sMap.containsKey(namekey)'+sMap.containsKey(namekey));
                             System.debug('Namekey'+namekey);
                             if (sMap.containsKey(namekey)) {
                             if (sMap.containsKey(namekey) && sMap.get(namekey).UnifiedI_Contact_ID__c == null) {
                                system.debug('根据名字匹配存在');
                                red.awsDataId = sMap.get(namekey).AWS_Data_Id__c;
                                red.sfid = sMap.get(namekey).id;
                            } else if(sMap.containsKey(namekey1) && sMap.get(namekey1).UnifiedI_Contact_ID__c == null) {
                                system.debug('sMap.containsKey(namekey1) && sMap.get(namekey1).UnifiedI_Contact_ID__c == null');
                                red.awsDataId = sMap.get(namekey1).AWS_Data_Id__c;
                                red.sfid = 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){
                                // red.awsDataId = sMap.get(gedata.NameEncrypted + gedata.MobileEncrypted).AWS_Data_Id__c;
                                // red.sfid = sMap.get(gedata.NameEncrypted + gedata.MobileEncrypted).id;
                            } else if(sMap.containsKey(namekey2) && sMap.get(namekey2).UnifiedI_Contact_ID__c == null){
                                system.debug('战略科室存在科室为空电话有值');
                                red.awsDataId = sMap.get(namekey2).AWS_Data_Id__c;
                                red.sfid = sMap.get(namekey2).id;
                            }else if(sMap.containsKey(namekey3) && sMap.get(namekey3).UnifiedI_Contact_ID__c == null){
                                system.debug('战略科室存在科室为空电话无值');
                                red.awsDataId = sMap.get(namekey3).AWS_Data_Id__c;
                                red.sfid = sMap.get(namekey3).id;
                            // // 通过姓名+手机号判断人员是否重复 thh 20220518 end
                            }else { // 7 完成
                                system.debug('根据名字匹配不存在');
                                //red.dataID = gedata.dataID;
                                //red.awsDataId = null;
                                //red.sfid = null;
                                for ( Integer i = 0; i < peopleList.size(); i++) {
                                    if (peopleList[i].Account.parent.Name !=DepartmentClasskey && peopleList[i].MobilePhone_Encrypted__c ==null) {
                                        System.debug('peopleList[i].Account.parent.Name = ' + peopleList[i].Account.parent.Name);
                                        System.debug('DepartmentClasskey = ' + DepartmentClasskey);
                                        System.debug('peopleList[i].MobilePhone_Encrypted__c = ' + peopleList[i].MobilePhone_Encrypted__c);
                                        System.debug('peopleList[i].Account.parent.Name !=DepartmentClasskey && peopleList[i].MobilePhone_Encrypted__c ==null');
                                        red.awsDataId =peopleList[i].AWS_Data_Id__c;
                                        red.sfid =peopleList[i].id;
                                    }
                                }
                            }
                            system.debug('red----------->'+red);
                            responseList.ResponseDetails.add(red);
                            //responseList.ResponseDetails.add(red);
                            system.debug('responseList.ResponseDetails'+responseList.ResponseDetails);
                        }else{
                            responseList.ResponseDetails.add(red);
                            system.debug('战略科室不存在');
                            for ( Integer i = 0; i < peopleList.size(); i++) {
                                if (peopleList[i].MobilePhone_Encrypted__c ==null) {
                                    System.debug('peopleList[i].MobilePhone_Encrypted__c ==null');
                                    red.awsDataId =peopleList[i].AWS_Data_Id__c;
                                    red.sfid =peopleList[i].id;
                                }
                            }
                            //responseList.ResponseDetails.add(red);
                        }
                        responseList.ResponseDetails.add(red);
                    }    
                }
            }
@@ -310,13 +366,13 @@
            iflog.ErrorLog__c += ex.getMessage() + '\n';
            iflog.ErrorLog__c += ex.getStackTraceString() + '\n';
        }
        update rowData;
        system.debug('Rowdata'+rowData);
        logstr += responseList +'\n';
        logstr += 'end';
        iflog.Log__c = logstr;
        update iflog;
        system.debug('responseList.ResponseDetails'+responseList.ResponseDetails);
        return responseList;
    update rowData;
    system.debug('Rowdata'+rowData);
    logstr += responseList +'\n';
    logstr += 'end';
    iflog.Log__c = logstr;
    update iflog;
    system.debug('responseList.ResponseDetails'+responseList.ResponseDetails);
    return responseList;
    }
}