From e6a0a7f9ffb463c5ce78d6770b09eac739f88b15 Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期三, 24 五月 2023 16:57:53 +0800
Subject: [PATCH] 优化确认框以及修改页面

---
 force-app/main/default/classes/OpportunityLightingButtonController.cls |  527 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 516 insertions(+), 11 deletions(-)

diff --git a/force-app/main/default/classes/OpportunityLightingButtonController.cls b/force-app/main/default/classes/OpportunityLightingButtonController.cls
index 45124f4..e88cb1e 100644
--- a/force-app/main/default/classes/OpportunityLightingButtonController.cls
+++ b/force-app/main/default/classes/OpportunityLightingButtonController.cls
@@ -4,7 +4,7 @@
  * @Author: chen jing wu
  * @Date: 2023-04-12 11:16:07
  * @LastEditors: chen jing wu
- * @LastEditTime: 2023-04-13 17:02:46
+ * @LastEditTime: 2023-05-24 16:34:15
  */
 public with sharing class OpportunityLightingButtonController {
     @AuraEnabled
@@ -65,8 +65,12 @@
             res.trade = opportunity.Trade__c;
             res.isCorrosion = opportunity.Is_Corrosion__c;
             res.ifAuthorizingLock = opportunity.If_Authorizing_Lock__c;
-            String profile18 = UserInfo.getProfileId();
-            res.profileId = profile18.substring(0,profile18.length() - 3);
+            res.profileId = UserInfo.getProfileId();
+            res.systemProfileId = getProfileIdByName(lexLightingButtonConstant.SYSTEM_PROFILE_NAME);
+            res.j3ProfileId = getProfileIdByName(lexLightingButtonConstant.J3_PROFILE_NAME);
+            res.s61ProfileId = getProfileIdByName(lexLightingButtonConstant.S61_PROFILE_NAME);
+            res.s62ProfileId = getProfileIdByName(lexLightingButtonConstant.S62_PROFILE_NAME);
+            res.m4ProfileId = getProfileIdByName(lexLightingButtonConstant.M4_PROFILE_NAME);
         } catch (Exception e) {
             System.debug('e:****' + e);
         }
@@ -117,7 +121,7 @@
         return res;
     }
     @AuraEnabled
-    public static InitData initFoBeforeOPDPDFBtnButton(String recordId){
+    public static InitData initForBeforeOPDPDFBtnButton(String recordId){
         InitData res = new InitData();
         try {
             Opportunity opportunity = [
@@ -176,10 +180,274 @@
             res.bidPlannedDate = opportunity.Bid_Planned_Date__c;
             res.salesAssistantName = opportunity.Sales_assistant_name__c;
             res.salesAssistantID = opportunity.Sales_assistant_ID__c;
-            String profileId18 = UserInfo.getProfileId();
-            res.profileId = profileId18.substring(0, profileId18.length() - 3);
+            res.profileId = UserInfo.getProfileId();
+            res.systemProfileId = getProfileIdByName(lexLightingButtonConstant.SYSTEM_PROFILE_NAME);
+            res.s1ProfileId = getProfileIdByName(lexLightingButtonConstant.S1_PROFILE_NAME);
+            res.s4ProfileId = getProfileIdByName(lexLightingButtonConstant.S4_PROFILE_NAME);
         } catch (Exception e) {
             System.debug('e:****' + e);
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForCancelReportButton(String recordId){
+        InitData res = new InitData();
+        try {
+        Opportunity opportunity = [
+            select
+            StageName,
+            SAP_Send_OK__c,
+            Cnt_Lost_cancel_report__c,
+            Cnt_Lost_cancel_Draft__c,
+            Job_category__c,
+            Bidding_Project_Name_Bid__c,
+            Name,
+            Sales_assistant_name__c,
+            Sales_assistant_ID__c,
+            Manager_name__c,
+            Sales_manager_departmentID__c,
+            Sales_owner_buchang__c,
+            Sales_owner_buchangID__c
+            from Opportunity where Id =: recordId
+        ];
+        res.stageName = opportunity.StageName;
+        res.sapSendOK = opportunity.SAP_Send_OK__c;
+        res.cntLostCancelReport = opportunity.Cnt_Lost_cancel_report__c;
+        res.cntLostCancelDraft = opportunity.Cnt_Lost_cancel_Draft__c;
+        res.jobCategory = opportunity.Job_category__c;
+        res.biddingProjectNameBid = opportunity.Bidding_Project_Name_Bid__c;
+        res.name = opportunity.Name;
+        res.salesAssistantName = opportunity.Sales_assistant_name__c;
+        res.salesAssistantID = opportunity.Sales_assistant_ID__c;
+        res.managerName = opportunity.Manager_name__c;
+        res.salesManagerDepartmentID = opportunity.Sales_manager_departmentID__c;
+        res.salesOwnerBuchang = opportunity.Sales_owner_buchang__c;
+        res.salesOwnerBuchangID = opportunity.Sales_owner_buchangID__c;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForLostReportButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opportunity = [
+                select
+                StageName,
+                SAP_Send_OK__c,
+                Cnt_Lost_cancel_report__c,
+                Name,
+                Sales_assistant_name__c,
+                Sales_assistant_ID__c,
+                Manager_name__c,
+                Sales_manager_departmentID__c,
+                Sales_owner_buchang__c,
+                Sales_owner_buchangID__c
+                from Opportunity where Id =: recordId
+            ];
+            res.stageName = opportunity.StageName;
+            res.sapSendOK = opportunity.SAP_Send_OK__c;
+            res.cntLostCancelReport = opportunity.Cnt_Lost_cancel_report__c;
+            res.name = opportunity.Name;
+            res.salesAssistantName = opportunity.Sales_assistant_name__c;
+            res.salesAssistantID = opportunity.Sales_assistant_ID__c;
+            res.managerName = opportunity.Manager_name__c;
+            res.salesManagerDepartmentID = opportunity.Sales_manager_departmentID__c;
+            res.salesOwnerBuchang = opportunity.Sales_owner_buchang__c;
+            res.salesOwnerBuchangID = opportunity.Sales_owner_buchangID__c;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForQuotationRequestButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opportunity = [
+                select
+                Bidding_Project_Name_Bid__r.Id,
+                Estimation_Id__c
+                from Opportunity where Id =: recordId
+            ];
+            res.biddingProjectNameBidId = opportunity.Bidding_Project_Name_Bid__r.Id;
+            res.estimationId = opportunity.Estimation_Id__c;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForStockApplyButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opportunity = [
+                select
+                Stock_apply_status__c,
+                Last_opportunity_file__r.Id
+                from Opportunity where Id =: recordId
+            ];
+            res.stockApplyStatus = opportunity.Stock_apply_status__c;
+            res.lastOpportunityFileId = opportunity.Last_opportunity_file__r.Id;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForQuotationProductNewButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opportunity = [
+                select
+                CurrencyIsoCode
+                from Opportunity where Id =: recordId
+            ];
+            res.currencyIsoCode = opportunity.CurrencyIsoCode;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForCopyWithAssetButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity oppo = [
+                select
+                Name,
+                SAP_Send_OK__c,
+                IsAuthorized__c
+                from Opportunity where Id =: recordId
+            ];
+            res.name = oppo.Name;
+            res.sapSendOK = oppo.SAP_Send_OK__c;
+            res.isAuthorized = oppo.IsAuthorized__c;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForNewOpportunityAgencyButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opp = [
+                select
+                Agency1__r.Id,
+                Agency_Opportunity__c,
+                Trade__c,
+                Hospital__r.Id,
+                Name,
+                Close_Forecasted_Date__c,
+                Bid_Planned_Date__c,
+                Dealer_Final_Price__c,
+                Wholesale_Price__c,
+                Agency1__r.Name,
+                Opportunity_stage__c,
+                Opportunity_Category__c
+                from Opportunity where Id =: recordId
+            ];
+            res.agency1Id = opp.Agency1__r.Id;
+            res.agencyOpportunity = opp.Agency_Opportunity__c;
+            res.trade = opp.Trade__c;
+            res.hospitalId = opp.Hospital__r.Id;
+            res.name = opp.Name;
+            res.closeForecastedDate = opp.Close_Forecasted_Date__c;
+            res.bidPlannedDate = opp.Bid_Planned_Date__c;
+            res.dealerFinalPrice = opp.Dealer_Final_Price__c;
+            res.wholesalePrice = opp.Wholesale_Price__c;
+            res.agency1 = opp.Agency1__c;
+            res.opportunityStage = opp.Opportunity_stage__c;
+            res.opportunityCategory = opp.Opportunity_Category__c;
+            res.agency1Name = opp.Agency1__r.Name;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForOpporSpliteButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity oppo = [
+                select
+                Authorized_DB_No__c,
+                Estimation_Decision__c,
+                SI_Decide_ID__c,
+                Name,
+                Opportunity_No__c,
+                IsAuthorized__c
+                from Opportunity where Id =: recordId
+            ];
+            res.authorizedDBNo = oppo.Authorized_DB_No__c;
+            res.estimationDecision = oppo.Estimation_Decision__c;
+            res.siDecideID = oppo.SI_Decide_ID__c;
+            res.name = oppo.Name;
+            res.opportunityNo = oppo.Opportunity_No__c;
+            res.isAuthorized = oppo.IsAuthorized__c;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForCreateActivityButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opp = [
+                select
+                AccountId
+                from Opportunity where Id =: recordId
+            ];
+            res.accountId = opp.AccountId;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForAssignTaskButtonButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opp = [
+                select
+                AccountId,
+                Name
+                from Opportunity where Id =: recordId
+            ];
+            Account acc = [
+                select
+                Name
+                from Account where Id =:opp.AccountId
+            ];
+            res.accountId = opp.AccountId;
+            res.accountName = acc.Name;
+            res.name = opp.Name;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+        return res;
+    }
+    @AuraEnabled
+    public static InitData initForChangeContractTypeButton(String recordId){
+        InitData res = new InitData();
+        try {
+            Opportunity opp = [
+                select
+                StageName,
+                Estimation_Decision__c,
+                SAP_Send_OK__c,
+                If_Authorizing_Lock__c
+                from Opportunity where Id =: recordId
+            ];
+            res.stageName = opp.StageName;
+            res.estimationDecision = opp.Estimation_Decision__c;
+            res.sapSendOK = opp.SAP_Send_OK__c;
+            res.ifAuthorizingLock = opp.If_Authorizing_Lock__c;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
         }
         return res;
     }
@@ -205,7 +473,7 @@
         try {
             Opportunity opp = new Opportunity();
             opp.Id = recordId;
-            opp.ConfirmationofAward__c = '绔炰簤瀵规墜涓爣';
+            opp.ConfirmationofAward__c = LightingButtonConstant.OPPORTUNITY_CONFIRMATION_OF_AWARD_LOSE_BID;
             update opp;
             return null;
         } catch (Exception e) {
@@ -219,9 +487,28 @@
     public static string updateForOLYwinBidButton(String recordId){
         try {
             Opportunity opp = [select ConfirmationofAward__c,Closing_Bid_Date__c from Opportunity where Id =: recordId];
-            opp.ConfirmationofAward__c = 'OLY涓爣';
+            opp.ConfirmationofAward__c = LightingButtonConstant.OPPORTUNITY_CONFIRMATION_OF_AWARD_OLY_WIN_BID;
             if (opp.Closing_Bid_Date__c == null) {
                 opp.Closing_Bid_Date__c = Date.today();
+            }
+            update opp;
+            return null;
+        } catch (Exception e) {
+            String eMessage = e.getMessage();
+            Integer left = eMessage.indexOf(',') + 1;
+            Integer right = eMessage.length();
+            return eMessage.substring(left,right);
+        }
+    }
+    @AuraEnabled
+    public static string updateForStockApplyButton(String recordId,Boolean flag){
+        try {
+            Opportunity opp = new Opportunity();
+            opp.Id = recordId;
+            if(flag){
+                opp.Stock_apply_status__c  = lexLightingButtonConstant.STOCK_APPLY_STATUS_WRITE_OVER;
+            }else {
+                opp.Stock_apply_status__c = lexLightingButtonConstant.STOCK_APPLY_STATUS_DRAFT;
             }
             update opp;
             return null;
@@ -239,7 +526,7 @@
             rac = [
                 select 
                 id 
-                from InquiryPredictsDateChange__c where Predicted_Date_Status__c = '瀹℃壒涓�' and Opportunity__c =:recordId];
+                from InquiryPredictsDateChange__c where Predicted_Date_Status__c = :LightingButtonConstant.PREDICTED_DATE_STATUS and Opportunity__c =:recordId];
         } catch (Exception e) {
             System.debug('e:****' + e);
         }
@@ -249,10 +536,11 @@
     public static List<task__c> queryForLoseBidButton(String recordId){
         List<task__c> tasks = null;
         try {
+            String obscureName = '%' + LightingButtonConstant.TASK_NAME_BY_CONFIRMATION_OF_WINNING_BID + '%';
             tasks = [
                 select
                 taskStatus__c
-                from task__c where OpportunityId__c =: recordId and name like '%涓爣缁撴灉纭%'];
+                from task__c where OpportunityId__c =: recordId and name like :obscureName];
         } catch (Exception e) {
             System.debug('e:****' + e);
         }
@@ -262,14 +550,171 @@
     public static List<task__c> queryForOLYwinBidButton(String recordId){
         List<task__c> tasks = null;
         try {
+            String obscureName = '%' + LightingButtonConstant.TASK_NAME_BY_CONFIRMATION_OF_WINNING_BID + '%';
             tasks = [
                 select
                 taskStatus__c
-                from task__c where OpportunityId__c =: recordId and name like '%涓爣缁撴灉纭%'];
+                from task__c where OpportunityId__c =: recordId and name like :obscureName];
         } catch (Exception e) {
             System.debug('e:****' + e);
         }
         return tasks;
+    }
+    @AuraEnabled
+    public static List<Tender_Opportunity_Link__c> queryForCancelReportButton(String recordId){
+        List<Tender_Opportunity_Link__c> links = null;
+        try {
+            links = [
+                select id,
+                Tender_information__r.subInfoType__c
+                from Tender_Opportunity_Link__c 
+                where (Tender_information__r.subInfoType__c =:lexLightingButtonConstant.SUB_INFO_TYPE_SCRAPPED_LABEL OR Tender_information__r.subInfoType__c =:lexLightingButtonConstant.SUB_INFO_TYPE_FLOW_LABEL) and Opportunity__c =: recordId
+            ];
+        } catch (Exception e) {
+            System.debug('e:****' + e);
+        }
+        return links;
+    }
+    @AuraEnabled
+    public static List<QuoteIrai__c > queryForQuotationRequestButton(String recordId){
+        List<QuoteIrai__c> quotes = null;
+        try {
+            String opportunityId = '%' + recordId + '%';
+            quotes = [
+                select 
+                id 
+                from QuoteIrai__c where Note__c like :opportunityId and QuoteIrai_Status__c =:lexLightingButtonConstant.QUOTEIRAI_STATUS_DRAFT
+            ];
+        } catch (Exception e) {
+            System.debug('e:****' + e);
+        }
+        return quotes;
+    }
+
+    @AuraEnabled
+    public static List<Agency_Hospital_Link__c> queryForNewOpportunityAgencyButtonToRecords(String agency1Id,String hospitalId){
+        List<Agency_Hospital_Link__c> links = null;
+        try {
+            links = [
+                SELECT 
+                Id, 
+                Name 
+                FROM Agency_Hospital_Link__c WHERE Agency__c =: agency1Id AND Hospital__c =: hospitalId
+            ];
+        } catch (Exception e) {
+            System.debug('e:****' + e);
+        }
+        return links;
+    }
+
+    @AuraEnabled
+    public static List<RecordType> queryForNewOpportunityAgencyButtonToRecTypeList(String sobjectType,String developerName,Boolean isActive){
+        List<RecordType> types = null;
+        try {
+            types = [
+                SELECT 
+                Id, 
+                Name FROM RecordType WHERE SobjectType =: sobjectType And developerName=: developerName And IsActive =: isActive 
+            ];
+        } catch (Exception e) {
+            System.debug('e:****' + e);
+        }
+        return types;
+    }
+
+    @AuraEnabled
+    public static List<FieldDefinition> queryForNewOpportunityAgencyButtonToRecords2(String qualifiedApiName){
+        List<FieldDefinition> fields = null;
+        try {
+            fields = [
+                select 
+                QualifiedApiName, 
+                EntityDefinition.KeyPrefix, 
+                DurableId From FieldDefinition WHERE EntityDefinition.QualifiedApiName =: qualifiedApiName
+            ];
+        } catch (Exception e) {
+            System.debug('e:****' + e);
+        }
+        return fields;
+    }
+    @AuraEnabled
+    public static Object submitProcess(String opportunityId) {
+        try {
+            Approval.ProcessSubmitRequest request = new Approval.ProcessSubmitRequest();
+            request.setObjectId(opportunityId);
+            Approval.ProcessResult[] processResults = new Approval.ProcessResult[] {};
+            processResults.add(Approval.process(request));
+            return processResults[0].errors;
+        } catch (Exception e) {
+            String eMessage = e.getMessage();
+            Integer left = eMessage.indexOf(',') + 1;
+            Integer right = eMessage.length();
+            return eMessage.substring(left,right);
+        }
+    }
+    @AuraEnabled
+    public static string getUserIdByName(String userName){
+        User user = null;
+        try {
+            user = [
+                select
+                Id
+                from User where Name =: userName
+            ];
+            return user.Id;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+    }
+    @AuraEnabled
+    public static string getProfileIdByName(String profileName){
+        Profile pro = null;
+        try {
+            pro = [
+                select
+                Id
+                from Profile where Name =: profileName
+            ];
+            return pro.Id;
+        } catch (Exception e) {
+            throw new AuraHandledException(e.getMessage());
+        }
+    }
+    @AuraEnabled
+    public static String changeTrade(String oppId){
+
+        List<Quote> quoList = [select id from Quote where OpportunityId = :oppId];
+        List<OpportunityLineItem> oppLI = [select id from OpportunityLineItem where Opportunity.id = :oppId];
+
+        Opportunity opp = new Opportunity();
+        opp.id = oppId;
+        opp.Estimation_Decision__c = false;
+        opp.Estimation_Id__c = null;
+        opp.Quote_Update_Sum__c = null;
+        opp.Estimation_No__c = null;
+        opp.Estimation_Proposal_Date__c = null;
+        opp.Estimation_Name__c = null;
+        // LHJ SWAG-C9QAAJ 鍘绘帀 Start
+        // opp.Authorized_Finish_Sales__c = null;
+        // opp.Authorized_DB_No__c = null;
+        // opp.Authorized_Date__c = null;
+        // opp.Autholization_Activated_Date__c = null;
+        // opp.Bidding_Content__c = null;
+        // opp.Bid_Date__c = null;
+        // opp.Bidding_No__c = null;
+        // opp.Bidding_Project_Name__c = null;
+        // LHJ End
+
+        Savepoint sp = Database.setSavepoint();
+        try {
+            delete quoList;
+            delete oppLI;
+            update opp;
+            return '1';     
+        } catch (Exception ex) {
+            Database.rollback(sp);
+            return  ex.getMessage() + ' | Line:' + ex.getLineNumber();
+        }
     }
     public class InitData{
         @AuraEnabled
@@ -328,5 +773,65 @@
         public String salesAssistantName;
         @AuraEnabled
         public String salesAssistantID;
+        @AuraEnabled
+        public String jobCategory;
+        @AuraEnabled
+        public String biddingProjectNameBid;
+        @AuraEnabled
+        public String managerName;
+        @AuraEnabled
+        public String salesManagerDepartmentID;
+        @AuraEnabled
+        public String salesOwnerBuchang;
+        @AuraEnabled
+        public String salesOwnerBuchangID;
+        @AuraEnabled
+        public String biddingProjectNameBidId;
+        @AuraEnabled
+        public String stockApplyStatus;
+        @AuraEnabled
+        public String lastOpportunityFileId;
+        @AuraEnabled
+        public String currencyIsoCode;
+        @AuraEnabled
+        public Boolean isAuthorized;
+        @AuraEnabled
+        public String agencyOpportunity;
+        @AuraEnabled
+        public String hospitalId;
+        @AuraEnabled
+        public Date closeForecastedDate;
+        @AuraEnabled
+        public Decimal dealerFinalPrice;
+        @AuraEnabled
+        public Decimal wholesalePrice;
+        @AuraEnabled
+        public String opportunityStage;
+        @AuraEnabled
+        public String opportunityCategory;
+        @AuraEnabled
+        public String agency1Name;
+        @AuraEnabled
+        public String authorizedDBNo;
+        @AuraEnabled
+        public String siDecideID;
+        @AuraEnabled
+        public String opportunityNo;
+        @AuraEnabled
+        public String systemProfileId;
+        @AuraEnabled
+        public String j3ProfileId;
+        @AuraEnabled
+        public String s62ProfileId;
+        @AuraEnabled
+        public String s61ProfileId;
+        @AuraEnabled
+        public String m4ProfileId;
+        @AuraEnabled
+        public String s4ProfileId;
+        @AuraEnabled
+        public String s1ProfileId;
+        @AuraEnabled
+        public String accountName;
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1