public with sharing class LexConsumApply_FromCampaignCtl {
    public LexConsumApply_FromCampaignCtl() {

    }
    @AuraEnabled
    public static List<FieldDefinition> rentalApp(){
        try {
            List<FieldDefinition> rep = [Select QualifiedApiName, EntityDefinition.KeyPrefix, DurableId From FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Consum_Apply__c'];
            return rep;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

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

    @AuraEnabled
    public static InitData init(String recordId){
        InitData res = new initData();
        try {
            Campaign rep = [select Id,Name,Internal_in_charge_province__c,Status,Rental_Apply_Flag__c,RecordTypeId from Campaign where Id =: recordId];
            res.campaignId = rep.Id;
            res.name = rep.Name;
            res.chargeProvince = rep.Internal_in_charge_province__c == null ? '' : rep.Internal_in_charge_province__c;
            res.status = rep.Status;
            res.rentalApplyFlag = rep.Rental_Apply_Flag__c;
            res.recordTypeId = rep.RecordTypeId;
            res.servicetrainig = Schema.SObjectType.Campaign.getRecordTypeInfosByDeveloperName().get('Service_trainig').getRecordTypeId();
            return res;
        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }
    public class InitData{
        @AuraEnabled
        public String campaignId;
        @AuraEnabled
        public String chargeProvince;
        @AuraEnabled
        public String status;
        @AuraEnabled
        public Decimal rentalApplyFlag;
        @AuraEnabled
        public String recordTypeId;
        @AuraEnabled
        public String name;
        @AuraEnabled
        public String servicetrainig;
    }

    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 jobCategory;
        @AuraEnabled
        public string userprovince;
    }
}