# Business Logic — JKKPrcSimulationCC.searchWribSvc() [77 LOC]

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

## 1. Role

### JKKPrcSimulationCC.searchWribSvc()

This method constructs the complete list of discount services (割引サービス) eligible for automatic application during price simulation. It serves as the central aggregation point that gathers discount service codes from multiple sources and merges them into a single result set, ensuring that the caller receives every service applicable to the current customer and contract context.

The method handles three distinct service acquisition paths: (1) a base set of all discount services via the standard service interface, (2) instant discount (即割) and family pack (ファミリーパック) specific discount services queried through a separate interface when those features are enabled, and (3) individually specified discount service codes provided by the caller that must be resolved and added. Before merging, it removes contract-excluded entries (`delCpInf`) to prevent ineligible services from appearing in results.

The design follows a **routing and merge pattern**: the method dispatches to different mapper queries based on feature flags, then iterates through each source to deduplicate results before returning the final merged list. It acts as a shared utility called by `chkMainWribSvc()` during price simulation — an internal common component rather than a screen entry point.

When conditional branches activate, each handles a specific discount dimension: the instant discount branch filters for service type code `"31"` (即割 / instant discount), while the family pack branch specifically searches for service code `"W00000006"` (the family pack discount service) and adds it at most once. The user-specified codes branch resolves each explicitly requested discount service and ensures it is included unless already present.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["searchWribSvc(commonInfo)"])
    
    START --> STEP1["getMapper.callWribSvcIcrnShokai(commonInfo, FUNC_1)"]
    STEP1 --> STEP2["delCpInf(wrisvcList)"]
    STEP2 --> STEP3{"isSokuwariON || isFamilyPackON"}
    
    STEP3 -->|true| STEP4["getMapper.callWribSvcIcrnShokai2(commonInfo, FUNC_1)"]
    STEP4 --> STEP5{"isSokuwariON?"}
    STEP3 -->|false| STEP13{"commonInfo has WRIB_SVC_CD_LIST?"}
    
    STEP5 -->|true| STEP6["for wribSvcMap in sokuwariFamilyList"]
    STEP6 --> STEP7["wribTypeCd = wribSvcMap.get(WRIB_TYPE_CD)"]
    STEP7 --> STEP8["wribSvcCd = wribSvcMap.get(WRIB_SVC_CD)"]
    STEP8 --> STEP9{"SOKUWARI == wribTypeCd && !isContains(wrisvcList, wribSvcCd)"}
    STEP9 -->|true| STEP10["wrisvcList.add(wribSvcMap)"]
    STEP10 --> STEP6
    STEP9 -->|false| STEP6
    STEP5 -->|false| STEP11{"isFamilyPackON?"}
    
    STEP11 -->|true| STEP12["for wribSvcMap in sokuwariFamilyList"]
    STEP12 --> STEP12A["wribSvcCd = wribSvcMap.get(WRIB_SVC_CD)"]
    STEP12A --> STEP12B{"FAMILYPACK_WRIB_SVC == wribSvcCd && !isContains(wrisvcList, wribSvcCd)"}
    STEP12B -->|true| STEP12C["wrisvcList.add(wribSvcMap); break"]
    STEP12C --> STEP13
    STEP12B -->|false| STEP12
    STEP11 -->|false| STEP13
    
    STEP13 -->|true| STEP14["for wribSvcCdMap in wribSvcCdList"]
    STEP14 --> STEP15["wribSvcCd = wribSvcCdMap.get(WRIB_SVC_CD)"]
    STEP15 --> STEP16["getMapper.callWribSvcUniqShokai(commonInfo, wribSvcCd, FUNC_2)"]
    STEP16 --> STEP17{"wribSvcMap != null && !isContains(wrisvcList, wribSvcCd)"}
    STEP17 -->|true| STEP18["wrisvcList.add(wribSvcMap)"]
    STEP18 --> STEP14
    STEP17 -->|false| STEP14
    STEP13 -->|false| END_NODE["return wrisvcList"]
    STEP14 --> END_NODE
    
    END_NODE(["Return wrisvcList"])
```

**Processing flow:**

1. **Base service query** — Calls `callWribSvcIcrnShokai` via the mapper with function code `"1"` to fetch all standard discount services eligible for automatic application.
2. **Contract exclusion cleanup** — Removes contract-related entries that should be excluded from the discount service list via `delCpInf`.
3. **Feature-gated secondary query** — If either instant discount (即割) or family pack (ファミリーパック) is enabled (via `isSokuwariON` or `isFamilyPackON`), queries a secondary discount service list via `callWribSvcIcrnShokai2` with function code `"1"`.
4. **Instant discount merge** — If instant discount is enabled, iterates through the secondary list and adds entries whose `WRIB_TYPE_CD` equals `"31"` (SOKUWARI / instant discount), provided they are not already in the result set.
5. **Family pack merge** — If family pack is enabled, iterates through the secondary list and adds the entry with service code `"W00000006"` (FAMILYPACK_WRIB_SVC), then breaks immediately after the first match.
6. **User-specified code resolution** — Retrieves the user-provided discount service code list from `commonInfo` and resolves each code via `callWribSvcUniqShokai` (function code `"2"`), adding any non-null results not already present.
7. **Return** — Returns the fully merged discount service list.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `commonInfo` | `HashMap<String, Object>` | The central input context map carrying all price simulation parameters. Contains feature enablement flags (`SOKUWARI_ON` / `FAMILYPACK_ON`), the list of user-specified discount service codes under key `WRIB_SVC_CD_LIST` (containing entries with `WRIB_SVC_CD` sub-fields), and other context used by mapper queries. This map drives which conditional branches activate and determines the final contents of the returned service list. |

**Instance fields and external state read by this method:**

| Source | Description |
|--------|-------------|
| `JKKPrcSimulationCCMapper` (via `getMapper()`) | The mapper instance used to invoke service interface methods. Each call to `getMapper()` returns the mapper to execute database / service queries. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKPrcSimulationCC.getMapper` | JKKPrcSimulationCC | - | Returns the mapper instance to access service interface methods |
| R | `JKKPrcSimulationCCMapper.callWribSvcIcrnShokai` | JKKPrcSimulationCCMapper | - | Queries the standard discount service list (all eligible discount services for automatic application) with function code `"1"` |
| D | `JKKPrcSimulationCC.delCpInf` | JKKPrcSimulationCC | - | Removes contract-excluded service entries from the discount service list |
| R | `JKKPrcSimulationCC.isSokuwariON` | JKKPrcSimulationCC | - | Checks whether instant discount (即割) is enabled for the current simulation |
| R | `JKKPrcSimulationCC.isFamilyPackON` | JKKPrcSimulationCC | - | Checks whether family pack (ファミリーパック) discount is enabled for the current simulation |
| R | `JKKPrcSimulationCCMapper.callWribSvcIcrnShokai2` | JKKPrcSimulationCCMapper | - | Queries the secondary discount service list (instant discount / family pack services) with function code `"1"` |
| R | `JKKPrcSimulationCC.isContains` | JKKPrcSimulationCC | - | Checks whether a given discount service code already exists in the result list (deduplication check) |
| R | `JKKPrcSimulationCCMapper.callWribSvcUniqShokai` | JKKPrcSimulationCCMapper | - | Resolves a single uniquely specified discount service code, returning its full info with function code `"2"` |
| - | `JKKPrcSimulationCC.printlnEjbLog` | JKKPrcSimulationCC | - | Debug logging — prints the intermediate and final discount service lists |

**How to classify:**

- **R (Read)**: All `callWribSvc*` mapper methods are read operations — they query discount service data from the service interface layer.
- **D (Delete)**: `delCpInf` removes (deletes) entries from the in-memory list that represent contract exclusions.
- **Utility calls**: `isContains`, `isSokuwariON`, `isFamilyPackON`, `getMapper`, `printlnEjbLog` are helper/utility methods that support processing but do not perform direct CRUD on data.

## 5. Dependency Trace

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

Direct callers found: 1 method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `chkMainWribSvc` (JKKPrcSimulationCC) | `chkMainWribSvc(commonInfo)` -> `searchWribSvc(commonInfo)` | `callWribSvcIcrnShokai [R]`, `delCpInf [D]`, `callWribSvcIcrnShokai2 [R]`, `callWribSvcUniqShokai [R]` |

**Call chain detail:**
- `chkMainWribSvc()` (line 475) is a private method within `JKKPrcSimulationCC` that builds the discount service eligibility list for price simulation. It first groups services via `makeSvcGrpList()`, then calls `searchWribSvc()` to gather the full set of applicable discount service codes, and finally iterates the result to match against establishment condition groups.

**Terminal operations from this method** (all downstream calls executed by `searchWribSvc`): `printlnEjbLog [-]`, `isContains [-]`, `callWribSvcUniqShokai [-]`, `getMapper [R]`, `isFamilyPackON [-]`, `isSokuwariON [-]`, `delCpInf [-]`, `callWribSvcIcrnShokai [-]`, `callWribSvcIcrnShokai2 [-]`.

No screen or batch entry points were found within 8 hops of this method. It is an internal common component method called exclusively by `chkMainWribSvc`, which itself participates in the broader price simulation flow (`KKSV0553` price simulation screen context).

## 6. Per-Branch Detail Blocks

**Block 1** — [EXEC] Base discount service acquisition (L1234)

> Acquires the complete list of all standard discount services eligible for automatic application, then removes contract-excluded entries.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `wrisvcList = getMapper().callWribSvcIcrnShokai(commonInfo, FUNC_1)` // Fetches all eligible discount services; FUNC_1 = "1" (機能コード) [-> FUNC_1 = "1"] |
| 2 | EXEC | `printlnEjbLog("割引サービスリスト【" + wrisvcList + "】")` // Debug log of intermediate result |
| 3 | EXEC | `delCpInf(wrisvcList)` // Removes contract-excluded service entries [v4.00.01 add] |

**Block 2** — [IF] Feature-gated secondary query: isSokuwariON or isFamilyPackON (L1247)

> If either instant discount or family pack discount is enabled, queries the secondary discount service list containing those specific services.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sokuwariFamilyList = null` // Holds secondary query result |
| 2 | COND | `isSokuwariON(commonInfo) \|\| isFamilyPackON(commonInfo)` // SOKUWARI_ON = "1" (即割指定), FAMILYPACK_ON = "1" (ファミリーパック指定) |

**Block 2.1** — [EXEC] Secondary service query (L1251) — nested inside Block 2, only when condition is true

| # | Type | Code |
|---|------|------|
| 1 | CALL | `sokuwariFamilyList = getMapper().callWribSvcIcrnShokai2(commonInfo, FUNC_1)` // Queries instant discount / family pack specific discount services; FUNC_1 = "1" |

**Block 3** — [IF] Merge instant discount services (L1257)

> If instant discount (即割) is enabled, iterates through the secondary list and adds entries whose service type code matches the instant discount code `"31"`, excluding duplicates.

| # | Type | Code |
|---|------|------|
| 1 | COND | `isSokuwariON(commonInfo)` // SOKUWARI_ON = "1" (即割指定) |

**Block 3.1** — [FOR] Iterate secondary list (L1259)

| # | Type | Code |
|---|------|------|
| 1 | ITER | `for (HashMap<String, Object> wribSvcMap : sokuwariFamilyList)` |

**Block 3.1.1** — [EXEC] Extract type and service codes (L1261–1262)

| # | Type | Code |
|---|------|------|
| 1 | SET | `wribTypeCd = (String)wribSvcMap.get(KKSV0553_KKSV0553OP_WORK_WRISVC.WRIB_TYPE_CD)` // Discount service type code |
| 2 | SET | `wribSvcCd = (String)wribSvcMap.get(KKSV0553_KKSV0553OP_WORK_WRIB_SVC_CD_INFO.WRIB_SVC_CD)` // Discount service code [-> WRIB_SVC_CD = "wrib_svc_cd"] |

**Block 3.1.2** — [IF] Filter instant discount type and deduplicate (L1263)

> Adds the entry only if it is of instant discount type and not already present in the result set.

| # | Type | Code |
|---|------|------|
| 1 | COND | `SOKUWARI.equals(wribTypeCd)` // SOKUWARI = "31" (即割) [-> SOKUWARI = "31"] |
| 2 | COND | `!isContains(wrisvcList, wribSvcCd)` // Deduplication check |

**Block 3.1.2.1** — [EXEC] Add matching instant discount entry (L1264)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `wrisvcList.add(wribSvcMap)` |

**Block 4** — [IF] Merge family pack discount service (L1270)

> If family pack discount is enabled, searches the secondary list for the family pack service code `"W00000006"` and adds it at most once (break on first match).

| # | Type | Code |
|---|------|------|
| 1 | COND | `isFamilyPackON(commonInfo)` // FAMILYPACK_ON = "1" (ファミリーパック指定) |

**Block 4.1** — [FOR] Iterate secondary list (L1272)

| # | Type | Code |
|---|------|------|
| 1 | ITER | `for (HashMap<String, Object> wribSvcMap : sokuwariFamilyList)` |

**Block 4.1.1** — [EXEC] Extract service code (L1274)

| # | Type | Code |
|---|------|------|
| 1 | SET | `wribSvcCd = (String)wribSvcMap.get(KKSV0553_KKSV0553OP_WORK_WRIB_SVC_CD_INFO.WRIB_SVC_CD)` // Discount service code [-> WRIB_SVC_CD = "wrib_svc_cd"] |

**Block 4.1.2** — [IF] Match family pack service code and deduplicate (L1275)

> Only the exact family pack service code is accepted, and the loop breaks after adding it (one-time add).

| # | Type | Code |
|---|------|------|
| 1 | COND | `FAMILYPACK_WRIB_SVC.equals(wribSvcCd)` // FAMILYPACK_WRIB_SVC = "W00000006" (ファミリーパック割引サービスコード) [-> FAMILYPACK_WRIB_SVC = "W00000006"] |
| 2 | COND | `!isContains(wrisvcList, wribSvcCd)` // Deduplication check |

**Block 4.1.2.1** — [EXEC] Add family pack entry and break (L1276)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `wrisvcList.add(wribSvcMap)` |
| 2 | EXEC | `break` // Stop after finding the first match |

**Block 5** — [EXEC] Acquire user-specified discount service codes (L1284–1292)

> Retrieves the list of discount service codes explicitly provided by the user (entered data discount codes), resolves each one via the mapper, and adds any valid non-duplicate results to the final list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wribSvcCdList = (ArrayList<HashMap<String, Object>>)commonInfo.get(KKSV0553_KKSV0553OP_WORK.WRIB_SVC_CD_LIST)` // User-specified discount service code list [-> WRIB_SVC_CD_LIST = "wrib_svc_cd_list"] |
| 2 | ITER | `for (HashMap<String, Object> wribSvcCdMap : wribSvcCdList)` |

**Block 5.1** — [EXEC] Extract service code and resolve (L1286–1287)

| # | Type | Code |
|---|------|------|
| 1 | SET | `wribSvcCd = (String)wribSvcCdMap.get(KKSV0553_KKSV0553OP_WORK_WRIB_SVC_CD_INFO.WRIB_SVC_CD)` // Extract service code from map entry [-> WRIB_SVC_CD = "wrib_svc_cd"] |
| 2 | CALL | `wribSvcMap = getMapper().callWribSvcUniqShokai(commonInfo, wribSvcCd, FUNC_2)` // Resolves the single unique discount service; FUNC_2 = "2" (機能コード) [-> FUNC_2 = "2"] |

**Block 5.2** — [IF] Validate result and deduplicate (L1288)

> Adds the resolved service entry only if the mapper returned a non-null result and the code is not already in the list.

| # | Type | Code |
|---|------|------|
| 1 | COND | `wribSvcMap != null` |
| 2 | COND | `!isContains(wrisvcList, wribSvcCd)` // Deduplication check |

**Block 5.2.1** — [EXEC] Add resolved user-specified service (L1289)

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `wrisvcList.add(wribSvcMap)` |

**Block 6** — [EXEC] Final logging and return (L1294–1296)

> Logs the complete final discount service list (including user-entered codes) and returns it to the caller.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `printlnEjbLog("自動適用対象割引サービスリスト（入力データ割引サービスコード含む）【" + wrisvcList + "】")` // Debug log of final merged result |
| 2 | RETURN | `return wrisvcList` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `wrisvcList` | Field | Discount service list — the aggregated list of all discount services eligible for automatic application during price simulation |
| `sokuwariFamilyList` | Field | Secondary discount service list — the result set for instant discount (即割) and family pack (ファミリーパック) specific services |
| `wribSvcCdList` | Field | User-specified discount service code list — discount services explicitly entered by the user that must be included regardless of automatic eligibility |
| `WRIB_TYPE_CD` | Field | Discount service type code — classifies the type/category of a discount service (e.g., "31" for instant discount) |
| `WRIB_SVC_CD` | Field | Discount service code — unique identifier for a discount service (e.g., "W00000006" for family pack) |
| `WRIB_SVC_CD_LIST` | Field | Key in commonInfo map — holds the user-provided list of discount service codes to include |
| SOKUWARI | Constant | "31" — Instant discount (即割) service type code. Represents a time-limited promotional discount applied immediately at contract. |
| SOKUWARI_ON | Constant | "1" — Instant discount enablement flag. When set, triggers querying and merging of instant discount services. |
| FAMILYPACK_ON | Constant | "1" — Family pack enablement flag. When set, triggers querying and merging of family pack discount services. |
| FAMILYPACK_WRIB_SVC | Constant | "W00000006" — Family pack discount service code. The unique code identifying the family pack discount service. |
| FUNC_1 | Constant | "1" — Function code passed to mapper queries. Indicates standard/primary discount service query mode. |
| FUNC_2 | Constant | "2" — Function code passed to mapper queries. Indicates unique/single service resolution mode. |
| DEL_CP_INF | Constant | Contract exclusion — removes services that should not apply to contracted/committed services |
| `callWribSvcIcrnShokai` | Method | Mapper method to query all standard discount services eligible for automatic application |
| `callWribSvcIcrnShokai2` | Method | Mapper method to query secondary discount services (instant discount / family pack) |
| `callWribSvcUniqShokai` | Method | Mapper method to resolve a single uniquely specified discount service code to its full details |
| delCpInf | Method | Removes contract-excluded entries from the discount service list |
| isContains | Method | Checks whether a service code already exists in a list (deduplication utility) |
| isSokuwariON | Method | Checks whether the instant discount feature is enabled for the current context |
| isFamilyPackON | Method | Checks whether the family pack discount feature is enabled for the current context |
| 割引サービス | Business term | Discount Service — a pricing reduction applied to customer contracts (e.g., instant discount, family pack, referral discount) |
| 即割 | Business term | Instant Discount (Sokuwari) — a promotional discount applied immediately upon contract activation |
| ファミリーパック | Business term | Family Pack — a bundled discount service for multiple lines within the same household |
| 自動適用 | Business term | Automatic Application — the process of identifying and applying eligible discount services without manual selection |
| JKKPrcSimulationCC | Class | Price Simulation Common Component — a shared business logic component for price calculation and simulation in the K-Opticom customer base system |
| KKSV0553 | Screen | Price simulation screen — the UI screen context where this discount service search method is used |
