高章伟
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
global class RepairProductGuaranteUpdateBatch implements Database.Batchable<sObject> {
 
    Boolean IsNeedExecute = false; // 2021-03-05  mzy  WLIG-BYHD79  SFDC环境batch合并调查  是否符合执行条件
    
    global RepairProductGuaranteUpdateBatch() {
        
    }
 
    // 2021-03-05  mzy  WLIG-BYHD79  SFDC环境batch合并调查  start
    global RepairProductGuaranteUpdateBatch(Boolean NeedExecute) {
        this.IsNeedExecute = NeedExecute;
    }
    // 2021-03-05  mzy  WLIG-BYHD79  SFDC环境batch合并调查  end
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        if(System.test.isRunningTest()){
            return Database.getQueryLocator(
            [SELECT Id, Name, NewProductGuarante_Formula__c, NewProductGuarante_Txt__c
             FROM Repair__c ]);
        }
        return Database.getQueryLocator(
            [SELECT Id, Name, NewProductGuarante_Formula__c, NewProductGuarante_Txt__c
             FROM Repair__c 
             WHERE (    (   NewProductGuarante_Formula__c = ''
                        AND NewProductGuarante_Txt__c != '')
                    OR (    NewProductGuarante_Formula__c != ''
                        AND NewProductGuarante_Txt__c = '')
                    OR (    NewProductGuarante_Formula__c = '1: 新品保修'
                        AND NewProductGuarante_Txt__c != '1: 新品保修')
                    OR (    NewProductGuarante_Formula__c = '2: 多年保修'
                        AND NewProductGuarante_Txt__c != '2: 多年保修')
                    // LHJ 多年保修 Start
                    OR (    NewProductGuarante_Formula__c = '2: 服务多年保修'
                        AND NewProductGuarante_Txt__c != '2: 服务多年保修')
                    OR (    NewProductGuarante_Formula__c = '8: 市场多年保修'
                        AND NewProductGuarante_Txt__c != '8: 市场多年保修')
                    // LHJ 多年保修 End
                    OR (    NewProductGuarante_Formula__c = '3: 销售特殊保修期'
                        AND NewProductGuarante_Txt__c != '3: 销售特殊保修期')
                    )
                AND (
                        Account__r.RecordType.DeveloperName = 'Department_GS'
                    OR  Account__r.RecordType.DeveloperName = 'Department_OTH' 
                    OR  Account__r.RecordType.DeveloperName = 'Department_ENT' 
                    OR  Account__r.RecordType.DeveloperName = 'Department_GYN' 
                    OR  Account__r.RecordType.DeveloperName = 'Department_URO' 
                    OR  Account__r.RecordType.DeveloperName = 'Department_BF' 
                    OR  Account__r.RecordType.DeveloperName = 'Department_GI')
            ]
        );
    }
 
       global void execute(Database.BatchableContext BC, List<SObject> sList) {
        if (sList != null && sList.size() > 0) {
            List<Repair__c> updateList = new List<Repair__c>();
            for (SObject sObj : sList) {
                Repair__c rc = (Repair__c) sObj;
                rc.NewProductGuarante_Txt__c = rc.NewProductGuarante_Formula__c;
                updateList.add(rc);
            }
            update updateList;
        }
    }
    
    global void finish(Database.BatchableContext BC) {
 
        //2021-03-10  mzy  WLIG-BYHD79  SFDC环境batch合并调查  start
        if(!Test.isRunningTest() &&IsNeedExecute==true){
              //batch里调用下一个batch时,希望跟原有的Schedule里面传的条数保持一致
            Id execBTId = Database.executebatch(new Send_Have_Arrival_wh_Email_Batch(true),200);
        }
        //2021-03-10  mzy  WLIG-BYHD79  SFDC环境batch合并调查 end
 
        
    }
    
}