/**
     * @Author    lijinhuan
     * @DateTime  2023-02-07T17:49:45+0800
     * 测试类：FrameNumUploadControllerTest
*/
public without sharing class DNDetailsHandler  extends Oly_TriggerHandler {

    private Map<Id, Statu_Achievements_DN_details__c > newMap;
    private Map<Id, Statu_Achievements_DN_details__c > oldMap;
    private List<Statu_Achievements_DN_details__c > newList;
    private List<Statu_Achievements_DN_details__c > oldList;
    public DNDetailsHandler() {
        this.newMap = (Map<Id, Statu_Achievements_DN_details__c >) Trigger.newMap;
        this.oldMap = (Map<Id, Statu_Achievements_DN_details__c >) Trigger.oldMap;
        this.newList = (List<Statu_Achievements_DN_details__c >) Trigger.new;
        this.oldList = (List<Statu_Achievements_DN_details__c >) Trigger.old;
    }
    protected override void afterInsert() {
    	// insertFrameNumManag();
    }
    protected override void afterUpdate() {
    	// insertFrameNumManag(); // 测试用   
    }

	protected override void afterDelete() {
		// 进口单证 start
		// 删除进口单证数据
		deleteFrameNumManage();
		// 进口单证 end
	}

    protected override void beforeInsert() {
    }
    
    protected override void beforeUpdate() {

    }

	protected override void beforeDelete() {

	}

    // private Void insertFrameNumManag(){
    // 	Set<String> IdSet = new Set<String>();
    // 	Map<String,Id> eSignFormMap = new Map<String,Id>();
    // 	Map<String,String> DNMap  = new Map<String,String>();
    // 	for (Statu_Achievements_DN_details__c nObj : newList) {
    //         IdSet.add(nObj.Id);
    //     }
    // 	Map<String,Statu_Achievements_DN_details__c> sandMap = new Map<String,Statu_Achievements_DN_details__c>();
	//     // 查询明细 在机身编码中有没，没有生成
	//     for(Statu_Achievements_DN_details__c dn:[SELECT Id,SerialNumber__c,asset__c,
	// 			    Statu_Achievements_DN__c,SerialNoorLotNo_Raw__c,TracingCode_Raw__c,
	// 			    OTCode_Raw__c,asset__r.Name,QTY__c,Statu_Achievements_DN__r.Name
	// 			    FROM Statu_Achievements_DN_details__c
	// 				WHERE Id =:IdSet ]){
	//         sandMap.put(dn.TracingCode_Raw__c,dn);
	//     	DNMap.put(dn.TracingCode_Raw__c,dn.Statu_Achievements_DN__r.Name);
	//     }
    //     for(FrameNumManage__c f:[SELECT ManagementCode__c  FROM FrameNumManage__c WHERE ManagementCode__c in :sandMap.keySet()]){
    //         sandMap.remove(f.ManagementCode__c);
    //     }
	//     for(eSignForm__c es:[SELECT Id,DNName__c FROM eSignForm__c WHERE DNName__c IN: DNMap.values()]){
    //         for(String key:DNMap.keySet()){
    //             if(DNMap.get(key) == es.DNName__c){
    //                 eSignFormMap.put(key,es.Id);
    //             }
    //         } 
    //     }
	//     if(sandMap.size() > 0){
	//         List<FrameNumManage__c> infnmList = new List<FrameNumManage__c>();
	//         for (Statu_Achievements_DN_details__c s:sandMap.values()) {
	//             FrameNumManage__c temp = new FrameNumManage__c();
	//             temp.Name = s.TracingCode_Raw__c;
	//             temp.ManagementCode__c = s.TracingCode_Raw__c;
	//             temp.SerialNumberS__c = s.SerialNoorLotNo_Raw__c+'('+s.TracingCode_Raw__c+')';
	//             temp.SerialNumber__c = s.SerialNoorLotNo_Raw__c;
	//             temp.Num__c = s.QTY__c;
	//             temp.CheckOutNo__c  = s.Statu_Achievements_DN__r.Name.subString(2);//发货DN 的name去掉前两位的 00

	//             temp.Statu_Achievements_DN_details__c = s.Id;
	//             temp.Asset__c = s.asset__c;
	//             temp.signInForm__c = eSignFormMap.get(s.TracingCode_Raw__c);
	            
	//             temp.Material__c = s.OTCode_Raw__c;
	//             temp.MaterialDepict__c = s.asset__r.Name;
	//             infnmList.add(temp);
	//         }
	//         if(infnmList.size() > 0){
	//             insert infnmList;
	//             // Database.executeBatch(new SetFrameNumManageBatch(), 100);
	//         }    
	//     }
	// }

	private void deleteFrameNumManage() {
		List<FrameNumManage__c> rnmList = [select Id from FrameNumManage__c where Statu_Achievements_DN_details__c in :newMap.keySet()];
		if (rnmList != null && rnmList.size() > 0) {
			delete rnmList;
		}
	}
}