高章伟
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
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
@isTest
private class ProductScoreHistoryServiceTest {
    static Account dep;
    private static void setup() {
        // OLY_OCM-644
        StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
 
        //Account 经销商 recordtypeID
        Id AgencyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
 
        //Account 医院 recordtypeID
        Id HPRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
 
        // 省
        Address_Level__c al = new Address_Level__c(Name = '東京', Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999');
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c(Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999', Level1_Name__c = '東京',
                Name = '渋谷区', Level2_Code__c = 'CN-9999', Level2_Sys_No__c = '9999999', Address_Level__c = al.Id);
        insert al2;
 
        Account AccountHP = new Account(Name = 't_e_s_tHP001', AgentCode_Ext__c = '9999900', RecordTypeId = HPRecordTypeId,
                Is_Active__c = '有効', Attribute_Type__c = '卫生部', Speciality_Type__c = '综合医院',
                Grade__c = '一级', OCM_Category__c = 'SLTV', Is_Medical__c = '医疗机构',
                State_Master__c = al.Id, City_Master__c = al2.Id, Town__c = '东京', OCM_man_province_txt__c = '北京');
        insert AccountHP;
 
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :AccountHP.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = AccountHP.Id;
        insert dep;
 
        Account AccountAgent1 = new Account(Name = 't_e_s_tAgent001', RecordTypeId = AgencyRecordTypeId);
        insert AccountAgent1;
 
        Account AccountAgent2 = new Account(Name = 't_e_s_tAgent002', RecordTypeId = AgencyRecordTypeId, ParentId = AccountHP.Id);
        insert AccountAgent2;
 
        Product2 prod01 = new Product2(
                Name = 'Test01',
                ProductCode = 'Test01',
                Asset_Model_No__c = 'Test01',
                SFDA_Status__c = '有効',
                Dealer_special_Object__c = true,
                Family = 'ET',
                Category2__c = '耗材',
                Category3__c = 'ERCP',
                Category4__c = '导丝',
                Category5__c = 'Visiglide35'
        );
        Product2 prod02 = new Product2(
                Name = 'T_est002',
                ProductCode = 'T_estCode002',
                Category2__c = '耗材',
                Category3__c = 'ERCP',
                Category4__c = '导丝',
                Category5__c = 'Visiglide35',
                Family = 'ET',
                Packing_list_manual__c = 1,
                Asset_Model_No__c = 'T_est02',
                SFDA_Status__c = '有効',
                Dealer_special_Object__c = true
        );
        Product2 prod03 = new Product2(
                Name = 'T_est003',
                ProductCode = 'T_estCode003',
                Category2__c = '耗材',
                Category3__c = 'Capsule',
                Category4__c = 'CP打印机',
                Category5__c = 'CP打印机',
                Family = 'ET',
                Packing_list_manual__c = 1,
                Asset_Model_No__c = 'T_est03',
                SFDA_Status__c = '有効',
                Dealer_special_Object__c = true
        );
        Product2 prod04 = new Product2(
                Name = 'T_est004',
                ProductCode = 'T_estCode004',
                Category2__c = '耗材',
                Category3__c = '基幹',
                Category4__c = '清洗刷',
                Category5__c = 'DBW',
                Family = 'ET',
                Packing_list_manual__c = 1,
                Asset_Model_No__c = 'T_est04',
                SFDA_Status__c = '有効',
                Dealer_special_Object__c = true
        );
        Product2 prod05 = new Product2(
                Name = 'T_est005',
                ProductCode = 'T_estCode005',
                Category2__c = '耗材',
                Category3__c = '基幹',
                Category4__c = '清洗刷',
                Category5__c = 'DBW',
                Family = 'ET',
                Packing_list_manual__c = 6,
                Asset_Model_No__c = 'T_est05',
                SFDA_Status__c = '有効',
                Dealer_special_Object__c = true
        );
        Product2 prod06 = new Product2(
                Name = 'T_est006',
                ProductCode = 'T_estCode006',
                Category2__c = '耗材',
                Category3__c = '基幹',
                Category4__c = '清洗刷',
                Category5__c = 'DBW',
                Family = 'ET',
                Packing_list_manual__c = 5,
                Asset_Model_No__c = 'T_est06',
                SFDA_Status__c = '有効',
                Dealer_special_Object__c = true
        );
        Product2 [] pd2s = new List<Product2>{
                prod01, prod02, prod03, prod04, prod05, prod06
        };
        insert pd2s;
 
        List<Product2__c> prod2cs = new List<Product2__c>();
        for(Product2 p: pd2s) {
            Product2__c pdc = new Product2__c(
                    Name=p.Name,
                    OT_CODE_Text__c=p.ProductCode,
                    Product2__c = p.Id
            );
            prod2cs.add(pdc);
        }
        insert prod2cs;
 
        System.runAs(new User(Id = Userinfo.getUserId())) {
 
            //产品得分表
    //        ET_Product_ScoreTable_Batch bat = new ET_Product_ScoreTable_Batch();
    //        Database.executeBatch(bat);
            Product_Score_Table__c [] pstList = new List<Product_Score_Table__c>();
            Product_Score_Table__c pst01 = new Product_Score_Table__c(
            OCM_Term__c = '154P',
            Plan_Category3__c = 'ERCP',
            Category3__c = 'ERCP',
            Category4__c = '导丝');
            pstList.add(pst01);
            Product_Score_Table__c pst02 = new Product_Score_Table__c(
                    OCM_Term__c = '154P',
                    Plan_Category3__c = 'Capsule',
                    Category3__c = 'Capsule',
                    Category4__c = 'CP打印机'
                    );
            pstList.add(pst02);
 
            Product_Score_Table__c pst03 = new Product_Score_Table__c(
                    OCM_Term__c = '154P',
                    Plan_Category3__c = 'Capsule',
                    Category3__c = '基幹',
                    Category4__c = '清洗刷'
            );
            pstList.add(pst03);
 
            for(Product_Score_Table__c pst: pstList) {
                pst.UniqueKey__c = pst.OCM_Term__c+':'+pst.Category3__c+':'+pst.Category4__c;
            }
            insert pstList;
 
        }
 
    }
 
 
    static testMethod void testMethod1() {
        setup();
        Test.startTest();
        Account AccountHP = [SELECT Id, Name, Management_Code__c, OCM_man_province_txt__c FROM Account WHERE Name = 't_e_s_tHP001'];
        Account AccountAgent2 = [SELECT Id,Name FROM Account WHERE Name = 't_e_s_tAgent002'];
 
        Id PSTH_RecordTypeId = Schema.SObjectType.Product_Score_Table_History__c.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
 
        //历史资料
        Product2 p = [SELECT Plan_Term__c,Category3__c,Category4__c,CreatedDate FROM Product2 WHERE Name = 'Test01'];
        String month = String.valueOf(p.CreatedDate.month());
        String term = p.Plan_Term__c.left(4);
        String uniqueKey = 'A:' + term + ':' + month + ':' + AccountHP.OCM_man_province_txt__c + ':' + AccountHP.Management_Code__c + ':' + AccountAgent2.Id + ':' + p.Category3__c + ':' + p.Category4__c;
        String pstKey = term + ':' + p.Category3__c + ':' + p.Category4__c;
        Product_Score_Table__c pst = [SELECT Id FROM Product_Score_Table__c WHERE UniqueKey__c = :pstKey];
        Product_Score_Table_History__c psth01 = new Product_Score_Table_History__c();
        //UniqueKey__c :  (151PA/151PB)计画财年:第三分类 :新4.5分类 :经销商 :医院
        psth01.UniqueKey__c = uniqueKey;
        psth01.Hospital__c = AccountHP.Id;
        psth01.Product_Score_Table__c = pst.Id;
        psth01.OCM_Province_Text__c = AccountHP.OCM_man_province_txt__c;
        psth01.Province_From_Consume__c = TRUE;
        psth01.Sales_Amount__c = 67;
        psth01.Shipping_date__c = Date.newInstance(Date.today().year(), Date.today().month(), 1);
        psth01.Agency__c = AccountAgent2.Id;
        psth01.Qty__c = 2;
        psth01.RecordTypeId = PSTH_RecordTypeId;
        insert psth01;
        ProductScoreHistoryService.GetNotCompleteData(dep.Id);
        
        ProductScoreHistoryService.RevokeData(psth01.Id);
           ProductScoreHistoryService.GetDoContentC();
        ProductScoreHistoryService.GetCheckPurchaseC();
        ProductScoreHistoryService.GetActionContentC();
        String saverow = '[{"attributes":{"type":"Product_Score_Table_History__c","url":"/services/data/v51.0/sobjects/Product_Score_Table_History__c/' + psth01.Id + '"},"Id":"' + psth01.Id + '","Name":"testname"}]';
        ProductScoreHistoryService.SaveData(saverow);
 
 
 
 
    }
}