From 07390e2fcb4adf27c928335bf27ae7939c5a80ad Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期二, 23 五月 2023 11:28:12 +0800
Subject: [PATCH] bakcup20230523

---
 force-app/main/default/classes/lexPCLLostReportLwcController.cls |  206 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 141 insertions(+), 65 deletions(-)

diff --git a/force-app/main/default/classes/lexPCLLostReportLwcController.cls b/force-app/main/default/classes/lexPCLLostReportLwcController.cls
index 83c5603..51bc6f0 100644
--- a/force-app/main/default/classes/lexPCLLostReportLwcController.cls
+++ b/force-app/main/default/classes/lexPCLLostReportLwcController.cls
@@ -56,19 +56,72 @@
     } 
 
 	@AuraEnabled
-    public static List<String> getPickList(String objectName, String fieldName) {
-        List<String> values = new List<String>();
+    public static String getPickList(String objectName, String fieldName) {
+		List<Map<String, Object>> lstPickvals = new List<Map<String, Object>>();
         List<Schema.DescribeSobjectResult> results = Schema.describeSObjects(new List<String>{objectName});
         
         for(Schema.DescribeSobjectResult res : results) {
             for (Schema.PicklistEntry entry : res.fields.getMap().get(fieldName).getDescribe().getPicklistValues()) {
                 if (entry.isActive()) {
-                    values.add(entry.getValue());
+                    lstPickvals.add(new Map<String, Object>{'label' => entry.getValue(), 'value' => entry.getValue()});
                 }
             }
         }
-        return values;
+		Map<string,List<Map<String, Object>>> pickList =  new Map<string,List<Map<String, Object>>>();
+		List<Map<String, Object>> zhuji = new List<Map<String, Object>>();
+		List<Map<String, Object>> jingzi = new List<Map<String, Object>>();
+		List<Map<String, Object>> xiaojingzhong = new List<Map<String, Object>>();
+		List<Map<String, Object>> nengliang = new List<Map<String, Object>>();
+		List<Map<String, Object>> qita = new List<Map<String, Object>>();
+		Map<String, Object> empty = new Map<String, Object>{'label' => '--鏃�--', 'value' => ''};
+		zhuji.add(empty);
+		jingzi.add(empty);
+		xiaojingzhong.add(empty);
+		nengliang.add(empty);
+		qita.add(empty);
+		for (Integer i = 0; i < lstPickvals.size(); i++) {
+			if ((i >= 0 && i <= 6) || i == 36) {
+				zhuji.add(lstPickvals[i]);
+			}
+			if ((i >= 7 && i <= 23) || i == 36) {
+				jingzi.add(lstPickvals[i]);
+			}
+			if ((i >= 24 && i <= 29) || i == 35) {
+				xiaojingzhong.add(lstPickvals[i]);
+			}
+			if ((i >= 30 && i <= 34) || i == 36) {
+				nengliang.add(lstPickvals[i]);
+			}
+			if (i == 36) {
+				qita.add(lstPickvals[i]);
+			}
+		}
+		pickList.put('涓绘満', zhuji);
+		pickList.put('闀滃瓙', jingzi);
+		pickList.put('灏忛暅绉�', xiaojingzhong);
+		pickList.put('鑳介噺', nengliang);
+		pickList.put('鍏朵粬', qita);
+        return JSON.serialize(pickList);
     }
+	@AuraEnabled
+	public static String getPickListByFilter(String objectName,String fieldName,String controlFieldName,String controlFieldValue){
+		try {
+			Schema.DescribeFieldResult fieldDescribe = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap().get(fieldName).getDescribe();
+			// 濡傛灉璇ュ瓧娈典负閫夐」鍒楄〃绫诲瀷锛屽垯鑾峰彇閫夐」鍒楄〃
+			List<Schema.PicklistEntry> picklistValues = fieldDescribe.getPicklistValues();
+			// 鏍规嵁鎺у埗瀛楁鐨勫�肩瓫閫夊嚭瀵瑰簲鐨勯�夐」
+			List<Map<String, Object>> lstPickvals = new List<Map<String, Object>>();
+			for (Schema.PicklistEntry entry : picklistValues) {
+				if (entry.isActive() && entry.getValue().startsWith(controlFieldValue)) {
+					lstPickvals.add(new Map<String, Object>{'label' => entry.getValue(), 'value' => entry.getValue()});
+				}
+			}
+			String jsonStr = JSON.serialize(lstPickvals);
+			return jsonStr;
+		} catch (Exception e) {
+			throw new AuraHandledException(e.getMessage());
+		}
+	}
 
 
 	@AuraEnabled
@@ -298,20 +351,20 @@
 		}
 	}
 	// 淇濆瓨
-	@AuraEnabled
-	public static String save(){
-
-		if(!DataCheck()) {
-			return null;
-		}
-		if(!dataEntry()) {
-			return null;
-		}
-
-		brandCount = LostReport.LostBrands.size();
-		pageStatus = 'View';
-		return '淇濆瓨鎴愬姛锛�';
-	}
+	// @AuraEnabled
+	// public static String save(LostReport report){
+	// 	try {
+	// 		if(!dataEntry(report)) {
+	// 			return null;
+	// 		}
+	
+	// 		// brandCount = LostReport.LostBrands.size();
+	// 		pageStatus = 'View';
+	// 		return '淇濆瓨鎴愬姛锛�';
+	// 	} catch (Exception e) {
+	// 		return e.getMessage();
+	// 	}
+	// }
 	//璇诲彇骞舵瀯寤虹珵浜夊鎵嬪搧鐗�
 	// public void BrandmapSet(){
 	// 	CompetitionMap = new map<string, id>();
@@ -324,7 +377,8 @@
 	// }
 	// 鏁版嵁妫�鏌�
 	@AuraEnabled
-	public static boolean DataCheck(){
+	public static boolean DataCheck(LostReport report){
+		LostReport = report;
 		boolean dataCheck = true;
 		if(string.isBlank(LostReport.LostReport.LostType__c))
 		{
@@ -399,6 +453,7 @@
 			}
 			// 褰撳け鍗曞搧鐗屽悕涓哄叾浠栨椂,鎶ラ敊瀛楁涓哄け鍗曞鎵嬪瀷鍙凤紙鎵嬪姩锛� thh 2022-01-17 end
 		}
+		
 
 		return dataCheck;
 	}
@@ -425,10 +480,9 @@
 		String jsonStr = JSON.serialize(lstPickvals);
         return jsonStr;
 	}
-	@AuraEnabled
-	public static list<LostBrand> brandcopy(){
+	public static list<LostBrand> brandcopy(LostReport report){
 		list<LostBrand> tempbrands = new list<LostBrand>();
-		for(LostBrand tempbrand: LostReport.LostBrands) {
+		for(LostBrand tempbrand: report.LostBrands) {
 			LostBrand LostBrand =
 				new LostBrand(tempbrand.lineNo,tempbrand.LostProducts );
 			LostBrand.lostBrand = tempbrand.lostBrand.clone();
@@ -439,46 +493,47 @@
 	}
 	// 鏁版嵁褰曞叆
 	@AuraEnabled
-	public static boolean dataEntry(){
+	public static Map<String,String> dataEntry(String report1){
+		LostReport report = (LostReport)JSON.deserialize(report1, LostReport.class);
+		Map<String,String> messageMap = new Map <String,String>();
 		system.debug('save---start:');
 		Savepoint sp = Database.setSavepoint();
-		Lost_cancel_report__c templostReport = LostReport.lostReport.clone();
-		templostReport.id = LostReport.lostReport.id;
-		list<LostBrand> tempBrands = brandcopy();
 		try{
 			// 寰呭畬鎴愶紝杩欓噷闇�瑕佹妸绗竴涓搧鐗岀殑淇℃伅璧嬪�煎埌杩欎釜澶卞崟鎶ュ憡涓婂幓锛岃繕鏈夐渶瑕佹妸鍚勪釜鍝佺墝閲戦姹囨�诲姞璧锋潵锛�
 			//system.debug('LostReport.LostBrands:'+LostReport.LostBrands);
 			// 璁剧疆璁板綍绫诲瀷
-			LostReport.lostReport.recordTypeID  =  LostReport.lostReport.LostType__c== '澶卞崟'?Schema.SObjectType.Lost_cancel_report__c.getRecordTypeInfosByDeveloperName().get('PCL_Lost_report').getRecordTypeId() : Schema.SObjectType.Lost_cancel_report__c.getRecordTypeInfosByDeveloperName().get('PCL_PartLost_report').getRecordTypeId();
-			LostReport.lostReport.LostTotalAmount__c    = 0;
-			LostReport.lostReport.of_lost_system_processor__c   = 0;
-			LostReport.lostReport.Lost_reason_main__c = null;
-			LostReport.lostReport.Lost_Reason_Sub__c  = null;
-			LostReport.lostReport.Lost_By_Company__c = null;
-			for(LostBrand tempLostBrand : LostReport.LostBrands) {
+			report.lostReport.recordTypeID  =  report.lostReport.LostType__c== '澶卞崟'?Schema.SObjectType.Lost_cancel_report__c.getRecordTypeInfosByDeveloperName().get('PCL_Lost_report').getRecordTypeId() : Schema.SObjectType.Lost_cancel_report__c.getRecordTypeInfosByDeveloperName().get('PCL_PartLost_report').getRecordTypeId();
+			report.lostReport.LostTotalAmount__c    = 0;
+			report.lostReport.of_lost_system_processor__c   = 0;
+			report.lostReport.Lost_reason_main__c = null;
+			report.lostReport.Lost_Reason_Sub__c  = null;
+			report.lostReport.Lost_By_Company__c = null;
+			for(LostBrand tempLostBrand : report.LostBrands) {
 				if(string.isNotBlank(tempLostBrand.lostBrand.Lost_By_Company__c)) {
-					LostReport.lostReport.LostTotalAmount__c += tempLostBrand.lostBrand.LostPrice__c;
-					LostReport.lostReport.Lost_reason_main__c =
-						LostReport.lostReport.Lost_reason_main__c == null
+					report.lostReport.LostTotalAmount__c += tempLostBrand.lostBrand.LostPrice__c;
+					report.lostReport.Lost_reason_main__c =
+					report.lostReport.Lost_reason_main__c == null
 						? tempLostBrand.lostBrand.Lost_reason_main__c
-						: LostReport.lostReport.Lost_reason_main__c;
-					LostReport.lostReport.Lost_Reason_Sub__c  =
-						LostReport.lostReport.Lost_Reason_Sub__c == null
+						: report.lostReport.Lost_reason_main__c;
+						report.lostReport.Lost_Reason_Sub__c  =
+						report.lostReport.Lost_Reason_Sub__c == null
 						? tempLostBrand.lostBrand.Lost_Reason_Sub__c
-						: LostReport.lostReport.Lost_Reason_Sub__c;
-					LostReport.lostReport.Lost_By_Company__c =
-						LostReport.lostReport.Lost_By_Company__c == null
+						: report.lostReport.Lost_Reason_Sub__c;
+						report.lostReport.Lost_By_Company__c =
+						report.lostReport.Lost_By_Company__c == null
 						? tempLostBrand.lostBrand.Lost_By_Company__c
-						: LostReport.lostReport.Lost_By_Company__c;
+						: report.lostReport.Lost_By_Company__c;
 
 					for( PCLLostProducts tempLostProduct : tempLostBrand.LostProducts) {
 						if(tempLostProduct.LostProductss.Quantity__c !=null && tempLostProduct.LostProductss.Quantity__c >0) {
-							LostReport.lostReport.of_lost_system_processor__c   += tempLostProduct.LostProductss.Quantity__c;
+							report.lostReport.of_lost_system_processor__c   += tempLostProduct.LostProductss.Quantity__c;
 						}
 					}
 				}
 			}
-			upsert LostReport.lostReport;
+			upsert report.lostReport;
+			String reportId = report.lostReport.Id;
+			messageMap.put('reportId', reportId);
 			// 闇�瑕佹彃鍏ユ洿鏂扮殑澶卞崟鍝佺墝
 			map<integer,PCLLostBrand__c> upsertLostBrandMap = new map<integer,PCLLostBrand__c>();
 			// 闇�瑕佸垹鎺夌殑澶卞崟鍝佺墝
@@ -487,12 +542,12 @@
 			map<string,PCLLostProduct__c> upsertLostProductMap = new map<string,PCLLostProduct__c>();
 			// 闇�瑕佸垹鎺夌殑澶卞崟鍝佺墝
 			list<PCLLostProduct__c> deleteLostProductList = new list<PCLLostProduct__c>();
-			for(LostBrand tempLostBrand : LostReport.LostBrands ) {
+			for(LostBrand tempLostBrand : report.LostBrands ) {
 				// 濡傛灉鏈夊け鍗曞搧鐗岋紝閭d箞灏辫鎻掑叆鏇存柊锛�
 				system.debug('tempLostBrand.lostBrand.Lost_By_Company__c:'+tempLostBrand.lostBrand.Lost_By_Company__c);
 				if(string.isNotBlank(tempLostBrand.lostBrand.Lost_By_Company__c)) {
 					upsertLostBrandMap.put(tempLostBrand.lineNo,tempLostBrand.lostBrand);
-					tempLostBrand.lostBrand.Lost_cancel_report__c = LostReport.lostReport.id;
+					tempLostBrand.lostBrand.Lost_cancel_report__c = report.lostReport.id;
 					tempLostBrand.lostBrand.Name = tempLostBrand.lostBrand.Lost_By_Company__c;
 					integer tempNo = 0;
 					for( PCLLostProducts tempLostProduct : tempLostBrand.LostProducts) {
@@ -542,11 +597,11 @@
 
 			}
 
-			for(integer brandNumber =0; brandNumber< LostReport.LostBrands.size(); brandNumber++) {
+			for(integer brandNumber =0; brandNumber< report.LostBrands.size(); brandNumber++) {
 
-				LostBrand tempLostBrand = LostReport.LostBrands.get(brandNumber);
+				LostBrand tempLostBrand = report.LostBrands.get(brandNumber);
 				if(tempLostBrand.lostBrand.Id == null) {
-					LostReport.LostBrands.remove(brandNumber);
+					report.LostBrands.remove(brandNumber);
 					brandNumber--;
 					continue;
 				}
@@ -559,38 +614,36 @@
 					}
 				}
 			}
-			lostReportId = LostReport.lostReport.id;
+			// lostReportId = report.lostReport.id;
 			system.debug('save---end:');
 		}catch (Exception ex) {
 			Database.rollback(sp);
-			LostReport.lostReport = templostReport;
-			LostReport.LostBrands = tempBrands;
 			// 杩欓噷闇�瑕佸啓涓�浜涙姤閿欎俊鎭�
-			ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,ex.getMessage()));
-			return false;
+			messageMap.put('error', ex.getMessage());
+			return messageMap;
 		}
-		return true;
+		return messageMap;
 	}
 
 	
 	// 鎻愪氦
 	@AuraEnabled
-	public static Map<string,Object> submit(){
+	public static Map<string,Object> submit(LostReport report,String reportId){
 		Map<string,string> messages = new Map<string,string>();
-		if(!'鑽夋'.equals(LostReport.LostReport.Report_Status__c) ) {
+		if(!'鑽夋'.equals(report.lostReport.Report_Status__c) ) {
 			messages.put('error', '鍙湁鍦ㄨ崏妗堜腑鎵嶈兘鎻愪氦鐢宠锛�');
 			return messages;
 		}
 		Map<string,Object> objs = new Map<string,Object>();
 		Savepoint sp = Database.setSavepoint();
 		try{
-			LostReport.lostReport.Report_Status__c = '鎻愪氦';
-			update LostReport.lostReport;
+			report.lostReport.Report_Status__c = '鎻愪氦';
+			update report.lostReport;
 			Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
-			psr.setObjectId(lostReportId);
+			psr.setObjectId(reportId);
 			Approval.ProcessResult submitResult = Approval.process(psr);
 			objs.put('uri', '/apex/PCLLostReportPage');
-			objs.put('Id', lostReportId);
+			objs.put('Id', reportId);
 			objs.put('pageStatus', 'View');
 			objs.put('submitFlag', '1');
 			return objs;
@@ -649,6 +702,15 @@
 		tempLostBrand.ProductSize = tempLostBrand.LostProducts.size();
 		return null;
 	}
+	@AuraEnabled
+	public static PCLLostProducts getLostProduct(){
+		try {
+			PCLLostProduct__c plp = new PCLLostProduct__c();
+			return new PCLLostProducts(0,plp);
+		} catch (Exception e) {
+			throw new AuraHandledException(e.getMessage());
+		}
+	}
 	// update tcm 20211125 娣诲姞鍨嬪彿鏃惰嚜鍔ㄥ甫鍑哄搧鐗� end
 	// 椤甸潰鐨勬暟鎹粨鏋�
 	public class LostReport {
@@ -679,8 +741,6 @@
 		public list<PCLLostProducts> LostProducts;
 		@AuraEnabled
 		public Integer ProductSize;
-		@AuraEnabled
-		public List<Map<String,String>> columns;
 		public LostBrand( integer lineNo ){
 			lostBrand = new PCLLostBrand__c();
 			this.lineNo = lineNo;
@@ -709,7 +769,8 @@
 		public PCLLostProduct__c LostProductss;
 		@AuraEnabled
 		public Boolean bool;
-
+		@AuraEnabled
+		public List<Map<String, Object>> productOptions = new List<Map<String, Object>>();
 		public PCLLostProducts() {
 			this.lineNo2 = 0;
 			this.LostProductss=new PCLLostProduct__c();
@@ -752,4 +813,19 @@
 		}
 	}
 	// add tcm 20211118 end
+
+	@AuraEnabled
+	public static List<Product2> searchProduct(){
+		try {
+			List<Product2> products = [
+				select
+				Id,name
+				from Product2 
+				where Brand_Name__c = 'STORZ' limit 10
+			];
+			return products;
+		} catch (Exception e) {
+			throw new AuraHandledException(e.getMessage());
+		}
+	}
 }
\ No newline at end of file

--
Gitblit v1.9.1