//刷新数据：9月重复性检查项目合并
//一批一条数据
global class RepeatProMergeBtach implements Database.Batchable<SObject> , Database.AllowsCallouts,Database.Stateful{
    
    private final List<String> proIdList = null;

    private Boolean sendToQLM = false; //lt 20240115 DB202401099582 add
    
    global RepeatProMergeBtach(){
    }

    //lt 20240115 DB202401099582 update
    global RepeatProMergeBtach(List<String> str, Boolean apiSend){
        this.proIdList = str;
        this.sendToQLM = apiSend;
    }

    //lt 20240115 DB202401099582 add
    global RepeatProMergeBtach(Boolean apiSend) {
        this.sendToQLM = apiSend;
    }

    global Database.QueryLocator start(Database.BatchableContext BC){

        String soql = 'Select Id,Name,InfoId__c,Logical_delete__c,ProjectId__c,Retain_Tender__c '
                    + 'From Tender_information__c '
                    + 'Where Retain_Tender__c != null '
                    + 'And RepeatProMergeFLG__c = true ' ;
        if(this.proIdList <> null){
            soql += 'And Id in:proIdList';
        }
        System.debug('20231008---soql:'+soql);
        return Database.getQueryLocator(soql);
    }

    global void execute(Database.BatchableContext BC, List<Tender_information__c> tenList){
        System.debug('20231008---execute---');
        System.debug('20231008---tenList---'+tenList);
        if(tenList.Size() > 0 ){
            for(Tender_information__c ten : tenList){
                String tenJson = JSON.serialize(ten);
                System.debug('20231008---tenJson:'+tenJson);
                //lt 20240115 DB202401099582 update NFM504Controller.sendRequestNotFuture(ten.Id);
                if (this.sendToQLM) {
                    System.debug('20240115---ten.Id:'+ten.Id);
                    NFM504Controller.sendRequestNotFuture(ten.Id);
                } else {
                    TenderDeleteLwcController.saveData(tenJson);
                }
            }
        }
    }

    global void finish(Database.BatchableContext BC){
        
    }

    
}