# Business Logic — JKKUseStpRlsRunCC.executeSeiOpSvcKei_UseStp() [143 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKUseStpRlsRunCC` |
| Layer | CC/Common Component |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKUseStpRlsRunCC.executeSeiOpSvcKei_UseStp()

This method implements the **Option Service Contract Use Suspension Cancellation** processing (請求オプションサービス契約利用停止解除処理). It is the core business logic handler responsible for restoring an option service contract that was placed in a "suspended" state back to an active state. The method operates on the **Sei Op Svc Kei** (Seiihin Option Service Category / 請求オプションサービス種別) entity — a specific type of optional add-on service contracted alongside a primary telecom service.

The method implements a **query-then-resolve dispatch pattern**. First, it inquires the current agreement consensus and contract status of the target option service contract via the `EKK0441A010` service component. If the status indicates suspension (`"220"`), it then queries the full contract history to identify the most appropriate prior contract state to restore. Based on that prior state, it dispatches to one of two cancellation service components: `EKK0441C090` for standard suspension cancellation or `EKK0441C091` for pause-in-middle suspension cancellation.

This is a **shared utility component** called by the `executeUseStpRlsMain` method within the same class, making it the primary processing logic for the use suspension cancellation workflow. It handles two distinct cancellation scenarios — standard suspension (usually caused by non-payment or administrative hold) and pause-in-middle suspension (status `"210"`, where the contract was suspended during a pause period) — ensuring the contract is restored to the correct state regardless of the suspension origin.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["executeSeiOpSvcKei_UseStp(params)"])
    STATUS_INIT(["statusCode = 0"])
    CALL_A010(["getEKK0441A010SC - Inquiry Option Service Contract Agreement Consensus"])
    CHECK_A010{"statusCode != 0"}
    GET_RESULT_A010(["get EKK0441A010Hash from resultHash"])
    GET_STAT(["get seiopsvc_kei_stat from EKK0441A010Hash"])
    GET_ADD_DTM(["get seiopsvc_gene_add_dtm from EKK0441A010Hash"])
    CHECK_STP{"seiopsvc_kei_stat == SVC_KEI_STAT_STP"}
    STATUS_SVP(["statusCode = getEKK0441B002SC - Inquiry History List"])
    CHECK_B002{"statusCode != 0"}
    GET_HISTORY(["get eKK0441B002HashList from resultHash"])
    CHECK_LIST{"list.size > 0"}
    FOR_LOOP(["for loop over eKK0441B002HashList"])
    GET_GENE_DTM(["get gene_add_dtm from history record"])
    CHECK_DTM{"gene_add_dtm matches seiopsvc_gene_add_dtm?"}
    CONTINUE(["continue to next record"])
    GET_STAT_HIST(["get seiOpSvcKeiStatRireki from history record"])
    CHECK_STAT_HIST{"seiopsvc_kei_stat == seiOpSvcKeiStatRireki?"}
    CONTINUE_HIST(["continue to next record"])
    CHECK_HIST_STAT{"seiOpSvcKeiStatRireki == 210?"}
    CALL_C091(["getEKK0441C091SC - Pause Middle Suspension Cancel"])
    CHECK_C091{"statusCode != 0"}
    BREAK_C091(["break loop"])
    CALL_C090(["getEKK0441C090SC - Option Service Contract Suspension Cancel"])
    CHECK_C090{"statusCode != 0"}
    BREAK_C090(["break loop"])
    EMPTY_HISTORY(["do nothing - no history records"])
    RETURN_OK(["return 0"])
    RETURN_ERR(["return statusCode"])

    START --> STATUS_INIT
    STATUS_INIT --> CALL_A010
    CALL_A010 --> CHECK_A010
    CHECK_A010 -->|true| RETURN_ERR
    CHECK_A010 -->|false| GET_RESULT_A010
    GET_RESULT_A010 --> GET_STAT
    GET_STAT --> GET_ADD_DTM
    GET_ADD_DTM --> CHECK_STP
    CHECK_STP -->|false| RETURN_OK
    CHECK_STP -->|true| STATUS_SVP
    STATUS_SVP --> CHECK_B002
    CHECK_B002 -->|true| RETURN_ERR
    CHECK_B002 -->|false| GET_HISTORY
    GET_HISTORY --> CHECK_LIST
    CHECK_LIST -->|false| EMPTY_HISTORY
    CHECK_LIST -->|true| FOR_LOOP
    FOR_LOOP --> CHECK_DTM
    CHECK_DTM -->|true| CONTINUE
    CONTINUE --> GET_GENE_DTM
    CHECK_DTM -->|false| GET_STAT_HIST
    GET_STAT_HIST --> CHECK_STAT_HIST
    CHECK_STAT_HIST -->|true| CONTINUE_HIST
    CONTINUE_HIST --> GET_GENE_DTM
    CHECK_STAT_HIST -->|false| CHECK_HIST_STAT
    CHECK_HIST_STAT -->|true| CALL_C091
    CHECK_HIST_STAT -->|false| CALL_C090
    CALL_C091 --> CHECK_C091
    CHECK_C091 -->|true| RETURN_ERR
    CHECK_C091 -->|false| BREAK_C091
    BREAK_C091 --> GET_GENE_DTM
    CALL_C090 --> CHECK_C090
    CHECK_C090 -->|true| RETURN_ERR
    CHECK_C090 -->|false| BREAK_C090
    BREAK_C090 --> GET_GENE_DTM
    EMPTY_HISTORY --> RETURN_OK
    RETURN_OK --> END(["END"])
    RETURN_ERR --> END
```

**Block descriptions:**

1. **Initialization** — Sets `statusCode` to `0` (success code).
2. **Contract Agreement Inquiry** — Calls `getEKK0441A010SC` to retrieve the agreement consensus for the option service contract identified by `seiOpSvcKeiNo`. On any error, returns immediately.
3. **Status Extraction** — Extracts the contract status (`seiopsvc_kei_stat`) and generation addition timestamp (`seiopsvc_gene_add_dtm`) from the inquiry result.
4. **Suspended Check** — The key decision point. The constant `SVC_KEI_STAT_STP = "220"` represents the "suspended" (利用停止中) status. If the contract is NOT suspended, the method returns success immediately (no cancellation needed).
5. **History Inquiry (suspended path)** — When suspended, calls `getEKK0441B002SC` to retrieve the full contract history list for the option service contract, ordered by generation addition date descending.
6. **History Loop** — Iterates over the history list, comparing each record against the current contract to find the most recent non-matching prior state. The loop uses two matching conditions to skip irrelevant records:
   - Skip if the generation date matches the current contract's generation date (same version).
   - Skip if the prior status matches the current suspended status (same state as current).
7. **Prior Status Dispatch** — For the first non-skipped history record, checks if the prior status is `"210"` (pause-in-middle). If so, calls `getEKK0441C091SC` (Pause-in-Middle Cancellation); otherwise calls `getEKK0441C090SC` (Standard Cancellation). After successful processing, breaks the loop.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | The session handle carrying session management context (database connections, transaction boundaries, security context) used by all downstream service component calls. |
| 2 | `param` | `IRequestParameterReadWrite` | The request parameter object that carries model groups and control maps. It serves as both input and output for CBS (Component-Based Service) calls, allowing mapping layer classes to set and retrieve CBS-specific input/output data structures. |
| 3 | `requestParam` | `HashMap<String, Object>` | The request parameter map carrying business data passed from the calling screen/controller. Used as input to the `getEKK0441A010SC` inquiry. |
| 4 | `resultHash` | `HashMap<String, Object>` | The result hash map used to pass output data between method calls. Populated by `getEKK0441A010SC` with the contract agreement data, and by `getEKK0441B002SC` with the contract history list. Read by subsequent processing steps. |
| 5 | `seiOpSvcKeiNo` | `String` | The **Seiihin Option Service Contract Number** (請求オプションサービス契約番号) — the unique identifier of the specific option service contract to be restored from suspension. This value is passed to all CBS calls to identify the target contract. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `getEKK0441A010SC` | EKK0441A010SC | KK_T_SEIOPSVC_KEI (Seiihin Option Service Contract) | Inquiry Option Service Contract Agreement Consensus — retrieves the current agreement and status (`seiopsvc_kei_stat`) of the target option service contract identified by `seiOpSvcKeiNo`. Sets `SEIOPSVC_KEI_STAT = "220"` for suspended status. |
| R | `getEKK0441B002SC` | EKK0441B002SC | KK_T_SEIOPSVC_KEI_ISHN (Option Service Contract History) | Inquiry Option Service Contract History List — retrieves the full history of contract status changes for the target contract, ordered by `GENE_ADD_DTM` (Generation Addition Date/Time) descending. Results include prior `seiopsvc_kei_stat` values. |
| U | `getEKK0441C090SC` | EKK0441C090CBS | KK_T_SEIOPSVC_KEI (Seiihin Option Service Contract) | Option Service Contract Suspension Cancellation (請求オプションサービス契約停止解除) — standard cancellation that restores the contract from a non-pause-in-middle suspended state. Uses `FUNC_CODE` to identify the cancellation operation. |
| U | `getEKK0441C091SC` | EKK0441C091CBS | KK_T_SEIOPSVC_KEI (Seiihin Option Service Contract) | Pause-in-Middle Option Service Contract Suspension Cancellation (休止中請求オプションサービス契約停止解除) — special cancellation path for contracts suspended during a pause (status `"210"`, 休止中) — as opposed to standard suspension. |

### Method call classification:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `getEKK0441A010SC` | EKK0441A010SC | KK_T_SEIOPSVC_KEI | Reads the current agreement consensus of the option service contract (Seiihin Option Service Category). Returns status code `"220"` when the contract is in a suspended state. |
| R | `getEKK0441B002SC` | EKK0441B002SC | KK_T_SEIOPSVC_KEI_ISHN | Reads the complete history of contract status changes. Results are sorted descending by generation addition date/time (`gene_add_dtm`). Each record contains a prior `seiopsvc_kei_stat` value. |
| U | `getEKK0441C090SC` | EKK0441C090CBS | KK_T_SEIOPSVC_KEI | Updates the contract status to restore it from a standard suspension. Applied when the prior history record's status is NOT `"210"` (i.e., not pause-in-middle). |
| U | `getEKK0441C091SC` | EKK0441C091CBS | KK_T_SEIOPSVC_KEI | Updates the contract status to restore it from a pause-in-middle suspension. Applied when the prior history record's status IS `"210"` (休止中 — paused middle). |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.
Terminal operations from this method: `getEKK0441C090SC` [U], `getEKK0441C091SC` [U], `getEKK0441B002SC` [R], `getEKK0441A010SC` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `executeUseStpRlsMain` (JKKUseStpRlsRunCC) | `executeUseStpRlsMain` -> `executeSeiOpSvcKei_UseStp` | `getEKK0441C090SC [U] KK_T_SEIOPSVC_KEI`, `getEKK0441C091SC [U] KK_T_SEIOPSVC_KEI` |

**Caller details:**
- The method `executeUseStpRlsMain` is the entry point that orchestrates the broader Use Suspension Cancellation workflow (利用停止解除処理). It calls `executeSeiOpSvcKei_UseStp` to handle the Sei Op Svc Kei (請求オプションサービス種別) sub-process.
- `executeUseStpRlsMain` itself is called from screen processing — likely from a screen controller that handles the use suspension cancellation UI operation.

## 6. Per-Branch Detail Blocks

### Block 1 — INIT (L1673)

> Initialize the status code variable for return value tracking.

| # | Type | Code |
|---|------|------|
| 1 | SET | `statusCode = 0;` // Status code initialized to success |

### Block 2 — CALL getEKK0441A010SC (L1676)

> Inquiry the Option Service Contract Agreement Consensus (請求オプションサービス契約同意照会) to retrieve the current contract state.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `statusCode = getEKK0441A010SC(param, handle, requestParam, resultHash, seiOpSvcKeiNo);` // SC Code: EKK0441A010SC — reads KK_T_SEIOPSVC_KEI |

### Block 3 — IF statusCode check (L1677)

> If the agreement inquiry returned a non-zero status code, there was an error. Return immediately to prevent cascading failures.

| # | Type | Code |
|---|------|------|
| 1 | COND | `if (statusCode != 0)` |
| 2 | RETURN | `return statusCode;` // Early return on inquiry error |

### Block 4 — EXTRACT status and timestamp (L1680–1686)

> Extract the contract status and the generation addition timestamp from the inquiry result. The `OM-2014-0002565` change log marker (2014/08/21) indicates the `gene_add_dtm` field was added to support the history comparison logic.

| # | Type | Code |
|---|------|------|
| 1 | SET | `eKK0441A010Hash = (HashMap<String, Object>) resultHash.get(TEMPLATE_ID_EKK0441A010);` // [TEMPLATE_ID_EKK0441A010 = "EKK0441A010"] |
| 2 | SET | `seiopsvc_kei_stat = (String) eKK0441A010Hash.get(EKK0441A010CBSMsg1List.SEIOPSVC_KEI_STAT);` // [SEIOPSVC_KEI_STAT = "seiopsvc_kei_stat"] |
| 3 | SET | `seiopsvc_gene_add_dtm = (String) eKK0441A010Hash.get(EKK0441A010CBSMsg1List.GENE_ADD_DTM);` // [GENE_ADD_DTM = "gene_add_dtm"] |

### Block 5 — IF suspension status check (L1688)

> **Core decision: Is the contract currently suspended?**
> Constant: `SVC_KEI_STAT_STP = "220"` (利用停止中 — Suspended)
> If NOT suspended, skip all cancellation logic and return success (the contract is already active).

| # | Type | Code |
|---|------|------|
| 1 | COND | `if (SVC_KEI_STAT_STP.equals(seiopsvc_kei_stat))` |
| 2 | SET | `statusCode = getEKK0441B002SC(param, handle, requestParam, resultHash, seiOpSvcKeiNo);` // [Block 5.1 — history inquiry] |
| 3 | COND | `if (statusCode != 0)` // [Block 5.2 — error check] |
| 4 | RETURN | `return statusCode;` |
| 5 | SET | `eKK0441B002HashList = (ArrayList<HashMap<String, Object>>) resultHash.get(TEMPLATE_ID_EKK0441B002);` // [Block 5.3 — extract history list] |
| 6 | COND | `if (eKK0441B002HashList.size() > 0)` // [Block 5.4 — history present] |
| 7 | (else) | // Empty block — do nothing when no history records exist |
| 8 | ELSE-EXIT | // Fall through to `return 0` |
| ELSE-EXIT | // [If NOT suspended, fall through to `return 0`] |

### Block 5.1 — FOR loop over history records (L1699)

> Iterate over the contract history list (ordered by generation addition date descending). For each record, skip it if it matches the current contract's generation date OR if its status matches the current suspended status. The first record that differs in both aspects is the "prior state" to restore.

| # | Type | Code |
|---|------|------|
| 1 | SET | `eKK0441B002Hash = eKK0441B002HashList.get(idx_su);` // Get current history record |
| 2 | SET | `gene_add_dtm = (String) eKK0441B002Hash.get(EKK0441B002CBSMsg1List.GENE_ADD_DTM);` // [GENE_ADD_DTM = "gene_add_dtm"] |
| 3 | COND | `if (seiopsvc_gene_add_dtm.equals(gene_add_dtm))` // Same generation date — same version, skip |
| 4 | EXEC | `continue;` |
| 5 | ELSE-ELSE | // [Block 5.1.2 — different generation date] |

### Block 5.1.2 — Prior status extraction (L1710)

> The generation date does not match — this is a different version. Extract the prior contract status from this history record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `seiOpSvcKeiStatRireki = (String) eKK0441B002Hash.get(EKK0441B002CBSMsg1List.SEIOPSVC_KEI_STAT);` // [SEIOPSVC_KEI_STAT = "seiopsvc_kei_stat"] |

### Block 5.1.3 — IF prior status matches current suspended status (L1714)

> If the prior record's status is the same as the current suspended status, skip this record (it was already being handled by the current suspension state).

| # | Type | Code |
|---|------|------|
| 1 | COND | `if (seiopsvc_kei_stat.equals(seiOpSvcKeiStatRireki))` |
| 2 | EXEC | `continue;` |
| 3 | ELSE-ELSE | // [Block 5.1.4 — prior status is different from current] |

### Block 5.1.4 — IF prior status is "210" dispatch (L1720)

> **Key dispatch: Determine the cancellation type based on the prior contract status.**
> - Status `"210"` (休止中 — Paused Middle): The contract was suspended while in a paused state. Requires special cancellation via `EKK0441C091`.
> - Any other status: Standard suspension cancellation via `EKK0441C090`.

| # | Type | Code |
|---|------|------|
| 1 | COND | `if ("210".equals(seiOpSvcKeiStatRireki))` // [休止中中断中 — Paused Middle] |
| 2 | CALL | `statusCode = getEKK0441C091SC(param, handle, requestParam, resultHash);` // SC: EKK0441C091CBS — Pause-in-Middle Cancellation |
| 3 | COND | `if (statusCode != 0)` // [Block 5.1.4.2 — C091 error check] |
| 4 | RETURN | `return statusCode;` |
| 5 | ELSE-ELSE | `break;` // Success — exit the for loop |
| ELSE-ELSE | // [Block 5.1.4.3 — not "210"] |

### Block 5.1.4.3 — Standard Cancellation (L1733)

> The prior status was NOT `"210"`. Use the standard suspension cancellation.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `statusCode = getEKK0441C090SC(param, handle, requestParam, resultHash);` // SC: EKK0441C090CBS — Standard Suspension Cancellation |
| 2 | COND | `if (statusCode != 0)` // [Block 5.1.4.3.2 — C090 error check] |
| 3 | RETURN | `return statusCode;` |
| 4 | ELSE-ELSE | `break;` // Success — exit the for loop |

### Block 6 — RETURN success (L1760)

> If the contract was not suspended (status != "220"), or all processing completed successfully, return `0`.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return 0;` // Success |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `seiOpSvcKeiNo` | Field | Seihihin Option Service Contract Number (請求オプションサービス契約番号) — The unique identifier for an option service contract add-on attached to a primary telecom subscription. |
| `seiopsvc_kei_stat` | Field | Option Service Contract Status (請求オプションサービス契約ステータス) — The current operational state of the option service contract. `"220"` = suspended (利用停止中), `"210"` = paused middle (休止中). |
| `gene_add_dtm` | Field | Generation Addition Date/Time (世代登録年月日時) — A timestamp used to version contract records. Records with different `gene_add_dtm` values represent different versions/generations of the same contract. |
| `seiopsvc_gene_add_dtm` | Field | Current contract's Generation Addition Date/Time — Used to distinguish the current contract version from historical records. |
| `seiOpSvcKeiStatRireki` | Field | Option Service Contract Status History (請求オプションサービス契約ステータス履歴) — The status value from a prior generation of the contract, used to determine the correct cancellation type. |
| `statusCode` | Field | Processing status code — `0` indicates success; non-zero indicates an error requiring immediate return. |
| `SVC_KEI_STAT_STP` | Constant | Service Category Status Suspended — Value `"220"`. Indicates the contract is in a "use suspended" (利用停止中) state, requiring cancellation processing. |
| `EKK0441A010` | SC Code | Agreement Consensus Inquiry — Reads the current agreement status and state of an option service contract from `KK_T_SEIOPSVC_KEI`. |
| `EKK0441B002` | SC Code | Contract History List Inquiry — Retrieves the full history of contract status changes from `KK_T_SEIOPSVC_KEI_ISHN`, ordered by generation date descending. |
| `EKK0441C090` | SC Code | Option Service Contract Suspension Cancellation (請求オプションサービス契約停止解除) — Restores a contract from standard suspension to active. |
| `EKK0441C091` | SC Code | Pause-in-Middle Option Service Contract Suspension Cancellation (休止中請求オプションサービス契約停止解除) — Special path for contracts that were suspended during a pause period. |
| KK_T_SEIOPSVC_KEI | DB Entity | Seiihin Option Service Contract table — Core table storing option service contract records. |
| KK_T_SEIOPSVC_KEI_ISHN | DB Entity | Seiihin Option Service Contract History table — History/audit table storing contract state transitions. |
| 利用停止 | Business term | Use Suspension (Use Stop) — A state where an option service is temporarily disabled, typically due to non-payment or administrative reasons. Status code `"220"`. |
| 利用停止解除 | Business term | Use Suspension Cancellation — The process of restoring a suspended option service contract to active status. |
| 休止中 | Business term | Paused Middle — A state where the primary service itself is paused (e.g., temporary service suspension). Status code `"210"`. Requires special handling because the underlying service is not simply in arrears but actively paused. |
| 請求オプションサービス | Business term | Bill Option Service — Optional add-on services (e.g., additional phone lines, internet packages) billed alongside the primary telecom service. |
| TEMPLATE_ID_EKK0441A010 | Constant | Template identifier for EKK0441A010CBS service — Value `"EKK0441A010"`. Used as the key in `resultHash`. |
| TEMPLATE_ID_EKK0441B002 | Constant | Template identifier for EKK0441B002CBS service — Value `"EKK0441B002"`. Used as the key in `resultHash` to retrieve the history list. |
| OM-2014-0002565 | Change log | System modification ticket (2014/08/21) — Added the `gene_add_dtm` field comparison logic to the suspension cancellation flow, ensuring history records are correctly matched to contract versions. |
