liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@isTest
private class UpdateNewMaintenanceTaskBatchTest {
    static testMethod void testMethod1() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
 
        // Implement test code
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hp;
 
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;
 
 
     
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today().addDays(-1);
        contract.Hospital__c = hp.Id;
        contract.Department_Class__c = dc.Id;
        contract.Department__c = dpt1.Id;
        contract.Contract_Start_Date__c = Date.today().addMonths(-1);
        contract.Contract_End_Date__c = Date.today().addMonths(11);
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.Service_Contract_Staff__c = UserInfo.getUserId();
        contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); 
        insert contract;
 
        //生成服务合同报告书
        NewMaintenanceReport_Task__c tempNMCT = new NewMaintenanceReport_Task__c();
        tempNMCT.Name = 'FWreport-01';
        tempNMCT.Distribution_Start_Date__c = Date.today();
        tempNMCT.Distribution_End_Date__c = Date.today().addMonths(2).addDays(-1).addDays(30);
        tempNMCT.NewMaintenance_Contract__c = contract.Id;
        tempNMCT.ActualDistributionTimes_Quarter__c = 0;
        tempNMCT.OverOrCurrent__c = false;
        insert tempNMCT;
 
 
        Database.executeBatch(new UpdateNewMaintenanceTaskBatch(true));
    }
        static testMethod void testMethod2() {
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
 
        // Implement test code
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'];
        if (rectHp.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'];
        if (rectDpt.size() == 0) {
            return;
        }
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id);
        insert hp;
 
        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id);
        dpt1.Name         = '*';
        dpt1.Department_Name__c  = 'TestDepart1';
        dpt1.ParentId            = dc.Id;
        dpt1.Department_Class__c = dc.Id;
        dpt1.Hospital__c         = hp.Id;
        insert dpt1;
 
 
     
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Status__c ='契約';
        contract.Maintenance_Contract_No__c = 'Kami_Contract_No';
        contract.Contract_Conclusion_Date__c = Date.today().addDays(-1);
        contract.Hospital__c = hp.Id;
        contract.Department_Class__c = dc.Id;
        contract.Department__c = dpt1.Id;
        contract.Contract_Start_Date__c = Date.today().addMonths(-1);
        contract.Contract_End_Date__c = Date.today().addMonths(11);
        contract.SalesOfficeCode_selection__c = '北京RC';
        contract.Service_Contract_Staff__c = UserInfo.getUserId();
        contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); 
        insert contract;
 
        //生成服务合同报告书
        NewMaintenanceReport_Task__c tempNMCT = new NewMaintenanceReport_Task__c();
        tempNMCT.Name = 'FWreport-01';
        tempNMCT.Distribution_Start_Date__c = Date.today();
        tempNMCT.Distribution_End_Date__c = Date.today().addMonths(2).addDays(-1).addDays(30);
        tempNMCT.NewMaintenance_Contract__c = contract.Id;
        tempNMCT.ActualDistributionTimes_Quarter__c = 0;
        tempNMCT.OverOrCurrent__c = false;
        insert tempNMCT;
 
 
        Database.executeBatch(new UpdateNewMaintenanceTaskBatch());
    }
}