public without sharing class AssetMaintainDetailHandler extends Oly_TriggerHandler {
    private Map<Id, AssetMaintainDetail__c> newMap;
    private Map<Id, AssetMaintainDetail__c> oldMap;
    private List<AssetMaintainDetail__c> newList;
    private List<AssetMaintainDetail__c> oldList;
    private Datetime today = System.now();
    private Map<String,String> MAINTYPE_ABBR_MAP = new Map<String, String> {
            '断念找回(断念取消)'=> 'DNQX',
            '断念找回(重新登录)'=>'DNDL',
            '冻结'=>'DJ',
            '解冻'=>'JD',
            '实物报废'=>'BFSW',
            '废弃(丢失)'=>'BFDS',
            '废弃(盘亏)'=>'BFPK',
            '盘盈(数量管理)'=>'PY',
            '耗材已消耗数'=>'XH'
        } ;
    public AssetMaintainDetailHandler() {
        this.newMap = (Map<Id, AssetMaintainDetail__c>) Trigger.newMap;
        this.oldMap = (Map<Id, AssetMaintainDetail__c>) Trigger.oldMap;
        this.newList = (List<AssetMaintainDetail__c>) Trigger.new;
        this.oldList = (List<AssetMaintainDetail__c>) Trigger.old;
    }
    protected override void beforeInsert() {
        beforeSetValue();
    }
    protected override void beforeUpdate() {
        beforeSetValue();
    }

    private void beforeSetValue() {
        for (AssetMaintainDetail__c nObj : newList) {
            if(Trigger.isInsert || Trigger.isUpdate){
                nObj.Name = 'WHD-' + this.MAINTYPE_ABBR_MAP.get(nObj.MaintainType__c) + this.today.format('-YYYYMM-') + String.valueOf(nObj.OrderNumber__c).leftpad(4, '0');
            }
        }
    }
}