高章伟
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
@isTest
private class NFM602ControllerTest {
    static testMethod void testMethod1() {
        
    }
    @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.Name         = 'NFM105TestCompany';
        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;
 
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner01', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner01@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        Inspection_Report__c ins = new Inspection_Report__c(Name = '*',
            Hospital__c = company.Id
           
        );
        insert ins;
        Inspection_Item__c item = new Inspection_Item__c(
                Inspection_ReportId__c =ins.Id, //'a1Y9D000000i9tWUAQ',
                ItemStatus__c = 'NG'
            );
        insert item;
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = '[{"strategicDepartmenCd":null,"spotCheckPerson":"00510000005sEEMAA2","spotCheckEquipTotalQty":1,"spotCheckDate":"20210806000000","spotCheckBatch":"10","spotCheckAbnormalQty":0,"ListOfAbnormalDevicesInfo":null,"hospitalCd":"8089815","departmentCd":null,"contractStartDate":null,"contractEquipQty":0,"contractEndDate":null,"contractCd":null,"checkStartTime":"20210806100000","checkEndTime":"20210806120000"}]';
        iflog.Type__c = '602test';
        insert iflog;
    }
    @isTest
    static void testcallout1(){
        List<Inspection_Report__c> reportList = [select id from Inspection_Report__c];
 
        Test.startTest();
 
        List<Id> idList = new List<Id>();
        for(Inspection_Report__c inspection : reportList){
            idList.add(inspection.Id);
        }
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Log__c = 'test start \n';
        insert iflog;
        NFM602Controller.callout(iflog.Id,idList);
        Test.stopTest();
    }
 
    @isTest
    static void testcallout2(){
        List<Inspection_Report__c> insList = [select id from Inspection_Report__c];
 
        Test.startTest();
 
        List<Id> idList = new List<Id>();
        for(Inspection_Report__c ins : insList){
            idList.add(ins.Id);
        }
        NFM602Controller.executeNotFuture(null,idList);
        
        Test.stopTest();
    }
 
    @isTest
    static void testcallout3(){
        BatchIF_Log__c iflog = [select id from BatchIF_Log__c where Type__c = '602test'];
        NFM602Controller.ManualExecute(iflog.Id);
    }
 
    @isTest
    static void testcallout4(){
        //维修合同
        Maintenance_Contract__c macnt = new Maintenance_Contract__c();
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User hpOwner = new User(Test_staff__c = true, Job_Category__c='销售服务' ,LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner02', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner02@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        // 取引先作成
        RecordType rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        RecordType rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        Account hp = new Account(RecordTypeId = rectHp.Id, Name = 'InsReportPDFControllerTestHp1', OwnerId = hpOwner.Id);
        insert hp;
        Account section = [Select Id from Account where RecordType.Name = '戦略科室分類 消化科' and ParentId =: hp.Id];
        Account depart = new Account();
        depart.RecordTypeId = rectDpt.Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'HistoryTestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = hp.Id;
        insert depart;
 
        macnt.Name = '测试服务合同1';
        macnt.Status__c = '合同中';
        //科室
        macnt.Department__c = depart.id;
        //主担当者
        macnt.Service_Contract_Staff__c = hpOwner.Id ;
        insert macnt;
 
        //点检计划
        Inspectup_Plan__c Inplan = new Inspectup_Plan__c();
        //币种
        Inplan.CurrencyIsoCode = 'CNY';
        //点检计划编码
        Inplan.Name  = 'Check_plan_Test1';
        //实际执行数      
        Inplan.Actual_Execution_Quantity__c = 0;
        //Maintenance_Contract__c:维修合同
        Inplan.Maintenance_Contract__c = macnt.id;
        //Planned_Start_Date__c:计划开始日
        Inplan.Planned_Start_Date__c = Date.today().addDays(-1);
        // Planned_End_Date__c:计划结束日
        Inplan.Planned_End_Date__c = Date.today().addDays(+2);
        //Timeliness_Rate__c:本次点检及时率
        Inplan.Timeliness_Rate__c = 80;
        //Implementation_Rate__c:本次点检实施率
        Inplan.Implementation_Rate__c = 80;
        insert Inplan;
 
        Asset ass1 = new Asset(
            AccountId = depart.Id,
            Hospital__c = hp.Id,
            SerialNumber = 'lw0001',
            Name = '测试设备0001:aaaaa'
        );
        Asset ass2 = new Asset(
            AccountId = depart.Id,
            Hospital__c = hp.Id,
            SerialNumber = 'lw0002',
            Name = '测试设备0002:aaaaa'
        );
        insert new Asset[] {ass1, ass2};
        RecordType irType = [select Id,Name from RecordType where IsActive = true and SobjectType = 'Inspection_Report__c' and DeveloperName = 'ContractInspection'];
        
        Inspection_Report__c ir2 = new Inspection_Report__c(Name = 'Test01',
            Hospital__c = hp.Id,
            Reporter__c = hpOwner.id,
            Status__c = '草案中',
            Inspectup_Plan__c = Inplan.Id,
            Contract__c = macnt.id,
            Inspection_Date__c = Date.today(),
            RecordTypeId = irType.Id
        );//点检报告书
        insert ir2;
 
 
        Inspection_Item__c ii2 = new Inspection_Item__c(
            Inspection_ReportId__c = ir2.Id,
            AssetId__c = ass2.Id,
            ItemStatus__c = 'NG'
        );
        insert new Inspection_Item__c[] {ii2};
 
        
        // ir2.Status__c = '申请中';
        // update ir2;
        ir2.Status__c = '批准';
        update ir2;
 
        // delete ir;
    }
    
}