高章伟
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
@isTest
public class PCLLostProduct2AssetHandlerTest {
    @testSetup
    public static void testSetup(){
        setUp();
    }
    public static void setUp(){
        Account company1 = new Account();
        Account company2 = new Account();
        company1.RecordTypeId = '01210000000QemG';
        company1.Name = '病院テスト1';
        company2.RecordTypeId = '01210000000QemG';
        company2.Name = '病院テスト2';
        insert new Account[] {company1, company2};
 
        List<Account> dc1s = 
        [Select Id, Name, Department_Class_Label__c, 
        Sys_Dept_Name_Change_Chk__c 
        from Account where Parent.Id = :company1.Id and
        RecordType.DeveloperName = 'Department_Class_BF'];
 
        Account depart1 = new Account();
        depart1.RecordTypeId = '01210000000QfmR';
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
 
        Account depart2 = new Account();
        depart2.RecordTypeId = '01210000000QfmR';
        depart2.Name         = '*';
        depart2.Department_Name__c  = '診療科2';
        depart2.ParentId            = dc1s[0].Id;
        depart2.Department_Class__c = dc1s[0].Id;
        depart2.Hospital__c         = company1.Id;
 
        insert new Account[] {depart1, depart2};
        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = true;
        prd1.Category5__c = '竞争对手';
        prd1.Brand_Name__c = 'STORZ';
        // prd1.Lost_By_Company__c= 'STORZ'; //add tcm 20211213
 
        Product2 prd2 = new Product2();
        prd2.ProductCode_Ext__c     = 'HistoryPrd2';
        prd2.ProductCode            = 'HistoryPrd2';
        prd2.Repair_Product_Code__c = 'HistoryPrd2_RP';
        prd2.Name                   = 'HistoryPrd2';
        prd2.Manual_Entry__c        = true;
        prd2.Category5__c = '竞争对手';
        prd2.Brand_Name__c = 'STORZ';
        // prd2.Lost_By_Company__c= 'STORZ'; //add tcm 20211213
 
        insert new Product2[] {prd1, prd2};
 
        Opportunity opp1 = new Opportunity(Name='aiueo', StageName='contact', CloseDate=Date.today(),
            Hospital__c = company1.Id,
            Department_Class__c = dc1s[0].Id,
            AccountId = depart1.Id
        );
        Opportunity opp2 = new Opportunity(Name='aiueo1', StageName='contact', CloseDate=Date.today(),
            Hospital__c = company1.Id,
            Department_Class__c = dc1s[0].Id,
            AccountId = depart2.Id
        );
        insert new Opportunity[] {opp1, opp2};
        // 失单
        Lost_cancel_report__c lcr1 = new Lost_cancel_report__c(
            Opportunity__c = opp1.Id, 
            RecordTypeId = '01210000000R4hM',
            LostType__c = '失单',
            Manager_sales__c = UserInfo.getUserId()
        );
        // 部分失单
        Lost_cancel_report__c lcr2 = new Lost_cancel_report__c(
            Opportunity__c = opp2.Id, 
            RecordTypeId = '01210000000R4hM',
            LostType__c = '部分失单',
            Manager_sales__c = UserInfo.getUserId()
        );
        insert new list<Lost_cancel_report__c> {lcr1, lcr2};
 
        PCLLostBrand__c lcB = new PCLLostBrand__c(
            Lost_cancel_report__c = lcr1.id,
            // ProductClass__c ='主机',
            // ProductCategory__c = '3D',
            Lost_By_Company__c = 'STORZ',
            LostPrice__c = 11,
            Agency__c = depart1.id,
            Lost_reason_main__c ='无信息,跟进不及时'
            );
        insert lcB;
        PCLLostProduct__c lsP1 = new PCLLostProduct__c(
            PCLLostBrand__c = lcB.id,
            Quantity__c = 1,
            name = 'lsp1',
            LostBrandName__c = 'STORZ'
            );
        PCLLostProduct__c lsP2 = new PCLLostProduct__c(
            PCLLostBrand__c = lcB.id,
            lostProduct__c = prd1.id,
            Quantity__c = 2,
            name = 'lsp2',
            LostBrandName__c = 'STORZ'
            );
        insert new list<PCLLostProduct__c>{lsP1, lsP2};
        Asset asset01 = createAsset(
            'asset01', depart1.Id, dc1s[0].Id, company1.Id, 
            '00001', prd1.Id,'主机', lsP2.id);
 
    }
    @isTest
    private static void testInsert() {
        PCLLostBrand__c lcB = [select id from PCLLostBrand__c limit 1];
        product2 prd1 = [select id from product2 limit 1];
        PCLLostProduct__c lsP1 = new PCLLostProduct__c(
            PCLLostBrand__c = lcB.id,
            Quantity__c = 1,
            name = 'lsp3',
            LostProduct__c = prd1.id,
            LostBrandName__c = 'STORZ'
            );
        insert lsP1;
  
    }
    @isTest
    private static void testdelete() {
        PCLLostProduct__c lsP1 = [select id 
        from PCLLostProduct__c 
        where name = 'lsp1'];
        delete lsP1;
  
    }
 
    public static Asset createAsset(String input, String accountid, 
        String dcId, String hpId, String serialNo, String prId,String mark, id lpid) {
        Asset asset = new Asset();
        asset.Name = input;
        asset.AccountId = accountid;
        asset.Department_Class__c = dcId;
        asset.Hospital__c = hpId;
        asset.SerialNumber = serialNo;
        asset.Product2Id = prId;
        asset.InstallDate = Date.today();
        asset.IsCompetitorProduct  = true;
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        //在创建Asset的时候添加AssetMark__c 字段
        asset.AssetMark__c = mark;
        asset.LostProduct__c = lpid;
        //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        insert asset;
        return asset;
    }
 
    @isTest
    private static void testupdate() {
        list<product2> prdList = [select id from product2 limit 2];
        PCLLostProduct__c lsP1 = [select id,lostProduct__c
        from PCLLostProduct__c 
        where name = 'lsp2'];
        lsP1.lostProduct__c = null;
        update lsp1;
        lsP1.lostProduct__c = prdList[0].id;
        lsP1.Quantity__c = 3;
        update lsp1;
        lsP1.lostProduct__c = prdList[1].id;
        lsP1.Quantity__c = 1;
        update lsp1;
    }
}