# Business Logic — JBSbatKKAdChgSmtvlRnki.selectTajgsWribKeiByTajgsWribSvcKeiNo() [21 LOC]

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

## 1. Role

### JBSbatKKAdChgSmtvlRnki.selectTajgsWribKeiByTajgsWribSvcKeiNo()

This method retrieves a list of **third-party discount contract records** (他事業者割引契約) based on a given **third-party discount contract number** (他事業者割引契約番号). It serves as a data access helper within the batch processing flow, encapsulating the logic to execute a parameterized SQL query against the `KK_T_TAJGS_WRIB_KEI` database table and collect all matching rows into a typed result list. The method is invoked by the batch's `execute()` method during contract data processing — specifically when the batch needs to examine third-party discount contract details to determine cancellation status and notify relevant parties. It follows a simple **delegation pattern**, wrapping the low-level DB interface (`db_KK_T_TAJGS_WRIB_KEI`) behind a business-meaningful method signature, and returns results as an `ArrayList<HashMap<String, Object>>` suitable for downstream iteration and field extraction.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["selectTajgsWribKeiByTajgsWribSvcKeiNo<br/>tajgsWribKeiNo"])
    INIT["Initialize resultList<br/>ArrayList of HashMaps"]
    PARAM["Build param array<br/>tajgsWribKeiNo, opeDate, opeDate"]
    EXEC["executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004(param)"]
    FETCH["db_KK_T_TAJGS_WRIB_KEI.selectNext()"]
    LOOP{dbInterface != null?}
    ADD["resultList.add(getMap())"]
    FETCH2["dbInterface = selectNext()"]
    RETURN["return resultList"]
    END(["Return"])

    START --> INIT
    INIT --> PARAM
    PARAM --> EXEC
    EXEC --> FETCH
    FETCH --> LOOP
    LOOP -->|Yes| ADD
    ADD --> FETCH2
    FETCH2 --> LOOP
    LOOP -->|No| RETURN
    RETURN --> END
```

**Processing Summary:**

1. **Initialize** an empty `ArrayList<HashMap<String, Object>>` to collect query results.
2. **Build parameter array** with three values: the input contract number (`tajgsWribKeiNo`), and the operation date (`super.opeDate`) used twice — likely for audit/tracking purposes.
3. **Execute SQL query** via `executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004(param)`, which calls `db_KK_T_TAJGS_WRIB_KEI.selectBySqlDefine()` with the SQL key `KK_SELECT_004`. This queries the `KK_T_TAJGS_WRIB_KEI` table for all rows matching the contract number.
4. **Iterate through results** using `db_KK_T_TAJGS_WRIB_KEI.selectNext()` in a while loop, converting each result row to a `HashMap` via `getMap()` and adding it to the result list.
5. **Return** the populated result list. Returns an empty list if no matching records exist.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `tajgsWribKeiNo` | `String` | Third-party discount contract number — a unique identifier used to look up discount contract records associated with another service provider's promotional pricing agreement. This acts as the primary filter key for the database query. |
| - | `super.opeDate` (instance field) | `String` | Operation date — the system date used for audit/tracking, passed as bind parameters to the SQL query (used twice, likely for start/end date range or record creation timestamp). |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKAdChgSmtvlRnki.executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004` | - | `KK_T_TAJGS_WRIB_KEI` | Calls `executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004` which executes a parameterized SQL SELECT via `db_KK_T_TAJGS_WRIB_KEI.selectBySqlDefine()` with SQL key `KK_SELECT_004` |
| R | `db_KK_T_TAJGS_WRIB_KEI.selectNext()` | - | `KK_T_TAJGS_WRIB_KEI` | Iteratively fetches next result row from the prepared SELECT query as a `JBSbatCommonDBInterface` |

## 5. Dependency Trace

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004` [-], `selectNext` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKAdChgSmtvlRnki.execute() | `JBSbatKKAdChgSmtvlRnki.execute()` -> `selectTajgsWribKeiByTajgsWribSvcKeiNo` | `executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004 [-] KK_T_TAJGS_WRIB_KEI` |

**Caller Details:**
The `execute()` method (within the same class `JBSbatKKAdChgSmtvlRnki`) retrieves a third-party discount contract number from an input map (`inMap.getString(JBSbatKKIFM267.TAJGS_WRIB_KEI_NO)`) and passes it to `selectTajgsWribKeiByTajgsWribSvcKeiNo()`. The returned list is then iterated to check cancellation status (`dskZumiFlg`) and all-termination notification flags (`allDslTchiZumiFlg`).

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(L784)` Initialize result collection

> Creates an empty `ArrayList<HashMap<String, Object>>` to hold all matching third-party discount contract records.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultList = new ArrayList<HashMap<String, Object>>()` // Initialize empty result list |

**Block 2** — [SET] `(L786)` Build parameter array

> Prepares the bind parameters for the SQL query: the contract number and the operation date (used twice, likely for audit trail purposes).

| # | Type | Code |
|---|------|------|
| 1 | SET | `param[0] = tajgsWribKeiNo` // Third-party discount contract number |
| 2 | SET | `param[1] = super.opeDate` // Operation date — audit/tracking |
| 3 | SET | `param[2] = super.opeDate` // Operation date — audit/tracking (duplicate) |

**Block 3** — [CALL] `(L791)` Execute SQL query

> Delegates to `executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004(param)` which builds a `JBSbatCommonDBInterface` parameter list and executes the SQL SELECT defined by key `KK_SELECT_004` against the `KK_T_TAJGS_WRIB_KEI` table.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_TAJGS_WRIB_KEI_KK_SELECT_004(param)` // Execute parameterized SQL query on KK_T_TAJGS_WRIB_KEI |

**Block 4** — [CALL] `(L793)` Fetch first result row

> Calls `selectNext()` on the DB interface to obtain the first row from the executed query result set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dbInterface = db_KK_T_TAJGS_WRIB_KEI.selectNext()` // Fetch first row |

**Block 5** — [WHILE] `(L795)` Iterate through all result rows

> While rows remain, convert each to a HashMap and add to the result list. This continues until `selectNext()` returns null (no more rows).

| # | Type | Code |
|---|------|------|
| 1 | WHILE | `while (dbInterface != null)` // Iterate all matching records |

**Block 5.1** — [EXEC] `(L797)` Add row to result list

> Converts the current DB interface row to a HashMap via `getMap()` and adds it to the accumulated result list.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `resultList.add((HashMap<String, Object>)dbInterface.getMap())` // Add row to results |

**Block 5.2** — [EXEC] `(L798)` Fetch next row

> Advances the cursor to the next row. When no more rows exist, this returns null and the while loop terminates.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `dbInterface = db_KK_T_TAJGS_WRIB_KEI.selectNext()` // Move to next row |

**Block 6** — [RETURN] `(L800)` Return results

> Returns the collected list of matching third-party discount contract records. Returns an empty list if no records were found.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return resultList` // Return collected contract records |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `tajgsWribKeiNo` | Field | Third-party discount contract number (他事業者割引契約番号) — unique identifier for a promotional pricing agreement with an external service provider |
| `tajgsWribKeiList` | Field | Third-party discount contract list — the returned collection of contract record maps |
| `opeDate` | Field | Operation date (運用年月日) — system date used for audit trail and data processing timestamps |
| `KK_T_TAJGS_WRIB_KEI` | Table | Third-party discount contract table — database table storing third-party discount contract records |
| `KK_SELECT_004` | Constant | SQL SELECT key — identifies the predefined SQL query for selecting third-party discount contracts |
| `selectBySqlDefine` | Method | SQL execution method — executes a parameterized SELECT query from a SQL definition file using bind parameters |
| `selectNext` | Method | Result iterator — fetches the next row from a previously executed query's result set |
| `getMap` | Method | Row extractor — converts a DB interface row into a HashMap of column names to values |
| 他事業者割引契約 | Japanese term | Third-party discount contract — a promotional pricing agreement between the service provider and an external carrier/partner that provides discounted rates to end customers |
| 他事業者 | Japanese term | Third-party / external service provider — an outside telecommunications carrier or partner organization |
| 割引 | Japanese term | Discount — reduced pricing or promotional rate |
| 契約番号 | Japanese term | Contract number — unique identifier for a contract record |
| JBSbatCommonDBInterface | Class | Batch DB interface — common interface for batch database operations, provides `setValue()` for bind parameters and `getMap()` for row extraction |
| Batch | Context | koptBatch — the batch processing module where this service method resides |
