global class NFM512Batch implements Database.Batchable, Database.AllowsCallouts { // 设定发送指定数据的ID public String setId; // 设定执行日期 public String setDate; public String endDate; // 是否发送指定的数据 public Boolean isAppoint = false; // 是否发送指定日期的数据 public Boolean isSpecifyDate = false; // 设定发送的数据的IdList public List setIdList; //发送当日符合条件的数据 global NFM512Batch() { // String yesterday = Date.today().addDays(-1).format().replace('/', '-'); // String today = Date.today().format().replace('/', '-'); // this.setDate = yesterday + 'T00:00:00.000+0000'; // this.endDate = today + 'T00:00:00.000+0000'; // this.setDate = 'and ResultDate__c = LAST_N_DAYS:1 and ResultDate__c != LAST_N_DAYS:0 '; // this.setDate = ' and LastModifiedDate >= LAST_N_DAYS:1'; // this.setDate = ' and (CreatedDate >= LAST_N_DAYS:3 OR (CreatedDate >= 2023-10-01T00:00:00.000+0800 and QLMGetDataTime__c >= LAST_N_DAYS:2))'; this.setDate = ' and QLMGetDataTime__c >= LAST_N_DAYS:2'; //20231226 } // 发送指定日期符合条件的数据, eg: testDate = Date.newInstance(2022, 05, 02),发送20220501完成签收的签收单 global NFM512Batch(Date testDate) { isAppoint = true; isSpecifyDate = true; String yesterday = testDate.addDays(-1).format().replace('/', '-'); String pointday = testDate.format().replace('/', '-'); this.setDate = yesterday + 'T00:00:00.000+0800'; this.endDate = pointday + 'T00:00:00.000+0800'; } // 发送在指定日期(区间)的所有符合条件的数据 *** global NFM512Batch(Date testDate, Date testDate1) { isAppoint = true; isSpecifyDate = true; String pointday = testDate.format().replace('/', '-'); String pointday1 = testDate1.format().replace('/', '-'); this.setDate = pointday + 'T00:00:00.000+0800'; this.endDate = pointday1 + 'T00:00:00.000+0800'; } // 发送指定Id的数据 global NFM512Batch(String setId) { this.setId = setId; this.isAppoint = true; } // 发送指定IdList的数据 global NFM512Batch(List setIdList) { this.setIdList = setIdList; this.isAppoint = true; System.debug('lt789---this.setIdList:' + this.setIdList); } global Database.QueryLocator start(Database.BatchableContext bc) { //转义符 \' String QLMrecordId = Schema.SObjectType.Tender_information__c.getRecordTypeInfosByDeveloperName().get('QLM').getRecordTypeId(); System.debug('lt789---QLMrecordId:' + QLMrecordId); String query = 'select Id,name,TenderManageCode__c,InfoType__c,InfoTitle__c,' + 'XmNumber__c,ZhaoBiaoUnit1__c,ZhongBiaoUnit1__c,CreatedDate,' + 'ResultDate__c,InfoPublishTime__c,QLMGetDataTime__c ' + 'From Tender_information__c ' + 'Where RecordTypeId = \'' + QLMrecordId + '\'' // + ' AND IsRelateProject__c = \'是\'' //20231226 + ' AND IsRelateProject__c != \'\'' //20231226 // + ' AND Logical_delete__c = false' //20240105 // + ' AND ZCDataUpdate__c = false' //20231226 // + ' AND IsRelateProject__c != \'否\'' // + ' AND InfoType__c = \'3:结果\'' // + ' AND (subInfoType__c =\'3-5:中标通知\' OR subInfoType__c = \'3-6:合同公告\')' ; System.debug('lt789---query1:' + query); if(String.isNotBlank(setId)){ query += ' and Id =: setId '; } else if (setIdList != null && setIdList.size() > 0) { query += ' and Id IN: setIdList '; } else if(!isAppoint){ query += setDate; } else if(isSpecifyDate){ // query += ' and LastModifiedDate >= ' + setDate; // query += ' and LastModifiedDate < ' + endDate; // this.setDate = ' and (InfoPublishTime__c >= LAST_N_DAYS:1 OR CreatedDate >= LAST_N_DAYS:1)' // OR QLMGetDataTime__c >= LAST_N_DAYS:1 //20231018 query += ' and CreatedDate >= ' + setDate ; query += ' and CreatedDate < ' + endDate ; } // else { // System.debug('lt789---query2:' + query); // query += ' and LastModifiedDate >= LAST_N_DAYS:0'; // } System.debug('lt789---query:' + query); return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List tenderList) { List tenderIdList = new List(); if(tenderList.size() > 0){ for(Tender_information__c ten : tenderList){ tenderIdList.add(ten.Id); } } System.debug('lt789---tenderIdList:' + tenderIdList); if(tenderIdList.size() > 0){ NFM512Controller.executeNotFuture(null, tenderIdList); } } global void finish(Database.BatchableContext BC) { } }