高章伟
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
@isTest
private class NFM601ControllerTest {
    
    @testSetup
    static void makeTestRepair() {
        
 
        List < RecordType > rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '病院'
        ];
        if (rectCo.size() == 0) {
            throw new ControllerUtil.myException('not found 病院 recodetype');
        }
        List < RecordType > rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '戦略科室分類 消化科'
        ];
        if (rectSct.size() == 0) {
            throw new ControllerUtil.myException('not found 戦略科室分類 呼吸科 recodetype');
        }
        List < RecordType > rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '診療科 消化科'
        ];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Is_Active__c = '有効';
        company.Name = 'NFM105TestCompany';
        company.AwaitToSendAWS__c = true;
        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.Department_Name__c = 'NFM105TestDepart';
        depart.ParentId = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c = company.Id;
        upsert depart;
 
        company.Site = '测试变更别名1';
 
        upsert company; 
 
        List < RecordType > rectDpt2 = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and DeveloperName = 'Agency'
        ];
        if (rectDpt.size() == 0) {
            throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
        }
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        Account company2 = new Account();
        company2.RecordTypeId = rectDpt2[0].Id;
        company2.Name = 'NFM105TestCompany';
        upsert company2;
 
        License_Information__c lic = new License_Information__c();
        lic.name = 'Test20181204';
        lic.LicenseType__c = '医疗器械经营许可证';
        lic.BusinessLicense__c = '20180522';
        lic.ValidFrom__c = date.newinstance(2018, 05, 22);
        lic.ValidTo__c = date.newinstance(2018, 05, 22);
        lic.Scope3__c = '6815;6822;6823;6825';
        lic.IsInquire__c = false;
        lic.LicenseAndAccount__c = company2.Id;
        insert lic;
        License_Information__c lic1 = new License_Information__c();
        lic1.name = 'Test20190111';
        lic1.LicenseType__c = '第二类医疗器械经营备案凭证';
        lic1.BusinessLicense__c = '20190522';
        lic1.ValidFrom__c = date.newinstance(2018, 05, 21);
        lic1.ValidTo__c = date.newinstance(2018, 05, 21);
        lic.IsInquire__c = false;
        lic1.Scope__c = '6815;6822;6823;6825';
        lic1.LicenseAndAccount__c = company2.Id;
        insert lic1;
 
        List < RecordType > rectDptAgencyContract = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and DeveloperName = 'AgencyContract'
        ];
        if (rectDptAgencyContract.size() == 0) {
            return;
        }
    
        Account AagencyContractAccount = new Account();
        AagencyContractAccount.RecordTypeId = rectDptAgencyContract[0].Id;
        AagencyContractAccount.Contract_Decide_Start_Date__c = System.today();
        AagencyContractAccount.Contract_Decide_End_Date__c = System.today();
        AagencyContractAccount.Contract_End_Date__c = Date.today();
        AagencyContractAccount.Name = '*';
        AagencyContractAccount.Department_Name__c = 'NFM601TestDepart';
        AagencyContractAccount.ParentId = company2.Id;
        AagencyContractAccount.Agent_Ref__c = company2.Id;
        AagencyContractAccount.ET_SP_Dealer__c = true;
        upsert AagencyContractAccount;
 
 
        List < BatchIF_Transfer__c > transfers = new List < BatchIF_Transfer__c > ();
        BatchIF_Transfer__c transfer = new BatchIF_Transfer__c();
        transfer.Table__c = 'Account';
        transfer.Column__c = 'RecordTypeId';
        transfer.External_Value__c = rectDpt[0].Id;
        transfer.Internal_Value__c = '消化科';
        insert transfer;
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = '{"GeData":[{"HospitalInfoData":[{"StrategicDeptCode":"","Province":"CN-05","ParentCode":"360155呼吸科","HospitalRank":"L","HospitalName":"忻州市二八二医院 呼吸科 呼吸一科","HospitalCode":"","DeptType":"BF","DeptCode":"8087357","City":"CN-0567","Area":"3.西北","Accounttype":"3"}],"DealerInfoData":[]}]}';
        iflog.Type__c = '601test';
        insert iflog;
    }
 
    @isTest
    static void testCallOut1() {
        List < Account > userList = [select id from Account];
 
        Test.startTest();
 
        List < Id > idList = new List < Id > ();
        for (Account user: userList) {
            idList.add(user.Id);
        }
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = 'test start \n';
        insert iflog;
 
        NFM601Controller.callout(iflog.Id, idList);
 
        Test.stopTest();
    }
 
    // @isTest
    // static void testCallOut2() {
    //     List < Account > userList = [select id from Account];
 
    //     Test.startTest();
 
    //     List < Id > idList = new List < Id > ();
    //     for (Account user: userList) {
    //         idList.add(user.Id);
    //     }
    //     NFM601Controller.executefuture(null, idList);
 
    //     Test.stopTest();
    // }
 
    @isTest
    static void testcallout3() {
        BatchIF_Log__c iflog = [select id from BatchIF_Log__c where Type__c = '601test'];
        NFM601Controller.ManualExecute(iflog.Id);
    }
 
    @isTest
    static void testcallout4() {
        // BatchIF_Log__c iflog = [select id from BatchIF_Log__c where Type__c = '601test'];
        // NFM601Controller.ManualExecute(iflog.Id);
        Database.executeBatch(new Sfdc2PoAccountBatch(),100);
    }
 
    @isTest
    static void testcallout5() {
         List < RecordType > rectCo00 = [select Id from RecordType where IsActive = true and SobjectType = 'Account'
            and Name = '病院'
        ];
        Account hospital = new Account();
        hospital.RecordTypeId = rectCo00[0].Id;
        hospital.Is_Active__c = '有効';
        hospital.Name = 'hospital';
        hospital.AwaitToSendAWS__c = true;
        insert hospital;
        List < String > accountIdList = new List < String >();
        accountIdList.add(hospital.Id);
        Database.executeBatch(new Sfdc2PoAccountBatch(accountIdList),100);
    }
 
}