public without sharing class ConsumableOtherArrDetController { // 订单 ID private String orderId = ''; public List otherArrDetIifo { get; set; } public ConsumableOtherArrDetController() { orderId = ApexPages.currentPage().getParameters().get('Id'); otherArrDetIifo = new List(); } // 画面初始化 public void init() { List arrDetIifo = new List(); List notArrDetIifo = new List(); List allArrDetIifo = new List(); // List conList = [SELECT id,Bar_Code__c FROM Consumable_order_details2__c WHERE Dealer_Arrive__c = true AND Consumable_order_minor__c = :orderId]; List conList = [SELECT id,Bar_Code__c FROM Consumable_order_details2__c WHERE Consumable_order_minor__c = :orderId]; Map srtMap = new Map(); for(Consumable_order_details2__c con : conList){ srtMap.put(con.Bar_Code__c, con.Id); } List str = new List(); for(String s : srtMap.keySet()){ str.add(srtMap.get(s)); } List arrDetList = [SELECT Asset_Model_No__c prodModel,count(Id) recordCount FROM Consumable_order_details2__c WHERE Id =: str AND Dealer_Arrive__c = true GROUP BY Asset_Model_No__c]; for(Integer i = 0 ; i< arrDetList.size();i++){ arrDetIifo.add(new showRecords(arrDetList[i])); } List notArrDetList = [SELECT Asset_Model_No__c prodModel,count(Id) recordCount FROM Consumable_order_details2__c WHERE Dealer_Arrive__c = false AND Consumable_order_minor__c = :orderId GROUP BY Asset_Model_No__c]; for(Integer i = 0 ; i< notArrDetList.size();i++){ notArrDetIifo.add(new showRecords(notArrDetList[i])); } // List allArrDetList = [SELECT Asset_Model_No__c prodModel,count(Id) recordCount FROM Consumable_order_details2__c // WHERE Id =: str // GROUP BY Asset_Model_No__c]; List allArrDetList = [SELECT Asset_Model_No__c,Consumable_count__c FROM Consumable_Orderdetails__c WHERE Consumable_order__c =: orderId]; // for(Integer i = 0 ; i< allArrDetList.size();i++){ // allArrDetIifo.add(new showRecords(notArrDetList[i])); // } Map arrDetMap = new Map(); for(showRecords arr : arrDetIifo){ arrDetMap.put(arr.prodModel, arr.recordCount); } for(showRecords notarr : notArrDetIifo){ if(arrDetMap.containsKey(notarr.prodModel)){ arrDetMap.put(notarr.prodModel, arrDetMap.get(notarr.prodModel)+notarr.recordCount); }else{ arrDetMap.put(notarr.prodModel, notarr.recordCount); } } List AssetModelNoEdList = new List();//20200904 ljh add for(Consumable_Orderdetails__c allarr : allArrDetList){ for(String promodel : arrDetMap.keySet()){ if(allarr.Asset_Model_No__c == promodel){ if((allarr.Consumable_count__c - arrDetMap.get(promodel)) > 0){ allarr.Consumable_count__c = (allarr.Consumable_count__c - arrDetMap.get(promodel)); otherArrDetIifo.add(allarr); } AssetModelNoEdList.add(promodel);//20200904 ljh add } } } //20200904 ljh add start for(Consumable_Orderdetails__c allarr1 : allArrDetList){ if(!AssetModelNoEdList.contains(allarr1.Asset_Model_No__c)){ otherArrDetIifo.add(allarr1); } } //20200904 ljh add end // for(Consumable_Orderdetails__c allarr : allArrDetIifo){ // for(String promodel : arrDetMap.keySet()){ // if(allarr.prodModel == promodel){ // if((allarr.recordCount - arrDetMap.get(promodel)) >= 0){ // allarr.recordCount = (allarr.recordCount - arrDetMap.get(promodel)); // otherArrDetIifo.add(allarr); // } // } // } // } } // Data Bean class showRecords implements Comparable { public Decimal recordCount { get; set; } public String prodModel { get; set; } public showRecords(AggregateResult e) { recordCount =Integer.valueOf(e.get('recordCount')); prodModel = String.valueOf(e.get('prodModel')); } // 排序 public Integer compareTo(Object compareTo) { return null; } } }