@isTest public class RetrospectiveWeeklyReportControllerTest { static user myUser_Test; static Contact core; static Account myAccount2; public static Account account1 = new Account(); public static Account account2 = new Account(); public static Contact contact1 = new Contact(); public static Contact contact2 = new Contact(); public static User user = new User(); public static Agency_Hospital_Link__c agency_hospital_link = new Agency_Hospital_Link__c(); public static Agency_Contact__c agency_contact = new Agency_Contact__c(); public static ProductTypes__c product_types = new ProductTypes__c(); // 经销商活动周报导入 update by vivek start public static ProductTypes__c product_types1 = new ProductTypes__c(); public static ProductTypes__c product_types2 = new ProductTypes__c(); public static ProductTypes__c product_types3 = new ProductTypes__c(); public static FieldClassification__c fcftion = new FieldClassification__c(); public static FieldClassification__c fcftion1 = new FieldClassification__c(); public static product2 pro2 = new product2(); // 经销商活动周报导入 update by vivek end public static Agency_Opportunity__c agency_opportunity = new Agency_Opportunity__c(); public static OlympusCalendar__c olympus_calendar = new OlympusCalendar__c(); public static String report_id; public static String report_header_id; public RetrospectiveWeeklyReportControllerTest() { } @TestSetup static void makeData(){ List strList= new List(); strList.add('Agency_Contact__c'); strList.add('Contact'); TestDataUtility.CreatePIPolicyConfigurations(strList); } private static void testinit(){ account1.Name = 'test1医院'; account1.RecordTypeId = '01210000000QemG'; insert account1; account2.Name = 'test1经销商'; account2.RecordTypeId = '01210000000Qem1'; insert account2; // 取引先責任者 contact1.AccountId = account1.Id; contact1.FirstName = '責任者'; contact1.LastName = 'test1医院'; insert contact1; contact2.AccountId = account2.Id; contact2.FirstName = '責任者'; contact2.LastName = 'test1经销商'; insert contact2; Profile p = [select Id from Profile where Name = '901_经销商活动系统']; user.ProfileId = p.Id; user.ContactId = contact2.Id; user.FirstName = 'ユーザー'; user.LastName = 'テスト'; user.Email = 'test_user@example.com'; user.emailencodingkey='UTF-8'; user.languagelocalekey='zh_CN'; user.localesidkey='ja_JP'; user.timezonesidkey='Asia/Shanghai'; user.Username = 'test_user@example.com'; user.Alias = 'テユ'; user.CommunityNickname = 'テストユーザー'; insert user; // 代理店医院 agency_hospital_link.Name = 'test1代理店医院'; agency_hospital_link.Hospital__c = account1.Id; agency_hospital_link.Agency__c = account2.Id; agency_hospital_link.OwnerId = user.Id; agency_hospital_link.Agency_Campaign_Obj__c = true; insert agency_hospital_link; // 先生 agency_contact.Name = 'test1医院先生'; agency_contact.Doctor_Division1__c = '院长'; agency_contact.Type__c = '医生'; agency_contact.Agency_Hospital__c = agency_hospital_link.Id; agency_contact.OwnerId = user.Id; // 经销商活动周报导入 update by vivek start // agency_contact.Hospital_ID18__c = agency_hospital_link.Id; // 经销商活动周报导入 update by vivek end insert agency_contact; // 製品区分 product_types.Name = '製品区分1'; product_types.OwnerId = user.Id; product_types.Department_Cateogy__c = 'GI;BF;ET;GYN;OTH;URO;GS;ENT'; insert product_types; // 经销商活动周报导入 update by vivek start product_types1.OwnerId = user.Id; product_types1.Department_Cateogy__c = 'GI;BF;ET;GYN;OTH;URO;GS;ENT'; product_types1.Name = '170系统'; product_types1.OPD_Flg__c = true; insert product_types1; product_types2.OwnerId = user.Id; product_types2.Department_Cateogy__c = 'GI;BF;ET;GYN;OTH;URO;GS;ENT'; product_types2.Name = 'EUS系统'; product_types2.SIS_Flg__c = true; insert product_types2; product_types3.OwnerId = user.Id; product_types3.Department_Cateogy__c = 'GI;BF;ET;GYN;OTH;URO;GS;ENT'; product_types3.Name = 'CHF胆道镜'; insert product_types3; fcftion.ProductCcategory__c='波科'; fcftion.ET_ENG_classification__c = 'ET'; fcftion.ProductClassification__c = 'ERCP'; insert fcftion; fcftion1.ProductCcategory__c='波科'; fcftion1.ET_ENG_classification__c = 'ENG'; fcftion1.ProductClassification__c = 'ERCP'; insert fcftion1; // 经销商活动周报导入 update by vivek end // 引合 agency_opportunity.RecordTypeId = [select Id,DeveloperName from RecordType where IsActive = true and SobjectType = 'Agency_Opportunity__c' and DeveloperName = 'Opportunity'].Id; agency_opportunity.Name = '引合1'; agency_opportunity.Hospital_Target__c = account1.Id; agency_opportunity.Agency__c = account2.Id; agency_opportunity.Agency_Hospital__c = agency_hospital_link.Id; agency_opportunity.StageName__c = '还没申请预算'; agency_opportunity.OwnerId = user.Id; agency_opportunity.NewOpportunity_Agency_Apply_Status__c = '批准'; insert agency_opportunity; // オリンパスカレンダー olympus_calendar.Date__c = Date.valueOf('2017-04-10'); olympus_calendar.OwnerId = user.Id; insert olympus_calendar; ProductTypes__c producttyoe = WeeklyReportCmp.getProduct(product_types.Id); } @isTest private static void test01() { // List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; // if (rectCo.size() == 0) { // return; // } // myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5'); // insert myAccount2; // Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)']; // // Profile prof = [select Id from Profile where Name ='System Administrator']; // core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id); // insert core; // myUser_Test = New User(ContactId = core.id,UserPro_Type__c = 'ET',Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // insert myUser_Test; //testinit(); User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()]; system.runAs(thisUser){ // testinit(); // myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5'); // insert myAccount2; // Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)']; // // Profile prof = [select Id from Profile where Name ='System Administrator']; // core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id); // insert core; // myUser_Test = New User(ContactId = core.id,UserPro_Type__c = 'ET',Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // insert myUser_Test; // TestDataUtility.CreatePIPolicyConfiguration('Agency_Contact__c'); // String sobjectType = 'Agency_Contact__c'; //Test.startTest(); List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5'); insert myAccount2; Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)']; // Profile prof = [select Id from Profile where Name ='System Administrator']; core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id); insert core; myUser_Test = New User(ContactId = core.id,UserPro_Type__c = 'ET',Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); insert myUser_Test; testinit(); //TestDataUtility.CreatePIPolicyConfiguration('Agency_Contact__c'); String sobjectType = 'Agency_Contact__c'; Test.startTest(); PIHelper.getPIIntegrationInfo(sobjectType); RetrospectiveWeeklyReportController retrospectiveWeeklyReportobj = new RetrospectiveWeeklyReportController(); retrospectiveWeeklyReportobj.UserDoin(); retrospectiveWeeklyReportobj.setalldata(); RetrospectiveWeeklyReportController.selectdoctor3c(); RetrospectiveWeeklyReportController.getalldata(); RetrospectiveWeeklyReportController.getProduct(product_types.Id); String ids =String.valueof(contact1.Id); String key =ids+':20170410'; String aa =RetrospectiveWeeklyReportController.createReportHeader('','2017-04-10',ids,key); RetrospectiveWeeklyReportController.makeReportHeader('','2017-04-10',ids,key); //RetrospectiveWeeklyReportController.getHospitalList(''); RetrospectiveWeeklyReportController.getUseProduct1('a','ERCP'); RetrospectiveWeeklyReportController.getDoctorList(String.valueof(agency_hospital_link.Id)); String bb=RetrospectiveWeeklyReportController.saveAgencyReport('消化科',2,false,2,String.valueof(contact1.Id),'','','','','','',aa,String.valueof(agency_hospital_link.Id),'',String.valueof(agency_contact.Id),'2017-04-10','','','','','','','','2017-04-10'); // Agency_Report__c agency_report=RetrospectiveWeeklyReportController.makeAgencyReport('消化科',2,false,2,String.valueof(contact1.Id),'','','','','','',String.valueof(aa.Id),String.valueof(agency_hospital_link.Id),'',String.valueof(agency_contact.Id),'2017-04-10','','','','','','','','2017-04-10'); // insert agency_report; RetrospectiveWeeklyReportController.editAgencyReport(bb,'消化科',2,false,2,String.valueof(contact1.Id),'','','','','','',aa,String.valueof(agency_hospital_link.Id),'',String.valueof(agency_contact.Id),'2017-04-10','','','','2017-04-10'); RetrospectiveWeeklyReportController.selectOpportunityByIdAndHospitalLinkId('',''); RetrospectiveWeeklyReportController.getReports('2017-04-10','2017-04-10'); RetrospectiveWeeklyReportController.getReportsById(''); RetrospectiveWeeklyReportController.getReportsByDate('2017-04-10','2017-04-10'); retrospectiveWeeklyReportobj.selectMAgencyPerson(); String ccc ='活动日,医院,科室,经销商人员,工作记录,医院人员,产品分类(第三分类),使用产品1(产品型号),使用产品2,使用产品3,效果/进度,科室同类耗材月使用量,术士分类,已采用其他品牌,其他品牌产品类别,产品用量,工作标记\r\n,,,广津 经销商,,临床信息(使用量)收集,,,,,,,,,,,\r\n2022/5/16,大连市妇女儿童医疗中心,泌尿外科,曹 玉鹏,科室会,医生,ERCP,B5-2Q,BML-110A,MAJ-403,不认可,1,导丝,库克,,,需要\r\n,,,广津 经销商,,,,,,,,,,,,,\r\n'; RetrospectiveWeeklyReportController.processDataAWSId(ccc); RetrospectiveWeeklyReportController.getAwsurl('Agency_Contact__c'); List fields =new List(); RetrospectiveWeeklyReportController.processData(ccc,'',fields); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('呼吸科'); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('耳鼻喉科'); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('ET耗材'); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('消化科'); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('普外科'); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('妇科'); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('其他'); RetrospectiveWeeklyReportController.GetDepartment_Cateogy('泌尿科'); List> prolist = new List>(); Map x = new Map(); x.put('label','aaa'); prolist.add(x); RetrospectiveWeeklyReportController.ifTrueProduct(prolist,'aaa'); RetrospectiveWeeklyReportController.newlyBuild(String.valueof(agency_hospital_link.Id),'test1医院先生','',''); RetrospectiveWeeklyReportController.selectPurposeTypes('SIS'); RetrospectiveWeeklyReportController.selectProductClassificationc('ERCP'); RetrospectiveWeeklyReportController.selectProductCcategory(); RetrospectiveWeeklyReportController.selectProductCcategory01('波科'); Test.stopTest(); } } @isTest private static void test02() { // List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; // if (rectCo.size() == 0) { // return; // } // myAccount2 = new Account(Name='Testaccount003',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5'); // insert myAccount2; // Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)']; // // Profile prof = [select Id from Profile where Name ='System Administrator']; // core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id); // insert core; // myUser_Test = New User(ContactId = core.id,UserPro_Type__c = 'ENG',Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser3', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); // insert myUser_Test; //testinit(); User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()]; system.runAs(thisUser){ List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } myAccount2 = new Account(Name='Testaccount003',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5'); insert myAccount2; Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)']; // Profile prof = [select Id from Profile where Name ='System Administrator']; core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id); insert core; myUser_Test = New User(ContactId = core.id,UserPro_Type__c = 'ENG',Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser3', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com'); insert myUser_Test; testinit(); //TestDataUtility.CreatePIPolicyConfiguration('Agency_Contact__c'); String sobjectType = 'Agency_Contact__c'; Test.startTest(); PIHelper.getPIIntegrationInfo(sobjectType); RetrospectiveWeeklyReportController retrospectiveWeeklyReportobj = new RetrospectiveWeeklyReportController(); retrospectiveWeeklyReportobj.UserDoin(); retrospectiveWeeklyReportobj.setalldata(); RetrospectiveWeeklyReportController.selectdoctor3c(); RetrospectiveWeeklyReportController.getalldata(); RetrospectiveWeeklyReportController.getProduct(product_types.Id); String ids =String.valueof(contact1.Id); String key =ids+':20170410'; String aa =RetrospectiveWeeklyReportController.createReportHeader('','2017-04-10',ids,key); String bb=RetrospectiveWeeklyReportController.saveAgencyReport('消化科',2,false,2,String.valueof(contact1.Id),'','','','','','',aa,String.valueof(agency_hospital_link.Id),'',String.valueof(agency_contact.Id),'2017-04-10','','','','','','','','2017-04-10'); // Agency_Report__c agency_report=RetrospectiveWeeklyReportController.makeAgencyReport('消化科',2,false,2,String.valueof(contact1.Id),'','','','','','',String.valueof(aa.Id),String.valueof(agency_hospital_link.Id),'',String.valueof(agency_contact.Id),'2017-04-10','','','','','','','','2017-04-10'); // insert agency_report; RetrospectiveWeeklyReportController.editAgencyReport(bb,'消化科',2,false,2,String.valueof(contact1.Id),'','','','','','',aa,String.valueof(agency_hospital_link.Id),'',String.valueof(agency_contact.Id),'2017-04-10','','','','2017-04-10'); RetrospectiveWeeklyReportController.selectOpportunityByIdAndHospitalLinkId('',''); RetrospectiveWeeklyReportController.getReports('2017-04-10','2017-04-10'); RetrospectiveWeeklyReportController.getReportsById(''); RetrospectiveWeeklyReportController.getReportsByDate('2017-04-10','2017-04-10'); retrospectiveWeeklyReportobj.selectMAgencyPerson(); String ccc ='活动日,医院,科室,经销商人员,工作记录,医院人员,产品分类(第三分类),使用产品1(产品型号),使用产品2,使用产品3,效果/进度,科室同类耗材月使用量,术士分类,已采用其他品牌,其他品牌产品类别,产品用量,工作标记\r\n2022/5/16,大连市妇女儿童医疗中心,泌尿外科,曹 玉鹏,临床信息(使用量)收集,医生,ERCP,B5-2Q,B5-2Q,B5-2Q,不认可,1,导丝,库克,,,需要\r\n2022/5/16,大连市妇女儿童医疗中心,神经内二科,广津 经销商,院内入院申请,周正强,aaa,B5-2Q,BML-110A,MAJ-403,申请驳回,1,取石气囊,波科,,,需要\r\n'; RetrospectiveWeeklyReportController.processDataAWSId(ccc); RetrospectiveWeeklyReportController.getAwsurl('Agency_Contact__c'); List fields =new List(); RetrospectiveWeeklyReportController.processData(ccc,'',fields); List> prolist = new List>(); Map x = new Map(); x.put('label','aaa'); prolist.add(x); RetrospectiveWeeklyReportController.ifTrueProduct(prolist,'aaa'); RetrospectiveWeeklyReportController.newlyBuild(String.valueof(agency_hospital_link.Id),'test1医院先生','',''); RetrospectiveWeeklyReportController.selectPurposeTypes('SIS'); RetrospectiveWeeklyReportController.selectProductClassificationc('ERCP'); RetrospectiveWeeklyReportController.selectProductCcategory(); RetrospectiveWeeklyReportController.selectProductCcategory01('波科'); //RetrospectiveWeeklyReportController.saveAgencyContact('波科','波科','波科','波科','波科','波科',String.valueof(agency_hospital_link.Id),'波科'); RetrospectiveWeeklyReportController.saveAgencyContact('波科','波科','波科',String.valueof(agency_hospital_link.Id),'波科'); //zhj 新方案改造,参数Encrypt去掉 2023-01-28 RetrospectiveWeeklyReportController.deleteAgencyReport('121'); RetrospectiveWeeklyReportController.GetProductClassification('121'); Test.stopTest(); } } // @isTest // private static void test03() { // RetrospectiveWeeklyReportController.improveTestRate(); // } @isTest private static void searchAgencyDataId() { User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()]; system.runAs(thisUser){ testinit(); Test.startTest(); RetrospectiveWeeklyReportController.searchAgencyDataId(agency_hospital_link.Id); Test.stopTest(); } } }