高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
@isTest
private class NFM206RestTest {
    
    @isTest static void test_method_one() {
        // Implement test code
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
       List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        List<RecordType> rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo.size() == 0) {
            return;
        }
        //经销商
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
 
 
 
        Date authorized_Date = Date.today()-1;
        Date autholization_Activated = Date.today()-1;
        Date bid_Date = Date.today()-1;
        Date dtlast = Date.today()+1;
 
        Opportunity  opp = new Opportunity(Authorized_Finish_Sales__c='11',
                                           Authorized_DB_No__c='1008', Authorized_Date__c = authorized_Date, 
                                           Autholization_Activated_Date__c = autholization_Activated ,Bidding_Content__c='qwer',
                                           Bid_Date__c = bid_Date, Bidding_No__c='4035',Agency1__c = myAccount1.Id,
                                           Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標',
                                           Name='xunjia',CloseDate=dtlast,
                                           Contract_DB_complite_day__c = bid_Date,
                                           SAP_Send_OK__c = true
                                        
                                           );
        insert opp;
        List<Opportunity> opplist = [select Id,Name,Opportunity_No__c from Opportunity where Opportunity_No__c != '' ];
      
        NFM206Rest.GeDatas GeDatas = new NFM206Rest.GeDatas();
        NFM206Rest.GeData GeData = new NFM206Rest.GeData();
        GeDatas.GeData = new NFM206Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        
        GeData.Opportunity_No = opplist.get(0).Opportunity_No__c;
        GeData.OCM_Agent1_Price_DB = '1130000';
        GeData.NotesApprovedNo = 'MSHHTSQHD201812057'
                                + 'MSHHTSQHD201812057'
                                + 'MSHHTSQHD201812057'
                                + 'MSHHTSQHD201812057'
                                + 'MSHHTSQHD201812057'
                                + 'MSHHTSQHD201812057';
        GeData.Contract_DB_SalesDept_complite_day = null;
        GeData.Contract_DB_request_reason = '';
        GeData.Contract_DB_complite_day = String.valueOf(Date.today()-1);
        GeData.Closing_Bid_Date = String.valueOf(Date.today()-1);
        GeData.Assistant_Applied_Date = String.valueOf(Date.today()-1);
        GeData.ApprovedType = '1';
        GeData.SPOApprovedQuote = 'test';//20200430 add
        System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData);
        NFM206Rest.executefuture(rowData.Id);
        
        GeData.ApprovedType = '3';
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData);
        NFM206Rest.executefuture(rowData.Id);
 
        GeData.ApprovedType = '';
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData);
        NFM206Rest.executefuture(rowData.Id);
 
 
        GeData.Opportunity_No = '';
 
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData);
        NFM206Rest.executefuture(rowData.Id);
    
        GeData.ApprovedType = '1';
        GeData.Opportunity_No = 'opp0522';
        rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData);
        NFM206Rest.executefuture(rowData.Id);
    
        System.Test.stopTest();
    }
    
    @isTest static void test_method_two() {
        // Implement test code
 
       List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        List<RecordType> rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo.size() == 0) {
            return;
        }
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        //经销商
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
 
 
 
        Date authorized_Date = Date.today()-1;
        Date autholization_Activated = Date.today()-1;
        Date bid_Date = Date.today()-1;
        Date dtlast = Date.today()+1;
 
 
 
        Opportunity  opp = new Opportunity(Authorized_Finish_Sales__c='11',
                                           Authorized_DB_No__c='1008', Authorized_Date__c = authorized_Date, 
                                           Autholization_Activated_Date__c = autholization_Activated ,Bidding_Content__c='qwer',
                                           Bid_Date__c = bid_Date, Bidding_No__c='4035',Agency1__c = myAccount1.Id,
                                           Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標',
                                           Name='xunjia',CloseDate=dtlast,
                                           Contract_DB_complite_day__c = bid_Date
                                           //SAP_Send_OK__c = true
                                           );
        insert opp;
        List<Opportunity> opplist = [select Id,Name,Opportunity_No__c from Opportunity where Opportunity_No__c != '' ];
        
        NFM206Rest.GeDatas GeDatas = new NFM206Rest.GeDatas();
        NFM206Rest.GeData GeData = new NFM206Rest.GeData();
        GeDatas.GeData = new NFM206Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        
        GeData.Opportunity_No = opplist.get(0).Opportunity_No__c;
        GeData.OCM_Agent1_Price_DB = '1130000';
        GeData.NotesApprovedNo = '';
        GeData.SPOApprovedQuote = 'test';//20200430 add
        GeData.Contract_DB_SalesDept_complite_day = null;
        GeData.Contract_DB_request_reason = '';
        GeData.Contract_DB_complite_day = null;
        GeData.Closing_Bid_Date = null;
        GeData.Assistant_Applied_Date = null;
        GeData.ContractType = '1';
        GeData.ApprovedType = '1';
        System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData);
        NFM206Rest.main(rowData.Id);
          
        System.Test.stopTest();
    }
    @isTest static void test_method_three() {
        // Implement test code
 
       List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
 
        List<RecordType> rectContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo.size() == 0) {
            return;
        }
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        //经销商
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
 
 
 
        Date authorized_Date = Date.today()-1;
        Date autholization_Activated = Date.today()-1;
        Date bid_Date = Date.today()-1;
        Date dtlast = Date.today()+1;
 
 
 
        Opportunity  opp = new Opportunity(Authorized_Finish_Sales__c='11',
                                           Authorized_DB_No__c='1008', Authorized_Date__c = authorized_Date, 
                                           Autholization_Activated_Date__c = autholization_Activated ,Bidding_Content__c='qwer',
                                           Bid_Date__c = bid_Date, Bidding_No__c='4035',Agency1__c = myAccount1.Id,
                                           Agency2__c = myAccount1.Id, Bidding_Project_Name__c='efg',StageName='目標',
                                           Name='xunjia',CloseDate=dtlast,
                                           Contract_DB_complite_day__c = bid_Date,
                                           //songxiaoqi-------start
                                            Estimation_Decision__c = true,
                                           Estimation_No__c = 'test',
                                           Estimation_Id__c='002'
                                           //StageName='引合'
                                           //songxiaoqi--------end
                                           //SAP_Send_OK__c = true
                                           );
        insert opp;
        //2020/11/4 songxiaoqi  update
        opp.Estimation_Decision__c=true;
        opp.StageName= '引合';
        //2020/11/4 songxiaoqi  end
        update opp;
        Opportunity opplist =  [select Id,Name,Opportunity_No__c ,Estimation_Decision__c from Opportunity where Id = :opp.Id ];
         System.assertEquals(true, opplist.Estimation_Decision__c);
        NFM206Rest.GeDatas GeDatas = new NFM206Rest.GeDatas();
        NFM206Rest.GeData GeData = new NFM206Rest.GeData();
        GeDatas.GeData = new NFM206Rest.GeData[]{GeData};
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
        
        // GeData.Opportunity_No = opplist.get(0).Opportunity_No__c;
        GeData.Opportunity_No = opplist.Opportunity_No__c;
        GeData.OCM_Agent1_Price_DB = '1130000';
        GeData.NotesApprovedNo = '';
        GeData.SPOApprovedQuote = 'test';//20200430 add
        GeData.Contract_DB_SalesDept_complite_day = null;
        GeData.Contract_DB_request_reason = '';
        GeData.Contract_DB_complite_day = null;
        GeData.Closing_Bid_Date = null;
        GeData.Assistant_Applied_Date = null;
        GeData.ContractType = '2';
        GeData.ApprovedType = '1';
        //songxiaoqi--------start
        //测试合同终止
        GeData.IsTermination ='true';
         //songxiaoqi--------结束
        System.Test.startTest();
        NFMUtil.Monitoring Monitoring = GeDatas.Monitoring;
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM206', GeDatas.GeData);
        NFM206Rest.main(rowData.Id);
          
        System.Test.stopTest();
    }
    @isTest 
    static void test_method_four() {
 
        Test.startTest();
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
 
        String JsonMsg = '{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM206","MessageGroupNumber":"20180001722190"},"GeData":[{"Opportunity_No":"BJ-SP-BJ0577783","OCM_Agent1_Price_DB":"950000","NotesApprovedNo":"MGZHTSQHN201812009","Contract_DB_SalesDept_complite_day":null,"Contract_DB_request_reason":"","Contract_DB_complite_day":"20181218","Closing_Bid_Date":"20181206","Assistant_Applied_Date":"20181218","ApprovedType":"3","SPOApprovedQuote":"test"}]}';
        req.requestURI = 'services/apexrest/NFM206/execute';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
        RestContext.response= res;
 
        NFM206Rest.execute();
 
        Test.stopTest();
        //Test.setMock(HttpCalloutMock.class, new NFM205RestCalloutMock());
        //NFM205Rest.execute1('{"Monitoring":{"TransmissionDateTime":"201812201320","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"SPO","NumberOfRecord":"1","MessageType":"NFM205","MessageGroupNumber":"20180001722190"},"GeData":[{"Opportunity_Code":"HKBJ-GI-BJ0588881","Bidding_No":"as123121","Bidding_Content":"招标内容","Bid_Project_Name":"招标项目名","Bid_Date":"20181203","Authorized_Status":"1","Authorized_Finish_Sales":"30033","Authorized_DB_No":"MGZWESQHN201812001","Authorized_Date":"20190316","Autholization_Activated_Date":"20190415"}]}');
    }
     
}