public with sharing class NFM511FutureController implements Queueable { //先定义 // public String txId; public String rowData_id; public NFM511FutureController(String rowData_id) { this.rowData_id = rowData_id; } public static Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt); public void execute(QueueableContext context /*, String iflog_Id*/ ) { //需加一数字变量(如果获取到 html附件,其他附件,在日志中显示数量) BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, MessageGroupNumber__c, retry_cnt__c From BatchIF_Log__c Where RowDataFlg__c = true And Id = : rowData_id ]; //存放报错信息 BatchIF_Log__c iflog511Future = new BatchIF_Log__c(); iflog511Future.Type__c = 'NFM511Future'; iflog511Future.MessageGroupNumber__c = rowData.MessageGroupNumber__c; iflog511Future.Log__c = ' '; iflog511Future.ErrorLog__c = ' '; iflog511Future.RowDataFlg__c = false; // iflog511Future.AWS_Transaction_Id__c=rowData.AWS_Transaction_Id__c; insert iflog511Future; NFM511FutureController.main(rowData.Id, iflog511Future.Id, false); } @future(callout = true) public static void callout(String rowData_id, String iflog_id, boolean Manual_execution511future) { NFM511FutureController.main(rowData_id, iflog_id, false); } // @future(callout = true) //重发(把从接口获取到的数据存入日志中,再把日志中存入的数据重新JOSN解析一遍) public static void main(String rowData_id, String iflog_id, boolean Manual_execution511future) { BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, MessageGroupNumber__c, retry_cnt__c From BatchIF_Log__c Where Id = : rowData_id ]; BatchIF_Log__c iflog511Future = [select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c,Log5__c, Log6__c, Log7__c, Log8__c, MessageGroupNumber__c, retry_cnt__c From BatchIF_Log__c Where id = : iflog_id ]; // 由于检索出来的rowData和iflog为空,则进行一下判断 iflog511Future.Log__c = iflog511Future.Log__c == null ? '' : iflog511Future.Log__c; iflog511Future.ErrorLog__c = iflog511Future.ErrorLog__c == null ? '' : iflog511Future.ErrorLog__c; rowData.Log__c = rowData.Log__c == null ? '' : rowData.Log__c; rowData.ErrorLog__c = rowData.ErrorLog__c == null ? '' : rowData.ErrorLog__c; //20230909 iflog511Future.Type__c = 'NFM511Future'; iflog511Future.MessageGroupNumber__c = rowData.MessageGroupNumber__c; iflog511Future.RowDataFlg__c = false; //20230909 System.debug('+++++++NFM511+++++++iflog511Future:'+iflog511Future); System.debug('+++++++NFM511+++++++rowData:'+rowData); // String QLMDataStr = NFMUtil.QLMgetRowDataStr(rowData); String QLMDataStr = rowData.Log__c; system.debug('+++++++NFM511+++++++QLMDataStr:'+QLMDataStr); NFM511controller.AllData getQLMData1 = (NFM511controller.AllData) JSON.deserialize(QLMDataStr, NFM511controller.AllData.class); system.debug('+++++++NFM511+++++++getQLMData1:'+json.serialize(getQLMData1)); if (getQLMData1 == null) { return; } Savepoint sp = Database.setSavepoint(); //覆盖之前的数据(更新成新数据--以下三步) //1、for 遍历接口数据,做一个infoId 的list //2、通过list查招标信息;做一个Map key infoid value 招标信息id try { // 招标信息 // Map < string, List < bidInfoFile__c >> createbidInfoFileMap = new map < string, List < bidInfoFile__c >> (); // Map < String, List < Tender_information_details__c >> tempList1 = new Map < String, List < Tender_information_details__c >> (); // Map < string, Tender_information__c > updateTenderMap = new map < string, Tender_information__c > (); // Set < String > TarDetailSet = new Set < String > (); for (NFM511Controller.ListItem records: getQLMData1.data.records) { system.debug('+++++++NFM511+++++++records:'+json.serialize(records)); // 項目転送のセット ZCData__c zc = new ZCData__c(); // if (String.isBlank(records.bid)) { // iflog511Future.ErrorLog__c += 'Error! [' + records.bid + ']NotExist. This information is skipped.\n'; // continue; // } else { // zc.bid__c = records.bid; // } if (!String.isBlank(records.sfdcCode)){ zc.sfdcCode__c = records.sfdcCode; } if (!String.isBlank(records.bid)){ zc.bid__c = records.bid; } if (records.bidQuantity != null){ zc.bidQuantity__c = records.bidQuantity; } if (!String.isBlank(records.city)){ zc.city__c = records.city; } if (!String.isBlank(records.speci)){ zc.speci__c = records.speci; } if (!String.isBlank(records.contractObject)){ zc.contractObject__c = records.contractObject; } if (!String.isBlank(records.title)){ zc.title__c = records.title; } if (records.bidTotalPrice != null){ zc.bidTotalPrice__c = records.bidTotalPrice; } if (!String.isBlank(records.threeClass)){ zc.threeClass__c = records.threeClass; } if (!String.isBlank(records.projectNo)){ zc.projectNo__c = records.projectNo; } if (records.modifyTime != null){ zc.modifyTime__c = records.modifyTime; } if (!String.isBlank(records.province)){ zc.province__c = records.province; } if (!String.isBlank(records.twoClass)){ zc.twoClass__c = records.twoClass; } if (!String.isBlank(records.supplier)){ zc.supplier__c = records.supplier; } if (!String.isBlank(records.brand)){ zc.brand__c = records.brand; } if (records.bidUnitPrice != null){ zc.bidUnitPrice__c = records.bidUnitPrice; } if (records.winningDetailId != null){ zc.winningDetailId__c = records.winningDetailId; } if (records.publishTime != null){ zc.publishTime__c = records.publishTime; } if (records.projectTotalPrice != null){ zc.projectTotalPrice__c = records.projectTotalPrice; } if (!String.isBlank(records.noticeType)){ zc.noticeType__c = records.noticeType; } if (!String.isBlank(records.originalUrl)){ zc.originalUrl__c = records.originalUrl; } if (!String.isBlank(records.url)){ zc.url__c = records.url; } if (!String.isBlank(records.hostIf)){ zc.hostIf__c = records.hostIf; } if (!String.isBlank(records.brandType)){ zc.brandType__c = records.brandType; } if (records.createTime != null){ zc.createTime__c = records.createTime; } if (!String.isBlank(records.tenderee)){ zc.tenderee__c = records.tenderee; } if (!String.isBlank(records.district)){ zc.district__c = records.district; } if (!String.isBlank(records.progress)){ zc.progress__c = records.progress; } if (!String.isBlank(records.fundingSource)){ zc.fundingSource__c = records.fundingSource; } if (!String.isBlank(records.oneClass)){ zc.oneClass__c = records.oneClass; } //20240105 lt start if (!String.isBlank(records.projectJudgeId)){ zc.project_judge_id__c = records.projectJudgeId; } //20240105 lt end insert zc; if (System.Test.isRunningTest()) { throw new ControllerUtil.myException('aaa'); } } }catch (Exception ex) { // 如果数据获取过程中,有错误(同一游标,如果报错,是他重新获取一遍,如果三次都没能获取到,就发送邮件报错信息,然后手动进行获取) Database.rollback(sp); System.debug('ex.getlinenumber()------'+ex.getlinenumber()); System.debug(Logginglevel.ERROR, 'QLMData_' + rowData.MessageGroupNumber__c + ':' + ex.getMessage()); System.debug(Logginglevel.ERROR, 'QLMData_' + rowData.MessageGroupNumber__c + ':' + ex.getStackTraceString()); // logstr += '\n' + ex.getMessage(); iflog511Future.ErrorLog__c ='发生错误行数'+ ex.getlinenumber() + ':' + '511Future抛出异常:' + ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + iflog511Future.ErrorLog__c; if (!Manual_execution511future) { // NFM511Controller.againSendExceptionRequest(iflog511Future, 'NFM511Future_Count__c', rowData, '511Future抛出异常:' + ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowData.ErrorLog__c + '错误次数已经超过自动收信设定的最大次数,请手动收信'); } //System.debug(ANY o); } // update rowData; System.debug('+++++++5+++++++' + rowData); System.debug('+++++++3+++++++' + iflog511Future.Log__c); System.debug('+++++++2+++++++' + iflog511Future.ErrorLog__c); //如果存入信息超出限制,用省略号代替 if (iflog511Future.Log__c.length() > 131072) { iflog511Future.Log__c = iflog511Future.Log__c.subString(0, 131065) + ' ...'; } if (iflog511Future.ErrorLog__c.length() > 32768) { iflog511Future.ErrorLog__c = iflog511Future.ErrorLog__c.subString(0, 32760) + ' ...'; } upsert iflog511Future; } }