高章伟
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
182
183
184
@isTest
private class RentalApplyShareHandlerTest {
    static Account createHospital( String hospitalName) {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'HP'].id;
        hospital.Name = hospitalName;
        insert hospital;
        StaticParameter.EscapeAccountTrigger = true;
        return hospital;
    }
    static List<Account> selectStrategicDep( Account hospital) {
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name,OwnerId FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        return strategicDep;
    }
    static Account createDep( Account hospital, Account strategicDep) {
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep.Id;
        dep.Department_Class__c = strategicDep.Id;
        dep.Hospital__c = hospital.Id;
        // dep.State_Text__c = '上海市';
        insert dep;
        return dep;
    }
    static testMethod void testMethod1() {    
        System.runAs(new User(Id = Userinfo.getUserId())) { 
           // 病院、戦略科室、診療科の情報を作成します
            Account hospital = createHospital( 'test hospital');
            Account[] strategicDep = selectStrategicDep( hospital);
            Account dep = createDep( hospital, strategicDep[0]);
    
    
            Rental_Apply__c ra1 = new Rental_Apply__c();
            ra1.Name = 'test';
            //ra1.applyUser__c = user.Id;
            ra1.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Cao_An_Zhong.ordinal());
            ra1.demo_purpose1__c = '其他';
            ra1.demo_purpose2__c = '其他';
            ra1.Request_shipping_day__c = Date.today().addDays(3);
            ra1.Hope_Lonaer_date_Num__c = 6;
            ra1.Approver_of_Service_Department__c = null;
            ra1.Hospital__c = hospital.Id;
            ra1.Strategic_dept__c = strategicDep[0].Id;
            ra1.Account__c = dep.Id;
            
            insert ra1;
            
             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', 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;
            
            List<Rental_Apply__c> raList = [SELECT id,OwnerId,Approver_of_Service_Department__c,Strategic_user__c,Strategic_dept__c,ShareStrategicUser__c FROM Rental_Apply__c WHERE Id = :ra1.Id ];
            System.debug('===+++'+raList);
            System.assertEquals(1, raList.size());
            //List<User> user = [select Id,Name from User where IsActive = true];
            strategicDep[0].OwnerId = hpOwner.Id;
            update strategicDep;
            update raList;
         }
    }
 
//add by rentx 2020-12-04 start
    static testMethod void testMethod2(){
    // 病院、戦略科室、診療科の情報を作成します
        Account hospital = createHospital( 'test hospital');
        Account[] strategicDep = selectStrategicDep( hospital);
        Account dep = createDep( hospital, strategicDep[0]);
 
        Test.startTest();
        
        Rental_Apply__c ra1 = new Rental_Apply__c();
        ra1.Name = 'test';
        ra1.Status__c = FixtureUtil.raStatusMap.get(FixtureUtil.RaStatus.Cao_An_Zhong.ordinal());
        ra1.demo_purpose1__c = '其他';
        ra1.demo_purpose2__c = '其他';
        ra1.Request_shipping_day__c = Date.today().addDays(3);
        ra1.Hope_Lonaer_date_Num__c = 6;
        ra1.Hospital__c = hospital.Id;
        ra1.Strategic_dept__c = strategicDep[0].Id;
        ra1.Account__c = dep.Id;
        
        insert ra1;
        List<Rental_Apply__c> raList = [SELECT id,OwnerId,Approver_of_Service_Department__c,Strategic_user__c,Strategic_dept__c,ShareStrategicUser__c FROM Rental_Apply__c WHERE Id = :ra1.Id ];
        System.assertEquals(1, raList.size());
 
        
 
        List<User> user = [select Id,Name from User where IsActive = true AND Job_Category__c = '销售服务'];
        // List<User> user1 = [select Id,Name from User where IsActive = true AND Job_Category__c = '销售服务'];
        strategicDep[0].OwnerId = user[0].Id;
        strategicDep[0].Department_Class_Label__c = '消化科';
 
        update strategicDep;
 
        hospital.FSE_GI_Main_Leader__c = user[0].Id;
        hospital.FSE_SP_Main_Leader__c = user[1].Id;
        update hospital;
 
        ra1.Person_In_Charge__c = user[2].Id;
        ra1.hospitalLeaderSP__c = '12';
        ra1.hospitalLeaderGI__c = '34';
        update ra1;
 
        strategicDep[0].OwnerId = user[1].Id;
        strategicDep[0].Department_Class_Label__c = '其他';
        update strategicDep;
 
        ra1.Strategic_dept__c = strategicDep[0].Id;
        update ra1;
        Test.stopTest();
    }
 
    @isTest
    static  void insertRentalApply_Test() {
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '计划中';
        oPDPlan0.OPDPlan_ImplementDate__c = Date.today();
        oPDPlan0.NoOpp_Reason__c = 'HCP对应';
        insert oPDPlan0;
        Rental_Apply__c raObj = new Rental_Apply__c();
        raObj.Name = 'testra';
        raObj.Product_category__c = 'GI';
        raObj.Demo_purpose1__c = '维修代用';
        raObj.demo_purpose2__c = FixtureUtil.raDemo_purpose2MAP.get('baoxiuyonghu');
        raObj.direct_send__c = '医疗机构';
        raObj.Loaner_received_staff__c = '王五';
        raObj.Loaner_received_staff_phone__c = '110';
        raObj.direct_shippment_address__c = '北京市';
        raObj.ApplyPerson_Phone__c = '12345';
 
        raObj.Request_shipping_day__c = Date.toDay();  // 希望到货日
        raObj.Phone_number__c = '1234567890';
        raObj.OPDPlan__c = oPDPlan0.Id;
        raObj.demo_purpose2__c = '试用(无询价)';
        insert raObj;
 
        OPDPlan__c oPDPlan0Clone = new OPDPlan__c();
        oPDPlan0Clone = oPDPlan0.clone();
        oPDPlan0Clone.Id = null;
        oPDPlan0Clone.RentalReson__c = '追加配套';
        //oPDPlan0Clone.OriginalOpdPlanApp109lication__c = oPDPlan0.Id;
        insert oPDPlan0Clone;
        //新增不变更验证字段-变更时触发
        Rental_Apply__c raObjClone = new Rental_Apply__c();
        raObjClone = raObj.clone();
        raObjClone.Id  = null;
        raObjClone.OPDPlan__c = oPDPlan0Clone.Id;
        raObjClone.SupplementCreated__c = true;
        insert raObjClone;
        Rental_Apply__c ress = [select Id,Name from Rental_Apply__c where Id = :raObjClone.Id];
        system.debug('ress---->'+ress.Name); 
        //新增时触发验证规则
        OPDPlan__c oPDPlan0Clone2 = new OPDPlan__c();
        oPDPlan0Clone2 = oPDPlan0.clone();
        oPDPlan0Clone2.Id = null;
        oPDPlan0Clone2.RentalReson__c = '追加配套';
        oPDPlan0Clone2.OriginalOpdPlanApplication__c = oPDPlan0.Id;
        insert oPDPlan0Clone2;
        Rental_Apply__c raObjClone2 = new Rental_Apply__c();
        raObjClone2 = raObj.clone();
        raObjClone2.Id  = null;
        raObjClone2.Phone_number__c ='0522';
        raObjClone2.OPDPlan__c = oPDPlan0Clone2.Id;
        raObjClone2.SupplementCreated__c = true;
        insert raObjClone2;
 
        /*raObjClone.Phone_number__c = '000000';
        system.debug('raObjClone---->'+raObjClone.Name);
        raObjClone.SupplementCreated__c  = true;
        update raObjClone;*/
 
        Test.startTest();
        //OpdPlanWebService.insertRentalApply(raObj.Id, oPDPlan0Clone.Id);
        Test.stopTest();
    }
 
}