From ead4df22dca33a867279471821ca675f91dec760 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期六, 14 五月 2022 18:44:54 +0800
Subject: [PATCH] FixIssue0514

---
 force-app/main/default/classes/SearchSetProductController.cls |  245 +++++++++++++++++++++++++++---------------------
 1 files changed, 136 insertions(+), 109 deletions(-)

diff --git a/force-app/main/default/classes/SearchSetProductController.cls b/force-app/main/default/classes/SearchSetProductController.cls
index 478a847..0b8cf1a 100644
--- a/force-app/main/default/classes/SearchSetProductController.cls
+++ b/force-app/main/default/classes/SearchSetProductController.cls
@@ -1,142 +1,169 @@
 public class SearchSetProductController {
-  public Product_Set__c rc {get;set;}
-  public Product_Set__c sc {get;set;}
-  public List<Product_Set__c> cl {get;set;}
+	
+    public List<productSet__c> cl {get;set;}
 
-  public String SearchName {get;set;}
-  public String SearchCode {get;set;}
-  public String SearchPrice {get;set;}
-  public String SearchQuantity {get;set;}
+	public String SearchName {get;set;}
+	public String SearchCode {get;set;}
 
-  public String baseUrl {get;set;}
-  public String reportid {get;set;}
+	public Integer activitiesSize {get;set;}
+	public List<QELine> activities {get;set;}
+	public String setPFString {get;set;}
+    public String gainQuoteSetNameAndSetQty;
+    public Map<String,Decimal> setNameAndSetQtyMap;
+    public Map<String,Decimal> setNameAndSetDiscountMap;
+	public SearchSetProductController(){
+		this.setNameAndSetQtyMap = new Map<String,Decimal>();
+        this.setNameAndSetDiscountMap = new Map<String,Decimal>();
+        cl = new List<productSet__c>();
+        //鑾峰彇浠庡墠涓�涓〉闈紶杩囨潵鐨�"浜у搧閰嶅鍚嶇О"鍜�"浜у搧閰嶅鏁伴噺"
+        this.gainQuoteSetNameAndSetQty = Apexpages.currentPage().getParameters().get('gainQuoteSetNameAndSetQty');
+        system.debug('gainQuoteSetNameAndSetQty_Test_0_' + gainQuoteSetNameAndSetQty);
+        if (gainQuoteSetNameAndSetQty.length() >0) {
 
-  //public List<SSPLine> activities {get;set;}
-  public List<String> setProductidFullList{get;set;}
-  public List<SSPLine> activities {get;set;}
-  public String setPFString {get;set;}
-  public String DataStatus {get;set;}
-
-  //閫夐」鍚嶇О
-  public String filterName { get; set; }
-
-
+            for (String setNameAndSetQty : gainQuoteSetNameAndSetQty.split(';')) {
+                setNameAndSetQtyMap.put(setNameAndSetQty.split(',')[0],Decimal.valueOf(setNameAndSetQty.split(',')[1]));
+                setNameAndSetDiscountMap.put(setNameAndSetQty.split(',')[0], Decimal.valueOf(setNameAndSetQty.split(',')[2]));
+            }
+        }
+        system.debug('setNameAndSetQtyMap_Test_0_' + setNameAndSetQtyMap);
+	}
   public SearchSetProductController(ApexPages.StandardController controller){
-
-    rc = new Product_Set__c();
-    sc = new Product_Set__c();
-    cl = new List<Product_Set__c>();
-    baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
+    this();    
   }
 
   public void init(){
-    Report r = new Report();
-    List<Report> rs = new List<Report>();
-    rs=[Select id,DeveloperName,Name,NamespacePrefix from Report Where DeveloperName='Set_Product_Detail'];
-    if (rs.size()>0){
-        //system.debug('DeveloperName=' + rs[0].DeveloperName);
-        //system.debug('Name=' + rs[0].Name);
-        //system.debug('NamespacePrefix=' + rs[0].NamespacePrefix);
-        reportid = rs[0].id;
-        reportid = reportid.substring(0,15);
-    }
-  }
+    system.debug('gainQuoteSetNameAndSetQty_Test' + gainQuoteSetNameAndSetQty);
+    system.debug('setNameAndSetQtyMap_Test' + setNameAndSetQtyMap);
+    activitiesSize = 0;
+    
+    searchproductSet();
+    activitiesSize = activities.size();
+  } 
 
-  public PageReference serContact(){
-    String searchSql = 'Select id, name, Price__c, Product_Set_CD__c, Quantity__c,Valid_Status__c,Quote_Select_Info__c From Product_Set__c ';
-    String whereStr = 'Where Valid_Status__c = true ';
-    String whereSql = '';
+    public PageReference searchproductSet() {
 
-    if(SearchName != null && SearchName != ''){
-      whereSql += 'and name Like ' + '\'%' + SearchName + '%\' ';
-    }
+        //鏌ユ壘鏈夋晥鐨�"浜у搧閰嶅"
+        cl = [Select id, Name,Code__c From productSet__c Where  IsValid__c = true order by Name];
 
-    if(filterName != null && filterName != ''){
-      whereSql += 'and Applicable_Department__c =\'' + filterName + '\'';
-    }
+        activities = new List<QELine>();
+        List<QELine> selectedActivities = new List<QELine>();
+        //灏嗕笂涓〉闈紶杩囨潵鐨勪骇鍝侀厤濂楅�変腑锛屽苟鏀惧埌鍓嶉潰
+        for(productSet__c psl : cl){            
+            if (setNameAndSetQtyMap.containsKey(psl.Name)) {
+                QELine a = new QELine(psl);
+                a.Quantity =  setNameAndSetQtyMap.get(psl.Name);
+                a.QuantityReference = setNameAndSetQtyMap.get(psl.Name);
+                a.Discount = setNameAndSetDiscountMap.get(psl.Name);
+                a.isSelected = true;
+                selectedActivities.add(a);  
+            } 
+        
+        }
+        for(productSet__c psl : cl){
+            
+            if (!setNameAndSetQtyMap.containsKey(psl.Name)) {
+                QELine a = new QELine(psl);
+                a.Quantity = 0;
+                a.QuantityReference = 0;
+                a.Discount = 0 ;
+                selectedActivities.add(a); 
+            } else {
+                continue;
+            } 
+        }
+        activities = selectedActivities;
+        return null;   
+    } 
 
-    if(SearchCode != null && SearchCode != ''){
-      whereSql += 'and Product_Set_CD__c like ' + '\'%' + SearchCode + '%\' ';
-    }
-/*
-    if(SearchPrice != null && SearchPrice != ''){
-      whereSql += 'and Price__c = \'' + SearchPrice + '\' ';
-    }
+    public PageReference serContact(){
+        
+        String searchSql = 'Select id,Code__c,Name From productSet__c ';
+        String whereStr = 'Where  IsValid__c = true ';
+        String whereSql = '';
 
-    if(SearchQuantity != null && SearchQuantity != ''){
-      whereSql += 'and Quantity__c = \'' + SearchQuantity + '\' ';
-    }
-*/
-    searchSql = searchSql + whereStr + whereSql;
+        if(SearchName != null && SearchName != ''){
+            whereSql += ' and Name Like ' + '\'%' + SearchName + '%\' ';
+        }
 
-    searchSql += ' order by Product_Set_CD__c limit 500';
+        if(SearchCode != null && SearchCode != ''){
+          whereSql += 'and Code__c like ' + '\'%' + SearchCode + '%\' ';
+        }
 
-    cl = Database.query(searchSql);
-    activities = New List<SSPLine>();
-//    SSPLine a = new SSPLine();
-    for(Product_Set__c psl : cl){
-        SSPLine a = new SSPLine(psl);
-        activities.add(a);
-    }
-    return null;
+        searchSql = searchSql + whereStr + whereSql;
+
+        searchSql += ' order by Code__c limit 500';
+
+        cl = Database.query(searchSql);
+
+        Map<String,QELine> selectedQELineMap = new Map<String,QELine>();
+        if (activities.size() >0 ) {
+            for (QELine  q :activities) {
+                if (q.isSelected == true) {
+                    selectedQELineMap.put(q.setProductidFull, q);
+                } 
+            }
+        }
+
+        for(productSet__c psl : cl){
+            
+            if (!setNameAndSetQtyMap.containsKey(psl.Name)) {
+                QELine a = new QELine(psl);
+                if (selectedQELineMap.containsKey(a.setProductidFull)) {
+                    continue;
+                } else {
+                    a.Quantity = 0 ;
+                    selectedQELineMap.put(a.setProductidFull, a);
+                }
+                
+            } else {
+                continue;
+            }
+            
+            
+        }
+        activities = selectedQELineMap.values();
+        return null;
   }
   public void SelectDone(){
     setPFString = '';
-    setProductidFullList = New List<String>();
-    if(activities.size()==1){
-      setPFString = activities[0].setProductidFull;
-    }else{
-      for(SSPLine arc : activities){
+    String idAndQuantity ;
+
+    for (QELine arc :activities) {
+
         if(arc.isSelected==true){
-          if(String.isblank(setPFString)||setPFString==null){
-            setPFString = arc.setProductidFull;
-          }else{
-            setPFString = setPFString+','+arc.setProductidFull;
-          }
-          
+            
+            if (arc.Quantity > 0) {
+                idAndQuantity = arc.setProductidFull +','+ arc.Quantity +','+ arc.Discount;
+                
+                if(String.isblank(setPFString)||setPFString==null){
+                    
+                    setPFString = idAndQuantity;
+                }else{
+                    
+                    setPFString = setPFString +';'+ idAndQuantity;
+                }
+            }
+            
         }
-      }
     }
-    DataStatus = 'Fin';
+    
   }
 
-  //閫夐」鍗¢泦鍚�
-    public static List<SelectOption> getlistViewOptions() {
-        List<SelectOption> listViewOptions = new List<SelectOption>();
-        listViewOptions.add(new SelectOption('', '--鏃�--'));
-        listViewOptions.add(new SelectOption('娑堝寲绉�','娑堝寲绉�'));
-        listViewOptions.add(new SelectOption('鍛煎惛绉�','鍛煎惛绉�'));
-        listViewOptions.add(new SelectOption('鏅绉�','鏅绉�'));
-        listViewOptions.add(new SelectOption('娉屽翱绉�','娉屽翱绉�'));
-        listViewOptions.add(new SelectOption('濡囩','濡囩'));
-        listViewOptions.add(new SelectOption('鑰抽蓟鍠夌','鑰抽蓟鍠夌'));
-        listViewOptions.add(new SelectOption('鑳介噺','鑳介噺'));
-        listViewOptions.add(new SelectOption('SI','SI'));
-        listViewOptions.add(new SelectOption('澶栫閫氱敤','澶栫閫氱敤'));
-        return listViewOptions;
-    }
-
-    public class SSPLine {
+    public class QELine {
         public Boolean isSelected {get;set;}
-        public String setProductid { get; set; }
         public String setProductidFull { get; set; }
         public Decimal Quantity { get; set; }
-        public Product_Set__c theObject { get; set; }
+        public Decimal QuantityReference { get; set; }
+        public Decimal Discount { get; set; }
         public String Name { get; set; }       
-        public String Product_Set_CD_c { get; set; }
-        public String Quote_Select_Info_c { get; set; }
-        public Boolean Valid_c { get; set; }
+        public String Code { get; set; }
 
-        public SSPLine(Product_Set__c psl) {
-          isSelected = false;
-          setProductid = psl.id;
-	        setProductid = setProductid.substring(0,15);
+        public QELine(productSet__c psl) {
+            isSelected = false;
 	        setProductidFull = psl.id;
 	        Name = psl.Name;
-	        Product_Set_CD_c= psl.Product_Set_CD__c;
-	        Quantity = psl.Quantity__c;
-	        Quote_Select_Info_c = psl.Quote_Select_Info__c;
-	        Valid_c = psl.Valid_Status__c;
+            Code = psl.Code__c;
+	        
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1