# Business Logic — JBSBatKKKkOpDlRvAdd.insertKktkSvcKei() [413 LOC]

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

## 1. Role

### JBSBatKKKkOpDlRvAdd.insertKktkSvcKei()

The `insertKktkSvcKei` method is responsible for inserting a complete **equipment provider service contract** (機器提供サービス契約, *kiki teikyo saabisu keiyaku*) record into the `KK_T_KKTK_SVC_KEI` database table. This method is the core data-packing routine invoked during equipment operation service cancellation confirmation processing. It retrieves the existing (current) service contract record using the contract number (`kktk_svc_kei_no`) and generation registration datetime (`gene_add_dtm`) as composite key, then maps all 171 fields from that source record into a parameter array for insertion as a new contract record — effectively creating a contractual update or migration record.

The method implements a **bulk field-copy pattern**: it systematically reads every column from the source `KK_T_KKTK_SVC_KEI` record and places it at a specific position in a 171-element `String[]` array. Alongside the raw copy, the method injects several hardcoded or computed override values — including a fixed service contract status code (`CD00056_STAT_DSLZUMI = "910"` meaning "pre-DSL completion"), a reservation application code (`RSV_APLY_CD_RSV_FIX = "2"` meaning "reservation fixed"), and a service withdrawal reason code (`CD00879_SVC_DLRE_CD_01 = "01"`).

For date-sensitive fields (plan end date, service charge end date, etc.), the method applies conditional logic: if a custom rule date (from `getChgStDate`) is present, it overrides the plan/service charge start dates; otherwise it pulls the values directly from the database. Several date fields (plan end date, service charge end date, service termination date) are set to `idoRsvAplyYmd - 1` (one day before the reservation application date), reflecting the v25.00.00 fix for billing end date accuracy. The method delegates the actual database insert to `executeKK_T_KKTK_SVC_KEI_PKINSERT(setParam)`, which performs a primary-key-based insert into the `KK_T_KKTK_SVC_KEI` table.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertKktkSvcKei start"])
    WHERE["Create whereMap"]
    WHERE_SET["Set KKTK_SVC_KEI_NO and GENE_ADD_DTM in whereMap"]
    SELECT["db_KK_T_KKTK_SVC_KEI.selectByPrimaryKeys(whereMap)"]
    RULE["getChgStDate(kktkSvKeiKeyMap)"]
    PARAM["Create setParam[171] array"]
    COPY["Copy 171 fields from kktkSvKeiKeyMap to setParam"]
    CHECK_SPACE["SPACE.equals(ruleDate)"]
    CHECK_TRUE["ruleDate is empty (SPACE)"]
    CHECK_FALSE["ruleDate has value"]
    FILL_104_111_R{"Use DB values from kktkSvKeiKeyMap"}
    FILL_104_111_E["Set setParam[104] and setParam[111] = ruleDate"]
    INSERT["executeKK_T_KKTK_SVC_KEI_PKInsert(setParam)"]
    INSERT_TABLE["C: KK_T_KKTK_SVC_KEI - Insert contract record"]
    END_NODE(["Return / Next"])

    START --> WHERE --> WHERE_SET --> SELECT --> RULE --> PARAM --> COPY --> CHECK_SPACE
    CHECK_SPACE --> |true| CHECK_TRUE --> FILL_104_111_R
    CHECK_SPACE --> |false| CHECK_FALSE --> FILL_104_111_E
    FILL_104_111_R --> INSERT
    FILL_104_111_E --> INSERT
    INSERT --> INSERT_TABLE --> END_NODE
```

**Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|-----------------|
| `JKKStrConst.CD00056_STAT_DSLZUMI` | `"910"` | Service contract status: pre-DSL completion (pre-DSL ready) |
| `JKKBatConst.RSV_APLY_CD_RSV_FIX` | `"2"` | Reservation application code: reservation fixed (confirmed) |
| `JBSbatKKConst.CD00879_SVC_DLRE_CD_01` | `"01"` | Service withdrawal reason code: reason 01 (standard withdrawal) |
| `JBSbatKKConst.CD01359_FIN_FLG_1` | `"1"` | Service withdrawal procedure completion flag: completed |
| `JKKBatConst.SPACE` | `""` | Empty string — represents null/blank date value |
| `JBCBatConst.SVC_CD_NET` | `"01"` | Internet service code (referenced in related rule processing) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `kktk_svc_kei_no` | `String` | Equipment provider service contract number — unique identifier for the service contract line item to be retrieved and re-inserted. Used as the primary key to fetch the existing contract record from `KK_T_KKTK_SVC_KEI`. |
| 2 | `gene_add_dtm` | `String` | Generation registration datetime — the creation timestamp of the current contract generation. Used alongside `kktk_svc_kei_no` as a composite primary key to identify the exact contract record in a versioned table structure. |
| 3 | `ido_Kbn` | `String` | Migration division/type code — distinguishes the type of contract change operation (e.g., equipment migration, service cancellation). Stored in `setParam[139]` as the "migration division" field. |
| 4 | `sysDate` | `String` | System date — used as the "generation registration year/month/day/time" (`setParam[1]`). Represents the current system timestamp for the new contract record's generation timestamp. |
| 5 | `idoRsvAplyYmd` | `String` | Migration reservation application date — the date on which the migration reservation is applied. Introduced in v25.00.00 (OM-2016-0001850) to fix billing end date inaccuracy. Used for plan end date, service charge end date, service termination date, and their derived date calculations (e.g., `idoRsvAplyYmd - 1`). |

**Instance fields read by this method:**

| Field | Type | Usage |
|-------|------|-------|
| `this.opeDate` | `String` | Operation date — used for `setParam[98]` (reservation application date) |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `db_KK_T_KKTK_SVC_KEI.selectByPrimaryKeys` | (internal DAO) | `KK_T_KKTK_SVC_KEI` | Selects the existing equipment provider service contract record by composite primary key (`KKTK_SVC_KEI_NO`, `GENE_ADD_DTM`) |
| R | `JBSbatCommonDBInterface.getString` (×171 times) | — | In-memory map | Reads each field value from the retrieved contract record into `setParam` array positions 0–170 |
| R | `JBSbatDateUtil.adjustDate` | — | — | Computes `idoRsvAplyYmd - 1` for plan end date, service charge end date (2 calls) |
| R | `JBSbatDateUtil.adjustDate` | — | — | Computes `idoRsvAplyYmd - 1` for service termination date (1 call) |
| R | `getChgStDate(kktkSvKeiKeyMap)` | Internal method | `KK_T_KKTK_SVC_KEI.SVC_STA_YMD` | Checks if the service start date's year/month matches the operation date; if so, returns the service start date as the rule date, otherwise returns empty string |
| C | `executeKK_T_KKTK_SVC_KEI_PKINSERT` | — | `KK_T_KKTK_SVC_KEI` | Inserts the fully populated 171-field parameter array as a new record into `KK_T_KKTK_SVC_KEI` using primary key insert |

### Additional called methods (not in pre-computed table):

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatCommonDBInterface.setString` / `setValue` | — | `JBSbatCommonDBInterface` (whereMap) | Sets primary key values on the where clause map for the SELECT query |
| - | `JBSbatDateUtil.adjustDate` | — | — | Date arithmetic to compute dates 1 day prior to `idoRsvAplyYmd` |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch:JBSBatKKKkOpDlRvAdd | `execute()` -> `insertKktkSvcKei(...)` | `db_KK_T_KKTK_SVC_KEI.selectByPrimaryKeys [R] KK_T_KKTK_SVC_KEI`, `executeKK_T_KKTK_SVC_KEI_PKInsert [C] KK_T_KKTK_SVC_KEI`, `getString [R] in-memory (171 fields)`, `adjustDate [-] (3 calls)` |
| 2 | Batch:JBSBatKKKkOpDlRvAdd | `execute()` -> `getChgStDate(kktkSvKeiKeyMap)` (called within insertKktkSvcKei) | `kktkSvKeiKeyMap.getString [R] SVC_STA_YMD` |

**Terminal operations from this method:**

| Terminal Operation | Type | Description |
|-------------------|------|-------------|
| `db_KK_T_KKTK_SVC_KEI.selectByPrimaryKeys` | R | Reads the existing contract record from `KK_T_KKTK_SVC_KEI` |
| `getString` (×171) | R | Reads all field values from the retrieved record |
| `adjustDate` (×3) | - | Date arithmetic for plan/service charge end dates and service termination date |
| `getChgStDate` | R | Internal rule date determination method |
| `executeKK_T_KKTK_SVC_KEI_PKInsert` | C | Inserts new contract record into `KK_T_KKTK_SVC_KEI` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Build WHERE clause for SELECT (L3006–3010)

> Creates the WHERE map with primary key values to query the existing contract record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereMap = new JBSbatCommonDBInterface()` |
| 2 | SET | `whereMap.setValue(KKTK_SVC_KEI_NO, kktk_svc_kei_no)` // Set contract number in WHERE |
| 3 | SET | `whereMap.setValue(GENE_ADD_DTM, gene_add_dtm)` // Set generation registration datetime in WHERE |
| 4 | CALL | `kktkSvKeiKeyMap = db_KK_T_KKTK_SVC_KEI.selectByPrimaryKeys(whereMap)` // R: Retrieve existing contract record from KK_T_KKTK_SVC_KEI |

**Block 2** — [SET] Invoke custom rule date determination (L3013)

> Calls `getChgStDate` which checks if the service start date's year/month matches the operation date. Returns the service start date if they match, or empty string (`SPACE`) otherwise.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ruleDate = getChgStDate(kktkSvKeiKeyMap)` // Get rule date for billing adjustments |

**Block 3** — [SET] Allocate parameter array (L3017–3021)

> Creates the 171-element parameter array. Version comments show growth from 168 to 170 to 171 fields across v9.00.00 and v10.00.00 releases.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam = new String[171]` // v10.00.00: 171 fields (expanded from 170, 168) |

**Block 4** — [SET] Copy fields 0–170 from retrieved record to setParam (L3024–3396)

> Systematically reads all fields from the source contract record. The block consists of 171 SET operations. Key override values are injected inline. Below are the notable groupings:

**Block 4.1** — Contract identification fields (L3024–3030)

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[0] = kktkSvKeiKeyMap.getString(KKTK_SVC_KEI_NO)` // Equipment provider service contract number |
| 2 | SET | `setParam[1] = sysDate` // Generation registration datetime |
| 3 | SET | `setParam[2] = JKKStrConst.CD00056_STAT_DSLZUMI` // // Service contract status: "910" (pre-DSL completion) |
| 4 | SET | `setParam[3] = kktkSvKeiKeyMap.getString(KKTK_SVC_CD)` // Equipment provider service code |
| 5 | SET | `setParam[4] = kktkSvKeiKeyMap.getString(PCRS_CD)` // Price code |
| 6 | SET | `setParam[5] = kktkSvKeiKeyMap.getString(PPLAN_CD)` // Price plan code |
| 7 | SET | `setParam[6] = kktkSvKeiKeyMap.getString(TK_HOSHIKI_KEI_NO)` // Provider method contract number |
| 8 | SET | `setParam[7] = kktkSvKeiKeyMap.getString(KKTK_SBT_CD)` // Equipment provider type code |
| 9 | SET | `setParam[8] = kktkSvKeiKeyMap.getString(HAMBAI_SBT_CD)` // Sales type code |

**Block 4.2** — Scheduling and equipment fields (L3031–3066)

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[9] = ...getString(SVC_USE_STA_KIBO_YMD)` // Service use start desired date |
| 2 | SET | `setParam[10] = ...getString(RSV_TSTA_KIBO_YMD)` // Reservation application start desired date |
| 3 | SET | `setParam[11] = ...getString(KIBO_MAKER_CD)` // Desired maker code |
| 4 | SET | `setParam[12] = ...getString(KIKI_SHITEI_SBT_CD)` // Equipment designated type code |
| 5 | SET | `setParam[13] = ...getString(TAKNKIKI_SBT_CD)` // Home equipment type code |
| 6 | SET | `setParam[14] = ...getString(TAKNKIKI_MODEL_CD)` // Home equipment model code |
| 7 | SET | `setParam[15] = ...getString(KIKI_SEIZO_NO)` // Equipment serial number |
| 8 | SET | `setParam[16] = ...getString(HUZOKUHIN_SBT_CD)` // Accessory type code |
| 9 | SET | `setParam[17] = ...getString(HUZOKUHIN_MODEL_CD)` // Accessory model code |
| 10 | SET | `setParam[18] = ...getString(TAKNKIKI_SETHIN_MODEL_CD)` // Home equipment set product model code |
| 11 | SET | `setParam[19] = ...getString(KIKI_CHG_NO)` // Equipment change number |
| 12 | SET | `setParam[20] = ...getString(KIKI_CHG_RSN_CD)` // Equipment change reason code |
| 13 | SET | `setParam[21] = ...getString(TSUSHIN_KIKI_SET_CD)` // Communication equipment set code |
| 14 | SET | `setParam[22] = ...getString(HDD_CAPA_CD)` // HDD capacity code |
| 15 | SET | `setParam[23] = ...getString(KIKI_STC_SAKI_PLACE_NO)` // Equipment installation site location number |

**Block 4.3** — Address and delivery fields (L3067–3137)

> Sets sender (配送先) address fields (indices 42–60), and installation site (設置先) address fields (indices 61–73).

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[42] = ...getString(KIKI_SOHUS_NM)` // Equipment sender name |
| 2 | SET | `setParam[44] = ...getString(KIKI_SOHUS_AD_CD)` // Equipment sender address code |
| 3 | SET | `setParam[45] = ...getString(KIKI_SOHUS_PCD)` // Equipment sender postal code |
| 4 | SET | `setParam[46] = ...getString(KIKI_SOHUS_STATE_NM)` // Equipment sender prefecture name |
| 5 | SET | `setParam[47] = ...getString(KIKI_SOHUS_CITY_NM)` // Equipment sender city name |
| 6 | SET | `setParam[61] = ...getString(KIKI_STC_SAKI_NM)` // Equipment installation site name |
| 7 | SET | `setParam[63] = ...getString(KIKI_STC_SAKI_AD_CD)` // Equipment installation site address code |
| 8 | SET | `setParam[64] = ...getString(KIKI_STC_SAKI_PCD)` // Equipment installation site postal code |

**Block 4.4** — Date-sensitive fields with version-affected overrides (L3227–3310)

> This section contains the most critical business logic. Several date fields are set from `this.opeDate` or `idoRsvAplyYmd`, reflecting the v25.00.00 fix (OM-2016-0001850).

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[98] = this.opeDate` // Reservation application date |
| 2 | SET | `setParam[100] = JKKBatConst.RSV_APLY_CD_RSV_FIX` // // Reservation application code: "2" (reservation fixed) |
| 3 | SET | `setParam[103] = idoRsvAplyYmd` // v25.00.00: Plan end date from migration reservation application date (was this.opeDate) |
| 4 | SET | `setParam[105] = JBSbatDateUtil.adjustDate(idoRsvAplyYmd, -1)` // v25.00.00: Plan charge end date = idoRsvAplyYmd - 1 |
| 5 | SET | `setParam[124] = idoRsvAplyYmd` // v25.00.00: Service end date from migration reservation application date |
| 6 | SET | `setParam[125] = JBSbatDateUtil.adjustDate(idoRsvAplyYmd, -1)` // v25.00.00: Service charge end date = idoRsvAplyYmd - 1 |
| 7 | SET | `setParam[126] = idoRsvAplyYmd` // v25.00.00: Service withdrawal date from migration reservation application date |
| 8 | SET | `setParam[127] = JBSbatKKConst.CD00879_SVC_DLRE_CD_01` // // v22.00.00: Service withdrawal reason code: "01" |
| 9 | SET | `setParam[130] = JBSbatKKConst.CD01359_FIN_FLG_1` // // v22.00.00: Service withdrawal procedure completion flag: "1" |
| 10 | SET | `setParam[131] = JKKBatConst.SPACE` // // v7.00.04: Recovery date set to empty string (cleared from DB) |
| 11 | SET | `setParam[139] = ido_Kbn` // Migration division/type code |

**Block 4.5** — Remaining auto-tracking fields (L3355–3396)

> Sets deletion tracking fields (DEL_DTM, DEL_OPEACNT, DEL_UNYO_YMD, DEL_TRN_ID), invalid flag (MK_FLG), and version-added fields (indices 168–170 for warranty/compensation period start date calculation).

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam[159] = ...getString(DEL_DTM)` // Deletion datetime |
| 2 | SET | `setParam[160] = ...getString(DEL_OPEACNT)` // Deletion operator account |
| 3 | SET | `setParam[161] = ...getString(MK_FLG)` // Invalid flag |
| 4 | SET | `setParam[166] = ...getString(DEL_UNYO_YMD)` // Deletion operation date |
| 5 | SET | `setParam[167] = ...getString(DEL_TRN_ID)` // Deletion transaction ID |
| 6 | SET | `setParam[168] = ...getString(HCPRD_STAD_SNSTSTD_YMD)` // v9.00.00: Warranty/compensation period start date calculation standard date |
| 7 | SET | `setParam[169] = ...getString(HCPRD_STAD_SNSTSTD_YMD_IKF)` // v9.00.00: Warranty/compensation period start date calculation standard date carry flag |
| 8 | SET | `setParam[170] = ...getString(HCPRD_STAD_SNSTSTD_YMD_SCD)` // v10.00.00: Warranty/compensation period start date calculation standard date identification code |

**Block 5** — [IF/ELSE] Rule date conditional for plan/service charge start dates (L3399–3410)

> If `ruleDate` is empty (`SPACE`), the plan and service charge start dates come directly from the database. Otherwise, `ruleDate` (computed from service start date) is used as both plan and service charge start dates. This is the v7.00.05 correction.

| # | Type | Code |
|---|------|------|
| 1 | IF | `JKKBatConst.SPACE.equals(ruleDate)` // [CONSTANT: SPACE=""] Check if ruleDate is empty |
| 1.1 | SET (true branch) | `setParam[104] = ...getString(PLAN_CHRG_STAYMD)` // Plan charge start date from DB |
| 1.2 | SET (true branch) | `setParam[111] = ...getString(SVC_CHRG_STAYMD)` // Service charge start date from DB |
| 1.3 | SET (else branch) | `setParam[104] = ruleDate` // Plan charge start date from rule engine |
| 1.4 | SET (else branch) | `setParam[111] = ruleDate` // Service charge start date from rule engine |

**Block 6** — [EXEC] Insert the complete record (L3412)

> Delegates the actual database insertion to `executeKK_T_KKTK_SVC_KEI_PKInsert`, which performs a primary key insert into `KK_T_KKTK_SVC_KEI`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KKTK_SVC_KEI_PKInsert(setParam)` // C: Insert 171-field contract record into KK_T_KKTK_SVC_KEI |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kktk_svc_kei_no` | Field | Equipment provider service contract number — unique identifier for a service contract in the KK_T_KKTK_SVC_KEI table |
| `gene_add_dtm` | Field | Generation registration datetime — the creation timestamp used as part of the composite primary key for versioned contract records |
| `ido_Kbn` | Field | Migration division/type code — classifies the type of contract change (e.g., equipment migration vs. service cancellation) |
| `idoRsvAplyYmd` | Field | Migration reservation application date — the date on which the migration reservation is submitted; used for computing plan/service end dates and termination dates |
| `opeDate` | Field | Operation date — the system's current operation date, used for reservation application date (setParam[98]) |
| `ruleDate` | Field | Rule date — a computed date from the service start date, used for plan/service charge start date overrides |
| `setParam` | Field | Parameter array — 171-element String array holding all field values for the contract insert |
| KK_T_KKTK_SVC_KEI | Table | Equipment provider service contract table — the core table storing equipment provider service contract records |
| `CD00056_STAT_DSLZUMI` | Constant | Service contract status code "910" — pre-DSL completion (preparation stage before DSL activation) |
| `CD00879_SVC_DLRE_CD_01` | Constant | Service withdrawal reason code "01" — standard contract withdrawal reason |
| `CD01359_FIN_FLG_1` | Constant | Service withdrawal procedure completion flag "1" — withdrawal procedure has been completed |
| `RSV_APLY_CD_RSV_FIX` | Constant | Reservation application code "2" — reservation is fixed/confirmed |
| `SPACE` | Constant | Empty string "" — used as a sentinel value representing null/blank |
| `getChgStDate` | Method | Determines the rule date by comparing service start date's year/month with operation date |
| `executeKK_T_KKTK_SVC_KEI_PKInsert` | Method | Inserts a fully populated 171-field parameter array into KK_T_KKTK_SVC_KEI using primary key insert |
| v25.00.00 | Version | Release that fixed billing end date inaccuracy by using idoRsvAplyYmd instead of opeDate for plan end, plan charge end, service end, service charge end, and service withdrawal dates |
| v22.00.00 | Version | Release that consolidated local constant definitions to centralized JBSbatKKConst constants |
| v10.00.00 | Version | Release that added the warranty/compensation period start date calculation standard date identification code (field 170) |
| v9.00.00 | Version | Release that added warranty/compensation period start date calculation standard date and carry flag (fields 168–169) |
| v7.00.05 | Version | Release that added the rule-date conditional for plan/service charge start dates |
| v7.00.04 | Version | Release that cleared the recovery date field (setParam[131]) |
| 機器提供サービス | Business term | Equipment provider service — telecom service where the provider supplies hardware (set-top boxes, routers, etc.) alongside connectivity |
| 解約 | Business term | Cancellation/withdrawal — the process of terminating a service contract, triggering the creation of a new contract record with end dates |
| ルーラー (Rule engine) | Business term | Automated billing date computation engine (RULE0066) that determines service charge start dates |
| 異動 (Ido) | Business term | Migration/transfer — the operation of changing service parameters (equipment, addresses, plans) while maintaining the contract |
| SOD | Acronym | Service Order Data — telecom order fulfillment entity used for service change processing |
| DSL | Acronym | Digital Subscriber Line — a type of broadband connection technology |
| FTTH | Acronym | Fiber To The Home — fiber-optic broadband service (referenced in broader system context) |
