global without sharing class NFM401WebService{
    webservice static String sendToETQ(String iflog_Id,BatchIF_Log__c rowDataSFDC, List<String> repairIds,String statu){
        List<QIS_Report__c> temp = [select id from QIS_Report__c where id in :repairIds ];
        if(temp != null && temp.size() > 0){
            try {
                Database.executeBatch(new QISToPDFBatch(iflog_Id, rowDataSFDC,repairIds,statu),50); //生成PDF
            }
            catch (Exception e) {
                return '更新QIS报错:'+ e.getMessage();
            }
            // Database.executeBatch(new QISToPDFBatch(iflog_Id, rowDataSFDC,repairIds,statu),50); //生成PDF
        }else{

            // var updateRe = new sforce.SObject("Repair__c"); 
            // updateRe.Id = RepairId; 
            // updateRe.INTERFACE_RECORD_ID__c = null; 
            // updateRe.ETQ_UPLOAD_STATUS__c = null; 
            // updateRe.ETQ_UPLOAD_MESSAGE__c = null; 
            // updateRe.OSH_ConfirmationDate__c = new Date(); 
            // updateRe.OSH_Affirmant__c = uid; 
            // var serverTimestamp = sforce.connection.getServerTimestamp(); 
            // updateRe.AWS_Interface_Time__c = serverTimestamp.timestamp; 
            // updateRe.AsyncData__c = true; 
            // //alert('updateRe'+updateRe); 
            // result = sforce.connection.update([updateRe]); 
            BatchIF_Log__c iflog = new BatchIF_Log__c();
            iflog.Type__c = 'sendToETQ';
            iflog.ErrorLog__c = '';
            iflog.Log__c = 'NFM401WebService start--';

            Repair__c updateRe = new Repair__c();
            updateRe.Id = repairIds[0];
            updateRe.INTERFACE_RECORD_ID__c = null; 
            updateRe.ETQ_UPLOAD_STATUS__c = null; 
            updateRe.ETQ_UPLOAD_MESSAGE__c = null; 
            updateRe.OSH_ConfirmationDate__c = Date.today(); 
            updateRe.OSH_Affirmant__c = UserInfo.getUserId(); 
            updateRe.AWS_Interface_Time__c = Datetime.now();
            updateRe.AsyncData__c = true; 
            //update by rentx 2021-03-23 start 需要先更新修理的信息再掉401接口 不然的话可能会出现 调用成功但是部分修理更新失败的情况 将更新修理的步骤提前 则当修理更新失败时 就不会往下执行401的接口了 
            try{
                update updateRe;
                Database.executeBatch(new RepairToPDFBatch(iflog_Id, rowDataSFDC,repairIds,statu)); //生成PDF
                iflog.Log__c += '\n修理:'+updateRe+' 更新成功';
                iflog.Log__c = '\nNFM401WebService end--';
                insert iflog;
            }catch(Exception ex){
                iflog.ErrorLog__c += '修理:'+updateRe+' 更新失败,因为::'+ex.getMessage();
                iflog.Log__c = '\nNFM401WebService end--';
                // System.debug('更新修理报错::36'+updateRe);
                insert iflog;
                return '更新修理报错:'+ ex.getMessage();
            }
            // update updateRe;
            // Database.executeBatch(new RepairToPDFBatch(iflog_Id, rowDataSFDC,repairIds,statu)); //生成PDF
            //update by rentx end
        }
        return '发送成功!';
    }
}