高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class NFM605BatchTest {
    
    @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;
 
        Maintenance_Contract__c contract = new Maintenance_Contract__c();
        contract.Department__c = depart.Id;
        insert contract;
        // 截止日期是昨天
        NewMaintenanceReport_Task__c  report  = new NewMaintenanceReport_Task__c();
        report.Name = 'test';
        report.NewMaintenance_Contract__c = contract.Id;
        report.reissueBatch__c = true;
        report.CorrespondingPeriod__c = Date.today().addDays(-1);
        insert report;
        // 截止日期是7天前
        NewMaintenanceReport_Task__c  report2  = new NewMaintenanceReport_Task__c();
        report2.Name = 'test';
        report2.NewMaintenance_Contract__c = contract.Id;
        report2.reissueBatch__c = true;
        report2.CorrespondingPeriod__c = Date.today().addDays(-7);
        insert report2;
 
 
        NewMaintenanceReport_Task__c  report3  = new NewMaintenanceReport_Task__c();
        report3.Name = 'test';
        report3.NewMaintenance_Contract__c = contract.Id;
        report3.reissueBatch__c = true;
        report3.CorrespondingPeriod__c = Date.today().addDays(-30);
        insert report3;
    }
    @IsTest
    static void myTest1(){
        Test.startTest();
            // 查找指定天数的
            Database.executeBatch(new NFM605Batch(NFMUtil.formatDate2Str(Date.today().addDays(-7))));
        Test.stopTest();
        
        
    }
    @IsTest
    static void myTest(){
        Test.startTest();
            // 默认查找昨天的
            Database.executeBatch(new NFM605Batch());
        Test.stopTest();
        
    }
    @IsTest
    static void myTest2(){
        Test.startTest();
            // 查找指定数据
            List < Id > idList = new List < Id >();
            List<NewMaintenanceReport_Task__c> getList = [Select Id from NewMaintenanceReport_Task__c];
            for(NewMaintenanceReport_Task__c task:[Select Id from NewMaintenanceReport_Task__c]){
                idList.add(task.Id);
            }
            if (idList.size() > 0) {
                Database.executeBatch(new NFM605Batch(idList));
            }
            
        Test.stopTest();
        
        
    }
 
    static testMethod void myTest3() {
        System.Test.startTest();
         Database.executeBatch(new NFM605Batch(true),100);
     System.Test.stopTest();
    }
}