| | |
| | | public without sharing class SSOpportunityBatch implements Database.Batchable<SObject>, Database.Stateful { |
| | | public static Integer FIELDMAX = 200; |
| | | public static Integer FIELDMAX = 30; |
| | | private final List<Id> TEST_ID = null; |
| | | private BatchIF_Log__c iflog; |
| | | |
| | |
| | | String fieldPath = fieldPathList[i]; |
| | | if (i == fieldPathList.size() - 1) { |
| | | rtn = sobj.get(fieldPath); |
| | | System.debug(rtn + '= sobj.get(' + fieldPath + ')'); |
| | | System.debug(rtn + '=*** sobj.get(' + fieldPath + ')'); |
| | | } else { |
| | | sobj = sobj.getSObject(fieldPath); |
| | | if (sobj == null) { |
| | | break; |
| | | } |
| | | System.debug(sobj + '= sobj.getSObject(' + fieldPath + ')'); |
| | | System.debug(sobj + '=### sobj.getSObject(' + fieldPath + ')'); |
| | | } |
| | | } |
| | | return rtn; |
| | |
| | | } else { |
| | | // SS_Prospect_5days_list__c の対象かどうか、loopの中単独判断 |
| | | // soql += ' where StageName = \'引合\''; |
| | | |
| | | // CHAN-AUE3TB Batch SSOpportunity的执行数据筛选 |
| | | Date nowDay = Date.today(); |
| | | nowDay = nowDay.addDays(-15); |
| | | Integer iyear = nowDay.year(); |
| | | if (nowDay.month() < 4) { |
| | | iyear -= 1; |
| | | } |
| | | Date thisYd = Date.valueOf(iyear + '-4-1'); |
| | | soql += ' where StageName = \'引合\' or StageName = \'注残\' or StageName = \'出荷\' or ((StageName = \'完了\' or StageName = \'削除\' or StageName = \'敗戦\') and SFDCLast_Process_Date__c >= :thisYd)'; |
| | | soql += ' or (StageName = \'完了\' and Shipping_Finished_Day_Func__c >= :thisYd)'; |
| | | } |
| | | System.debug('soql=' + soql); |
| | | return Database.getQueryLocator(soql); |
| | |
| | | List<SObject> insSSOppList = new List<SObject>(); |
| | | List<Id> insSSOppId = new List<Id>(); |
| | | List<SObject> insSSOliList = new List<SObject>(); |
| | | //20161205Add |
| | | Map<id,id> SSBDreportToSSodp = new Map<id,id>(); |
| | | // 商談 |
| | | system.debug('===================111111111'); |
| | | SS_Batch_Column_Mapping__c oppMapping = SS_Batch_Column_Mapping__c.getValues('Opportunity'); |
| | | Schema.SObjectType ssOppType = Schema.getGlobalDescribe().get(String.valueOf(oppMapping.get('SS_TableName__c'))); |
| | | for (Opportunity opp : oppList) { |
| | |
| | | String lpadI = ('00' + i).right(3); |
| | | String fromColumn = 'From_Column_' + lpadI + '__c'; |
| | | String apiStr = String.valueOf(oppMapping.get(fromColumn)); |
| | | system.debug('======8888'+String.isBlank(apiStr)); |
| | | if (String.isBlank(apiStr) == false) { |
| | | String ssColumn = 'SS_Column_' + lpadI + '__c'; |
| | | String ssApiStr = String.valueOf(oppMapping.get(ssColumn)); |
| | | system.debug('===================77777'+ssApiStr.toLowerCase().startsWith('opportunity.')+ssApiStr.toLowerCase()); |
| | | if (ssApiStr.toLowerCase().startsWith('opportunity.')) { |
| | | // 商談の項目を更新、変更があるかどうか判断する |
| | | system.debug('===================5555'+opp.get(ssApiStr.substring(12)) +'^^^^^^'+ opp.get(apiStr)); |
| | | if (opp.get(ssApiStr.substring(12)) != opp.get(apiStr)) { |
| | | try { |
| | | opp.put(ssApiStr.substring(12), opp.get(apiStr)); |
| | |
| | | } |
| | | } |
| | | } |
| | | system.debug('===================222222222'+insSSOpp); |
| | | if (updSelfFlg) { |
| | | updSelfList.add(opp); |
| | | } |
| | | system.debug(updSelfList); |
| | | // SS_Prospect_5days_list__c の対象かどうか、loopの中単独判断 |
| | | //if (opp.StageName == '引合') { |
| | | if (opp.StageName == '引合' || opp.StageName == '注残' || opp.StageName == '出荷' || opp.StageName == '完了' || opp.StageName == '削除') { |
| | | insSSOppList.add(insSSOpp); |
| | | insSSOppId.add(opp.Id); |
| | | } |
| | | |
| | | //} |
| | | } |
| | | |
| | | insert insSSOppList; |
| | | system.debug('===================888888888'+insSSOppList[0].id); |
| | | for(integer i = 0; i< insSSOppList.size();i++){ |
| | | SSBDreportToSSodp.put(insSSOppId[i],insSSOppList[i].id); |
| | | } |
| | | // 商談商品 |
| | | SS_Batch_Column_Mapping__c oliMapping = SS_Batch_Column_Mapping__c.getValues('OpportunityLineItem'); |
| | | // select項目を oliMapping より生成 |
| | |
| | | } |
| | | } |
| | | } |
| | | insSSOli.put('SSBD_All_Report_ID__c', SSBDreportToSSodp.get(oli.ID_test1__c)); |
| | | System.debug('insSSOli:' + insSSOli); |
| | | } |
| | | |
| | | if (Oly_TriggerHandler.isBypassed('PowerBIBaseHandler') == false) { |
| | | Oly_TriggerHandler.bypass('PowerBIBaseHandler'); |
| | | } |
| | | |
| | | |
| | | // エラーをlogに書き出す |
| | | if (updSelfList.size() > 0) { |
| | | System.debug('updSelfList:' + updSelfList); |
| | | Database.SaveResult[] lsr = Database.update(updSelfList, false); |
| | | List<Opportunity> reuseUpdateList = new List<Opportunity>(); |
| | | for (Integer tIdx = 0; tIdx < lsr.size(); tIdx++) { |
| | | Database.SaveResult sr = lsr[tIdx]; |
| | | System.debug('sr.isSuccess:' + sr.isSuccess()); |
| | | if (!sr.isSuccess()) { |
| | | //wangweipeng 20210618 获取没有update的数据 |
| | | reuseUpdateList.add(updSelfList[tIdx]); |
| | | |
| | | |
| | | /*Database.Error emsg = sr.getErrors()[0]; |
| | | //update by Gzw 2020-10-30 start |
| | | if (!String.valueOf(emsg.getStatusCode()).contains('INACTIVE_OWNER_OR_USER')) { |
| | | iflog.ErrorLog__c += 'ERROR ' + updSelfList[tIdx].Opportunity_No__c + ' Opportunity:' + emsg + '\n'; |
| | | } |
| | | // iflog.ErrorLog__c += 'ERROR ' + updSelfList[tIdx].Opportunity_No__c + ' Opportunity:' + emsg + '\n'; |
| | | //update by Gzw 2020-10-30 end |
| | | */ |
| | | Database.Error emsg = sr.getErrors()[0]; |
| | | iflog.ErrorLog__c += 'ERROR Opportunity:' + emsg + '\n'; |
| | | } |
| | | } |
| | | |
| | | //wangweipeng 20210618 如果update失败,重复更新,最多3次,如果失败记录日志 start |
| | | if(reuseUpdateList != null && reuseUpdateList.size() > 0){ |
| | | reuseUpdate(reuseUpdateList,1); |
| | | } |
| | | //wangweipeng 20210618 如果update失败,重复更新,最多3次,如果失败记录日志 end |
| | | } |
| | | |
| | | //insert insSSOppList; |
| | | Database.SaveResult[] lsr2 = Database.insert(insSSOppList, false); |
| | | for (Integer tIdx = 0; tIdx < lsr2.size(); tIdx++) { |
| | | Database.SaveResult sr = lsr2[tIdx]; |
| | | if (!sr.isSuccess()) { |
| | | Database.Error emsg = sr.getErrors()[0]; |
| | | //update by rentx 2020-10-27 start |
| | | if (!String.valueOf(emsg.getStatusCode()).contains('INACTIVE_OWNER_OR_USER')) { |
| | | iflog.ErrorLog__c += 'ERROR ' + insSSOppList[tIdx].get('Opportunity_No__c') + ' SS_opp:' + emsg + '\n'; |
| | | } |
| | | //update by rentx 2020-10-27 end |
| | | // iflog.ErrorLog__c += 'ERROR ' + insSSOppList[tIdx].get('Opportunity_No__c') + ' SS_opp:' + emsg + '\n'; |
| | | } |
| | | } |
| | | //insert insSSOliList; |
| | | Database.SaveResult[] lsr3 = Database.insert(insSSOliList, false); |
| | | for (Integer tIdx = 0; tIdx < lsr3.size(); tIdx++) { |
| | | Database.SaveResult sr = lsr3[tIdx]; |
| | | if (!sr.isSuccess()) { |
| | | Database.Error emsg = sr.getErrors()[0]; |
| | | iflog.ErrorLog__c += 'ERROR ' + insSSOliList[tIdx].get('Opportunity_number__c') + ' SS_oli:' + emsg + '\n'; |
| | | } |
| | | } |
| | | |
| | | |
| | | insert insSSOliList; |
| | | //SSBD_ALL_Report to |
| | | //************************************************************************************************************** |
| | | // |
| | | //************************************************************************************************************** |
| | | //************************************************************************************************************** |
| | | // |
| | | //************************************************************************************************************** |
| | | |
| | | } |
| | | |
| | | public void finish(Database.BatchableContext BC) { |
| | | |
| | | if (Test.isRunningTest() == false && TEST_ID == null) { |
| | | Database.executeBatch(new SSBackorderBatch(null), 100); |
| | | // Database.executeBatch(new SSOpporToSSBDallRepBatch(), 100); |
| | | } |
| | | |
| | | iflog.Log__c += '\nSSOpportunityBatch end'; |
| | |
| | | } |
| | | update iflog; |
| | | } |
| | | |
| | | //wangweipeng 20210618 如果update失败,重复更新,最多3次,如果失败记录日志 start |
| | | //参数:updSelfList 要重新插入的数据 indexUpdate 第几次插入 |
| | | public void reuseUpdate(List<Opportunity> updSelfList,Integer indexUpdate){ |
| | | System.debug('这是此方法走的第:'+indexUpdate+' 次了。'); |
| | | Database.SaveResult[] lsr = Database.update(updSelfList, false); |
| | | List<Opportunity> reuseUpdateList = new List<Opportunity>(); |
| | | for (Integer tIdx = 0; tIdx < lsr.size(); tIdx++) { |
| | | Database.SaveResult sr = lsr[tIdx]; |
| | | if (!sr.isSuccess()) { |
| | | if(indexUpdate >= 3){ |
| | | Database.Error emsg = sr.getErrors()[0]; |
| | | //update by Gzw 2020-10-30 start |
| | | if (!String.valueOf(emsg.getStatusCode()).contains('INACTIVE_OWNER_OR_USER')) { |
| | | iflog.ErrorLog__c += 'ERROR ' + updSelfList[tIdx].Opportunity_No__c + ' Opportunity:' + emsg + '\n'; |
| | | } |
| | | // iflog.ErrorLog__c += 'ERROR ' + updSelfList[tIdx].Opportunity_No__c + ' Opportunity:' + emsg + '\n'; |
| | | //update by Gzw 2020-10-30 end |
| | | }else{ |
| | | //获取没有update的数据 |
| | | reuseUpdateList.add(updSelfList[tIdx]); |
| | | } |
| | | } |
| | | } |
| | | if(indexUpdate < 3){ |
| | | indexUpdate ++; |
| | | if(reuseUpdateList != null && reuseUpdateList.size() > 0){ |
| | | reuseUpdate(reuseUpdateList,indexUpdate); |
| | | } |
| | | } |
| | | } |
| | | //wangweipeng 20210618 如果update失败,重复更新,最多3次,如果失败记录日志 end |
| | | } |