public with sharing class RepairQuoteTrigger {

	public static void ChangeRepair(List<Repair_Quotation__c> newList, Map<Id, Repair_Quotation__c> newMap, List<Repair_Quotation__c> oldList, Map<Id, Repair_Quotation__c> oldMap) {
		System.debug('===========> start');
		List<String> rqIds = new List<String>(); 
		Map<id,Repair_Quotation__c> RqMap = new Map<id,Repair_Quotation__c>();
		if (Trigger.isUpdate) {
			Boolean flag = false;
			for(Repair_Quotation__c rq : newList){
				if(Trigger.isUpdate && rq.ListPrice__c != oldMap.get(rq.id).ListPrice__c){
					//rqIds.add(rq.id);
					flag = true;
				}
			}
			if(flag == false){
                return;
            }
            for(Repair_Quotation__c rq : newList){
				if(Trigger.isUpdate && rq.ListPrice__c != oldMap.get(rq.id).ListPrice__c){
					rqIds.add(rq.id);
					RqMap.put(rq.id, rq);
				}
			}
		}else if(Trigger.isInsert){
			for(Repair_Quotation__c rq : newList){
				rqIds.add(rq.id);
				RqMap.put(rq.id, rq);
			}
		}

		List<Repair__c> RepairUpdateList = new List<Repair__c>();
		if(rqIds.size() > 0){
			//修理的同期中的修理报价de报价金额改变的修理
			List<Repair__c> RpList = [select id,Repair_Quotation_Id__c from Repair__c where Repair_Quotation_Id__c in :rqIds];
			if(RpList.size() > 0){
				for(Repair__c rp : RpList){
					Repair_Quotation__c Rqa = RqMap.get(rp.Repair_Quotation_Id__c);
					rp.Repair_Quotation_Price__c = Rqa.ListPrice__c;
					RepairUpdateList.add(rp);
				}
				update RepairUpdateList;
			}
		}
		System.debug('===========> end');
	}
}