public  with sharing    class InspectCheckController {
    public InspectCheckController() {

    }

    //根据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;
    }

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

 //20220913 you SWAG-CJ3DS5 start
      //招投标项目列表字段 irresponsibleReason__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.IsBid__c == '否') {
                temp.NotBidApprovalStatus__c = '草案中';
                temp.ownerid = UserInfo.getUserId();
            //}else{
            //    temp.NotBidApprovalStatus__c = null;
            //    temp.irresponsibleReasonOther__c = null;
            //    temp.irresponsibleReason__c = null;
            //    temp.irresponseApplyTime__c = null;
            //    temp.RepsExtraContent__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.IsBid__c == '否') {
                temp.NotBidApprovalStatus__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 SearchYH(String content,String[] his){

        String sql2 = 'select ';
        String props2 = CommonUtils.GetSqlToPorps(account.SObjectType);
        sql2 += props2;
        sql2 += ' from account';
        sql2 += ' where Id  in :his';
        List<account> arraysAccount = Database.query(sql2);
    
        List<String>  ids = new  List<String>();
        List<String> names =new  List<String>();
        for(account a : arraysAccount)
        {
            ids.Add(a.GI_Main__c);
            ids.Add(a.BF_owner__c);
            ids.Add(a.ET_owner__c);
            ids.Add(a.SP_Main__c);
            ids.Add(a.URO_owner_ID__c);
            ids.Add(a.GYN_owner__c);
            ids.Add(a.ENT_owner_ID__c);
            ids.Add(a.ENT_owner_ID__c);

            if(a.Energy_LeaderStr__c != null && a.Energy_LeaderStr__c != '')
            {
                string energy =  a.Energy_LeaderStr__c;
                string[] eneArr = energy.split(',');
                for(string item : eneArr)
                {
                    names.Add(item);
                }
            }
           

        }

 
        //select Id,Name,Alias from user where Name Like '%赖 思吕%' and (id in ('00510000006xTn0AAE') or  alias in ('思赖'))  limit 100
        content = '%'+content+'%';
        String sql = 'select ';
        String props = CommonUtils.GetSqlToPorps(user.SObjectType);
        sql += props;
        sql += ' from user';
        sql += ' where (Name  Like :content or alias Like :content)';
        sql += ' and (Id in :ids or alias in :names)';
        sql += ' and IsActive = true';
        sql += ' limit 5 ';
        List<user> arrays = Database.query(sql);
        return JSON.serialize(arrays); 
    }

    //查询普通科室
    // @AuraEnabled
    // public  static String SearchPTKS(String content,String ParentId){
    //     String jsonData = CommonUtils.GetPTKS(content,ParentId);
    //     return jsonData;
    // }

    //查询普通科室 有医院限制的
    // @AuraEnabled
    // public  static String SearchPTKSByYYParent(String content,String ParentId){
    //     String jsonData = CommonUtils.GetPTKSByYYParent(content,ParentId);
    //     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;
    } 


     //查询用户
     @AuraEnabled
     public  static String SearchUserByIds(String[] his){
 
         String sql2 = 'select ';
         String props2 = CommonUtils.GetSqlToPorps(account.SObjectType);
         sql2 += props2;
         sql2 += ' from account';
         sql2 += ' where Id  in :his';
         List<account> arraysAccount = Database.query(sql2);
     
         List<String>  ids = new  List<String>();
         List<String> names =new  List<String>();
         for(account a : arraysAccount)
         {
             ids.Add(a.GI_Main__c);
             ids.Add(a.BF_owner__c);
             ids.Add(a.ET_owner__c);
             ids.Add(a.SP_Main__c);
             ids.Add(a.URO_owner_ID__c);
             ids.Add(a.GYN_owner__c);
             ids.Add(a.ENT_owner_ID__c);
             ids.Add(a.ENT_owner_ID__c);
 
             if(a.Energy_LeaderStr__c != null && a.Energy_LeaderStr__c != '')
             {
                 string energy =  a.Energy_LeaderStr__c;
                 string[] eneArr = energy.split(',');
                 for(string item : eneArr)
                 {
                     names.Add(item);
                 }
             }
            
 
         }
         String sql = 'select ';
         String props = CommonUtils.GetSqlToPorps(user.SObjectType);
         sql += props;
         sql += ' from user';
         sql += ' where';
         sql += ' Id in :ids or alias in :names ';
        //  sql += ' and IsActive = true';
         List<user> arrays = Database.query(sql);
         return JSON.serialize(arrays); 
     }
     //为所有人赋值
    //  @AuraEnabled
    //  public  static String AssignValuesToOwner(String Id,String checkboxValue){
    //      if(checkboxValue!=null){
    //         String sql = 'select Id,Hospital__r.GI_Main__c,Hospital__r.BF_owner__c,Hospital__r.SP_Main__c,Hospital__r.URO_owner_ID__c,Hospital__r.GYN_owner__c,Hospital__r.ENT_owner_ID__c,OwnerId from Tender_information__c where Id = :Id';
    //         List<Tender_information__c> arrays = Database.query(sql);
    //         List<String> chekv = checkboxValue.split(';');
    //         Map<String,String> cmap = new Map<String,String>();
    //         if(arrays.size()!=0){
    //             Tender_information__c tic= new Tender_information__c();
    //             tic = arrays[0];
    //             // for (String chek : chekv) {
    //             //     if(chekv.contains('01210000000QemLAAS')){//&&tic.Hospital__r.GI_Main__c!=null
    //             //         tic.OwnerId=tic.Hospital__r.GI_Main__c;
    //             //     }else if(chekv.contains('01210000000QezZAAS')){
    //             //         tic.OwnerId=tic.Hospital__r.BF_owner__c;
    //             //     }else if(chekv.contains('01210000000QezeAAC')){
    //             //         tic.OwnerId=tic.Hospital__r.SP_Main__c;
    //             //     }else if(chekv.contains('01210000000QezjAAC')){
    //             //         tic.OwnerId=tic.Hospital__r.URO_owner_ID__c;
    //             //     }else if(chekv.contains('01210000000QezoAAC')){
    //             //         tic.OwnerId=tic.Hospital__r.GYN_owner__c;
    //             //     }else if(chekv.contains('01210000000QeztAAC')){
    //             //         tic.OwnerId=tic.Hospital__r.ENT_owner_ID__c;
    //             //     }else{
    //             //         System.debug('UserInfo.getUserId===='+UserInfo.getUserId());
    //             //         System.debug('tic.OwnerId===='+tic.OwnerId);
    //             //         if(tic.OwnerId!=UserInfo.getUserId()){
    //             //             tic.OwnerId=UserInfo.getUserId();
    //             //         }
    //             //         System.debug('tic.OwnerId2===='+tic.OwnerId);
    //             //     }
    //             // }
    //             update tic;
    //         }
    //      }
    //      return '成功';
    //  } 
    
}