# Business Logic — JKKKapKeiInfoCancelCC.execEKKA0020504() [75 LOC]

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

## 1. Role

### JKKKapKeiInfoCancelCC.execEKKA0020504()

This method implements the **indoor device management system integration process** for inventory reconciliation when customer contracts are cancelled or orders are voided. In the FTTH (Fiber To The Home) and broadband telecom service context, when a subscriber cancels a service that included a leased terminal (e.g., ONU, router, set-top box), the delivery/receipt count associated with that device model must be decremented by one in the home logistics inventory system.

The method operates as a **batch-routing/dispatch component** within the business platform's common component layer. It receives a list of devices to cancel (`delKikiList`), iterates over each one, verifies that the device has already entered the "delivery accepted" state (配送済み — only devices with confirmed delivery trigger inventory reconciliation), queries the device contract agreement details via `execEKK0341A010`, determines the correct warehouse/shelf location based on the management site identifier, aggregates the inventory items by key, and finally dispatches all pending inventory updates to the `EKKA0020504` CBS (Common Business Service) via a single `callSCArray` invocation.

Its **role in the larger system** is that of an intermediary reconciliation step: it sits between the order cancellation workflow and the home logistics inventory system, ensuring that terminal stock counts are kept accurate after contract terminations. It is called from `JKKKapKeiInfoCancelCC.updKapKeiCancel()`, which handles the broader contract cancellation flow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execEKKA0020504"])

    START --> INIT["Initialize: upDateList, zaikoCheckMap"]

    INIT --> FOR["for cancelMap in delKikiList"]

    FOR --> CHKSTAT["chkHaisoStat(cancelMap.get(haiso_stat))"]

    CHKSTAT --> DELSTAT{jikou3 equals 1 ?}

    DELSTAT -->|No| SKIP["continue - skip inventory update"]
    SKIP --> FOR
    DELSTAT -->|Yes| CALL0341["execEKK0341A010(handle, scCall, param, dataMapKey, cancelMap)"]

    CALL0341 --> MODELCHECK{model_cd not empty ?}

    MODELCHECK -->|No| FOR
    MODELCHECK -->|Yes| KNRICHECK{KNRI_PLC_SKBT equals 2 ?}

    KNRICHECK -->|No| FOR
    KNRICHECK -->|Yes| SOKOTANA["getSokoTana(kriplace_skcd, hkcat_soko_cd, hkcat_skdn_cd, koji_cd, koji_slf_cd, office_cd, office_slf_cd)"]

    SOKOTANA --> EXTRACT["Extract: knriPlcSkbtCd, sokoCd, tanaCd, tkModelCd"]

    EXTRACT --> SETCHECK["setZaikoCheckMap(zaikoCheckMap, knriPlcSkbtCd, sokoCd, tanaCd, tkModelCd)"]

    SETCHECK --> FOR

    FOR --> ITERSTART{iterator has next ?}

    ITERSTART -->|No| CHECKUPDATE{upDateList.size > 0 ?}
    ITERSTART -->|Yes| NEXTITEM["mapkey = it.next()"]

    NEXTITEM --> GETMAP["zaikoKikiMap = zaikoCheckMap.get(mapkey)"]

    GETMAP --> SETZAIKO["setZaikoMap(upDateList, zaikoKikiMap)"]

    SETZAIKO --> ITERSTART

    CHECKUPDATE -->|No| END_NODE(["Return"])
    CHECKUPDATE -->|Yes| INITMSG["Init ekka0020504IN params: TEMPLATEID=EKKA0020504, FUNC_CODE=1"]

    INITMSG --> CALLCBS["callSCArray(handle, scCall, param, dataMapKey, ekka0020504IN, EKKA0020504CBSMsg1List, upDateList)"]

    CALLCBS --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle used to maintain transaction context across service component calls. Enables the CBS invocation to participate in the same database transaction as the caller. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | Service component invocation bridge — the mechanism through which this CC layer delegates to downstream CBS/SC services (e.g., `callSCArray` uses this to invoke the EKKA0020504 CBS). |
| 3 | `param` | `IRequestParameterReadWrite` | Request parameter container holding shared request context (data map, message list keys). Used to pass parameters to and from CBS invocations. |
| 4 | `dataMapKey` | `String` | Key identifying the data map within the request parameter container where CBS messages and results are stored. Typically a business-domain key that isolates the data for this cancellation workflow. |
| 5 | `delKikiList` | `ArrayList<HashMap<String, Object>>` | The core business input — a list of device (機器) records that are targets of cancellation/contract termination. Each `HashMap` represents one device with fields such as `haiso_stat` (delivery status), and is used to query the device contract agreement details via `execEKK0341A010`. |

**Instance fields / external state read:**
- `KNRI_PLC_SKBT_CD_KOJICOMP = "2"` — Constant defining the management location identifier code for "non-construction company" devices. Devices where the site identifier equals this value are skipped because they are handled differently (the management location code is empty in the service contract).

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKKapKeiInfoCancelCC.chkHaisoStat` | - | - | Read — Checks delivery status of a device; returns "1" if delivery accepted (配送済み). |
| C | `JKKKapKeiInfoCancelCC.execEKK0341A010` | EKK0341A010SC | KIKI_STI, KIKI_HKAT (Device service contract agreement tables) | Create/Read — Queries the device service contract agreement (機器提供サービス契約同意) for a specific device, returning contract details including model code, site identifier, warehouse codes, and construction company info. |
| R | `JKKKapKeiInfoCancelCC.getSokoTana` | - | - | Read — Resolves management location identifier, warehouse code, and shelf code from contract site information. Uses helper constants to map site types to actual codes. |
| - | `JKKKapKeiInfoCancelCC.setZaikoCheckMap` | - | - | Internal — Aggregates inventory check entries into `zaikoCheckMap`, keyed by location+model for batch processing. |
| - | `JKKKapKeiInfoCancelCC.setZaikoMap` | - | - | Internal — Transforms the aggregated check map into the update list format (`upDateList`) expected by the CBS. |
| U | `JKKKapKeiInfoCancelCC.callSCArray` | EKKA0020504CBS | EKKA0020504 (Indoor device logistics inventory table) | Update — Invokes the EKKA0020504 CBS (宅内機器物流在庫更新 — indoor device logistics inventory update) to decrement the delivery/receipt count by one for each device in the update list. Uses `TEMPLATE_ID_EKKA0020504 = "EKKA0020504"` and `FUNC_CODE_1 = "1"`. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JKKKapKeiInfoCancelCC.updKapKeiCancel()` | `updKapKeiCancel` -> `execEKKA0020504` | `callSCArray [U] EKKA0020504 CBS`, `setZaikoMap [-]`, `keySet [-]`, `setZaikoCheckMap [-]`, `chkHaisoStat [R]`, `execEKK0341A010 [C]` |

**No screen/batch entry points found.** This method is only called from within the same class's `updKapKeiCancel()` method, which is itself a CBS/CC entry point for the contract cancellation workflow.

**Terminal operations from this method:** `callSCArray` [U], `setZaikoMap` [-], `keySet` [-], `setZaikoCheckMap` [-], `chkHaisoStat` [R], `execEKK0341A010` [C], `getSokoTana` [R].

## 6. Per-Branch Detail Blocks

**Block 1** — [INIT] `(Initialization)` (L3002)

> Initializes local data structures for tracking devices eligible for inventory update.

| # | Type | Code |
|---|------|------|
| 1 | SET | `upDateList = new ArrayList<>()` // Inventory update list (在庫更新用リスト) |
| 2 | SET | `zaikoCheckMap = new HashMap<>()` // Inventory check map (在庫チェックMap) |

**Block 2** — [FOR] `(for cancelMap in delKikiList)` (L3007)

> Iterates over each device marked for cancellation. This is the main processing loop.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `cancelMap.get("haiso_stat")` // Extract delivery status from cancelMap |
| 2 | CALL | `chkHaisoStat((String)cancelMap.get("haiso_stat"))` // Check if delivery accepted |

**Block 2.1** — [IF] `(condition: jikou3 != "1")` [配送済判定: 配送済みでない場合はスキップ] (L3011)

> Only devices with confirmed delivery (配送済み) proceed to inventory update. This prevents updating stock for devices that have not yet been shipped.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `"1".equals(jikou3)` → false |
| 2 | EXEC | `continue` // Skip this device — not yet delivered, no inventory change needed |

**Block 2.2** — [ELSE — delivery status is "1"] `(配送済み)` (L3015)

> Device has been delivered; proceed to query contract agreement details.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `execEKK0341A010(handle, scCall, param, dataMapKey, cancelMap)` // Query device service contract agreement (機器提供サービス契約同意会の実行) |

**Block 2.2.1** — [IF] `(condition: model_cd is empty)` (L3018)

> If the contract agreement query returned no model code, skip inventory update for this device.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `!"".equals(ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.TAKNKIKI_MODEL_CD))` → false |
| 2 | EXEC | *(fall through — no model code means no device was registered, so skip inventory update)* |

**Block 2.2.2** — [ELSE] `(model_cd is present)` (L3021)

> Device model code exists; check whether the management location identifier indicates a contracted device.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `!KNRI_PLC_SKBT_CD_KOJICOMP.equals(kriplace_skcd)` → evaluate |
| 1.1 | **[CONSTANT: `KNRI_PLC_SKBT_CD_KOJICOMP = "2"`]** — 管理場所識別コード：工事会社以外 (management location identifier: non-construction company) |

**Block 2.2.2.1** — [IF — contracted device: skip] `(条件: 管理場所識別コードが工事会社以外ではない)` (L3024)

> When the device's site identifier equals "2" (工事会社 = construction company), the management location code should be left blank. Skip inventory reconciliation.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `KNRI_PLC_SKBT_CD_KOJICOMP.equals(kriplace_skcd)` → true |
| 2 | EXEC | *(skip — fall through to next cancelMap)* |

**Block 2.2.2.2** — [ELSE — non-contracted device: resolve warehouse location] (L3026)

> The device is not a construction-company-managed device. Resolve the correct warehouse and shelf codes using `getSokoTana`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `getSokoTana(kriplace_skcd, hkcat_soko_cd, hkcat_skdn_cd, koji_cd, koji_slf_cd, office_cd, office_slf_cd)` // Resolve management location info from contract site (管理場所識別コードにより設定する項目を変更) |
| 2 | SET | `knriPlcSkbtCd = sokoTanaMap.get(TMP_KRIPLACE_SKCD)` // Extract temporary management location code |
| 3 | SET | `sokoCd = sokoTanaMap.get(TMP_SOKO_CD)` // Extract temporary warehouse code |
| 4 | SET | `tanaCd = sokoTanaMap.get(TMP_SKDN_CD)` // Extract temporary shelf code |
| 5 | SET | `tkModelCd = ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.TAKNKIKI_MODEL_CD)` // Extract device model code (型番) |

**Block 2.2.2.3** — [ELSE — aggregate into check map] (L3042)

> Add this device's inventory information to the aggregation map for batch processing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `setZaikoCheckMap(zaikoCheckMap, knriPlcSkbtCd, sokoCd, tanaCd, tkModelCd)` // Aggregate inventory check entry (在庫チェック数はマウスを設定) |

**Block 3** — [WHILE] `(zaikoCheckMap.keySet iterator)` (L3049)

> After processing all cancellation devices, iterate through the aggregated inventory check map to transform it into the update list format.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `it = zaikoCheckMap.keySet().iterator()` // Get iterator over check map keys |
| 2 | CONDITION | `it.hasNext()` |

**Block 3.1** — [LOOP BODY — per inventory entry] (L3054)

| # | Type | Code |
|---|------|------|
| 1 | SET | `mapkey = it.next()` |
| 2 | SET | `zaikoKikiMap = (HashMap)zaikoCheckMap.get(mapkey)` |
| 3 | CALL | `setZaikoMap(upDateList, zaikoKikiMap)` // Transform check entry into update list format (在庫更新リストに設定) |

**Block 4** — [IF] `(condition: upDateList.size > 0)` (L3059)

> If any devices were collected for inventory update, invoke the CBS to perform the actual stock count decrement.

| # | Type | Code |
|---|------|------|
| 1 | CONDITION | `upDateList.size() > 0` |
| 2 | SET | `ekka0020504IN = { { TEMPLATEID, TEMPLATE_ID_EKKA0020504 }, { FUNC_CODE, FUNC_CODE_1 } }` // CBS invocation params |
| 2.1 | **[CONSTANT: `TEMPLATE_ID_EKKA0020504 = "EKKA0020504"`]** — 宅内機器物流在庫更新テンプレートID |
| 2.2 | **[CONSTANT: `FUNC_CODE_1 = "1"`]** — 機能コード1 |
| 3 | CALL | `callSCArray(handle, scCall, param, dataMapKey, ekka0020504IN, "EKKA0020504CBSMsg1List", upDateList)` // Invoke EKKA0020504 CBS for inventory update (キャンセル・解約対象機器の宅内機器管理システム連携処理) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `delKikiList` | Field | Cancellation device list — devices targeted for contract cancellation that require inventory reconciliation |
| `haiso_stat` | Field | Delivery status — indicates whether a device has been delivered (配送済み). Value "1" means delivery accepted. |
| `jikou3` | Variable | Delivery status check result — internal variable holding the result of `chkHaisoStat()` |
| `haiso` | Japanese term | 配送 — delivery / shipment |
| `haiso_stat` | Japanese term | 配送ステータス — delivery status |
| `zaiko` | Japanese term | 在庫 — inventory / stock |
| `zaikoCheckMap` | Variable | Inventory check map — intermediate aggregation map keyed by location+model for batch inventory updates |
| `upDateList` | Variable | Inventory update list — the final list of device records to send to the inventory update CBS |
| `kiki` | Japanese term | 機器 — device / terminal equipment |
| `soko` | Japanese term | 倉庫 — warehouse |
| `tana` | Japanese term | 棚 — shelf |
| `sokoTana` | Method | Warehouse and shelf location resolver — maps contract site identifiers to actual warehouse/shelf codes |
| `kriplace_skcd` | Field | Site/place identifier code — management location classification for the device |
| `knriPlcSkbtCd` | Variable | 管理場所識別コード — management location identifier code that classifies whether the device is managed by a construction company or the service provider |
| `KNRI_PLC_SKBT_CD_KOJICOMP` | Constant | Management location identifier: non-construction company = "2" — devices with this value are excluded from warehouse-based inventory reconciliation |
| `tkModelCd` | Variable | 型番 — device model code (terminal equipment model number) |
| `TAKNKIKI_MODEL_CD` | Field | 簡易機器モデルコード — simplified device model code from the contract agreement message |
| `execEKK0341A010` | Method | Device service contract agreement query — retrieves full device contract details including model code, site info, and construction company data |
| `EKK0341A010CBSMsg1List` | Field | Message list key for the EKK0341A010 CBS response containing device contract agreement data |
| `callSCArray` | Method | Service component array invocation — generic CBS caller that dispatches an array of parameters to a CBS and populates a message list |
| `EKKA0020504` | CBS Code | Indoor device logistics inventory update CBS — decrements delivery/receipt count by 1 for cancelled devices |
| `TEMPLATE_ID_EKKA0020504` | Constant | Template ID for the EKKA0020504 CBS = "EKKA0020504" |
| `FUNC_CODE_1` | Constant | Function code = "1" — indicates standard update operation |
| TMP_KRIPLACE_SKCD | Constant | Temporary key "tmp_kriplace_skcd" for extracting resolved management location code from getSokoTana result |
| TMP_SOKO_CD | Constant | Temporary key "tmp_soko_cd" for extracting resolved warehouse code |
| TMP_SKDN_CD | Constant | Temporary key "tmp_skdn_cd" for extracting resolved shelf code |
| FTTH | Business term | Fiber To The Home — fiber-optic broadband internet service |
| CBS | Acronym | Common Business Service — enterprise service component that handles business logic and data access |
| SC | Acronym | Service Component — service layer component invoked by CC (Controller/Common Component) classes |
| CC | Acronym | Common Component / Controller Component — shared business coordination layer |
| 機器提供サービス契約同意会 | Japanese term | Device service contract agreement meeting/process — the contract agreement record that binds a subscriber to a leased device |
