# Business Logic — JBSbatKKBndWdtOvrSendPstCrd.getLastMonthFtthFstYmd() [24 LOC]

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

## 1. Role

### JBSbatKKBndWdtOvrSendPstCrd.getLastMonthFtthFstYmd()

This private method retrieves the **first-time FTTH communication volume over-notice date** (FTTH通信量初回超過通知年月日) for a given service contract's **previous month** of usage. In the broader batch workflow for sending over-limit notifications to Fiber-to-the-Home (FTTH) customers, this method serves as a **data-fetching utility** that queries the FTTH communication volume excess history table (`KK_T_FTTH_TSRCK_JSK`) to determine when the customer first exceeded their communication quota. It constructs a composite lookup key from the service contract number (`svcKeiNo`), price course code (`pcrsCd`), price plan code (`pplanCd`), and the target month (computed as last month relative to the current operation date), then returns the stored over-notice date from the matching record, or `null` if no record exists. This method is exclusively called internally by `updateFtthTsrckJsk()` to populate the over-notice date field in the batch update payload, either for actual notifications or warning notifications depending on the send type flag.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getLastMonthFtthFstYmd(svcKeiNo, pcrsCd, pplanCd)"])
    step1["Create whereMap (JBSbatCommonDBInterface)"]
    step2["Set SVC_KEI_NO = svcKeiNo"]
    step3["Set PCRS_CD = pcrsCd"]
    step4["Set PPLAN_CD = pplanCd"]
    step5["Call getTargetNengetsu(1)"]
    step6["Set FTTH_TUSHIN_USE_YM = last month year/month"]
    step7["Call executeKK_T_FTTH_TSRCK_JSK_PKSELECT(whereMap)"]
    step8{null != ftthInfo?}
    step9["ftthFstYmd = ftthInfo.getString(FTTH_TSR_FST_CHOK_TCH_YMD)"]
    END(["Return ftthFstYmd"])

    START --> step1
    step1 --> step2
    step2 --> step3
    step3 --> step4
    step4 --> step5
    step5 --> step6
    step6 --> step7
    step7 --> step8
    step8 -- "true (row exists)" --> step9
    step8 -- "false (no row)" --> END
    step9 --> END
```

**Processing Summary:**
1. **Initialize** a `JBSbatCommonDBInterface` object as the query parameter carrier (`whereMap`).
2. **Set composite key fields** — service contract number, price course code, and price plan code — onto the whereMap. These three fields form the primary key for the target table.
3. **Calculate target month** — call `getTargetNengetsu(1)` which computes `operationDate - 1 day - 1 month` and returns the year/month as a 6-character string (e.g., `"202605"` for May 2026).
4. **Set the target month** onto the whereMap as the FTTH usage month criterion.
5. **Execute primary key SELECT** — call `executeKK_T_FTTH_TSRCK_JSK_PKSELECT(whereMap)` to look up a single row from the `KK_T_FTTH_TSRCK_JSK` table matching all four criteria.
6. **Conditional branch** — if a matching row is found (`null != ftthInfo`), extract the over-notice date field (`FTTH_TSR_FST_CHOK_TCH_YMD`); otherwise leave `ftthFstYmd` as `null`.
7. **Return** the result.

## 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 as part of the composite primary key to locate the correct FTTH excess history record. |
| 2 | `pcrsCd` | `String` | Price Course Code — identifies the billing course (rate plan tier) assigned to the service contract. Combined with the plan code, it fully qualifies the customer's service tier. |
| 3 | `pplanCd` | `String` | Price Plan Code — identifies the specific pricing plan associated with the service contract. Together with the price course code, forms the service tier key. |

**Additional State Read:**
- `super.opeDate` — The current operation date (batch execution date), inherited from the parent class. Used by `getTargetNengetsu()` to compute the target month.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKBndWdtOvrSendPstCrd.executeKK_T_FTTH_TSRCK_JSK_PKSELECT` | (internal batch method) | `KK_T_FTTH_TSRCK_JSK` (FTTH Communication Volume Excess History) | Primary-key SELECT — retrieves a single row from the FTTH excess history table using the composite key (service contract number, price course code, price plan code, usage month). Returns a `JBSbatCommonDBInterface` carrying the row data, or `null` if no match. |
| R | `JBSbatKKBndWdtOvrSendPstCrd.getTargetNengetsu` | (internal batch method) | — | Computes the target year/month string by subtracting months from the operation date. Used to determine "last month" for the query criterion. |
| - | `JBSbatCommonDBInterface.setValue` | — | — | Sets key-value pairs in the query parameter map (whereMap). Four fields are set: SVC_KEI_NO, PCRS_CD, PPLAN_CD, FTTH_TUSHIN_USE_YM. |
| R | `JBSbatCommonDBInterface.getString` | — | — | Extracts a string value from the result map (`ftthInfo`) — retrieves the over-notice date field `FTTH_TSR_FST_CHOK_TCH_YMD`. |

**Table details — `KK_T_FTTH_TSRCK_JSK` (FTTH Communication Volume Excess History):**
This table tracks FTTH customer communication volume excess records. Key fields relevant to this method include:
- `SVC_KEI_NO` — Service Contract Number (PK component)
- `PCRS_CD` — Price Course Code (PK component)
- `PPLAN_CD` — Price Plan Code (PK component)
- `FTTH_TUSHIN_USE_YM` — FTTH Communication Usage Year/Month (PK component)
- `FTTH_TSR_FST_CHOK_TCH_YMD` — FTTH First Over-Notice Date (the value being retrieved)

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKBndWdtOvrSendPstCrd.updateFtthTsrckJsk` | `updateFtthTsrckJsk(svcKeiNo, sendKbn)` -> `getLastMonthFtthFstYmd(svcKeiNo, pcrsCd, pplanCd)` | `executeKK_T_FTTH_TSRCK_JSK_PKSELECT [R] KK_T_FTTH_TSRCK_JSK`, `getString [R] FTTH_TSR_FST_CHOK_TCH_YMD` |
| 2 | Batch: `JBSbatKKBndWdtOvrSendMl` (commented-out usage) | `getLastMonthFtthFstYmd` — referenced in comments (L930, L957), not actively called | — |

**Notes:**
- The primary caller is `updateFtthTsrckJsk()` within the same class. This method determines whether the batch is performing an **actual notification** (`SEND_KBN_JISHI`), a **warning notification** (`SEND_KBN_YOKOKU`), or neither, and calls `getLastMonthFtthFstYmd` for the actual notification and fallback cases to populate the over-notice date field.
- In `JBSbatKKBndWdtOvrSendMl`, calls to this method exist as commented-out code (L930, L957), suggesting cross-batch parity or historical usage.

## 6. Per-Branch Detail Blocks

**Block 1** — [INITIALIZATION] (L670)

> Initialize the query parameter container and local variables.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereMap = new JBSbatCommonDBInterface()` — Create empty query parameter map |
| 2 | SET | `ftthFstYmd = null` — Initialize return value to null |

**Block 2** — [SET x3] (L673–676)

> Set the composite primary key fields onto the whereMap. These three fields identify the specific service contract and its pricing tier.

| # | Type | Code | Business Meaning |
|---|------|------|------------------|
| 1 | SET | `whereMap.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.SVC_KEI_NO, svcKeiNo)` | Service Contract Number [-> `SVC_KEI_NO`] |
| 2 | SET | `whereMap.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.PCRS_CD, pcrsCd)` | Price Course Code [-> `PCRS_CD`] |
| 3 | SET | `whereMap.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.PPLAN_CD, pplanCd)` | Price Plan Code [-> `PPLAN_CD`] |

**Block 3** — [SET] (L678–679)

> Calculate the target month as last month relative to the operation date, and set it as a query criterion. `getTargetNengetsu(1)` computes: `operationDate - 1 day - 1 month`, returning a 6-character year/month string (e.g., `"202605"`).

| # | Type | Code | Business Meaning |
|---|------|------|------------------|
| 1 | CALL | `tshinYm = getTargetNengetsu(1)` | Compute last month's year/month string |
| 2 | SET | `whereMap.setValue(JBSbatKK_T_FTTH_TSRCK_JSK.FTTH_TUSHIN_USE_YM, tshinYm)` | FTTH Usage Year/Month [-> `FTTH_TUSHIN_USE_YM`] |

**Block 4** — [CALL] (L681)

> Execute the primary-key SELECT against the FTTH excess history table.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `ftthInfo = executeKK_T_FTTH_TSRCK_JSK_PKSELECT(whereMap)` | Retrieve FTTH excess record by composite key. Returns `JBSbatCommonDBInterface` with row data, or `null` if no match. |

**Block 5** — [IF-ELSE] `null != ftthInfo` (L683–686)

> Conditional branch: if a matching record was found, extract the over-notice date. If not, the return value stays `null`.

| # | Type | Code | Business Meaning |
|---|------|------|------------------|
| 1 | SET | `ftthFstYmd = ftthInfo.getString(JBSbatKK_T_FTTH_TSRCK_JSK.FTTH_TSR_FST_CHOK_TCH_YMD)` | Extract first over-notice date [-> `FTTH_TSR_FST_CHOK_TCH_YMD`] |

**Block 5.1** — [ELSE branch — implicit] (L683–686)

> When no matching record exists, `ftthFstYmd` remains `null`, indicating no prior over-notice date is on record for this service.

**Block 6** — [RETURN] (L688)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return ftthFstYmd` | Returns the over-notice date string, or `null` if no FTTH excess record exists |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiNo` | Field | Service Contract Number — unique identifier for a customer's service contract line item |
| `pcrsCd` | Field | Price Course Code — billing course/tier classification for the service contract |
| `pplanCd` | Field | Price Plan Code — specific pricing plan associated with the service contract |
| `ftthFstYmd` | Field | FTTH First Over-Notice Date — the date when the customer first exceeded their communication volume quota and was notified |
| `tshinYm` | Field | Usage Year/Month — the 6-character year/month string (e.g., "202605") representing the target month for the query |
| FTTH | Business term | Fiber To The Home — fiber-optic broadband internet service |
| `KK_T_FTTH_TSRCK_JSK` | Table | FTTH Communication Volume Excess History — database table tracking when FTTH customers exceeded their communication quota |
| `FTTH_TSR_FST_CHOK_TCH_YMD` | Field | FTTH First Over-Notice Year/Month/Day — the date field stored in the excess history table indicating when over-notice was first issued |
| `FTTH_TUSHIN_USE_YM` | Field | FTTH Communication Usage Year/Month — the month for which communication volume is being tracked and checked |
| `SVC_KEI_NO` | Field | Service Contract Number — primary key component identifying the service contract |
| `PCRS_CD` | Field | Price Course Code — primary key component identifying the billing course |
| `PPLAN_CD` | Field | Price Plan Code — primary key component identifying the pricing plan |
| `opeDate` | Field | Operation Date — the current batch execution date, used as the reference point for computing "last month" |
| `SEND_KBN_JISHI` | Constant | Actual Notification Type — send type flag indicating a real (actual) notification is being sent |
| `SEND_KBN_YOKOKU` | Constant | Warning Notification Type — send type flag indicating a warning (pre-emptive) notification is being sent |
| `getTargetNengetsu(minus)` | Method | Target Month Calculator — computes year/month string by subtracting days and months from the operation date |
| `JBSbatCommonDBInterface` | Component | Common Database Interface — a key-value map used to carry query parameters and result data between batch methods |
