// FixtureSetHandlerTest
|
public without sharing class FixtureSetHandler extends Oly_TriggerHandler {
|
private Map<Id, Fixture_Set__c> newMap;
|
private Map<Id, Fixture_Set__c> oldMap;
|
private List<Fixture_Set__c> newList;
|
private List<Fixture_Set__c> oldList;
|
|
public FixtureSetHandler() {
|
this.newMap = (Map<Id, Fixture_Set__c>) Trigger.newMap;
|
this.oldMap = (Map<Id, Fixture_Set__c>) Trigger.oldMap;
|
this.newList = (List<Fixture_Set__c>) Trigger.new;
|
this.oldList = (List<Fixture_Set__c>) Trigger.old;
|
}
|
|
protected override void beforeInsert() {
|
beforeSetValue();
|
}
|
protected override void beforeUpdate() {
|
beforeSetValue();
|
upToAsset();// 20230719 ljh DB202306212211 p9
|
}
|
private void beforeSetValue() {
|
for (Fixture_Set__c nObj : newList) {
|
nObj.Loaner_code__c = nObj.Name;
|
}
|
}
|
/**
|
* @Author: [lijinhuan]
|
* @description: 备品类型I和备品类型II放到保有设备上显示
|
* @return {*}
|
*/
|
private void upToAsset() {
|
Map<String,Fixture_Set__c> fsMap= new Map<String,Fixture_Set__c>();
|
// Set<String> ModelNoSet = new Set<String>();
|
for (Fixture_Set__c nObj : newList) {
|
Fixture_Set__c oObj;
|
if (Trigger.isUpdate) {
|
oObj = oldMap.get(nObj.Id);
|
}
|
// 发生改变
|
if( (String.isNotBlank(nObj.Loaner_categoryI__c) && nObj.Loaner_categoryI__c != oObj.Loaner_categoryI__c)
|
|| (String.isBlank(nObj.Loaner_categoryI__c) && String.isNotBlank(oObj.Loaner_categoryI__c))
|
|| (String.isNotBlank(nObj.Loaner_categoryII__c) && nObj.Loaner_categoryII__c != oObj.Loaner_categoryII__c)
|
|| (String.isBlank(nObj.Loaner_categoryII__c) && String.isNotBlank(oObj.Loaner_categoryII__c))
|
// 借用机会可视化UATbug25 zyh 20231218 start
|
|| (String.isBlank(nObj.Product_Type__c) && String.isNotBlank(oObj.Product_Type__c))
|
|| (String.isNotBlank(nObj.Product_Type__c) && nObj.Product_Type__c != oObj.Product_Type__c)
|
// 借用机会可视化UATbug25 zyh 20231218 end
|
){
|
if(String.isNotBlank(nObj.Fixture_Set_Body_Model_No__c)){
|
String model = nObj.Fixture_Set_Body_Model_No__c.toUpperCase();
|
fsMap.Put(model,nObj);
|
}
|
|
}
|
// if(Trigger.isDelete && String.isNotBlank(oObj.Fixture_Set_Body_Model_No__c ) && (String.isNotBlank(oObj.Loaner_categoryI__c)||String.isNotBlank(oObj.Loaner_categoryII__c))){
|
// ModelNoSet.add(oObj.Fixture_Set_Body_Model_No__c);
|
// }
|
}
|
// if(fsMap.size() > 0 || ModelNoSet.size() > 0){
|
if(fsMap.size() > 0){
|
// 查询这个配套的产品,赋值给产品
|
List<Product2> Product2List = [SELECT Id,Fixture_Model_No_T__c,Loaner_categoryI__c,Loaner_categoryII__c ,Product_Type__c
|
FROM Product2
|
// WHERE Fixture_Model_No_T__c IN :fsMap.keySet() OR Fixture_Model_No_T__c IN :ModelNoSet ];
|
WHERE Fixture_Model_No_T__c IN :fsMap.keySet() ];
|
if(Product2List.size() > 0){
|
Map<String,Product2> updateMap = new Map<String,Product2>();
|
for(Product2 pro:Product2List){
|
Product2 p2 = new Product2();
|
p2.Id = pro.Id;
|
p2.Loaner_categoryI__c = fsMap.get(pro.Fixture_Model_No_T__c.toUpperCase()).Loaner_categoryI__c;
|
p2.Loaner_categoryII__c = fsMap.get(pro.Fixture_Model_No_T__c.toUpperCase()).Loaner_categoryII__c;
|
// 借用机会可视化UATbug25 zyh 20231218 start
|
p2.Product_Type__c = fsMap.get(pro.Fixture_Model_No_T__c.toUpperCase()).Product_Type__c;
|
// 借用机会可视化UATbug25 zyh 20231218 end
|
if(((String.isNotBlank(p2.Loaner_categoryI__c) && p2.Loaner_categoryI__c.equals(pro.Loaner_categoryI__c)) || (String.isBlank(p2.Loaner_categoryI__c)&&String.isBlank(pro.Loaner_categoryI__c)))
|
&& ((String.isNotBlank(p2.Loaner_categoryII__c) && p2.Loaner_categoryII__c.equals(pro.Loaner_categoryII__c)) || (String.isBlank(p2.Loaner_categoryII__c)&&String.isBlank(pro.Loaner_categoryII__c)))
|
// 借用机会可视化UATbug25 zyh 20231218 start
|
&& ((String.isNotBlank(p2.Product_Type__c) && p2.Product_Type__c.equals(pro.Product_Type__c)) || (String.isBlank(p2.Product_Type__c)&&String.isBlank(pro.Product_Type__c)))){
|
// 借用机会可视化UATbug25 zyh 20231218 end
|
continue;
|
}
|
updateMap.put(pro.Id,p2);
|
}
|
if(updateMap.size() > 0){
|
update updateMap.values();
|
}
|
}
|
}
|
}
|
|
}
|