# Business Logic — JBSbatKKBndWdtOvrSendPstCrd.lockFtthTsrckJsk() [15 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKBndWdtOvrSendPstCrd` |
| Layer | Batch (package `eo.business.service` within `koptBatch`) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKBndWdtOvrSendPstCrd.lockFtthTsrckJsk()

This method locks a row in the **FTTH Traffic Excess Record** table (`KK_T_FTTH_TSRCK_JSK`) by performing a **pessimistic row lock** via `SELECT FOR UPDATE`. It is a private, internal-purpose method used exclusively by the batch processing service `JBSbatKKBndWdtOvrSendPstCrd` to protect concurrent updates to FTTH (Fiber To The Home) utilization records.

In business terms, FTTH customers accumulate monthly traffic usage that is tracked in the `KK_T_FTTH_TSRCK_JSK` table. When the batch process needs to update or process this usage data (e.g., to calculate whether a customer has exceeded their traffic quota for the first time), it must first acquire an exclusive lock on the corresponding row to prevent race conditions caused by concurrent batch executions or system updates. This method assembles the lock criteria — consisting of the service contract number, tariff course code, tariff plan code, and the target utilization year-month — into a `JBSbatCommonDBInterface` parameter object and delegates the actual `SELECT FOR UPDATE` to a dedicated batch DB interface method.

The method implements a **delegation pattern**: it constructs the locking parameter and delegates the actual database locking to `executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE`. It plays the role of a **shared utility helper** within the batch service, called by `updateFtthTsrckJsk()` before performing further data modifications on the FTTH traffic record.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["lockFtthTsrckJsk svcKeiNo, pcrsCd, pplanCd"])
    CREATE["Create lockParam as JBSbatCommonDBInterface"]
    SET_SVC["SET SVC_KEI_NO = svcKeiNo"]
    SET_PCRS["SET PCRS_CD = pcrsCd"]
    SET_PPLAN["SET PPLAN_CD = pplanCd"]
    CALL_NENGETSU["CALL getTargetNengetsu(0)"]
    SET_NENGETSU["SET FTTH_TUSHIN_USE_YM = target year-month from opeDate"]
    CALL_LOCK["CALL executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE(lockParam)"]
    END_NODE(["Return / Next"])

    START --> CREATE
    CREATE --> SET_SVC
    SET_SVC --> SET_PCRS
    SET_PCRS --> SET_PPLAN
    SET_PPLAN --> CALL_NENGETSU
    CALL_NENGETSU --> SET_NENGETSU
    SET_NENGETSU --> CALL_LOCK
    CALL_LOCK --> END_NODE
```

**Constant Resolution:**

| Constant | Actual Value | Business Meaning |
|----------|-------------|------------------|
| `JBSbatKK_T_FTTH_TSRCK_JSK.TABLE_NAME` | `"KK_T_FTTH_TSRCK_JSK"` | FTTH Communication Volume Excess Record table |
| `JBSbatKK_T_FTTH_TSRCK_JSK.SVC_KEI_NO` | `"SVC_KEI_NO"` | Service contract number |
| `JBSbatKK_T_FTTH_TSRCK_JSK.PCRS_CD` | `"PCRS_CD"` | Tariff course code |
| `JBSbatKK_T_FTTH_TSRCK_JSK.PPLAN_CD` | `"PPLAN_CD"` | Tariff plan code |
| `JBSbatKK_T_FTTH_TSRCK_JSK.FTTH_TUSHIN_USE_YM` | `"FTTH_TUSHIN_USE_YM"` | FTTH communication utilization year-month |

**Processing Summary:**
1. **Initialize** a `JBSbatCommonDBInterface` object (`lockParam`) to hold the lock criteria.
2. **Populate** the service contract number, tariff course code, and tariff plan code into `lockParam`. These three fields form the composite key used to identify the specific FTTH record to lock.
3. **Compute the target year-month** by calling `getTargetNengetsu(0)`, which derives the year-month string from the batch operation date (`opeDate` minus 1 day, minus 0 additional months, formatted as `yyyyMM`).
4. **Set the computed year-month** as the `FTTH_TUSHIN_USE_YM` field in `lockParam`.
5. **Execute the lock** by invoking `executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE(lockParam)`, which performs a `SELECT ... FOR UPDATE` on the `KK_T_FTTH_TSRCK_JSK` table using all four criteria to acquire an exclusive row lock.
6. **Return** immediately after the lock is acquired (no conditional branches — linear execution).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiNo` | `String` | **Service Contract Number** — The unique identifier for a customer's service contract line. Used to locate the correct FTTH traffic record in the `KK_T_FTTH_TSRCK_JSK` table. |
| 2 | `pcrsCd` | `String` | **Tariff Course Code** — Identifies the pricing/tariff course assigned to the service contract. Part of the composite key for record identification. |
| 3 | `pplanCd` | `String` | **Tariff Plan Code** — Identifies the specific tariff plan associated with the service contract. Together with `pcrsCd` and `svcKeiNo`, forms the full composite key for uniquely identifying the FTTH traffic record. |

**Additional state accessed:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `super.opeDate` | `Date` (inherited) | The batch operation date — used by `getTargetNengetsu(0)` to compute the target year-month for locking. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `JBSbatKKBndWdtOvrSendPstCrd.executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE` | (inferred: batch SC) | `KK_T_FTTH_TSRCK_JSK` | Executes `SELECT ... FOR UPDATE` on the FTTH Traffic Excess Record table to acquire an exclusive row lock using the composite key (SVC_KEI_NO, PCRS_CD, PPLAN_CD, FTTH_TUSHIN_USE_YM). |
| R | `JBSbatKKBndWdtOvrSendPstCrd.getTargetNengetsu` | (inferred: batch utility) | — | Retrieves the target year-month string based on the batch operation date (`opeDate`). Called with argument `0` to get the previous month. |
| - | `JDKStructuredMap.setValue` | — | — | Sets key-value pairs in the `JBSbatCommonDBInterface` parameter object (internal data structure wrapper). |

**CRUD Classification Rationale:**
- **U (Update via SELECT FOR UPDATE)**: The `executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE` method performs a `SELECT ... FOR UPDATE` query. Although it is a read query, it acquires an exclusive lock (pessimistic concurrency control) on the target row, which is classified as a "lock" operation preceding an update. This is standard pattern in enterprise batch processing where rows are locked before modification.
- **R (Read)**: `getTargetNengetsu(0)` reads from the inherited `opeDate` field and performs date arithmetic to derive the previous month's year-month string (`yyyyMM` format).

## 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: `JBSbatKKBndWdtOvrSendPstCrd.updateFtthTsrckJsk` | `updateFtthTsrckJsk(svcKeiNo, sendKbn)` -> `lockFtthTsrckJsk(svcKeiNo, pcrsCd, pplanCd)` | `executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE [U] KK_T_FTTH_TSRCK_JSK` |

**Dependency Summary:**
- **Direct Caller**: `updateFtthTsrckJsk()` (private method within the same class `JBSbatKKBndWdtOvrSendPstCrd`) calls `lockFtthTsrckJsk()` to acquire a row lock before performing update operations on the FTTH traffic excess record.
- **Caller Context**: `updateFtthTsrckJsk()` is called at line 208 of the same class (likely from a batch main processing loop that iterates over FTTH customer records).
- **Terminal Operations**: The sole terminal operation is `executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE` which performs a `SELECT FOR UPDATE` on the `KK_T_FTTH_TSRCK_JSK` table.

## 6. Per-Branch Detail Blocks

**Block 1** — [ASSIGN/SEQUENCE] `lockParam` initialization (L777)

> Creates the parameter object for the lock criteria and populates the composite key fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `lockParam = new JBSbatCommonDBInterface()` // Initialize empty parameter object |
| 2 | SET | `lockParam.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.SVC_KEI_NO, svcKeiNo)` // Set service contract number [-> SVC_KEI_NO="SVC_KEI_NO"] |
| 3 | SET | `lockParam.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.PCRS_CD, pcrsCd)` // Set tariff course code [-> PCRS_CD="PCRS_CD"] |
| 4 | SET | `lockParam.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.PPLAN_CD, pplanCd)` // Set tariff plan code [-> PPLAN_CD="PPLAN_CD"] |

**Block 2** — [ASSIGN/SEQUENCE] `FTTH_TUSHIN_USE_YM` population (L784-785)

> Computes the target year-month from the batch operation date and sets it in the lock parameter.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `nengetsu = getTargetNengetsu(0)` // Get previous month from opeDate, minus 0 additional months. Returns `yyyyMM` formatted string. |
| 2 | SET | `lockParam.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.FTTH_TUSHIN_USE_YM, nengetsu)` // Set FTTH communication utilization year-month [-> FTTH_TUSHIN_USE_YM="FTTH_TUSHIN_USE_YM"] |

**Block 3** — [CALL] Row lock execution (L787)

> Acquires a pessimistic row lock on the FTTH traffic record.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE(lockParam)` // Executes `SELECT ... FOR UPDATE` on KK_T_FTTH_TSRCK_JSK using all 4 criteria. Blocks until the row is locked. |
| 2 | RETURN | `// Return void` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiNo` | Field | Service contract number — unique identifier for a customer's service contract line item in the FTTH system |
| `pcrsCd` | Field | Tariff course code — identifies the pricing tier/course assigned to the service contract |
| `pplanCd` | Field | Tariff plan code — identifies the specific tariff plan associated with the service contract |
| `opeDate` | Field | Operation date — the batch processing date used as the reference point for computing target periods |
| `nengetsu` | Field | Target year-month — a `yyyyMM` formatted string derived from the operation date |
| `KK_T_FTTH_TSRCK_JSK` | Table | FTTH Communication Volume Excess Record table — stores per-customer FTTH traffic usage records including excess notification data |
| FTTH | Business term | Fiber To The Home — fiber-optic broadband internet service provided by K-Opticom |
| `SELECT FOR UPDATE` | Technical | Pessimistic locking mechanism — acquires an exclusive row-level lock so no other transaction can modify the row until the current transaction commits |
| `JBSbatCommonDBInterface` | Class | Batch common DB interface — a structured map data structure used to pass parameters to batch DB operations (extends JDK `StructuredMap`) |
| `getTargetNengetsu` | Method | Target month calculator — derives a `yyyyMM` year-month string by subtracting a specified number of months and days from the batch operation date |
| `executeKK_T_FTTH_TSRCK_JSK_PKSELECT_FORUPDATE` | Method | Primary key SELECT with pessimistic lock — executes a `SELECT FOR UPDATE` query on the FTTH traffic excess record table |
| `SVC_KEI_NO` | Constant | Service contract number column key |
| `PCRS_CD` | Constant | Tariff course code column key |
| `PPLAN_CD` | Constant | Tariff plan code column key |
| `FTTH_TUSHIN_USE_YM` | Constant | FTTH communication utilization year-month column key |
| `FTTH_TSR_FST_CHOK_TCH_YMD` | Constant | FTTH traffic excess first notification year-month-day column key |
| `TIK_CTL_JSSI_ZM_FLG` | Constant | Domain control implementation flag — indicates whether domain restriction has been applied |
| `TIK_CTL_JSSI_YMD` | Constant | Domain control implementation year-month-day |
| `ISP_NINSHO_ID` | Constant | ISP authentication ID — authentication ID for internet service provider linkage |
| `MLTISE_NINSHO_ID` | Constant | Multiplex authentication ID — authentication ID for multiplexed service linkage |
| `ADD_DTM` | Constant | Registration datetime — timestamp when the record was created |
| `ADD_OPEACNT` | Constant | Registration operator account — operator who created the record |
| `UPD_DTM` | Constant | Update datetime — timestamp when the record was last modified |
| `UPD_OPEACNT` | Constant | Update operator account — operator who last modified the record |
| `DEL_DTM` | Constant | Deletion datetime — timestamp when the record was deleted |
| `DEL_OPEACNT` | Constant | Deletion operator account — operator who deleted the record |
| `MK_FLG` | Constant | Invalid/marked flag — soft-delete indicator for the record |
| `ADD_UNYO_YMD` | Constant | Registration operational year — operational date for registration |
