/*
 * @Author: zhangchunxu
 * @Date: 2023-07-17 10:21:05
 * @LastEditors: zhangchunxu
 * @LastEditTime: 2023-08-07 19:44:59
 * 
 */
public class ESignController {
    @AuraEnabled
    public static InitData ESignController (String recordId){
        InitData res = new initData();
        try{
            eSignForm__c report = [SELECT Id,Group_purchase_PCL__c,OCM_man_province_cus__c,HPSignUpStatus__c,Sales_Root_Formula__c,HPSignUpDate__c,agencyAutoSignUpStatus__c,agencySignUpDate__c,Statu_Achievements_DN__c  FROM eSignForm__c WHERE Id = :recordId LIMIT 1];
            res.Id = report.Id;
            res.GrouppurchasePCL = report.Group_purchase_PCL__c;
            res.OCMManProvinceCus = report.OCM_man_province_cus__c;
            res.HPSignUpStatus = report.HPSignUpStatus__c;
            res.agencyAutoSignUpStatus = report.agencyAutoSignUpStatus__c;
            res.SalesRootFormula = report.Sales_Root_Formula__c;
            res.HPSignUpDate = report.HPSignUpDate__c;
            res.agencySignUpDate = report.agencySignUpDate__c;
            res.profileId = UserInfo.getProfileId();
            res.userId = UserInfo.getUserId();
            res.systemProfileId = getProfileIdByName(LightingButtonConstant.SYSTEM_PROFILE_NAME);
            res.OBA4_sinFor = getProfileIdByName(LightingButtonConstant.OBA4_sinFor);
            res.StatuAchievementsDNId = report.Statu_Achievements_DN__c;
            System.debug(LoggingLevel.INFO, '*** res: ' + res);
        }catch(Exception e){
            System.debug(LoggingLevel.INFO, '*** e: ' + e);
        }
        return res;
    }

    @AuraEnabled
    public static string getProfileIdByName(String name){
        Profile profile = null;
        try {
            profile = [select Id from Profile where Name =:name];
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
        return profile.Id;
    }

    //检索OCSM管理省 上的营业管理部担当
    // var sql = "select id, Name, SalesManage__c from OCM_Management_Province__c where Name = "+"\'"+Group_purchase_PCL+"\'";
    // var ocsmResult = sforce.connection.query(sql);
    // var ocsm = ocsmResult.getArray("records");
    @AuraEnabled
    public static List<OCM_Management_Province__c> OcsmResult(String GrouppurchasePCL) {
        try { 
            list<OCM_Management_Province__c>  result = [SELECT Id, Name, SalesManage__c FROM OCM_Management_Province__c  WHERE Name = :GrouppurchasePCL];
            System.debug(LoggingLevel.INFO, '*** kebukeyi: ' + result);
            return result;
        } catch (Exception ex) {
            System.debug(LoggingLevel.INFO, '*** xingbuxing: ' + ex);
        }
        return null;
    }

    public class InitData{
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public Boolean GrouppurchasePCL;
        @AuraEnabled
        public String OCMManProvinceCus;
        @AuraEnabled
        public String HPSignUpStatus;
        @AuraEnabled
        public String agencyAutoSignUpStatus;
        @AuraEnabled
        public String SalesRootFormula;
        @AuraEnabled
        public Date HPSignUpDate;
        @AuraEnabled
        public Date agencySignUpDate;
        @AuraEnabled
        public String profileId;
        @AuraEnabled
        public String userId;
        @AuraEnabled
        public String systemProfileId;
        @AuraEnabled
        public String OBA4_sinFor;
        @AuraEnabled
        public String StatuAchievementsDNId;
    }
}