public with sharing class LexVisitReportCancelController {

    @AuraEnabled
    public static String init(String recordId){
        try {
            Visit_Report__c vistReport = [SELECT Id, Status__c, OwnerId from Visit_Report__c WHERE Id = :recordId];
            UserResult currentUser = userInfoOwner();
            if(currentUser.Id == vistReport.OwnerId && vistReport.Status__c=='草案中'){
                Visit_Report__c updateData = new Visit_Report__c();
                updateData.Id = vistReport.Id;
                UPDATE updateData;
                return '取消成功';
            }else{
                return '只草案中状态及同行报告书的所有人可以取消';
            }
        }   
        catch (Exception e) {
           return e.getMessage(); 
        }
        
    }

    //获取当前登录人的Id
    public static UserResult userInfoOwner() {
        UserResult result = new UserResult();
        ID myUserID = UserInfo.getUserId();
        
        try { 
            User tempUser =
                [select id from user where id = : myUserID ];
            result.id = tempUser.id;
        } catch (exception e) {
            
            result.result = e.getMessage();
        }
        return result;
    }

    public class UserResult {
        @AuraEnabled
        public string result;
        public UserResult( ) {
            result = 'Success';
        }
        @AuraEnabled
        public string id;
        //20210105 CHAN-BWX3YU you end
    }
}