高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
@isTest
private class CreateNewMaintenanceTaskBatchTest {
 
    static testMethod void testMethod1() {
        ControllerUtil.EscapeNFM007Trigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
        Oly_TriggerHandler.bypass('NFM106Controller.NFM106Trigger');
 
 
        // 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_GS'];
        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_GS'];
        
        // 診療科を作る
        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;
 
        //顺延 (合同盖章完毕日 > [合同开始日 + 1个月] )
        Maintenance_Contract__c contract2 = new Maintenance_Contract__c();
        contract2.Name = 'tect contract2';
        contract2.Status__c ='契約';
        contract2.Maintenance_Contract_No__c = 'Kami_Contract_No2';
        contract2.Contract_Conclusion_Date__c = Date.today().addDays(-1);
        contract2.Hospital__c = hp.Id;
        contract2.Department_Class__c = dc.Id;
        contract2.Department__c = dpt1.Id;
        contract2.Contract_Start_Date__c = Date.today().addMonths(-4);
        contract2.Contract_End_Date__c = Date.today().addMonths(16);
        contract2.Contract_print_completed__c = Date.today().addMonths(-3);
        contract2.SalesOfficeCode_selection__c = '北京RC';
        contract2.Service_Contract_Staff__c = UserInfo.getUserId();
        contract2.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); 
        insert contract2;
 
        //创建SLA任务
        task__c task = new task__c();
        task.RecordTypeId = Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('SLAReport_Task').getRecordTypeId();
        task.taskDifferent__c = '被动任务';
        task.taskStatus__c = '03 完成';
        task.Activity_Date__c = Date.today();
        task.account__c =  dpt1.Id;
        task.Maintenance_Contract__c = contract.Id;
        insert task;
 
 
        //System.Test.StartTest();
        Database.executeBatch(new CreateNewMaintenanceTaskBatch(true),200); 
        //System.Test.StopTest();
    }
    static testMethod void testMethod2() {
        ControllerUtil.EscapeNFM007Trigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true;
        Oly_TriggerHandler.bypass('NFM106Controller.NFM106Trigger');
 
 
        // 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_GS'];
        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_GS'];
        
        // 診療科を作る
        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;
 
        //顺延 (合同盖章完毕日 > [合同开始日 + 1个月] )
        Maintenance_Contract__c contract2 = new Maintenance_Contract__c();
        contract2.Name = 'tect contract2';
        contract2.Status__c ='契約';
        contract2.Maintenance_Contract_No__c = 'Kami_Contract_No2';
        contract2.Contract_Conclusion_Date__c = Date.today().addDays(-1);
        contract2.Hospital__c = hp.Id;
        contract2.Department_Class__c = dc.Id;
        contract2.Department__c = dpt1.Id;
        contract2.Contract_Start_Date__c = Date.today().addMonths(-4);
        contract2.Contract_End_Date__c = Date.today().addMonths(16);
        contract2.Contract_print_completed__c = Date.today().addMonths(-3);
        contract2.SalesOfficeCode_selection__c = '北京RC';
        contract2.Service_Contract_Staff__c = UserInfo.getUserId();
        contract2.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); 
        insert contract2;
 
        //创建SLA任务
        task__c task = new task__c();
        task.RecordTypeId = Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('SLAReport_Task').getRecordTypeId();
        task.taskDifferent__c = '被动任务';
        task.taskStatus__c = '03 完成';
        task.Activity_Date__c = Date.today();
        task.account__c =  dpt1.Id;
        task.Maintenance_Contract__c = contract.Id;
        insert task;
 
 
        //System.Test.StartTest();
        Database.executeBatch(new ServiceMaintenanceHistoryBatch(),200);
        //System.Test.StopTest();
    }
 
}