public without sharing class RepairDetailsTriggerHandler {
    public static String setNumber(List<RepairDetails__c> newList, Map<Id, RepairDetails__c> newMap, List<RepairDetails__c> oldList, Map<Id, RepairDetails__c> oldMap){
        //system.debug('setNumber');
        Map<String,List<RepairDetails__c>> repairMap = new Map<String,List<RepairDetails__c>>();
        for(RepairDetails__c repd : newList){
            if(repairMap.containsKey(repd.Repair__c)){
                repairMap.get(repd.Repair__c).add(repd);
            }else{
                repairMap.put(repd.Repair__c, new List<RepairDetails__c>());
                repairMap.get(repd.Repair__c).add(repd);
            }
            //system.debug(repairMap);
        }
        if(repairMap.size() > 0){
            //count(id) 不为0时修改Name
            Set<String> rep = repairMap.keySet();
            List<AggregateResult> repair = [select count(id) ID ,Repair__c from RepairDetails__c where Repair__c =: rep group by Repair__c];
            List<RepairDetails__c> repdList = [select Repair__c, Repair__r.name from RepairDetails__c where Repair__c =: rep];
            Map<String,String> id_name = new Map<String,String>();
            //system.debug(repair);
            //system.debug(repdList);
            for(RepairDetails__c rd : repdList){
                id_name.put(rd.Repair__c, rd.Repair__r.Name);
            }
            List<String> overID = new List<String>();
            //system.debug(id_name);
            for(AggregateResult  ar : repair){
                String rep1 = (String)ar.get('repair__c');
                List<RepairDetails__c> repairDList = repairMap.get(rep1);
                //system.debug(repairDList);
                Integer num = (Integer)ar.get('ID') == null ? 0 : (Integer)ar.get('ID');
                //system.debug(rep1+'--------'+num);
                for(RepairDetails__c red : repairDList){
                    red.Name = id_name.get(rep1) + (num > 8 ? '-'+(++num) : '-0'+(++num));
                }
                overID.add(rep1);
                repairMap.put(rep1, repairDList); 
            }
            //count(id)为null时设置ID;
            List<String> newID = new List<String>();
            if(overID.size() == 0){
                newId.addAll(repairMap.keySet());
            }else{
                for(String id : repairMap.keySet()){
                    if(overID.contains(id) == false){
                       newID.add(id);
                    }
                }
            }
            if(newID.size()>0){
                List<Repair__c> needList = [select id,Name from Repair__c where id =: newID];
                for(Repair__c re : needList){
                    Integer i = 1;
                    for(RepairDetails__c red : repairMap.get(re.id)){
                        red.Name = re.Name + (i > 9 ? '-'+(i++) : '-0'+(i++));
                    }
                }
            }
            //system.debug(newList);
        }
        return '';   
    }
}