public without sharing class AssetHandlerCheck extends Oly_TriggerHandler {
|
private Map<Id, Asset> newMap;
|
private Map<Id, Asset> oldMap;
|
private List<Asset> newList;
|
private List<Asset> oldList;
|
private static Set<Id> rentalErrorIds = new Set<Id>();
|
private static Set<Id> jizhongErrorIds = new Set<Id>();
|
|
public AssetHandlerCheck() {
|
this.newMap = (Map<Id, Asset>) Trigger.newMap;
|
this.oldMap = (Map<Id, Asset>) Trigger.oldMap;
|
this.newList = (List<Asset>) Trigger.new;
|
this.oldList = (List<Asset>) Trigger.old;
|
}
|
|
protected override void afterInsert() {
|
checkAsset();
|
}
|
|
protected override void afterUpdate() {
|
checkAsset();
|
}
|
|
private void checkAsset() {
|
Set<String> ids = new Set<String> ();
|
for (Asset nObj : newList) {
|
Asset oObj = null;
|
if(oldMap != null && oldMap.containsKey(nObj.Id)) {
|
oObj = oldMap.get(nObj.Id);
|
}
|
if (nObj.AssetManageConfirm__c && nObj.Account_Management_Code__c != System.Label.Account_Asset_FJZ ) {
|
if(!jizhongErrorIds.contains(nObj.Id) && nObj.Ji_Zhong_Guan_Li_Ku_Cun__c < 0
|
&& (oObj == null || oObj.Ji_Zhong_Guan_Li_Ku_Cun__c != nObj.Ji_Zhong_Guan_Li_Ku_Cun__c)) {
|
ids.add(nObj.Id);
|
jizhongErrorIds.add(nObj.Id);
|
}
|
if(!rentalErrorIds.contains(nObj.Id)
|
&& (nObj.Out_of_wh__c != nObj.Out_of_wh_Sys__c || nObj.Rental_Count_Sys__c != nObj.Rental_Count__c)) {
|
ids.add(nObj.Id);
|
rentalErrorIds.add(nObj.Id);
|
}
|
}
|
}
|
|
if(!ids.isEmpty()) {
|
String idsStr = String.join(new List<String>(ids),',');
|
System.enqueueJob(new AssetHandlerCheckQueuable(idsStr));
|
}
|
}
|
}
|