高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
force-app/main/default/triggers/RentalApplyBeforeUpdate.trigger
@@ -27,11 +27,9 @@
        List<Rental_Apply__c> RacList = new List<Rental_Apply__c>();
        List<Rental_Apply__c> RacListElse = new List<Rental_Apply__c>();
        List<AggregateResult> GroList = new List<AggregateResult>();
        List<String> CampaignId = new List<String>();       //学会Id List
        Map<String,String> RenMap = new Map<String,String>();
        Map<String,String> RenCountMap = new Map<String,String>();
        GroList = [select count(id) countId,Old_Rental_Apply__c from Rental_Apply__c where Old_Rental_Apply__c !=null group by Old_Rental_Apply__c];
        for(AggregateResult Ta : GroList){
            RenMap.put( string.valueOf(Ta.get('Old_Rental_Apply__c')),string.valueOf(Ta.get('Old_Rental_Apply__c') )); //旧借出申请
            RenCountMap.put( string.valueOf(Ta.get('Old_Rental_Apply__c')),string.valueOf(Ta.get('countId') ));
@@ -45,15 +43,11 @@
            if(ra.Name ==null){
                ra.Name='*';
            }
            //查裁决申请的List
            if (!String.isBlank(ra.Campaign__c)){
                CampaignId.add(ra.Campaign__c);
            }
    //
            if(RenMap.containsKey(ra.Old_Rental_Apply__c)){
                LoopListRaOCon.add(ra.Old_Rental_Apply__c);
                LoopListRaN.put(ra.Old_Rental_Apply__c,LoopListRaOCon.size()-1);
                //RacList = [select id,Old_Rental_Apply__r.Name from Rental_Apply__c where Old_Rental_Apply__c =: ra.Old_Rental_Apply__c];
                //ra.Name = RacList[0].Old_Rental_Apply__r.Name+'-'+RacList.size();
            }else{
@@ -64,27 +58,10 @@
                //  ra.Name = RacList[0].Name+'-'+1;
                //  ra.Old_Rental_Apply__c = ra.id;
                //}
            }
            
        }
        //备品借出申请增加决裁信息判断,为把此时点的决裁编号和决裁状态写到决裁编号(创建)和决裁状态(创建)上
        if( CampaignId.size() > 0 ){
            Map<Id, Application_for_Conference_Adjudication__c> application_for_con_map = new Map<Id, Application_for_Conference_Adjudication__c>([
                    select id ,ProcessState__c,MeetingApprovedNo__c
                    from Application_for_Conference_Adjudication__c
                    where id in: CampaignId]);
            for( Rental_Apply__c ra : trigger.new ) {
                if(application_for_con_map != null && application_for_con_map.containsKey(ra.Campaign__c) ){
                    ra.ApprovedNo_Create__c = application_for_con_map.get(ra.Campaign__c).MeetingApprovedNo__c;
                    ra.Approved_State_Create__c = application_for_con_map.get(ra.Campaign__c).ProcessState__c;
                }
            }
        }
        // bp2
        // System.debug('测试是否进入');
        // RacList = [select id,Old_Rental_Apply__r.Name from Rental_Apply__c where Old_Rental_Apply__c in : LoopListRaOCon];