高章伟
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
@isTest
private class UpdateStatuAchievementsBatchTest {
 
    static testMethod void myUnitTest() {
        Opportunity opp = new Opportunity(Name='aiueo', StageName='出荷', CloseDate=Date.today());
        insert opp;
        
        Statu_Achievements__c sta = new Statu_Achievements__c(
            Name='test01',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有'
        );
        Statu_Achievements__c sta2 = new Statu_Achievements__c(
            Name='test02',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有',
            Last_Batch_Day__c = Date.today().addDays(-14)
        );
        Statu_Achievements__c sta3 = new Statu_Achievements__c(
            Name='test03',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有',
            Last_Batch_Day__c = Date.today().addDays(-21)
        );
        Statu_Achievements__c sta4 = new Statu_Achievements__c(
            Name='test04',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有',
            Last_Batch_Day__c = Date.today().addDays(-28)
        );
        Statu_Achievements__c sta5 = new Statu_Achievements__c(
            Name='test05',
            Opportunity__c = opp.Id,
            DeliveryStatus__c = 'test',
            PaymentRate__c = '1234',
            End_User_price__c = 0,
            AssignmentStatus__c = '全部分配',
            Last_week__c = '5 货齐,未付款,无用户合同',
            X2weeks_ago__c = '4 备货中',
            X3Weeks_ago__c = '3 已付款,无用户合同',
            X4weeks_ago__c = '2 待付款',
            X5weeks_ago__c = '1 全没有',
            Last_Batch_Day__c = Date.today().addDays(-35)
        );
        insert new Statu_Achievements__c[] {sta,sta2,sta3,sta4,sta5};
        
        Statu_Achievements__c sta1 = [select Current_status__c,Last_week__c,X2weeks_ago__c,X3Weeks_ago__c,X4weeks_ago__c,X5weeks_ago__c from Statu_Achievements__c where Id = :sta.Id];
        System.assertEquals('6 货齐,已付款,无用户合同', sta1.Current_status__c);
        System.assertEquals('5 货齐,未付款,无用户合同', sta1.Last_week__c);
        System.assertEquals('4 备货中', sta1.X2weeks_ago__c);
        System.assertEquals('3 已付款,无用户合同', sta1.X3Weeks_ago__c);
        System.assertEquals('2 待付款', sta1.X4weeks_ago__c);
        System.assertEquals('1 全没有', sta1.X5weeks_ago__c);
        
        System.Test.StartTest();
        Id execBTId = Database.executeBatch(new UpdateStatuAchievementsBatch(), 5);
        System.Test.StopTest();
        
        Statu_Achievements__c sta_1 = [select Current_status__c,Last_week__c,X2weeks_ago__c,X3Weeks_ago__c,X4weeks_ago__c,X5weeks_ago__c from Statu_Achievements__c where Id = :sta.Id];
        System.assertEquals('6 货齐,已付款,无用户合同', sta_1.Current_status__c);
        System.assertEquals('6 货齐,已付款,无用户合同', sta_1.Last_week__c);
        System.assertEquals('5 货齐,未付款,无用户合同', sta_1.X2weeks_ago__c);
        System.assertEquals('4 备货中', sta_1.X3Weeks_ago__c);
        System.assertEquals('3 已付款,无用户合同', sta_1.X4weeks_ago__c);
        System.assertEquals('2 待付款', sta_1.X5weeks_ago__c);
        
        Statu_Achievements__c sta_2 = [select Current_status__c,Last_week__c,X2weeks_ago__c,X3Weeks_ago__c,X4weeks_ago__c,X5weeks_ago__c from Statu_Achievements__c where Id = :sta2.Id];
        System.assertEquals('6 货齐,已付款,无用户合同', sta_2.Current_status__c);
        System.assertEquals('6 货齐,已付款,无用户合同', sta_2.Last_week__c);
        System.assertEquals(null, sta_2.X2weeks_ago__c);
        System.assertEquals('5 货齐,未付款,无用户合同', sta_2.X3Weeks_ago__c);
        System.assertEquals('4 备货中', sta_2.X4weeks_ago__c);
        System.assertEquals('3 已付款,无用户合同', sta_2.X5weeks_ago__c);
        
        Statu_Achievements__c sta_3 = [select Current_status__c,Last_week__c,X2weeks_ago__c,X3Weeks_ago__c,X4weeks_ago__c,X5weeks_ago__c from Statu_Achievements__c where Id = :sta3.Id];
        System.assertEquals('6 货齐,已付款,无用户合同', sta_3.Current_status__c);
        System.assertEquals('6 货齐,已付款,无用户合同', sta_3.Last_week__c);
        System.assertEquals(null, sta_3.X2weeks_ago__c);
        System.assertEquals(null, sta_3.X3Weeks_ago__c);
        System.assertEquals('5 货齐,未付款,无用户合同', sta_3.X4weeks_ago__c);
        System.assertEquals('4 备货中', sta_3.X5weeks_ago__c);
        
        Statu_Achievements__c sta_4 = [select Current_status__c,Last_week__c,X2weeks_ago__c,X3Weeks_ago__c,X4weeks_ago__c,X5weeks_ago__c from Statu_Achievements__c where Id = :sta4.Id];
        System.assertEquals('6 货齐,已付款,无用户合同', sta_4.Current_status__c);
        System.assertEquals('6 货齐,已付款,无用户合同', sta_4.Last_week__c);
        System.assertEquals(null, sta_4.X2weeks_ago__c);
        System.assertEquals(null, sta_4.X3Weeks_ago__c);
        System.assertEquals(null, sta_4.X4weeks_ago__c);
        System.assertEquals('5 货齐,未付款,无用户合同', sta_4.X5weeks_ago__c);
        
        Statu_Achievements__c sta_5 = [select Current_status__c,Last_week__c,X2weeks_ago__c,X3Weeks_ago__c,X4weeks_ago__c,X5weeks_ago__c from Statu_Achievements__c where Id = :sta5.Id];
        System.assertEquals('6 货齐,已付款,无用户合同', sta_5.Current_status__c);
        System.assertEquals('6 货齐,已付款,无用户合同', sta_5.Last_week__c);
        System.assertEquals(null, sta_5.X2weeks_ago__c);
        System.assertEquals(null, sta_5.X3Weeks_ago__c);
        System.assertEquals(null, sta_5.X4weeks_ago__c);
        System.assertEquals(null, sta_5.X5weeks_ago__c);
    }
}