public without sharing class OrderItemTriggerHandler {
|
|
public static void setProductConfig(List<OrderItem> newList, Map<Id, OrderItem> newMap, List<OrderItem> oldList, Map<Id, OrderItem> oldMap) {
|
List<OrderItem> targetList = null;
|
if (Trigger.isDelete) {
|
targetList = oldList;
|
} else {
|
targetList = newList;
|
}
|
// 处理对象的合同ID
|
List<String> ordIdList = new List<String>();
|
Map<String, String> ordMap = new Map<String, String>();
|
for (OrderItem target : targetList) {
|
if (ordMap.containsKey(target.OrderId) == false) {
|
ordIdList.add(target.OrderId);
|
ordMap.put(target.OrderId, target.OrderId);
|
}
|
}
|
// 取得处理对象的合同产品
|
List<OrderItem> oiList = [select Id, PricebookEntry.Product2.ProductCode, Quantity, OrderId from OrderItem where OrderId = :ordIdList order by OrderId, PricebookEntry.Product2.ProductCode, Quantity];
|
Map<String, List<OrderItem>> oiMap = new Map<String, List<OrderItem>>();
|
List<OrderItem> nList = new List<OrderItem>();
|
String tmp = '';
|
for (OrderItem oi : oiList) {
|
if (tmp == '' || oi.OrderId != tmp) {
|
tmp = oi.OrderId;
|
nList = new List<OrderItem>();
|
oiMap.put(oi.OrderId, nList);
|
nList.add(oi);
|
} else {
|
nList.add(oi);
|
}
|
}
|
// 更新处理对象的合同
|
List<Order> ordList = [select Id, RecordTypeId, ProductConfig__c, ProductConfig_D__c from Order where Id = :ordIdList];
|
List<Order> updList = new List<Order>();
|
for (Order target : ordList) {
|
List<OrderItem> ois = oiMap.get(target.Id);
|
if (ois == null || ois.size() == 0) {
|
continue;
|
}
|
String oiStr = '';
|
for (OrderItem oi : ois) {
|
if (oiStr == '') {
|
oiStr += oi.PricebookEntry.Product2.ProductCode + '*' + oi.Quantity + '\n';
|
} else {
|
oiStr += oi.PricebookEntry.Product2.ProductCode + '*' + oi.Quantity + '\n';
|
}
|
}
|
|
boolean individualCase = target.RecordTypeId == System.Label.RT_Contract_IndividualCase_ANI ||
|
target.RecordTypeId == System.Label.RT_Contract_IndividualCase_BS ||
|
target.RecordTypeId == System.Label.RT_Contract_IndividualCase_IE ||
|
target.RecordTypeId == System.Label.RT_Contract_IndividualCase_NDT ||
|
target.RecordTypeId == System.Label.RT_Contract_IndividualCase_RVI;
|
|
Order upd = new Order(Id = target.Id);
|
if (UserInfo.getUserType() == 'PowerPartner' || target.RecordTypeId == System.Label.RT_ServiceContract
|
|| target.RecordTypeId == System.Label.RT_ServiceContractIE || target.RecordTypeId == System.Label.RT_ServiceContractRVI || individualCase) {
|
upd.ProductConfig_D__c = oiStr;
|
} else {
|
upd.ProductConfig__c = oiStr;
|
upd.ProductConfig_D__c = oiStr;
|
}
|
updList.add(upd);
|
}
|
|
if (updList.size() > 0) update updList;
|
}
|
|
public static void insSingleProduct(List<OrderItem> newList, Map<Id, OrderItem> newMap, List<OrderItem> oldList, Map<Id, OrderItem> oldMap) {
|
List<Id> idList = new List<Id>();
|
idList.addAll(newMap.keySet());
|
List<order_Single_product__c> ospList = new List<order_Single_product__c>();
|
if(idList.size() >0 ){
|
for(Id id: idList){
|
if(newMap.get(id).ODISingleProduct__c == true){
|
order_Single_product__c osp = new order_Single_product__c();
|
osp.OrderProduct__c = id;
|
osp.Order__c = newMap.get(id).OrderId;
|
osp.CurrencyIsoCode = newMap.get(id).CurrencyCode__c;
|
ospList.add(osp);
|
}
|
}
|
System.debug(ospList);
|
insert ospList;
|
}
|
}
|
|
public static void delSingleProduct(List<OrderItem> newList, Map<Id, OrderItem> newMap, List<OrderItem> oldList, Map<Id, OrderItem> oldMap) {
|
List<Id> idList = new List<Id>();
|
for(OrderItem ord : oldList){
|
if(ord.ODISingleProduct__c == true){
|
idList.add(ord.Id);
|
}
|
}
|
if(idList.size() >0 ){
|
List<order_Single_product__c> ospList = [select id from order_Single_product__c where OrderProduct__c in :idList];
|
System.debug('ospList***'+ospList);
|
delete ospList;
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
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++;
|
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++;
|
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++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
i++;
|
}
|
}
|