19626
2023-09-09 e14d6d0619330cad423f06493e3aa2371faa2a8f
force-app/main/default/classes/Xin_SearchVisitorPlace.cls
@@ -47,7 +47,7 @@
        Map<Id, Account> accMap = new Map<Id, Account>((List<Account>) Database.query(queryString));
       if (accMap.size() <= 50) {
           // さらに省単位のデータを検索
           Map<Id, Account> stateDepartmentMap = ControllerUtil.selectDepartByHospitalState(nameCondition, reporterState, 51 - accMap.size());
           Map<Id, Account> stateDepartmentMap = selectDepartByHospitalState(nameCondition, reporterState, 51 - accMap.size());
           if (stateDepartmentMap.size() > 0) {
               for (Id accId : stateDepartmentMap.keySet()) {
                   if (!accMap.containsKey(accId)) {
@@ -60,4 +60,23 @@
       this.results.sort();                                    // order by Name
       //this.results = Database.Query('select id, Name from Account where Name like ' + nameCondition + ' AND Id NOT IN (select AccountId From AccountShare where UserOrGroupId = \'00510000000gaBh\' and RowCause = \'ImplicitParent\' ) order by Name limit 30');
   }
   // 省単位 or 全国の診療科を検索,最初の50件
    public Map<Id, Account> selectDepartByHospitalState(String nameCondition, String reporterState, Integer limitCnt) {
        User loginUser = [Select Id, State_Hospital__c, Job_Category__c from User where Id =: UserInfo.getUserId()];
        String queryString = 'select Id, Name, Department_Class__c, Department_Class__r.Name, Hospital__c, Hospital__r.Name from Account where' + nameCondition + ' Hospital__r.RecordType.DeveloperName = \'HP\' and Is_Active__c <> \'無効\'';
        if (loginUser.Job_Category__c == 'GI市场'
                || loginUser.Job_Category__c == 'SP市场'
                || loginUser.Job_Category__c == '服务本部'
                || loginUser.Job_Category__c == '培训'
        ) {
            // 全国範囲、なにもしない
        } else {
            // 省単位の条件追加
            system.debug('selectDepartByHospitalState reporterState=' + reporterState);
            queryString += ' and Parent.Parent.State_Master__r.Name = :reporterState';
        }
        queryString += ' order by Name limit :limitCnt';
        system.debug('selectDepartByHospitalState queryString=' + queryString);
        return new Map<Id, Account>((List<Account>) Database.query(queryString));
    }
}