# Business Logic — JBSbatKKIntrCdIkaAdd.singleCheck() [68 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKIntrCdIkaAdd` |
| Layer | Service (Batch Service) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKIntrCdIkaAdd.singleCheck()

This method performs **single-item (field-level) validation** on input data for the **Referral Code Bulk Registration** batch process (紹介コード一括登録). It receives a `Map<String, Object>` that may be populated from either TXT file input or database retrieval, and validates each field sequentially: SYSID, Service Contract Number (SVC_KEI_NO), and Validity Expiry Date (YK_KIGEN_YMD).

The method implements a **sequential gate pattern**: each field is validated through three sub-checks (blank presence, digit count, and character range validity), and the first failing check returns an error code immediately, short-circuiting further validation. This ensures efficient error reporting by surfacing the first data quality issue encountered.

The validation rules are consistent across all three fields: SYSID, SVC_KEI_NO, and YK_KIGEN_YMD must all conform to the character set defined by `hannkakuesuuji1` (half-range alphanumeric characters). SYSID and SVC_KEI_NO are limited to 10 digits maximum. YK_KIGEN_YMD is limited to exactly 8 digits (representing a YYYYMMDD date) and must pass a valid date format check.

As a **private method** called from `checkMain()`, this method is a dedicated validation utility within the batch registration service. It does not interact with the database directly — it is purely a data integrity gate that runs after the batch has loaded or read input data but before the data is persisted.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["singleCheck(rsMap)"])
    START --> GET_SYSID["Get SYSID from rsMap"]
    GET_SYSID --> CHECK_SYSID_BLANK{SYSID is null/blank?}
    CHECK_SYSID_BLANK -->|Yes| RETURN_E020["Return E020"]
    CHECK_SYSID_BLANK -->|No| CHECK_SYSID_DIGITS{"SYSID digit count <= 10?"}
    CHECK_SYSID_DIGITS -->|No| RETURN_E040["Return E040"]
    CHECK_SYSID_DIGITS -->|Yes| CHECK_SYSID_CHARS{"SYSID character range valid?"}
    CHECK_SYSID_CHARS -->|No| RETURN_E030["Return E030"]
    CHECK_SYSID_CHARS -->|Yes| GET_SVC_KEI_NO["Get SVC_KEI_NO from rsMap"]
    GET_SVC_KEI_NO --> CHECK_SVC_BLANK{"SVC_KEI_NO is null/blank?"}
    CHECK_SVC_BLANK -->|Yes| RETURN_E050["Return E050"]
    CHECK_SVC_BLANK -->|No| CHECK_SVC_DIGITS{"SVC_KEI_NO digit count <= 10?"}
    CHECK_SVC_DIGITS -->|No| RETURN_E070["Return E070"]
    CHECK_SVC_DIGITS -->|Yes| CHECK_SVC_CHARS{"SVC_KEI_NO character range valid?"}
    CHECK_SVC_CHARS -->|No| RETURN_E060["Return E060"]
    CHECK_SVC_CHARS -->|Yes| GET_YK_KIGEN_YMD["Get YK_KIGEN_YMD from rsMap"]
    GET_YK_KIGEN_YMD --> CHECK_YK_KIGEN_BLANK{YK_KIGEN_YMD is null/blank?}
    CHECK_YK_KIGEN_BLANK -->|Yes| RETURN_NULL["Return null (success)"]
    CHECK_YK_KIGEN_BLANK -->|No| CHECK_YK_KIGEN_DIGITS{"YK_KIGEN_YMD digit count = 8?"}
    CHECK_YK_KIGEN_DIGITS -->|No| RETURN_E090["Return E090"]
    CHECK_YK_KIGEN_DIGITS -->|Yes| CHECK_YK_KIGEN_CHARS{"YK_KIGEN_YMD valid date format?"}
    CHECK_YK_KIGEN_CHARS -->|No| RETURN_E080["Return E080"]
    CHECK_YK_KIGEN_CHARS -->|Yes| RETURN_NULL
    RETURN_E020 --> END_CHECK(["End"])
    RETURN_E040 --> END_CHECK
    RETURN_E030 --> END_CHECK
    RETURN_E050 --> END_CHECK
    RETURN_E070 --> END_CHECK
    RETURN_E060 --> END_CHECK
    RETURN_E090 --> END_CHECK
    RETURN_E080 --> END_CHECK
    RETURN_NULL --> END_CHECK
```

**Processing summary:** The method validates three fields in sequence. Each field may fail at three checkpoints: (1) blank presence check via `JKKStringUtil.isNullBlank()`, (2) digit count check via `JBSbatCheckUtil.invoke()`, and (3) character range check via `JBSbatCheckUtil.invoke()`. If all validations pass, `null` is returned to indicate success.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `rsMap` | `Map<String, Object>` | Input data map containing referral code batch registration records. Populated from either TXT file input or database retrieval. Contains the following keys: `SYSID` (system identifier for the batch record), `SVC_KEI_NO` (service contract number — the unique identifier for a service contract line item), and `YK_KIGEN_YMD` (validity expiry date in YYYYMMDD format). |

**External state:** None. The method reads no instance fields or external dependencies. It is a pure validation function that operates solely on its input parameter.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatCheckUtil.invoke` | - | - | Character count and range validation via `JBSbatCheckUtil.invoke()` — used for digit count and character set checks |
| - | `JKKStringUtil.isNullBlank` | - | - | Null/blank presence check on string values |

**Note:** This method performs **pure data validation** and does not execute any Create, Read, Update, or Delete operations against the database. It calls utility methods for field-level validation (blank checks, digit count limits, character range enforcement) but does not directly access any SC Code or database entities.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKIntrCdIkaAdd | `checkMain()` -> `singleCheck(rsMap)` | `isNullBlank [-]`, `JBSbatCheckUtil.invoke [-]` |

**Description:** The method is called directly from `checkMain()` within the same class `JBSbatKKIntrCdIkaAdd`. It is a private validation utility that does not appear to be called by any screen (KKSV) or CBS entry points. The `checkMain()` method is the primary entry point for the referral code bulk registration batch, and `singleCheck()` is invoked as part of its data validation pipeline.

## 6. Per-Branch Detail Blocks

**Block 1** — [IF/ELSE-IF chain: SYSID field validation] (L845)

> (Optional: Sets up local variable for single-item value extraction.)

| # | Type | Code |
|---|------|------|
| 1 | SET | `strValue = null` // local variable initialization |
| 2 | SET | `strValue = (String)rsMap.get(JBSbatKKIFM875.SYSID)` // Get SYSID value [-> SYSID = "SYSID"] |

**Block 1.1** — [IF] `JKKStringUtil.isNullBlank(strValue)` (L848)

> Blank presence check for SYSID. Returns E020 error if SYSID is missing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JKKStringUtil.isNullBlank(strValue)` // Check if SYSID is null or blank |
| 2 | RETURN | `return ErrCdEnum.E020` // Error: SYSID missing |

**Block 1.2** — [IF] `!JBSbatCheckUtil.invoke(strValue, new String[]{"ketasuu1","10"})` (L853)

> Digit count check for SYSID. SYSID must have at most 10 digits.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JBSbatCheckUtil.invoke(strValue, new String[]{"ketasuu1","10"})` // Check digit count <= 10 |
| 2 | RETURN | `return ErrCdEnum.E040` // Error: SYSID digit count exceeds limit |

**Block 1.3** — [IF] `!JBSbatCheckUtil.invoke(strValue, new String[]{"hannkakuesuuji1"})` (L858)

> Character range check for SYSID. SYSID must contain only half-range alphanumeric characters.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JBSbatCheckUtil.invoke(strValue, new String[]{"hannkakuesuuji1"})` // Check character range valid |
| 2 | RETURN | `return ErrCdEnum.E030` // Error: SYSID contains invalid characters |

**Block 2** — [IF/ELSE-IF chain: SVC_KEI_NO (Service Contract Number) field validation] (L863)

> SYSID passed all checks. Now validate the Service Contract Number field.

| # | Type | Code |
|---|------|------|
| 1 | SET | `strValue = (String)rsMap.get(JBSbatKKIFM875.SVC_KEI_NO)` // Get SVC_KEI_NO value [-> SVC_KEI_NO = "SVC_KEI_NO"] |

**Block 2.1** — [IF] `JKKStringUtil.isNullBlank(strValue)` (L866)

> Blank presence check for SVC_KEI_NO. Returns E050 error if missing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JKKStringUtil.isNullBlank(strValue)` // Check if SVC_KEI_NO is null or blank |
| 2 | RETURN | `return ErrCdEnum.E050` // Error: Service Contract Number missing |

**Block 2.2** — [IF] `!JBSbatCheckUtil.invoke(strValue, new String[]{"ketasuu1","10"})` (L871)

> Digit count check for SVC_KEI_NO. Must have at most 10 digits.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JBSbatCheckUtil.invoke(strValue, new String[]{"ketasuu1","10"})` // Check digit count <= 10 |
| 2 | RETURN | `return ErrCdEnum.E070` // Error: Service Contract Number digit count exceeds limit |

**Block 2.3** — [IF] `!JBSbatCheckUtil.invoke(strValue, new String[]{"hannkakuesuuji1"})` (L876)

> Character range check for SVC_KEI_NO. Must contain only half-range alphanumeric characters.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JBSbatCheckUtil.invoke(strValue, new String[]{"hannkakuesuuji1"})` // Check character range valid |
| 2 | RETURN | `return ErrCdEnum.E060` // Error: Service Contract Number contains invalid characters |

**Block 3** — [IF/ELSE-IF chain: YK_KIGEN_YMD (Validity Expiry Date) field validation] (L881)

> SVC_KEI_NO passed all checks. Now validate the Validity Expiry Date field. This field is **optional** — if blank, no further checks are needed. If provided, it must have exactly 8 digits and pass a valid date format check.

| # | Type | Code |
|---|------|------|
| 1 | SET | `strValue = (String)rsMap.get(JBSbatKKIFM875.YK_KIGEN_YMD)` // Get YK_KIGEN_YMD value [-> YK_KIGEN_YMD = "YK_KIGEN_YMD"] |

**Block 3.1** — [IF] `!JKKStringUtil.isNullBlank(strValue)` (L884)

> YK_KIGEN_YMD is NOT blank (i.e., it has a value). Enter validation blocks. The condition is inverted — validation runs only when the field is provided.

**Block 3.1.1** — [IF] `!JBSbatCheckUtil.invoke(strValue, new String[]{"ketasuu1", "8"})` (L887)

> Digit count check for YK_KIGEN_YMD. Must have exactly 8 digits (YYYYMMDD format).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JBSbatCheckUtil.invoke(strValue, new String[]{"ketasuu1", "8"})` // Check digit count = 8 |
| 2 | RETURN | `return ErrCdEnum.E090` // Error: YK_KIGEN_YMD digit count is incorrect |

**Block 3.1.2** — [IF] `!JBSbatCheckUtil.invoke(strValue, new String[]{"year_month_day1"})` (L893)

> Date format check for YK_KIGEN_YMD. Must be a valid date format (YYYYMMDD).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JBSbatCheckUtil.invoke(strValue, new String[]{"year_month_day1"})` // Check valid date format |
| 2 | RETURN | `return ErrCdEnum.E080` // Error: YK_KIGEN_YMD is not a valid date |

**Block 4** — [RETURN] (L899)

> All validations passed (or YK_KIGEN_YMD was not provided, which is acceptable). Return null to indicate success.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return null` // No errors — all field validations passed |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `SYSID` | Field | System Identifier — a unique system-generated identifier for the batch record. Mandatory. Half-range alphanumeric, up to 10 digits. |
| `SVC_KEI_NO` | Field | Service Contract Number — the unique identifier for a service contract line item. Mandatory. Half-range alphanumeric, up to 10 digits. |
| `YK_KIGEN_YMD` | Field | Validity Expiry Date — the date when the referral code registration expires, in YYYYMMDD format. Optional. Must be exactly 8 digits if provided. |
| Referral Code (紹介コード) | Business term | A promotional code used in customer referral programs. This batch process handles bulk registration of such codes. |
| hannkakuesuuji1 | Check type | Half-range alphanumeric character set validation — restricts input to ASCII digits (0-9), uppercase letters (A-Z), and lowercase letters (a-z). |
| ketasuu1 | Check type | Digit count validation — checks that the number of digits does not exceed the specified maximum. |
| year_month_day1 | Check type | Valid date format validation — checks that the value is a properly formatted date (YYYYMMDD) with valid year, month, and day components. |
| E020 | Error code | SYSID missing — the SYSID field is null or blank. |
| E030 | Error code | SYSID invalid characters — the SYSID contains characters outside the allowed half-range alphanumeric set. |
| E040 | Error code | SYSID digit count exceeded — the SYSID contains more than 10 digits. |
| E050 | Error code | Service Contract Number missing — the SVC_KEI_NO field is null or blank. |
| E060 | Error code | Service Contract Number invalid characters — the SVC_KEI_NO contains characters outside the allowed half-range alphanumeric set. |
| E070 | Error code | Service Contract Number digit count exceeded — the SVC_KEI_NO contains more than 10 digits. |
| E080 | Error code | YK_KIGEN_YMD invalid date format — the expiry date is not a valid YYYYMMDD date. |
| E090 | Error code | YK_KIGEN_YMD digit count incorrect — the expiry date does not contain exactly 8 digits. |
| JBSbatCheckUtil | Utility class | Shared batch validation utility providing character range, digit count, and date format check methods. |
| JKKStringUtil | Utility class | Shared string utility providing null/blank detection (`isNullBlank`) for input validation. |
| JBSbatKKIFM875 | Constant class | Field constant definitions for the referral code bulk registration file format. Defines SYSID, SVC_KEI_NO, and YK_KIGEN_YMD keys. |
| ErrCdEnum | Enum | Error code enumeration containing standardized batch error codes (E020, E030, E040, E050, E060, E070, E080, E090). |
