From cb4bae31a02af72fea30e1a57c1d498eabef5d01 Mon Sep 17 00:00:00 2001 From: 李彤 <litong@prec-tech.com> Date: 星期四, 16 三月 2023 10:17:12 +0800 Subject: [PATCH] 同步代码 --- force-app/main/default/classes/LostCancelReportOppBatch.cls | 298 +++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 179 insertions(+), 119 deletions(-) diff --git a/force-app/main/default/classes/LostCancelReportOppBatch.cls b/force-app/main/default/classes/LostCancelReportOppBatch.cls index 72442ae..8765955 100644 --- a/force-app/main/default/classes/LostCancelReportOppBatch.cls +++ b/force-app/main/default/classes/LostCancelReportOppBatch.cls @@ -31,7 +31,8 @@ // query += ' where Id in :IdList'; // } // 2022-01-18 淇敼 浠庡け鍗曟姤鍛婂彇鍊� - String query = 'SELECT Id FROM Lost_cancel_report__c WHERE Report_Status__c = \'鎵瑰噯\' AND LostType__c in (\'澶卞崟\', \'閮ㄥ垎澶卞崟\') '; + String query = 'SELECT Id, Opportunity__c FROM Lost_cancel_report__c WHERE Report_Status__c = \'鎵瑰噯\' AND LostType__c in (\'澶卞崟\', \'閮ㄥ垎澶卞崟\') '; + //20230215 lt DB202302247719 add , Opportunity__c if (start_date != null) { query += ' AND Submit_Day__c >= :start_date'; } @@ -138,148 +139,207 @@ // 2022-01-18 淇敼 浠庡け鍗曟姤鍛婂彇鍊� global void execute(Database.BatchableContext BC, List<Lost_cancel_report__c> scope) { + + // List<String> reportIdList=new List<String>();//20230215 lt DB202302247719 娉ㄩ噴 + Set<String> oppIdList = new Set<String>();//20230215 lt DB202302247719 - List<String> reportIdList=new List<String>(); for (Lost_cancel_report__c report : scope) { - reportIdList.add(report.Id); + // reportIdList.add(report.Id); //20230215 lt DB202302247719 娉ㄩ噴 + oppIdList.add(report.Opportunity__c); //20230215 lt DB202302247719 } - List<PCLLostProduct__c> pclLpList=[select - id, // 澶卞崟鍨嬪彿id - Quantity__c, // 澶卞崟鏁伴噺 - LostProductName__c, // 澶卞崟瀵规墜鍨嬪彿 - LostProductMannual__c, // 澶卞崟瀵规墜鍨嬪彿锛堟墜鍔級 - PCLLostBrand__r.Lost_By_Company__c, // 澶卞崟鍝佺墝 - PCLLostBrand__r.Lost_reason_main__c, // 澶卞崟鍘熷洜锛堜富锛� - PCLLostBrand__r.Lost_Reason_Sub__c, // 澶卞崟鍘熷洜锛堟锛� - PCLLostBrand__r.Lost_By_Company_Mannual__c, // 澶卞崟鍝佺墝锛堟墜鍔級 - PCLLostBrand__r.Agency__r.Name, // 涓爣缁忛攢鍟� - PCLLostBrand__r.AgencyMannual__c, // 涓爣缁忛攢鍟嗭紙鎵嬪姩锛� - PCLLostBrand__r.Lost_cancel_report__r.LostType__c, // 澶卞崟绫诲瀷 - PCLLostBrand__r.Lost_cancel_report__r.LostTotalAmount__c, // 澶卞崟鎬婚噾棰� - PCLLostBrand__r.Lost_cancel_report__r.TotalAmountLost__c, // 澶卞崟鎬婚噾棰濓紙涓嶅惈绋庯級 //20230215 lt DB202302247719 - PCLLostBrand__r.Lost_cancel_report__r.of_lost_system_processor__c, // 澶卞崟涓绘満鍙版暟 - PCLLostBrand__r.Lost_cancel_report__r.Opportunity__c - from - PCLLostProduct__c - where - PCLLostBrand__r.Lost_cancel_report__c in :reportIdList]; - - // 鍒濆鍖栦繚瀛樺弬鏁� - Map<String, Opportunity> opp_map = new Map<String, Opportunity>(); - Map<String, String> prod_map = new Map<String, String>(); - Map<String, String> agency_map = new Map<String, String>(); + //DB202302247719 娉ㄩ噴 lt 娉ㄩ噴鍘熷洜锛欴B202302247719璇鹃鍒峰け鍗曟姤鍛婃暟鎹彧鍒峰け鍗曢噾棰� + // List<PCLLostProduct__c> pclLpList=[select + // id, // 澶卞崟鍨嬪彿id + // Quantity__c, // 澶卞崟鏁伴噺 + // LostProductName__c, // 澶卞崟瀵规墜鍨嬪彿 + // LostProductMannual__c, // 澶卞崟瀵规墜鍨嬪彿锛堟墜鍔級 + // PCLLostBrand__r.Lost_By_Company__c, // 澶卞崟鍝佺墝 + // PCLLostBrand__r.Lost_reason_main__c, // 澶卞崟鍘熷洜锛堜富锛� + // PCLLostBrand__r.Lost_Reason_Sub__c, // 澶卞崟鍘熷洜锛堟锛� + // PCLLostBrand__r.Lost_By_Company_Mannual__c, // 澶卞崟鍝佺墝锛堟墜鍔級 + // PCLLostBrand__r.Agency__r.Name, // 涓爣缁忛攢鍟� + // PCLLostBrand__r.AgencyMannual__c, // 涓爣缁忛攢鍟嗭紙鎵嬪姩锛� + // PCLLostBrand__r.Lost_cancel_report__r.LostType__c, // 澶卞崟绫诲瀷 + // PCLLostBrand__r.Lost_cancel_report__r.LostTotalAmount__c, // 澶卞崟鎬婚噾棰� + // PCLLostBrand__r.Lost_cancel_report__r.TotalAmountLost__c, // 澶卞崟鎬婚噾棰濓紙涓嶅惈绋庯級 //20230215 lt DB202302247719 + // PCLLostBrand__r.Lost_cancel_report__r.of_lost_system_processor__c, // 澶卞崟涓绘満鍙版暟 + // PCLLostBrand__r.Lost_cancel_report__r.Opportunity__c + // from + // PCLLostProduct__c + // where + // PCLLostBrand__r.Lost_cancel_report__r.Opportunity__c in :reportIdList]; + //20230215 lt DB202302247719 PCLLostBrand__r.Lost_cancel_report__c ---update--- PCLLostBrand__r.Lost_cancel_report__r.Opportunity__c - // 寰幆鏁寸悊鏁版嵁 - for (PCLLostProduct__c lost : pclLpList) { - // 鍒ゆ柇鏄惁鍙敤鏁版嵁 - // if (String.isBlank(lost.LostProductName__c) && String.isBlank(lost.LostProductMannual__c)) { - // continue; - // } + List<Lost_cancel_report__c> lcrList = [SELECT Id, Opportunity__c, TotalAmountLost__c + FROM Lost_cancel_report__c + WHERE Opportunity__c in :oppIdList]; + //DB202302247719 娉ㄩ噴 lt 娉ㄩ噴鍘熷洜锛欴B202302247719璇鹃鍒峰け鍗曟姤鍛婃暟鎹彧鍒峰け鍗曢噾棰� + + //DB202302247719 lt start + Map<String, Opportunity> opp_map = new Map<String, Opportunity>(); + + for (Lost_cancel_report__c lcr : lcrList){ // 璇环id - String opp_id = lost.PCLLostBrand__r.Lost_cancel_report__r.Opportunity__c; + String opp_id = lcr.Opportunity__c; + // 璇环 Opportunity opp = opp_map.get(opp_id); if (opp == null) { opp = new Opportunity(); opp.Id = opp_id; - opp.of_lost_system_processor__c = 0; opp_map.put(opp_id, opp); } - // 璧嬪�� - opp.LostTypeText__c = lost.PCLLostBrand__r.Lost_cancel_report__r.LostType__c; // 澶卞崟绫诲瀷 - //opp.LostPrices__c = lost.PCLLostBrand__r.Lost_cancel_report__r.LostTotalAmount__c; // 澶卞崟閲戦 //20230215 lt DB202302247719 娉ㄩ噴 - opp.LostPrices__c = lost.PCLLostBrand__r.Lost_cancel_report__r.TotalAmountLost__c; // 澶卞崟閲戦 //20230215 lt DB202302247719 - opp.Lost_reason_main__c = lost.PCLLostBrand__r.Lost_reason_main__c; // 澶卞崟鍘熷洜锛堜富锛� - opp.Lost_Reason_Sub__c = lost.PCLLostBrand__r.Lost_Reason_Sub__c; // 澶卞崟鐞嗙敱锛堟锛� - opp.of_lost_system_processor__c += lost.Quantity__c; // 澶卞崟涓绘満鍙版暟锛堢疮鍔狅級 - // 澶卞崟浜у搧123 start - if (opp.CompetitorProduct1__c == null) { - opp.CompetitorProduct1__c = lost_product_name(lost.LostProductName__c, lost.LostProductMannual__c); - }else if (opp.CompetitorProduct2__c == null) { - opp.CompetitorProduct2__c = lost_product_name(lost.LostProductName__c, lost.LostProductMannual__c); - }else if (opp.CompetitorProduct3__c == null) { - opp.CompetitorProduct3__c = lost_product_name(lost.LostProductName__c, lost.LostProductMannual__c); + System.debug('---lt123---璇环澶卞崟閲戦---'+opp.LostPrices__c); + System.debug('---lt123---澶卞崟鎬婚噾棰濓紝鍗冨厓涓嶅惈绋�---'+lcr.TotalAmountLost__c); + if(lcr.TotalAmountLost__c != null){ + if(opp.LostPrices__c == null){ + opp.LostPrices__c = 0; + } + opp.LostPrices__c += lcr.TotalAmountLost__c; // 澶卞崟閲戦 + System.debug('---lt123---绱姞鍚庤浠峰け鍗曢噾棰�---'+opp.LostPrices__c); } - // 澶卞崟浜у搧123 end - - // 澶卞崟鍝佺墝 - opp.PCLLostBrands__c = lost_brand_name(opp.PCLLostBrands__c, lost.PCLLostBrand__r.Lost_By_Company__c, lost.PCLLostBrand__r.Lost_By_Company_Mannual__c); - - // 涓爣缁忛攢鍟� - opp.Agencies__c = lost_agency_name(opp.Agencies__c, lost.PCLLostBrand__r.Agency__r.Name, lost.PCLLostBrand__r.AgencyMannual__c); } + //DB202302247719 lt end + + //DB202302247719 娉ㄩ噴 lt 娉ㄩ噴鍘熷洜锛欴B202302247719璇鹃鍒峰け鍗曟姤鍛婃暟鎹彧鍒峰け鍗曢噾棰� + // // 鍒濆鍖栦繚瀛樺弬鏁� + // Map<String, Opportunity> opp_map = new Map<String, Opportunity>(); + // Map<String, String> prod_map = new Map<String, String>(); + // Map<String, String> agency_map = new Map<String, String>(); + + // // 寰幆鏁寸悊鏁版嵁 + // for (PCLLostProduct__c lost : pclLpList) { + // // 鍒ゆ柇鏄惁鍙敤鏁版嵁 + // // if (String.isBlank(lost.LostProductName__c) && String.isBlank(lost.LostProductMannual__c)) { + // // continue; + // // } + // // 璇环id + // String opp_id = lost.PCLLostBrand__r.Lost_cancel_report__r.Opportunity__c; + // // 璇环 + // Opportunity opp = opp_map.get(opp_id); + // if (opp == null) { + // opp = new Opportunity(); + // opp.Id = opp_id; + // opp.of_lost_system_processor__c = 0; + // opp_map.put(opp_id, opp); + // } + + // //20230215 lt DB202302247719 start + // System.debug('---lt123---璇环澶卞崟閲戦---'+opp.LostPrices__c); + // System.debug('---lt123---澶卞崟鎬婚噾棰濓紝鍗冨厓涓嶅惈绋�---'+lost.PCLLostBrand__r.Lost_cancel_report__r.TotalAmountLost__c); + + // if(lost.PCLLostBrand__r.Lost_cancel_report__r.TotalAmountLost__c != null){ + // if(opp.LostPrices__c == null){ + // opp.LostPrices__c = 0; + // } + // opp.LostPrices__c += lost.PCLLostBrand__r.Lost_cancel_report__r.TotalAmountLost__c; // 澶卞崟閲戦 + // } + + // //DB202302247719 娉ㄩ噴 lt 娉ㄩ噴鍘熷洜锛欴B202302247719璇鹃鍒峰け鍗曟姤鍛婃暟鎹彧鍒峰け鍗曢噾棰� + // // 璧嬪�� + // // opp.LostTypeText__c = lost.PCLLostBrand__r.Lost_cancel_report__r.LostType__c; // 澶卞崟绫诲瀷 + // // //opp.LostPrices__c = lost.PCLLostBrand__r.Lost_cancel_report__r.LostTotalAmount__c; // 澶卞崟閲戦 + // // opp.Lost_reason_main__c = lost.PCLLostBrand__r.Lost_reason_main__c; // 澶卞崟鍘熷洜锛堜富锛� + // // opp.Lost_Reason_Sub__c = lost.PCLLostBrand__r.Lost_Reason_Sub__c; // 澶卞崟鐞嗙敱锛堟锛� + // // opp.of_lost_system_processor__c += lost.Quantity__c; // 澶卞崟涓绘満鍙版暟锛堢疮鍔狅級 + + + // // 澶卞崟浜у搧123 start + // // if (opp.CompetitorProduct1__c == null) { + // // opp.CompetitorProduct1__c = lost_product_name(lost.LostProductName__c, lost.LostProductMannual__c); + // // }else if (opp.CompetitorProduct2__c == null) { + // // opp.CompetitorProduct2__c = lost_product_name(lost.LostProductName__c, lost.LostProductMannual__c); + // // }else if (opp.CompetitorProduct3__c == null) { + // // opp.CompetitorProduct3__c = lost_product_name(lost.LostProductName__c, lost.LostProductMannual__c); + // // } + // // 澶卞崟浜у搧123 end + + // // 澶卞崟鍝佺墝 + // // opp.PCLLostBrands__c = lost_brand_name(opp.PCLLostBrands__c, lost.PCLLostBrand__r.Lost_By_Company__c, lost.PCLLostBrand__r.Lost_By_Company_Mannual__c); + + // // 涓爣缁忛攢鍟� + // // opp.Agencies__c = lost_agency_name(opp.Agencies__c, lost.PCLLostBrand__r.Agency__r.Name, lost.PCLLostBrand__r.AgencyMannual__c); + // //DB202302247719 娉ㄩ噴 lt + // //20230215 lt DB202302247719 end + + // } + //DB202302247719 娉ㄩ噴 lt 娉ㄩ噴鍘熷洜锛欴B202302247719璇鹃鍒峰け鍗曟姤鍛婃暟鎹彧鍒峰け鍗曢噾棰� System.debug(opp_map); + StaticParameter.EscapeOppandStaTrigger = true; //20230215 lt DB202302247719 update opp_map.values(); + StaticParameter.EscapeOppandStaTrigger = true; //20230215 lt DB202302247719 } + //DB202302247719 娉ㄩ噴 lt 娉ㄩ噴鍘熷洜锛欴B202302247719璇鹃鍒峰け鍗曟姤鍛婃暟鎹彧鍒峰け鍗曢噾棰� // 澶卞崟瀵规墜鍨嬪彿 - private String lost_product_name(String lost_product, String lost_product_mannual) { - if (String.isBlank(lost_product) && String.isNotBlank(lost_product_mannual)) { - return lost_product_mannual; - } - return lost_product; - } + // private String lost_product_name(String lost_product, String lost_product_mannual) { + // if (String.isBlank(lost_product) && String.isNotBlank(lost_product_mannual)) { + // return lost_product_mannual; + // } + // return lost_product; + // } - // 澶卞崟鍝佺墝 - private String lost_brand_name(String lost_brand_in_opp, String lost_brand, String lost_brand_mannual) { - // 鍒濆鍖栧弬鏁� - String plus = ''; - // 鍒ゆ柇 - // SWAG-CCC6F6 2022-04-22 ssm start - // 璇环涓婇兘鍙樉绀洪�夐」鍒楄〃鐨勫�硷紝涓嶉渶瑕佹墜鍔ㄧ殑鍊� - // if ('鍏朵粬'.equals(lost_brand) && String.isNotBlank(lost_brand_mannual)) { - // plus = lost_brand_mannual; - // } else { - // plus = lost_brand; - // } - plus = lost_brand; - // SWAG-CCC6F6 2022-04-22 ssm end - // 鍒濆鍖栬繑鍥炲�� - if (String.isBlank(lost_brand_in_opp)) { - lost_brand_in_opp = ''; - } - // 鎷兼帴 - if (String.isNotBlank(plus) && !lost_brand_in_opp.contains(plus)) { - // 澧炲姞鍒嗛殧鏍囪瘑 - if (String.isNotBlank(lost_brand_in_opp)) { - lost_brand_in_opp += ','; - } - lost_brand_in_opp += plus; - } - return lost_brand_in_opp; - } + // // 澶卞崟鍝佺墝 + // private String lost_brand_name(String lost_brand_in_opp, String lost_brand, String lost_brand_mannual) { + // // 鍒濆鍖栧弬鏁� + // String plus = ''; + // // 鍒ゆ柇 + // // SWAG-CCC6F6 2022-04-22 ssm start + // // 璇环涓婇兘鍙樉绀洪�夐」鍒楄〃鐨勫�硷紝涓嶉渶瑕佹墜鍔ㄧ殑鍊� + // // if ('鍏朵粬'.equals(lost_brand) && String.isNotBlank(lost_brand_mannual)) { + // // plus = lost_brand_mannual; + // // } else { + // // plus = lost_brand; + // // } + // plus = lost_brand; + // // SWAG-CCC6F6 2022-04-22 ssm end + // // 鍒濆鍖栬繑鍥炲�� + // if (String.isBlank(lost_brand_in_opp)) { + // lost_brand_in_opp = ''; + // } + // // 鎷兼帴 + // if (String.isNotBlank(plus) && !lost_brand_in_opp.contains(plus)) { + // // 澧炲姞鍒嗛殧鏍囪瘑 + // if (String.isNotBlank(lost_brand_in_opp)) { + // lost_brand_in_opp += ','; + // } + // lost_brand_in_opp += plus; + // } + // return lost_brand_in_opp; + // } - // 涓爣缁忛攢鍟� - private String lost_agency_name(String lost_agency_in_opp, String lost_agency, String lost_agency_mannual) { - // 鍒濆鍖栧弬鏁� - String plus = ''; - // 鍒ゆ柇 - // SWAG-CCC6F6 2022-04-22 ssm start - // 璇环涓婇兘鍙樉绀洪�夐」鍒楄〃鐨勫�硷紝涓嶉渶瑕佹墜鍔ㄧ殑鍊� - // if ('瀵规墜缁忛攢鍟�'.equals(lost_agency) && String.isNotBlank(lost_agency_mannual)) { - // plus = lost_agency_mannual; - // } else { - // plus = lost_agency; - // } - plus = lost_agency; - // SWAG-CCC6F6 2022-04-22 ssm end - // 鍒濆鍖栬繑鍥炲�� - if (String.isBlank(lost_agency_in_opp)) { - lost_agency_in_opp = ''; - } - // 鎷兼帴 - if (String.isNotBlank(plus) && !lost_agency_in_opp.contains(plus)) { - // 澧炲姞鍒嗛殧鏍囪瘑 - if (String.isNotBlank(lost_agency_in_opp)) { - lost_agency_in_opp += ','; - } - lost_agency_in_opp += plus; - } - return lost_agency_in_opp; - } + // // 涓爣缁忛攢鍟� + // private String lost_agency_name(String lost_agency_in_opp, String lost_agency, String lost_agency_mannual) { + // // 鍒濆鍖栧弬鏁� + // String plus = ''; + // // 鍒ゆ柇 + // // SWAG-CCC6F6 2022-04-22 ssm start + // // 璇环涓婇兘鍙樉绀洪�夐」鍒楄〃鐨勫�硷紝涓嶉渶瑕佹墜鍔ㄧ殑鍊� + // // if ('瀵规墜缁忛攢鍟�'.equals(lost_agency) && String.isNotBlank(lost_agency_mannual)) { + // // plus = lost_agency_mannual; + // // } else { + // // plus = lost_agency; + // // } + // plus = lost_agency; + // // SWAG-CCC6F6 2022-04-22 ssm end + // // 鍒濆鍖栬繑鍥炲�� + // if (String.isBlank(lost_agency_in_opp)) { + // lost_agency_in_opp = ''; + // } + // // 鎷兼帴 + // if (String.isNotBlank(plus) && !lost_agency_in_opp.contains(plus)) { + // // 澧炲姞鍒嗛殧鏍囪瘑 + // if (String.isNotBlank(lost_agency_in_opp)) { + // lost_agency_in_opp += ','; + // } + // lost_agency_in_opp += plus; + // } + // return lost_agency_in_opp; + // } + //DB202302247719 娉ㄩ噴 lt 娉ㄩ噴鍘熷洜锛欴B202302247719璇鹃鍒峰け鍗曟姤鍛婃暟鎹彧鍒峰け鍗曢噾棰� global void finish(Database.BatchableContext BC) { -- Gitblit v1.9.1