public without sharing class LostReportDetailHandler extends Oly_TriggerHandler {
|
private Map<Id, LostReport_Detail__c> newMap;
|
private Map<Id, LostReport_Detail__c> oldMap;
|
private List<LostReport_Detail__c> newList;
|
private List<LostReport_Detail__c> oldList;
|
|
public LostReportDetailHandler() {
|
this.newMap = (Map<Id, LostReport_Detail__c>) Trigger.newMap;
|
this.oldMap = (Map<Id, LostReport_Detail__c>) Trigger.oldMap;
|
this.newList = (List<LostReport_Detail__c>) Trigger.new;
|
this.oldList = (List<LostReport_Detail__c>) Trigger.old;
|
}
|
|
protected override void beforeInsert() {
|
beforeSetValue();
|
}
|
|
protected override void afterUpdate() {
|
checkDelete();
|
}
|
|
protected override void afterDelete() {
|
setDeleteField();
|
}
|
|
private void beforeSetValue() {
|
for (LostReport_Detail__c nObj : newList) {
|
if (Trigger.isInsert && nObj.Asset_day__c == null) {
|
nObj.Asset_day__c = nObj.Asset_day_F__c;
|
}
|
}
|
}
|
|
private void setDeleteField() {
|
List<Inventory_Detail__c> ldList = new List<Inventory_Detail__c>();
|
List<Rental_Apply_Equipment_Set_Detail__c> raesdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
|
for (LostReport_Detail__c oObj : oldList) {
|
if (String.isNotBlank(oObj.Rental_Apply_Equipment_Set_Detail__c) && oObj.LostReport_Status_F__c != '草案中') {
|
raesdList.add(new Rental_Apply_Equipment_Set_Detail__c(Id = oObj.Rental_Apply_Equipment_Set_Detail__c
|
, DeleteLostReport_Detail_Reason__c = oObj.DeleteLostReport_Detail_Reason__c
|
, HadLostReport_Detail__c = oObj.HadLostReport_Detail__c
|
));
|
}
|
if (String.isNotBlank(oObj.Inventory_Detail__c) && oObj.LostReport_Status_F__c != '草案中') {
|
ldList.add(new Inventory_Detail__c(Id = oObj.Inventory_Detail__c
|
, DeleteLostReport_Detail_Reason__c = oObj.DeleteLostReport_Detail_Reason__c
|
, HadLostReport_Detail__c = oObj.HadLostReport_Detail__c
|
));
|
}
|
}
|
if (ldList.size() > 0) {
|
update ldList;
|
}
|
if (raesdList.size() > 0) {
|
update raesdList;
|
}
|
}
|
private void checkDelete() {
|
List<LostReport_Detail__c> ldList = new List<LostReport_Detail__c>();
|
for (LostReport_Detail__c nObj : newList) {
|
LostReport_Detail__c oObj = oldMap.get(nObj.Id);
|
if (oObj.CancelLostReport__c != nObj.CancelLostReport__c
|
&& nObj.CancelLostReport__c) {
|
ldList.add(new LostReport_Detail__c(Id = nObj.Id));
|
}
|
}
|
if (ldList.size() > 0) {
|
delete ldList;
|
}
|
}
|
}
|