binxie
2024-01-16 1b08402678deb31bba4a347bfd388eba8360cbc1
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
56
57
58
59
60
61
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.toUpperCase(),nObj);
            }
        }
        // 20230727 ljh 备品类型I和备品类型II放到保有设备上显示 end
        if(fsdMap.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 :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.toUpperCase()).Loaner_categoryI__c;
                    p2.Loaner_categoryII__c =fsdMap.get(pro.Fixture_Model_No_T__c.toUpperCase()).Loaner_categoryII__c;
                    // 借用机会可视化UATbug25 zyh 20240106 start
                    p2.Product_Type__c =fsdMap.get(pro.Fixture_Model_No_T__c.toUpperCase()).Product_Type__c;
                    // 借用机会可视化UATbug25 zyh 20240106 end
                    if(p2.Loaner_categoryI__c.equals(pro.Loaner_categoryI__c)
                        && p2.Loaner_categoryII__c.equals(pro.Loaner_categoryII__c)
                        // 借用机会可视化UATbug25 zyh 20240106 start
                        && (String.isBlank(p2.Product_Type__c) || (String.isNotBlank(p2.Product_Type__c) && p2.Product_Type__c.equals(pro.Product_Type__c)))){
                        // 借用机会可视化UATbug25 zyh 20240106 end
                        continue;
                    }
                    updateMap.put(pro.Id,p2);
                }
                if(updateMap.size() > 0){
                    update updateMap.values();
                }
            }
        }
        // 20230727 ljh 备品类型I和备品类型II放到保有设备上显示 start
    }
}