Skip to content

顧客情報登録実装編#

1.1. 処理概要#

画面の入力内容をもとに顧客情報の登録を行います。
本処理を行うには、API認証よりAPIを呼び出すためのアクセストークンが必要となります。

1.1.1. 呼出API#

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

No API 処理内容 使用用途
1 POST /v2/api/customers 顧客を登録する 顧客情報登録画面で登録ボタン押下時に顧客情報を作成

1.1.2. 処理フロー#

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

1.1.3. 実装例#

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

CustomerRegisterController.java

/**
 * 登録ボタン処理
 */
// Spring annotation
@RequestMapping(value = "/CustomerRegister/regist" , method = RequestMethod.POST)
public String regist(
    Model model,
    @Valid CustomerRegisterForm form,
    BindingResult result
) {
    // 項目チェック
    if (result.hasErrors()) {
        return ControllerConstants.CUSTOMER_REGISTER_JSP;
    }

    Web_IFCustomerEntry_I iFCustomerEntry_I = new Web_IFCustomerEntry_I();
    Web_IFCustomerEntry_O iFCustomerEntry_O = new Web_IFCustomerEntry_O();

    // 現在日時を取得
    String timestamp = DateUtil.nowDatetime(DateUtil.FORMAT_YMDHMSS);

    iFCustomerEntry_I.entry_id = CommonConstants.登録者ID;
    iFCustomerEntry_I.address1 = form.getAddress1();
    iFCustomerEntry_I.address2 = form.getAddress2();
    iFCustomerEntry_I.address3 = form.getAddress3();
    iFCustomerEntry_I.address4 = form.getAddress4();
    iFCustomerEntry_I.address_of_workplace1 = form.getAddressOfWorkplace1();
    iFCustomerEntry_I.address_of_workplace2 = form.getAddressOfWorkplace2();
    iFCustomerEntry_I.address_of_workplace3 = form.getAddressOfWorkplace3();
    iFCustomerEntry_I.address_of_workplace4 = form.getAddressOfWorkplace4();
    iFCustomerEntry_I.apply_start_date = timestamp.substring(0, 8);
    iFCustomerEntry_I.company_name = form.getCompanyName();
    iFCustomerEntry_I.customer_name1 = form.getCustomerName1();
    iFCustomerEntry_I.customer_name2 = form.getCustomerName2();
    iFCustomerEntry_I.customer_name3 = form.getCustomerName3();
    iFCustomerEntry_I.customer_name4 = form.getCustomerName4();
    iFCustomerEntry_I.customer_name5 = form.getCustomerName5();
    iFCustomerEntry_I.customer_name6 = form.getCustomerName6();
    iFCustomerEntry_I.date_of_birth = form.getDateOfBirth();
    iFCustomerEntry_I.department = form.getDepartment();
    iFCustomerEntry_I.email_address1 = form.getEmailAddress1();
    iFCustomerEntry_I.email_address2 = form.getEmailAddress2();
    iFCustomerEntry_I.gender = form.getGender();
    iFCustomerEntry_I.nationality = form.getNationality();
    iFCustomerEntry_I.occupation = form.getOccupation();
    iFCustomerEntry_I.phone_number1 = form.getPhoneNumber1();
    iFCustomerEntry_I.phone_number2 = form.getPhoneNumber2();
    iFCustomerEntry_I.position = form.getPosition();
    iFCustomerEntry_I.postcode_of_workplace = form.getPostcodeOfWorkplace();
    iFCustomerEntry_I.status = SampleUtil.emptyToNull(form.getStatus());
    if (form.getStatus().equals(CustomerConstants.仮登録_code)) {
        iFCustomerEntry_I.temporary_registration_date_and_time = timestamp;
    } else if (form.getStatus().equals(CustomerConstants.本登録_code)) {
        iFCustomerEntry_I.official_registration_date_and_time  = timestamp;
    }
    iFCustomerEntry_I.zip_code = form.getZipCode();
    // フリー項目
    JsonObject freeItem = null;
    if (!form.getFree1().isEmpty() || !form.getFree2().isEmpty() ||
            !form.getFree3().isEmpty() || !form.getFree4().isEmpty()) {
        freeItem = new JsonObject();
        freeItem.addProperty("free1", SampleUtil.emptyToNull(form.getFree1()));
        freeItem.addProperty("free2", SampleUtil.emptyToNull(form.getFree2()));
        freeItem.addProperty("free3", SampleUtil.emptyToNull(form.getFree3()));
        freeItem.addProperty("free4", SampleUtil.emptyToNull(form.getFree4()));
    }
    iFCustomerEntry_I.freeItem = freeItem;
    iFCustomerEntry_I.free_item1 = form.getFreeItem1();

    try {
        iFCustomerEntry_O = customerService.customerEntry(iFCustomerEntry_I);
        if (ControllerConstants.API_RESULT_NG.equals(iFCustomerEntry_O.result_information.result)) {
            form.setErrorInformation(iFCustomerEntry_O.result_information.detailed_result);
            return ControllerConstants.CUSTOMER_REGISTER_JSP;
        }
    } catch (ApiException e) {
        model.addAttribute("errorCode", e.getErrorCode().getValue());
        return ControllerConstants.SYSTEM_ERROR_JSP;

    } catch (Exception e) {
        return ControllerConstants.SYSTEM_ERROR_JSP;
    }

    model.addAttribute("customerRegisterForm", form);

    form.setMessage(getMsg(MessageConstants.MSGI00001,
                            getMsg(MessageConstants.LBL000004),
                                iFCustomerEntry_O.customer_id));

    form.setCustomerId(iFCustomerEntry_O.customer_id);

    return ControllerConstants.CUSTOMER_REGISTER_JSP;
}

CustomerService.java

/**
 * 顧客_登録 API
 * 
 * @param web_IFCustomerEntry_I IF顧客_登録_入力
 * @return IF顧客_登録_出力
 */
public Web_IFCustomerEntry_O customerEntry(Web_IFCustomerEntry_I web_IFCustomerEntry_I) {
    // 通信設定
    String strURI = ClientUtil.makeURI(UriInfo.CustomerEntry, null, null);
    HttpPost postMethod = ClientUtil.makeHttpPost(strURI, web_IFCustomerEntry_I);

    return CommonHttpClient.httpPost(postMethod, Web_IFCustomerEntry_O.class);
}

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

Top