高章伟
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@isTest
private class OPDQuarterPlanPhotographBatchTest {
    
        static Date thismonth_Lastday ;
    static Date lastmonth_Lastday ;
    
    static void  basicData() {
        // カスタム設定を定義
        SS_BatchColumnMapping__c opdMapping = new SS_BatchColumnMapping__c(Name = 'OPDPlan__c', SS_TableName__c='SS_OPDPlan__c');
        opdMapping.From_Column_001__c = 'Id';
        opdMapping.SS_Column_001__c = 'OPDPlan__c.Name';
        opdMapping.From_Column_002__c = 'Name';
        opdMapping.SS_Column_002__c = 'Name';
        insert new SS_BatchColumnMapping__c[] {opdMapping};
        Date toDate = Date.today();
        //本月的第一天
        Date mon1stDate = Date.newInstance(toDate.year(), toDate.month(), 1);
        //本月的最后一天
        thismonth_Lastday = Date.toDay().addMonths(1).toStartOfMonth().addDays(-1);
        System.debug('thismonth_Lastday6666' + thismonth_Lastday);
        //上月的第一天
        Date lastmonth_firstday = Date.toDay().addMonths(-1).toStartOfMonth();
        //上月的最后一天
        lastmonth_Lastday = Date.newInstance(toDate.year(), toDate.month(), 1).addDays(-1);
        System.debug('lastmonth_Lastday1234' + lastmonth_Lastday);
        //下月的第一天
        Date nextmonth_firstday = Date.toDay().addMonths(1).toStartOfMonth();
        //下月的最后一天
        Date nextmonth_Lastday = Date.toDay().addMonths(2).toStartOfMonth().addDays(-1);
 
        OPDPlan__c oPDPlan0 = new OPDPlan__c();
        oPDPlan0.Status__c = '计划中';
        oPDPlan0.OPDPlan_ImplementDate__c = nextmonth_firstday;
        oPDPlan0.NoOpp_Reason__c = '无询价查阅权限';
        insert oPDPlan0;
 
        OPDPlan__c oPDPlan1 = new OPDPlan__c();
        oPDPlan1.Status__c = '计划中';
        oPDPlan1.OPDPlan_ImplementDate__c = nextmonth_firstday;
        oPDPlan1.NoOpp_Reason__c = '无询价查阅权限';
        insert oPDPlan1;
 
        OPDPlan__c oPDPlan2 = new OPDPlan__c();
        oPDPlan2.Status__c = '计划中';
        oPDPlan2.OPDPlan_ImplementDate__c = nextmonth_firstday;
        oPDPlan2.NoOpp_Reason__c = '无询价查阅权限';
        insert oPDPlan2;
 
        OPDPlan__c oPDPlan3 = new OPDPlan__c();
        oPDPlan3.Status__c = '计划中';
        oPDPlan3.OPDPlan_ImplementDate__c = nextmonth_firstday;
        oPDPlan3.NoOpp_Reason__c = '无询价查阅权限';
        insert oPDPlan3;
        OPDPlan__c oPDPlan4 = new OPDPlan__c();
        oPDPlan4.Status__c = '计划中';
        oPDPlan4.NoOpp_Reason__c = '无询价查阅权限';
        oPDPlan4.OPDPlan_ImplementDate__c = nextmonth_firstday;
        insert oPDPlan4;
        
        OPDPlan__c oPDPlan5 = new OPDPlan__c();
        oPDPlan5.Status__c = '计划中';
        oPDPlan5.NoOpp_Reason__c = '无询价查阅权限';
        oPDPlan5.OPDPlan_ImplementDate__c = nextmonth_firstday;
        insert oPDPlan5;
    }
    //正常执行
    @isTest 
    static void test_method_one() {
 
        basicData();
        Id execBTId = null;
        System.Test.StartTest();
        List<OPDPlan__c> oPDPlans = [Select Id,Name,Status__c,lastMonth_Plan__c,ThisMonthPlan__c,If_ThisMonth_Plan__c 
                                        from OPDPlan__c
                                         Where (( lastMonth_Plan__c != 0 and ThisMonthPlan__c = 0) or 
                                              ( lastMonth_Plan__c = 0 and ThisMonthPlan__c != 0) or 
                                              ( ThisMonthPlan__c = 0 and If_ThisMonth_Plan__c != 0) or 
                                              ( ThisMonthPlan__c != 0 and If_ThisMonth_Plan__c = 0))
                                              and OPDPlan_ImplementDate__c <= :thismonth_Lastday];
        // System.assertEquals(4, oPDPlans.size());
        execBTId = Database.executeBatch(new OPDQuarterPlanPhotographBatch());
        
        System.Test.StopTest();
        
    }
    ////指定日期执行
    //@isTest 
    //static void test_method_two() {
    //    basicData();
 //       Id execBTId = null;
 //       List<OPDPlan__c> oPDPlans = [Select Id,Name,Status__c,lastMonth_Plan__c,ThisMonthPlan__c,If_ThisMonth_Plan__c 
 //                                       from OPDPlan__c
 //                                        Where (( lastMonth_Plan__c != 0 and ThisMonthPlan__c = 0) or 
 //                                             ( lastMonth_Plan__c = 0 and ThisMonthPlan__c != 0) or 
 //                                             ( ThisMonthPlan__c = 0 and If_ThisMonth_Plan__c != 0) or 
 //                                             ( ThisMonthPlan__c != 0 and If_ThisMonth_Plan__c = 0) or 
 //                                             ( lastMonth_Execute__c = 0 and ThisMonthExecute__c != 0) or
 //                                             ( lastMonth_Execute__c != 0 and ThisMonthExecute__c = 0)) 
 //                                             and OPDPlan_ImplementDate__c <= :lastmonth_Lastday];
 //       System.assertEquals(2, oPDPlans.size());
 //       System.Test.StartTest();
 //       execBTId = Database.executeBatch(new OPDPlanMarkBatch(String.valueOf(lastmonth_Lastday)));
 //       System.Test.StopTest();
    //}
    //指定"OPD计划"的Id执行
    @isTest 
    static void test_method_three() {
        basicData();
        List<String> oPDPlanIds = new List<String>();
        List<OPDPlan__c> oDPlans = [ select Id,Name from OPDPlan__c];
        System.assertEquals(6, oDPlans.size());
        for (OPDPlan__c opdPlan : oDPlans) {
            oPDPlanIds.add(opdPlan.Id);
        }
        Id execBTId = null;
        System.Test.StartTest();
        execBTId = Database.executeBatch(new OPDQuarterPlanPhotographBatch(oPDPlanIds));
        System.Test.StopTest();
    }
}