Skip to content

サービス情報検索実装編#

1.1. 処理概要#

前画面より引き継がれた条件をもとに、サービス情報の件数の取得と、サービス情報の検索を行います。
取得したサービス情報の件数をもとに、サービス情報を表示するページ数を算出して画面に表示します。
画面上でページ番号が選択された場合は、その数によってサービス情報の検索の開始位置と終了位置を指定することで、ページング処理を実装しています。
本処理を行うには、API認証よりAPIを呼び出すためのアクセストークンが必要となります。

1.1.1. 呼出API#

以下、サービス情報検索で呼び出すAPIとなります。

No API 処理内容 使用用途
1 GET /API/v2/api/servicepricemaster サービス料金情報を検索する サービス一覧画面で前画面より引き継がれた情報をもとにサービス情報の検索
および、ページ数の算出のための情報検索

1.1.2. 処理フロー#

サービス情報検索を行うまでの処理は以下のフローとなります。

1.1.3. 実装例#

以下API呼び出しの実装例となります。
※本マニュアルに記載している実装例は、分かりやすさを優先し簡易的に記載しております。提供しているソースと異なりますので詳細については提供ソースをご確認ください。

ServiceMasterListController.java

/**
 * 検索
 * 
 * @param model モデル
 * @param form サービス一覧フォーム
 * @return サービス一覧
 */
@RequestMapping(value = "/ServiceMasterList/search")
public String search(Model model, 
        @Valid ServiceMasterListForm form, 
        BindingResult result,
        @ModelAttribute("serviceCode") String serviceCode,
        @ModelAttribute("administrationNumber") String administrationNumber) {

    form.setErrorInformation(null);     

    if (serviceCode != null) {
        form.setServiceCode(serviceCode);
    }
    if (administrationNumber != null) {
        form.setAdministrationNumber(administrationNumber);
    }

    if (result.hasErrors()) {
        return ControllerConstants.SERVICE_MASTER_LIST_JSP;
    }

    form.setServiceMasterList(null);
    form.setNowPage(1L);

    Web_IFServicePriceInformationSearch_I web_IFServicePriceInformationSearch_I = new Web_IFServicePriceInformationSearch_I();
    Web_IFServicePriceInformationSearch_O web_IFServicePriceInformationSearch_O = new Web_IFServicePriceInformationSearch_O();
    ServiceMasterListDto serviceMasterListDto = new ServiceMasterListDto();
    List<ServiceMasterListDto> serviceMasterList = new ArrayList<ServiceMasterListDto>();

    web_IFServicePriceInformationSearch_I.service_code = SampleUtil.emptyToNull(form.getServiceCode());
    web_IFServicePriceInformationSearch_I.service_name = SampleUtil.emptyToNull(form.getServiceName());

    web_IFServicePriceInformationSearch_I.apply_start_date_from = SampleUtil.emptyToNull(form.getApplyStartDate());
    web_IFServicePriceInformationSearch_I.apply_start_date_to = SampleUtil.emptyToNull(form.getApplyEndDate());
    web_IFServicePriceInformationSearch_I.reception_start_date_from = SampleUtil.emptyToNull(form.getReceptionStartDate());
    web_IFServicePriceInformationSearch_I.reception_start_date_to = SampleUtil.emptyToNull(form.getReceptionEndDate());
    web_IFServicePriceInformationSearch_I.release_start_date_from = SampleUtil.emptyToNull(form.getReleaseStartDate());
    web_IFServicePriceInformationSearch_I.release_start_date_to = SampleUtil.emptyToNull(form.getReleaseEndDate());

    web_IFServicePriceInformationSearch_I.sort_item1 = SampleUtil.emptyToNull(form.getSortItem1());
    web_IFServicePriceInformationSearch_I.sort_item2 = SampleUtil.emptyToNull(form.getSortItem2());
    web_IFServicePriceInformationSearch_I.sort_item3 = SampleUtil.emptyToNull(form.getSortItem3());
    web_IFServicePriceInformationSearch_I.sort1 = SampleUtil.emptyToNull(form.getSort1());
    web_IFServicePriceInformationSearch_I.sort2 = SampleUtil.emptyToNull(form.getSort2());
    web_IFServicePriceInformationSearch_I.sort3 = SampleUtil.emptyToNull(form.getSort3());

    web_IFServicePriceInformationSearch_I.language_locale = CommonConstants.言語ロケール_ja;
    web_IFServicePriceInformationSearch_I.charge_info_retrieval_flg = "0";

    try {
        // サービス料金情報を検索
        web_IFServicePriceInformationSearch_O = serviceMasterService.servicePriceInformationSearch(web_IFServicePriceInformationSearch_I);

        // 正常の場合
        if(ControllerConstants.API_RESULT_OK.equals(web_IFServicePriceInformationSearch_O.result_information.result)){
            long service_master_information_list_size = (long) web_IFServicePriceInformationSearch_O.service_master_information_list.size();
            form.setListSize(service_master_information_list_size);

            int index = 0;

            if (service_master_information_list_size >= form.getMAX_PAGE_LINE()) {
                index = Integer.parseInt(String.valueOf(form.getMAX_PAGE_LINE()));
            } else {
                index = (int)service_master_information_list_size;
            }
            for (int i = 0; i < index; i++) {
                serviceMasterListDto = new ServiceMasterListDto();
                serviceMasterListDto.setServiceCode(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).service_code);
                serviceMasterListDto.setServiceName(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).service_master_formultilingual_information_list.get(0).service_name);
                serviceMasterListDto.setStartApplyDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).apply_start_date);
                serviceMasterListDto.setEndApplyDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).apply_end_date);
                serviceMasterListDto.setStartReceptDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).reception_start_date);
                serviceMasterListDto.setEndReceptDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).reception_end_date);
                serviceMasterListDto.setStartReleaseDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).release_start_date);
                serviceMasterListDto.setEndReleaseDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).release_end_date);
                serviceMasterListDto.setAdministration_number(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).administration_number);

                serviceMasterList.add(serviceMasterListDto);
            }
        }

        // 結果情報.NGの場合
        if (ControllerConstants.API_RESULT_NG.equals(web_IFServicePriceInformationSearch_O.result_information.result)) {
            form.setErrorInformation(web_IFServicePriceInformationSearch_O.result_information.detailed_result);
            return ControllerConstants.SERVICE_MASTER_LIST_JSP;
        }

    // 異常の場合
    } catch (ApiException e) {
        // 対象なし以外はエラーとする
        if (!ApiErrorType.対象なし.equals(e.getErrorCode())) {
            if (e.getErrorDetail() != null) {
                logger.error(e.getErrorDetail().toString(), e);
            }
            model.addAttribute("errorCode", e.getErrorCode().getValue());
            return ControllerConstants.SYSTEM_ERROR_JSP;
        } else {
            // メッセージ表示
            form.setErrorInformation(getMsg(MessageConstants.MSGE00003));
            return ControllerConstants.SERVICE_MASTER_LIST_JSP;
        }
    } catch (Exception e) {
        logger.error(ApiErrorType.システムエラー.name(), e);
        return ControllerConstants.SYSTEM_ERROR_JSP;
    }

    form.setServiceMasterList(serviceMasterList);
    serviceMasterListFormSession.setServiceMasterListForm(form);
    model.addAttribute("serviceMasterListForm", form);

    // 画面遷移用のセッションにフォーム(検索条件)情報格納
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setServiceName(form.getServiceName());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setServiceCode(form.getServiceCode());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setApplyStartDate(form.getApplyStartDate());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setApplyEndDate(form.getApplyEndDate());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setReceptionStartDate(form.getReceptionStartDate());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setReceptionEndDate(form.getReceptionEndDate());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setReleaseStartDate(form.getReleaseStartDate());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setReleaseEndDate(form.getReleaseEndDate());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setSortItem1(form.getSortItem1());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setSortItem2(form.getSortItem2());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setSortItem3(form.getSortItem3());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setSort1(form.getSort1());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setSort2(form.getSort2());
    serviceMasterListFormPrevSession.getServiceMasterListPrevForm().setSort3(form.getSort3());

    return ControllerConstants.SERVICE_MASTER_LIST_JSP;
}



/**
 * ページリンク
 * 
 * @param model モデル
 * @param form サービス一覧フォーム
 * @param page ページ番号
 * @return サービス一覧
 */
@RequestMapping(value = "/ServiceMasterList/page/{page}", method = RequestMethod.GET)
public String page(Model model, @ModelAttribute("serviceMasterListForm") ServiceMasterListForm form,
        @PathVariable("page") Long page) {

    form.setErrorInformation(null);
    form.setNowPage(page);

    Web_IFServicePriceInformationSearch_I web_IFServicePriceInformationSearch_I = new Web_IFServicePriceInformationSearch_I();
    Web_IFServicePriceInformationSearch_O web_IFServicePriceInformationSearch_O = new Web_IFServicePriceInformationSearch_O();
    ServiceMasterListDto serviceMasterListDto = new ServiceMasterListDto();
    List<ServiceMasterListDto> serviceMasterList = new ArrayList<ServiceMasterListDto>();

    web_IFServicePriceInformationSearch_I.service_code = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getServiceCode());
    web_IFServicePriceInformationSearch_I.service_name = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getServiceName());

    web_IFServicePriceInformationSearch_I.apply_start_date_from = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getApplyStartDate());
    web_IFServicePriceInformationSearch_I.apply_start_date_to = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getApplyEndDate());
    web_IFServicePriceInformationSearch_I.reception_start_date_from = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getReceptionStartDate());
    web_IFServicePriceInformationSearch_I.reception_start_date_to = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getReceptionEndDate());
    web_IFServicePriceInformationSearch_I.release_start_date_from = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getReleaseStartDate());
    web_IFServicePriceInformationSearch_I.release_start_date_to = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getReleaseEndDate());

    web_IFServicePriceInformationSearch_I.sort_item1 = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getSortItem1());
    web_IFServicePriceInformationSearch_I.sort_item2 = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getSortItem2());
    web_IFServicePriceInformationSearch_I.sort_item3 = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getSortItem3());
    web_IFServicePriceInformationSearch_I.sort1 = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getSort1());
    web_IFServicePriceInformationSearch_I.sort2 = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getSort2());
    web_IFServicePriceInformationSearch_I.sort3 = SampleUtil.emptyToNull(serviceMasterListFormSession.getServiceMasterListForm().getSort3());

    web_IFServicePriceInformationSearch_I.language_locale = CommonConstants.言語ロケール_ja;
    web_IFServicePriceInformationSearch_I.charge_info_retrieval_flg = "0";

    try {
        // サービス料金情報を検索
        web_IFServicePriceInformationSearch_O = serviceMasterService.servicePriceInformationSearch(web_IFServicePriceInformationSearch_I);

        // 正常の場合
        if(ControllerConstants.API_RESULT_OK.equals(web_IFServicePriceInformationSearch_O.result_information.result)){
            long service_master_information_list_size = (long) web_IFServicePriceInformationSearch_O.service_master_information_list.size();
            form.setListSize(service_master_information_list_size);

            int index = 0;
            int startPoint = Integer.parseInt(String.valueOf(serviceMasterListFormSession.getServiceMasterListForm().getStartPosition()));
            int endPoint = Integer.parseInt(String.valueOf(serviceMasterListFormSession.getServiceMasterListForm().getEndPosition()));

            if (service_master_information_list_size > endPoint) {
                index = endPoint;
            } else {
                index = (int)service_master_information_list_size;
            }

            for (int i = startPoint - 1; i < index; i++) {
                serviceMasterListDto = new ServiceMasterListDto();
                serviceMasterListDto.setServiceCode(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).service_code);
                serviceMasterListDto.setServiceName(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).service_master_formultilingual_information_list.get(0).service_name);
                serviceMasterListDto.setStartApplyDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).apply_start_date);
                serviceMasterListDto.setEndApplyDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).apply_end_date);
                serviceMasterListDto.setStartReceptDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).reception_start_date);
                serviceMasterListDto.setEndReceptDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).reception_end_date);
                serviceMasterListDto.setStartReleaseDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).release_start_date);
                serviceMasterListDto.setEndReleaseDate(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).release_end_date);
                serviceMasterListDto.setAdministration_number(web_IFServicePriceInformationSearch_O.service_master_information_list.get(i).administration_number);

                serviceMasterList.add(serviceMasterListDto);
            }
        }

        // 結果情報.NGの場合
        if (ControllerConstants.API_RESULT_NG.equals(web_IFServicePriceInformationSearch_O.result_information.result)) {
            form.setErrorInformation(web_IFServicePriceInformationSearch_O.result_information.detailed_result);
            return ControllerConstants.SERVICE_MASTER_LIST_JSP;
        }

        // ページ番号はあるが、そのページのデータが0件の場合、エラーメッセージを表示
        if (serviceMasterList.isEmpty()) {
            // メッセージ表示
            form.setErrorInformation(getMsg(MessageConstants.MSGE00003));
        }

    // 異常の場合
    } catch (ApiException e) {
        // 対象なし以外はエラーとする
        if (!ApiErrorType.対象なし.equals(e.getErrorCode())) {
            model.addAttribute("errorCode", e.getErrorCode().getValue());
            return ControllerConstants.SYSTEM_ERROR_JSP;
        } else {
            // メッセージ表示
            form.setErrorInformation(getMsg(MessageConstants.MSGE00003));
            return ControllerConstants.SERVICE_MASTER_LIST_JSP;
        }
    } catch (Exception e) {
        return ControllerConstants.SYSTEM_ERROR_JSP;
    }

    form.setServiceMasterList(serviceMasterList);
    serviceMasterListFormSession.setServiceMasterListForm(form);
    model.addAttribute("serviceMasterListForm", form);

    return ControllerConstants.SERVICE_MASTER_LIST_JSP;
}

ServiceMasterService.java

/**
 * サービス料金情報_検索 API
 * 
 * @param web_IFServicePriceInformationSearch_I IFサービス料金情報_検索_入力
 * @return IFサービス料金情報_検索_出力
 */
public Web_IFServicePriceInformationSearch_O servicePriceInformationSearch(Web_IFServicePriceInformationSearch_I web_IFServicePriceInformationSearch_I) {

    // 通信設定
    HashMap<String, String> mapQueryString = ClientUtil.makeMapQueryString(web_IFServicePriceInformationSearch_I);
    String strURI = ClientUtil.makeURI(UriInfo.ServicePriceMasterSearch, null, mapQueryString);
    HttpGet getMethod = ClientUtil.makeHttpGet(strURI);

    return CommonHttpClient.httpGet(getMethod, Web_IFServicePriceInformationSearch_O.class);

}

共通HTTPリクエストクラス[CommonHttpClient.java]の実装例についてはこちらをご参照ください。

Top