From d0bf536263a31d700e3c96f6f5abd69620ff2fa8 Mon Sep 17 00:00:00 2001
From: 李金换 <lijinhuan@prec-tech.com>
Date: 星期三, 23 三月 2022 13:27:59 +0800
Subject: [PATCH] Merge branch 'NFM105限次合同异常数据0323'

---
 force-app/main/default/classes/NFM105Rest.cls |   90 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 64 insertions(+), 26 deletions(-)

diff --git a/force-app/main/default/classes/NFM105Rest.cls b/force-app/main/default/classes/NFM105Rest.cls
index 56bbb61..80e7a37 100644
--- a/force-app/main/default/classes/NFM105Rest.cls
+++ b/force-app/main/default/classes/NFM105Rest.cls
@@ -162,7 +162,6 @@
                                     , 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 
@@ -724,43 +723,82 @@
             }*/
             //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);  
+                    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) { 
+                        contractIds.add(rep.Maintenance_Contract__c);
                     }
                 }
-                if (contractMap.size() > 0) {
-                    //鏌ヨ褰撳墠闄愭鍚堝悓涓嬬殑鎵�鏈夌淮淇悎鍚屼繚鏈夎澶�
-                    maassList = [SELECT id , Series_RepairCount_F__c
+                //鏌ヨ褰撳墠闄愭鍚堝悓涓嬬殑鎵�鏈夌淮淇悎鍚屼繚鏈夎澶�
+                maassList = [SELECT id , Series_RepairCount_F__c
                                 , Maintenance_Contract_Asset_Estimate__c
                                 , Asset__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
@@ -789,7 +827,7 @@
                         }
                     }
                     if (updateList.size() > 0) {
-                        system.debug('zheli:'+updateList);
+                        // system.debug('zheli:'+updateList);
                         update updateList;
                     }
                 }

--
Gitblit v1.9.1