Li Jun
2022-04-06 fb04e7c01d119c60632b4298d18fd93f3ccb3d79
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
@isTest
private class StraightBackAddressControllerTest {
 
    private static Repair__c rpr { get; set; }
    @TestSetup
    static void makeData(){
        List<String> strList = new List<String>();
        strList.add('Address__c');
        strList.add('Contact');
        strList.add('Repair__c');
        TestDataUtility.CreatePIPolicyConfigurations(strList);
    }
    @isTest
    static void testMethod1() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
        //省
        Address_Level__c alc1 = new Address_Level__c(
            Name = '北京市'
        );
        insert new Address_Level__c[] {alc1};
        Address_Level2__c alc11 = new Address_Level2__c(
            Name = '顺义区',Address_Level__c = alc1.Id,Level1_Name__c='北京市'
        );
        Address_Level2__c alc12 = new Address_Level2__c(
            Name = '昌平区',Address_Level__c = alc1.Id,Level1_Name__c='北京市'
        );
 
        insert new Address_Level2__c[] {alc11,alc12};
        //
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = '北京医院';
        company.State_Master__c = alc1.id; 
        company.City_Master__c = alc11.id;
        upsert company;
        Account section = [Select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where ParentId = :company.Id and RecordTypeId = :rectSct[0].Id];
 
        Account depart = new Account();
        depart.RecordTypeId        = rectDpt[0].Id;
        depart.Name                = '北京朝阳医院';
        depart.State_Master__c = alc1.id; 
        depart.City_Master__c = alc11.id;
        depart.Department_Name__c  = 'NFM104TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
 
        company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
        depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
 
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'NFM104Prd1';
        prd1.ProductCode            = 'NFM104Prd1';
        prd1.Repair_Product_Code__c = 'NFM104Prd1_RP';
        prd1.Name                   = 'NFM104Prd1';
        prd1.Manual_Entry__c        = false;
        insert prd1;
 
        Asset ast = new Asset();
        ast.Name                             = 'NFM104Ast1';
        ast.AccountId                        = depart.Id;
        ast.Department_Class__c              = section.Id;
        ast.Hospital__c                      = company.Id;
        ast.Product2Id                       = prd1.Id;
        ast.SerialNumber                     = 'NFM104SerialNumber';
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        insert ast;
 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
 
        User us = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        us.Job_Category__c = '销售服务';
        insert us;
 
        rpr = new Repair__c();
        rpr.SAPRepairNo__c   = 'NFM104Rpr1';
        rpr.Account__c             = depart.Id;
        rpr.Department_Class__c    = section.Id;
        rpr.Hospital__c            = company.Id;
        rpr.Delivered_Product__c   = ast.Id;
        rpr.SalesOfficeCode_selection__c = '北京';
        rpr.Status__c              = '1.受理完毕';
        rpr.Incharge_Staff__c = us.Id;
        rpr.Repair_Detail__c = 'test';
        rpr.On_site_repair__c = '直送SORC修理';
        rpr.Returns_Product_way__c = '返送医院';
        rpr.Address_Type_Index__c=1;
        insert rpr;
 
        Contact contact2 = new Contact();
        contact2.AccountId = depart.Id;
        contact2.FirstName = '小明';
        contact2.LastName = 'test1经销商';
        insert contact2;
 
        Address__c ascc = new Address__c();
        ascc.Address_Classification__c = '医院';
        ascc.Customer__c = depart.Id;
        ascc.Contacts__c = contact2.id;
        ascc.Telephone__c = '123123';
        ascc.Province__c = alc1.id;
        ascc.City__c = alc11.id;
        ascc.Detailed_Address__c = '北京市顺义区西海洪村';
        insert ascc;
 
 
        //测试构造器里面的代码
        PageReference peg = new PageReference('/apex/StraightBackAddress?id='+rpr.id);
        System.Test.setCurrentPage(peg);
 
        StraightBackAddressController sbac = new StraightBackAddressController();
         sbac.txtName = '北京';
         sbac.txtAddress = '市';
         sbac.typeText = '医院';
         sbac.UpdId = ascc.id;
         sbac.adoptId = ascc.id;
         sbac.init();//页面初始化方法
         sbac.onEditor();//修改按钮方法
         sbac.onCopy();//复制按钮方法
         //sbac.optHospitalId = '0011000000V9Tcx';
         //sbac.onChJudge();
         sbac.insUpdData.Contacts__c = null;
         sbac.insUpdData.Create_Contacts__c = '王五';
         sbac.save();
         sbac.adoptSave();
         sbac.searchBtn();
 
         StraightBackAddressController  ss = new StraightBackAddressController();
         ss.txtName = '经销商';
         ss.txtAddress = '哈哈';
         sbac.typeText = '办事处';
         ss.UpdId = ascc.id;
         ss.adoptId = ascc.id;
         ss.init();//页面初始化方法
         ss.onEditor();//修改按钮方法
         ss.onCopy();//复制按钮方法
         ss.insUpdData.Address_Classification__c = '';
         ss.insUpdData.Province__c = null;
         ss.insUpdData.City__c = null;
         ss.insUpdData.Telephone__c = null;
         ss.insUpdData.Detailed_Address__c = null;
         ss.insUpdData.Customer__c = null;
         ss.save();
         ss.searchBtn();
    }
 
     /**
     * 为了方便前段table获取值
     */
    class AddressData {
        //数据
        public Address__c address { get; set; }
        //编辑按钮是否展示
        public String canEdit { get; private set; }
        
        public AddressData(Address__c record) {
            address = record;
            canEdit = '';
        }
        //主要是用于第一个展示和复选框是否显示
        public AddressData(Account record,String disCanEdit,String AccType) {
            this.address = new Address__c(
                Address_Classification__c = AccType,
                Customer__c= record.id,
                Telephone__c = record.phone,
                Province__c = record.State_Master__c,
                City__c = record.City_Master__c,
                Detailed_Address__c = record.Address__c);
            canEdit = disCanEdit;
        }
    }
}