unknown
2023-08-23 50ce6a5e5ae7ac6ce3e6281acca9a0db568306e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public without sharing class FixtureSetDetailHandler extends Oly_TriggerHandler {
    private Map<Id, Fixture_Set_Detail__c> newMap;
    private Map<Id, Fixture_Set_Detail__c> oldMap;
    private List<Fixture_Set_Detail__c> newList;
    private List<Fixture_Set_Detail__c> oldList;
 
    public FixtureSetDetailHandler() {
        this.newMap = (Map<Id, Fixture_Set_Detail__c>) Trigger.newMap;
        this.oldMap = (Map<Id, Fixture_Set_Detail__c>) Trigger.oldMap;
        this.newList = (List<Fixture_Set_Detail__c>) Trigger.new;
        this.oldList = (List<Fixture_Set_Detail__c>) Trigger.old;
    }
 
    protected override void beforeInsert() {
        beforeSetValue();
    }
    protected override void beforeUpdate() {
        beforeSetValue();
    }
 
    private void beforeSetValue() {
        Map<String,Fixture_Set_Detail__c> fsdMap = new Map<String,Fixture_Set_Detail__c>();
        for (Fixture_Set_Detail__c nObj : newList) {
            nObj.Name_CHN_Created__c = nObj.Name_CHN__c;
            // 20230727 ljh ±¸Æ·ÀàÐÍIºÍ±¸Æ·ÀàÐÍII·Åµ½±£ÓÐÉ豸ÉÏÏÔʾ start
            if(nObj.Loaner_category__c){
                fsdMap.put(nObj.Fixture_Model_No_F__c,nObj);
            }
        }
        // 20230727 ljh ±¸Æ·ÀàÐÍIºÍ±¸Æ·ÀàÐÍII·Åµ½±£ÓÐÉ豸ÉÏÏÔʾ start
        if(fsdMap.size() > 0){
            List<Product2>  Product2List = [SELECT Id,Fixture_Model_No_T__c,Loaner_categoryI__c,Loaner_categoryII__c 
                                                 FROM Product2 
                                                WHERE Fixture_Model_No_T__c IN :fsdMap.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 = fsdMap.get(pro.Fixture_Model_No_T__c).Loaner_categoryI__c;
                    p2.Loaner_categoryII__c =fsdMap.get(pro.Fixture_Model_No_T__c).Loaner_categoryII__c;
                    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)))){
                        continue;
                    }
                    updateMap.put(pro.Id,p2);
                }
                if(updateMap.size() > 0){
                    update updateMap.values();
                }
            }
        }
        // 20230727 ljh ±¸Æ·ÀàÐÍIºÍ±¸Æ·ÀàÐÍII·Åµ½±£ÓÐÉ豸ÉÏÏÔʾ start
    }
}