# Business Logic — JBSbatKKDelRun.updateDelTrnJssiDtmOpsvkei() [70 LOC]

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

## 1. Role

### JBSbatKKDelRun.updateDelTrnJssiDtmOpsvkei()

This method performs the core business operation of **updating the deletion execution timestamp on an option service contract record** within the batch deletion (KK = 消去/elimination) processing flow. It is invoked by `updateDelTrnJssiDtm()` (the parent deletion transaction handler) to actually persist the deletion timestamp to the `KK_T_OP_SVC_KEI_KK` (Option Service Contract) table.

The method implements a **version-controlled update pattern** (often called a pessimistic concurrency control or check-and-set mechanism): it first reads the current `GENE_ADD_DTM` (generation registration datetime) from the database, compares it against the timestamp provided by the caller, and then executes the update regardless of whether the values match — but with different `whereMap` criteria depending on the comparison. When the database value matches the input, the original `whereMap` (with the input's timestamp) is used; when it has diverged, the updated `whereMap` is adjusted to match the current database timestamp before the update. This ensures the deletion proceeds even if the record was concurrently modified during the batch run.

The method's role in the larger system is as a **data hygiene operation** within the batch cleanup process. During periodic elimination runs, option service contracts must have their deletion execution datetime (`SVCTK_BUT_DEL_TRN_JSSI_DTM`) set to the current batch execution date, marking them as processed for downstream reconciliation and archival.

> Javadoc translation: "Option service contract deletion execution datetime update processing" (消去実施年月日時分秒の更新処理(オプションサービス契約)).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateDelTrnJssiDtmOpsvkei(inMap)"])
    
    START --> STEP1["Create setMap with SVCTK_BUT_DEL_TRN_JSSI_DTM = sysDate"]
    STEP1 --> STEP2["Create whereMap with OP_SVC_KEI_NO and GENE_ADD_DTM"]
    STEP2 --> STEP3["Prepare param array with OPSVKEI_NO and opeDate"]
    STEP3 --> STEP4["executeKK_T_OP_SVC_KEI_KK_SELECT_094(param)"]
    STEP4 --> STEP5["db_KK_T_OP_SVC_KEI.selectNext() -> getOpsvckeiMap"]
    STEP5 --> STEP6["sedai = getOpsvckeiMap.getString(GENE_ADD_DTM)"]
    STEP6 --> COND{sedai equals GENE_ADD_DTM from input?}
    COND -->|True| BLOCK_TRUE["Match branch: use original whereMap"]
    COND -->|False| BLOCK_FALSE["Mismatch branch: update whereMap.GENE_ADD_DTM with sedai"]
    BLOCK_TRUE --> UPDATE["db_KK_T_OP_SVC_KEI.updateByPrimaryKeys(whereMap, setMap)"]
    BLOCK_FALSE --> UPDATE
    UPDATE --> END_NODE(["Return / Next"])
```

**Business flow summary:**

1. **Prepare update payload** — Create a `setMap` containing the single update column: `SVCTK_BUT_DEL_TRN_JSSI_DTM` is set to `this.sysDate` (the batch run date), which represents the deletion execution datetime to be written.

2. **Prepare selection criteria** — Create a `whereMap` with the option service contract number (`OP_SVC_KEI_NO`) and the input-provided generation registration datetime (`GENE_ADD_DTM`) to form the primary key for the update.

3. **Check current DB state** — Execute the select query (`executeKK_T_OP_SVC_KEI_KK_SELECT_094`) with the contract number and batch operation date to retrieve the current record. Fetch the actual `GENE_ADD_DTM` from the database.

4. **Version compare and update** — Compare the fetched `sedai` against the input's `GENE_ADD_DTM`. If they match, the record has not changed — proceed with the original `whereMap`. If they differ, the record was modified externally — update `whereMap` to use the current database `GENE_ADD_DTM` before updating. In both cases, call `updateByPrimaryKeys` to write the deletion timestamp.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Input message map carrying the option service contract number (`OPSVKEI_NO`) and the generation registration datetime (`OPSVKEI_GADTM`). These values identify the specific contract record to be updated and represent the expected state of the record as known to the calling process. |

**Instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `this.sysDate` | `String` (inferred) | The batch run date, used as the value for the deletion execution timestamp (`SVCTK_BUT_DEL_TRN_JSSI_DTM`). Represents the current batch processing date. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKDelRun.executeKK_T_OP_SVC_KEI_KK_SELECT_094` | - | `KK_T_OP_SVC_KEI_KK` | Calls `executeKK_T_OP_SVC_KEI_KK_SELECT_094` — selects the current option service contract record for concurrency check |
| R | `JBSbatCommonDBInterface.getString` | - | - | Calls `getString` on `db_KK_T_OP_SVC_KEI` result to extract `GENE_ADD_DTM` |
| U | `db_KK_T_OP_SVC_KEI.updateByPrimaryKeys` | - | `KK_T_OP_SVC_KEI_KK` | Updates the option service contract record with the deletion timestamp |
| R | `JBSbatServiceInterfaceMap.getString` | - | - | Reads `OPSVKEI_NO` and `OPSVKEI_GADTM` from input map |

**Detailed analysis:**

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_OP_SVC_KEI_KK_SELECT_094` | `EKK0094SC` (inferred) | `KK_T_OP_SVC_KEI_KK` | Selects the current option service contract record by contract number and batch operation date to verify the generation registration timestamp |
| R | `db_KK_T_OP_SVC_KEI.selectNext` | `EKK0094SC` (inferred) | `KK_T_OP_SVC_KEI_KK` | Fetches the next row from the select result to read the actual `GENE_ADD_DTM` value |
| U | `db_KK_T_OP_SVC_KEI.updateByPrimaryKeys` | `EKK0094SC` (inferred) | `KK_T_OP_SVC_KEI_KK` | Updates the option service contract record's deletion execution timestamp using the primary key criteria |
| R | `JBSbatServiceInterfaceMap.getString` | - | - | Extracts the option service contract number and generation registration datetime from the input message map |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Method: `JBSbatKKDelRun.updateDelTrnJssiDtm` | `JBSbatKKDelRun.updateDelTrnJssiDtm` -> `JBSbatKKDelRun.updateDelTrnJssiDtmOpsvkei` | `db_KK_T_OP_SVC_KEI.updateByPrimaryKeys [U] KK_T_OP_SVC_KEI_KK` |

**Analysis:** The only known caller is `JBSbatKKDelRun.updateDelTrnJssiDtm()`, which is a private method within the same class. This method is part of the batch elimination (KK = 消去) processing pipeline, triggered by a batch scheduler rather than a user-facing screen. The `KK` prefix in the class name suggests this is a "Keshi" (消去/elimination) batch process. No screen entry points (KKSV*) were found, confirming this is a pure batch-side method invoked by the batch framework.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Create update setMap (L1244)

> Initializes the setMap with the deletion execution timestamp value. This map defines which columns will be updated and to what values.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `setMap = new JBSbatCommonDBInterface()` | Create a new common DB interface for holding update values |
| 2 | SET | `setMap.setValue("SVCTK_BUT_DEL_TRN_JSSI_DTM", this.sysDate)` | Set the deletion execution datetime to the current batch run date. `SVCTK_BUT_DEL_TRN_JSSI_DTM` = Service Contract Butai Elimination Registration Datetime |

**Block 2** — [SET] Create where criteria map (L1247)

> Initializes the whereMap with the primary key criteria for identifying the record to update.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `whereMap = new JBSbatCommonDBInterface()` | Create a new common DB interface for holding update criteria |
| 2 | SET | `whereMap.setValue("OP_SVC_KEI_NO", inMap.getString(JBSbatKKIFM161.OPSVKEI_NO))` | Set option service contract number as primary key from input. `OP_SVC_KEI_NO` = Option Service Contract Number |
| 3 | SET | `whereMap.setValue("GENE_ADD_DTM", inMap.getString(JBSbatKKIFM161.OPSVKEI_GADTM))` | Set generation registration datetime as primary key from input. `GENE_ADD_DTM` = Generation Addition Datetime (used for versioning) |

**Block 3** — [SET] Prepare param array for select query (L1250–L1256)

> Prepares parameters for the concurrency check select. The param array carries the contract number and batch operation date to fetch the current database state.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `param = null` | Declare param array (pre-OM change, null initialization) |
| 2 | SET | `param = new String[2]` | Initialize 2-element string array |
| 3 | SET | `param[0] = inMap.getString(JBSbatKKIFM161.OPSVKEI_NO)` | Contract number to delete — the option service contract number under deletion check |
| 4 | SET | `param[1] = super.opeDate` | Batch operation date — the date the batch is being run |

**Block 4** — [CALL] Execute concurrency check select (L1258)

> Queries the database to retrieve the current state of the option service contract record, enabling a compare-and-update strategy.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `executeKK_T_OP_SVC_KEI_KK_SELECT_094(param)` | Select current contract record. The 094 suffix indicates this is the concurrency check select version (post-performance improvement) |

**Block 5** — [CALL] Fetch select result (L1260)

> Retrieves the next row from the select result set, producing the current database state for comparison.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `getOpsvckeiMap = db_KK_T_OP_SVC_KEI.selectNext()` | Fetch the current record's generation add datetime for version comparison |

**Block 6** — [SET] Extract generation add datetime (L1261)

> Extracts the current `GENE_ADD_DTM` value from the database record into a local variable for comparison.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `sedai = (String) getOpsvckeiMap.getString("GENE_ADD_DTM")` | Extract the generation registration datetime from the fetched record. `sedai` (接帯) = generation/iteration identifier |

**Block 7** — [IF/ELSE] Version comparison branch (L1262–L1270)

> Compares the database's current `GENE_ADD_DTM` against the input's expected value. This is the core concurrency control — the update proceeds either way but with different criteria.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | COND | `sedai.equals(inMap.getString(JBSbatKKIFM161.OPSVKEI_GADTM))` | Compare DB version vs input version |

**Block 7.1** — [IF branch] Versions match (L1263–L1266)

> When the database timestamp matches the input, the record has not been modified externally. Use the original `whereMap` with the input's timestamp.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `db_KK_T_OP_SVC_KEI.updateByPrimaryKeys(whereMap, setMap)` | Update the contract record with original whereMap and the deletion timestamp setMap |

**Block 7.2** — [ELSE branch] Versions mismatch (L1268–L1271)

> When the database timestamp differs from the input, the record was modified externally (e.g., by another process or user). Adjust the whereMap to use the current database timestamp before updating, ensuring the update targets the correct record version.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `whereMap.setValue("GENE_ADD_DTM", sedai)` | Replace the input timestamp with the actual DB timestamp in the where criteria |
| 2 | EXEC | `db_KK_T_OP_SVC_KEI.updateByPrimaryKeys(whereMap, setMap)` | Update the contract record with adjusted whereMap and the deletion timestamp setMap |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `OPSVKEI_NO` | Field | Option Service Contract Number — unique identifier for an option service contract line item within the batch processing context |
| `OPSVKEI_GADTM` | Field | Option Service Contract Generation Registration Datetime — the timestamp when the contract record was last regenerated, used for optimistic concurrency control |
| `OP_SVC_KEI_NO` | Field | Option Service Contract Number — database column name for the contract identifier |
| `GENE_ADD_DTM` | Field | Generation Addition Datetime — database column storing the version/regeneration timestamp of the contract record; used to detect concurrent modifications |
| `SVCTK_BUT_DEL_TRN_JSSI_DTM` | Field | Service Contract Definite Item Elimination Registration Datetime — the timestamp written during the elimination (deletion) batch process to mark when the contract was processed for deletion; `SVCTK` = service contract, `BUT` = definite/final, `DEL` = elimination, `TRN_JSSI_DTM` = registration datetime |
| `sysDate` | Field | System date — the current batch run date set by the batch framework |
| `opeDate` / `ope` | Field | Operation date — the batch operation date inherited from the parent class, representing the processing date for the batch run |
| `sedai` | Field | Generation/iteration identifier — derived from the Japanese word `接帯` (settai), referring to the version or generation number of a contract record in the batch context |
| KK (class prefix) | Acronym | 消去 (Keshi) — elimination/deletion; refers to the batch process that performs periodic data elimination for obsolete contracts |
| `KK_T_OP_SVC_KEI_KK` | DB Table | Option Service Contract Table — the database table storing option service contract records; the trailing `KK` suffix denotes the batch-specific version of the table |
| `EKK0094SC` | SC Code | Option Service Contract Select — Service Component code for selecting option service contract records (inferred from method naming convention `executeKK_T_OP_SVC_KEI_KK_SELECT_094`) |
| JBSbat | Package prefix | JBatch — the batch processing framework package prefix used across the system |
| `db_KK_T_OP_SVC_KEI` | Instance field | Database access object for the `KK_T_OP_SVC_KEI_KK` table, providing `selectNext()` and `updateByPrimaryKeys()` methods |
| `JBSbatCommonDBInterface` | Type | Common database interface — a shared interface for building set/where parameter maps for DB operations |
| `JBSbatServiceInterfaceMap` | Type | Service interface map — the standard input message container carrying business parameters between batch methods |
