# Business Logic — JKKKisnUwHmdkAddCC.execWrisvcAutoAply() [71 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKKisnUwHmdkAddCC` |
| Layer | CC / Common Component (Custom business logic component in the `com.fujitsu.futurity.bp.custom.common` package) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKKisnUwHmdkAddCC.execWrisvcAutoAply()

This method orchestrates the **discount service auto-apply** process (割引サービス自動適用CC実行処理). Its business purpose is to assemble a structured payload of service contract and discount parameter data, then delegate to `JKKWrisvcAutoAplyCC.execute()` to automatically calculate and apply applicable service discounts to a customer's contract line items.

The method follows a **data builder + delegation** pattern: it creates a temporary work map keyed under the request parameter context, populates it with identifying metadata (function code, system ID, application division, application number, customer classification, modification distinction), and builds a nested service contract group list containing all relevant contract line items and their associated pricing details. For each discount entry in the `wari_cc_list` array, it extracts the six key pricing attributes (service contract number, status, service code, price group code, price course code, and price plan code) and attaches them to the payload.

The add/change division is hardcoded to `"15"`, indicating that this auto-apply operation applies to a new registration context (no differentiation between add and change is made). After delegating to the auto-apply engine, the method cleans up the temporary work data from the parameter map.

This method serves as a **shared utility** called from higher-level business logic (specifically `execKisnHeigo()`, the customer integration processing). It is not a screen entry point itself but a bridge between customer-facing integration processing and the discount auto-apply engine.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execWrisvcAutoAply"])
    SETUP_WORK_MAP["Set work key / create empty HashMap / setData"]
    GET_WRISVC_MAP["Get wrisvcMap from param"]
    SET_FUNC_CODE["Put func_code from ccMap.FUNC_CODE_KEY"]
    SET_SYSID["Put sysid from ccMap"]
    SET_ADD_CHGE_DIV["Put add_chge_div = 15"]
    SET_MSKM_NO["Put mskm_no (application number)"]
    SET_MSKM_SBT_CD["Put mskm_sbt_cd (application type code)"]
    SET_IDO_DIV["Put ido_div (modification distinction)"]
    INIT_SVC_GRP["Init svcKeiGrpArray / svcKeiGrpMap / svcKeiList / svcKeiMap"]
    SET_GRP_DIV["Set grp_div = 00"]
    SET_TG_SKBT_CD["Set tg_kei_skbt_cd = 01"]
    GET_WARIBIKI_LIST["Get wari_cc_list from ccMap"]
    CHECK_WARIBIKI_SIZE["wari_cc_list.size > 0 ?"]
    LOOP_START["for i = 0 to size"]
    SET_SVC_FIELDS["Set svc_kei_no, svc_kei_stat, svc_cd, prc_grp_cd, pcrs_cd, pplan_cd"]
    ADD_TO_LIST["svcKeiList.add(svcKeiMap)"]
    NEXT_I["i++"]
    FINISH_LIST["svcKeiGrpMap.put svc_kei_list / svcKeiGrpArray.add / wrisvcMap.put"]
    EXEC_AUTO_APPLY["new JKKWrisvcAutoAplyCC / execute(handle, param, workWrisvcAutoAplyDataKey)"]
    REMOVE_WORK["param.removeData(workWrisvcAutoAplyDataKey)"]
    END_NODE(["Return void"])

    START --> SETUP_WORK_MAP
    SETUP_WORK_MAP --> GET_WRISVC_MAP
    GET_WRISVC_MAP --> SET_FUNC_CODE
    SET_FUNC_CODE --> SET_SYSID
    SET_SYSID --> SET_ADD_CHGE_DIV
    SET_ADD_CHGE_DIV --> SET_MSKM_NO
    SET_MSKM_NO --> SET_MSKM_SBT_CD
    SET_MSKM_SBT_CD --> SET_IDO_DIV
    SET_IDO_DIV --> INIT_SVC_GRP
    INIT_SVC_GRP --> SET_GRP_DIV
    SET_GRP_DIV --> SET_TG_SKBT_CD
    SET_TG_SKBT_CD --> GET_WARIBIKI_LIST
    GET_WARIBIKI_LIST --> CHECK_WARIBIKI_SIZE
    CHECK_WARIBIKI_SIZE -->|yes| LOOP_START
    CHECK_WARIBIKI_SIZE -->|no| FINISH_LIST
    LOOP_START --> SET_SVC_FIELDS
    SET_SVC_FIELDS --> ADD_TO_LIST
    ADD_TO_LIST --> NEXT_I
    NEXT_I --> CHECK_WARIBIKI_SIZE
    FINISH_LIST --> EXEC_AUTO_APPLY
    EXEC_AUTO_APPLY --> REMOVE_WORK
    REMOVE_WORK --> END_NODE
```

**Processing summary:**
The method builds a hierarchical data structure in three stages:

1. **Header metadata setup** — Creates a work map and populates it with top-level identifiers: function code (from `JCMConstants.FUNC_CODE_KEY`), system ID, a fixed application division code `"15"`, the application number (`mskmNo`), application type code, and modification distinction code.

2. **Service contract group assembly** — Builds a nested list structure. A group division is set to `"00"`, a target contract category is set to `"01"`, and the discount parameter list (`wari_cc_list` from `ccMap`) is iterated to extract per-contract pricing details. Each iteration adds a service contract entry with 6 pricing fields to the service list.

3. **Delegation and cleanup** — The completed payload is registered in the work map, the `JKKWrisvcAutoAplyCC` engine is invoked with the work key, and the temporary work data is removed.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle for the current transaction context. Used by the delegated `JKKWrisvcAutoAplyCC.execute()` method to access the database and manage transaction boundaries. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter map that serves as a shared context object between processing stages. Used to store and retrieve the temporary work map via the key `"WrisvcAutoAplyCC"`. |
| 3 | `ccMap` | `HashMap<String, Object>` | Common context map carrying pre-computed business data into this method. Contains: `func_code` (function code via `JCMConstants.FUNC_CODE_KEY`), `sysid` (system ID), `mskm_sbt_cd` (application type code), `ido_div` (modification distinction), and `wari_cc_list` (the discount parameter list to iterate). |
| 4 | `mskmNo` | `String` | Application number (申請番号) — the unique identifier for the current application/request being processed. Used to tag the auto-apply operation with its originating application. |

**External state / instance fields read:**
- None. This method is fully self-contained and does not read any instance fields of `JKKKisnUwHmdkAddCC`.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `param.setData` | - | - | Sets the temporary work map (key: `"WrisvcAutoAplyCC"`) into the request parameter context |
| R | `param.getData` | - | - | Retrieves the work map from the request parameter context |
| R | `ccMap.get(JCMConstants.FUNC_CODE_KEY)` | - | - | Reads the function code from the common context map |
| R | `ccMap.get("sysid")` | - | - | Reads the system ID from the common context map |
| R | `ccMap.get("mskm_sbt_cd")` | - | - | Reads the application type code from the common context map |
| R | `ccMap.get("ido_div")` | - | - | Reads the modification distinction code from the common context map |
| R | `ccMap.get("wari_cc_list")` | - | - | Reads the discount parameter list (array of HashMap entries) from the common context map |
| R | `param.getData` (inside JKKWrisvcAutoAplyCC) | - | - | JKKWrisvcAutoAplyCC reads the work map to process discount auto-application |
| - | `JKKWrisvcAutoAplyCC.execute` | - | - | Delegates to the discount auto-apply engine which processes discount calculations and applies them to service contracts |
| - | `param.removeData` | - | - | Cleans up the temporary work map from the request parameter context after processing |

**Note on SC Codes and DB Tables:**
The `JKKWrisvcAutoAplyCC.execute` method is the core business engine that performs the actual discount auto-application logic (database reads, discount calculations, and contract updates). Its specific SC Codes, CBS codes, and target DB tables are defined within `JKKWrisvcAutoAplyCC` itself, not in this method. This method is a preparation and delegation layer — it builds and passes the payload but does not directly interact with database entities.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `execute` [-], `setData` [-], `getData` [-], `getData` [-], `getData` [-], `getData` [-], `removeData` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: `JKKKisnUwHmdkAddCC.execKisnHeigo` | `execKisnHeigo` -> `execWrisvcAutoAply(handle, param, ccMap, mskmNo)` | `JKKWrisvcAutoAplyCC.execute [-]` (discount auto-apply engine) |

**Call chain detail:**
- `execKisnHeigo` (customer integration processing) calls `execWrisvcAutoAply` to apply discounts to service contracts as part of the broader customer integration flow.
- This method does not connect to any screen (`KKSV*`) or batch entry point within 8 hops — it is a pure business component called from another CC/CBS method.

## 6. Per-Branch Detail Blocks

**Block 1** — [PROCESS] Work map initialization (L2227)

> Creates the temporary work map under the request parameter context and retrieves it for population.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workWrisvcAutoAplyDataKey = "WrisvcAutoAplyCC"` // Local constant for work map key |
| 2 | EXEC | `param.setData(workWrisvcAutoAplyDataKey, new HashMap<String, Object>())` // Initialize empty work map in request context |
| 3 | SET | `wrisvcMap = (HashMap<String, Object>) param.getData(workWrisvcAutoAplyDataKey)` // Retrieve the work map reference |

**Block 2** — [PROCESS] Header metadata population (L2230–L2238)

> Populates the work map with top-level identifying information for the auto-apply operation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wrisvcMap.put("func_code", ccMap.get(JCMConstants.FUNC_CODE_KEY))` // Function code from common context [-> FUNC_CODE_KEY resolved from JCMConstants] |
| 2 | SET | `wrisvcMap.put("sysid", (String) ccMap.get("sysid"))` // System ID identifying the source system |
| 3 | SET | `wrisvcMap.put("add_chge_div", "15")` // Fixed: application division = "15" (application type code, no add/change differentiation) |
| 4 | SET | `wrisvcMap.put("mskm_no", mskmNo)` // Application number passed as parameter |
| 5 | SET | `wrisvcMap.put("mskm_sbt_cd", (String) ccMap.get("mskm_sbt_cd"))` // Application type code from common context |
| 6 | SET | `wrisvcMap.put("ido_div", (String) ccMap.get("ido_div"))` // Modification distinction code from common context |

**Block 3** — [PROCESS] Service contract group list initialization (L2241–L2252)

> Builds the nested data structure for service contract group and lists. Sets group division and target contract category.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiGrpArray = new ArrayList<HashMap<String, Object>>()` // Service contract group list container |
| 2 | SET | `svcKeiGrpMap = new HashMap<String, Object>()` // Single group map |
| 3 | SET | `svcKeiGrpMap.put("grp_div", "00")` // Fixed: group division = "00" (single group) |
| 4 | SET | `svcKeiList = new ArrayList<HashMap<String, Object>>()` // Service contract entries list |
| 5 | SET | `svcKeiMap = new HashMap<String, Object>()` // Single service contract entry map |
| 6 | SET | `svcKeiMap.put("tg_kei_skbt_cd", "01")` // Fixed: target contract category = "01" (all contracts) |
| 7 | SET | `waribikiParamList = (ArrayList) ccMap.get("wari_cc_list")` // Discount parameter list from common context |
| 8 | SET | `childMap = new HashMap<String, Object>()` // Temporary map for iterating discount entries |

**Block 4** — [FOR] Discount parameter iteration loop (L2254–L2273)

> Iterates over the discount parameter list (`wari_cc_list`) and extracts pricing details for each discount entry. Each iteration populates the service contract entry map with 6 fields and adds it to the service list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `childMap = waribikiParamList.get(i)` // Get the i-th discount entry |
| 2 | SET | `svcKeiMap.put("svc_kei_no", (String) childMap.get("svc_kei_no"))` // Service contract number |
| 3 | SET | `svcKeiMap.put("svc_kei_stat", (String) childMap.get("svc_kei_stat"))` // Service contract status |
| 4 | SET | `svcKeiMap.put("svc_cd", (String) childMap.get("svc_cd"))` // Service code |
| 5 | SET | `svcKeiMap.put("prc_grp_cd", (String) childMap.get("prc_grp_cd"))` // Price group code |
| 6 | SET | `svcKeiMap.put("pcrs_cd", (String) childMap.get("pcrs_cd"))` // Price course code |
| 7 | SET | `svcKeiMap.put("pplan_cd", (String) childMap.get("pplan_cd"))` // Price plan code |
| 8 | EXEC | `svcKeiList.add(svcKeiMap)` // Add to service list |

**Block 5** — [PROCESS] Finalize work map and delegate (L2275–L2283)

> Assembles the completed payload, invokes the discount auto-apply engine, and cleans up.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiGrpMap.put("svc_kei_list", svcKeiList)` // Attach service list to group map |
| 2 | EXEC | `svcKeiGrpArray.add(svcKeiGrpMap)` // Add group to group list |
| 3 | SET | `wrisvcMap.put("svc_kei_grp_list", svcKeiGrpArray)` // Attach group list to work map |
| 4 | CALL | `JKKWrisvcAutoAplyCC wrisvcAutoAplyCC = new JKKWrisvcAutoAplyCC()` // Instantiate auto-apply engine |
| 5 | EXEC | `wrisvcAutoAplyCC.execute(handle, param, workWrisvcAutoAplyDataKey)` // Delegate to discount auto-apply engine |
| 6 | EXEC | `param.removeData(workWrisvcAutoAplyDataKey)` // Clean up temporary work data |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `wrisvc` | Abbreviation | Web Service — refers to web-service-based service contract operations in the system |
| `AutoAply` | Abbreviation | Auto-Apply — automatic application of discounts/benefits to service contracts |
| `mskm_no` | Field | Application number (申請番号) — unique identifier for a service application/request |
| `mskm_sbt_cd` | Field | Application type code (申請種類コード) — classifies the type of application being processed |
| `ido_div` | Field | Modification distinction (異動区分) — indicates whether this is an add, change, or cancel operation |
| `add_chge_div` | Field | Add/change division (登録/変更区分) — distinguishes between new registration and modification. Value `"15"` is the fixed value for auto-apply operations |
| `svc_kei_no` | Field | Service contract number (サービス契約番号) — unique identifier for a service contract line item |
| `svc_kei_stat` | Field | Service contract status (サービス契約ステータス) — current lifecycle state of the service contract |
| `svc_cd` | Field | Service code (サービスコード) — identifies the type of telecom service (e.g., FTTH, mobile, broadband) |
| `prc_grp_cd` | Field | Price group code (料金グループコード) — groups pricing plans for tariff and discount calculations |
| `pcrs_cd` | Field | Price course code (料金コースコード) — identifies the specific pricing course/tier |
| `pplan_cd` | Field | Price plan code (料金プランコード) — identifies the specific price plan/product bundle |
| `tg_kei_skbt_cd` | Field | Target contract category code (対象契約識別コード) — filter for which contract types to include. Value `"01"` selects all relevant contracts |
| `grp_div` | Field | Group division (グループ区分) — organizes service contracts into processing groups. Value `"00"` indicates a single/default group |
| `wari_cc_list` | Field | Discount CC list (割引CCリスト) — array of discount parameter entries, each containing service contract pricing details |
| `func_code` | Field | Function code (機能コード) — identifies the business function being executed, retrieved from `JCMConstants.FUNC_CODE_KEY` |
| `JCMConstants` | Class | Common constants class — central repository for system-wide constant definitions including function codes |
| `JCMConstants.FUNC_CODE_KEY` | Constant | Key for retrieving the function code from the common context map. Used to identify the calling business function |
| `SessionHandle` | Type | Database session handle — manages the transaction context and database connection for the current request |
| `IRequestParameterReadWrite` | Type | Request parameter interface — shared key-value context object passed across processing layers for data exchange |
| `JKKWrisvcAutoAplyCC` | Class | Discount auto-apply common component — the core engine that processes discount calculations and applies them to service contracts |
| CC | Abbreviation | Common Component — a reusable business logic component in the Fujitsu Futurity framework |
| `execKisnHeigo` | Method | Customer integration processing (顧客統合処理) — the higher-level method that calls `execWrisvcAutoAply` as part of customer data consolidation |
