Skip to content

顧客情報検索実装編#

1.1. 処理概要#

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

1.1.1. 呼出API#

以下、顧客情報検索で呼び出すAPIとなります。

No API 処理内容 使用用途
1 GET /v2/api/customers 顧客を検索する 顧客一覧画面で検索ボタン押下時に顧客情報を検索
2 GET /v2/api/customerslistcount 顧客の件数を取得する 入力内容をもとに顧客情報の件数を検索

1.1.2. 処理フロー#

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

1.1.3. 実装例#

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

CustomerListController.java

    /**
     * 顧客検索処理
     * @param form 顧客一覧フォーム
     * @return 顧客一覧フォーム
     */
    private CustomerListForm searchCustomer(CustomerListForm form, String customerId) {

        // 顧客の件数検索を行う
        Web_IFCustomerListCount_I web_IFCustomerListCount_I = new Web_IFCustomerListCount_I();
        if (customerId != null) {
            web_IFCustomerListCount_I.customer_id = customerId;
        } else {
            web_IFCustomerListCount_I.customer_id = SampleUtil.emptyToNull(form.getCustomerIdSch());
            web_IFCustomerListCount_I.customer_name1 = SampleUtil.emptyToNull(form.getCustomerNameSch());
            web_IFCustomerListCount_I.company_name = SampleUtil.emptyToNull(form.getCompanyNameSch());
            web_IFCustomerListCount_I.group_id = SampleUtil.emptyToNull(form.getGroupIdSch());
            web_IFCustomerListCount_I.status = SampleUtil.emptyToNull(form.getStatusSch());
            web_IFCustomerListCount_I.temporary_registration_date_and_time_from = SampleUtil.emptyToNull(form.getTempRegistDateFrom());
            web_IFCustomerListCount_I.temporary_registration_date_and_time_to = SampleUtil.emptyToNull(form.getTempRegistDateTo());
            web_IFCustomerListCount_I.official_registration_date_and_time_from = SampleUtil.emptyToNull(form.getOfficialRegistDateFrom());
            web_IFCustomerListCount_I.official_registration_date_and_time_to = SampleUtil.emptyToNull(form.getOfficialRegistDateTo());
            web_IFCustomerListCount_I.cancellation_date_and_time_from = SampleUtil.emptyToNull(form.getCancelDateFrom());
            web_IFCustomerListCount_I.cancellation_date_and_time_to = SampleUtil.emptyToNull(form.getCancelDateTo());
        }

        // 処理を実行
        Web_IFCustomerListCount_O web_IFCustomerListCount_O = null;
        try {
            web_IFCustomerListCount_O =
                            customerService.customerListCount(web_IFCustomerListCount_I);
            if (ControllerConstants.API_RESULT_NG.equals(web_IFCustomerListCount_O.result_information.result)) {
                form.setErrorInformation(web_IFCustomerListCount_O.result_information.detailed_result);
                return form;
            }
        } catch (ApiException e) {
            throw e;
        } catch (Exception e) {
            throw e;
        }

        // 件数を格納
        Long lCnt = Long.valueOf(web_IFCustomerListCount_O.count);;
        if (lCnt == 0L) {
            form.setErrorInformation(getMsg(MessageConstants.MSGE00003));
            return form;
        }
        form.setListSize(lCnt);

        // 件数が1件以上ある場合、顧客の検索を行う
        if (lCnt > 0L) {
            Web_IFCustomerListSearch_I web_IFCustomerListSearch_I = new Web_IFCustomerListSearch_I();
            if (customerId != null) {
                web_IFCustomerListSearch_I.customer_id = customerId;
            } else {
                web_IFCustomerListSearch_I.customer_id = SampleUtil.emptyToNull(form.getCustomerIdSch());;
                web_IFCustomerListSearch_I.customer_name1 = SampleUtil.emptyToNull(form.getCustomerNameSch());
                web_IFCustomerListSearch_I.company_name = SampleUtil.emptyToNull(form.getCompanyNameSch());
                web_IFCustomerListSearch_I.group_id = SampleUtil.emptyToNull(form.getGroupIdSch());
                web_IFCustomerListSearch_I.status = SampleUtil.emptyToNull(form.getStatusSch());
                web_IFCustomerListSearch_I.temporary_registration_date_and_time_from = SampleUtil.emptyToNull(form.getTempRegistDateFrom());
                web_IFCustomerListSearch_I.temporary_registration_date_and_time_to = SampleUtil.emptyToNull(form.getTempRegistDateTo());
                web_IFCustomerListSearch_I.official_registration_date_and_time_from = SampleUtil.emptyToNull(form.getOfficialRegistDateFrom());
                web_IFCustomerListSearch_I.official_registration_date_and_time_to = SampleUtil.emptyToNull(form.getOfficialRegistDateTo());
                web_IFCustomerListSearch_I.cancellation_date_and_time_from = SampleUtil.emptyToNull(form.getCancelDateFrom());
                web_IFCustomerListSearch_I.cancellation_date_and_time_to = SampleUtil.emptyToNull(form.getCancelDateTo());

                web_IFCustomerListSearch_I.sort_item1 = SampleUtil.emptyToNull(form.getSortItem1());
                web_IFCustomerListSearch_I.sort1 = SampleUtil.emptyToNull(form.getSort1());
                web_IFCustomerListSearch_I.sort_item2 = SampleUtil.emptyToNull(form.getSortItem2());
                web_IFCustomerListSearch_I.sort2 = SampleUtil.emptyToNull(form.getSort2());
                web_IFCustomerListSearch_I.sort_item3 = SampleUtil.emptyToNull(form.getSortItem3());
                web_IFCustomerListSearch_I.sort3 = SampleUtil.emptyToNull(form.getSort3());;
                web_IFCustomerListSearch_I.start_position = String.valueOf(form.getStartPosition());
                web_IFCustomerListSearch_I.end_position = String.valueOf(form.getEndPosition());
            }

            // 処理を実行
            Web_IFCustomerListSearch_O web_IFCustomerListSearch_O = null;
            try {
                web_IFCustomerListSearch_O = customerService.customerListSearch(web_IFCustomerListSearch_I);
            } catch (ApiException e) {
                throw e;
            } catch (Exception e) {
                throw e;
            }
            CustomerInformationListDto customerInformationListDto = null;
            List<CustomerInformationListDto> customerList = new ArrayList<CustomerInformationListDto>();

            for (Web_CustomerInformationList list : web_IFCustomerListSearch_O.customer_information_list) {
                customerInformationListDto = new CustomerInformationListDto();
                customerInformationListDto.setCustomerId(list.customer_id);     // 顧客ID
                customerInformationListDto.setCustomerName1(list.customer_name1);   // 顧客名1
                customerInformationListDto.setCustomerName2(list.customer_name2);   // 顧客名2
                customerInformationListDto.setCompanyName(list.company_name);   // 会社名
                if (!list.group_id_list.isEmpty()) {
                    String groupName = "";
                    boolean bflg = false;
                    for (Web_GroupIdList web_GroupIdList : list.group_id_list) {
                        if (bflg) {
                            // 改行設定
                            groupName = groupName + "<br>";
                        }
                        // グループ名を設定
                        String groupId = web_GroupIdList.group_id;
                        if (!(groupId == null)) {
                            for (GroupInformationListDto groupList : form.getGroupList()) {
                                if (groupId.equals(groupList.groupId)) {
                                    groupName = groupName + groupList.groupName;
                                    bflg = true;
                                    break;
                                }
                            }
                        }
                    }
                    customerInformationListDto.setGroupName(groupName);
                }
                customerInformationListDto.setStatus(this.getStatusName(list.status));
                customerList.add(customerInformationListDto);
            }
            form.setCustomerList(customerList);
        }

        return form;
    }

CustomerService.java

/**
 * 顧客_検索 API
 * 
 * @param Web_IFCustomerListSearch_I IF顧客_検索_入力
 * @return IF顧客_検索_出力
 */
public Web_IFCustomerListSearch_O customerListSearch(Web_IFCustomerListSearch_I web_IFCustomerListSearch_I) {
    // 通信設定
    HashMap<String, String> mapQueryString = new HashMap<String, String>();
    mapQueryString.put(UriInfo.customer_id, web_IFCustomerListSearch_I.customer_id);
    mapQueryString.put(UriInfo.customer_name1, web_IFCustomerListSearch_I.customer_name1);
    mapQueryString.put(UriInfo.company_name, web_IFCustomerListSearch_I.company_name);
    mapQueryString.put(UriInfo.group_id, web_IFCustomerListSearch_I.group_id);
    mapQueryString.put(UriInfo.temporary_registration_date_and_time_from, web_IFCustomerListSearch_I.temporary_registration_date_and_time_from);
    mapQueryString.put(UriInfo.temporary_registration_date_and_time_to, web_IFCustomerListSearch_I.temporary_registration_date_and_time_to);
    mapQueryString.put(UriInfo.official_registration_date_and_time_from, web_IFCustomerListSearch_I.official_registration_date_and_time_from);
    mapQueryString.put(UriInfo.official_registration_date_and_time_to, web_IFCustomerListSearch_I.official_registration_date_and_time_to);
    mapQueryString.put(UriInfo.cancellation_date_and_time_from, web_IFCustomerListSearch_I.cancellation_date_and_time_from);
    mapQueryString.put(UriInfo.cancellation_date_and_time_to, web_IFCustomerListSearch_I.cancellation_date_and_time_to);
    mapQueryString.put(UriInfo.status, web_IFCustomerListSearch_I.status);
    mapQueryString.put(UriInfo.sort_item1, web_IFCustomerListSearch_I.sort_item1);
    mapQueryString.put(UriInfo.sort1, web_IFCustomerListSearch_I.sort1);
    mapQueryString.put(UriInfo.sort_item2, web_IFCustomerListSearch_I.sort_item2);
    mapQueryString.put(UriInfo.sort2, web_IFCustomerListSearch_I.sort2);
    mapQueryString.put(UriInfo.sort_item3, web_IFCustomerListSearch_I.sort_item3);
    mapQueryString.put(UriInfo.sort3, web_IFCustomerListSearch_I.sort3);
    mapQueryString.put(UriInfo.start_position, web_IFCustomerListSearch_I.start_position);
    mapQueryString.put(UriInfo.end_position, web_IFCustomerListSearch_I.end_position);
    String strURI = ClientUtil.makeURI(UriInfo.CustomersSearch, null, mapQueryString);
    HttpGet getMethod = ClientUtil.makeHttpGet(strURI);

    return CommonHttpClient.httpGet(getMethod, Web_IFCustomerListSearch_O.class);
}
    /**
     * 顧客_件数検索 API
     * 
     * @param Web_IFCustomerListSearch_I IF顧客_件数検索_入力
     * @return IF顧客_件数検索_出力
     */
    public Web_IFCustomerListCount_O customerListCount(Web_IFCustomerListCount_I web_IFCustomerListCount_I) {
        // 通信設定
        HashMap<String, String> mapQueryString = new HashMap<String, String>();
        mapQueryString.put(UriInfo.customer_id, web_IFCustomerListCount_I.customer_id);
        mapQueryString.put(UriInfo.customer_name1, web_IFCustomerListCount_I.customer_name1);
        mapQueryString.put(UriInfo.company_name, web_IFCustomerListCount_I.company_name);
        mapQueryString.put(UriInfo.group_id, web_IFCustomerListCount_I.group_id);
        mapQueryString.put(UriInfo.temporary_registration_date_and_time_from, web_IFCustomerListCount_I.temporary_registration_date_and_time_from);
        mapQueryString.put(UriInfo.temporary_registration_date_and_time_to, web_IFCustomerListCount_I.temporary_registration_date_and_time_to);
        mapQueryString.put(UriInfo.official_registration_date_and_time_from, web_IFCustomerListCount_I.official_registration_date_and_time_from);
        mapQueryString.put(UriInfo.official_registration_date_and_time_to, web_IFCustomerListCount_I.official_registration_date_and_time_to);
        mapQueryString.put(UriInfo.cancellation_date_and_time_from, web_IFCustomerListCount_I.cancellation_date_and_time_from);
        mapQueryString.put(UriInfo.cancellation_date_and_time_to, web_IFCustomerListCount_I.cancellation_date_and_time_to);
        mapQueryString.put(UriInfo.status, web_IFCustomerListCount_I.status);
        String strURI = ClientUtil.makeURI(UriInfo.CustomersListCount, null, mapQueryString);
        HttpGet getMethod = ClientUtil.makeHttpGet(strURI);

        return CommonHttpClient.httpGet(getMethod, Web_IFCustomerListCount_O.class);
    }

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

Top