| | |
| | | , Repair_Quotation_Id__c, NFM105_MessageGroupNumber__c, Repair_List_Price_formula__c |
| | | , ReturnType__c, InspectType__c |
| | | , Maintenance_Contract__r.URF_Contract__c |
| | | , Maintenance_Contract_Asset_Estimate__r.URF_Series__c // 20220321 ljh 限次合同异常数据 |
| | | ,Maintenance_Contract__c |
| | | ,SerialNumber__c |
| | | ,Agreed_Date__c |
| | |
| | | }*/ |
| | | //add by rentx 2021-3-4 end |
| | | if (rprList.size() > 0) { |
| | | //contractAssetUrfMap<维修合同+保有设备,限次系列> |
| | | Map<String,String> contractAssetUrfMap = new Map<String,String>(); |
| | | //限次合同Id集合 |
| | | List<Id> contractIds = new List<Id>(); |
| | | //限次合同下的修理集合 |
| | | List<Repair__c> reList = new List<Repair__c>(); |
| | | // 限次合同 map |
| | | Map<String,Map<String,List<Repair__c>>> contractMap = new Map<String,Map<String,List<Repair__c>>>(); |
| | | //维修合同保有设备集合 |
| | | List<Maintenance_Contract_Asset__c> maassList = new List<Maintenance_Contract_Asset__c>(); |
| | | // 需要更新的 维修合同报价/保有设备 |
| | | List<Maintenance_Contract_Asset_Estimate__c> updateList = new List<Maintenance_Contract_Asset_Estimate__c>(); |
| | | //查询当前修理对应的维修合同是否为限次合同 && 大修 |
| | | for (Repair__c rep : rprList) { |
| | | if (rep.Maintenance_Contract__c != null && rep.Maintenance_Contract__r.URF_Contract__c == true && (rep.Repair_Rank__c == 'A' || rep.Repair_Rank__c == 'B' || rep.Repair_Rank__c == 'C') && rep.Agreed_Date__c != null) { |
| | | List<Repair__c> tempRepL; |
| | | Map<String,List<Repair__c>> tempRepM; |
| | | if(contractMap.containsKey(rep.Maintenance_Contract__c)){ |
| | | // 保有设备 和 限次系列 |
| | | tempRepM = contractMap.get(rep.Maintenance_Contract__c); |
| | | if(tempRepM.containsKey(rep.Delivered_Product__c)){ |
| | | tempRepM.get(rep.Delivered_Product__c).add(rep); |
| | | } |
| | | if(tempRepM.containsKey(rep.Maintenance_Contract_Asset_Estimate__r.URF_Series__c)){ |
| | | tempRepM.get(rep.Maintenance_Contract_Asset_Estimate__r.URF_Series__c).add(rep); |
| | | } |
| | | }else{ |
| | | tempRepM = new Map<String,List<Repair__c>>(); |
| | | tempRepL.add(rep); |
| | | tempRepM.put(rep.Delivered_Product__c,tempRepL); |
| | | tempRepM.put(rep.Maintenance_Contract_Asset_Estimate__r.URF_Series__c,tempRepL); |
| | | } |
| | | contractMap.put(rep.Maintenance_Contract__c,tempRepM); |
| | | contractIds.add(rep.Maintenance_Contract__c); |
| | | } |
| | | } |
| | | if (contractMap.size() > 0) { |
| | | //查询当前限次合同下的所有维修合同保有设备 |
| | | maassList = [SELECT id , Series_RepairCount_F__c |
| | | , Maintenance_Contract_Asset_Estimate__c |
| | |
| | | , Maintenance_Contract__c |
| | | , URF_Series_F__c |
| | | FROM Maintenance_Contract_Asset__c |
| | | WHERE Maintenance_Contract__c in :contractMap.keySet()]; |
| | | List<Maintenance_Contract_Asset_Estimate__c> updateList = new List<Maintenance_Contract_Asset_Estimate__c>(); |
| | | WHERE Maintenance_Contract__c in :contractIds]; |
| | | for (Maintenance_Contract_Asset__c maAss : maassList) { |
| | | // contractAssetUrfMap<维修合同+保有设备,限次系列> |
| | | String keyV = maAss.Maintenance_Contract__c +';'+ maAss.Asset__c; |
| | | if (!contractAssetUrfMap.containsKey(keyV) && String.isNotBlank(maAss.URF_Series_F__c)) { |
| | | contractAssetUrfMap.put(keyV, maAss.URF_Series_F__c); |
| | | } |
| | | } |
| | | //查询维修合同下的所有修理 |
| | | reList = [select id,Maintenance_Contract__c,Delivered_Product__c,Usage_Ratio_Price_Service__c from Repair__c where (Repair_Rank__c = 'A' OR Repair_Rank__c = 'B' OR Repair_Rank__c = 'C') and Agreed_Date__c <> null and Maintenance_Contract__c in :contractIds ]; |
| | | system.debug('zheli:'+reList.size()); |
| | | for (Repair__c rep : reList) { |
| | | List<Repair__c> tempRepL00; |
| | | List<Repair__c> tempRepL01; |
| | | List<Repair__c> tempRepL02; |
| | | List<Repair__c> tempRepL03; |
| | | Map<String,List<Repair__c>> tempRepM; |
| | | String keyV = rep.Maintenance_Contract__c +';'+rep.Delivered_Product__c; |
| | | if(contractMap.containsKey(rep.Maintenance_Contract__c)){ |
| | | tempRepM = contractMap.get(rep.Maintenance_Contract__c); |
| | | // 保有设备 和 限次系列 |
| | | if(tempRepM.containsKey(rep.Delivered_Product__c)){ |
| | | tempRepL02 = tempRepM.get(rep.Delivered_Product__c); |
| | | }else{ |
| | | tempRepL02 = new List<Repair__c>(); |
| | | } |
| | | tempRepL02.add(rep); |
| | | tempRepM.put(rep.Delivered_Product__c,tempRepL02); |
| | | if(contractAssetUrfMap.containsKey(keyV)){ |
| | | if(tempRepM.containsKey(contractAssetUrfMap.get(keyV))){ |
| | | tempRepL03 = tempRepM.get(contractAssetUrfMap.get(keyV)); |
| | | }else{ |
| | | tempRepL03 = new List<Repair__c>(); |
| | | } |
| | | tempRepL03.add(rep); |
| | | tempRepM.put(contractAssetUrfMap.get(keyV),tempRepL03); |
| | | } |
| | | }else{ |
| | | tempRepM = new Map<String,List<Repair__c>>(); |
| | | tempRepL00 = new List<Repair__c>(); |
| | | tempRepL00.add(rep); |
| | | tempRepL01 = new List<Repair__c>(); |
| | | tempRepL01.add(rep); |
| | | tempRepM.put(rep.Delivered_Product__c,tempRepL00); |
| | | if(contractAssetUrfMap.containsKey(keyV)){ |
| | | tempRepM.put(contractAssetUrfMap.get(keyV),tempRepL01); |
| | | } |
| | | } |
| | | contractMap.put(rep.Maintenance_Contract__c,tempRepM); |
| | | } |
| | | if (contractMap.size() > 0) { |
| | | for (Maintenance_Contract_Asset__c maAss : maassList) { |
| | | // 判断已维修次数是否发生改变 |
| | | if (contractMap.get(maAss.Maintenance_Contract__c) != null |
| | |
| | | } |
| | | } |
| | | if (updateList.size() > 0) { |
| | | system.debug('zheli:'+updateList); |
| | | // system.debug('zheli:'+updateList); |
| | | update updateList; |
| | | } |
| | | } |