高章伟
2022-03-10 1312ba82d4c880bdb5357d28e0d4af5b285f610f
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
@isTest
private class NFM701ControllerHandlerTest {
    
    @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 = 'NFM701TestDepart';
        AagencyContractAccount.ParentId = company2.Id;
        AagencyContractAccount.Agent_Ref__c = company2.Id;
        AagencyContractAccount.ET_SP_Dealer__c = true;
        // AagencyContractAccount.RecordType.DeveloperName = 'HP';
        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 = '{"GeDatas":{"Monitoring":{"TransmissionDateTime":"20211231104929","Text":"","Tag":"MSGH","Sender":"SFDC","Receiver":"OBPM","NumberOfRecord":"1","MessageType":"NFM701","MessageGroupNumber":"20211231104929"},"GeData":[{"StateMaster":"山西省","LinkedHospitalMCode":null,"IsMerge":false,"IsActive":true,"HospitalName":"夏县第二人民医院","HospitalMCode":"360437","Grade":"二级乙","DataType":"Hospital","CityMaster":"运城市","Address":"山西省运城市夏县运城地区夏县北街"}]}}';
        // iflog.Type__c = '701test';
        // insert iflog;
    }
    static testMethod void testMethod1() {
        List < Account > userList = [select id from Account];
        Test.startTest();
        Integer i = 0;
        List < Id > idList = new List < Id > ();
        for (Account user: userList) {
            idList.add(user.Id);
            user.Is_Active__c = '有效';
            user.Name = user.Name + i;
            i++;
        }
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = 'test start \n';
        insert iflog;
        upsert userList;
        // NFM701Controller.callout(iflog.Id, idList);
 
 
        Test.stopTest();
    }
}