public with sharing class LexSubmitCampaignController {
    //提交审批按钮 学会
    @AuraEnabled
    public static Campaign initSubmit(String recordId){
        try{
            Campaign res = [SELECT Id,Status,Is_LendProduct__c,EndDate
                FROM Campaign 
                    WHERE Id = : recordId];
            return res;
        }
        catch(Exception e){
            System.debug('lexSubmitCampaign,method:initSubmit   error: '+e.getMessage());
        }
        return null;
    }

    @AuraEnabled
    public static void newAndUpddateCampaign(String Id,String Status){
        try{    
            Campaign res = new Campaign();
            res.Id = Id;
            res.Status=Status;
            update res;
        }
        catch(Exception e){
            System.debug('lexSubmitCampaign,method:newAndUpddateCampaign   error: '+e.getMessage());
           
        }

    }

    
    @AuraEnabled
    public static String submitApprovalRequest(String recordId) {
        try{
           Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
           req.setObjectId(recordId);
           Approval.ProcessResult result = Approval.process(req);
           if(result!=null&&result.getErrors()!=null&&result.getErrors().size()>0) return result.getErrors().get(0).getMessage();
        }catch(Exception e){
            System.debug('lexSubmitCampaign,method:submitApprovalRequest submitApprovalRequest  error: '+e.getMessage());
            return e.getMessage();
        }
        return null;
    }

    //取消按钮 
    @AuraEnabled
    public static Campaign initCancle(String recordId){
        Campaign res = new Campaign();
        try {
            res = [SELECT Status,Id,CancleReason__c,IF_Submit__c
                                    From Campaign Where Id = :recordId];
            return res;
        }
        catch (Exception e) {
             System.debug('lexSubmitCampaign,method:initCancle   error: '+e.getMessage());
        }
        return res;
    }

    @AuraEnabled
    public static String newAndUpdateCampaignCancle(String campaignId ,String Status){

        try {
            Campaign res = new Campaign();
            res.Id = campaignId;
            res.Status =Status;
            update res;
            
        }
        catch (Exception e) {
            return e.getMessage();
        }
        return 'success';
    }    

    @AuraEnabled
    public static Campaign initMember(String recordId){
        Campaign res = new Campaign();
        try {
            res = [SELECT Status,Id,    ServiceDesignDep__c
                                    From Campaign Where Id = :recordId];
            return res;
        }
        catch (Exception e) {
             System.debug('lexSubmitCampaign,method:initCancle   error: '+e.getMessage());
        }
        return res;    
    }

    //取消按钮 CancleService
    @AuraEnabled
    public static Campaign initCancleService(String recordId){
        Campaign res = new Campaign();
        try {
            res = [SELECT Status,Id,CancleReason__c
                                    From Campaign Where Id = :recordId];
            return res;
        }
        catch (Exception e) {
             System.debug('lexSubmitCampaign,method:initCancle   error: '+e.getMessage());
        }
        return res;        
    }

    @AuraEnabled
    public static String cancleServiceNewAndUpdate(String Id,String Status,Boolean IsCancelFromOpen){
        Campaign res = new Campaign();
        try{
            res.Id = Id;
            res.Status = Status;
            res.IsCancelFromOpen__c = IsCancelFromOpen;
            UPDATE res;
            return 'success';
        }
        catch (Exception e) {
             System.debug('lexSubmitCampaign,method:initCancle   error: '+e.getMessage());
             return e.getMessage();
        }
        return 'success';
    }

    



}