public without sharing class OpportunityLineItemTriggerHandler { public static void updateForDealer(List newList, Map newMap, List oldList, Map oldMap) { // if(StaticParameter.StageProgressBarUpdate){ // return; // } OpportunityLineItemTriggerHandler.test(); List pIdList = new List(); List oIdList = new List(); for (OpportunityLineItem newOli : newList) { OpportunityLineItem oldOli = oldMap == null ? new OpportunityLineItem() : oldMap.get(newOli.Id); if (newOli.Product2Id != oldOli.Product2Id) { pIdList.add(newOli.Product2Id); oIdList.add(newOli.OpportunityId); } } system.debug('=====pIdList:' + pIdList); system.debug('=====oIdList:' + oIdList); Map psMap = new Map(); if (pIdList.size() > 0) { List psList = [select id, Product__c from Product_Search__c where Product__c = :pIdList]; for (Product_Search__c ps : psList) { psMap.put(ps.Product__c, ps.Id); } } system.debug('=====psMap:' + psMap); Map oppMap = new Map(); if (oIdList.size() > 0) { List oppList = [select id, SyncedQuoteId from Opportunity where id = :oIdList]; for (Opportunity opp : oppList) { oppMap.put(opp.Id, opp.SyncedQuoteId); } } system.debug('=====oppMap:' + oppMap); for (OpportunityLineItem newOli : newList) { system.debug('20190507____' + newOli); OpportunityLineItem oldOli = oldMap == null ? new OpportunityLineItem() : oldMap.get(newOli.Id); if (UserInfo.getUserType() != 'PowerPartner' || oppMap.get(newOli.OpportunityId) != null) { if (newOli.Quantity != oldOli.Quantity) { newOli.QuantityD__c = newOli.Quantity; } if (newOli.UnitPrice != oldOli.UnitPrice) { newOli.UnitPriceD__c = newOli.UnitPrice; } if (newOli.Description != oldOli.Description) { newOli.DescriptionD__c = newOli.Description; } if (newOli.Product2Id != oldOli.Product2Id) { system.debug('=====Product2Id:' + newOli.Product2Id); system.debug('=====OpportunityId;:' + newOli.OpportunityId); newOli.Product_Search__c = psMap.get(newOli.Product2Id); } } } } public static void setTextField(List newList, Map newMap, List oldList, Map oldMap) { // if(StaticParameter.StageProgressBarUpdate){ // return; // } OpportunityLineItemTriggerHandler.test(); for (OpportunityLineItem newOli : newList) { system.debug('!!!!!!!!!'+newOli.product_Description__c); OpportunityLineItem oldOli = oldMap == null ? new OpportunityLineItem() : oldMap.get(newOli.Id); if (newOli.Product2Id != oldOli.Product2Id) { newoli.Is_product_model_text__c = newoli.Is_product_model__c; } if(newOli.DescriptionD__c == null || newOli.DescriptionD__c == ''){ newOli.DescriptionD__c = newoli.product_Description__c; } if(newOli.Description == null || newOli.Description == ''){ newOli.Description = newoli.product_Description__c; } } } public static void SetProduct2Mark(List newList, Map newMap, List oldList, Map oldMap) { // if(StaticParameter.StageProgressBarUpdate){ // return; // } //XHL-20190510-AddStart OpportunityLineItemTriggerHandler.test(); //获取询价的Id List oIdList = new List(); for (OpportunityLineItem newOli : newList) { oIdList.add(newOli.OpportunityId); } //根据询价的Id,查找该询价中同步的报价 Map oppMap = new Map(); List syncedQuoteIdList = new List(); List oppList = new List(); if (oIdList.size() >0) { oppList = [select id, SyncedQuoteId,ProductSegment__c from Opportunity where id = :oIdList]; for (Opportunity opp : oppList) { if ( String.isNotBlank(opp.SyncedQuoteId)) { oppMap.put(opp.Id, opp.SyncedQuoteId); syncedQuoteIdList.add(opp.SyncedQuoteId); } } } List opportunityLineItemList = new List(); if (syncedQuoteIdList.size() > 0) { //根据同步的报价Id,获取询价行项目的Id,以及报价产品的分类 Map oliIdAndSingleProductMap = new Map(); List quoteLineItemList = [ select Id,OpportunityLineItemId__c,SingleProduct__c,Set__c,SetName__c from QuoteLineItem where QuoteId In :syncedQuoteIdList]; for (QuoteLineItem qli : quoteLineItemList) { oliIdAndSingleProductMap.put(qli.OpportunityLineItemId__c, qli); } for (OpportunityLineItem newOli : newList) { //因报价行项目中"询价行项目"的Id比报价行项目本身的Id短三位,因此作出如下处理 String newOliId = newOli.Id; String newOliIdSub = newOliId.substring(0,newOliId.length()-3); if (oliIdAndSingleProductMap.containsKey(newOliIdSub)) { OpportunityLineItem oli = new OpportunityLineItem(); oli.OLISingleProduct__c = oliIdAndSingleProductMap.get(newOliIdSub).SingleProduct__c; oli.Set__c = oliIdAndSingleProductMap.get(newOliIdSub).SetName__c; oli.Id = newOli.Id; opportunityLineItemList.add(oli); } } } else { if (oppList.size() > 0 && oppList[0].ProductSegment__c == 'BS'){ for (OpportunityLineItem newOli : newList) { OpportunityLineItem oli = new OpportunityLineItem(); oli.OLISingleProduct__c = true; oli.Set__c = '单品'; oli.Id = newOli.Id; opportunityLineItemList.add(oli); } } } if (opportunityLineItemList.size() > 0) { update opportunityLineItemList; } //XHL-20190510-AddEnd } public static void test(){ Integer i = 1; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; i++; } }