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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
@isTest
private class OFSUploadImageRestTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    @isTest 
    static void test_method1() {
 
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        
        // 製品を作る
        Product2 productA = new Product2( Name='テスト商品');
        insert productA;
        
        // 価格表エントリを作成する     
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
        
        // 納入機器を作成する
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dep.Id;
        asset.Department_Class__c = strategicDep[0].Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        insert asset;
        
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        insert contract;
        
        // 修理を作成する
        Repair__c repair = new Repair__c();
        repair.Account__c = dep.Id;
        repair.Department_Class__c = strategicDep[0].Id;
        repair.Hospital__c = hospital.Id;
        repair.Delivered_Product__c = asset.Id;
        repair.AWS_Data_Id__c = 'a041000002YZUGzAAP';
        insert repair;
        Repair_Quotation__c rq = new Repair_Quotation__c();
        rq.Name                  = 'testNFM104';
        rq.Repair__c             = repair.Id;
        rq.MessageGroupNumber__c = '1';
        insert rq;
        ContentVersion version = new ContentVersion(
            Title = 'test',
            VersionData = EncodingUtil.base64Decode('test'),
            ContentLocation = 's',
            PathOnClient = 'test.txt'
        );
        insert version;
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recordType');
        }
        String str = EncodingUtil.base64Encode(version.VersionData);
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        Account depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":null,'+
                            '"departmentCd":"'+depart.Management_Code__c+'",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
        Test.startTest();
        OFSUploadImageRest.doPost(repair.Id,str,str,rq.Id);
        OFSUploadImageRest.doPost('',str,str,rq.Id);
        // OFSUploadImageRest.doPost(repair.Id,str,str,'');
        Test.stopTest();
 
    }
 
    @isTest 
    static void test_method2() {
 
        // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
        
        // 製品を作る
        Product2 productA = new Product2( Name='テスト商品');
        insert productA;
        
        // 価格表エントリを作成する     
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
        
        // 納入機器を作成する
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dep.Id;
        asset.Department_Class__c = strategicDep[0].Id;
        asset.Hospital__c = hospital.Id;
        asset.SerialNumber = 'testserial';
        insert asset;
        
        // 维修合同を作成する
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Name = 'tect contract';
        contract.Hospital__c = hospital.Id;
        contract.Department_Class__c = strategicDep[0].Id;
        contract.Department__c = dep.Id;
        insert contract;
        
        // 修理を作成する
        Repair__c repair = new Repair__c();
        repair.Account__c = dep.Id;
        repair.Department_Class__c = strategicDep[0].Id;
        repair.Hospital__c = hospital.Id;
        repair.Delivered_Product__c = asset.Id;
        repair.AWS_Data_Id__c = 'a041000002YZUGzAAP';
        insert repair;
        Repair_Quotation__c rq = new Repair_Quotation__c();
        rq.Name                  = 'testNFM104';
        rq.Repair__c             = repair.Id;
        rq.MessageGroupNumber__c = '1';
        insert rq;
        ContentVersion version = new ContentVersion(
            Title = 'test',
            VersionData = EncodingUtil.base64Decode('test'),
            ContentLocation = 's',
            PathOnClient = 'test.txt'
        );
        insert version;
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recordType');
        }
        String str = EncodingUtil.base64Encode(version.VersionData);
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        Account depart = [select Management_Code__c from Account where RecordTypeId = :rectDpt[0].Id];
        String JsonMsg = '{"visitStartDate":"20211221033551",'+
                        '"visitPurpose":"维修跟进",'+
                        '"visitInfo":"报价任务",'+
                        '"visitEndDate":"20211221033554",'+
                        '"visitDistinction":"用户拜访",'+
                        '"synchroDate":"20211221153601",'+
                        '"replyResult":"报价跟进",'+
                        '"replyID":"88",'+
                        '"mngCd":null,'+
                            '"departmentCd":"'+depart.Management_Code__c+'",'+
                        '"applicantId":"5",'+
                        '"activityDifferentiation":"报价跟进"}';
        req.requestURI = 'services/apexrest/NFM608/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
        Test.startTest();
        OFSUploadRepairImageRest.doPost(repair.Id,str,str,rq.Id);
        OFSUploadRepairImageRest.doPost('',str,str,rq.Id);
        // OFSUploadRepairImageRest.doPost(repair.Id,str,str,'');
        Test.stopTest();
 
    }
 
 
    
}