public without sharing class searchHospitalController {

    public String SearchName {get;set;}
    private String accountid = null;
    public List<Account> at {get;set;}
    //经销商产品分类
    public String agencyProType {get;set;}

    public void init(){
        User useracc = [SELECT accountid,UserPro_Type__c FROM user WHERE id = :UserInfo.getUserId() ];
        accountid = Useracc.accountid;
        // DB202309406949 gzw start
        agencyProType = Useracc.UserPro_Type__c;
        String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Address__c FROM Account';
        soql += ' where id in (SELECT Hospital__c FROM hospitalprice__c WHERE account__c = :accountid and Product_Type_F__c = :agencyProType) ' ;
        soql += ' order by Name desc limit 100';
        System.debug('soql+++++++++: ' + soql);
        // DB202309406949 gzw end
        at = Database.query(soql);
    }

    public PageReference serContact(){
        at = Database.query(this.makeSoql(SearchName,accountid));
        return null;
    }

    private String makeSoql(String searchName,String accountid){
        // DB202309406949 gzw start
        String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Address__c FROM Account';
        soql += ' where id in (SELECT Hospital__c FROM hospitalprice__c WHERE account__c = :accountid and Product_Type_F__c = :agencyProType) ' ;
        // DB202309406949 gzw end
        if(String.isNotBlank(searchName)){
            soql += ' AND Name like \'%' + SearchName+ '%\'';
        }
        soql += ' order by Name desc limit 100';
        System.debug('soql+++++++++: ' + soql);
        return soql;

    }
}