# Business Logic — JKKKikiKaifukuWrisvcCC.execKikiTorokuWrisvc() [58 LOC]

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

## 1. Role

### JKKKikiKaifukuWrisvcCC.execKikiTorokuWrisvc()

This method is the **equipment-provided service agreement recovery registration dispatcher** (`機器提供サービス契約回復登録出し処理`) within the K-Opticom customer base system (`eo顧客基幹システム`). Its business purpose is to determine how to resolve the **service agreement application number** (`mskm_no`) — which is required as a foreign key for registration — and then conditionally invoke the actual recovery registration logic.

The method implements a **conditional routing pattern** based on the service agreement status (`svc_kei_stat`). If the service agreement status is "Received" (`010`), it queries the **Application Detail Agreement Consultation** CBS (`EKK0021A010`) to resolve the application number from the application detail number. Otherwise (for non-received statuses), it reads the application number directly from the incoming request message (`ccMsg`), as it is already known from upstream processing.

Additionally, the method gates the recovery registration call on the **function code** (`func_code`). Only when `func_code` equals `"1"` (Check & Registration — `チェック＆登録`) does it proceed to call `execKktkSvcKeiInfoKaifuku()`, which performs the actual equipment-provided service agreement recovery registration. For other function codes, the method performs only the preparation logic and returns without performing any registration.

As a **private method**, this is a shared utility called by the public `execKikiKaifukuWrisvc()` entry point within the same class, which itself is invoked by multiple CBS/batch orchestrators including `JKKKikiIchiranIkkatsuCC`, `JKKKikiIchiranKkUpdCC`, and `JKKCoseRkRsvCanNtKojiUkCC`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execKikiTorokuWrisvc"])
    START --> GET_MSG["取得 ccMsg func_code workMap"]
    GET_MSG --> GET_TEMPLATE["取得 サービス契約テンプレート EKK0081A010"]
    GET_TEMPLATE --> GET_STAT["取得 svc_kei_stat"]
    GET_STAT --> CHECK_STAT{svc_kei_stat = 010<br/>受領済}
    CHECK_STAT -->|Yes| GET_MSKM_DTL["取得 svc_kei_mskm_dtl_no<br/>申請明細EKK0021A010検索"]
    CHECK_STAT -->|No| GET_MSG2["取得 mskm_no from ccMsg"]
    GET_MSKM_DTL --> CHECK_NULL{ekk0021 result null<br/>かつ length 0?}
    CHECK_NULL -->|Yes| SET_MSKM["mskmNo EKK0021 MSG1 MSKM_NO"]
    CHECK_NULL -->|No| SET_EMPTY["mskmNo 空文字列"]
    GET_MSG2 --> CHECK_FUNC{func_code = 1<br/>チェック登録}
    SET_MSKM --> CHECK_FUNC
    SET_EMPTY --> CHECK_FUNC
    CHECK_FUNC -->|Yes| CALL_REG["execKktkSvcKeiInfoKaifuku<br/>機器提供サービス契約回復登録"]
    CHECK_FUNC -->|No| END_NODE(["Return"])
    CALL_REG --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle providing the connection context for all CBS (Coordinated Business Service) calls executed within this method. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | Service Component invocation bridge that dispatches CBS calls (e.g., `EKK0021A010`) to the backend service layer. |
| 3 | `param` | `IRequestParameterReadWrite` | Request parameter object carrying data across the processing chain; provides `getData()` for message map access and `getMappingWorkArea()` for work area retrieval. |
| 4 | `dataMapKey` | `String` | Key identifier for the data map within `param` that contains the request message (`ccMsg`), including fields like `func_code`. Resolved from `fixedText` by the caller. |
| 5 | `temporaryData` | `HashMap<String, Object>` | Temporary data storage shared across CBS calls; contains pre-fetched template data (`EKK0081A010`, `EKK0341A010`) populated by the parent `execKikiKaifukuWrisvc()` method before this method is invoked. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `callSC` (EKK0021A010) | EKK0021A010SC | KK_T_MSKM (Application Detail Master) | Calls `EKK0021A010CBS` — Application Detail Agreement Consultation to resolve `mskm_no` from `svc_kei_mskm_dtl_no` when status is "Received". |
| R | `callSC` (EKK0081A010) | EKK0081A010SC | KK_T_SVKEI (Service Agreement Master) | Called by parent `execKikiKaifukuWrisvc()` to retrieve `svc_kei_stat` and service agreement detail number. Data pre-loaded into `temporaryData`. |
| R | `callSC` (EKK0341A010) | EKK0341A010SC | KK_T_KKTKSVKEI (Equipment-Provided Service Agreement Master) | Called by parent `execKikiKaifukuWrisvc()` to retrieve equipment-provided service agreement data. Pre-loaded into `temporaryData`. |
| C | `execKktkSvcKeiInfoKaifuku` | EKK0341A010CBS | KK_T_KKTKSVKEI (Equipment-Provided Service Agreement Master) | Equipment-provided service agreement recovery registration — inserts/retrieves recovery record. Invoked only when `func_code = "1"`. |
| R | `getNullToStr` | - | - | Utility method within the same class that safely converts null values to empty strings, used to prevent NPE on template data access. |

### Detail Breakdown:

| # | CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|---|------|----------|---------|-------------|----------------------|
| 1 | R | `JKKKikiKaifukuWrisvcCC.callSC` | EKK0021A010SC | KK_T_MSKM_DTL (Application Detail) | When `svc_kei_stat` is "010" (Received), queries `EKK0021A010CBS` (Application Detail Agreement Consultation) with `func_code="2"`, `key_mskm_dtl_no=svcKeiMskmDtlNo` to resolve the application number (`mskm_no`). |
| 2 | R | `callSC` (pre-loaded) | EKK0081A010SC | KK_T_SVKEI (Service Agreement) | Parent method pre-loaded `EKK0081A010` template into `temporaryData`; this method reads `svc_kei_stat` and `mskm_dtl_no` from it via `getString()`. |
| 3 | R | `callSC` (pre-loaded) | EKK0341A010SC | KK_T_KKTKSVKEI (Equipment Service Agreement) | Parent method pre-loaded `EKK0341A010` template; this method reads it to pass to `execKktkSvcKeiInfoKaifuku()` for the registration path. |
| 4 | C | `execKktkSvcKeiInfoKaifuku` | EKK0341A010CBS | KK_T_KKTKSVKEI (Equipment Service Agreement) | Invokes equipment-provided service agreement recovery registration. Internally prepares a parameter map and calls `execWrisvcAutoAply()` to apply recovery discounts automatically. Triggered only when `func_code = "1"` (Check & Registration). |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0194 | `KKSV0194CBS.process` -> `JKKKikiIchiranIkkatsuCC.execKikiKaifuku` -> `JKKKikiKaifukuWrisvcCC.execKikiKaifukuWrisvc` -> `JKKKikiKaifukuWrisvcCC.execKikiTorokuWrisvc` | `callSC [R] KK_T_SVKEI` / `EKK0021A010SC [R] KK_T_MSKM_DTL` / `execKktkSvcKeiInfoKaifuku [C] KK_T_KKTKSVKEI` |
| 2 | Screen:KKSV0197 | `KKSV0197CBS.process` -> `JKKKikiIchiranKkUpdCC.execKikiKaifuku` -> `JKKKikiKaifukuWrisvcCC.execKikiKaifukuWrisvc` -> `execKikiTorokuWrisvc` | Same as above |
| 3 | Screen:KKSV0198 | `KKSV0198CBS.process` -> `JKKKikiIchiranIkkatsuCC.execKikiKaifuku` -> `JKKKikiKaifukuWrisvcCC.execKikiKaifukuWrisvc` -> `execKikiTorokuWrisvc` | Same as above |
| 4 | Screen:KKSV0195 | `KKSV0195CBS.process` -> `JKKCoseRkRsvCanNtKojiUkCC.execKikiKaifuku` -> `JKKKikiKaifukuWrisvcCC.execKikiKaifukuWrisvc` -> `execKikiTorokuWrisvc` | Same as above |

**Note:** The direct callers listed are:
- `JKKKikiKaifukuWrisvcCC.execKikiKaifukuWrisvc()` — public entry point within the same class
- `JKKKikiIchiranKkCreateCC` — contains commented-out calls (inactive)

All live entry points flow through the four screen CBS entries (KKSV0194–KKSV0198) which trigger the service agreement recovery workflow.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `ccMsg = param.getData(dataMapKey)` (L190)

| # | Type | Code |
|---|------|------|
| 1 | SET | `ccMsg = (HashMap) param.getData(dataMapKey)` |
| 2 | SET | `func_code = (String) ccMsg.get("func_code")` // Function code — determines processing type |

**Block 2** — [SET] `workMap = param.getMappingWorkArea()` (L194)

> (Optional: Retrieves the common work area (`共通領域を取得`), though this variable is not used further in the method — likely reserved for future use.)

| # | Type | Code |
|---|------|------|
| 1 | SET | `workMap = param.getMappingWorkArea()` // 共通領域を取得 (Retrieve common area) |

**Block 3** — [SET] `ekk0081a010cbsMsg = (CAANMsg) temporaryData.get(TEMPLATE_ID_EKK0081A010)` (L198)

> Retrieves the pre-fetched service agreement consultation template. This was loaded by the parent `execKikiKaifukuWrisvc()` via a `callSC` to `EKK0081A010SC`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ekk0081a010cbsMsg = (CAANMsg) temporaryData.get(TEMPLATE_ID_EKK0081A010)` // `EKK0081A010` = "EKK0081A010" |

**Block 4** — [SET] `svcKeiStat = getNullToStr(ekk0081a010cbsMsg.getString(EKK0081A010CBSMsg1List.SVC_KEI_STAT))` (L201)

> Retrieves the service agreement status field. Uses `getNullToStr` utility to prevent NPE. The status value determines the subsequent branch logic.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiStat = getNullToStr(ekk0081a010cbsMsg.getString(EKK0081A010CBSMsg1List.SVC_KEI_STAT))` |

**Block 5** — [SET] `mskmNo = ""` (L203)

> Initializes the application number variable to empty string as a safe default.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mskmNo = ""` // Default empty string |

**Block 6** — [IF] `(SVC_KEI_STAT_UKZUMI.equals(svcKeiStat))` — `SVC_KEI_STAT_UKZUMI = "010"` (Service Agreement Status: Received) (L205)

> If the service agreement status is "010" (受領済 — Received), the service agreement application detail number is used to look up the application number via `EKK0021A010CBS`. This handles the case where only the detail reference is available and the full application number must be resolved.

**Block 6.1** — [SET] `svcKeiMskmDtlNo = getNullToStr(ekk0081a010cbsMsg.getString(EKK0081A010CBSMsg1List.MSKM_DTL_NO))` (L210)

> Retrieves the service agreement application detail number (`申請明細番号`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiMskmDtlNo = getNullToStr(ekk0081a010cbsMsg.getString(EKK0081A010CBSMsg1List.MSKM_DTL_NO))` // サービス契約の申請明細番号 (Service agreement application detail number) |

**Block 6.2** — [SET] Build `ekk0021a010IN` mapping array for EKK0021A010CBS query (L214–L219)

> Constructs the input parameter mapping for the Application Detail Agreement Consultation CBS. `func_code="2"` indicates a query (search) operation. The query key is the service agreement application detail number.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ekk0021a010IN = Object[][]` — 4-row mapping array |
| 2 | SET | `EKK0021A010CBSMsg.TEMPLATEID` = `TEMPLATE_ID_EKK0021A010` ("EKK0021A010") |
| 3 | SET | `EKK0021A010CBSMsg.FUNC_CODE` = `"2"` // Query mode |
| 4 | SET | `EKK0021A010CBSMsg.KEY_MSKM_DTL_NO` = `svcKeiMskmDtlNo` |
| 5 | SET | `EKK0021A010CBSMsg.KEY_GENE_ADD_DTM` = `""` |

**Block 6.3** — [SET + CALL] `ekk0021a010cbsMsg1list = callSC(handle, scCall, param, dataMapKey, ekk0021a010IN).getCAANMsgList(...)` (L221–L222)

> Invokes the `EKK0021A010CBS` (Application Detail Agreement Consultation) service component to look up the application number. Result is cast to a CAANMsg array.

| # | Type | Code |
|---|------|------|
| 1 | SET + CALL | `ekk0021a010cbsMsg1list = callSC(handle, scCall, param, dataMapKey, ekk0021a010IN).getCAANMsgList(EKK0021A010CBSMsg.EKK0021A010CBSMSG1LIST)` |

**Block 6.4** — [IF] `(ekk0021a010cbsMsg1list != null && ekk0021a010cbsMsg1list.length != 0)` (L222)

> Checks if the consultation returned results.

**Block 6.4.1** — [SET] `mskmNo = ekk0021a010cbsMsg1list[0].getString(EKK0021A010CBSMsg1List.MSKM_NO)` (L223)

> Extracts the application number (`mskm_no`) from the first result row.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mskmNo = ekk0021a010cbsMsg1list[0].getString(EKK0021A010CBSMsg1List.MSKM_NO)` // 申請番号 (Application number) |

**Block 7** — [ELSE] `else` (L228)

> When the service agreement status is NOT "010" (Received), the application number is already known from the upstream request data and is read directly from `ccMsg`. This is the common case for recovery operations where the full application number was already populated by the screen/CBS.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mskmNo = (String) ccMsg.get("mskm_no")` // 申請番号をリクエストから取得 (Get application number from request) |

**Block 8** — [IF] `(FUNC_CODE_1.equals(func_code))` — `FUNC_CODE_1 = "1"` (Check & Registration) (L232)

> The critical gating condition. Only when the function code is `"1"` (チェック＆登録 — Check and Registration) does the method proceed to perform the actual equipment-provided service agreement recovery registration. Other function codes (e.g., inquiry, cancellation) result in a no-op for this method.

**Block 8.1** — [SET] `ekk0341a010Msg = (CAANMsg) temporaryData.get(TEMPLATE_ID_EKK0341A010)` (L234)

> Retrieves the pre-fetched equipment-provided service agreement consultation template (`EKK0341A010`) from `temporaryData`. This template was loaded by the parent method via a prior `callSC`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ekk0341a010Msg = (CAANMsg) temporaryData.get(TEMPLATE_ID_EKK0341A010)` // `EKK0341A010` = "EKK0341A010" (機器提供サービス契約一致照会) |

**Block 8.2** — [CALL] `execKktkSvcKeiInfoKaifuku(handle, scCall, param, dataMapKey, ekk0341a010Msg, mskmNo)` (L236)

> Invokes the equipment-provided service agreement recovery registration method. This method (defined at L253 within the same class) prepares a parameter map and delegates to `execWrisvcAutoAply()` which performs the actual automatic recovery discount application processing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `execKktkSvcKeiInfoKaifuku(handle, scCall, param, dataMapKey, ekk0341a010Msg, mskmNo)` // 機器提供サービス契約情報登録 (Equipment-provided service agreement information registration) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `mskm_no` | Field | Application number (`申請番号`) — unique identifier for a service agreement application record. Used as a foreign key linking service agreement details to the master application. |
| `svc_kei_stat` | Field | Service agreement status (`サービス契約ステータス`) — indicates the lifecycle state of a service agreement. "010" = Received (`受領済`), meaning the service agreement has been received and the application detail can be queried. |
| `svc_kei_mskm_dtl_no` | Field | Service agreement application detail number (`サービス契約の申請明細番号`) — internal reference key used to look up the full application number via the Application Detail Agreement Consultation CBS. |
| `func_code` | Field | Function code (`機能コード`) — determines the processing mode. "1" = Check & Registration (`チェック＆登録`), triggering the actual registration; other values trigger inquiry or other non-registering paths. |
| `EKK0081A010` | Template | Service Agreement Consultation Template (`サービス契約一致照会テンプレート`) — CBS template for querying service agreement master data including status and detail references. |
| `EKK0021A010` | Template | Application Detail Agreement Consultation Template (`申請明細一致照会テンプレート`) — CBS template for querying application detail master to resolve the application number from a detail reference. |
| `EKK0341A010` | Template | Equipment-Provided Service Agreement Consultation Template (`機器提供サービス契約一致照会テンプレート`) — CBS template for querying equipment-provided service agreement data used in the recovery registration path. |
| EKK0081A010CBS | CBS | Service Agreement Consultation Service Component — Coordinated Business Service that queries the service agreement master table (`KK_T_SVKEI`). |
| EKK0021A010CBS | CBS | Application Detail Agreement Consultation Service Component — Coordinated Business Service that queries the application detail master table (`KK_T_MSKM_DTL`). |
| 受領済 (Ukuzumi) | Business term | "Received" — the state of a service agreement that has been received/acknowledged by the system, allowing subsequent detail lookups and processing. |
| 機器提供サービス (Kikiteiyo) | Business term | Equipment-Provided Service — a telecom service where the provider supplies the customer with equipment (e.g., router, set-top box) as part of the service contract. |
| 回復 (Kaifuku) | Business term | Recovery — in this context, refers to recovering/reinstating service agreements during the discount recovery process (割引回復), typically after a contract change or reactivation. |
| 割引 (Waribiki) | Business term | Discount — refers to promotional billing discounts applied to service contracts, which this CC handles recovering/restoring. |
| execKktkSvcKeiInfoKaifuku | Method | Equipment-Provided Service Agreement Recovery Registration — inner method that constructs the registration parameter map and delegates to the automatic recovery discount application CC (`execWrisvcAutoAply`). |
| execWrisvcAutoAply | Method | Wrisvc Auto Application CC — applies recovery discounts automatically to the service agreement, using parameters like service code, pricing plan, and equipment type. |
| KK_T_SVKEI | DB Table | Service Agreement Master table (`サービス契約マスタ`) — stores service agreement header records including status, type, and date fields. |
| KK_T_MSKM_DTL | DB Table | Application Detail Master table (`申請明細マスタ`) — stores application detail records linking to the master application table (`KK_T_MSKM`). |
| KK_T_KKTKSVKEI | DB Table | Equipment-Provided Service Agreement Master table (`機器提供サービス契約マスタ`) — stores equipment-provided service agreement records for recovery and discount processing. |
| eo顧客基幹システム | System | e-Open Customer Base System (`eo顧客基幹システム`) — Fujitsu's telecom customer management platform where this module operates. |
| CC (Common Component) | Architecture | Shared business logic component (`共通コンポーネント`) — reusable middleware class extending `AbstractCommonComponent` that coordinates CBS calls and business rules. |
| CBS (Coordinated Business Service) | Architecture | Enterprise service that encapsulates database operations and business rules for a specific domain function. |
