@isTest
|
private class ProductScoreHistoryServiceTest {
|
static Account dep;
|
private static void setup() {
|
// OLY_OCM-644
|
StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
|
|
//Account 经销商 recordtypeID
|
Id AgencyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
|
|
//Account 医院 recordtypeID
|
Id HPRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
|
|
// 省
|
Address_Level__c al = new Address_Level__c(Name = '東京', Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999');
|
insert al;
|
// 市
|
Address_Level2__c al2 = new Address_Level2__c(Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999', Level1_Name__c = '東京',
|
Name = '渋谷区', Level2_Code__c = 'CN-9999', Level2_Sys_No__c = '9999999', Address_Level__c = al.Id);
|
insert al2;
|
|
Account AccountHP = new Account(Name = 't_e_s_tHP001', AgentCode_Ext__c = '9999900', RecordTypeId = HPRecordTypeId,
|
Is_Active__c = '有効', Attribute_Type__c = '卫生部', Speciality_Type__c = '综合医院',
|
Grade__c = '一级', OCM_Category__c = 'SLTV', Is_Medical__c = '医疗机构',
|
State_Master__c = al.Id, City_Master__c = al2.Id, Town__c = '东京', OCM_man_province_txt__c = '北京');
|
insert AccountHP;
|
|
// 戦略科室を得る
|
Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :AccountHP.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
|
// 診療科を作る
|
dep = new Account();
|
dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
|
dep.Name = 'test dep';
|
dep.AgentCode_Ext__c = '9999998';
|
dep.ParentId = strategicDep[0].Id;
|
dep.Department_Class__c = strategicDep[0].Id;
|
dep.Hospital__c = AccountHP.Id;
|
insert dep;
|
|
Account AccountAgent1 = new Account(Name = 't_e_s_tAgent001', RecordTypeId = AgencyRecordTypeId);
|
insert AccountAgent1;
|
|
Account AccountAgent2 = new Account(Name = 't_e_s_tAgent002', RecordTypeId = AgencyRecordTypeId, ParentId = AccountHP.Id);
|
insert AccountAgent2;
|
|
Product2 prod01 = new Product2(
|
Name = 'Test01',
|
ProductCode = 'Test01',
|
Asset_Model_No__c = 'Test01',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true,
|
Family = 'ET',
|
Category2__c = '耗材',
|
Category3__c = 'ERCP',
|
Category4__c = '导丝',
|
Category5__c = 'Visiglide35'
|
);
|
Product2 prod02 = new Product2(
|
Name = 'T_est002',
|
ProductCode = 'T_estCode002',
|
Category2__c = '耗材',
|
Category3__c = 'ERCP',
|
Category4__c = '导丝',
|
Category5__c = 'Visiglide35',
|
Family = 'ET',
|
Packing_list_manual__c = 1,
|
Asset_Model_No__c = 'T_est02',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true
|
);
|
Product2 prod03 = new Product2(
|
Name = 'T_est003',
|
ProductCode = 'T_estCode003',
|
Category2__c = '耗材',
|
Category3__c = 'Capsule',
|
Category4__c = 'CP打印机',
|
Category5__c = 'CP打印机',
|
Family = 'ET',
|
Packing_list_manual__c = 1,
|
Asset_Model_No__c = 'T_est03',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true
|
);
|
Product2 prod04 = new Product2(
|
Name = 'T_est004',
|
ProductCode = 'T_estCode004',
|
Category2__c = '耗材',
|
Category3__c = '基幹',
|
Category4__c = '清洗刷',
|
Category5__c = 'DBW',
|
Family = 'ET',
|
Packing_list_manual__c = 1,
|
Asset_Model_No__c = 'T_est04',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true
|
);
|
Product2 prod05 = new Product2(
|
Name = 'T_est005',
|
ProductCode = 'T_estCode005',
|
Category2__c = '耗材',
|
Category3__c = '基幹',
|
Category4__c = '清洗刷',
|
Category5__c = 'DBW',
|
Family = 'ET',
|
Packing_list_manual__c = 6,
|
Asset_Model_No__c = 'T_est05',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true
|
);
|
Product2 prod06 = new Product2(
|
Name = 'T_est006',
|
ProductCode = 'T_estCode006',
|
Category2__c = '耗材',
|
Category3__c = '基幹',
|
Category4__c = '清洗刷',
|
Category5__c = 'DBW',
|
Family = 'ET',
|
Packing_list_manual__c = 5,
|
Asset_Model_No__c = 'T_est06',
|
SFDA_Status__c = '有効',
|
Dealer_special_Object__c = true
|
);
|
Product2 [] pd2s = new List<Product2>{
|
prod01, prod02, prod03, prod04, prod05, prod06
|
};
|
insert pd2s;
|
|
List<Product2__c> prod2cs = new List<Product2__c>();
|
for(Product2 p: pd2s) {
|
Product2__c pdc = new Product2__c(
|
Name=p.Name,
|
OT_CODE_Text__c=p.ProductCode,
|
Product2__c = p.Id
|
);
|
prod2cs.add(pdc);
|
}
|
insert prod2cs;
|
|
System.runAs(new User(Id = Userinfo.getUserId())) {
|
|
//产品得分表
|
// ET_Product_ScoreTable_Batch bat = new ET_Product_ScoreTable_Batch();
|
// Database.executeBatch(bat);
|
Product_Score_Table__c [] pstList = new List<Product_Score_Table__c>();
|
Product_Score_Table__c pst01 = new Product_Score_Table__c(
|
OCM_Term__c = '154P',
|
Plan_Category3__c = 'ERCP',
|
Category3__c = 'ERCP',
|
Category4__c = '导丝');
|
pstList.add(pst01);
|
Product_Score_Table__c pst02 = new Product_Score_Table__c(
|
OCM_Term__c = '154P',
|
Plan_Category3__c = 'Capsule',
|
Category3__c = 'Capsule',
|
Category4__c = 'CP打印机'
|
);
|
pstList.add(pst02);
|
|
Product_Score_Table__c pst03 = new Product_Score_Table__c(
|
OCM_Term__c = '154P',
|
Plan_Category3__c = 'Capsule',
|
Category3__c = '基幹',
|
Category4__c = '清洗刷'
|
);
|
pstList.add(pst03);
|
|
for(Product_Score_Table__c pst: pstList) {
|
pst.UniqueKey__c = pst.OCM_Term__c+':'+pst.Category3__c+':'+pst.Category4__c;
|
}
|
insert pstList;
|
|
}
|
|
}
|
|
|
static testMethod void testMethod1() {
|
setup();
|
Test.startTest();
|
Account AccountHP = [SELECT Id, Name, Management_Code__c, OCM_man_province_txt__c FROM Account WHERE Name = 't_e_s_tHP001'];
|
Account AccountAgent2 = [SELECT Id,Name FROM Account WHERE Name = 't_e_s_tAgent002'];
|
|
Id PSTH_RecordTypeId = Schema.SObjectType.Product_Score_Table_History__c.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
|
|
//历史资料
|
Product2 p = [SELECT Plan_Term__c,Category3__c,Category4__c,CreatedDate FROM Product2 WHERE Name = 'Test01'];
|
String month = String.valueOf(p.CreatedDate.month());
|
String term = p.Plan_Term__c.left(4);
|
String uniqueKey = 'A:' + term + ':' + month + ':' + AccountHP.OCM_man_province_txt__c + ':' + AccountHP.Management_Code__c + ':' + AccountAgent2.Id + ':' + p.Category3__c + ':' + p.Category4__c;
|
String pstKey = term + ':' + p.Category3__c + ':' + p.Category4__c;
|
Product_Score_Table__c pst = [SELECT Id FROM Product_Score_Table__c WHERE UniqueKey__c = :pstKey];
|
Product_Score_Table_History__c psth01 = new Product_Score_Table_History__c();
|
//UniqueKey__c : (151PA/151PB)计画财年:第三分类 :新4.5分类 :经销商 :医院
|
psth01.UniqueKey__c = uniqueKey;
|
psth01.Hospital__c = AccountHP.Id;
|
psth01.Product_Score_Table__c = pst.Id;
|
psth01.OCM_Province_Text__c = AccountHP.OCM_man_province_txt__c;
|
psth01.Province_From_Consume__c = TRUE;
|
psth01.Sales_Amount__c = 67;
|
psth01.Shipping_date__c = Date.newInstance(Date.today().year(), Date.today().month(), 1);
|
psth01.Agency__c = AccountAgent2.Id;
|
psth01.Qty__c = 2;
|
psth01.RecordTypeId = PSTH_RecordTypeId;
|
insert psth01;
|
ProductScoreHistoryService.GetNotCompleteData(dep.Id);
|
|
ProductScoreHistoryService.RevokeData(psth01.Id);
|
ProductScoreHistoryService.GetDoContentC();
|
ProductScoreHistoryService.GetCheckPurchaseC();
|
ProductScoreHistoryService.GetActionContentC();
|
String saverow = '[{"attributes":{"type":"Product_Score_Table_History__c","url":"/services/data/v51.0/sobjects/Product_Score_Table_History__c/' + psth01.Id + '"},"Id":"' + psth01.Id + '","Name":"testname"}]';
|
ProductScoreHistoryService.SaveData(saverow);
|
|
|
|
|
}
|
}
|