GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
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
@isTest
private class SBG010TRestTest {
    static String  setdata(){
        Id pricebookId = Test.getStandardPricebookId();
        Pricebook2 pricebook = new Pricebook2(
            Name = 'BS',
            isActive = true
        );
        insert pricebook;
        Product2 product1 = new Product2();
        product1.Name = 'product1';
        Product2 product2 = new Product2();
        product2.Name = 'product2';
        Product2 product3 = new Product2();
        product3.Name = 'product3';
        insert new Product2[] {product1,product2,product3};
        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
        );
        PricebookEntry standardPrice2 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product2.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
        );
        PricebookEntry standardPrice3 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product3.Id,
            UnitPrice = 0,
            CurrencyIsoCode = 'CNY',
            IsActive = true
        );
        insert new PricebookEntry[] {standardPrice1,standardPrice2,standardPrice3};
 
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'CNY';
        PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
        entry3.UnitPrice = 0;
        entry3.IsActive = true;
        entry3.UseStandardPrice = false;
        entry3.CurrencyIsoCode = 'CNY';
        insert new PricebookEntry[] {entry1,entry2,entry3};
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer IE',
            FacilityName__c='abc',
            PostCode__c = '123456'
        );
        insert accIE; 
 
 
        Date day1 = Date.today();
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity();
        opp.Name = 'test opp';
        opp.AccountId = accIE.Id;
        opp.RecordTypeId = rectOpp[0].Id;
        opp.OwnerId = UserInfo.getUserId();
        opp.StageName = 'Prospect Created';
        opp.CurrencyIsoCode = 'CNY';
        opp.ProductSegment__c = 'IE';
        opp.CloseDate = Date.today();
        opp.NewInquiryDate__c = Date.today().addDays(-2);
        opp.ExpectedOrderDate__c = Date.today().addDays(2);
        opp.ApprovalStatus_D__c = 'Pass';
        opp.LeadSource = 'LeadSource_D__c';
        opp.BudgetAmount__c = 111;
        opp.CancelReasonText__c = 'Cancel_Reason_Text_D__c';
        opp.CancelReason__c = 'Cancel_reason_D__c';
        opp.CompetitorCompany__c = 'Competitor_Company_D__c';
        opp.Competitor_Product__c = 'Competitor_Product_D__c';
        opp.Competitor_Product2__c = 'Competitor_Product2_D__c';
        opp.Competitor_Product3__c = 'Competitor_Product3_D__c';
        opp.Competitor_Product4__c = 'Competitor_Product4_D__c';
        opp.Competitor_Product5__c = 'Competitor_Product5_D__c';
        opp.Competitor_Product6__c = 'Competitor_Product6_D__c';
        opp.Competitor_Product7__c = 'Competitor_Product7_D__c';
        opp.Competitor_Product8__c = 'Competitor_Product8_D__c';
        opp.CompetitorProductCode__c = 'Competitor_Product_Code_D__c';
        opp.CompetitorProductCode2__c = 'Competitor_Product_Code2_D__c';
        opp.CompetitorProductCode3__c = 'Competitor_Product_Code3_D__c';
        opp.CompetitorProductCode4__c = 'Competitor_Product_Code4_D__c';
        opp.CompetitorProductCode5__c = 'Competitor_Product_Code5_D__c';
        opp.CompetitorProductCode6__c = 'Competitor_Product_Code6_D__c';
        opp.CompetitorProductCode7__c = 'Competitor_Product_Code7_D__c';
        opp.CompetitorProductCode8__c = 'Competitor_Product_Code8_D__c';
        opp.DealerSalesStaffName__c = 'Dealer_Sales_Staff_Name_D__c';
        opp.DealerService__c = 'Dealer_Service_D__c';
        opp.ExpectedDeliveryDate__c = day1;
        opp.InquiryResult__c = 'InquiryResultD__c';
        //opp.InquiryResultCancel__c = day1;
        //opp.InquiryResultLost__c = day1;
        opp.InquiryResultOrder__c = day1;
        opp.LostAmount__c = 111;
        opp.LostCompetitorProduct__c = 'Lost_competitor_product_D__c';
        opp.LostReasonText__c = 'LostReasonText_D__c';
        opp.LostReason__c = 'Lostreason_D__c';
        opp.Phase1Date__c = day1;
        opp.Phase2Date__c = day1;
        opp.Phase3Date__c = day1;
        opp.SalesChannel__c = 'Sales_Channel_D__c';
        opp.SubDealer__c = 'Sub_Dealer_D__c';
        opp.TradeType__c = 'Trade_Type_D__c';
        //opp.Machine_Parts__c = 'Machine_Parts_D__c';
        //opp.SpecialDeliveryAddress__c = 'SpecialDeliveryAddress_D__c';
        //opp.ForeignTradeCompany__c = 'ForeignTradeCompany_D__c';
        insert opp;
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = opp.Id;
        oli.Quantity = 2;
        oli.UnitPrice = 111;
        oli.Description = 'test';
        oli.PricebookEntryId = entry1.Id;
        insert oli;
        List<RecordType> rectOrder = [select id from RecordType where IsActive = true and SobjectType = 'Order'];
        Order odr = new Order(
            Name = '',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Draft',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            CurrencyIsoCode = 'CNY',
            RecordTypeId = '01228000000NJt6'
        );
        insert odr;
 
        Delivery__c de1 = new Delivery__c();
        de1.SSBD_Contract__c = odr.Id;
 
        insert de1;
        Order ordd = [Select OrderNumber,Id,Name From Order];
      return ordd.OrderNumber;
 
    }
    @isTest static void test_method_one() {
   
    
        SBG010Rest.GeData GeData = new SBG010Rest.GeData();
        SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
        GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        String ocode = setdata();
        GeData.OrderCode = ocode;
 
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
 
        SBG010Rest.main(rowData.Id);
    }
 
    @isTest static void test_method2() {
   
    
        SBG010Rest.GeData GeData = new SBG010Rest.GeData();
        SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
        GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        String ocode = setdata();
        GeData.OrderCode = ocode;
        GeData.SoNo = '123131';
        GeData.SoShippingStatus = '未发货';
 
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
 
        SBG010Rest.main(rowData.Id);
    }
        @isTest static void test_method3() {
   
    
        SBG010Rest.GeData GeData = new SBG010Rest.GeData();
        SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
        GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        String ocode = setdata();
          GeData.OrderCode = ocode;
        GeData.SoNo = '123131';
        
 
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
 
        SBG010Rest.main(rowData.Id);
    }
     @isTest static void test_method4() {
   
    
        SBG010Rest.GeData GeData = new SBG010Rest.GeData();
        SBG010Rest.GeDatas GeDatas = new SBG010Rest.GeDatas();
        GeDatas.GeData = new SBG010Rest.GeData[] { GeData };
 
        Datetime nowDT = Datetime.now();
        String nowStr = nowDT.format('yyyyMMddHHmm');
        GeDatas.Monitoring = new NFMUtil.Monitoring();
        GeDatas.Monitoring.MessageGroupNumber = nowStr + '01';
 
        String ocode = setdata();
  
        GeData.SoNo = '123131';
        GeData.SoShippingStatus = '未发货';
 
        BatchIF_Log__c rowData = NFMUtil.saveRowData(GeDatas.Monitoring, 'SBG004', GeDatas.GeData);
 
        SBG010Rest.main(rowData.Id);
    }
 
 
     @isTest static void test_method_Send() {
 
    Test.startTest();
 
    RestRequest req = new RestRequest();
    RestResponse res = new RestResponse();
 
    // String JsonMsg = '{"GeDatas": {"Monitoring": {"Tag": "MSGH","Sender": 1330,"Receiver": 1592,"MessageType": "SBG004","MessageGroupNumber": 331591,"NumberOfRecord": 1,"TransmissionDateTime": 201908081115},"GeData": [{"TradeType": "Taxation","SalesChannel": "99","PurposeOfAdvice": "3","ProductSegment": "IE","ProductCode": "N5702700","Other3": "","Other2": "","Other1": "","MachineParts": "Machine","EffectiveDateTo": "99991231","EffectiveDateFrom": "20190801","Currency_x": "RMB","CostPrice": 12241.00}]}}';
    String JsonMsg = '{"GeDatas": {"Monitoring": {"Tag": "MSGH"},"GeData":[{"SoShippingStatus": "全部发货"}]}}';
    req.requestURI = 'services/apexrest/SBG004/execute';
    req.httpMethod = 'POST';
    req.requestBody = Blob.valueof(JsonMsg);
    RestContext.request = req;
    RestContext.response= res;
 
    SBG010Rest.execute();
 
    Test.stopTest();
 
   // { "GeDatas": {"Monitoring": {"Tag": "MSGH","Sender": 1330,"Receiver": 1592,"MessageType": "SBG017", "MessageGroupNumber": 331591, "NumberOfRecord": 1, "TransmissionDateTime": 201903251115 },"GeData": [{ "StockAnswer": "OK111","SAPQuotationCode": "20022780  ", "Other3": "", "Other2": "", "Other1": "",  "OpportunityCode": "O-2018-067607"}]}}
 
    //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"}]}');
}
 
}