From 988f9735377909b6310301e582c15804e004783f Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期六, 07 十月 2023 10:36:13 +0800
Subject: [PATCH] 近期修改cjw

---
 force-app/main/default/classes/lexPCLLostReportLwcController.cls |  209 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 174 insertions(+), 35 deletions(-)

diff --git a/force-app/main/default/classes/lexPCLLostReportLwcController.cls b/force-app/main/default/classes/lexPCLLostReportLwcController.cls
index 58c3650..a55853f 100644
--- a/force-app/main/default/classes/lexPCLLostReportLwcController.cls
+++ b/force-app/main/default/classes/lexPCLLostReportLwcController.cls
@@ -31,7 +31,11 @@
 	public static integer secondNum {get; set;}
 	// add tcm 20211122 end
 
-
+	@AuraEnabled(cacheable=true)
+    public static Id getUserProfileId() {
+        Id profileId = [SELECT ProfileId FROM User WHERE Id = :UserInfo.getUserId()].ProfileId;
+        return profileId;
+    }
 	@AuraEnabled
     public static String getPickList(String objectName, String fieldName) {
 		List<Map<String, String>> lstPickvals = new List<Map<String, String>>();
@@ -47,6 +51,8 @@
 		Map<string,List<Map<String, String>>> pickList =  new Map<string,List<Map<String, String>>>();
 		List<Map<String, String>> zhuji = new List<Map<String, String>>();
 		List<Map<String, String>> jingzi = new List<Map<String, String>>();
+		List<Map<String, String>> xixiaoji = new List<Map<String, String>>();
+		List<Map<String, String>> guangyuan = new List<Map<String, String>>();
 		List<Map<String, String>> xiaojingzhong = new List<Map<String, String>>();
 		List<Map<String, String>> nengliang = new List<Map<String, String>>();
 		List<Map<String, String>> qita = new List<Map<String, String>>();
@@ -57,19 +63,25 @@
 		nengliang.add(empty);
 		qita.add(empty);
 		for (Integer i = 0; i < lstPickvals.size(); i++) {
-			if ((i >= 0 && i <= 6) || i == 36) {
+			if ((i >= 0 && i <= 6) || i == 38) {
 				zhuji.add(lstPickvals[i]);
 			}
-			if ((i >= 7 && i <= 23) || i == 36) {
+			if ((i >= 7 && i <= 23) || i == 38) {
 				jingzi.add(lstPickvals[i]);
 			}
-			if ((i >= 24 && i <= 29) || i == 35) {
+			if ((i >= 24 && i <= 29) || i == 35|| i == 38) {
 				xiaojingzhong.add(lstPickvals[i]);
 			}
-			if ((i >= 30 && i <= 34) || i == 36) {
+			if ((i >= 30 && i <= 34) || i == 38) {
 				nengliang.add(lstPickvals[i]);
 			}
 			if (i == 36) {
+				guangyuan.add(lstPickvals[i]);
+			}
+			if (i == 37) {
+				xixiaoji.add(lstPickvals[i]);
+			}
+			if (i == 38) {
 				qita.add(lstPickvals[i]);
 			}
 		}
@@ -77,6 +89,8 @@
 		pickList.put('闀滃瓙', jingzi);
 		pickList.put('灏忛暅绉�', xiaojingzhong);
 		pickList.put('鑳介噺', nengliang);
+		pickList.put('娲楁秷鏈�', xixiaoji);
+		pickList.put('鍏夋簮', guangyuan);
 		pickList.put('鍏朵粬', qita);
         return JSON.serialize(pickList);
     }
@@ -156,7 +170,7 @@
 			 Manager_sales__c,recordtypeid,recordtype.DeveloperName
 			 from Lost_cancel_report__c
 			 where id =: lostReportId limit 1];
-
+			System.debug('chenjingwu' + lostReportList);
 			if(lostReportList.size() == 0) {
 				pageStatus = null;
 				maps.put('message', '鎮ㄦ病鏈夋煡鐪嬭繖涓け鍗�/閮ㄥ垎澶卞崟鎶ュ憡鐨勬潈闄愶紒');
@@ -193,11 +207,12 @@
 			[
 				select id, LostPrice__c, Lost_By_Company__c,
 				Lost_reason_main__c,Lost_Reason_Sub__c,Name,Agency__c, AgencyMannual__c,
-				// ProductCategory__c,ProductClass__c,
-				Lost_cancel_report__c,Lost_By_Company_Mannual__c,
+				Lost_cancel_report__c,Lost_By_Company_Mannual__c,ChannelSpecificReasons__c,
 				( select id,PCLLostBrand__c,LostProduct__c,
+				LostProduct__r.Name,
 				  LostProductMannual__c,            //SWAG-C6P9PX lt 20210913 add
-				  ProductCategory__c,ProductClass__c, //add tcm 20211123
+				  ProductCategory__c,
+				  ProductClass__c, //add tcm 20211123
 				  Quantity__c,Name, LostBrandName__c 
 				  from PCLLostBrand__c.PCLLostBrandProduct__r)
 				from PCLLostBrand__c
@@ -216,8 +231,11 @@
 					system.debug('check products:'+ (templostBrand.PCLLostBrandProduct__r != null) + '|' + (templostBrand.PCLLostBrandProduct__r.size() > 0));
 					if (templostBrand.PCLLostBrandProduct__r != null && templostBrand.PCLLostBrandProduct__r.size() > 0) {
 						for( PCLLostProduct__c tempProduct: templostBrand.PCLLostBrandProduct__r) {
-
-							tempProductList.add(new PCLLostProducts(productCount,tempProduct));
+							PCLLostProducts pro = new PCLLostProducts(productCount,tempProduct);
+							if(tempProduct.LostProduct__r.Name != null){
+								pro.productName = tempProduct.LostProduct__r.Name;
+							}
+							tempProductList.add(pro);
 							productCount++;
 						}
 					} else {
@@ -230,10 +248,15 @@
 								newProduct.LostProductss.LostBrandName__c = templostBrand.Lost_By_Company__c;
 							}
 							system.debug('aaa4+++'+templostBrand.Lost_By_Company_Mannual__c);
+							
 						tempProductList.add(newProduct);
 						productCount++;
 					}
-					LostBrandList.add( new LostBrand(brandCount,tempProductList, templostBrand));
+					LostBrand br = new LostBrand(brandCount,tempProductList, templostBrand);
+					if(tempLostBrand.ChannelSpecificReasons__c != null){
+						br.reasonFlag = true;
+					}
+					LostBrandList.add(br);
 					brandCount++;
 				}
 
@@ -245,8 +268,29 @@
 		// 璇诲彇绔炰簤瀵规墜鍝佺墝
 		// BrandmapSet();
 		
-		if (LostReport.lostReport.Report_Status__c != '鑽夋' && lostReportId != null) {
-			ProcessInstance pro = [
+		if (lostReportId != null) {
+			// List<ProcessInstance> pros = [
+			// SELECT 
+			// ProcessDefinition.Name,
+			// 	(
+			// 	SELECT 
+			// 	Id,
+			// 	StepStatus, 
+			// 	IsPending,
+			// 	Comments,
+			// 	CreatedDate,
+			// 	Actor.Name,  
+			// 	OriginalActor.Name,
+			// 	ProcessNode.Name FROM StepsAndWorkitems order by IsPending DESC, CreatedDate DESC 
+			// )
+			// FROM ProcessInstance where TargetObjectId =:LostReport.lostReport.id order by CreatedDate DESC
+			// ];
+			// List<ProcessInstanceHistory> items = new List<ProcessInstanceHistory>();
+			// for(ProcessInstance pro: pros){
+			// 	items.add(pro.StepsAndWorkitems);
+			// }
+			// LostReport.approvalHistorys = items;
+			List<ProcessInstance> pros = [
 			SELECT 
 			ProcessDefinition.Name,
 				(
@@ -262,8 +306,19 @@
 			)
 			FROM ProcessInstance where TargetObjectId =:LostReport.lostReport.id order by CreatedDate DESC
 			];
+			if(pros.size() > 0){
+				List<ProcessInstanceHistory> items = new List<ProcessInstanceHistory>();
+				for(ProcessInstance pro: pros){
+					items.addAll(pro.StepsAndWorkitems);
+				}
+				LostReport.approvalHistorys = items;
+			}else{
+				List<ProcessInstanceHistory> items = new List<ProcessInstanceHistory>();
+				LostReport.approvalHistorys = items;
+			}
+			
+		}else{
 			List<ProcessInstanceHistory> items = new List<ProcessInstanceHistory>();
-			items.addall(pro.StepsAndWorkitems);
 			LostReport.approvalHistorys = items;
 		}
 		if(string.isNotEmpty(submitFlag)) {
@@ -309,7 +364,12 @@
                                   from BatchIF_Transfer__c
                                   where Dropped_Flag__c = false
                                           and Table__c = 'PCLLostBrand__c' and Column__c = 'Lost_By_Company__c' and External_value__c =: productName];
-			return transfer[0].Internal_value__c;
+			if(transfer.size() > 0){
+				return transfer[0].Internal_value__c;
+			}else{
+				return null;
+			}
+			
 		} catch (Exception e) {
 			throw new AuraHandledException(e.getMessage());
 		}
@@ -317,6 +377,7 @@
 	// 鏁版嵁褰曞叆
 	@AuraEnabled
 	public static Map<String,String> dataEntry(String report1,List<Id> deleteBrandIdList,List<Id> deleteProductIdList){
+		// LostReport report = (LostReport)JSON.deserializeUntyped(report1, LostReport.class);
 		LostReport report = (LostReport)JSON.deserialize(report1, LostReport.class);
 		Map<String,String> messageMap = new Map <String,String>();
 		system.debug('save---start:');
@@ -332,8 +393,8 @@
 			report.lostReport.Lost_Reason_Sub__c  = null;
 			report.lostReport.Lost_By_Company__c = null;
 				//鎵瑰噯鏃ヤ笉涓虹┖鏃剁粰淇敼鍚庡啀鎵瑰噯璧嬪��
-			if(LostReport.lostReport.Approved_Day__c != null){
-				LostReport.lostReport.ModifyAfterApproval__c = true;
+			if(report.lostReport.Approved_Day__c != null){
+				report.lostReport.ModifyAfterApproval__c = true;
 			}
 			for(LostBrand tempLostBrand : report.LostBrands) {
 				if(string.isNotBlank(tempLostBrand.lostBrand.Lost_By_Company__c)) {
@@ -451,7 +512,7 @@
 				}
 			}
 			if (report.lostReport.Report_Status__c != '鑽夋') {
-				ProcessInstance pro = [
+				List<ProcessInstance> pros = [
 				SELECT 
 				ProcessDefinition.Name,
 				 (
@@ -468,16 +529,33 @@
 				FROM ProcessInstance where TargetObjectId =:reportId order by CreatedDate DESC
 				];
 				List<ProcessInstanceHistory> items = new List<ProcessInstanceHistory>();
-				items.addall(pro.StepsAndWorkitems);
+				for(ProcessInstance pro: pros){
+					items.addAll(pro.StepsAndWorkitems);
+				}
+				report.approvalHistorys = items;
+			}else{
+				List<ProcessInstanceHistory> items = new List<ProcessInstanceHistory>();
 				report.approvalHistorys = items;
 			}
 			// lostReportId = report.lostReport.id;
 			system.debug('save---end:');
 			messageMap.put('LostReport',JSON.serialize(report));
-		}catch (Exception ex) {
+		}catch (Exception e) {
 			Database.rollback(sp);
 			// 杩欓噷闇�瑕佸啓涓�浜涙姤閿欎俊鎭�
-			messageMap.put('error', ex.getMessage());
+			if (e.getMessage().contains(',')) {
+                System.debug(LoggingLevel.INFO, '*** e: ' + e);
+                String exc = '' + e.getMessage();
+                Integer left = exc.indexOf(':') + 1;
+                Integer right = exc.lastIndexOf(':');
+                String str = exc.substring(left,right);
+                left = str.indexOf(',') +  1;
+                String newStr = str.substring(left);
+                messageMap.put('error', ''+ newStr);
+            }else {
+                messageMap.put('error', ''+ e.getMessage());
+            }
+			
 			return messageMap;
 		}
 		return messageMap;
@@ -486,19 +564,20 @@
 	
 	// 鎻愪氦
 	@AuraEnabled
-	public static Map<string,Object> submit(String report1,String reportId){
-		LostReport report = (LostReport)JSON.deserialize(report1, LostReport.class);
+	public static Map<string,Object> submit(String reportStatus,Boolean modifyAfterApproval,String reportId){
+		// LostReport report = (LostReport)JSON.deserialize(report1, LostReport.class);
 		Map<string,string> messages = new Map<string,string>();
-		if(!'鑽夋'.equals(report.lostReport.Report_Status__c) && LostReport.LostReport.ModifyAfterApproval__c == false) {
+		if(!'鑽夋'.equals(reportStatus) && modifyAfterApproval == false) {
 			messages.put('error', '鍙湁鍦ㄨ崏妗堜腑鎵嶈兘鎻愪氦鐢宠锛�');
 			return messages;
 		}
 		Map<string,Object> objs = new Map<string,Object>();
+		Lost_cancel_report__c report = new Lost_cancel_report__c();
 		Savepoint sp = Database.setSavepoint();
 		try{
-			report.lostReport.Id = reportId;
-			report.lostReport.Report_Status__c = '鎻愪氦';
-			update report.lostReport;
+			report.Id = reportId;
+			report.Report_Status__c = '鎻愪氦';
+			update report;
 			// Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
 			// psr.setObjectId(reportId);
 			// Approval.ProcessResult submitResult = Approval.process(psr);
@@ -506,7 +585,7 @@
 			objs.put('Id', reportId);
 			objs.put('pageStatus', 'View');
 			objs.put('submitFlag', '1');
-			ProcessInstance pro = [
+			List<ProcessInstance> pros = [
 				SELECT 
 				ProcessDefinition.Name,
 				 (
@@ -522,13 +601,28 @@
 				)
 				FROM ProcessInstance where TargetObjectId =:reportId order by CreatedDate DESC
 			];
+			
 			List<ProcessInstanceHistory> items = new List<ProcessInstanceHistory>();
-			items.addall(pro.StepsAndWorkitems);
+			for(ProcessInstance pro:pros){
+				items.addAll(pro.StepsAndWorkitems);
+			}
+			
 			objs.put('approvalHistorys',items);
 			return objs;
-		}catch(exception ex) {
+		}catch(exception e) {
 			Database.rollback(sp);
-			messages.put('error', ex.getMessage());
+			if (e.getMessage().contains(',')) {
+                System.debug(LoggingLevel.INFO, '*** e: ' + e);
+                String exc = '' + e.getMessage();
+                Integer left = exc.indexOf(':') + 1;
+                Integer right = exc.lastIndexOf(':');
+                String str = exc.substring(left,right);
+                left = str.indexOf(',') +  1;
+                String newStr = str.substring(left);
+                objs.put('error', ''+ newStr);
+            }else {
+                objs.put('error', ''+ e.getMessage());
+            }
 			return messages;
 		}
 	}
@@ -591,9 +685,14 @@
 		public list<PCLLostProducts> LostProducts;
 		@AuraEnabled
 		public Integer ProductSize;
+		@AuraEnabled
+		public Boolean reasonFlag = false;
+		@AuraEnabled
+		public String brandTitle; 
 		public LostBrand( integer lineNo ){
 			lostBrand = new PCLLostBrand__c();
 			this.lineNo = lineNo;
+			this.brandTitle = '澶卞崟鍝佺墝' + (lineNo + 1);
 			LostProducts = new list<PCLLostProducts> {new PCLLostProducts()};
 			ProductSize = 1;
 			lostBrand = new PCLLostBrand__c();
@@ -601,12 +700,14 @@
 		public LostBrand( integer lineNo, list<PCLLostProducts> LostProducts ){
 			lostBrand = new PCLLostBrand__c();
 			this.lineNo = lineNo;
+			this.brandTitle = '澶卞崟鍝佺墝' + (lineNo + 1);
 			this.LostProducts = LostProducts;
 			ProductSize = LostProducts.size();
 		}
 		public LostBrand( integer lineNo, list<PCLLostProducts> LostProducts,  PCLLostBrand__c lostBrand){
 			this.lostBrand = lostBrand;
 			this.lineNo = lineNo;
+			this.brandTitle = '澶卞崟鍝佺墝' + (lineNo + 1);
 			this.LostProducts = LostProducts;
 			ProductSize = LostProducts.size();
 		}
@@ -647,11 +748,12 @@
 	public static void search() {
 		if (LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.LostProduct__c==null) {
 			LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductClass__c=null;
-			LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductCategory__c=null;
 			LostReport.LostBrands[topNum].LostProducts[secondNum].bool=false;
 
 		}else {
-			Product2 prd = [select Id,ProductClass__c, ProductCategory__c from Product2 where Id =:LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.LostProduct__c];
+			Product2 prd = [select Id,ProductClass__c
+			, ProductCategory__c 
+			from Product2 where Id =:LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.LostProduct__c];
 			if (prd.ProductCategory__c!=null) {
 				LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductClass__c=prd.ProductClass__c;
 				LostReport.LostBrands[topNum].LostProducts[secondNum].LostProductss.ProductCategory__c=prd.ProductCategory__c;
@@ -668,7 +770,10 @@
 	public static string searchProduct(String lostProduct){
 		Product2 prd = null;
 		try {
-			prd = [select Id,ProductClass__c, ProductCategory__c from Product2 where Id =:lostProduct];
+			prd = [select Id
+			,ProductClass__c
+			, ProductCategory__c 
+			from Product2 where Id =:lostProduct];
 		} catch (Exception e) {
 			throw new AuraHandledException(e.getMessage());
 		}
@@ -677,4 +782,38 @@
 
 	// add tcm 20211118 end
 
+	@AuraEnabled
+    public static String submitForApproval(String recordId, String comments,String action){
+		try {
+			List<ProcessInstanceWorkitem> workItems = [
+            SELECT Id, ProcessInstanceId 
+            FROM ProcessInstanceWorkitem 
+            WHERE ProcessInstance.TargetObjectId = :recordId 
+			];
+			Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
+			req.setWorkitemId(workItems.get(0).Id);
+			req.setAction(action);
+			req.setComments(comments);
+		
+				
+			Approval.ProcessResult result = Approval.process(req);
+			return null; 
+		} catch (Exception e) {
+			return e.getMessage();
+		}
+        
+    }
+
+	@AuraEnabled
+    public static String reassignStep(String recordId, String newActorId ){
+		try {
+			List<ProcessInstanceWorkItem> workItemList = [SELECT ActorId FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId = : recordId];
+        	ApprovalHistoryUtil.reassignStep(workItemList, newActorId);
+			return null;
+		} catch (Exception e) {
+			return e.getMessage();
+		}
+        
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.1