public without sharing class ProductScoreTableHistoryHandler extends Oly_TriggerHandler {
|
|
private Map<Id, Product_Score_Table_History__c> newMap;
|
private Map<Id, Product_Score_Table_History__c> oldMap;
|
private List<Product_Score_Table_History__c> newList;
|
private List<Product_Score_Table_History__c> oldList;
|
|
public ProductScoreTableHistoryHandler() {
|
this.newMap = (Map<Id, Product_Score_Table_History__c>) Trigger.newMap;
|
this.oldMap = (Map<Id, Product_Score_Table_History__c>) Trigger.oldMap;
|
this.newList = (List<Product_Score_Table_History__c>) Trigger.new;
|
this.oldList = (List<Product_Score_Table_History__c>) Trigger.old;
|
}
|
|
protected override void beforeInsert() {
|
setproduct_CategoryPriceInfo();
|
}
|
|
protected override void beforeUpdate() {
|
//setproduct_CategoryPriceInfo();
|
}
|
|
private void setproduct_CategoryPriceInfo() {
|
Id PSTH_RecordTypeId = Schema.SObjectType.Product_Score_Table_History__c.getRecordTypeInfosByDeveloperName().get('TargetPDCA').getRecordTypeId();
|
|
//产品分类价格表
|
List<String> pstIdList = new List<String>();
|
for (Product_Score_Table_History__c psth : newList) {
|
if (psth.RecordTypeId == PSTH_RecordTypeId && String.isNotBlank(psth.UniqueKey__c)) {
|
pstIdList.add(psth.UniqueKey__c.split(':')[1] + ':' + psth.Category3__c +':'+ psth.Category4__c);
|
}
|
}
|
|
Map<String, Product_CategoryPrice_Table__c> pstIdMap = new Map<String, Product_CategoryPrice_Table__c>();
|
for(Product_CategoryPrice_Table__c tmpObj : [SELECT Id, UniqueKey__c
|
FROM Product_CategoryPrice_Table__c
|
WHERE UniqueKey__c IN :pstIdList]){
|
pstIdMap.put(tmpObj.UniqueKey__c, tmpObj);
|
}
|
|
for (Product_Score_Table_History__c psth : newList) {
|
if (psth.RecordTypeId == PSTH_RecordTypeId && String.isNotBlank(psth.UniqueKey__c)) {
|
String pstUniqueKey = psth.UniqueKey__c.split(':')[1] + ':' + psth.Category3__c +':'+ psth.Category4__c;
|
if (pstIdMap.containsKey(pstUniqueKey)) {
|
psth.Product_CategoryPrice_Table__c = pstIdMap.get(pstUniqueKey).Id;
|
}
|
}
|
}
|
}
|
}
|