From ca54382924f5a27063eabbc5b2a81b3d44496b58 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期四, 14 四月 2022 15:30:59 +0800
Subject: [PATCH] PIPLController0414

---
 force-app/main/default/classes/SSOpportunityBatch.cls |  132 +++++++++++--------------------------------
 1 files changed, 35 insertions(+), 97 deletions(-)

diff --git a/force-app/main/default/classes/SSOpportunityBatch.cls b/force-app/main/default/classes/SSOpportunityBatch.cls
index 9044e7f..2200912 100644
--- a/force-app/main/default/classes/SSOpportunityBatch.cls
+++ b/force-app/main/default/classes/SSOpportunityBatch.cls
@@ -1,5 +1,5 @@
 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;
 
@@ -36,13 +36,13 @@
             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;
@@ -76,17 +76,6 @@
         } else {
 // SS_Prospect_5days_list__c  銇璞°亱銇┿亞銇嬨�乴oop銇腑鍗樼嫭鍒ゆ柇
 //            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);
@@ -97,7 +86,10 @@
         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) {
@@ -107,11 +99,14 @@
                 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));
@@ -129,17 +124,23 @@
                     }
                 }
             }
+            system.debug('===================222222222'+insSSOpp);
             if (updSelfFlg) {
                 updSelfList.add(opp);
             }
+            system.debug(updSelfList);
             // SS_Prospect_5days_list__c  銇璞°亱銇┿亞銇嬨�乴oop銇腑鍗樼嫭鍒ゆ柇
             //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 銈堛倞鐢熸垚
@@ -164,72 +165,41 @@
                     }
                 }
             }
+            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';
@@ -241,36 +211,4 @@
         }
         update iflog;
     }
-
-    //wangweipeng  20210618  濡傛灉update澶辫触,閲嶅鏇存柊锛屾渶澶�3娆★紝濡傛灉澶辫触璁板綍鏃ュ織  start 
-    //鍙傛暟锛歶pdSelfList   瑕侀噸鏂版彃鍏ョ殑鏁版嵁     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
 }
\ No newline at end of file

--
Gitblit v1.9.1