From 1312ba82d4c880bdb5357d28e0d4af5b285f610f Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期四, 10 三月 2022 15:54:39 +0800
Subject: [PATCH] 最近一月修改内容

---
 force-app/main/default/classes/NFM704Rest.cls |  169 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 118 insertions(+), 51 deletions(-)

diff --git a/force-app/main/default/classes/NFM704Rest.cls b/force-app/main/default/classes/NFM704Rest.cls
index 0a89d87..0e20bc5 100644
--- a/force-app/main/default/classes/NFM704Rest.cls
+++ b/force-app/main/default/classes/NFM704Rest.cls
@@ -14,13 +14,21 @@
     public static final String LOG_TYPE = 'NFM704';
 
     global class GeData {
-        public String StaffMCode;   //SFDC浜哄憳绠$悊缂栫爜
+        public String StaffMCode;   //浜哄憳绠$悊缂栫爜OBPM
         public String HospitalMCode;     //鍖婚櫌绠$悊缂栫爜
-        public String OfficeMCode;   //绉戝绠$悊缂栫爜
+        public String OfficeMCode;   //OBPM绉戝
         public String HcpNo;    //HPC缂栫爜
         public String HCPLevel; //HCP绛夌骇
         public String Name;    //濮撳悕
         public String Mobile;   //鐢佃瘽
+        public String State;    //鐪�
+        public String City;     //甯�
+        public String WorkingSeniority; //涓村簥宸ヤ綔骞撮檺
+        public String TechnicalTitle; //鎶�鏈亴绉�
+        public String Speciality;   //鎿呴暱鐨勬墜鏈�
+        public String ProfessionalField;    //涓撲笟棰嗗煙
+        public String Society1;  //瀛︿細鍚嶇О
+        public String EventStatus; //瀛︿細鑱岀О
     }
 
     @HttpPost
@@ -89,10 +97,11 @@
             List<String> DoctorNoList = new List<String>();
 
             //寰呮洿鏂扮殑瀹㈡埛浜哄憳List
-            List<Contact> updateList = new List<Contact>();
+            List<Contact> upsertList = new List<Contact>();
 
-            //绉戝缂栫爜List
-            List<String> officeMCodeList = new List<String>();
+            //鍖婚櫌缂栫爜List
+            List<String> HospitalMCodeList = new List<String>();
+
 
             for(GeData ged : itemMasterList){
                 String dataComplete = verify(ged);
@@ -101,69 +110,86 @@
                     continue;
                 }
                 DoctorNoList.add(ged.StaffMCode);
-                officeMCodeList.add(ged.OfficeMCode);
+                //officeMCodeList.add(ged.OfficeMCode);
+                HospitalMCodeList.add(ged.HospitalMCode);
             }
-
+            system.debug('HospitalMCodeList=============>'+HospitalMCodeList);
+            system.debug('DoctorNoList=============>'+DoctorNoList);
+            //Map<String, Map<String,Contact>> hospitalMap = new Map<String, Map<String,Contact>>();
             Map<String, Contact> conListMap = new Map<String, Contact>();
             List<Contact> conList = [select Id,
-                                            CManageCode__c,     //浜哄憳绠$悊缂栫爜
-                                            Account.Hospital_Name__c,       //鍖婚櫌鍚嶇О
-                                            Account.Department_Name__c,       //绉戝鍚嶇О
-                                            Name,       //濮撳悕
-                                            Phone,      //鐢佃瘽
-                                            HcpNo__c,       //HCP缂栫爜
-                                            Isactive__c,    //鏄惁鏈夋晥
-                                            UpdateStatus__c            //鎿嶄綔绫诲瀷
-                                            from Contact WHERE CManageCode__c IN:DoctorNoList order by AccountId];
-
+                                            Management_Code__c, //鍖婚櫌绠$悊缂栫爜
+                                            CManageCode__c     //浜哄憳绠$悊缂栫爜
+                                            from Contact WHERE CManageCode__c IN:DoctorNoList];
+            system.debug('conList============>'+conList);
             
             for(Contact con : conList ){
+                
                 conListMap.put(con.CManageCode__c, con);
+                //hospitalMap.put(con.Management_Code__c,conListMap);
             }
 
-            //Management_Code__c
-            List<Account> accList = [select Id, Name, Management_Code__c from Account where Management_Code__c in :officeMCodeList];
-
+            List<Account> accList = [select Id, Name,GI_Main__c,Management_Code__c from Account where Management_Code__c in :HospitalMCodeList];
+            system.debug('accList=============>'+accList);
             Map<String, Account> accMap = new Map<String, Account>();
 
             for(Account acc : accList){
-                accMap.put(acc.Management_Code__c, acc);
+               accMap.put(acc.Management_Code__c, acc);
             }
+
 
             for( GeData ged : itemMasterList ){
-
-                Contact con = new Contact();
-
-                logstr += conListMap.get(ged.StaffMCode).Id;
-
-                if(conListMap.containsKey(ged.StaffMCode)){
-
-                    logstr += '宸插瓨鍦ㄥ鎴蜂汉鍛榎n';
-                    con.Id = conListMap.get(ged.StaffMCode).Id;
-
-                }else {
-                    logstr += '涓嶅瓨鍦ㄧ殑瀹㈡埛浜哄憳\n';
+                //Map<String, Contact> tempMap = new Map<String, Contact>();
+                if(accMap.containsKey(ged.HospitalMCode)){//鍖婚櫌缂栫爜鏄惁瀛樺湪 鏄�
+                    Contact con = new Contact();
+                    if(conListMap.containsKey(ged.StaffMCode)){
+                        //瀛樺湪鍒欐洿鏂�
+                        system.debug('鏇存柊鑱旂郴浜�');
+                        logstr += conListMap.get(ged.StaffMCode).Id + '\n';
+                        logstr += '宸插瓨鍦ㄥ鎴蜂汉鍛榎n';
+                        con.Id = conListMap.get(ged.StaffMCode).Id;
+                        system.debug('request'+conListMap.get(ged.StaffMCode).Management_Code__c.equals(ged.HospitalMCode));
+                        if(conListMap.get(ged.StaffMCode).Management_Code__c.equals(ged.HospitalMCode)){//鍒ゆ柇鑱旂郴浜轰笂鐨勭鐞嗙紪鐮佸拰鎺ュ彛浼犺緭杩囨潵鐨勭鐞嗙紪鐮佹槸鍚︿竴鑷�
+                            system.debug('request'+conListMap.get(ged.StaffMCode).Management_Code__c.equals(ged.HospitalMCode));
+                        }else{
+                            con.OBPMHospital__c = accMap.get(ged.HospitalMCode).Id;//鎺ユ敹鐨勭鐞嗙紪鐮佸搴旂殑鍖婚櫌鍐欏埌OBPM鍖婚櫌涓�
+                        }
+                        con = assignment(ged,con);
+                    }else{
+                        //涓嶅瓨鍦ㄥ垯鏂板缓
+                        system.debug('鏂板缓鑱旂郴浜�');
+                        //logstr += '涓嶅瓨鍦ㄧ殑瀹㈡埛浜哄憳\n';
+                        con.OwnerId = accMap.get(ged.HospitalMCode).GI_Main__c;//鎵�鏈変汉鍙栧尰闄笂鐨勬秷鍖栫鎷呭綋
+                        con.AccountId = accMap.get(ged.HospitalMCode).Id;//鏂板缓鑱旂郴浜烘斁鍒板尰闄笅
+                        con.LastName = ged.Name;
+                        con.FirstName = '';
+                        con = assignment(ged,con);
+                    }
+                    upsertList.add(con);
+                }else{//鍚�
+                    continue;
+                    logstr += '涓嶅瓨鍦ㄧ殑鍖婚櫌绠$悊缂栫爜:['+accMap.get(ged.HospitalMCode)+']/n';
                 }
 
-                //AccountId
-                if( accMap.get(ged.OfficeMCode) != null ){
-                    con.AccountId = accMap.get(ged.OfficeMCode).Id;
-                }else {
-                    logstr += '褰撳墠绉戝id鏈夎鎴栦笉瀛樺湪';
-                }
+                // //AccountId
+                // if( accMap.get(ged.OfficeMCode) != null ){
+                //     con.AccountId = accMap.get(ged.OfficeMCode).Id;
+                // }else {
+                //     logstr += '褰撳墠绉戝id鏈夎鎴栦笉瀛樺湪';
+                // }
 
-                con.HcpNo__c = ged.HcpNo;
-                con.HCPLevel__c = ged.HCPLevel;
-                con.LastName = ged.Name;
-                con.MobilePhone = ged.Mobile;
+                // con.HcpNo__c = ged.HcpNo;
+                // con.HCPLevel__c = ged.HCPLevel;
+                // con.LastName = ged.Name;
+                // con.MobilePhone = ged.Mobile;
 
-                conListMap.put(ged.StaffMCode, con);
-                
+                // conListMap.put(ged.StaffMCode, con);
             }
-
-            if(conListMap.size() > 0 ){
+            system.debug('upsertList==================>'+upsertList);
+            if(upsertList.size() > 0 ){
                 // Update updateList;
-                UpSert conListMap.values();
+                Oly_TriggerHandler.bypass('ConsumableOrderTrigger');
+                UpSert upsertList;
             }
 
             rowData.retry_cnt__c = 0;
@@ -191,9 +217,9 @@
         if (ged.HospitalMCode == null) {
             result += 'DataError: 鍖婚櫌绠$悊缂栫爜 [ HospitalMCode ] is null!\n';
         }
-        if (ged.OfficeMCode == null) {
-            result += 'DataError: 绉戝绠$悊缂栫爜 [ OfficeMCode ] is null!\n';
-        }
+        // if (ged.OfficeMCode == null) {
+        //     result += 'DataError: 绉戝绠$悊缂栫爜 [ OfficeMCode ] is null!\n';
+        // }
         if (ged.HcpNo == null) {
             result += 'DataError: HCP缂栫爜 [ HcpNo ] is null!\n';
         }
@@ -210,4 +236,45 @@
         return result;
     }
 
+    public static Contact assignment(GeData ged,Contact con){//鑱旂郴浜烘暟鎹祴鍊兼柟娉�
+        List<String> societyList = Breakup(ged.Society1);
+        List<String> eventStatusList = Breakup(ged.EventStatus);
+        con.NameOBPM__c             = ged.Name;//濮撳悕
+        con.MobileOBPM__c           = ged.Mobile;//鐢佃瘽
+        con.stateOBPM__c            = ged.State;//鐪丱BPM
+        con.CityOBPM__c             = ged.City;//甯侽BPM
+        con.HcpNo__c                = ged.HcpNo;//HPC缂栫爜
+        con.HCPLevel__c             = ged.HCPLevel;//HCP绛夌骇
+        con.OBPMDepartment__c       = ged.OfficeMCode;//OBPM绉戝
+        con.WorkingSeniorityOBPM__c = ged.WorkingSeniority;  //涓村簥宸ヤ綔骞撮檺
+        con.TechnicalTitleOBPM__c   = ged.TechnicalTitle;//鎶�鏈亴绉�
+        con.SpecialityOBPM__c       = ged.Speciality;//鎿呴暱鐨勬墜鏈�
+        con.ProfessionalField__c    = ged.ProfessionalField;//涓撲笟棰嗗煙
+        if(societyList.size()>0){
+            con.Learn_name1__c          = societyList[0];//瀛︿細鍚嶇О1
+        }
+        if(societyList.size()>1){
+            con.Learn_name2__c          = societyList[1];//瀛︿細鍚嶇О2
+        }
+        if(societyList.size()>2){
+            con.Learn_name3__c          = societyList[2];//瀛︿細鍚嶇О3
+        }
+        if(eventStatusList.size()>0){
+            con.Learn_serve1__c         = eventStatusList[0];//瀛︿細鑱岀О1
+        }
+        if(eventStatusList.size()>1){
+            con.Learn_serve2__c         = eventStatusList[1];//瀛︿細鑱岀О2
+        }
+        if(eventStatusList.size()>2){
+            con.Learn_serve3__c         = eventStatusList[2];//瀛︿細鑱岀О3
+        }
+        return con;
+    }
+
+    public static List<String> Breakup (String str){
+        // List<string> over = new List<string>();
+        // over =聽str.split('鈫�');
+        List<string> over = str.split('鈫�');
+        return over;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1