GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
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
global class UpdateTotalCostPriceSetTextInquiryBatch implements Database.Batchable<sObject> {
    private List<String> idList = null;
    global UpdateTotalCostPriceSetTextInquiryBatch() {}
    global UpdateTotalCostPriceSetTextInquiryBatch(List<String> temp) {
      idList = temp;
    }
 
    global Database.QueryLocator start(Database.BatchableContext BC) {
       String query;
       //王鹏伟新加条件
       //'Opportunity.StageName != \'Closed Won\' and Opportunity.StageName != \'Closed Lost\' and Opportunity.StageName != \'Closed Cancel\' and '+
       //'Opportunity.Model_product_cnt__c != 0 and Opportunity.ProductCount__c != 0 and Opportunity.OppBatchUpdate__c = true'
       query = 'select TotalCostPrice__c,TotalCostPrice_Text__c,Opportunity.Model_product_cnt__c,Opportunity.ProductCount__c,Opportunity.OppBatchUpdate__c from OpportunityLineItem where '+
       'Opportunity.StageName != \'Closed Won\' and Opportunity.StageName != \'Closed Lost\' and Opportunity.StageName != \'Closed Cancel\' '
       /*+'and Opportunity.Model_product_cnt__c != 0 and Opportunity.ProductCount__c != 0 and Opportunity.OppBatchUpdate__c = true'*/;
       if(idList != null){
          query = 'select TotalCostPrice__c,TotalCostPrice_Text__c,Opportunity.Model_product_cnt__c,Opportunity.ProductCount__c,Opportunity.OppBatchUpdate__c from OpportunityLineItem where '+
          'Opportunity.StageName != \'Closed Won\' and Opportunity.StageName != \'Closed Lost\' and Opportunity.StageName != \'Closed Cancel\' and Opportunity.Id=:idList';
       }
        return Database.getQueryLocator(query);
        
    }
 
    WebService static String executeWebSide(String Opportunityid){
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Type__c = 'PushNotification';
        iflog.Is_Error__c = 0;
        iflog.Log__c = 'UpdateTotalCostPriceSetTextInquiryBatch start0\n';
        iflog.ErrorLog__c = '';
        insert iflog;
        List<OpportunityLineItem> updateList = new List<OpportunityLineItem>();
        List<OpportunityLineItem> OpportunityDataList1 = [select
                                                Opportunity.StageName,
                                                TotalCostPrice__c,
                                                TotalCostPrice_Text__c,
                                                Opportunity.Model_product_cnt__c,
                                                Opportunity.ProductCount__c,
                                                Opportunity.OppBatchUpdate__c                                              
                                        from OpportunityLineItem where Opportunity.Id = :Opportunityid and Opportunity.StageName <> 'Closed Won' and Opportunity.StageName <> 'Closed Lost' and Opportunity.StageName <> 'Closed Cancel' 
                                        /*and Opportunity.Model_product_cnt__c != 0 and Opportunity.ProductCount__c != 0 and Opportunity.OppBatchUpdate__c = true*/];
        if (OpportunityDataList1.size() == 0){ 
            return '没有符合条件的询价数据';  
        } else {
            for (OpportunityLineItem OpportunityData:OpportunityDataList1){
                //王鹏伟 添加if筛选条件  && OpportunityData.Opportunity.Model_product_cnt__c != 0 && OpportunityData.Opportunity.ProductCount__c != 0 &&
                //OpportunityData.Opportunity.OppBatchUpdate__c == true   
                if (OpportunityData.TotalCostPrice__c != OpportunityData.TotalCostPrice_Text__c && 
                  OpportunityData.Opportunity.Model_product_cnt__c == 0 && OpportunityData.Opportunity.ProductCount__c != 0 &&
                  OpportunityData.Opportunity.OppBatchUpdate__c == true){ 
                      OpportunityData.TotalCostPrice_Text__c = (Decimal)OpportunityData.TotalCostPrice__c;
                      updateList.add(OpportunityData);
                }
            }
            if(updateList.size() >0){
                update updateList;
                return '更新成功';
            }else{
                //王鹏伟新加else返回
                return '该询价不符合更新条件,不需要更新。';
            }
        }
    }
    
    global void execute(Database.BatchableContext BC, List<OpportunityLineItem> OpportunityDataList) {
      //王鹏伟 添加if筛选条件
      //&& OpportunityData.Opportunity.Model_product_cnt__c != 0 && OpportunityData.Opportunity.ProductCount__c != 0 &&
      // OpportunityData.Opportunity.OppBatchUpdate__c == true
      List<OpportunityLineItem> itemList = new List<OpportunityLineItem>();
               for (OpportunityLineItem OpportunityData:OpportunityDataList){   
                      if (OpportunityData.TotalCostPrice__c != OpportunityData.TotalCostPrice_Text__c  && 
                        OpportunityData.Opportunity.Model_product_cnt__c == 0 && OpportunityData.Opportunity.ProductCount__c != 0 &&
                        OpportunityData.Opportunity.OppBatchUpdate__c == true) 
                      { 
                        OpportunityData.TotalCostPrice_Text__c = (Decimal)OpportunityData.TotalCostPrice__c;
                        itemList.add(OpportunityData);
            }
 
        }
        if(itemList.size()>0) update itemList;
       
       }   
 
    global void finish(Database.BatchableContext BC) {
        // 今回はやることないです
    }
}