# Business Logic — JBSbatKKintrjhAdd.premiumClubPointJudge() [44 LOC]

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

## 1. Role

### JBSbatKKintrjhAdd.premiumClubPointJudge()

This method performs eligibility determination for awarding Premium Club Points to a customer based on their contract application date. Specifically, it answers the business question: "Is this customer eligible to receive Premium Club Points?" The method operates as a **predicate/gatekeeper** within the referral information registration batch process (K-Opticom's customer base system). It follows a deterministic evaluation pattern: first fetching the premium renewal date from the work parameter management table, then retrieving the customer's application date from the application detail table, and finally comparing the two dates to determine eligibility. If the application date is on or after the premium renewal date, the customer qualifies (returns `RESULT_OK`); otherwise, they do not (returns `RESULT_NG`). This method is called directly from `createSvcStaTgInf()` within the same class as part of the batch job that registers referral target information. It is shared by the referral batch processing and serves as a business rule enforcement point in the Premium Club Rewards program.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["premiumClubPointJudge - entry"])
    INIT["Set result = RESULT_NG"]
    FETCH_RENEWAL["Fetch premium renewal date - selectZmWorkParamKnri016 KK_PRCL_RNAL_YMD"]
    CHECK_NULL{"workParamKnriMap1 null or empty?"}
    LOG_ERROR["Print error log EKKJB2240CW"]
    RETURN_ERROR["Return RESULT_ERROR"]
    GET_PREMIUM_YMD["Extract premiumYmd from getString WORK_PARAM_SETTE_VALUE"]
    CALL_SELECT["executeKK_T_MSKM_DTL_KK_SELECT_024 mskmDtlNoArr"]
    SELECT_NEXT["db_KK_T_MSKM_DTL selectNext"]
    CHECK_RESULT{"outDbMap_mskm_dtl not null?"}
    GET_MSKM_YMD["mskmYmd = Rtrim getString MSKM_YMD"]
    RETURN_NG["Return result NG"]
    CHECK_YMD{"mskmYmd not null and not empty?"}
    COMPARE{"premiumYmd compareTo mskmYmd leq 0?"}
    SET_OK["Set result = RESULT_OK"]
    RETURN_RESULT["Return result"]
    END_NODE(["End"])

    START --> INIT
    INIT --> FETCH_RENEWAL
    FETCH_RENEWAL --> CHECK_NULL
    CHECK_NULL -->|Yes| LOG_ERROR
    LOG_ERROR --> RETURN_ERROR
    RETURN_ERROR --> END_NODE
    CHECK_NULL -->|No| GET_PREMIUM_YMD
    GET_PREMIUM_YMD --> CALL_SELECT
    CALL_SELECT --> SELECT_NEXT
    SELECT_NEXT --> CHECK_RESULT
    CHECK_RESULT -->|Yes| GET_MSKM_YMD
    GET_MSKM_YMD --> CHECK_YMD
    CHECK_RESULT -->|No| RETURN_NG
    RETURN_NG --> END_NODE
    CHECK_YMD -->|Yes| COMPARE
    CHECK_YMD -->|No| RETURN_NG
    COMPARE -->|Yes| SET_OK
    COMPARE -->|No| RETURN_RESULT
    RETURN_RESULT --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `mskmDtlNo` | `String` | Application detail number — the unique identifier for a specific customer contract line item (申込明細番号). Used to query the `KK_T_MSKM_DTL` table for the applicant's contract application date (申込年月日). Each value uniquely identifies one application record. |

**External State Read:**
- `super.opeDate` (inherited from parent class) — Operation date used as the effective date range filter when querying the work parameter management table.
- `commonItem.getLogPrint()` — Log output accessor for error logging infrastructure.
- `db_KK_T_MSKM_DTL` — Database accessor for the application detail table.
- `BLANK` — Empty string constant used as a null-equivalence sentinel.
- `RESULT_NG = "1"` — Static constant for "not eligible" determination result.
- `RESULT_OK = "0"` — Static constant for "eligible" determination result.
- `RESULT_ERROR = "9"` — Static constant for error-state return value.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `selectZmWorkParamKnri016` | KK_INTR | ZM_M_WORK_PARAM_KNRI | Reads work parameter management table to fetch the premium renewal date (プレミアムクラブリニューアル日) using the parameter ID `KK_PRCL_RNAL_YMD`. Internally calls `executeZM_M_WORK_PARAM_KNRI_KK_SELECT_016`. |
| C | `executeKK_T_MSKM_DTL_KK_SELECT_024` | KK_SELECT_024 | KK_T_MSKM_DTL | Executes a database access definition to query the application detail table by application detail number (申込明細番号). Prepares the SQL parameter array with `mskmDtlNo`. |
| R | `db_KK_T_MSKM_DTL.selectNext` | KK_SELECT_024 | KK_T_MSKM_DTL | Retrieves the next result row from the application detail table query result set. Returns the application date (申込年月日). |
| - | `JBSbatInterface.Rtrim` | - | - | Trims trailing whitespace from the retrieved application date string value. |
| - | `JKKBatOneTimeLogWriter.printBusinessErrorLog` | - | - | Logs a business error when the premium renewal date work parameter is missing or blank. Error code: `EKKB2240CW`. |
| R | `JBSbatZMAdDataSet.getString` | - | - | Reads the work parameter setting value (`WORK_PARAM_SETTE_VALUE`) from the work parameter map to extract the premium renewal date. |
| R | `JESC0101B010TPMA.getString` | - | - | Reads a string value from a database interface map (used internally by the selected row). |
| R | `JESC0101B020TPMA.getString` | - | - | Reads a string value from a database interface map (used internally by the selected row). |
| - | `JBSbatCommonDBInterface` | - | - | Interface type for work parameter map and DB result map — provides `getString()` access to result values. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKintrjhAdd.createSvcStaTgInf()` | `createSvcStaTgInf()` -> `JBSbatKKintrjhAdd.premiumClubPointJudge` | `selectZmWorkParamKnri016 [R] ZM_M_WORK_PARAM_KNRI`, `executeKK_T_MSKM_DTL_KK_SELECT_024 [C] KK_T_MSKM_DTL`, `Rtrim` [-], `printBusinessErrorLog` [-] |

**How this method fits into the larger batch flow:**

The batch entry point `createSvcStaTgInf()` processes referral target registration data. During this process, it calls `premiumClubPointJudge(mskmDtlNo)` to determine whether a given customer (identified by their application detail number) is eligible for Premium Club Points. If eligible (`RESULT_OK = "0"`), the batch proceeds to the point-awarding logic; otherwise (`RESULT_NG = "1"`), the customer is excluded from this promotion.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(initialization)` (L1813)

Initialize the determination result variable. The default assumption is "not eligible" (`RESULT_NG`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `result = RESULT_NG` // [-> RESULT_NG="1"] — Default: not eligible for Premium Club Points |

**Block 2** — [SET] `(fetch premium renewal date)` (L1816)

Retrieve the premium renewal date from the work parameter management table. This table (ZM_M_WORK_PARAM_KNRI) stores system configuration parameters, including the effective date from which Premium Club Rewards became active.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workParamKnriMap1 = selectZmWorkParamKnri016(KK_PRCL_RNAL_YMD)` // [-> KK_PRCL_RNAL_YMD="KK_PRCL_RNAL_YMD"] — Fetch premium renewal date work parameter |

**Block 3** — [IF/ELSE] `(null or blank check on work parameter)` (L1817)

Validate that the work parameter was successfully retrieved and is non-empty. If missing, log a business error and return an error state.

> Business description: The premium renewal date is a critical reference value. If it cannot be retrieved from the work parameter table (possibly due to configuration issues or data initialization gaps), the method cannot safely proceed with the date comparison. It logs the error and returns `RESULT_ERROR`.

| # | Type | Code |
|---|------|------|
| 1 | COND | `workParamKnriMap1 == null || BLANK.equals(workParamKnriMap1)` // Check if work parameter is missing or blank |
| 2 | SET | `commonItem.getLogPrint().printBusinessErrorLog(JPCBatchMessageConstant.EKKB2240CW)` // [-> EKKB2240CW="EKKB2240CW"] — Log error: Premium renewal date acquisition error |
| 3 | RETURN | `return RESULT_ERROR` // [-> RESULT_ERROR="9"] — Return error state |

**Block 4** — [SET] `(extract premium renewal year-month-day)` (L1820)

Extract the actual premium renewal date string from the work parameter map using the `WORK_PARAM_SETTE_VALUE` column key.

| # | Type | Code |
|---|------|------|
| 1 | SET | `premiumYmd = workParamKnriMap1.getString(JBSbatZM_M_WORK_PARAM_KNRI.WORK_PARAM_SETTE_VALUE)` // Extract the work parameter setting value (premium renewal date as YYYYMMDD string) |

**Block 5** — [SET] `(prepare query parameters for application detail lookup)` (L1822)

Wrap the input application detail number into an array for the database query method.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mskmDtlNoArr = new String[]{mskmDtlNo}` // [-> 1-element array containing the input application detail number] |
| 2 | CALL | `this.executeKK_T_MSKM_DTL_KK_SELECT_024(mskmDtlNoArr)` // [KK_SELECT_024] — Query KK_T_MSKM_DTL by application detail number |
| 3 | SET | `mskmYmd = BLANK` // [-> BLANK=""] — Initialize with empty string |

**Block 6** — [IF/ELSE] `(check for query result existence)` (L1825)

Determine whether the application detail record was found in the database.

> Business description: If the application detail record exists (`outDbMap_mskm_dtl != null`), extract the application date. If no record is found, the application detail number is invalid or the customer has no application on file — return `RESULT_NG` (not eligible).

| # | Type | Code |
|---|------|------|
| 1 | COND | `outDbMap_mskm_dtl != null` // Check if application detail record was found |
| 2 | SET | `mskmYmd = JBSbatStringUtil.Rtrim(outDbMap_mskm_dtl.getString(JBSbatKK_T_MSKM_DTL.MSKM_YMD))` // [-> MSKM_YMD="MSKM_YMD"] — Extract and trim the application date (申込年月日) |
| 3 | SET | `(no-op — else branch only returns)` |

**Block 6.1** — [ELSE] `(no application record found)` (L1832)

When no application detail record exists, return `RESULT_NG` immediately.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return result` // [-> result="1" (RESULT_NG)] — Not eligible because no application record exists |

**Block 7** — [IF] `(check application date is non-empty)` (L1834)

Ensure the extracted application date is a valid non-empty string before comparing.

> Business description: The application date (申込年月日) must be a non-null, non-empty value to be compared against the premium renewal date. If it is empty, the method falls through without modifying `result` and returns the default `RESULT_NG`.

| # | Type | Code |
|---|------|------|
| 1 | COND | `mskmYmd != null && !mskmYmd.isEmpty()` // Check application date is valid |
| 2 | EXEC | (proceed to Block 7.1 for the date comparison) |

**Block 7.1** — [IF] `(date comparison: application on or after renewal date)` (L1836)

Compare the application date with the premium renewal date using string-based `compareTo` (which works correctly for YYYYMMDD format strings, as they are lexicographically orderable).

> Business description: If the application date (`mskmYmd`) is on or after the premium renewal date (`premiumYmd`), meaning the customer applied during or after the Premium Club program's effective date, they are eligible for Premium Club Points. The method sets `result = RESULT_OK`. This implements the core business rule: Premium Club Points are awarded to customers who apply on or after the renewal date.

| # | Type | Code |
|---|------|------|
| 1 | COND | `premiumYmd.compareTo(mskmYmd) <= 0` // [premiumYmd <= mskmYmd] — Application date is on or after renewal date |
| 2 | SET | `result = RESULT_OK` // [-> RESULT_OK="0"] — Eligible for Premium Club Points |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `mskmDtlNo` | Field | Application detail number (申込明細番号) — Unique identifier for a customer's contract line item in the application detail table. |
| `mskmYmd` | Field | Application date (申込年月日) — The date (in YYYYMMDD format) when the customer submitted their contract application. |
| `premiumYmd` | Field | Premium renewal date (プレミアムリニューアル日) — The effective date from which the Premium Club Rewards program is active. |
| `KK_PRCL_RNAL_YMD` | Constant | Work parameter key for premium renewal date. Value: `"KK_PRCL_RNAL_YMD"`. Used to query the work parameter management table. |
| `KK_INTR_PRPOINT` | Constant | Work parameter key for intraday premium point (not used in this method). Value: `"KK_INTR_PRPOINT"`. |
| `RESULT_OK` | Constant | Determination result: eligible. Value: `"0"`. Set when the application date is on or after the premium renewal date. |
| `RESULT_NG` | Constant | Determination result: not eligible. Value: `"1"`. Set when the application date is before the renewal date, or when no application record exists. |
| `RESULT_ERROR` | Constant | Determination result: error. Value: `"9"`. Set when the premium renewal date work parameter cannot be retrieved. |
| `BLANK` | Constant | Empty string sentinel used to check for missing values. Value: `""`. |
| `ZM_M_WORK_PARAM_KNRI` | Table | Work parameter management table — Stores system configuration parameters including the premium renewal date. Accessed via `WORK_PARAM_ID` and `WORK_PARAM_SETTE_VALUE` columns. |
| `KK_T_MSKM_DTL` | Table | Application detail table — Stores customer contract application records. Contains `MSKM_YMD` (application date) and is keyed by application detail number. |
| `WORK_PARAM_SETTE_VALUE` | Field | Work parameter setting value column — The actual value stored in the work parameter management table. |
| `EKKB2240CW` | Error Code | Error message key logged when the premium renewal date work parameter acquisition fails. |
| Premium Club Points | Business term | Loyalty reward points awarded to eligible customers as part of the Premium Club Rewards program introduced during the premium renewal. |
| `createSvcStaTgInf()` | Method | Referral target information registration — The calling batch method that iterates over referral data and uses this predicate to determine point eligibility. |
| `selectZmWorkParamKnri016` | Method | Work parameter retrieval utility — Queries the work parameter management table by parameter ID, effective start date, and effective end date. |
| `executeKK_T_MSKM_DTL_KK_SELECT_024` | Method | Database access method — Executes SQL key `KK_SELECT_024` to query the application detail table by application detail number. |
