| | |
| | | from Product_Register_Link__c |
| | | where Product2__r.Id in : p2ids]; |
| | | System.debug('pro2List='+pro2List); |
| | | //存放产品的id和等级类别字段的值的集合 |
| | | //存放产品的id和注册证医疗器械分类的值的集合 |
| | | Map<Id,List<String>> pro2Map = new Map<Id,List<String>>(); |
| | | //存放注册证上最前的维护日,一类证优先,否则二类证。 |
| | | Map<Id,Date> prSteMap = new Map<Id,Date>(); |
| | | Map<Id,Date> prSte1Map = new Map<Id,Date>(); |
| | | Map<Id,Date> prSteMap = new Map<Id,Date>();//存一类维护日 |
| | | Map<Id,Date> prSte1Map = new Map<Id,Date>();//存二类维护日 |
| | | if (pro2List.size()>0) { |
| | | for (Product_Register_Link__c prl: pro2List) { |
| | | if (pro2Map.containsKey(prl.Product2__r.Id)) { |
| | |
| | | pro2Map.get(prl.Product2__r.Id).add(prl.Product_Register__r.MedPrdClass__c); |
| | | } |
| | | |
| | | if (prl.Product_Register__r.MedPrdClass__c == '1' && prl.Product_Register__r.Stelsedag__c <> null) { |
| | | if (prl.Product_Register__r.MedPrdClass__c == '1' && prl.Product_Register__r.Stelsedag__c <> null && |
| | | newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c) { |
| | | if (prSteMap.containsKey(prl.Product2__r.Id)) { |
| | | if (prSteMap.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c) { |
| | | prSteMap.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c); |
| | |
| | | }else { |
| | | prSteMap.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c); |
| | | } |
| | | }else { |
| | | if (!prSteMap.containsKey(prl.Product2__r.Id) || prSteMap.get(prl.Product2__r.Id) == null) { |
| | | prSteMap.put(prl.Product2__r.Id,null); |
| | | } |
| | | } |
| | | |
| | | if ((prl.Product_Register__r.MedPrdClass__c == '2' || prl.Product_Register__r.MedPrdClass__c == '2') && prl.Product_Register__r.Stelsedag__c <> null) { |
| | | if ((prl.Product_Register__r.MedPrdClass__c == '2' || prl.Product_Register__r.MedPrdClass__c == '3') && prl.Product_Register__r.Stelsedag__c <> null && |
| | | newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c) { |
| | | if (prSte1Map.containsKey(prl.Product2__r.Id)) { |
| | | if (prSte1Map.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c) { |
| | | prSte1Map.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c); |
| | |
| | | }else { |
| | | prSte1Map.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c); |
| | | } |
| | | }else { |
| | | if (!prSte1Map.containsKey(prl.Product2__r.Id) || prSte1Map.get(prl.Product2__r.Id) == null) { |
| | | prSte1Map.put(prl.Product2__r.Id,null); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | if (pro2Map.size()>0) { |
| | | for (Product_Register_Link__c pr: pro2List) { |
| | | if (pro2Map.containsKey(pr.Product2__r.Id) && (prSteMap.containsKey(pr.Product2__r.Id) || prSte1Map.containsKey(pr.Product2__r.Id))) { |
| | | stedate = prSteMap.get(pr.Product2__r.Id)==null?prSte1Map.get(pr.Product2__r.Id)==null?null:prSte1Map.get(pr.Product2__r.Id):prSte1Map.get(pr.Product2__r.Id); |
| | | if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <> null && newMap.get(pr.Product2__r.Id).Diedatvanink__c <> null) { |
| | | if (pr.Product_Register__r.Stelsedag__c <> null) { |
| | | if (newMap.get(pr.Product2__r.Id).Diedatvanink__c <= stedate) { |
| | | if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3') { |
| | | System.debug('2'); |
| | | if (prlMap.get(pr.Product2__r.Id) == null) { |
| | | prlMap.put(pr.Product2__r.Id, '二类'); |
| | | }else { |
| | | String Lins = prlMap.get(pr.Product2__r.Id); |
| | | Lins += '二类'; |
| | | prlMap.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | }else if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && (pr.Product_Register__r.MedPrdClass__c == '1')) { |
| | | System.debug('1'); |
| | | if (prlMap.get(pr.Product2__r.Id) == null) { |
| | | prlMap.put(pr.Product2__r.Id, '一类'); |
| | | stedate = prSteMap.get(pr.Product2__r.Id)==null?(prSte1Map.get(pr.Product2__r.Id)==null?null:prSte1Map.get(pr.Product2__r.Id)):prSteMap.get(pr.Product2__r.Id); |
| | | if (stedate <> null) { |
| | | if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <> null && newMap.get(pr.Product2__r.Id).Diedatvanink__c <> null) { |
| | | if (pr.Product_Register__r.Stelsedag__c <> null) { |
| | | if (newMap.get(pr.Product2__r.Id).Diedatvanink__c <= stedate) { |
| | | if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3') { |
| | | System.debug('2'); |
| | | if (prlMap.get(pr.Product2__r.Id) == null || !prlMap.containsKey(pr.Product2__r.Id)) { |
| | | prlMap.put(pr.Product2__r.Id, '二类'); |
| | | }else { |
| | | String Lins = prlMap.get(pr.Product2__r.Id); |
| | | Lins += '一类'; |
| | | Lins += '二类'; |
| | | prlMap.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | }else { |
| | | System.debug('非'); |
| | | if (prlMap.get(pr.Product2__r.Id) == null) { |
| | | prlMap.put(pr.Product2__r.Id, '非监管'); |
| | | }else { |
| | | String Lins = prlMap.get(pr.Product2__r.Id); |
| | | Lins += '非监管'; |
| | | prlMap.put(pr.Product2__r.Id, Lins); |
| | | }else if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && (pr.Product_Register__r.MedPrdClass__c == '1')) { |
| | | System.debug('1'); |
| | | if (prlMap.get(pr.Product2__r.Id) == null || !prlMap.containsKey(pr.Product2__r.Id)) { |
| | | prlMap.put(pr.Product2__r.Id, '一类'); |
| | | }else { |
| | | String Lins = prlMap.get(pr.Product2__r.Id); |
| | | Lins += '一类'; |
| | | prlMap.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | } |
| | | }else if (newMap.get(pr.Product2__r.Id).Diedatvanink__c > stedate) { |
| | | if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && pr.Product_Register__r.MedPrdClass__c == '1') { |
| | | if (prl1Map.get(pr.Product2__r.Id) == null || !prl1Map.containsKey(pr.Product2__r.Id)) { |
| | | prl1Map.put(pr.Product2__r.Id, '一类'); |
| | | }else { |
| | | String Lins = prl1Map.get(pr.Product2__r.Id); |
| | | Lins += '一类'; |
| | | prl1Map.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | }else if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3') { |
| | | if (prl1Map.get(pr.Product2__r.Id) == null || !prl1Map.containsKey(pr.Product2__r.Id)) { |
| | | prl1Map.put(pr.Product2__r.Id, '二类'); |
| | | }else { |
| | | String Lins = prl1Map.get(pr.Product2__r.Id); |
| | | Lins += '二类'; |
| | | prl1Map.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | } |
| | | } |
| | | }else if (newMap.get(pr.Product2__r.Id).Diedatvanink__c > stedate) { |
| | | if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && pr.Product_Register__r.MedPrdClass__c == '1') { |
| | | if (prl1Map.get(pr.Product2__r.Id) == null) { |
| | | prl1Map.put(pr.Product2__r.Id, '一类'); |
| | | }else { |
| | | String Lins = prl1Map.get(pr.Product2__r.Id); |
| | | Lins += '一类'; |
| | | prl1Map.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | }else if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c |
| | | && pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3') { |
| | | if (prl1Map.get(pr.Product2__r.Id) == null) { |
| | | prl1Map.put(pr.Product2__r.Id, '二类'); |
| | | }else { |
| | | String Lins = prl1Map.get(pr.Product2__r.Id); |
| | | Lins += '二类'; |
| | | prl1Map.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | }else { |
| | | if (prlMap.get(pr.Product2__r.Id) == null) { |
| | | prlMap.put(pr.Product2__r.Id, '非监管'); |
| | | }else { |
| | | String Lins = prlMap.get(pr.Product2__r.Id); |
| | | Lins += '非监管'; |
| | | prlMap.put(pr.Product2__r.Id, Lins); |
| | | } |
| | | } |
| | | }else { |
| | | prl2Map.put(pr.Product2__r.Id, '空'); |
| | | } |
| | | }else { |
| | | prl2Map.put(pr.Product2__r.Id, '空'); |
| | | } |
| | | }else { |
| | | prl2Map.put(pr.Product2__r.Id, '空'); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | System.debug('stedate='+stedate); |
| | | System.debug('prlMap='+prlMap); |
| | | System.debug('prl1Map='+prl1Map); |
| | | |
| | | System.debug('prl2Map='+prl2Map); |
| | | //给产品上的等级类别字段赋值 |
| | | for (Product2 pr2: newList) { |
| | | if (prlMap.containsKey(pr2.Id)) { |
| | |
| | | pr2.Level_Category__c = '二类'; |
| | | }else if (prlMap.get(pr2.Id).contains('一类') && !prlMap.get(pr2.Id).contains('二类')) { |
| | | pr2.Level_Category__c = '一类'; |
| | | }else if (prlMap.get(pr2.Id).contains('非监管') && !prl2Map.containsKey(pr2.Id)) { |
| | | pr2.Level_Category__c = '非监管'; |
| | | }else { |
| | | pr2.Level_Category__c = null; |
| | | } |
| | | } |
| | | if (prl1Map.containsKey(pr2.Id)) { |
| | | }else if (prl1Map.containsKey(pr2.Id)) { |
| | | if (prl1Map.get(pr2.Id).contains('一类')) { |
| | | pr2.Level_Category__c = '一类'; |
| | | }else if (prl1Map.get(pr2.Id).contains('二类') && !prl1Map.get(pr2.Id).contains('一类')) { |
| | | pr2.Level_Category__c = '二类'; |
| | | }else if (prl1Map.get(pr2.Id).contains('非监管') && !prl2Map.containsKey(pr2.Id)) { |
| | | pr2.Level_Category__c = '非监管'; |
| | | }else { |
| | | pr2.Level_Category__c = null; |
| | | } |
| | | }else if (prl2Map.containsKey(pr2.Id)) { |
| | | pr2.Level_Category__c = '非监管'; |
| | | } |
| | | if (pr2.demoteer_Sap__c == null || pr2.Diedatvanink__c == null) { |
| | | pr2.Level_Category__c = null; |