From dd10019315aa7e0b26432bb48716da308cc11d82 Mon Sep 17 00:00:00 2001 From: Li Jun <buli@deloitte.com.cn> Date: 星期日, 24 四月 2022 18:55:57 +0800 Subject: [PATCH] Merge branch 'PIPLFunctionFixIssue0424' --- force-app/main/default/classes/SyncAccountContactToAWS.cls | 29 ++ force-app/main/default/classes/ContactTriggerHandlerTest.cls | 42 ++++ force-app/main/default/classes/ContactTriggerHandler.cls | 42 ++++ force-app/main/default/pages/ConsumTrialUpdate.page | 191 +++++++++++++++++++++ force-app/main/default/classes/NFM624Batch.cls | 5 force-app/main/default/classes/NFM624Rest.cls | 143 +++++++++------ force-app/main/default/classes/SyncAccountContactToAWSTest.cls | 75 ++++++++ force-app/main/default/classes/SyncAccountContactToAWSTest.cls-meta.xml | 5 8 files changed, 446 insertions(+), 86 deletions(-) diff --git a/force-app/main/default/classes/ContactTriggerHandler.cls b/force-app/main/default/classes/ContactTriggerHandler.cls index 43a4497..3c3c299 100644 --- a/force-app/main/default/classes/ContactTriggerHandler.cls +++ b/force-app/main/default/classes/ContactTriggerHandler.cls @@ -13,7 +13,9 @@ this.oldList = (List < Contact > ) Trigger.old; } protected override void beforeInsert() { - mobileNumberVerification(); + if(Test.isRunningTest()||UserInfo.getUserId()!=System.Label.ByPassTrigger){ //Add by Li Jun for PIPL 20220331 + mobileNumberVerification(); + } } protected override void afterInsert() { @@ -138,13 +140,41 @@ // ) ) ) { - Agency_Contact__c acObj = new Agency_Contact__c(Agency_ID__c = '000000000000000', Contact__c = nObj.Id, ContactId18__c = nObj.Id, Agency_Hospital__c = null, Name = nObj.LastName + ((String.isBlank(nObj.FirstName) == false) ? ' ' + nObj.FirstName : ''), Department_Class__c = nObj.Strategic_dept_Class__c, Type__c = nObj.Type__c, Doctor_Division1__c = nObj.Doctor_Division1__c); + //Agency_Contact__c acObj = new Agency_Contact__c(Agency_ID__c = '000000000000000', Contact__c = nObj.Id, ContactId18__c = nObj.Id, Agency_Hospital__c = null, Name = nObj.LastName + ((String.isBlank(nObj.FirstName) == false) ? ' ' + nObj.FirstName : ''), Department_Class__c = nObj.Strategic_dept_Class__c, Type__c = nObj.Type__c, Doctor_Division1__c = nObj.Doctor_Division1__c); + Agency_Contact__c acObj = new Agency_Contact__c( + Agency_ID__c = '000000000000000', + Contact__c = nObj.Id, + ContactId18__c = nObj.Id, + Agency_Hospital__c = null, + Name = nObj.LastName, + Name_Encrypted__c = nObj.LastName_Encrypted__c, + Department_Class__c = nObj.Strategic_dept_Class__c, + Type__c = nObj.Type__c, + Type_Encrypted__c = nObj.Type_Encrypted__c, + Doctor_Division1__c = nObj.Doctor_Division1__c, + Doctor_Division1_Encrypted__c = nObj.Doctor_Division1_Encrypted__c + ); targetContactMap.put(nObj.Id, acObj); } } } if (targetContactMap.size() > 0) { - upsert targetContactMap.values() ContactId18__c; + List<Agency_Contact__c> temp = targetContactMap.values(); + upsert temp ContactId18__c; + system.debug('temp='+temp); + EncryptInsert(temp); + } + } + + static void EncryptInsert(List<Agency_Contact__c> aclist){ + if(!(system.isFuture() || system.isBatch())){ + AwsServiceTool2.EncryptPushFuture(Json.serialize(aclist), 'Agency_Contact__c'); + }else{ + //Add By Li Jun for sync agency contact to aws 20220424 start + if(!Test.isRunningTest()){ + SyncAccountContactToAWS.assignOnceOneMinuteLater(); + } + //Add By Li Jun for sync agency contact to aws 20220424 end } } @@ -341,7 +371,6 @@ } } } - public static Map<Id,Id> NFM606_IdMap = new Map<Id,Id>(); // 606鎺ュ彛璋冪敤闂淇 thh 20220330 start private void sendToComPlat() { @@ -379,8 +408,9 @@ ID DoctorRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Doctor').getRecordTypeId(); ID AgencyRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); //鑾峰彇瀹㈡埛浜哄憳鐨勮褰曠被鍨婭D thh 20220330 end + System.debug('local.UnifiedI_Contact_ID__c1:' + local.UnifiedI_Contact_ID__c); + System.debug('local.MobilePhone1:' + local.MobilePhone); if (!local.IsFromSPO__c && !InternalStaffRecordTypeId.equals(local.RecordTypeId)) { - // 鍖婚櫌 瀹㈡埛浜哄憳 缁熶竴骞冲彴缂栫爜鏈夊�� 鍙戦�� PO if (DoctorRecordTypeId.equals(local.RecordTypeId) && String.isNotBlank(local.UnifiedI_Contact_ID__c)) { if (!NFM606_IdMap.containsKey(local.Id)) { @@ -414,7 +444,7 @@ // NFM606Controller.callout('', contactIdList); //娣诲姞future 鍒ゆ柇 add for pipl sushanhu 20220317 start // if (!(System.isFuture()||System.isBatch())) { - NFM606Controller.callout('', contactIdList); + NFM606Controller.callout('', contactIdList); // } else{ // NFM606Controller.executeNotFuture('', contactIdList); // } diff --git a/force-app/main/default/classes/ContactTriggerHandlerTest.cls b/force-app/main/default/classes/ContactTriggerHandlerTest.cls index ef501c9..5f26f37 100644 --- a/force-app/main/default/classes/ContactTriggerHandlerTest.cls +++ b/force-app/main/default/classes/ContactTriggerHandlerTest.cls @@ -6,20 +6,39 @@ public static Contact contact1 = new Contact(); public static Contact contact2 = new Contact(); + @Testsetup + static void setup(){ + TestDataUtility.CreatePIPolicyConfiguration('Agency_Contact__c'); + + } @isTest static void test_method_one() { + List<RecordType> HPrectCo = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; + List<RecordType> GIrectCo = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_Class_GI']; + List<RecordType> DoctorrectCo = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName = 'Doctor']; + if (HPrectCo.size() == 0) { + throw new ControllerUtil.myException('not found HP recordtype'); + } + if (GIrectCo.size() == 0) { + throw new ControllerUtil.myException('not found Department_Class_GI recordtype'); + } + if (DoctorrectCo.size() == 0) { + throw new ControllerUtil.myException('not found Doctor recordtype'); + } // 鍙栧紩鍏� account1.Name = 'test1鍖婚櫌'; - account1.RecordTypeId = '01210000000QemG'; + // account1.RecordTypeId = '01210000000QemG'; + account1.RecordTypeId = HPrectCo[0].Id; insert account1; // 鍙栧紩鍏堣铂浠昏�� contact1.AccountId = account1.Id; contact1.FirstName = '璨换鑰�'; contact1.LastName = 'test1鍖婚櫌'; - Account dept = [select Id from Account where RecordTypeId = '01210000000QemL']; + Account dept = [select Id from Account where RecordTypeId =: GIrectCo[0].Id]; contact1.Strategic_dept_Class__c = dept.Id; contact1.MobilePhone = '13409507069'; - contact1.RecordTypeId = '01210000000QfWdAAK'; + // contact1.RecordTypeId = '01210000000QfWdAAK'; + contact1.RecordTypeId = DoctorrectCo[0].Id; contact1.UnifiedI_Contact_ID__c = '100000'; insert contact1; MeetingManagement__c a = @@ -44,13 +63,23 @@ } @isTest static void test_method_two(){ + List<RecordType> AgencyrectCo1 = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency']; + if (AgencyrectCo1.size() == 0) { + throw new ControllerUtil.myException('not found AccountAgency recordtype'); + } + List<RecordType> AgencyrectCo2 = [select Id, Name, DeveloperName from RecordType where IsActive = true and SobjectType = 'Contact' and DeveloperName = 'Agency']; + if (AgencyrectCo2.size() == 0) { + throw new ControllerUtil.myException('not found ContactAgency recordtype'); + } account2.Name = 'test2 缁忛攢鍟�'; - account2.RecordTypeId = '01210000000Qem1'; + // account2.RecordTypeId = '01210000000Qem1'; + account2.RecordTypeId = AgencyrectCo1[0].Id; insert account2; contact2.FirstName = 'test'; contact2.LastName = 'Data'; - contact2.RecordTypeId = '01210000000QfWi'; + // contact2.RecordTypeId = '01210000000QfWi'; + contact2.RecordTypeId = AgencyrectCo2[0].Id; contact2.AccountId = account2.Id; contact2.Agency_User__c = true; contact2.MobilePhone = '18999999999'; @@ -61,7 +90,8 @@ Contact contact3 = new Contact(); contact3.FirstName = 'test'; contact3.LastName = 'Data'; - contact3.RecordTypeId = '01210000000QfWi'; + // contact3.RecordTypeId = '01210000000QfWi'; + contact3.RecordTypeId = AgencyrectCo2[0].Id; contact3.AccountId = account2.Id; // contact3.Agency_User__c = true; contact3.Ignore_Same_Name__c = true; diff --git a/force-app/main/default/classes/NFM624Batch.cls b/force-app/main/default/classes/NFM624Batch.cls index 8c77de7..b99180b 100644 --- a/force-app/main/default/classes/NFM624Batch.cls +++ b/force-app/main/default/classes/NFM624Batch.cls @@ -8,7 +8,7 @@ global Database.QueryLocator start(Database.BatchableContext bc) { - return Database.getQueryLocator([select Id, NFM624_Secondary_processing__c from BatchIF_Log__c where NFM624_Secondary_processing__c = false AND Type__C = 'NFM624' AND RowDataFlg__c = true AND retry_cnt__c < 3]); + return Database.getQueryLocator([select Id, NFM624_Secondary_processing__c from BatchIF_Log__c where NFM624_Secondary_processing__c = false AND Type__C = 'NFM624' AND RowDataFlg__c = true AND retry_cnt__c < 3 AND Is_Error__c != 1]); } global void execute(Database.BatchableContext BC, list<BatchIF_Log__c> scope) { @@ -24,8 +24,5 @@ // if(updateprocessingList.size()>0){ // update updateprocessingList; // } - if(!Test.isRunningTest()){ - Id execBTId = Database.executeBatch(new NFM601Batch(), 200); - } } } \ No newline at end of file diff --git a/force-app/main/default/classes/NFM624Rest.cls b/force-app/main/default/classes/NFM624Rest.cls index 84f63b1..f86d171 100644 --- a/force-app/main/default/classes/NFM624Rest.cls +++ b/force-app/main/default/classes/NFM624Rest.cls @@ -104,7 +104,11 @@ // 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'); @@ -144,17 +148,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) { @@ -177,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); @@ -214,7 +220,7 @@ //鏌ヨ鑱旂郴浜� Map < String, Map < String, Contact >> nameMap = new Map < String, Map < String, Contact >> (); //澶栧眰鎴樼暐绉戝锛屽唴灞傜瀹ゅ悕+鑱旂郴浜哄悕 List < Contact > peopleList = [select Id, - Account.Name, + Account.Name, Department__c, Account.parent.Name, Account.PlatformCode__c, @@ -227,20 +233,23 @@ AccountId from Contact where CManageCode__c IN: PersonManagementCodeList - 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 namekey = ct.Account.Name + ' ' + ct.LastName_Encrypted__c; + string namekey = ct.Account.Name + ' ' + ct.LastName_Encrypted__c.trim(); + string nameKey2 = ct.Account.Management_Code__c + ' ' + ct.LastName_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.LastName_Encrypted__c, ct); + snameMap.put(nameKey2,ct); + snameMap.put(ct.LastName_Encrypted__c.trim(), ct); nameMap.put(ct.Account.parent.Name, snameMap); system.debug('snameMap'+snameMap); } @@ -294,32 +303,40 @@ 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; @@ -328,6 +345,7 @@ if (gedata.AgentFlag == true) { //鏇存柊缁忛攢鍟嗚仈绯讳汉 if (!peopleMap.containsKey(personCode)) { + rowData.Is_Error__c = 1; logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃'; continue; } @@ -348,6 +366,7 @@ 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)) { //浜哄憳绠$悊缂栫爜瀛樺湪 @@ -363,13 +382,14 @@ upsertContactList.add(ct); } else { //鑱旂郴浜轰笉瀛樺湪 2 瀹屾垚 system.debug('2閫昏緫 鏈夊尰闄� 鏈夌瀹� 鏈変汉鍛樼鐞嗙紪鐮佷絾鏌ユ壘鏃犳浜� 鍔ㄤ綔锛氭姤閿�'); + rowData.Is_Error__c = 1; logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃'; continue; } } else { //浜哄憳绠$悊缂栫爜涓嶅瓨鍦� //鎼滅储浜哄悕/涓斿湪褰撳墠鎴樼暐绉戝绉戝涓� System.debug('浜哄憳绠$悊缂栫爜涓嶅瓨鍦�'); - string namekey = gedata.NameEncrypted; + string namekey = gedata.RelatedDepartment + ' ' + gedata.NameEncrypted; system.debug('DepartmentClasskey = '+DepartmentClasskey); system.debug('nameMap22222222 '+nameMap); if (nameMap.containskey(DepartmentClasskey)) { // 6 瀹屾垚 鏇存柊鎿嶄綔 @@ -379,7 +399,9 @@ if (sMap.containsKey(namekey)) { system.debug('Id璧嬪��'+sMap); ct.id = sMap.get(namekey).id; - } else { // 7 瀹屾垚 + } else if(sMap.containsKey(gedata.NameEncrypted)){ + ct.id = sMap.get(gedata.NameEncrypted).id; + }else { // 7 瀹屾垚 system.debug('7閫昏緫 鏃犱汉鍛樼鐞嗙紪鐮� 鏈夊尰闄� 鏈夌瀹� 浜哄悕鏌ユ壘鏃� 鍔ㄤ綔锛氭柊寤鸿仈绯讳汉 '); } } @@ -405,6 +427,7 @@ //upsertContactList.add(ct); } else { //浜哄憳绠$悊缂栫爜鏌ユ壘鏃犲�� 4 瀹屾垚 system.debug('4閫昏緫'); + rowData.Is_Error__c = 1; logstr += 'error:浜哄憳绠$悊缂栫爜 [PersonManagementCode] 瀵瑰簲鐨勮仈绯讳汉涓嶅瓨鍦紝姝ゆ潯鏁版嵁璺宠繃'; continue; } @@ -424,7 +447,7 @@ 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; @@ -447,6 +470,7 @@ } } }else if('鏃犳晥'.equals(hospital.Is_Active_Formula__c)){ + rowData.Is_Error__c = 1; logstr += 'error:璇ュ尰闄㈡棤鏁堬紝姝ゆ潯鏁版嵁璺宠繃'; continue; }else{ @@ -553,39 +577,34 @@ 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'; diff --git a/force-app/main/default/classes/SyncAccountContactToAWS.cls b/force-app/main/default/classes/SyncAccountContactToAWS.cls index 476cdba..df049b2 100644 --- a/force-app/main/default/classes/SyncAccountContactToAWS.cls +++ b/force-app/main/default/classes/SyncAccountContactToAWS.cls @@ -7,14 +7,15 @@ * 04/22/2022 - Bubba Li - Initial Code. * * */ -global class SyncAccountContactToAWS implements Database.Batchable<SObject>,Database.AllowsCallouts{ +global class SyncAccountContactToAWS implements Schedulable,Database.Batchable<SObject>,Database.AllowsCallouts{ + global String query; global SyncAccountContactToAWS(String query) { this.query = query; } global SyncAccountContactToAWS() { - this.query = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE AWS_Data_Id__c =\'\' And Contact__c != null'; + this.query = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE AWS_Data_Id__c =\'\' And Contact__c != null order by lastmodifieddate desc'; } global Database.QueryLocator start(Database.BatchableContext bc) { system.debug('Query by custom soql:'+this.query); @@ -23,9 +24,9 @@ global void execute(Database.BatchableContext BC, list<Agency_Contact__c> scope) { if(scope!=null && scope.size()>0){ for(Agency_Contact__c aContact:scope){ - aContact.Doctor_Division1_Encrypted__c = aContact.Contact__r.Doctor_Division1_Encrypted__c; - aContact.Name_Encrypted__c = aContact.Contact__r.LastName_Encrypted__c; - aContact.Type_Encrypted__c = aContact.Contact__r.Type_Encrypted__c; + aContact.Doctor_Division1_Encrypted__c = aContact.Contact__c!=null&&aContact.Contact__r.Doctor_Division1_Encrypted__c!=''?aContact.Contact__r.Doctor_Division1_Encrypted__c:''; + aContact.Name_Encrypted__c = aContact.Contact__c!=null&&aContact.Contact__r.LastName_Encrypted__c!=''?aContact.Contact__r.LastName_Encrypted__c:''; + aContact.Type_Encrypted__c = aContact.Contact__c!=null&&aContact.Contact__r.Type_Encrypted__c!=''?aContact.Contact__r.Type_Encrypted__c:''; aContact.AWS_Data_Id__c = ''; } system.debug('Agency Contact Info to AWS:'+JSON.serialize(scope)); @@ -33,7 +34,23 @@ } } + global void execute(SchedulableContext SC) { + Id execBTId = Database.executeBatch(new SyncAccountContactToAWS(), 1); + } + + public static void assignOnceOneMinuteLater() { + String hour = String.valueOf(Datetime.now().hour()); + String min = String.valueOf(Datetime.now().minute() + 1); + String ss = String.valueOf(Datetime.now().second()); + //parse to cron expression + String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?'; + SyncAccountContactToAWS s = new SyncAccountContactToAWS(); + System.schedule('Job Started At ' + String.valueOf(Datetime.now()), nextFireTime, s); + } + global void finish(Database.BatchableContext BC) { - + AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id = :BC.getJobId()]; + //then use the active job id and abort it + system.abortJob(a.id); } } \ No newline at end of file diff --git a/force-app/main/default/classes/SyncAccountContactToAWSTest.cls b/force-app/main/default/classes/SyncAccountContactToAWSTest.cls new file mode 100644 index 0000000..e926376 --- /dev/null +++ b/force-app/main/default/classes/SyncAccountContactToAWSTest.cls @@ -0,0 +1,75 @@ +@isTest +public class SyncAccountContactToAWSTest { + class HttpMock implements HttpCalloutMock{ + + public HTTPResponse respond(HTTPRequest request) { + // 鍒涘缓涓�涓亣鐨勫洖搴� + System.debug('------------------------------------------------------'); + HttpResponse response = new HttpResponse(); + string body = ''; + system.debug(request.getEndpoint()); + if(request.getEndpoint().contains('token')){ + system.debug('url=token'); + response.setHeader('Content-Type', 'application/json'); + body='{ "message": "", "object": "freqfewqfewewfewfew", "status": "", "success": true, "timestamp": 0, "txId": "" }'; + } else if(request.getEndpoint().contains('insert')){ + system.debug('url=Insert'); + response.setHeader('Content-Type', 'application/json'); + body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }'; + } else if(request.getEndpoint().contains('update')){ + system.debug('url=update'); + response.setHeader('Content-Type', 'application/json'); + body='{ "message": "", "object": [ { "dataId": "123456", "directShippmentAddress": "", "directShippmentAddressEncrypt": "", "isDelete": 0, "phoneNumber": "", "phoneNumberEncrypt": "", "sfRecordId": "a2R1m0000007BPD" } ], "status": "", "success": true, "timestamp": 0, "txId": "" }'; + } else{} + + response.setBody(body); + response.setStatus('OK'); + response.setStatusCode(200); + return response; + // } + } + } + @isTest + static void startTest() { + TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Agency_Contact__c','Contact'}); + Test.setMock(HttpCalloutMock.class, new HttpMock()); + List<Agency_Contact__c> lra = new List<Agency_Contact__c>(); + lra.add(new Agency_Contact__c(AWS_Data_Id__c='Test AWS')); + insert lra; + System.Test.startTest(); + try{ + //String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE id=\'a2R10000001cfatEAA\' And AWS_Data_Id__c =\'\' And Contact__c != null'; + String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE AWS_Data_Id__c =\'Test AWS\''; + SyncAccountContactToAWS contactBatch = new SyncAccountContactToAWS(soql); + Id execBTId = Database.executeBatch(contactBatch,1); + }catch(Exception e){ + system.debug('Exception from sync aws batch:'+ e.getMessage()); + } + try{ + SyncAccountContactToAWS.assignOnceOneMinuteLater(); + }catch(Exception e){ + system.debug('Exception from sync aws scheduler:'+ e.getMessage()); + } + System.Test.stopTest(); + } + + // static testMethod void testExecute() { + // // This test runs a scheduled job at midnight Sept. 3rd. 2022 + // String CRON_EXP = '0 0 0 3 9 ? 2022'; + // String soql = 'SELECT id,Doctor_Division1__c,Doctor_Division1_Encrypted__c,Name,Name_Encrypted__c,Type__c,Type_Encrypted__c,AWS_Data_Id__c,Contact__c, Contact__r.Doctor_Division1_Encrypted__c,Contact__r.LastName_Encrypted__c, Contact__r.Type_Encrypted__c FROM Agency_Contact__c WHERE id=\'a2R10000001cfatEAA\' And AWS_Data_Id__c =\'\' And Contact__c != null'; + + // System.Test.startTest(); + // // Schedule the test job + // String jobId = system.schedule('SyncAccountContactToAWSTest', CRON_EXP, new SyncAccountContactToAWS(soql)); + // // Get the information from the CronTrigger API object + // CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId]; + // // Verify the expressions are the same + // System.assertEquals(CRON_EXP, ct.CronExpression); + // // Verify the job has not run + // System.assertEquals(0, ct.TimesTriggered); + // // Verify the next time the job will run + // System.assertEquals('2022-09-03 00:00:00', String.valueOf(ct.NextFireTime)); + // System.Test.StopTest(); + // } + +} \ No newline at end of file diff --git a/force-app/main/default/classes/SyncAccountContactToAWSTest.cls-meta.xml b/force-app/main/default/classes/SyncAccountContactToAWSTest.cls-meta.xml new file mode 100644 index 0000000..40d6793 --- /dev/null +++ b/force-app/main/default/classes/SyncAccountContactToAWSTest.cls-meta.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> + <apiVersion>54.0</apiVersion> + <status>Active</status> +</ApexClass> diff --git a/force-app/main/default/pages/ConsumTrialUpdate.page b/force-app/main/default/pages/ConsumTrialUpdate.page index b268d0b..00d5674 100644 --- a/force-app/main/default/pages/ConsumTrialUpdate.page +++ b/force-app/main/default/pages/ConsumTrialUpdate.page @@ -5,6 +5,7 @@ <apex:stylesheet value="{!URLFOR($Resource.ConsumTrialPageCss)}"/> <apex:includeScript value="{!URLFOR($Resource.ReceivingNotePageJS)}"/> <apex:includeScript value="{!URLFOR($Resource.CommonUtilJs)}"/> + <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }"/> <apex:form id="allForm"> <style> table.headTable td { @@ -26,6 +27,7 @@ <script type="text/javascript"> var heightAjustment = 120; var widthAjustment = 30; + var staticResource = JSON.parse('{!staticResource}'); // 閫傜敤鎸夐挳 function applyJs() { @@ -240,6 +242,187 @@ } } + //2022 02 24 寮犲崕寤� display PI Data start + var rowBList; + var TrialUser = {}; + var ids = []; + + queryUser(); + + function q1(){ + var p = new Promise(function(resolve, reject){ + rowBList = JSON.parse('{!rowListString}') + var x = 0; + var y = 0; + let searchCallBack = function searchCallBack(result){ + let contacts = result.object; + if(contacts == null){ + return; + } + let temp = {} + temp.trialUser = contacts.trialUser; + TrialUser[contacts.dataId] = temp; + x++; + }; + for(var i=0;i<rowBList.length;i++){ + if(rowBList[i].AWSDataId ){ + y++; + ids.push(rowBList[i].AWSDataId + '_' + rowBList[i].Id); + AWSService.query(staticResource.queryUrl,rowBList[i].AWSDataId,searchCallBack,staticResource.token); + } + } + var id = setInterval(function(){ + if(x == y){ + console.log('success') + resolve('success'); + clearInterval(id); + } + },500); + }); + return p; + } + + function q2(value){ + var p = new Promise(function(resolve, reject){ + console.log('杩涘叆q2'+value) + for(var i=0;i<ids.length;i++){ + console.log('i = '+i); + document.getElementById(ids[i]).children[0].children[0].innerText = TrialUser[ids[i].substring(0,18)].trialUser; + console.log('i = '+i); + } + }); + } + + function queryUser(){ + unblockUI() + rowBList = JSON.parse('{!rowListString}') + console.log('pageB.fixMode = '+'{!pageB.fixMode}') + if('{!pageB.fixMode}' == 'true'){ + q1().then(function(data){ + return q2(data); + }) + unblockUI(); + }else{ + blockme(); + console.log(rowBList) + let searchCallBack = function searchCallBack(result){ + let contacts = result.object; + if(contacts == null){ + return; + } + let temp = {} + temp.trialUser = contacts.trialUser; + TrialUser[contacts.dataId] = temp; + }; + for(var i=0;i<rowBList.length;i++){ + ids.push(rowBList[i].AWSDataId + '_' + rowBList[i].Id); + AWSService.query(staticResource.queryUrl,rowBList[i].AWSDataId,searchCallBack,staticResource.token); + } + unblockUI(); + } + } + + function showPIDiv(awsDataId){ + if(awsDataId.length == 0){ + return + } + if(TrialUser[awsDataId.substring(0,18)] == null){ + return + } + console.log('awsDataId Value:'+awsDataId); + let parentNode = document.getElementById(awsDataId); + let createDiv = document.createElement("div"); + createDiv.id = awsDataId+"_PI"; + let piInformation = TrialUser[awsDataId.substring(0,18)].trialUser + //let piInformation = 'Name:'+contact['943114607025717249'].lastName +'\n' +'Phone:'+contact['943114607025717249'].phone + createDiv.innerText = piInformation; + let x=window.event.x; + let y=window.event.y; + createDiv.style.left=x; + createDiv.style.top=y; + createDiv.style.background="#dddddd"; + createDiv.style.position = "absolute"; + parentNode.appendChild(createDiv); + parentNode.style.position = "relative"; + } + + function hidePIDiv(awsDataId){ + if(awsDataId.length == 0){ + return + } + if(TrialUser[awsDataId.substring(0,18)] == null){ + return + } + document.getElementById(awsDataId+'_PI').remove(); + } + + function q3(){ + var p = new Promise(function(resolve, reject){ + console.log('saveRecordJS') + + var a = 0; + var b = 0; + let newCallBack = function newCallBack(result,indexNumber){ + + console.log('result = '+JSON.stringify(result)) + //璧嬪�糳ataId鍜宼rialUser + document.getElementById('allPage:allForm:dataBlock:dataline_R_aws:'+indexNumber+':EditAWSDataId').value = result.object[0].dataId; + document.getElementById('allPage:allForm:dataBlock:dataline_R:'+indexNumber+':inputField:6:inputField').value = result.object[0].trialUser; + let transParameters = { + txId: result.txId, + isSuccess: 1 + }; + let confirmCallBack = function confirmCallBack(result){ + console.log('confirmCallBack = '+JSON.stringify(result)) + } + b++; + AWSService.confirmTrans(staticResource.transactionUrl,JSON.stringify(transParameters),confirmCallBack,staticResource.token) + }; + for(var i=0;i<rowBList.length;i++){ + if(document.getElementById('allPage:allForm:dataBlock:dataline_L:'+i+':rowCheck').checked == true){ + a++; + } + } + debugger + for(var i=0;i<rowBList.length;i++){ + if(document.getElementById('allPage:allForm:dataBlock:dataline_L:'+i+':rowCheck').checked == true){ + //鍔犲瘑璇曠敤鑰� + var trialUser = document.getElementById('allPage:allForm:dataBlock:dataline_R:'+i+':inputField:6:j_id86').children[0].children[0].value + let consumApplyPayloadList = []; + let consumApplyPIData = new Object(); + consumApplyPIData.trialUser = trialUser; + consumApplyPIData.sfRecordId = ''; + consumApplyPayloadList.push(consumApplyPIData); + AWSService.postConsumTrial(staticResource.newUrl,i,JSON.stringify(consumApplyPayloadList),newCallBack,staticResource.token); + } + } + var id = setInterval(function(){ + if(a == b){ + console.log('a==b success') + resolve('success'); + clearInterval(id); + } + },500); + }); + return p; + } + + function q4(){ + debugger + saveRecord(); + } + function saveRecordJS(){ + if('{!pageB.fixMode}' != 'true'){ + return + } + // q3().then(function(data){ + // return q4(data); + // }) + saveRecord(); + unblockUI(); + } + //2022 02 24 寮犲崕寤� display PI Data end + </script> <apex:pageMessages /> <apex:actionFunction name="saveRecord" action="{!saveRecord}" oncomplete="unblockUI();refopener();" rerender="allForm"/> @@ -281,7 +464,7 @@ <apex:commandButton value="閫傜敤" rendered="{!canEdit}" onclick="applyJs();return false;"/> </span> <span style="margin-left: 10px;"> - <apex:commandButton value="淇濆瓨" onclick="blockme(); saveRecord(); return false;" rendered="{!canEdit}" reRender="allForm"/> + <apex:commandButton value="淇濆瓨" onclick="blockme(); saveRecordJS(); return false;" rendered="{!canEdit}" reRender="allForm"/> </span> </td> </tr> @@ -349,6 +532,9 @@ </apex:repeat> </table> </div> + <apex:repeat id="dataline_R_aws" value="{!pageB.rowBList}" var="var"> + <apex:inputHidden value="{!var.rnd.AWS_Data_Id__c}" id="EditAWSDataId"/> + </apex:repeat> <div id="in_Div" style="overflow:auto;"> <table class="list" style="border-bottom-width: 0px; font-size:11px; border-spacing:0;" border="" id="tableData"> <apex:variable value="{!0}" var="Cnt_R" /> @@ -356,7 +542,8 @@ <tr id="tableData_R_{!Cnt_R}" class="dataRow" onmouseover="if (window.hiOn){hiOn(this);} " onmouseout="if (window.hiOff){hiOff(this);} " onblur="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" > <apex:variable value="{!0}" var="Col_R" /> <apex:repeat value="{!inputFieldList}" var="info" id="inputField" > - <td class="dataCellBorder1 intf {!info.value} col_{!info.value}" style="{!IF(info.value=='RAESD_Status__c' && var.rnd[info.value]=='鐢宠鑰呮敹璐G','background-color: #009DDC','')}"> + <td class="dataCellBorder1 intf {!info.value} col_{!info.value}" style="{!IF(info.value=='RAESD_Status__c' && var.rnd[info.value]=='鐢宠鑰呮敹璐G','background-color: #009DDC','')}" id="{! IF(info.value=='Trial_User__c',var.rnd.AWS_Data_Id__c+'_'+var.rnd.Id,info.value)}" onmouseover="showPIDiv('{! IF(info.value=='Trial_User__c',var.rnd.AWS_Data_Id__c+'_'+var.rnd.Id,'')}')" onmouseout="hidePIDiv('{! IF(info.value=='Trial_User__c',var.rnd.AWS_Data_Id__c+'_'+var.rnd.Id,'')}')"> + <apex:outputPanel rendered="{!((contains(var.canChangeField, info.value) || var.canChangeField == '') && pageB.fixMode == true && var.canChange == true)}"> <apex:inputField id="inputField" value="{!var.rnd[info.value]}" onchange="setChangeFlg('{!var.lineNo-1}');changeEditable('{!var.lineNo-1}');" rendered="{!info.value != 'Asset_loaner_category__c' || var.haveAsset}" /> -- Gitblit v1.9.1