public  with sharing    class TerminateController {
    public TerminateController() {

    }

    //根据ID查询  招投标项目
    @AuraEnabled
    public  static string GetInspectById(String Id){
        QueryWrapper query = new QueryWrapper(Tender_information__c.SObjectType);
        query.eq('Id', Id);
        List<Tender_information__c> arrays = DataBasePlus.listPlus(query);
        return JSON.serialize(arrays); 
    }

    @AuraEnabled
    public static Boolean cannotModifyIsRelateProject(String Id){
        Boolean cannotModify = false;
        String profileIds = System.Label.Tender_IsnotRelated_ModifyDisable;
        System.debug('---lt123简档Id---'+UserInfo.getProfileId());
        // 判断当前用户简档
        if (profileIds.contains(UserInfo.getProfileId())) {
            // 获取招标项目 判断相关性
            Tender_information__c tender = [select Id, IsRelateProject__c from Tender_information__c where Id = :Id];
            if (tender != null && '是'.equals(tender.IsRelateProject__c)) {
                cannotModify = true;
            }
        }
        return cannotModify;
    }


     //招投标项目列表字段 irrelevantReasons__c 所有的值
    @AuraEnabled
    public  static string GetIrrelevantReasons(){
      String JsonData = CommonUtils.GetSelectedValues( Tender_information__c.irrelevantReasons__c.getDescribe());
      return JsonData;
    }

 
     //招投标项目列表字段 TerminateReason__c 所有的值
    @AuraEnabled
    public  static string GetIrresponsibleReason(){
      String JsonData = CommonUtils.GetSelectedValues( Tender_information__c.TerminateReason__c.getDescribe());
      return JsonData;
    }

 //20220913 you SWAG-CJ3DS5 start
      //招投标项目列表字段 TerminateReason__c 所有的值
    @AuraEnabled
    public  static string GetproInvolvedManual(){
      String JsonData = CommonUtils.GetSelectedValues( Tender_information__c.proInvolvedManual__c.getDescribe());
      return JsonData;
    }
//20220913 you SWAG-CJ3DS5 end  
  

      // 产品类
      public class Information {
        public  String hospital;//关联医院
        public  String account;// 关联普通科室
        public  String department;//关联医院
    }

    // 查询用户 根据父ID的值  
    @AuraEnabled
    public  static string  GetIsPrentIdArr(String Id){
        return CommonUtils.GetAccountPrentID(Id);
    }


    //保存数据  JSONData 是 招投标项目 对象的 json格式的值 
    @AuraEnabled
    public  static string  SaveData(String JsonData,String Id,String checkboxValue){
        try{
            Tender_information__c temp = (Tender_information__c)JSON.deserialize(JsonData,Tender_information__c.class);
            System.debug('temp=='+temp);
            
            StaticParameter.EscapeOtherUpdateTenOwner = false;
            update temp;
            StaticParameter.EscapeOtherUpdateTenOwner = true;
            
            //String assvale=AssignValuesToOwner(Id,checkboxValue);
        }catch(Exception ex)
        {
           return  ex.getMessage();
        }
        return  '成功';
    }

    //保存 应标数据 JSONData 是 招投标项目 对象的 json格式的值 
     @AuraEnabled
    public  static String SaveDataYB(String JsonData){
        try{
            Tender_information__c temp = (Tender_information__c)JSON.deserialize(JsonData,Tender_information__c.class);
          //if (temp.IsTerminate__c == '否') {
                temp.TerminateApprovalStatus__c = '草案中';
                temp.ownerid = UserInfo.getUserId();
            //}else{
            //    temp.TerminateApprovalStatus__c = null;
            //    temp.irresponsibleReasonOther__c = null;
            //    temp.TerminateReason__c = null;
            //    temp.irresponseApplyTime__c = null;
            //    temp.TerminateExtraContent__c = null;
            //}
            update temp;
        }catch(Exception ex)
        {
            return  ex.getMessage();
        }
        return  '成功';
    }

    //提交审核 应标数据 JSONData 是 招投标项目 对象的 json格式的值 
    @AuraEnabled
    public  static String ChangeDataYB(String JsonData){
        try{
            Tender_information__c temp = (Tender_information__c)JSON.deserialize(JsonData,Tender_information__c.class);
            if (temp.IsTerminate__c == '是') {
                temp.TerminateApprovalStatus__c = '填写完毕';
                temp.ownerid = UserInfo.getUserId();
            }
            update temp;
        }catch(Exception ex)
        {
            return  ex.getMessage();
        }
        return  '成功';
    }


    //查询战略科室
    @AuraEnabled
    public  static String SearchZLKS(String content,String[] ParentId){
        String jsonData = CommonUtils.GetZLKS(content,ParentId);
        return jsonData;
    }

    //查询医院
    @AuraEnabled
    public  static String SearchYY(String content){
        String jsonData = CommonUtils.GetYY(content);
        return jsonData;
    }

    //查询父类
    @AuraEnabled
    public  static String SearchParent(String Id){
        String jsonData = CommonUtils.GetParent(Id);
        return jsonData;
    }

    //查询医院下的科室
    @AuraEnabled
    public  static String SearchYYChilders(String content,String ParentId){
    String jsonData = CommonUtils.GetYYChilders(content,ParentId);
    return jsonData;
    }
       

     //根据id查询医院
     @AuraEnabled
     public  static String SearchAccountById(String Id){
        QueryWrapper query = new QueryWrapper(account.SObjectType);
        query.eq('Id',Id);
        List<account> arraysTemp = DataBasePlus.listPlus(query);
        return JSON.serialize(arraysTemp);  
     }

    //根据id查询用户
    @AuraEnabled
    public  static String SearchUserById(String Id){
        QueryWrapper query = new QueryWrapper(user.SObjectType);
        query.eq('Id',Id);
        List<user> arraysTemp = DataBasePlus.listPlus(query);
        return JSON.serialize(arraysTemp);  
    }


    //判断当前登录用户 是否是 所有人
    @AuraEnabled
    public  static String CheckOwner(String Id){
        String OwnerId = UserInfo.getUserId();
        String sql = 'select Id, owner.Id ,Name from Tender_information__c where  Id = :Id ';
        List<Tender_information__c> arrays = Database.query(sql);
        
        if(UserInfo.getProfileId() == System.Label.ProfileId_SystemAdmin)
        {
            return '1'+ '==' + '1';
        }
        if(arrays.size()<1)
        {
            return  '2'+ '==' + '1';
        }
        return OwnerId + '==' + arrays[0].owner.Id;
    } 

    
}