高章伟
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
@isTest
private class ProductMonthlySalesCountBatchTest
{
  static testMethod void test1() {
 
    Account hospital = new Account();
    hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName != 'HP' limit 1].id;
    hospital.Name = 'test hospital';
    insert hospital;
    Contact ctt=new Contact(RecordTypeId='01210000000QfWd');
    ctt.AccountId=hospital.Id;
    ctt.FirstName='名';
    ctt.LastName = '姓';
    insert ctt;
 
    // 产品一
    Product2 pro1 = new Product2(Name='产品一',IsActive=true,Family='SP',
    Fixture_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',
    Fixture_Model_No_T__c = 'n01',
    ProductMonthlySalesFlag__c=true,
    ProductCode_Ext__c='pc01',Manual_Entry__c=false,
    StorageStatus__c = '',StorageStatusNo__c = 22,
    WhiteSpace__c = true,Product_Status__c='正常销售',
    SFDA_Approbated_Status__c='有效',SFDA_Status__c='有効',
    M_BC_Stop_manufacure__c=date.today().addMonths(+10));
    insert pro1;
 
    // Product2 pro1=new Product2();
    // pro1.Name='产品一';
    // pro1.Manual_Entry__c=false;
    // pro1.M_BC_Stop_manufacure__c=date.today().addMonths(+10);
    // pro1.SFDA_Status__c='有効';
    // pro1.ProductMonthlySalesFlag__c=true;
    // insert pro1;
 
    // 产品二
    Product2 pro2 = new Product2(Name='产品二',IsActive=true,Family='SP',
    Fixture_Model_No__c='n02',Serial_Lot_No__c='S/N tracing',
    Fixture_Model_No_T__c = 'n02',
    ProductMonthlySalesFlag__c=true,
    Correspond_Code__c=pro1.Id,
    ProductCode_Ext__c='pc02',Manual_Entry__c=false,
    StorageStatus__c = '',StorageStatusNo__c = 22,
    WhiteSpace__c = true,Product_Status__c='正常销售',
    SFDA_Approbated_Status__c='有效',SFDA_Status__c='有効',
    M_BC_Stop_manufacure__c=date.today().addMonths(-1));
    insert pro2;
 
    // Product2 pro2=new Product2();
    // pro2.Name='产品二';
    // pro2.Manual_Entry__c=false;
    // pro2.ProductCode=pro1.Id;
    // pro2.Correspond_Code__c=pro1.Id;
    // pro2.M_BC_Stop_manufacure__c=date.today().addMonths(-1);
    // pro2.SFDA_Status__c='有効';
    // pro2.ProductMonthlySalesFlag__c=true;
    // insert pro2;
 
    // 产品三
 
    Product2 pro3 = new Product2(Name='产品三',IsActive=true,Family='SP',
    Fixture_Model_No__c='n03',Serial_Lot_No__c='S/N tracing',
    Correspond_Code__c=pro2.Id,
    Fixture_Model_No_T__c = 'n03',
    ProductMonthlySalesFlag__c=true,
    ProductCode_Ext__c='pc03',Manual_Entry__c=false,
    StorageStatus__c = '',StorageStatusNo__c = 22,
    WhiteSpace__c = true,Product_Status__c='正常销售',
    SFDA_Approbated_Status__c='有效',SFDA_Status__c='有効',
    M_BC_Stop_manufacure__c=date.today().addMonths(-1));
    insert pro3;
 
    // Product2 pro3=new Product2();
    // pro3.Name='产品二';
    // pro3.Manual_Entry__c=false;
    // pro3.ProductCode=pro2.Id;
    // pro3.Correspond_Code__c=pro2.Id;
    // pro3.M_BC_Stop_manufacure__c=date.today().addMonths(-1);
    // pro3.SFDA_Status__c='有効';
    // pro3.ProductMonthlySalesFlag__c=true;
 
    // insert pro3;
 
    // TODO
    List<Product2> pro=[select id,ProductCode,Correspond_Code__c,Correspond_ProductCode__c,M_BC_Stop_manufacure__c,ProductMonthlySalesFlag__c from Product2 where M_BC_Stop_manufacure__c !=null and SFDA_Status__c!='停止'];
    // system.assertEquals(3,pro.size());
 
    //保有设备一
    Asset aset1=new Asset();
    aset1.name='保有设备一';
    aset1.IsCompetitorProduct=false;
    aset1.Loaner_accsessary__c=true;
    // aset1.RecordTypeId ='01210000000kOPR';
    aset1.Product2Id=pro1.Id;
    aset1.Posting_Date__c=date.today().addMonths(-5);
    aset1.AccountId=hospital.Id;
    aset1.ContactId=ctt.Id;
    aset1.IF_Information_From__c=true;
    aset1.RecordTypeId=Schema.SObjectType.Asset.getRecordTypeInfosByDeveloperName().get('HPAsset').getRecordTypeId();
    insert aset1;
 
    //保有设备二
    Asset aset2=new Asset();
    aset2.name='保有设备二';
    aset2.IsCompetitorProduct=false;
    aset2.Loaner_accsessary__c=false;
    aset2.RecordTypeId ='01210000000kOPM';
    aset2.Product2Id=pro2.Id;
    aset2.Posting_Date__c=date.today().addMonths(-20);
    aset2.AccountId=hospital.Id;
    aset2.ContactId=ctt.Id;
    aset2.IF_Information_From__c=true;
    aset2.SerialNumber='序列号2';
    insert aset2;
 
    //保有设备三
    Asset aset3=new Asset();
    aset3.name='保有设备三';
    aset3.IsCompetitorProduct=false;
    aset3.Loaner_accsessary__c=false;
    aset3.RecordTypeId ='01210000000kOPM';
    aset3.Product2Id=pro2.Id;
    aset3.Posting_Date__c=date.today().addMonths(-7);
    aset3.AccountId=hospital.Id;
    aset3.ContactId=ctt.Id;
    aset3.IF_Information_From__c=true;
    aset3.Product_Serial_No__c='N4510030:9ZK(testtest)';
    aset3.SerialNumber='序列号3';
    insert aset3;
 
    //保有设备四
    Asset aset4=new Asset();
    aset4.name='保有设备四';
    aset4.IsCompetitorProduct=false;
    aset4.Loaner_accsessary__c=false;
    aset4.RecordTypeId ='01210000000kOPM';
    aset4.Product2Id=pro2.Id;
    aset4.Posting_Date__c=date.today().addMonths(-7);
    aset4.AccountId=hospital.Id;
    aset4.ContactId=ctt.Id;
    aset4.IF_Information_From__c=true;
    aset4.Product_Serial_No__c='N4510030:9ZK(testtest)';
    aset4.SerialNumber='序列号4';
    insert aset4;
 
    List<Asset> assetlog=[select Id,Product2Id,Posting_Date__c,RecordType.DeveloperName from Asset where Posting_Date__c!=null and RecordType.DeveloperName !='Shipment' and Posting_Date__c!=1900-01-01 order by Posting_Date__c desc];
    System.assertEquals(assetlog.size(), 4);
 
    // 创建月销量表
    ProductMonthlySales__c prd1=new ProductMonthlySales__c();
    prd1.GenerationMonths__c=5;
    prd1.MonthSales__c=20;
    prd1.Earliest_Shipping__c=date.today().addMonths(-100);
    prd1.CurrentDate__c=date.today().addMonths(-1);
    prd1.Name__c='创建月销量表';
    prd1.ProductM__c=pro1.Id;
    prd1.Product2Model__c='产品型号';
    insert prd1;
 
    List<String> a=new List<String>();
    a.add(pro1.id);
    a.add(pro3.id);
    Database.executeBatch(new ProductMonthlySalesCountBatch());
    Database.executeBatch(new ProductMonthlySalesCountBatch(true));
 
    Database.executeBatch(new ProductMonthlySalesCountBatch(a));
    Database.executeBatch(new ProductMonthlySalesCountBatch(pro1.id));
 
    Database.executeBatch(new ProductMonthlySalesCountBatch(a,true));
    Database.executeBatch(new ProductMonthlySalesCountBatch(pro1.id,true));
  }
}