# Business Logic — JBSbatKKMiStcKikiInfStku.searchKktk() [32 LOC]

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

## 1. Role

### JBSbatKKMiStcKikiInfStku.searchKktk()

This method performs a **search for an equipment delivery service contract** (機器提供サービス契約 — *kiki teikyou saabi keiyaku*) by service number and service code. It serves as the primary entry point for retrieving equipment delivery contract records during batch processing workflows, including equipment acquisition (機器取得 — *kiki shutoku*) and unloading/cancellation processing (荷卸 — *orooshi*).

The method implements a **routing/dispatch pattern**: it first checks whether the service code (`svc_cd`) matches specialized service types — specifically PLC (Packet over Lasercom, code `C015`) or STB (Set-Top Box, code `C009`). When matched, it delegates to the secondary method `searchKktk2()`, which employs a two-tier fallback query strategy (first querying by contract change status "110" with RSV_APLY_CD='1', then falling back to a standard cancel record). For all other service types (e.g., B-CAS card `C010`, CAS card `C011`, router `C014`, tablet `C021`), it executes a standard single-query database search using `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017`.

If the service number is empty or null, the method short-circuits and returns `null` — allowing downstream callers to handle the absence gracefully. If a record is found, it returns the database map interface; otherwise, it throws a `JBSbatBusinessException` with error code `EKKB0210CE`, indicating that the equipment delivery service contract record could not be found.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["searchKktk(svc_no, svc_cd, err_val)"])

    START --> CHECK_SVC_CD["Check svc_cd type"]

    CHECK_SVC_CD --> PLC_STB["KKTK_SVC_CD_PLC = C015"]
    CHECK_SVC_CD --> OTHERS["Other service types"]

    PLC_STB --> ROUTE2["Dispatch to searchKktk2(svc_no, svc_cd, err_val)"]
    OTHERS --> CHECK_SVC_NO["Check svc_no is not null/empty"]

    ROUTE2 --> RETURN2(["Return db_map from searchKktk2"])

    CHECK_SVC_NO --> EMPTY_SVC_NO["svc_no is null or empty"]
    CHECK_SVC_NO --> VALID_SVC_NO["svc_no has value"]

    EMPTY_SVC_NO --> RETURN_NULL(["Return null"])

    VALID_SVC_NO --> BUILD_PARAM["Build param array: param[0]=svc_no, param[1]=svc_cd, param[2]=opeDate"]

    BUILD_PARAM --> EXEC_SELECT["executeKK_T_KKTK_SVC_KEI_KK_SELECT_017(param)"]

    EXEC_SELECT --> FETCH_RESULT["db_KK_T_KKTK_SVC_KEI.selectNext() -> db_map"]

    FETCH_RESULT --> CHECK_RESULT["Check db_map is null"]

    CHECK_RESULT --> NULL_MAP["db_map is null"]
    CHECK_RESULT --> FOUND_MAP["db_map has result"]

    NULL_MAP --> THROW_ERROR["Throw JBSbatBusinessException EKKB0210CE
KK_T_KKTK_SVC_KEI, value"]

    FOUND_MAP --> RETURN_MAP(["Return db_map"])

    THROW_ERROR --> END_FAIL(["End - Error"])
    RETURN_MAP --> END_OK(["End - Success"])
    RETURN_NULL --> END_NULL(["End - No Data"])
    RETURN2 --> END_ROUTE2(["End - PLC/STB Route"])
```

**CRITICAL — Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|-----------------|
| `JBSbatKKConst.KKTK_SVC_CD_PLC` | `"C015"` | Equipment delivery service code for PLC (Packet over Lasercom) model |
| `JBSbatKKConst.KKTK_SVC_CD_STB` | — (value not found in JBSbatKKConst.java; likely `"C009"` based on `JKKSvcConst`) | Equipment delivery service code for IP-STB (Set-Top Box) |

The `KKTK_SVC_CD_STB` constant is referenced in the method as `JBSbatKKConst.KKTK_SVC_CD_STB` but does not appear in the `JBSbatKKConst.java` file at the expected offset. Based on cross-referenced usage in `JKKSvcConst.java` (line 263: `KKTK_SVC_CD_STB = "C009"`), the expected value is `"C009"`. This may indicate the constant is defined elsewhere in the inheritance hierarchy or in a parent constant class.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svc_no` | `String` | Equipment delivery service contract number (機器提供サービス契約番号) — the unique identifier for a service contract line item. If null or empty, the method returns `null` immediately without querying the database. |
| 2 | `svc_cd` | `String` | Equipment delivery service code (機器提供サービスコード) — classifies the type of equipment service. Controls the routing: if `C015` (PLC) or `C009` (STB), dispatches to `searchKktk2()` with a two-tier fallback query; otherwise, uses the standard single-query path via `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017`. |
| 3 | `err_val` | `String` | Error log output text (エラーログ出力用文言) — contextual label appended to the error message when a contract record is not found. Used to identify the calling context in error messages (e.g., "equipment delivery service contract number (context_label): svc_no"). |

**Instance fields / external state read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `super.opeDate` | `String` (inherited from `JBSbatBusinessService`) | Operation date — the current batch processing date, used as the third element of the query parameter array to filter records by processing date. |
| `db_KK_T_KKTK_SVC_KEI` | `JBSbatKK_T_KKTK_SVC_KEI` | Database accessor interface for the `KK_T_KKTK_SVC_KEI` table — used to execute the SQL query and retrieve the selected record. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKMiStcKikiInfStku.executeKK_T_KKTK_SVC_KEI_KK_SELECT_017` | (CBS) | `KK_T_KKTK_SVC_KEI` | Executes SQL-based SELECT on the equipment delivery service contract table. Builds a parameter list from `svc_no`, `svc_cd`, and `opeDate`, then calls `selectBySqlDefine` with the `KK_T_KKTK_SVC_KEI_KK_SELECT_017` SQL definition. |
| R | `JBSbatKKMiStcKikiInfStku.searchKktk2` | (CBS) | `KK_T_KKTK_SVC_KEI` | Secondary search for PLC/STB service codes. Performs a two-tier query: first tries `executeKK_T_KKTK_SVC_KEI_KK_SELECT_240` (contract change status "110" with RSV_APLY_CD='1'), then falls back to `executeKK_T_KKTK_SVC_KEI_KK_SELECT_241` (standard cancel record). |

### Detailed CRUD classification:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017` | (CBS) | `KK_T_KKTK_SVC_KEI` | Standard single-query SELECT on the equipment delivery service contract table (`KK_T_KKTK_SVC_KEI`). Parameters: service contract number, service code, and operation date. Retrieves the latest contract record matching the criteria. |
| R | `searchKktk2` | (CBS) | `KK_T_KKTK_SVC_KEI` | Two-tier fallback SELECT for PLC (`C015`) and STB (`C009`) service types. First queries for contract change-in-progress records (status "110", `RSV_APLY_CD`='1'), then falls back to standard cancel records. Uses `db_KK_T_KKTK_SVC_KEI2` table accessor. |

**How these were classified:**
- Both called methods are **Read (R)** operations — they contain `selectBySqlDefine` calls with `KK_SELECT_*` naming pattern.
- `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017` directly invokes `db_KK_T_KKTK_SVC_KEI.selectBySqlDefine(paramList, KK_T_KKTK_SVC_KEI_KK_SELECT_017)`.
- `searchKktk2` invokes both `executeKK_T_KKTK_SVC_KEI_KK_SELECT_240` and `executeKK_T_KKTK_SVC_KEI_KK_SELECT_241` (conditional fallback).

## 5. Dependency Trace

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

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: `JBSbatKKMiStcKikiInfStku.executeKKtkAndUcwk()` | `executeKKtkAndUcwk()` -> `searchKktk(svc_no, svc_cd, err_val)` | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017` [R] `KK_T_KKTK_SVC_KEI` |
| 2 | CBS: `JBSbatKKMiStcKikiInfStku.executeKktkSvcNo()` | `executeKktkSvcNo()` -> `searchKktk(svc_no, svc_cd, err_val)` | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017` [R] `KK_T_KKTK_SVC_KEI` |

**Notes:**
- Both callers are internal CBS (Common Business Service) methods within `JBSbatKKMiStcKikiInfStku`, indicating this method is a shared utility used within the equipment information acquisition (機器情報取得 — *kiki jouhou shutoku*) processing suite.
- `executeKKtkAndUcwk()` handles equipment acquisition and unloading processing (機器取得荷卸処理).
- `executeKktkSvcNo()` handles equipment delivery service number search processing (機器提供サービス契約番号検索処理).
- No screen (KKSV*) or batch (JS*) entry points were found within 8 hops — suggesting this method is primarily called by other CBS methods rather than directly by screens or batch entry points.

## 6. Per-Branch Detail Blocks

**Block 1** — IF `[svc_cd matches PLC or STB]` (L895)

> Routes PLC and STB service codes to the secondary search method (`searchKktk2`) which uses a two-tier fallback query strategy. This routing was added in v32.00.00 (2017/06/30, OM-2017-0000618) to change the equipment information acquisition method for STB and PLC.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `JBSbatKKConst.KKTK_SVC_CD_PLC.equals(svc_cd) || JBSbatKKConst.KKTK_SVC_CD_STB.equals(svc_cd)` `[KKTK_SVC_CD_PLC="C015"]` |
| 2 | CALL | `return searchKktk2(svc_no, svc_cd, err_val)` — delegates to secondary search with two-tier fallback query |
| 3 | RETURN | returns `db_map` from `searchKktk2` |

**Block 2** — [default / else branch: non-PLC/non-STB service codes] (L898)

> Handles all other service types (e.g., B-CAS card `C010`, CAS card `C011`, router `C014`, tablet `C021`, etc.) using the standard single-query search path.

| # | Type | Code |
|---|------|------|
| 1 | SET | `db_map = null` — initializes the database map interface to null |
| 2 | SET | `param = new String[3]` — creates a 3-element string array for query parameters |

**Block 3** — IF `[svc_no null/empty check]` (L903)

> Validates that the service contract number is provided. If missing, short-circuits and returns null without querying the database. This allows callers to handle the absence gracefully rather than throwing an error.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `null == svc_no || 0 == svc_no.length()` |
| 2 | RETURN | `return db_map` — returns null (uninitialized db_map) |

**Block 4** — [svc_no is valid — parameter building] (L910)

> Constructs the query parameter array with the service contract number, service code, and the operation date inherited from the parent class.

| # | Type | Code |
|---|------|------|
| 1 | SET | `param[0] = svc_no` — service contract number |
| 2 | SET | `param[1] = svc_cd` — service code |
| 3 | SET | `param[2] = super.opeDate` — operation date from parent class `JBSbatBusinessService` |

**Block 5** — EXEC `[execute database SELECT]` (L914)

> Executes the SQL-based SELECT query against the `KK_T_KKTK_SVC_KEI` table. The called method `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017` builds a parameter list and calls `db_KK_T_KKTK_SVC_KEI.selectBySqlDefine(paramList, KK_T_KKTK_SVC_KEI_KK_SELECT_017)`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KKTK_SVC_KEI_KK_SELECT_017(param)` — triggers SQL SELECT on equipment delivery service contract table |
| 2 | EXEC | `db_map = db_KK_T_KKTK_SVC_KEI.selectNext()` — retrieves the next record from the query result set |

**Block 6** — IF `[search result null check]` (L918)

> If no record was found by the SELECT query, throws a business exception with error code `EKKB0210CE`, including the table name `KK_T_KKTK_SVC_KEI` and a formatted value string containing the error context label and service contract number.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `null == db_map` |
| 2 | SET | `value = "機器提供サービス契約番号（" + err_val + "）：" + svc_no` `[English: "Equipment delivery service contract number (" + err_val + "): " + svc_no]` |
| 3 | EXEC | `throw new JBSbatBusinessException(JPCBatchMessageConstant.EKKB0210CE, new String[]{"KK_T_KKTK_SVC_KEI", value})` — throws batch business exception with table name and formatted error value |

**Block 7** — [normal success path] (L922)

> Returns the successfully retrieved database map interface containing the equipment delivery service contract record.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return db_map` — returns the query result |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svc_no` | Field | Service contract number (機器提供サービス契約番号) — unique identifier for an equipment delivery service contract line item |
| `svc_cd` | Field | Service code (機器提供サービスコード) — classifies the type of equipment service (PLC, STB, router, tablet, B-CAS, etc.) |
| `err_val` | Field | Error context value (エラーログ出力用文言) — contextual label used to identify the calling context in error messages |
| `opeDate` | Field | Operation date (操作日) — the current batch processing date, inherited from the parent `JBSbatBusinessService` class |
| `db_KK_T_KKTK_SVC_KEI` | Field | Database accessor for the `KK_T_KKTK_SVC_KEI` table — equipment delivery service contract status management table |
| `db_KK_T_KKTK_SVC_KEI2` | Field | Secondary database accessor — used by `searchKktk2()` for PLC/STB fallback queries |
| KK_T_KKTK_SVC_KEI | Entity/DB | Equipment Delivery Service Contract Status Management Table (機器提供サービス契約状態管理表) — core table storing equipment delivery service contract records, including status and reservation application codes |
| KK_T_KKTK_SVC_KEI_KK_SELECT_017 | SQL Def. | SQL definition for standard equipment delivery service contract SELECT query with PK-based filtering |
| KK_T_KKTK_SVC_KEI_KK_SELECT_240 | SQL Def. | SQL definition for contract change-in-progress query (status "110", RSV_APLY_CD='1') — first tier of PLC/STB fallback |
| KK_T_KKTK_SVC_KEI_KK_SELECT_241 | SQL Def. | SQL definition for standard cancel record query — fallback second tier of PLC/STB search |
| KKTK_SVC_CD_PLC | Constant | Service code `"C015"` — PLC (Packet over Lasercom) model equipment delivery service |
| KKTK_SVC_CD_STB | Constant | Service code `"C009"` (expected, not verified in JBSbatKKConst.java) — IP-STB (Set-Top Box) equipment delivery service |
| KKTK_SVC_CD_B_CAS | Constant | Service code `"C010"` — B-CAS card (smart card for broadcast content decryption) |
| KKTK_SVC_CD_ROUTER | Constant | Service code `"C014"` — Router model equipment delivery service |
| KKTK_SVC_CD_TABLET | Constant | Service code `"C021"` — Tablet model equipment delivery service |
| EKKB0210CE | Error Code | Business exception error code — indicates a record was not found in the `KK_T_KKTK_SVC_KEI` table |
| JBSbatBusinessException | Class | Batch business exception — thrown when business logic rules are violated (e.g., missing contract record) |
| JBSbatCommonDBInterface | Interface | Common database interface — generic return type for database query results, providing `selectNext()` to retrieve records |
| JBSbatBusinessService | Class | Parent class for all batch business services — provides inherited fields like `opeDate` |
| 機器取得荷卸処理 | Japanese term | Equipment Acquisition and Unloading Processing — batch process for acquiring equipment and performing unloading (荷卸) operations |
| 機器情報取得 | Japanese term | Equipment Information Acquisition — the broader processing suite in which `searchKktk` participates |
| 契約変更中 | Japanese term | Contract Change-in-Progress — contract status code `"110"` indicating a pending service contract change |
| RSV_APLY_CD | Field | Reservation Application Code — database field indicating reservation application status (`'1'` = applied) |
| PLC | Business term | Packet over Lasercom — a laser communication-based broadband delivery service model using packet transmission over optical links |
| STB | Business term | Set-Top Box — set-top box equipment for cable/satellite television reception |
| B-CAS | Business term | Broadcast Content Authentication System — Japanese smart card used for broadcast content decryption and rights management |
| 機器提供サービス | Japanese term | Equipment Delivery Service — service involving the delivery of equipment (PLC terminals, STBs, routers, tablets) to customers |
| 機器提供サービス契約 | Japanese term | Equipment Delivery Service Contract — the formal contract record linking a customer to delivered equipment |
