From d8dc84a3d56df839895f1c417a4d9cbee763d262 Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期五, 03 三月 2023 14:50:59 +0800
Subject: [PATCH] gzw 测试环境代码更新

---
 force-app/main/default/classes/NFM704Rest.cls |  254 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 199 insertions(+), 55 deletions(-)

diff --git a/force-app/main/default/classes/NFM704Rest.cls b/force-app/main/default/classes/NFM704Rest.cls
index 0a89d87..fc1ea27 100644
--- a/force-app/main/default/classes/NFM704Rest.cls
+++ b/force-app/main/default/classes/NFM704Rest.cls
@@ -5,7 +5,11 @@
 
 @RestResource(urlMapping='/NFM704/*')
 global with sharing class NFM704Rest {
-
+     //add Response to aws 20220421 add sushanhu start
+   
+     static Boolean SFStatus=true;
+     static String SFMessage='';
+    //add Response to aws 20220421 add sushanhu end
     global class GeDatas {
         public NFMUtil.Monitoring Monitoring;
         public  GeData[] GeData;
@@ -14,13 +18,32 @@
     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; //瀛︿細鑱岀О // 甯︽湁绠ご 鍒囧壊鑾峰彇EventStatuslist pi鏀归�犱箣鍚� 瀛�***
+        //add for pipl  by sushanhu 20220420 start
+        // public String HCPLevelEncrypted; //HCP绛夌骇瀵嗘枃                //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // public String NameEncrypted;    //濮撳悕                       //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // public String MobileEncrypted;   //鐢佃瘽                      //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // public String TechnicalTitleEncrypted; //鎶�鏈亴绉�            //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // public String SpecialityEncrypted;   //鎿呴暱鐨勬墜鏈�            //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // public String ProfessionalFieldEncrypted;    //涓撲笟棰嗗煙      //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // public List<String> EventStatusEncryptedList; //瀛︿細鑱岀О 澶囨敞鏈夐�昏緫 甯︽湁绠ご 鍒囧壊鑾峰彇EventStatuslist 瀛榟ash      //zhj鏂版柟妗堟敼閫� 2022-12-07
+        public String DataId;//AWSDATAID
+        //public String WorkingSeniorityEncrypted;//涓村簥宸ヤ綔骞撮檺瀵嗘枃
+        //add for pipl  by sushanhu 20220420 end                        //zhj鏂版柟妗堟敼閫� 2022-12-07
     }
 
     @HttpPost
@@ -28,7 +51,9 @@
         //鍙栧緱鎺ュ彛浼犺緭鍐呭
         String strData = RestContext.request.requestBody.toString();
         GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class);
-    
+        //add Response to aws 20220421 add sushanhu start
+        NFMUtil.NFMResponse result = NFMUtil.getNFMResponse();
+        //add Response to aws 20220421 add sushanhu end
         if(ges == null) {
             return;
         }
@@ -49,8 +74,16 @@
         RestResponse res = RestContext.response;
         res.addHeader('Content-Type', 'application/json');
         res.statusCode = 200;
-        String jsonResponse = '{"Result":{"Result": "00", "Message":""}}';
+        // String jsonResponse = '{"Result":{"Result": "00", "Message":""}}';
+        // res.responseBody = blob.valueOf(jsonResponse);
+        //updata response toAWS sushanhu for pipl 20220421 start
+        result.SFStatus=SFStatus;
+        result.SFMessage=SFMessage;
+        //String jsonResponse =JSON.serialize(result);
+        String jsonResponse ='{"SFMessage":"","staticResponse":{"Result":{"Result":"00","Message":""}},"SFStatus":true}';
+        system.debug('result---'+jsonResponse);
         res.responseBody = blob.valueOf(jsonResponse);
+        //updata response toAWS sushanhu for pipl 20220421 end
         return;
 
     }
@@ -84,15 +117,21 @@
 
         Savepoint sp = Database.setSavepoint();
 
+        // 704鏀瑰杽 2023-02-09 ssm start
+        // 澧炲姞涓�涓爣璁帮紝褰撳洖浼犳暟鎹噷锛屽尰闄㈢鐞嗙紪鐮佷负绌烘椂锛屾姤閿欎絾涓嶉噸鍙�
+        Boolean error_without_resend = false;
+        // 704鏀瑰杽 2023-02-09 ssm end
+
         try{
             //绠$悊缂栫爜List
             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 +140,95 @@
                     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
+                                            and CManageCode__c != null];
+            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;
+                        // add by sushanhu for pipl 20220420 start
+                        //con.LastName_Encrypted__c =ged.NameEncrypted;         //zhj鏂版柟妗堟敼閫� 2022-12-07
+                        // add by sushanhu for pipl 20220420 end
+                        con.FirstName = '';
+                        con = assignment(ged,con);
+                    }
+                    upsertList.add(con);
+                }else{//鍚�
+                    // continue;
+                    logstr += '涓嶅瓨鍦ㄧ殑鍖婚櫌绠$悊缂栫爜:['+accMap.get(ged.HospitalMCode)+']/n';
+                    // 704鏀瑰杽 2023-02-09 ssm start
+                    // 璁剧疆鏍囪涓簍rue
+                    error_without_resend = true;
+                    // 704鏀瑰杽 2023-02-09 ssm end
+                    throw new ControllerUtil.myException('涓嶅瓨鍦ㄧ殑鍖婚櫌绠$悊缂栫爜:['+accMap.get(ged.HospitalMCode)+']');
                 }
 
-                //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('ContactTriggerHandler');
+                UpSert upsertList;
             }
 
             rowData.retry_cnt__c = 0;
@@ -176,10 +241,24 @@
             logstr += '\n' + ex.getMessage();
             iflog.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + iflog.ErrorLog__c;
             // 寮傚父閲嶅彂
-            rowData = NFMUtil.LogAutoSend(rowData, ex, null);
+            // 704鏀瑰杽 2023-02-09 ssm start
+            if (error_without_resend) {
+                // retry_cnt璁剧疆涓�0
+                rowData.retry_cnt__c = 0;
+                logstr += '\nend';
+                rowData.ErrorLog__c += ex.getMessage() + '\n' + ex.getStackTraceString() + '\n';
+                iflog.ErrorLog__c += ex.getMessage() + '\n' + ex.getStackTraceString() + '\n';
+                iflog.Log__c += logstr;
+                upsert iflog;
+                upsert rowData;
+            } else {
+                rowData = NFMUtil.LogAutoSend(rowData, ex, null);
+            }
+            // 704鏀瑰杽 2023-02-09 ssm end
         }
         iflog.Log__c = logstr;
         upsert iflog;
+        upsert rowData;
     }
 
     public static String verify(GeData ged){
@@ -191,9 +270,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 +289,69 @@
         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;//涓撲笟棰嗗煙
+        //add by sushanhu 20220420 for pipl start 
+        // con.HCPLevel_Encrypted__c   = ged.HCPLevelEncrypted;                     //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // con.NameOBPM_Encrypted__c   = ged.NameEncrypted;                         //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // con.MobileOBPM_Encrypted__c    = ged.MobileEncrypted;                    //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // con.WorkingSeniorityOBPM_Encrypted__c = ged.WorkingSeniorityEncrypted;   //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // con.TechnicalTitleOBPM_Encrypted__c = ged.TechnicalTitleEncrypted;       //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // con.ProfessionalField_Encrypted__c = ged.ProfessionalFieldEncrypted;     //zhj鏂版柟妗堟敼閫� 2022-12-07
+        // con.SpecialityOBPM_Encrypted__c = ged.SpecialityEncrypted;               //zhj鏂版柟妗堟敼閫� 2022-12-07
+        con.AWS_Data_Id__c          = ged.DataId;
+        //add by sushanhu 20220420 for pipl end
+
+        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
+            // add by sushanhu for pipl 20220420 start
+            //zhj鏂版柟妗堟敼閫� 2022-12-07 start
+            // if(ged.EventStatusEncryptedList.size()>0){
+            //      con.Learn_serve1_Encrypted__c =ged.EventStatusEncryptedList[0];
+            // }
+            //zhj鏂版柟妗堟敼閫� 2022-12-07 end
+            // add by sushanhu for pipl 20220420 end
+        }
+        if(eventStatusList.size()>1){
+            con.Learn_serve2__c         = eventStatusList[1];//瀛︿細鑱岀О2
+            // add by sushanhu for pipl 20220420 start
+            //con.Learn_serve2_Encrypted__c =ged.EventStatusEncryptedList[1];   //zhj鏂版柟妗堟敼閫� 2022-12-07
+            // add by sushanhu for pipl 20220420 end
+        }
+        if(eventStatusList.size()>2){
+            con.Learn_serve3__c         = eventStatusList[2];//瀛︿細鑱岀О3
+            // add by sushanhu for pipl 20220420 start
+            //con.Learn_serve3_Encrypted__c =ged.EventStatusEncryptedList[2];   //zhj鏂版柟妗堟敼閫� 2022-12-07
+            // add by sushanhu for pipl 20220420 end
+        }
+        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