From 1727a4f4d02e429475608e60f142a63bc24127bc Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期一, 23 十月 2023 10:07:34 +0800
Subject: [PATCH] 近期修改

---
 force-app/main/default/classes/ReportController.cls |  381 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 235 insertions(+), 146 deletions(-)

diff --git a/force-app/main/default/classes/ReportController.cls b/force-app/main/default/classes/ReportController.cls
index 518ec43..fc6ccde 100644
--- a/force-app/main/default/classes/ReportController.cls
+++ b/force-app/main/default/classes/ReportController.cls
@@ -17,7 +17,7 @@
             res.recordTypeId1 = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(lexLightingButtonConstant.RECORD_TYPE_NAME_BY_SIS_ENG).getRecordTypeId();
             res.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(lexLightingButtonConstant.RECORD_TYPE_NAME_BY_SIS_ET).getRecordTypeId();
         } catch (Exception e) {
-            throw new AuraHandledException(e.getMessage());
+            System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
         return res;
     }
@@ -36,7 +36,7 @@
             res.opdPlan = rent.OPDPlan__c;
             res.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(lexLightingButtonConstant.RECORD_TYPE_NAME_BY_OPD).getRecordTypeId();
         } catch (Exception e) {
-            throw new AuraHandledException(e.getMessage());
+            System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
         return res;
     }
@@ -70,7 +70,7 @@
             res.profileId = UserInfo.getProfileId();
             res.userId = UserInfo.getUserId();
             res.luShengId = getUserIdByName(LightingButtonConstant.LU_SHENG_NAME);
-            res.huDiAnId = getUserIdByName(LightingButtonConstant.HU_DI_AN_NAME);
+            // res.huDiAnId = getUserIdByName(LightingButtonConstant.HU_DI_AN_NAME);
             res.systemProfileId = getProfileIdByName(LightingButtonConstant.SYSTEM_PROFILE_NAME);
             System.debug(LoggingLevel.INFO, '*** res: ' + res);
         } catch (Exception e) {
@@ -257,7 +257,7 @@
         try {
            res =  new InitData();
         } catch (Exception e) {
-            throw new AuraHandledException(e.getMessage());
+            System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
         return res;
     }
@@ -276,7 +276,7 @@
             res.datec = re.Date__c;
             res.practitioner1 = re.Practitioner1__c;
         } catch (Exception e) {
-            throw new AuraHandledException(e.getMessage());
+            System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
         return res;
     }
@@ -293,14 +293,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     //OPDtoSIS鎿嶄綔鏇存柊鐩稿簲鏁版嵁
@@ -313,14 +318,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
 
@@ -336,14 +346,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     //瀹屾瘯鎿嶄綔鏇存柊鐩稿簲鏁版嵁
@@ -357,14 +372,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     //OCSM瑕佹姤鍛婃搷浣滄洿鏂扮浉搴旀暟鎹�
@@ -377,14 +397,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
 
@@ -398,14 +423,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     //DispatchOCSMQARA鎿嶄綔鏇存柊鐩稿簲鏁版嵁
@@ -418,14 +448,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     //OCSM涓嶈鎶ュ憡鎿嶄綔鏇存柊鐩稿簲鏁版嵁
@@ -438,14 +473,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
 
@@ -459,14 +499,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     
@@ -500,14 +545,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
 
@@ -521,18 +571,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            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);
-                return newStr;
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // } 
+            return e.getDmlMessage(0);
         }
     }
 
@@ -549,14 +600,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     //VOC鍥炵瓟鏇存柊鐩稿簲鏁版嵁
@@ -568,17 +624,33 @@
             User[] records = [SELECT  Job_Category__c FROM User WHERE Id = :createdById];
             List<String> userAccess = new List<String>();
             if (records[0].Job_Category__c == LightingButtonConstant.TYPE_OF_SALES_SERVICES) {
-            userAccess.add(rac.JingliApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
-            userAccess.add(rac.BuchangApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
-            rac.VOC_CreatedBy_jingli__c = rac.JingliApprovalManager__c;
-            rac.VOC_CreatedBy_buzhang__c = rac.BuchangApprovalManager__c;
-            } else {
-            userAccess.add(rac.SalesManager__c + LightingButtonConstant.USER_ACCESS_READ);
-            userAccess.add(rac.BuchangApprovalManagerSales__c + LightingButtonConstant.USER_ACCESS_READ);
-            rac.VOC_CreatedBy_jingli__c = rac.SalesManager__c;
-            rac.VOC_CreatedBy_buzhang__c = rac.BuchangApprovalManagerSales__c;
+            if(rac.JingliApprovalManager__c != null){
+                userAccess.add(rac.JingliApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
+                rac.VOC_CreatedBy_jingli__c = rac.JingliApprovalManager__c;
             }
-            userAccess.add(rac.ZongjianApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
+            if(rac.BuchangApprovalManager__c != null){
+                userAccess.add(rac.BuchangApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
+                rac.VOC_CreatedBy_buzhang__c = rac.BuchangApprovalManager__c;
+            }
+            
+            
+            } else {
+                if(rac.SalesManager__c != null){
+                    userAccess.add(rac.SalesManager__c + LightingButtonConstant.USER_ACCESS_READ);
+                    rac.VOC_CreatedBy_jingli__c = rac.SalesManager__c;
+                }
+                if(rac.BuchangApprovalManagerSales__c != null){
+                    userAccess.add(rac.BuchangApprovalManagerSales__c + LightingButtonConstant.USER_ACCESS_READ);
+                    rac.VOC_CreatedBy_buzhang__c = rac.BuchangApprovalManagerSales__c;
+                }
+           
+            
+            
+            
+            }
+            if(rac.ZongjianApprovalManager__c != null){
+                userAccess.add(rac.ZongjianApprovalManager__c + LightingButtonConstant.USER_ACCESS_READ);
+            }
             String rtn = ControllerUtil.setSObjectShare(LightingButtonConstant.SOBJECT_NAME_OF_REPORT_SHARE,LightingButtonConstant.SOBJECT_NAME_OF_VOC_SHARE,recordId,userAccess,rac.Owner.Id);
             if (rtn != LightingButtonConstant.OK) {
             return rtn;
@@ -589,14 +661,19 @@
             update rac;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
+            return e.getDmlMessage(0);
         }
     }
     //VOC鍒ゅ畾鏇存柊鐩稿簲鏁版嵁
@@ -608,26 +685,34 @@
                 // VOC瀵惧繙鑰呫伄绲岀悊閮ㄩ暦绶忕洠銈掕ō瀹�
                 User[] records = [SELECT Id, Job_Category__c, JingliApprovalManager__c, SalesManager__c, BuchangApprovalManager__c, BuchangApprovalManagerSales__c, ZongjianApprovalManager__c FROM User WHERE Id = :personId];
                 if (records[0].job_Category__c == LightingButtonConstant.TYPE_OF_SALES_SERVICES) {
-                    rac.VOC_jingli__c = records[0].JingliApprovalManager__c == null ? '' : records[0].JingliApprovalManager__c;
-                    rac.VOC_buzhang__c = records[0].BuchangApprovalManager__c == null ? '' : records[0].BuchangApprovalManager__c;
+                    rac.VOC_jingli__c = records[0].JingliApprovalManager__c == null ? null : records[0].JingliApprovalManager__c;
+                    rac.VOC_buzhang__c = records[0].BuchangApprovalManager__c == null ? null : records[0].BuchangApprovalManager__c;
                 } else {
-                    rac.VOC_jingli__c = records[0].SalesManager__c == null ? '' : records[0].SalesManager__c;
-                    rac.VOC_buzhang__c = records[0].BuchangApprovalManagerSales__c == null ? '' : records[0].BuchangApprovalManagerSales__c;
+                    rac.VOC_jingli__c = records[0].SalesManager__c == null ? null : records[0].SalesManager__c;
+                    rac.VOC_buzhang__c = records[0].BuchangApprovalManagerSales__c == null ? null : records[0].BuchangApprovalManagerSales__c;
                 }
-                rac.VOC_zongjian__c = records[0].ZongjianApprovalManager__c == null ? '' : records[0].ZongjianApprovalManager__c;
+                rac.VOC_zongjian__c = records[0].ZongjianApprovalManager__c == null ? null : records[0].ZongjianApprovalManager__c;
                 rac.Status__c = LightingButtonConstant.STATUS_VOC_CHECK_OVER;
                 rac.VOC_Finish__c = false;
                 Date serverTimestamp = Date.today();
                 rac.VOC_share_date__c = serverTimestamp;
                 // share
                 List<String> userAccess = new List<String>();
-                userAccess.add(rac.Responsible_Person__c + LightingButtonConstant.USER_ACCESS_EDIT);
-                userAccess.add(rac.VOC_jingli__c + LightingButtonConstant.USER_ACCESS_READ);
-                userAccess.add(rac.VOC_buzhang__c + LightingButtonConstant.USER_ACCESS_READ);
-                userAccess.add(rac.VOC_zongjian__c + LightingButtonConstant.USER_ACCESS_READ);
+                if(rac.Responsible_Person__c != null){
+                    userAccess.add(rac.Responsible_Person__c + LightingButtonConstant.USER_ACCESS_EDIT);
+                }
+                if(rac.VOC_jingli__c != null){
+                    userAccess.add(rac.VOC_jingli__c + LightingButtonConstant.USER_ACCESS_READ);
+                }
+                if(rac.VOC_buzhang__c != null){
+                    userAccess.add(rac.VOC_buzhang__c + LightingButtonConstant.USER_ACCESS_READ);
+                }
+                if(rac.VOC_zongjian__c != null){
+                    userAccess.add(rac.VOC_zongjian__c + LightingButtonConstant.USER_ACCESS_READ);
+                }
                 String rtn = ControllerUtil.setSObjectShare(LightingButtonConstant.SOBJECT_NAME_OF_REPORT_SHARE,LightingButtonConstant.SOBJECT_NAME_OF_VOC_SHARE,recordId,userAccess,rac.Owner.Id);
                 if (rtn != LightingButtonConstant.OK) {
-                    return null;
+                    return rtn;
                 }
                 update rac;
                 } else {
@@ -637,9 +722,7 @@
                 }
                 return null;
         } catch (Exception e) {
-            System.debug(LoggingLevel.INFO, '*** e: ' + e);
-            String exc = e.getMessage();
-            return exc;
+            return e.getDmlMessage(0);
         }
     }
     //VOC瀹屾瘯鎿嶄綔鏇存柊鐩稿簲鏁版嵁
@@ -651,14 +734,19 @@
             update report;
             return null;
         } catch (Exception e) {
-            if (e.getMessage().contains(',')) {
-                String eMessage = e.getMessage();
-                Integer left = eMessage.indexOf(',');
-                Integer right = eMessage.length();
-                return eMessage.substring(left,right);
-            }else {
-                return e.getMessage();   
-            }  
+            return e.getDmlMessage(0);
+            // 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);
+            //     return newStr;
+            // }else {
+            //     return e.getMessage();   
+            // }
         }
     }
     @AuraEnabled
@@ -667,7 +755,7 @@
         try {
             user = [select Id from User where Name =:name]; 
         } catch (Exception e) {
-            throw new AuraHandledException(e.getMessage());
+            System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
         return user.Id;
     }
@@ -677,10 +765,11 @@
         try {
             profile = [select Id from Profile where Name =:name];
         } catch (Exception e) {
-            throw new AuraHandledException(e.getMessage());
+            System.debug(LoggingLevel.INFO, '*** e: ' + e);
         }
         return profile.Id;
     }
+    
     public class InitData{
         @AuraEnabled
         public String status;

--
Gitblit v1.9.1