19626
2023-09-09 e14d6d0619330cad423f06493e3aa2371faa2a8f
force-app/main/default/classes/ReportController.cls
@@ -2,6 +2,44 @@
用于给lwc的js初始化数据和对记录进行dml操作,此controller属于报告书
*/
public with sharing class ReportController {
    @AuraEnabled
    public static InitData initForOPDReportConsumButton(String recordId){
        InitData res = new initData();
        try {
            Consum_Apply__c con = [select RA_Status__c,Product_category__c,Id,Hospital__c,Strategic_dept__c,Account__c from Consum_Apply__c where Id =: recordId];
            res.raStatus = con.RA_Status__c;
            res.productCategory = con.Product_category__c;
            res.consumApplyId = con.Id;
            res.hospital = con.Hospital__c;
            res.strategicDept = con.Strategic_dept__c;
            res.account = con.Account__c;
            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());
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForOPDReportButton(String recordId){
        InitData res = new initData();
        try {
            Rental_Apply__c rent = [select RA_Status__c,Asset_return_day2__c,Hospital__c,Strategic_dept__c,Account__c,OPDPlan__c,Follow_UP_Opp__c,demo_purpose2__c from Rental_Apply__c where Id =: recordId];
            res.raStatus = rent.RA_Status__c;
            res.assetReturnDay2 = rent.Asset_return_day2__c;
            res.hospitalId = rent.Hospital__c;
            res.strategicDeptId = rent.Strategic_dept__c;
            res.accountId = rent.Account__c;
            res.demoPurpose2 = rent.demo_purpose2__c;
            res.followUPOpp = rent.Follow_UP_Opp__c;
            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());
        }
        return res;
    }
    //给VOC完毕相应的js提供初始化数据
    @AuraEnabled
    public static InitData initForVOCFinishButton (String recordId) {
@@ -32,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) {
@@ -223,6 +261,25 @@
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForNewOnLineSurveyButton(String recordId){
        InitData res = new InitData();
        try {
            Report__c re = [
                select
                Date__c,
                Practitioner1__c,
                OwnerId
                from Report__c where Id =: recordId
            ];
            res.ownerId = re.OwnerId;
            res.datec = re.Date__c;
            res.practitioner1 = re.Practitioner1__c;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return res;
    }
    //给提交相应的js提供初始化数据
    @AuraEnabled
@@ -236,10 +293,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    //OPDtoSIS操作更新相应数据
@@ -248,14 +313,22 @@
        try {
            Report__c rac = new Report__c();
            rac.Id = recordId;
            rac.RecordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_OPD).getRecordTypeId();
            rac.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_OPD).getRecordTypeId();
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
@@ -271,10 +344,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    //完毕操作更新相应数据
@@ -284,14 +365,22 @@
        try {
            rac.Id = recordId;
            rac.Status__c = LightingButtonConstant.STATUS_COMPLETE;
            rac.RecordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.VOC_NAME).getRecordTypeId();
            rac.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.VOC_NAME).getRecordTypeId();
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    //OCSM要报告操作更新相应数据
@@ -304,10 +393,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
@@ -317,14 +414,22 @@
        Report__c rac = new Report__c();
        try {
            rac.Id = recordId;
            rac.RecordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_FOLLOW_THE_STAGE).getRecordTypeId();
            rac.recordTypeId = Schema.SObjectType.Report__c.getRecordTypeInfosByName().get(LightingButtonConstant.RECORD_TYPE_NAME_BY_FOLLOW_THE_STAGE).getRecordTypeId();
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',') + 1;
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    //DispatchOCSMQARA操作更新相应数据
@@ -337,10 +442,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',');
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    //OCSM不要报告操作更新相应数据
@@ -353,10 +466,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',');
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
@@ -370,10 +491,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',');
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    
@@ -407,12 +536,22 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',');
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    //VOC回答更新相应数据
    @AuraEnabled
    public static String updateForVOCAnswerButton(String recordId){
@@ -422,14 +561,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            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;
            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();
            }
        }
    }
@@ -446,10 +589,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',');
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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();
            }
        }
    }
    //VOC回答更新相应数据
@@ -458,24 +609,39 @@
        try {
            Report__c rac = [select Status__c,JingliApprovalManager__r.Id,BuchangApprovalManager__r.Id,SalesManager__r.Id,BuchangApprovalManagerSales__r.Id,ZongjianApprovalManager__c,Submit_time__c,Submit_report_day__c,Owner.Id from Report__c where Id = :recordId];
            // share
            rac.Id = recordId;
            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 null;
            return rtn;
            }
            rac.Status__c = LightingButtonConstant.STATUS_VOC_WRITE_OVER;
            rac.Submit_time__c = Date.today();
@@ -483,10 +649,18 @@
            update rac;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',');
            Integer right = eMessage.length();
            return eMessage.substring(left, right);
            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();
            }
        }
    }
    //VOC判定更新相应数据
@@ -498,26 +672,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 {
@@ -541,10 +723,18 @@
            update report;
            return null;
        } catch (Exception e) {
            String eMessage = e.getMessage();
            Integer left = eMessage.indexOf(',');
            Integer right = eMessage.length();
            return eMessage.substring(left,right);
            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
@@ -610,10 +800,41 @@
        public String huDiAnId;
        @AuraEnabled
        public String systemProfileId;
        @AuraEnabled
        public String raStatus;
        @AuraEnabled
        public String productCategory;
        @AuraEnabled
        public String hospitalId;
        @AuraEnabled
        public String hospital;
        @AuraEnabled
        public String strategicDeptId;
        @AuraEnabled
        public String strategicDept;
        @AuraEnabled
        public String accountId;
        @AuraEnabled
        public String account;
        @AuraEnabled
        public String rentalApplyId;
        @AuraEnabled
        public String consumApplyId;
        @AuraEnabled
        public String recordTypeId;
        @AuraEnabled
        public String recordTypeId1;
        @AuraEnabled
        public Date assetReturnDay2;
        @AuraEnabled
        public String followUPOpp;
        @AuraEnabled
        public String demoPurpose2;
        @AuraEnabled
        public String opdPlan;
        @AuraEnabled
        public Date datec;
        @AuraEnabled
        public String practitioner1;
    }
}