# Business Logic — JKKCallWrisvcAutoAplyCC.callWrisvcAutoAply() [48 LOC]

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

## 1. Role

### JKKCallWrisvcAutoAplyCC.callWrisvcAutoAply()

This method serves as the centralized entry point for invoking **discount automatic application service processing** (割引自動適用CCの呼出) within the Fujitsu Futurity billing and telecom order management system. It orchestrates the end-to-end flow of applying automatic discounts to service contracts by delegating to the `JKKWrisvcAutoAplyCC` component, which contains the core discount computation and application logic.

The method implements a **delegation and routing pattern**: it gathers all necessary input context (user data, work area state, and the service list), assembles a structured message map through `editInMsg`, passes it to the discount CC for execution, and handles an optional **invoice simultaneous merge** (請求先同時併合) scenario. When simultaneous merging is active, the method iterates over each invoice contract number and re-invokes the discount CC individually per invoice, ensuring discounts are applied correctly in a consolidated billing context.

It acts as a **shared utility** called by multiple screens and CBS components — specifically `JKKKeiHimoUpdCC`, `JKKKeiHimoUpdShosaMaeCC`, and `JKKWrisvcAutoAplyGetSvcInfoCC` — making it a critical cross-cutting component in the service order and billing modification workflow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["callWrisvcAutoAply entry"])
    
    START --> INIT["Instantiate JKKWrisvcAutoAplyCC"]
    INIT --> FETCH_DATA["Fetch dataMap from param.getData(fixedText)"]
    FETCH_DATA --> FETCH_WORK["Fetch workMap from param.getMappingWorkArea(), extract WORK data"]
    FETCH_WORK --> FETCH_SVC["Fetch svcList from KKSV0360WORK01 / svc_kei_list"]
    FETCH_SVC --> MSG_CREATE["Create message map via editInMsg(param, dataMap, svcList, workDataMap, null)"]
    MSG_CREATE --> SET_DATA["Set paramMap into param.setData(fixedText, paramMap)"]
    SET_DATA --> EXEC1["Execute discount CC: wrisvcAutoAplyCC.execute(handle, param, fixedText)"]
    EXEC1 --> CHECK_INVOICE["Check work01Map.seiky_doji_heigo equals 'ON'"]
    
    CHECK_INVOICE -->|No| RETURN["Return param"]
    
    CHECK_INVOICE -->|Yes| GET_LIST["Get invoice contract numbers via getSeikyKeiNoList(svcList)"]
    GET_LIST --> LOOP_START{"Loop i from 0 to seikyKeiNoList.length"}
    
    LOOP_START -->|In range| EDIT_MSG["Create message map via editInMsg(param, dataMap, svcList, workDataMap, seikyKeiNoList[i])"]
    EDIT_MSG --> SET_DATA2["Set paramMap into param.setData(fixedText, paramMap)"]
    SET_DATA2 --> EXEC2["Execute discount CC: wrisvcAutoAplyCC.execute(handle, param, fixedText)"]
    EXEC2 --> LOOP_INC["Increment i"]
    LOOP_INC --> LOOP_START
    
    LOOP_START -->|Done| RETURN
```

**Processing overview:**

The method follows a linear flow with one conditional branch:

1. **Initialization** — Instantiates the core discount service component (`JKKWrisvcAutoAplyCC`).
2. **Context gathering** — Retrieves three distinct data sources:
   - `dataMap` from `param.getData(fixedText)` — user-provided / screen-passed data
   - `workDataMap` from the mapping work area under key `"WORK"` — system work context
   - `svcList` from the `KKSV0360WORK01` work area under key `"svc_kei_list"` — the list of service contracts (detail work numbers) targeted for discount application
3. **Message preparation** — Delegates to `editInMsg` to assemble the request message map for discount processing, passing `null` as the invoice number (indicating the non-consolidated / initial path).
4. **Set data** — Stores the prepared message map back into `param` under the `fixedText` key.
5. **Execute discount CC** — Calls `wrisvcAutoAplyCC.execute(handle, param, fixedText)` to run the core discount automatic application logic.
6. **Conditional invoice simultaneous merge** — If `seiky_doji_heigo` (請求先同時併合, invoice simultaneous merge) is set to `"ON"`, the method enters an iterative merge loop:
   - Retrieves the list of invoice contract numbers (`seikyKeiNoList`) via `getSeikyKeiNoList(svcList)`.
   - For each invoice contract number, re-assembles the message map (now passing the specific invoice number), updates `param`, and re-invokes the discount CC to apply discounts in the context of that merged invoice.
7. **Return** — Returns the updated `param` object to the caller.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Session management handle carrying session context such as authentication, transaction boundary, and locale settings for the billing service request. |
| 2 | `param` | `IRequestParameterReadWrite` | Model group and control map container that carries request data, work area mappings, and service component data. It holds the user data (`fixedText` key), the prepared message map, and the mapping work area used across the processing chain. |
| 3 | `fixedText` | `String` | User-defined arbitrary string that serves as a **data key** — used to store and retrieve data entries in `param` (via `getData`/`setData`). Acts as the namespace for this method's data payloads within the parameter object. |

**Instance fields / external state read:**

| Source | Usage |
|--------|-------|
| `param.getData(fixedText)` | Retrieves the user data map for the current request context. |
| `param.getMappingWorkArea()` | Retrieves the system work area map; accesses `"WORK"` key for work data. |
| `param.getData("KKSV0360WORK01")` | Retrieves the work area for screen `KKSV0360`, accesses `"svc_kei_list"` key for the service list. |
| `param.getData("KKSV0360WORK01")` then `.get("seiky_doji_heigo")` | Checks whether invoice simultaneous merge mode is active. |
| `param.setData(fixedText, paramMap)` | Writes the prepared message map back for downstream consumers. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `JKKCallWrisvcAutoAplyCC.editInMsg` | - | - | Calls `editInMsg` in `JKKCallWrisvcAutoAplyCC` — Assembles/updates the input message map for discount service processing (called twice: once with null invoice number, once per merged invoice number). |
| R | `JKKCallWrisvcAutoAplyCC.getSeikyKeiNoList` | - | - | Calls `getSeikyKeiNoList` in `JKKCallWrisvcAutoAplyCC` — Extracts and returns the list of invoice contract numbers (`seiky_kei_no`) from the service list for consolidated billing processing. |
| - | `JKKWrisvcAutoAplyCC.execute` | - | - | Calls `execute` in `JKKWrisvcAutoAplyCC` — Executes the core discount automatic application logic; called once initially and then once per invoice contract number when simultaneous merge is active. |
| - | `IRequestParameterReadWrite.getData` | - | - | Reads data from the request parameter object via `param.getData(fixedText)` and `param.getData("KKSV0360WORK01")` — retrieves user data and screen work area. |
| - | `IRequestParameterReadWrite.getMappingWorkArea` | - | - | Reads the mapping work area from the request parameter — retrieves system work context (`"WORK"` key). |
| - | `IRequestParameterReadWrite.setData` | - | - | Writes the prepared message map into the parameter object under the `fixedText` key for downstream use. |

## 5. Dependency Trace

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

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: JKKKeiHimoUpdCC | `executeWrisvcAutoAplyCallCC` -> `JKKCallWrisvcAutoAplyCC.callWrisvcAutoAply` | `wrisvcAutoAplyCC.execute [-]` |
| 2 | CBS: JKKKeiHimoUpdShosaMaeCC | `execUpd` -> `JKKCallWrisvcAutoAplyCC.callWrisvcAutoAply` | `wrisvcAutoAplyCC.execute [-]` |
| 3 | CBS: JKKWrisvcAutoAplyGetSvcInfoCC | `getSvcInfo` -> `JKKCallWrisvcAutoAplyCC.callWrisvcAutoAply` | `wrisvcAutoAplyCC.execute [-]` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `initialization` (L53)

> Instantiates the core discount service component and prepares local data structures. The method comment "割引自動適用CC" means "Discount Automatic Application CC."

| # | Type | Code |
|---|------|------|
| 1 | SET | `JKKWrisvcAutoAplyCC wrisvcAutoAplyCC = new JKKWrisvcAutoAplyCC()` // Instantiate discount CC — (割引自動適用CC) |
| 2 | SET | `HashMap<String, Object> paramMap = null` // Prepare message map variable |

**Block 2** — [SET] `context gathering` (L56-L63)

> Retrieves user data, work area context, and the service list from the parameter object. The comment "ユーザデータ情報" means "User data information."

| # | Type | Code |
|---|------|------|
| 1 | SET | `HashMap<String, Object> dataMap = (HashMap<String, Object>)param.getData(fixedText)` // Fetch user data — (ユーザデータ情報) |
| 2 | SET | `Map workMap = (Map)param.getMappingWorkArea()` // Fetch work area — (作業領域の取得) |
| 3 | SET | `HashMap<String, Object> workDataMap = (HashMap<String, Object>)workMap.get("WORK")` // Extract WORK data from work area |
| 4 | SET | `HashMap<String, Object> work01Map = (HashMap<String, Object>)param.getData("KKSV0360WORK01")` // Fetch screen KKSV0360 work area — (変更対象のリストを取得) |
| 5 | SET | `ArrayList<Object> svcList = (ArrayList<Object>)work01Map.get("svc_kei_list")` // Extract service list (detail work numbers) |

**Block 3** — [SET + CALL] `message creation and initial execution` (L65-L69)

> Assembles the request message map for the discount CC and executes it. The comment "割引自動適用CC用のメッセージを作成" means "Create message for Discount Automatic Application CC."

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap = editInMsg(param, dataMap, svcList, workDataMap, null)` // Create message map with null invoice number (non-consolidated) — (割引自動適用CC用のメッセージを作成) |
| 2 | EXEC | `param.setData(fixedText, paramMap)` // Set prepared map into param |
| 3 | CALL | `wrisvcAutoAplyCC.execute(handle, param, fixedText)` // Execute discount CC — (割引CC実行) |

**Block 4** — [IF] `conditional invoice simultaneous merge processing` (L71-L91)

> Checks whether simultaneous invoice merge mode is active (`seiky_doji_heigo` equals `"ON"`). The comment "請求先同時併合の場合" means "In case of invoice simultaneous merge." This is the sole conditional branch in the method.

| # | Type | Code |
|---|------|------|
| 1 | IF | `"ON".equals((String)work01Map.get("seiky_doji_heigo"))` // Check if invoice simultaneous merge is enabled — (請求先同時併合の場合) |

**Block 4.1** — [nested: for loop] `invoice simultaneous merge loop` (L72-L91)

> When merge mode is ON: retrieves invoice contract numbers, then iterates over each to re-execute the discount CC in a consolidated invoice context.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String[] seikyKeiNoList = getSeikyKeiNoList(svcList)` // Get invoice contract numbers — (併合対象の請求契約番号の取得) |
| 2 | FOR | `for(int i=0; i<seikyKeiNoList.length; i++)` // Iterate over each merged invoice contract number — (併合対象の請求契約番号の件数分繰り返す) |
| 3.1 | SET (inside loop) | `paramMap = editInMsg(param, dataMap, svcList, workDataMap, seikyKeiNoList[i])` // Create message map with specific invoice number — (請求契約内容変更(契約者併合)用のメッセージを作成) |
| 3.2 | EXEC (inside loop) | `param.setData(fixedText, paramMap)` // Update param with merged-invoice message map |
| 3.3 | CALL (inside loop) | `wrisvcAutoAplyCC.execute(handle, param, fixedText)` // Execute discount CC for this merged invoice — (割引CC実行) |

**Block 5** — [RETURN] (L94)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return the fully processed parameter object |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `seiky_doji_heigo` | Field | Invoice simultaneous merge flag — when set to `"ON"`, triggers consolidated billing processing where discounts are applied individually per merged invoice contract number. |
| `svc_kei_list` | Field | Service detail list — the list of service contract detail work numbers (サービス詳細作業番号) targeted for discount application. |
| `svc_kei_ucwk_no` | Field | Service detail work number — internal tracking ID for each service contract line item. |
| `fixedText` | Field | User-defined arbitrary string key — used as a namespace key for storing/retrieving data in the `IRequestParameterReadWrite` parameter object. |
| KKSV0360WORK01 | Work area | Screen-specific work area for screen KKSV0360 (discount application screen) — holds `svc_kei_list` and `seiky_doji_heigo`. |
| JKKWrisvcAutoAplyCC | Component | Core discount automatic application component — performs the actual discount computation and application logic for service contracts. |
| 割引自動適用 | Japanese term | Discount Automatic Application — the business process of automatically calculating and applying discounts to service contracts. |
| 割引CC | Japanese abbreviation | Discount Common Component — short form for `JKKWrisvcAutoAplyCC`. |
| 請求先同時併合 | Japanese term | Invoice Simultaneous Merge — the process of consolidating multiple billing addresses/contracts into a single invoice; requires re-applying discounts per merged invoice. |
| 契約者併合 | Japanese term | Contract Holder Merge — a subtype of invoice merge where multiple contract holders are consolidated under a single billing entity. |
| セッションマネージャー | Japanese term | Session Manager — the session management system; `SessionHandle` carries authentication and context. |
| モデルグループ | Japanese term | Model Group — the data model structure carried by `IRequestParameterReadWrite`. |
| param.getData / param.setData | API | Methods on `IRequestParameterReadWrite` for reading and writing keyed data entries in the request parameter container. |
| param.getMappingWorkArea | API | Method that returns the system work area map used for inter-component data exchange. |
