binxie
2023-06-26 de9565270a88b0749d17c1961cd41399c8483c96
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
trigger AfterUpdateAsset on Asset (after update) {
    /*20170209由于华东上线课题24行要求注释 LK201702099*/
    // 目标资产
    /*List<Asset> targetAssetList = new List<Asset>();
    for (Asset assetNew : Trigger.new) {
        Asset assetOld = trigger.oldMap.get(assetNew.Id);
        if (assetOld.Internal_asset_location__c != assetNew.Internal_asset_location__c) {
            targetAssetList.add(assetNew);
        }
    }
    if (targetAssetList.size() > 0) {
        // 备品set检索
        List<AggregateResult> esList = [
                select Equipment_Set__c esId 
                  from Equipment_Set_Detail__c 
                 where Asset__c in : targetAssetList
                 group by Equipment_Set__c];
        List<Id> esid = new List<Id>();
        for (AggregateResult es : esList) {
            esid.add(String.valueOf(es.get('esId')));
        }
        if (esid.size() > 0) {
            // 备品set明细检索
            List<AggregateResult> esdList = [
                    select Equipment_Set__c esId, 
                           Equipment_Set__r.Name esName, 
                           Max(Internal_asset_location__c) maxLocation, 
                           Min(Internal_asset_location__c) minLocation
                      from Equipment_Set_Detail__c
                     where Equipment_Set__c in : esid
                       and Internal_asset_location__c != null
                     group by Equipment_Set__c, Equipment_Set__r.Name
                     order by Equipment_Set__c];
            // 备品set明细check
            List<Equipment_Set__c> updateList = new List<Equipment_Set__c>();
            for (AggregateResult esd : esdList) {
                system.debug('=====esName:' + String.valueOf(esd.get('esName')) + ',maxLocation:' + String.valueOf(esd.get('maxLocation')));
                system.debug('=====esName:' + String.valueOf(esd.get('esName')) + ',maxLocation:' + String.valueOf(esd.get('minLocation')));
                if (String.valueOf(esd.get('maxLocation')) != String.valueOf(esd.get('minLocation'))) {
                    // TODO 如何准确定位?
                    Trigger.new[0].addError('备品set的各明细[备品存放地]不一致,不能更新[备品存放地]。');
                } else {
                    Equipment_Set__c updateEs = new Equipment_Set__c(id=String.valueOf(esd.get('esId')), Internal_asset_location__c=String.valueOf(esd.get('maxLocation')));
                    updateList.add(updateEs);
                }
            }
            // 备品set更新
            if (updateList.size() > 0) {
                update updateList;
            }
        }
    }*/
}