trigger AssetImageBeforeTrigger on Asset (before insert, before update) { 
 | 
    //add by gzw 20210729 start 
 | 
    if (StaticParameter.EscapeVMCTrigger) { 
 | 
        return ; 
 | 
    } 
 | 
    //add by gzw 20210729 end 
 | 
    if (trigger.isBefore) { 
 | 
        for(Asset newS : trigger.new) { 
 | 
            if (Trigger.isUpdate && newS.Status == '使用中' 
 | 
                    && String.isBlank(((Asset) Trigger.oldMap.get(newS.Id)).ImageAsset__c) 
 | 
                    && !String.isBlank(newS.ImageAsset__c) 
 | 
            ) { 
 | 
                newS.ImageAssetUploadedTime__c = Datetime.now(); 
 | 
                newS.ImageAssetUploadedBy__c = UserInfo.getUserId(); 
 | 
            } 
 | 
            if (Trigger.isUpdate && newS.Status == '使用中' 
 | 
                        && String.isBlank(((Asset) Trigger.oldMap.get(newS.Id)).ImageSerial__c) 
 | 
                    && !String.isBlank(newS.ImageSerial__c) 
 | 
            ) { 
 | 
                newS.ImageSerialUploadedTime__c = Datetime.now(); 
 | 
                newS.ImageSerialUploadedBy__c = UserInfo.getUserId(); 
 | 
            } 
 | 
  
 | 
             System.debug('-------->Start'); 
 | 
            if(Trigger.isUpdate && !String.isBlank(((Asset)Trigger.oldMap.get(newS.Id)).Reson_Can_not_Warranty__c)){ 
 | 
                String reason = ((Asset)Trigger.oldMap.get(newS.Id)).Reson_Can_not_Warranty__c; 
 | 
  
 | 
                System.debug('oldreason'+reason); 
 | 
                System.debug('reason'+newS.Reson_Can_not_Warranty__c); 
 | 
                System.debug('Asset_Owner__c'+newS.Asset_Owner__c); 
 | 
                if(newS.Asset_Owner__c != '病院資産'){ 
 | 
                    if(newS.Reson_Can_not_Warranty__c != null){ 
 | 
                        if(!newS.Reson_Can_not_Warranty__c.contains('备品')){ 
 | 
                            // newS.Reson_Can_not_Warranty__c = reason + '备品'; 
 | 
                            newS.Reson_Can_not_Warranty__c = newS.Reson_Can_not_Warranty__c + '备品'; 
 | 
                        } 
 | 
                    }else{ 
 | 
                        newS.Reson_Can_not_Warranty__c = '备品'; 
 | 
                    } 
 | 
                     
 | 
                }else{ 
 | 
                    if(newS.Reson_Can_not_Warranty__c != null){ 
 | 
                        if(newS.Reson_Can_not_Warranty__c.contains('备品')){ 
 | 
                            //newS.Reson_Can_not_Warranty__c = reason.replace('备品', ''); 
 | 
                            newS.Reson_Can_not_Warranty__c = newS.Reson_Can_not_Warranty__c.replace('备品', ''); 
 | 
                        } 
 | 
                    } 
 | 
                } 
 | 
                if(newS.Final_Examination_Date__c != null){ 
 | 
                    if(Date.today().addDays(-90) > newS.Final_Examination_Date__c){ 
 | 
                        if(!reason.contains('点检')){ 
 | 
                            newS.Reson_Can_not_Warranty__c = reason + '点检'; 
 | 
                        } 
 | 
                    }else{ 
 | 
                        if(reason.contains('点检')){ 
 | 
                            newS.Reson_Can_not_Warranty__c = reason.replace('点检', ''); 
 | 
                        } 
 | 
                    } 
 | 
                }else{ 
 | 
                    if(reason.contains('点检')){ 
 | 
                        newS.Reson_Can_not_Warranty__c = reason.replace('点检', ''); 
 | 
                    } 
 | 
                } 
 | 
                 
 | 
            }else if(Trigger.isInsert || Trigger.isUpdate && String.isBlank(((Asset)Trigger.oldMap.get(newS.Id)).Reson_Can_not_Warranty__c)){ 
 | 
                if(newS.Asset_Owner__c != '病院資産'){ 
 | 
                    newS.Reson_Can_not_Warranty__c = '备品'; 
 | 
                }else{ 
 | 
                    if(newS.Reson_Can_not_Warranty__c != null){ 
 | 
                        if(newS.Reson_Can_not_Warranty__c.contains('备品')){ 
 | 
                            //newS.Reson_Can_not_Warranty__c = reason.replace('备品', ''); 
 | 
                            newS.Reson_Can_not_Warranty__c = newS.Reson_Can_not_Warranty__c.replace('备品', ''); 
 | 
                        } 
 | 
                    } 
 | 
                } 
 | 
                if(newS.Final_Examination_Date__c != null){ 
 | 
                    if(Date.today().addDays(-90) > newS.Final_Examination_Date__c){ 
 | 
                        newS.Reson_Can_not_Warranty__c = '点检'; 
 | 
                    } 
 | 
                } 
 | 
  
 | 
            } 
 | 
            System.debug('-------->End'); 
 | 
        } 
 | 
    }     
 | 
} 
 |