# Business Logic — JKKKojiWrisvcAutoAplyCC.setKktkSvc() [35 LOC]

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

## 1. Role

### JKKKojiWrisvcAutoAplyCC.setKktkSvc()

This method acts as a **service-type filter and data transformer** within the Work Order Service Auto-Apply Common Component. Its business purpose is to extract equipment-provision service contract lines (機材提供サービス契約 — *ki-zai teikyo saabisu keiyaku*) from a parent list and restructure them into a canonical format expected by the downstream `JKKWrisvcAutoAplyCC.execute()` service application engine.

Specifically, it filters the input list to include **only STB (Set Top Box) service records** — identified by the service code `"C009"` — which represents equipment-related telecom services such as cable TV or IPTV set-top box provisioning. For each matching record, it creates a new HashMap containing a fixed subset of fields required for service contract processing: the target contract category code (hardcoded to `"06"`), the service contract number, service contract status, price course code, price plan code, equipment provision service code, and equipment provision type code.

The method implements a **mapping/filtering pattern**: it iterates over the input list, applies a single-type filter (STB only), and builds a narrowed result list. It is a shared utility called from `JKKKojiWrisvcAutoAplyCC.execute()` in four distinct operational contexts — registration (`add_chge_div = "01"`), cancellation (`add_chge_div = "03"`), restoration (`add_chge_div = "04"`), and cancel (`add_chge_div = "05"`) — each of which passes different source lists (e.g., `createKikiList`, `dslKikiList`, `kaihkKikiList`, `cancelKikiList`) and expects the filtered service list to drive the subsequent auto-application logic.

This method performs **no database access, no SC code invocation, and no side effects** — it is a pure data transformation utility that narrows and restructures in-memory data for the downstream service application process.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["setKktkSvc list"])
    CHECK_NULL["list null check"]
    INIT["svcKeiList = new ArrayList()"]
    INIT_MAPS["kikiMap = null, svcKeiMap = null"]
    LOOP["for i = 0 to list.size()"]
    GET_ITEM["kikiMap = list.get i"]
    FILTER["kktk_svc_cd equals C009"]
    CREATE_MAP["svcKeiMap = new HashMap()"]
    TG_MAP_PUT["svcKeiMap.put tg_kei_skbt_cd"]
    KKT_MAP_PUT1["svcKeiMap.put kktk_svc_kei_no"]
    KKT_MAP_PUT2["svcKeiMap.put kktk_svc_kei_stat"]
    KKT_MAP_PUT3["svcKeiMap.put pcrs_cd"]
    KKT_MAP_PUT4["svcKeiMap.put pplan_cd"]
    KKT_MAP_PUT5["svcKeiMap.put kktk_svc_cd"]
    KKT_MAP_PUT6["svcKeiMap.put kktk_sbt_cd"]
    ADD_LIST["svcKeiList.add svcKeiMap"]
    NEXT_ITER["i++"]
    RETURN["return svcKeiList"]
    EMPTY_RETURN["return empty svcKeiList"]

    START --> CHECK_NULL
    CHECK_NULL -- true --> INIT
    INIT --> INIT_MAPS
    INIT_MAPS --> LOOP
    LOOP --> GET_ITEM
    GET_ITEM --> FILTER
    FILTER -- true --> CREATE_MAP
    CREATE_MAP --> TG_MAP_PUT
    TG_MAP_PUT --> KKT_MAP_PUT1
    KKT_MAP_PUT1 --> KKT_MAP_PUT2
    KKT_MAP_PUT2 --> KKT_MAP_PUT3
    KKT_MAP_PUT3 --> KKT_MAP_PUT4
    KKT_MAP_PUT4 --> KKT_MAP_PUT5
    KKT_MAP_PUT5 --> KKT_MAP_PUT6
    KKT_MAP_PUT6 --> ADD_LIST
    ADD_LIST --> NEXT_ITER
    NEXT_ITER --> LOOP
    FILTER -- false --> NEXT_ITER
    LOOP -- end --> RETURN
    CHECK_NULL -- false --> EMPTY_RETURN
```

The method applies a single conditional branch at the top level and within the loop:

1. **Null/empty guard**: If `list` is `null` or empty, skip all processing and return an empty `svcKeiList`.
2. **Iterate over input list**: For each element (cast as `HashMap`):
   - **Filter on service code**: Extract `kktk_svc_cd` and compare it to `"C009"` (STB equipment provision service). Only records matching this code are included.
   - **Build canonical map**: For matching records, construct a new HashMap with 7 fields — one hardcoded (`tg_kei_skbt_cd = "06"`), six copied directly from the source map.
   - **Add to result**: Push the constructed map onto the result list.
3. After iteration, return the result list (may be empty if no STB records were found).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `list` | `ArrayList` | A list of equipment-provision service contract records (each element is a `HashMap` of String keys and Object values) containing fields such as `kktk_svc_cd`, `kktk_svc_kei_no`, `kktk_svc_kei_stat`, `pcrs_cd`, `pplan_cd`, and `kktk_sbt_cd`. This list is sourced from the parent `execute()` method and varies depending on the operation context: new registration list, cancellation list, restoration list, or cancel list. |

**Instance fields read:** None. This method is stateless and does not reference any instance variables.

**Constants used:**

| Constant | Value | Business Meaning |
|----------|-------|-----------------|
| `"C009"` (literal) | `"C009"` | STB (Set Top Box) equipment provision service code — identifies service records for set-top box / IPTV equipment provisioning. Only records with this service code are included in the output. |

## 4. CRUD Operations / Called Services

This method performs **no database operations, no SC (Service Component) calls, and no CBS (Callback Service) invocations**. It is a pure in-memory data transformation — a filter-and-map utility.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| N/A | (none) | — | — | This method is a pure in-memory filter and field-mapper. It creates no data, reads no entities, updates nothing, and deletes nothing. |

**No external service calls:** The method contains zero calls to SC/CBS layers. All processing is performed on in-memory `ArrayList`/`HashMap` structures.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Method: `JKKKojiWrisvcAutoAplyCC.execute()` | `JKKKojiWrisvcAutoAplyCC.execute` -> `setKktkSvc(createKikiList)` (new registration, L89) | `wrisvcAutoAplyCC.execute(handle, param, fixedText)` [C/R] Service Application Engine |
| 2 | Method: `JKKKojiWrisvcAutoAplyCC.execute()` | `JKKKojiWrisvcAutoAplyCC.execute` -> `setKktkSvc(dslKikiList)` (cancellation, L135) | `wrisvcAutoAplyCC.execute(handle, param, fixedText)` [C/R] Service Application Engine |
| 3 | Method: `JKKKojiWrisvcAutoAplyCC.execute()` | `JKKKojiWrisvcAutoAplyCC.execute` -> `setKktkSvc(kaihkKikiList)` (restoration, L178) | `wrisvcAutoAplyCC.execute(handle, param, fixedText)` [C/R] Service Application Engine |
| 4 | Method: `JKKKojiWrisvcAutoAplyCC.execute()` | `JKKKojiWrisvcAutoAplyCC.execute` -> `setKktkSvc(cancelKikiList)` (cancel, L221) | `wrisvcAutoAplyCC.execute(handle, param, fixedText)` [C/R] Service Application Engine |
| 5 | Method: `JKKKojiKikiUpdCC.execute()` | `JKKKojiKikiUpdCC.execute` -> `setKktkSvc(ekk0341pkMsg)` (equipment update, L1209, L1285, L1701) | `addProcessList` -> downstream process |

**Context details for each caller:**

- **Call #1 (L89)**: New registration flow — input is `createKikiList` (new equipment-provision service contracts). Sets `add_chge_div = "01"` (registration/creation).
- **Call #2 (L135)**: Cancellation flow — input is `dslKikiList` (equipment-provision service contracts to cancel). Sets `add_chge_div = "03"` (cancellation), `svc_dlre_cd = "01"`.
- **Call #3 (L178)**: Restoration flow — input is `kaihkKikiList` (restored equipment-provision service contracts). Sets `add_chge_div = "04"` (restoration).
- **Call #4 (L221)**: Cancel flow — input is `cancelKikiList` (cancelled equipment-provision service contracts). Sets `add_chge_div = "05"` (cancel), `svc_cancel_rsn_cd = "01"`.
- **Call #5**: `JKKKojiKikiUpdCC` calls a differently-overloaded `setKktkSvc` that takes a `CAANMsg` instead of `ArrayList` (L2463 in `JKKKojiKikiUpdCC.java`). This is a separate method signature used in equipment update operations.

## 6. Per-Branch Detail Blocks

**Block 1** — IF (null/empty guard) `(list != null && list.size() > 0)` (L445)

> If the input list is null or empty, skip all processing. The method creates an empty result list and returns it immediately after the if-block.

| # | Type | Code |
|---|------|------|
| 1 | INIT | `ArrayList svcKeiList = new ArrayList();` // Create empty result list [L444] |
| 2 | IF | `if (list != null && list.size() > 0)` // Guard: skip if no input data [L445] |
|   | SET (no-op on false) | Branch is not taken when list is null or empty — fall through to return |

**Block 2** — FOR (iterate over input list) `(i = 0; i < list.size(); i++)` (L449)

> Iterate over each element of the input list, casting to `HashMap`. For each element, check whether it is an STB service record and if so, extract a subset of fields into a canonical structure.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kikiMap = null; svcKeiMap = null;` // Initialize temp maps [L446-L447] |
| 2 | LOOP | `for (int i = 0; i < list.size(); i++)` // Iterate over all input records [L449] |
| 3 | SET | `kikiMap = (HashMap)list.get(i);` // Cast list element to HashMap [L451] |
| 4 | IF | `if ("C009".equals(kikiMap.get("kktk_svc_cd")))` // Filter: STB service code [L453] |
|   | [CONSTANT] | `"C009"` — STB (Set Top Box) equipment provision service code [L453] |

**Block 2.1** — IF (STB filter: `"C009"`) `(kktk_svc_cd equals C009)` (L453)

> When the equipment-provision service code matches STB (`"C009"`), create a new canonical HashMap and populate it with 7 fields. One field (`tg_kei_skbt_cd`) is hardcoded to `"06"` (target contract category), while the remaining 6 are copied from the source record's keys. This canonical map represents a service contract line item in the format expected by the downstream `JKKWrisvcAutoAplyCC.execute()` auto-application engine.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiMap = new HashMap();` // Create new canonical map [L455] |
| 2 | SET | `svcKeiMap.put("tg_kei_skbt_cd", "06");` // Target contract category code (固定値) [-> "06"] |
| 3 | SET | `svcKeiMap.put("kktk_svc_kei_no", (String)kikiMap.get("kktk_svc_kei_no"));` // Service contract number (機器提供サービス契約番号) |
| 4 | SET | `svcKeiMap.put("kktk_svc_kei_stat", (String)kikiMap.get("kktk_svc_kei_stat"));` // Service contract status (機器提供サービス契約ステータス) |
| 5 | SET | `svcKeiMap.put("pcrs_cd", (String)kikiMap.get("pcrs_cd"));` // Price course code (料金コースコード) |
| 6 | SET | `svcKeiMap.put("pplan_cd", (String)kikiMap.get("pplan_cd"));` // Price plan code (料金プランコード) |
| 7 | SET | `svcKeiMap.put("kktk_svc_cd", (String)kikiMap.get("kktk_svc_cd"));` // Equipment provision service code (機器提供サービスコード) |
| 8 | SET | `svcKeiMap.put("kktk_sbt_cd", (String)kikiMap.get("kktk_sbt_cd"));` // Equipment provision type code (機器提供種類コード) |
| 9 | EXEC | `svcKeiList.add(svcKeiMap);` // Add canonical map to result list [L466] |

**Block 3** — RETURN (return result) (L475)

> After the loop completes (or if the null-guard was bypassed), return the `svcKeiList`. The list may be empty if no STB records were found, or it contains the filtered and transformed service contract lines.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return svcKeiList;` // Return filtered list of STB service contract lines [L475] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kktk_svc_cd` | Field | Equipment Provision Service Code — the service type identifier for equipment-related telecom services. `"C009"` specifically identifies STB (Set Top Box) services. |
| `kktk_svc_kei_no` | Field | Service Contract Number — the unique identifier for a service contract line item (機器提供サービス契約番号). |
| `kktk_svc_kei_stat` | Field | Service Contract Status — the current status of the service contract line item (機器提供サービス契約ステータス). |
| `pcrs_cd` | Field | Price Course Code — the pricing tier/code associated with the service contract (料金コースコード). |
| `pplan_cd` | Field | Price Plan Code — the pricing plan associated with the service contract (料金プランコード). |
| `kktk_sbt_cd` | Field | Equipment Provision Type Code — classifies the type of equipment provision (機器提供種類コード). |
| `tg_kei_skbt_cd` | Field | Target Contract Category Code — a fixed code (`"06"`) indicating the target contract classification for auto-applied service contracts. |
| `C009` | Constant | STB (Set Top Box) Equipment Provision Service Code — identifies service records for set-top box / IPTV equipment provisioning. |
| `svc_kei_list` | Field | Service Contract List — a list of service contract line item maps passed to the auto-application engine. |
| `svc_kei_grp_list` | Field | Service Contract Group List — a group-level wrapper containing the service contract list for the application engine. |
| `add_chge_div` | Field | Registration/Change Classification — distinguishes the operation type: `"01"` = registration (登録), `"03"` = cancellation (解約), `"04"` = restoration (回復), `"05"` = cancel (キャンセル). |
| `svc_dlre_cd` | Field | Service Discontinuation Reason Code — the reason code for service cancellation. |
| `svc_cancel_rsn_cd` | Field | Service Cancel Reason Code — the reason code for service cancel operations. |
| STB | Acronym | Set Top Box — a set-top box device for cable TV, IPTV, or satellite TV reception. In this system, it represents equipment-provision services. |
| `kiki` | Abbreviation | Equipment (機材) — shorthand for equipment/machinery in field names. |
| `kei` | Abbreviation | Contract/Category (契約) — shorthand for service contract in field names. |
| `sbt` | Abbreviation | Type/Category (種類) — shorthand for service type in field names. |
| `pcrs` | Abbreviation | Price Course (料金コース) — shorthand for price course code. |
| `pplan` | Abbreviation | Price Plan (料金プラン) — shorthand for price plan code. |
| `tg_kei` | Abbreviation | Target Contract (対象契約) — shorthand for target contract category code. |
| `skbt` | Abbreviation | Service Contract Type (サービス契約種別) — shorthand for service contract type code. |
| `JKKKojiWrisvcAutoAplyCC` | Class | Work Order Service Auto-Apply Common Component — a common component that automates service application when a work order (工事割引き) is created, handling registration, cancellation, restoration, and cancel scenarios. |
| `JKKWrisvcAutoAplyCC` | Class | Work Order Service Auto-Apply CC — the downstream service application engine that processes the filtered service contract list returned by `setKktkSvc()`. |
| `wrisvc` | Abbreviation | Work Order Service (工事割引きサービス) — business domain referring to service operations tied to installation/work orders. |
| `auto_aply` | Abbreviation | Auto Apply (自動適用) — the automatic application of service contracts without manual intervention. |
| `koji` | Abbreviation | Work/Construction (工事) — refers to installation, maintenance, or repair work orders in the telecom operations domain. |
