# Business Logic — JBSbatKKKjClDataInTrn.insertKkOpSvcKeiTakinoRouterDslCncl() [99 LOC]

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

## 1. Role

### JBSbatKKKjClDataInTrn.insertKkOpSvcKeiTakinoRouterDslCncl()

This method orchestrates the **cancellation registration for an Equipment Option Service Contract** across two functional paths: **Router function** (ルータ機能 — the main equipment option service contract processing path) and **VA function** (VA機能 — Virtual Assignment / value-add function for equipment-provided service contracts). It serves as a **batch-level coordinator** that queries the system for existing contract records in each function path, and when found, triggers contract cancellation registration, progress update, and — for VA — phone number rewriting.

The method implements a **dual-path sequential dispatch pattern**: first it queries the **router function** (identified by key `G01`), and if data exists, it performs contract cancellation registration and progress cancellation registration. Then it independently queries the **VA function** (key `G02`), and if data exists, it performs the same contract cancellation and progress cancellation, but additionally rewrites the phone number in the service contract detail and related tables. This separation ensures that both the main service contract and any value-added equipment provisioning are cancelled independently.

Its role in the larger system is a **batch entry point** for the equipment option service contract cancellation workflow. It is called by itself within the same class (the method's caller is itself, meaning it is likely invoked from an outer batch orchestration layer not traced within 8 hops). It delegates to `kkOpSvcKeiAdd()` for contract status transformation, `insertPrgKiki()` for progress registration, and `telnoHmdkUpd()` for phone number rewrites.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertKkOpSvcKeiTakinoRouterDslCncl(kktkSvcKei_map, kojiakFinYmd, svcKeiNo)"])
    START --> INIT["Initialize: dbMapKkOpSvcKei = null, dbMapKkOpSvcKeiPk = null, kkopSvcKeiNo = empty, geneAddDtm = empty"]
    INIT --> READ_KKTK["Read kktkSvcKeiNo = Rtrim(kktkSvcKei_map.getString(KKTK_SVC_KEI_NO))"]
    READ_KKTK --> ROUTER_QUERY["Query router function: executeKK_T_KKOP_SVC_KEI_KK_SELECT_003(kktkSvcKeiNo, G01, super.opeDate)"]
    ROUTER_QUERY --> ROUTER_RESULT["dbMapKkOpSvcKei = db_KK_T_KKOP_SVC_KEI.selectNext()"]
    ROUTER_RESULT --> CHECK_ROUTER{Query returns data?}
    CHECK_ROUTER -- Yes --> ROUTER_EXISTS["Log: Router function data exists
Read kkopSvcKeiNo and geneAddDtm
PK select: executeKK_T_KKOP_SVC_KEI_PKSELECT
kkOpSvcKeiAdd() - register contract cancellation
insertPrgKiki(stat=1) - progress registration (9704)"]
    CHECK_ROUTER -- No --> VA_QUERY["Log: Router function data not found
Query VA function: executeKK_T_KKOP_SVC_KEI_KK_SELECT_003(kktkSvcKeiNo, G02, super.opeDate)"]
    ROUTER_EXISTS --> VA_QUERY
    VA_QUERY --> VA_RESULT["dbMapKkOpSvcKei = db_KK_T_KKOP_SVC_KEI.selectNext()"]
    VA_RESULT --> CHECK_VA{VA query returns data?}
    CHECK_VA -- Yes --> VA_EXISTS["Log: VA function data exists
Read kkopSvcKeiNo and geneAddDtm
PK select: executeKK_T_KKOP_SVC_KEI_PKSELECT
kkOpSvcKeiAdd() - register contract cancellation
telnoHmdkUpd() - rewrite phone number
insertPrgKiki(stat=1) - progress registration (9704)"]
    CHECK_VA -- No --> VA_NOT_EXISTS["Log: VA function data not found"]
    VA_EXISTS --> END_NODE(["Return void"])
    VA_NOT_EXISTS --> END_NODE
```

**Key IDs:**

| ID | Value | Business Meaning |
|----|-------|------------------|
| `G01` | `"G01"` | Router function query key — identifies the main equipment option service contract record |
| `G02` | `"G02"` | VA function query key — identifies the value-added equipment-provided service contract record |

**Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|------------------|
| `CD00647_PRG_STAT_9704` | `"9704"` | Progress status: Work cancellation (工事取消) |
| `MK_FLG_YK` | `"0"` | Invalid flag: Valid (無効フラグ: 有効) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `kktkSvcKei_map` | `JBSbatCommonDBInterface` | Equipment-provided service contract input document — a database interface carrying the full record of the equipment-provided service contract (T_KKTK_SVC_KEI table). Used to extract the service contract number (KKTK_SVC_KEI_NO) for querying router/VA function data, and passed through to downstream methods for progress registration and phone number rewriting. |
| 2 | `kojiakFinYmd` | `String` | Work completion date (工事完了日), used as the **work item cancellation date** (工事案件キャンセル年月日). Passed directly to `kkOpSvcKeiAdd()` where it drives the effective end date computation for terminated contracts (status "030" branch). |
| 3 | `svcKeiNo` | `String` | Service contract number (サービス契約番号) — the primary contract identifier used when registering progress cancellation in `insertPrgKiki()`. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `super.opeDate` | `String` | Operation date — used as the effective date for SQL query parameters in router/VA function lookups |
| `super.logPrint` | Log interface | Debug logging utility — used to output debug messages for each functional path result |
| `batchUserId` | `String` | Batch update operator ID — used in the called method `insertPrgKiki()` as the registration/update operator (indirectly read) |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatStringUtil.Rtrim` | JBSbatStringUtil | - | Trims whitespace from database string values read from data maps |
| R | `kktkSvcKei_map.getString(KKTK_SVC_KEI_NO)` | JBSbatKK_T_KKTK_SVC_KEI | KKTK_SVC_KEI_NO | Reads the equipment-provided service contract number from the input data map |
| R | `executeKK_T_KKOP_SVC_KEI_KK_SELECT_003` | KK_SELECT_003 | **T_KKOP_SVC_KEI** | Executes SQL query to find router/VA function contract records by contract number, function key (G01/G02), and operation date |
| R | `db_KK_T_KKOP_SVC_KEI.selectNext()` | KK_SELECT_003 | **T_KKOP_SVC_KEI** | Retrieves the next record from the SQL query result set |
| R | `dbMapKkOpSvcKei.getString(KKOP_SVC_KEI_NO)` | JBSbatKK_T_KKOP_SVC_KEI | KKOP_SVC_KEI_NO | Reads the equipment option service contract number from the query result |
| R | `dbMapKkOpSvcKei.getString(GENE_ADD_DTM)` | JBSbatKK_T_KKOP_SVC_KEI | GENE_ADD_DTM | Reads the generation registration date/time stamp for PK resolution |
| R | `executeKK_T_KKOP_SVC_KEI_PKSELECT` | - | **T_KKOP_SVC_KEI** | Performs primary-key-based select on T_KKOP_SVC_KEI using contract number and generation date |
| C | `kkOpSvcKeiAdd` | - | **T_KKOP_SVC_KEI** | Registers (updates) the equipment option service contract cancellation via status transformation and insert |
| C | `insertPrgKiki` | - | **T_PRG** | Registers progress record with status "9704" (work cancellation) — progress cancellation registration |
| C | `executeKK_T_KKOP_SVC_KEI_KK_SELECT_003` (VA) | KK_SELECT_003 | **T_KKOP_SVC_KEI** | Executes SQL query for VA function contract records (key G02) |
| - | `super.logPrint.printDebugLog` | JACBatDebugLogUtil | - | Outputs debug log messages for each processing path |
| C | `telnoHmdkUpd` | - | **T_SVKEIUW_EOH_TEL**, **T_SVC_KEI_UCWK**, **T_KKTK_SVC_KEI**, **ZM_M_TAKNKIKI_MODEL** | Rewrites phone numbers in service contract detail tables — triggers select/insert on T_SVKEIUW_EOH_TEL, PK select on T_SVC_KEI_UCWK, and insertSvkeiUcwkTelnoHmdkUpd/insertSvkeiuwEohTelHmdkUpd |

**CRUD Summary:**
- **Read (R):** Queries the router/VA function data from `T_KKOP_SVC_KEI` via SQL define `KK_SELECT_003`, reads the contract number and generation timestamp for PK-based lookups, then performs primary-key selects on the same table.
- **Create (C):** Registers contract cancellation data via `kkOpSvcKeiAdd()` into `T_KKOP_SVC_KEI`, registers progress cancellation via `insertPrgKiki()` into `T_PRG`, and rewrites phone numbers via `telnoHmdkUpd()` across `T_SVKEIUW_EOH_TEL`, `T_SVC_KEI_UCWK`, and `T_KKTK_SVC_KEI_VA`.
- **No Update or Delete** operations are performed directly in this method — all data changes are delegated to called methods.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKKjClDataInTrn` (caller not within 8 hops) | `batch_entry` -> `insertKkOpSvcKeiTakinoRouterDslCncl` | `kkOpSvcKeiAdd [C] T_KKOP_SVC_KEI`, `insertPrgKiki [C] T_PRG`, `telnoHmdkUpd [C] T_SVKEIUW_EOH_TEL, T_SVC_KEI_UCWK, T_KKTK_SVC_KEI_VA` |

**Caller Details:**

This method is a **private batch service entry point** with no screen or CBS callers found within 8 hops. It is invoked directly by a higher-level batch process that coordinates the equipment option service contract cancellation workflow. The method operates as a **router/VA dual-path coordinator**, independently processing the main service contract and any value-added equipment provision.

**Terminal operations reached from this method:**
- `kkOpSvcKeiAdd()` -> `executeKK_T_KKOP_SVC_KEI_PKINSERT [C] T_KKOP_SVC_KEI`
- `insertPrgKiki()` -> `executeKK_T_PRG_PKINSERT [C] T_PRG`
- `telnoHmdkUpd()` -> `executeKK_T_SVKEIUW_EOH_TEL_KK_SELECT_045 [R] T_SVKEIUW_EOH_TEL`, `executeKK_T_KKTK_SVC_KEI_KK_SELECT_195 [R] T_KKTK_SVC_KEI_VA`, `executeKK_T_SVC_KEI_UCWK_PKSELECT [R] T_SVC_KEI_UCWK`, `executeKK_T_SVKEIUW_EOH_TEL_PKSELECT [R] T_SVKEIUW_EOH_TEL`, `insertSvkeiUcwkTelnoHmdkUpd [C] T_SVC_KEI_UCWK`, `insertSvkeiuwEohTelHmdkUpd [C] T_SVKEIUW_EOH_TEL`

## 6. Per-Branch Detail Blocks

**Block 1** — [VARIABLE INITIALIZATION] (L9830–L9839)

> Initializes local variables to null/empty values for use in subsequent query processing.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dbMapKkOpSvcKei = null` // Query result (null initialized) |
| 2 | SET | `dbMapKkOpSvcKeiPk = null` // Equipment option service contract PK query result (null initialized) |
| 3 | SET | `kkopSvcKeiNo = ""` // Equipment option service contract number (empty initialized) |
| 4 | SET | `geneAddDtm = ""` // Generation registration date/time stamp (empty initialized) |
| 5 | SET | `kktkSvcKeiNo = Rtrim(kktkSvcKei_map.getString(KKTK_SVC_KEI_NO))` // Equipment-provided service contract number |

**Block 2** — [ROUTER FUNCTION QUERY] (L9843–L9847)

> Queries the router function (G01) to find existing equipment option service contract records.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KKOP_SVC_KEI_KK_SELECT_003(new Object[]{kktkSvcKeiNo, G01, super.opeDate})` // Router function query: query key G01 with contract number and operation date |
| 2 | SET | `dbMapKkOpSvcKei = db_KK_T_KKOP_SVC_KEI.selectNext()` // Retrieve next result row |

**Block 3** — [IF Router Function Data Found] (L9850)

> When router function query returns a record: log existence, resolve the contract number and generation date via PK select, register contract cancellation, and register progress cancellation.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("★★★[Equipment Option Service Contract] Router function data exists")` // Debug log |
| 2 | SET | `kkopSvcKeiNo = Rtrim(dbMapKkOpSvcKei.getString(KKOP_SVC_KEI_NO))` // Read equipment option service contract number |
| 3 | SET | `geneAddDtm = Rtrim(dbMapKkOpSvcKei.getString(GENE_ADD_DTM))` // Read generation registration date/time stamp |
| 4 | SET | `dbMapKkOpSvcKeiPk = executeKK_T_KKOP_SVC_KEI_PKSELECT(new Object[]{kkopSvcKeiNo, geneAddDtm})` // Primary-key select on T_KKOP_SVC_KEI |
| 5 | CALL | `kkOpSvcKeiAdd(dbMapKkOpSvcKeiPk, kojiakFinYmd)` // Register equipment option service contract cancellation |
| 6 | CALL | `insertPrgKiki(kktkSvcKei_map, "1", svcKeiNo)` // Register progress cancellation (stat="1" -> 9704) |

**Block 4** — [ELSE Router Function Not Found] (L9866)

> When router function query returns no record: log non-existence and proceed to VA function query.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("★★★[Equipment Option Service Contract] Router function data not found")` // Debug log |

**Block 5** — [VA FUNCTION QUERY] (L9872–L9876)

> Queries the VA function (G02) to find existing equipment-provided service contract records, independent of the router query result.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KKOP_SVC_KEI_KK_SELECT_003(new Object[]{kktkSvcKeiNo, G02, super.opeDate})` // VA function query: query key G02 with contract number and operation date |
| 2 | SET | `dbMapKkOpSvcKei = db_KK_T_KKOP_SVC_KEI.selectNext()` // Retrieve next result row |

**Block 6** — [IF VA Function Data Found] (L9879)

> When VA function query returns a record: log existence, resolve the contract number and generation date via PK select, register contract cancellation, rewrite phone numbers, and register progress cancellation.
> Note: The v8.00.00 correction removed the inner `kikiRntaiKeiChgechuFlg` check — all VA data now triggers the cancellation path unconditionally.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("★★★[Equipment Option Service Contract] VA function data exists")` // Debug log |
| 2 | SET | `kkopSvcKeiNo = Rtrim(dbMapKkOpSvcKei.getString(KKOP_SVC_KEI_NO))` // Read equipment option service contract number |
| 3 | SET | `geneAddDtm = Rtrim(dbMapKkOpSvcKei.getString(GENE_ADD_DTM))` // Read generation registration date/time stamp |
| 4 | SET | `dbMapKkOpSvcKeiPk = executeKK_T_KKOP_SVC_KEI_PKSELECT(new Object[]{kkopSvcKeiNo, geneAddDtm})` // Primary-key select on T_KKOP_SVC_KEI |
| 5 | CALL | `kkOpSvcKeiAdd(dbMapKkOpSvcKeiPk, kojiakFinYmd)` // Register equipment option service contract cancellation |
| 6 | CALL | `telnoHmdkUpd(kktkSvcKei_map)` // Rewrite phone number in service contract detail tables |
| 7 | CALL | `insertPrgKiki(kktkSvcKei_map, "1", svcKeiNo)` // Register progress cancellation (stat="1" -> 9704) |

**Block 7** — [ELSE VA Function Not Found] (L9916)

> When VA function query returns no record: log non-existence. Processing completes.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("★★★[Equipment Option Service Contract] VA function data not found")` // Debug log |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kktkSvcKeiNo` | Field | Equipment-provided service contract number — identifier for the service contract provided by the equipment vendor |
| `kkopSvcKeiNo` | Field | Equipment option service contract number — unique identifier for the equipment option service contract |
| `geneAddDtm` | Field | Generation registration date/time stamp — timestamp used as part of the primary key for versioned contract records |
| `svcKeiNo` | Parameter | Service contract number — primary contract identifier passed to progress registration |
| `kojiakFinYmd` | Parameter | Work completion date — date when the installation work was completed, used as work item cancellation date |
| `dbMapKkOpSvcKei` | Field | Query result data map — holds the result of the router/VA function query against T_KKOP_SVC_KEI |
| `dbMapKkOpSvcKeiPk` | Field | PK query result data map — holds the result of the primary-key select on T_KKOP_SVC_KEI |
| `kktkSvcKei_map` | Parameter | Equipment-provided service contract input document — the full data map carrying the equipment-provided service contract record |
| `batchUserId` | Field | Batch update operator ID — system user ID of the batch process operator |
| G01 | ID | Router function query key — identifies the main equipment option service contract record in T_KKOP_SVC_KEI |
| G02 | ID | VA function query key — identifies the value-added equipment-provided service contract record |
| T_KKOP_SVC_KEI | Table | Equipment Option Service Contract table — main table for equipment option service contract records |
| T_KKTK_SVC_KEI | Table | Equipment-Provided Service Contract table — table for equipment-provided service contract records |
| T_KKTK_SVC_KEI_VA | Table | Equipment-Provided Service Contract VA view — view/table for VA function equipment-provided service contract records |
| T_PRG | Table | Progress table — tracks processing progress/cancellation status |
| T_SVKEIUW_EOH_TEL | Table | Service Contract Detail <EO光电 Phone> table — stores service contract detail records with telephone numbers for EO (Fujitsu) optical phone services |
| T_SVC_KEI_UCWK | Table | Service Contract Detail table — internal detail records for service contracts |
| ZM_M_TAKNKIKI_MODEL | Table | Home Equipment Model master table — master data for home equipment (router/modem) model information including port count |
| KK_SELECT_003 | SQL Key | SQL define key for querying T_KKOP_SVC_KEI by contract number, function key, and operation date |
| KK_SELECT_045 | SQL Key | SQL define key for querying T_SVKEIUW_EOH_TEL by operation date and service contract internal detail number |
| KK_SELECT_195 | SQL Key | SQL define key for querying T_KKTK_SVC_KEI by service contract number and operation date |
| CD00647_PRG_STAT_9704 | Constant | "9704" — Progress status: Work cancellation (工事取消) |
| MK_FLG_YK | Constant | "0" — Invalid flag: Valid (無効フラグ: 有効) |
| Rtrim | Method | Right-trim — removes trailing whitespace from strings |
| Router function (ルータ機能) | Term | Main equipment option service contract processing path — handles the primary contract lifecycle |
| VA function (VA機能) | Term | Value-Added function — handles equipment-provided service contract modifications such as phone number rewrites |
| 工事取消 (Kouji torikeshi) | Term | Work cancellation — cancellation of a work order/installation case |
| 電話番号再付替 (Tengou bangou saitsugae) | Term | Phone number rewrite — reassignment of telephone number in service contract detail records |
| 進化登録 (Shinka touroku) | Term | Progress registration — registration of processing progress/cancellation status |
| VOIP | Acronym | Voice over IP — IP-based telephony service |
| EO | Business term | EO (Fujitsu) — Fujitsu's optical telecommunications service brand |
| 工事完了日 (Kouji kanryo bi) | Term | Work completion date — date when installation/construction work was completed |
