# Business Logic — JKKStbUcwkEoTvKktkSvcKeiCC.execWrisvcAutoAply() [70 LOC]

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

## 1. Role

### JKKStbUcwkEoTvKktkSvcKeiCC.execWrisvcAutoAply()

This method serves as a **discount application coordination routine** for the "eo光TV" (eo Light TV) service contract line item registration flow. Specifically, it retrieves device registration data that was previously stored by a machine registration common component, assembles a structured discount request payload containing service contract details (service type, pricing code, plan code, system ID, and order reference numbers), and then delegates to `JKKWrisvcAutoAplyCC.execute()` to perform the automatic discount application logic.

The method implements a **preparation-and-delegation** pattern: it does not contain business rules for discount calculation itself. Instead, it gathers the necessary context from a shared `HashMap` (`kikiCreateCCMap`), builds the `workWrisvcAutoAplyDataKey` parameter set with all required fields (addition/change division, system ID, application serial number, application type code, modification division, function code, and a structured service contract group list), and hands control to the dedicated discount application CC (`JKKWrisvcAutoAplyCC`).

It is a **shared utility component** called exclusively by `stbUcwkEoTvKktkSvcKei()` during the STB (Set-Top Box) eoTV service contract registration process. The method only executes when a service contract detail work list (`svc_kei_ucwk_list`) exists and contains at least one element — otherwise it returns silently without performing any operation.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execWrisvcAutoAply(handle, param, inMap, mskmNo)"])

    START --> RETRIEVE["Retrieve kikiCreateCCMap from param.getData(kikiAddCC)"]
    RETRIEVE --> GET_CREATE["Get create_list from kikiCreateCCMap"]
    GET_CREATE --> GET_KKTK["Call getKktkSvcKeiData createList"]
    GET_KKTK --> GET_UCWK_LIST["Get svc_kei_ucwk_list from kikiCreateCCMap"]
    GET_UCWK_LIST --> CHECK_LIST{ucwkList != null
and size greater than 0}
    CHECK_LIST -->|True| EXTRACT_U["Extract first element as ucwkMap"]
    EXTRACT_U --> SET_KEY["Set workWrisvcAutoAplyDataKey = WrisvcAutoAplyCC"]
    SET_KEY --> SET_DATA["param.setData workWrisvcAutoAplyDataKey, new HashMap"]
    SET_DATA --> GET_OUT["Get outMap from param.getData"]
    GET_OUT --> PUT_ADD["outMap.put add_chge_div, 16"]
    PUT_ADD --> PUT_SYSID["outMap.put sysid, kktkSvcKeiMap SYSID"]
    PUT_SYSID --> PUT_MSKM["outMap.put mskm_no, mskmNo"]
    PUT_MSKM --> PUT_MSKM_SBT["outMap.put mskm_sbt_cd, 00012"]
    PUT_MSKM_SBT --> PUT_IDO["outMap.put ido_div, inMap idv_div"]
    PUT_IDO --> PUT_FUNC["outMap.put func_code, inMap func_code"]
    PUT_FUNC --> INIT_ARRAY["Initialize workSvcKeiArray and workSvcKeiMap"]
    INIT_ARRAY --> PUT_GRP["workSvcKeiMap.put grp_div, 00"]
    PUT_GRP --> INIT_SVC_LIST["Initialize workSvcKeiList and workSvcKeiData"]
    INIT_SVC_LIST --> PUT_TG["workSvcKeiData.put tg_kei_skbt_cd, 03"]
    PUT_TG --> PUT_SVC_KEI["workSvcKeiData.put svc_kei_ucwk_no, ucwkMap SVC_KEI_UCWK_NO"]
    PUT_SVC_KEI --> PUT_SVC_STAT["workSvcKeiData.put svc_kei_ucwk_stat, ucwkMap SVC_KEI_UCWK_STAT"]
    PUT_SVC_STAT --> PUT_PCRS["workSvcKeiData.put pcrs_cd, ucwkMap PCS_CD"]
    PUT_PCRS --> PUT_PPLAN["workSvcKeiData.put pplan_cd, ucwkMap PPLAN_CD"]
    PUT_PPLAN --> ADD_TO_LIST["workSvcKeiList.add workSvcKeiData"]
    ADD_TO_LIST --> PUT_SVC_KEY["workSvcKeiMap.put svc_kei_list, workSvcKeiList"]
    PUT_SVC_KEY --> ADD_ARRAY["workSvcKeiArray.add workSvcKeiMap"]
    ADD_ARRAY --> PUT_GRP_LIST["outMap.put svc_kei_grp_list, workSvcKeiArray"]
    PUT_GRP_LIST --> EXEC_CC["Create JKKWrisvcAutoAplyCC
Call execute handle, param, workWrisvcAutoAplyDataKey"]
    EXEC_CC --> REMOVE_DATA["param.removeData workWrisvcAutoAplyDataKey"]
    REMOVE_DATA --> END_NODE(["Return"])
    CHECK_LIST -->|False| END_NODE
```

**Processing summary:**
1. Retrieves device registration data from the request parameter map using the key `kikiAddCC`.
2. Extracts the `create_list` and fetches service contract mapping data via `getKktkSvcKeiData()`.
3. Extracts the `svc_kei_ucwk_list` (service contract detail work list).
4. **Conditional check**: If the work list is non-null and has at least one entry, proceed with discount setup; otherwise skip.
5. Extracts the first work item and builds a structured payload under the key `WrisvcAutoAplyCC`:
   - Sets addition/change division to `"16"` (Discount Addition/Change).
   - Populates system ID from the service contract mapping.
   - Sets the application serial number (`mskmNo`) and application type code `"00012"` (eo Light TV service contract).
   - Carries through modification division and function code from `inMap`.
   - Assembles a service contract group list containing the target service contract details (contract ID code `"03"`, work contract number, status, pricing code, and plan code).
6. Instantiates `JKKWrisvcAutoAplyCC` and delegates to its `execute()` method with the assembled payload.
7. Cleans up by removing the intermediate data key from the request parameter map.

**CRITICAL Constant Resolutions:**

| Constant | Value | Business Meaning |
|----------|-------|------------------|
| `workWrisvcAutoAplyDataKey` | `"WrisvcAutoAplyCC"` | Data key for discount application payload in request parameters |
| `add_chge_div` | `"16"` | Addition/Change Division — code 16 = Discount Application (Addition/Change) |
| `mskm_sbt_cd` | `"00012"` | Application Type Code — eo Light TV service contract |
| `grp_div` | `"00"` | Group Division — primary service contract group |
| `tg_kei_skbt_cd` | `"03"` | Target Contract Type Code — eo Light TV service contract type |
| `EKK0341A010CBSMsg1List.SYSID` | `"sysid"` | System ID field name — enterprise/customer system identifier |
| `EKK0161A010CBSMsg1List.SVC_KEI_UCWK_NO` | `"svc_kei_ucwk_no"` | Service Contract Detail Work Number field |
| `EKK0161A010CBSMsg1List.SVC_KEI_UCWK_STAT` | `"svc_kei_ucwk_stat"` | Service Contract Detail Status field |
| `EKK0161A010CBSMsg1List.PCRS_CD` | `"pcrs_cd"` | Pricing Code field |
| `EKK0161A010CBSMsg1List.PPLAN_CD` | `"pplan_cd"` | Plan Code field |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle used for transactional operations and context management during the discount application process. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter container holding the full request-scoped data map. Contains device registration data (`kikiAddCC` key) and receives the assembled discount payload (`WrisvcAutoAplyCC` key) before delegating to the discount CC. |
| 3 | `inMap` | `HashMap` | Input map carrying contextual data from the calling method. Provides `ido_div` (modification division code — indicates whether this is a new addition, change, or cancellation) and `func_code` (function code — identifies the screen or business function invoking this routine). |
| 4 | `mskmNo` | `String` | Application serial number (申込番号) — the unique sequential order number assigned to the customer's service contract application. Used to correlate discount application with the originating order. |

**External state / instance fields read:** None. This method is fully stateless with respect to instance fields — all data flows through method parameters and the `kikiCreateCCMap` retrieved from `param`.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKStbUcwkEoTvKktkSvcKeiCC.getKktkSvcKeiData` | (same CC) | `create_list` in-memory data | Reads device registration data and builds service contract mapping from the create list |
| S | `JBSbatAKKshkmRsltInfoTukiawsday.setData` | - | - | Calls `setData` in `JBSbatAKKshkmRsltInfoTukiawsday` (via delegated CC) |
| S | `JBSbatAKKshkmRsltInfoTukiaws.setData` | - | - | Calls `setData` in `JBSbatAKKshkmRsltInfoTukiaws` (via delegated CC) |
| S | `JBSbatAKKshkmRsltInfoTukiawsRealSkh.setData` | - | - | Calls `setData` in `JBSbatAKKshkmRsltInfoTukiawsRealSkh` (via delegated CC) |
| S | `JBSbatAKKshkmRsltInfTkCvsNCnsl.setData` | - | - | Calls `setData` in `JBSbatAKKshkmRsltInfTkCvsNCnsl` (via delegated CC) |
| R | `JBSbatDKNyukaFinAdd.getData` | - | - | Calls `getData` in `JBSbatDKNyukaFinAdd` (via delegated CC) |
| S | `JBSbatKKGetCTITelno.setData` | - | - | Calls `setData` in `JBSbatKKGetCTITelno` (via delegated CC) |
| R | `JFUeoTelOpTransferCC.getData` | - | - | Calls `getData` in `JFUeoTelOpTransferCC` (via delegated CC) |
| R | `JFUTransferCC.getData` | - | - | Calls `getData` in `JFUTransferCC` (via delegated CC) |
| R | `JFUTransferListToListCC.getData` | - | - | Calls `getData` in `JFUTransferListToListCC` (via delegated CC) |
| C/S | `JKKWrisvcAutoAplyCC.execute` | EKK3131A010CBS | Service contract / discount tables | Executes automatic discount application — creates/modifies discount entries in service contract detail tables |
| R | `KKW12701SFLogic.getData` | - | - | Calls `getData` in `KKW12701SFLogic` (via delegated CC) |

**Operation descriptions:**
- **R (Read):** Data retrieval operations performed by the delegated `JKKWrisvcAutoAplyCC.execute()` method. These read service contract details, pricing data, transfer information, and finalization data from the database.
- **C (Create):** The `JKKWrisvcAutoAplyCC.execute()` method creates new discount application records in the service contract detail tables when `add_chge_div = "16"`.
- **S (Set):** `setData` calls are internal data structure operations (mapping field names to values) within the CC layer, not direct DB operations.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JKKStbUcwkEoTvKktkSvcKeiCC.stbUcwkEoTvKktkSvcKei()` | `stbUcwkEoTvKktkSvcKei()` → `execWrisvcAutoAply()` | `execute [C] Service Contract Detail (Discount) tables` |

**Description:**
This method is a private helper called exclusively by `stbUcwkEoTvKktkSvcKei()` within the same class. The calling method processes STB (Set-Top Box) eoTV service contract registration and invokes `execWrisvcAutoAply()` to handle the automatic discount application portion after device registration data has been prepared. No public screen entry points call this method directly — it is an internal coordination step in the broader service contract registration workflow.

**Terminal operations reached from this method:** `execute` [C/S], `getData` [R], `getData` [R], `getData` [R], `getData` [R], `getData` [R], `setData` [S], `setData` [S], `setData` [S], `setData` [S], `setData` [S], `getKktkSvcKeiData` [R], `getData` [R], `getData` [R], `getData` [R], `getData` [R], `getData` [R]

## 6. Per-Branch Detail Blocks

**Block 1** — [ASSIGN] `kikiCreateCCMap` retrieval (L1051)

Retrieves the device registration map from the request parameter. This map was previously populated by the machine registration common component and contains both the `create_list` and `svc_kei_ucwk_list`.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `HashMap<String, Object> kikiCreateCCMap = (HashMap<String, Object>)param.getData("kikiAddCC")` | // 機器登録CCで登録したデータを取得 (Retrieve data registered by machine registration CC) [-> param.getData("kikiAddCC")] |

**Block 2** — [ASSIGN] `create_list` extraction (L1053)

Extracts the list of device creation entries from the registration map. This list feeds into `getKktkSvcKeiData()` to build the service contract mapping data.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `ArrayList<Map<String, Object>> createList = (ArrayList<Map<String, Object>>)kikiCreateCCMap.get("create_list")` | // extract create_list from kikiCreateCCMap |
| 2 | SET | `HashMap<String, Object> kktkSvcKeiMap = getKktkSvcKeiData(createList)` | // Build service contract mapping from create list [-> CALL getKktkSvcKeiData] |

**Block 3** — [ASSIGN] `svc_kei_ucwk_list` extraction (L1055)

Extracts the service contract detail work list. This list contains the work item(s) that will have discount auto-application performed.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | EXEC | `ArrayList<Map<String, Object>> kikiAddCCUcwkList = (ArrayList<Map<String, Object>>)kikiCreateCCMap.get("svc_kei_ucwk_list")` | // Extract service contract work list from registration map |
| 2 | SET | `HashMap<String, Object> ucwkMap = null` | // Initialize work map variable |

**Block 4** — [IF] `kikiAddCCUcwkList` null/empty check (L1058)

Conditions: `kikiAddCCUcwkList != null && kikiAddCCUcwkList.size() > 0`

> If the service contract work list is non-null and contains at least one entry, proceed with discount application setup. Otherwise, the method returns silently (no discount is applied).

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | IF | `if(kikiAddCCUcwkList != null && kikiAddCCUcwkList.size() > 0)` | // サービス契約内訳リストがnullでなく且つ、サイズが1件以上ある場合割引CCを実行 (If service contract detail list is not null and has 1 or more entries, execute discount CC) |

**Block 4.1** — [ELSE-IF] — N/A (single IF with implicit ELSE of no-op)

**Block 4.1** — [THEN branch] Discount payload construction (L1060–L1111)

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `ucwkMap = (HashMap<String, Object>)kikiAddCCUcwkList.get(0)` | // Use the first work item as the discount target |
| 2 | SET | `String workWrisvcAutoAplyDataKey = "WrisvcAutoAplyCC"` | // パラメータ設定 (Set parameter key) — data key for discount CC payload |
| 3 | EXEC | `param.setData(workWrisvcAutoAplyDataKey, new HashMap<String, Object>())` | // Initialize discount payload map in request parameters |
| 4 | SET | `HashMap<String, Object> outMap = (HashMap<String, Object>)param.getData(workWrisvcAutoAplyDataKey)` | // Get the newly created outMap reference |
| 5 | SET | `outMap.put("add_chge_div", "16")` | // 登録／変更区分 (Addition/Change Division) — "16" = Discount Application |
| 6 | SET | `outMap.put("sysid", kktkSvcKeiMap.get(EKK0341A010CBSMsg1List.SYSID))` | // システムID (System ID) — enterprise/customer identifier from service contract mapping |
| 7 | SET | `outMap.put("mskm_no", mskmNo)` | // 申込番号 (Application Serial Number) — order number passed as parameter |
| 8 | SET | `outMap.put("mskm_sbt_cd", "00012")` | // 申込種別コード (Application Type Code) — "00012" = eo Light TV service contract |
| 9 | SET | `outMap.put("ido_div", (String)inMap.get("ido_div"))` | // 異動区分 (Modification Division) — from inMap context |
| 10 | SET | `outMap.put("func_code", (String)inMap.get("func_code"))` | // 機能コード (Function Code) — from inMap context |
| 11 | SET | `ArrayList<HashMap<String, Object>> workSvcKeiArray = new ArrayList<>()` | // サービス契約グループリスト (Service Contract Group List) — outer container |
| 12 | SET | `HashMap<String, Object> workSvcKeiMap = new HashMap<>()` | // Inner map for group-level data |
| 13 | SET | `workSvcKeiMap.put("grp_div", "00")` | // グループ区分 (Group Division) — "00" = primary group |
| 14 | SET | `ArrayList<HashMap<String, Object>> workSvcKeiList = new ArrayList<>()` | // サービス契約リスト (Service Contract List) — container for individual contracts |
| 15 | SET | `HashMap<String, Object> workSvcKeiData = new HashMap<>()` | // Data map for a single service contract detail |
| 16 | SET | `workSvcKeiData.put("tg_kei_skbt_cd", "03")` | // 対象契約識別コード (Target Contract Type Code) — "03" = eo Light TV |
| 17 | SET | `workSvcKeiData.put("svc_kei_ucwk_no", ucwkMap.get(EKK0161A010CBSMsg1List.SVC_KEI_UCWK_NO))` | // サービス契約内訳番号 (Service Contract Detail Number) |
| 18 | SET | `workSvcKeiData.put("svc_kei_ucwk_stat", ucwkMap.get(EKK0161A010CBSMsg1List.SVC_KEI_UCWK_STAT))` | // サービス契約内訳ステータス (Service Contract Detail Status) |
| 19 | SET | `workSvcKeiData.put("pcrs_cd", ucwkMap.get(EKK0161A010CBSMsg1List.PCRS_CD))` | // 料金コースコード (Pricing Course Code) |
| 20 | SET | `workSvcKeiData.put("pplan_cd", ucwkMap.get(EKK0161A010CBSMsg1List.PPLAN_CD))` | // 料金プランコード (Pricing Plan Code) |
| 21 | EXEC | `workSvcKeiList.add(workSvcKeiData)` | // Add the single service contract data to the list |
| 22 | SET | `workSvcKeiMap.put("svc_kei_list", workSvcKeiList)` | // Attach the contract list to the group map |
| 23 | SET | `workSvcKeiArray.add(workSvcKeiMap)` | // Attach the group map to the outer array |
| 24 | SET | `outMap.put("svc_kei_grp_list", workSvcKeiArray)` | // Assign the complete service contract group list to the payload |
| 25 | EXEC | `JKKWrisvcAutoAplyCC wrisvcAutoAplyCC = new JKKWrisvcAutoAplyCC()` | // 割引サービス自動適用CC実行処理 (Execute discount service auto-application CC) |
| 26 | CALL | `wrisvcAutoAplyCC.execute(handle, param, workWrisvcAutoAplyDataKey)` | // Delegate to the dedicated discount application CC |
| 27 | EXEC | `param.removeData(workWrisvcAutoAplyDataKey)` | // Cleanup — remove the intermediate data key from request parameters |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kikiAddCC` | Field/Key | Device Registration Common Component — key in request parameters holding device registration data (`create_list`, `svc_kei_ucwk_list`) |
| `create_list` | Field/Key | Device creation list — list of devices registered through the machine registration CC |
| `svc_kei_ucwk_list` | Field/Key | Service Contract Detail Work List — list of service contract detail items pending discount application |
| `add_chge_div` | Field/Key | Addition/Change Division (登録／変更区分) — classification code for whether the operation is a new addition, modification, or deletion. Value `"16"` = Discount Application |
| `sysid` | Field/Key | System ID (システムID) — unique identifier for the enterprise or customer system in the telecom billing context |
| `mskm_no` | Field/Key | Application Serial Number (申込番号) — sequential order number assigned to a customer's service contract application |
| `mskm_sbt_cd` | Field/Key | Application Type Code (申込種別コード) — classifies the type of service application. Value `"00012"` = eo Light TV service contract |
| `ido_div` | Field/Key | Modification Division (異動区分) — indicates whether the operation is a new addition, change, or cancellation of a service contract |
| `func_code` | Field/Key | Function Code (機能コード) — identifies the calling screen or business function |
| `grp_div` | Field/Key | Group Division (グループ区分) — classifies the service contract group level. Value `"00"` = primary group |
| `tg_kei_skbt_cd` | Field/Key | Target Contract Type Code (対象契約識別コード) — identifies the type of service contract. Value `"03"` = eo Light TV service contract |
| `svc_kei_ucwk_no` | Field/Key | Service Contract Detail Number (サービス契約内訳番号) — internal tracking ID for a specific service contract line item |
| `svc_kei_ucwk_stat` | Field/Key | Service Contract Detail Status (サービス契約内訳ステータス) — current processing status of the service contract detail |
| `pcrs_cd` | Field/Key | Pricing Course Code (料金コースコード) — identifies the pricing tier/plan for the service |
| `pplan_cd` | Field/Key | Pricing Plan Code (料金プランコード) — identifies the specific pricing plan for the service |
| `WrisvcAutoAplyCC` | Key | Data key for the discount service auto-application payload stored in request parameters |
| eo Light TV (eo光テレビ) | Business term | Fujitsu/K-Opticom's IPTV service bundled with fiber-optic internet, providing television content over IP |
| STB (Set-Top Box) | Acronym | Hardware device that receives and decodes IPTV signals for television output |
| CC | Acronym | Common Component — a shared business logic component class in the K-Opticom system architecture |
| SC | Acronym | Service Component — a service layer class handling specific business operations, often tied to a CBS (Call-Based Service) |
| CBS | Acronym | Call-Based Service — the data access/service component that performs database operations |
| JKKWrisvcAutoAplyCC | Class | Discount Service Auto-Application Common Component — dedicated component that processes automatic discount application logic for service contracts |
| SOD | Acronym | Service Order Data — order fulfillment entity in the telecom domain |
| JBCbat* | Class prefix | Batch result info entity classes — used for storing batch processing result information during service contract operations |
