Li Jun
2022-03-28 f5a94e721ae5a26f817f0df75065b64f1f192eb3
force-app/main/default/classes/NFM501FutureController.cls
@@ -3,32 +3,56 @@
    //先定义
    //    投标截止时间
    // 2021/01/04 18:00
    //add by sushanhu for pi 20220310 start
    public  String txId;
    //add by sushanhu for pi 20220310 end
    public String rowData_id;
    public NFM501FutureController(String rowData_id) {
        this.rowData_id = rowData_id;
    }
     //add by sushanhu for pi 20220310 start
    //  public NFM501FutureController(String rowData_id,String txId) {
    //      this.rowData_id = rowData_id;
    //     this.txId = txId;
    //  }
     //add by sushanhu for pi 20220310 end
    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,
            Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c,
            Log12__c, MessageGroupNumber__c, retry_cnt__c, NFM501Future_Count__c,
            NFM501_Web_Annex_Count__c
            NFM501_Web_Annex_Count__c,
            AWS_Transaction_Id__c //ADD BY SUSHANHU for pi 20220310
            from BatchIF_Log__c where RowDataFlg__c = true and Id = : rowData_id
        ];
        //存放报错信息
        //add by sushanhu for pipl 20220311 start
        system.debug('txId from log'+rowData.AWS_Transaction_Id__c);
        if (!String.isEmpty(rowData.AWS_Transaction_Id__c)) {
            txId =rowData.AWS_Transaction_Id__c; //add by sushanhu for pipl 20220310
        }else {
            system.debug('txId from NF501'+txId);
        }
         //add by sushanhu for pipl 20220311 end
        system.debug('nfm501future awsid'+txId);
        BatchIF_Log__c iflog501Future = new BatchIF_Log__c();
        iflog501Future.Type__c = 'NFM501';
        iflog501Future.MessageGroupNumber__c = rowData.MessageGroupNumber__c;
        iflog501Future.Log__c = ' ';
        iflog501Future.ErrorLog__c = ' ';
        iflog501Future.RowDataFlg__c = false;
        iflog501Future.AWS_Transaction_Id__c=rowData.AWS_Transaction_Id__c;
        insert iflog501Future;
        NFM501FutureController.main(rowData.Id, iflog501Future.Id, false);
        NFM501FutureController.main(rowData.Id, iflog501Future.Id, false,txId);
    }
    @future(callout = true)
    //重发(把从接口获取到的数据存入日志中,再把日志中存入的数据重新JOSN解析一遍)
    public static void main(String rowData_id, String iflog_id, boolean Manual_execution501future) {
    public static void main(String rowData_id, String iflog_id, boolean Manual_execution501future,
                                String txId //增加事务id forpipl 20220310
            ) {
        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, Log9__c, Log10__c, Log11__c,
            Log12__c, MessageGroupNumber__c, retry_cnt__c, NFM501Future_Count__c,
@@ -49,9 +73,12 @@
        String QLMDataStr = NFMUtil.QLMgetRowDataStr(rowData);
        NFM501controller.AllData getQLMData1 = (NFM501controller.AllData)
        JSON.deserialize(QLMDataStr, NFM501controller.AllData.class);
        if (getQLMData1 == null) {
            return;
        }
        List<PIHelper.IdList> idList = new List<PIHelper.IdList>();//存储更新后得sfid和awsid add by sushanhu 20220310
        PIHelper.PIIntegration NFM501AWS =PIHelper.getPIIntegrationInfo('QLMNFM501'); //add by sushanhu 20220310
        Savepoint sp = Database.setSavepoint();
        //IF转换表(为实现选项列表的下拉选项)
        Map < String, String > transferMap = new Map < String, String > ();
@@ -95,7 +122,8 @@
            SumUnit__c, AreaCity__c, AreaCountry__c, AgentUnit1__c,
            AgentUnit2__c, AgentUnit3__c, AgentUnit4__c, AgentUnit5__c,
            ZhaoRelationName__c, ZhongRelationName__c,
            publicDate__c, noticeDate__c, ResultDate__c
            publicDate__c, noticeDate__c, ResultDate__c,
            AWS_Data_Id__c //ADD FOR pi SUSHANHU 20220311
            FROM Tender_information__c Where ProjectId__c in : projectIdList
        ];
        Map < String, Tender_information__c > TenMap = new Map < String, Tender_information__c > ();
@@ -122,15 +150,24 @@
            tempbidInfoFileURLList.add(bidInfoFile.infoAddress__c);
            SelectbidInfoFileMap.put(bidInfoFile.Tender_information__r.ProjectId__c, tempbidInfoFileURLList);
        }
        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 (NFM501Controller.ListItem LI: getQLMData1.data.list1) {
                // 項目転送のセット
                Tender_information__c te1 = new Tender_information__c();
                //add aws dataid sushanhu 20220223 start
                if(String.isEmpty(LI.DataId)){
                    continue;
                }
                te1.AWS_Data_Id__c = LI.DataId;
                //add aws dataid sushanhu 20220223 end
                if (String.isBlank(LI.projectId)) {
                    iflog501Future.ErrorLog__c += 'Error! [' + LI.projectId + ']NotExist. This information is skipped.\n';
                    continue;
@@ -183,6 +220,9 @@
                //拼接字符串
                if (LI.ZhaoRelationWay != null && LI.ZhaoRelationWay.size() > 0) {
                    te1.ZhaoRelationWay__c = String.join(LI.ZhaoRelationWay, ',');
                     //add 密文 sushanhu 20220223 start
                     te1.ZhaoRelationWay_Encrypted__c =String.join(LI.ZhaoRelationWayEncrypted,',');
                     //add 密文 sushanhu 20220223 end
                }
                //转换表(选项列表的下拉选项)
                te1.IsElectronic__c = NFMUtil.getMapValue(transferMap, 'IsElectronic__c', LI.isElectronic, iflog501Future);
@@ -283,6 +323,9 @@
                }
                if (LI.AgentRelationWay != null && LI.AgentRelationWay.size() > 0) {
                    te1.AgentRelationWay__c = String.join(LI.AgentRelationWay, ',');
                    //add 密文 sushanhu 20220223 start
                    te1.AgentRelationWay_Encrypted__c =String.join(LI.AgentRelationWayEncrypted,',');
                    //add 密文 sushanhu 20220223 end
                }
                // 将改附件存入招投标项目子对象中
                if (LI.InfoFile != null && LI.InfoFile.size() > 0) {
@@ -327,6 +370,9 @@
                }
                if (LI.AgentRelationName != null && LI.AgentRelationName.size() > 0) {
                    te1.AgentRelationName__c = String.join(LI.AgentRelationName, ',');
                    //add 密文 sushanhu 20220223 start
                    te1.AgentRelationName_Encrypted__c =String.join(LI.AgentRelationNameEncrypted,',');
                    //add 密文 sushanhu 20220223 end
                }
                if (String.isNotBlank(LI.bidingEndTime)) {
                    te1.BidingEndTime__c = Datetime.valueOf(LI.bidingEndTime);
@@ -355,6 +401,9 @@
                }
                if (LI.ZhongRelationWay != null && LI.ZhongRelationWay.size() > 0) {
                    te1.ZhongRelationWay__c = String.join(LI.ZhongRelationWay, ',');
                    //add 密文 sushanhu 20220223 start
                    te1.ZhongRelationWay_Encrypted__c =String.join(LI.ZhongRelationWayEncrypted,',');
                    //add 密文 sushanhu 20220223 end
                }
                if (String.isNotBlank(LI.bidingAcquireTime)) {
                    te1.BidingAcquireTime__c = Datetime.valueOf(LI.bidingAcquireTime);
@@ -462,10 +511,18 @@
                }
                if (LI.ZhaoRelationName != null && LI.ZhaoRelationName.size() > 0) {
                    te1.ZhaoRelationName__c = String.join(LI.ZhaoRelationName, ',');
                    //add 密文 sushanhu 20220223 start
                    te1.ZhaoRelationName_Encrypted__c =String.join(LI.ZhaoRelationNameEncrypted,',');
                    //add 密文 sushanhu 20220223 end
                }
                if (LI.ZhongRelationName != null && LI.ZhongRelationName.size() > 0) {
                    te1.ZhongRelationName__c = String.join(LI.ZhaoRelationName, ',');
                     //add 密文 sushanhu 20220223 start
                     te1.ZhongRelationName_Encrypted__c =String.join(LI.ZhongRelationNameEncrypted,',');
                     //add 密文 sushanhu 20220223 end
                }
                //精琢科技   zxk   2021-11-11  SWAG-C637NF   start
                // 如果第一次项目阶段就传来变更状态的话,那么就不生成招投标项目(由于变更阶段项目名称传来为空,为了不让项目名自动赋值为Id)
                if (String.isNotBlank(te1.InfoType__c) && String.isNotBlank(LI.projectId)) {
@@ -499,8 +556,16 @@
            System.debug('123456789123456789:' + updateTenderMap);
            //将招标信息和招标信息详情关联起来(通过ProjectId这一唯一标识)
            Map < string, Tender_information__c > TenderMap = new map < string, Tender_information__c > ();
            for (Tender_information__c TMap: updateTenderMap.values()) {
                system.debug('TMap---'+JSON.serialize(TMap));
                TenderMap.put(TMap.ProjectId__c, TMap);
                PIHelper.IdList il= new PIHelper.IdList();
                // add for pipl  sushanhu 20220310 start
                il.awsId =TMap.AWS_Data_Id__c;
                il.sfRecordId=TMap.Id;
                idList.add(il);
                // add for pipl  sushanhu 20220310 end
            }
            System.debug('12345678!!!!!' + TenderMap.values());
            List < Tender_information_details__c > TenList = new List < Tender_information_details__c > ();
@@ -537,9 +602,17 @@
            if (System.Test.isRunningTest()) {
                throw new ControllerUtil.myException('aaa');
            }
            //确认事务 add for pi sushanhu 20220310 start
            // PIHelper.confirmTrans('NFM501',1,null,txId,NFM501AWS.token,NFM501AWS.transactionURL,idList);
            PIHelper.insertConfirmTrans('NFM501',1,null,txId,1,NFM501AWS.transactionURL,idList);
            //确认事务 add for pi sushanhu 20220310 end
        } catch (Exception ex) {
            // 如果数据获取过程中,有错误(同一游标,如果报错,是他重新获取一遍,如果三次都没能获取到,就发送邮件报错信息,然后手动进行获取)
            Database.rollback(sp);
            //确认事务 add for pi sushanhu 20220310 start
            // PIHelper.confirmTrans('NFM501',0,null,txId,NFM501AWS.token,NFM501AWS.transactionURL,idList);
            PIHelper.insertConfirmTrans('NFM501',0,null,txId,1,NFM501AWS.transactionURL,idList);
            //确认事务 add for pi sushanhu 20220310 end
            System.debug(Logginglevel.ERROR, 'QLMData_' + rowData.MessageGroupNumber__c + ':' + ex.getMessage());
            System.debug(Logginglevel.ERROR, 'QLMData_' + rowData.MessageGroupNumber__c + ':' + ex.getStackTraceString());
            // logstr += '\n' + ex.getMessage();