@isTest
private class UpdateConrenewalpriceBatchTest {
@isTest static void UpdateConrenewalpriceBatchTest() {

	//戦略科室分類
	RecordType rectSct1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 普外科'];

	Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];

	//战略科室普外科所有人 科室呼吸科所有人
	User deptPOwner = new User(Test_staff__c = true, LastName = 'deptP', FirstName = 'owner', Alias = 'deptP', CommunityNickname = 'deptPOwner', Email = 'olympus_deptpowner@sunbridge.com', Username = 'olympus_deptpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
	insert deptPOwner;

	//医院所有人
	User comOwner = new User(Test_staff__c = true, LastName = 'com', FirstName = 'owner', Alias = 'com', CommunityNickname = 'comOwner', Email = 'olympus_comowner@sunbridge.com', Username = 'olympus_comowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
	insert comOwner;

	//病院
	List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
	if (rectCo.size() == 0) {
		return;
	}

	// 医院
	Account company = new Account();
	company.RecordTypeId = rectCo[0].Id;
	company.Name = 'HPテスト1';
	company.OwnerId = comOwner.Id;
	insert company;

	//战略科室 普外科
	Account sct1 = [Select Id, Name, Department_Class_Label__c, Hospital__c, OwnerId from Account where Parent.Id = :company.Id and RecordTypeId = : rectSct1.Id];
	sct1.OwnerId = deptPOwner.Id;
	update sct1;

	Account dpt1 = new Account();
	//dpt1.RecordTypeId = rectDpt1.Id;
	dpt1.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GS').getRecordTypeId();
	dpt1.Name = '普外科';
	dpt1.Department_Class__c = sct1.Id;
	dpt1.ParentId = sct1.Id;
	dpt1.Department_Name__c  = '診療科1';
	dpt1.Hospital__c = company.Id;
	// dpt1.OwnerId = deptHOwner.Id;
	insert dpt1;

	Achievement_linkage__c oppMapping = new Achievement_linkage__c();
	oppMapping.Name = '01';
	oppMapping.Consumption_rate_Lower__c = 0;
	oppMapping.Consumption_rate_Upper__c = 50;
	oppMapping.PriceCount_Lower__c  = -40;
	oppMapping.PriceCount_Upper__c  = -30;
	insert oppMapping;

	Maintenance_Contract__c mc=new Maintenance_Contract__c();
	mc.Department__c = dpt1.Id;
	mc.Status__c='契約';
	mc.Maintenance_Contract_No__c='dsdsds';
	mc.Management_Code__c ='SH-RS-FJ0054009';
	insert mc;

	// 测试程序
	UpdateConrenewalpriceBatch u1=new UpdateConrenewalpriceBatch();
	Database.executeBatch(u1, 1);

	List<String> aa=new List<string>();
	aa.add(String.valueOf(mc.id));
	Database.executeBatch(new UpdateConrenewalpriceBatch(aa), 1);
}
}