public with sharing class lexNewSparePartsLoanApplicationCtl {
    public lexNewSparePartsLoanApplicationCtl() {

    }

    //获取当前登录人的 id
    @AuraEnabled
    public static UserResult UserInfo_Owner() {
        UserResult result = new UserResult();
        ID myUserID = UserInfo.getUserId();
        try { 
            User tempUser =
                [select Id,Job_Category__c,isFormal_Stuff__c,FirstName,LastName,Province__c from user where id = : myUserID ];
            result.id = tempUser.Id;
            result.isFormalStuff = tempUser.isFormal_Stuff__c;
            result.firstName = tempUser.FirstName;
            result.lastName = tempUser.LastName;
            result.userProvince = tempUser.Province__c;
            result.userJobCategory = tempUser.Job_Category__c;
        } catch (exception e) {
            
            result.result = e.getMessage();
        }
        return result;
    }

    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try {
            List<OPDPlan__c> repList = [select Id,HospitalID__c,Related_Opportunity1_ID__r.Id,Campaign__r.Id,Status__c,Rental_Apply_Flag__c,OPDType__c,CampaignStatus__c,CampaignRecodeTypeId__c,Internal_in_charge_province__c,StayOrNot__c,OriginalOpdPlanApplication__c,IF_Approved__c,Approved_No__c,Approved_Status__c,Rental_Apply2__c,OriginalOpdPlan__c,CampaignName__c,Related_Opportunity1_ID__c,NoOpp_Reason__c,Account_Laboratory__c,OCM_category_Name__c,OCM_category_ID__c,HospitalName__c,Name,IsJump__c,JumpCause__c,originalOpdRentalApply__c,RentalApplyName__c from OPDPlan__c where Id =: recordId];
            if(repList.size() > 0){
                OPDPlan__c rep = repList[0];
                res.opdPlanId = rep.Id;
                res.opdHospitalId = rep.HospitalID__c == null ? '' : rep.HospitalID__c;
                res.opdCampaignId = rep.Campaign__r.Id == null ? '' : rep.Campaign__r.Id;
                res.opdOpportunityId = rep.Related_Opportunity1_ID__r.Id == null ? '' : rep.Related_Opportunity1_ID__r.Id;
                res.opdStatus = rep.Status__c == null ? '' : rep.Status__c;
                res.opdRentalApplyFlag = rep.Rental_Apply_Flag__c;
                res.opdType = rep.OPDType__c == null ? '' : rep.OPDType__c;
                res.opdCampaignStatus = rep.CampaignStatus__c == null ? '' : rep.CampaignStatus__c;
                res.opdCampaignRecodeTypeId = rep.CampaignRecodeTypeId__c == null ? '' : rep.CampaignRecodeTypeId__c;
                res.opdInternalinchargeprovince = rep.Internal_in_charge_province__c == null ? '' : rep.Internal_in_charge_province__c;
                res.opdStayOrNot = rep.StayOrNot__c == null ? '' : rep.StayOrNot__c;
                res.opdOriginalOpdPlanApplication = rep.OriginalOpdPlanApplication__c== null ? '' : rep.OriginalOpdPlanApplication__c;
                res.opdIFApproved = rep.IF_Approved__c;
                res.opdApprovedNo = rep.Approved_No__c == null ? '' : rep.Approved_No__c;
                res.opdApprovedStatus = rep.Approved_Status__c == null ? '' : rep.Approved_Status__c;
                res.opdRentalApply2 = rep.Rental_Apply2__c == null ? '' : rep.Rental_Apply2__c;
                res.opdOriginalOpdPlan = rep.OriginalOpdPlan__c == null ? '' : rep.OriginalOpdPlan__c;
                res.opdCampaignName = rep.CampaignName__c == null ? '' : rep.CampaignName__c;
                res.opdRelatedOpportunity1ID = rep.Related_Opportunity1_ID__c == null ? '' : rep.Related_Opportunity1_ID__c;
                res.opdNoOppReason = rep.NoOpp_Reason__c == null ? '' : rep.NoOpp_Reason__c;
                res.opdAccountLaboratory = rep.Account_Laboratory__c == null ? '' : rep.Account_Laboratory__c;
                res.opdOCMcategoryName = rep.OCM_category_Name__c == null ? '' : rep.OCM_category_Name__c;
                res.opdOCMcategoryId = rep.OCM_category_ID__c == null ? '' : rep.OCM_category_ID__c;
                res.opdHospitalName = rep.HospitalName__c == null ? '' : rep.HospitalName__c;
                res.opdName = rep.Name == null ? '' : rep.Name;
                res.opdIsJump = rep.IsJump__c;
                res.opdJumpCause = rep.JumpCause__c == null ? '' : rep.JumpCause__c;
                res.opdoriginalOpdRentalApply = rep.originalOpdRentalApply__c == null ? '' : rep.originalOpdRentalApply__c;
                res.opdRentalApplyName = rep.RentalApplyName__c == null ? '' : rep.RentalApplyName__c;
                res.opdStatusProcessState = System.Label.StatusProcessState;
                res.opdCampaignTypeId = Schema.SObjectType.Campaign.getRecordTypeInfosByDeveloperName().get('Service_trainig').getRecordTypeId();
                return res;
            }
            return null;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
    public class InitData{
        @AuraEnabled
        public String opdPlanId;
        @AuraEnabled
        public String opdCampaignId;
        @AuraEnabled
        public String opdOpportunityId;
        @AuraEnabled
        public String opdStatus;
        @AuraEnabled
        public Decimal opdRentalApplyFlag;
        @AuraEnabled
        public String opdType;
        @AuraEnabled
        public String opdCampaignStatus;
        @AuraEnabled
        public String opdCampaignRecodeTypeId;
        @AuraEnabled
        public String opdInternalinchargeprovince;
        @AuraEnabled
        public String opdStayOrNot;
        @AuraEnabled
        public String opdOriginalOpdPlanApplication;
        @AuraEnabled
        public Boolean opdIFApproved;
        @AuraEnabled
        public String opdApprovedNo;
        @AuraEnabled
        public String opdApprovedStatus;
        @AuraEnabled
        public String opdRentalApply2;
        @AuraEnabled
        public String opdOriginalOpdPlan;
        @AuraEnabled
        public String opdCampaignName;
        @AuraEnabled
        public String opdRelatedOpportunity1ID;
        @AuraEnabled
        public String opdNoOppReason;
        @AuraEnabled
        public String opdAccountLaboratory;
        @AuraEnabled
        public String opdOCMcategoryName;
        @AuraEnabled
        public String opdOCMcategoryId;
        @AuraEnabled
        public String opdHospitalName;
        @AuraEnabled
        public String opdHospitalId;
        @AuraEnabled
        public String opdName;
        @AuraEnabled
        public Boolean opdIsJump;
        @AuraEnabled
        public String opdJumpCause;
        @AuraEnabled
        public String opdoriginalOpdRentalApply;
        @AuraEnabled
        public String opdRentalApplyName;
        @AuraEnabled
        public String opdStatusProcessState;
        @AuraEnabled
        public String opdCampaignTypeId;
    }

    public class UserResult {
        @AuraEnabled
        public string result;
        public UserResult( ) {
            result = 'Success';
        }
        @AuraEnabled
        public string id;
        @AuraEnabled
        public Boolean isFormalStuff;
        @AuraEnabled
        public string firstName;
        @AuraEnabled
        public string lastName;
        @AuraEnabled
        public string userProvince;
        @AuraEnabled
        public string userJobCategory;
    }
}