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;
|
}
|
}
|
}*/
|
}
|