# Business Logic — JKKPrcSimulationCC.chkMainWribSvc() [131 LOC]

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

## 1. Role

### JKKPrcSimulationCC.chkMainWribSvc()

This method implements the **discount service eligibility filtering** business operation within the price simulation framework. It receives a set of user-selected services and determines which ones qualify for discount (割引) pricing based on a multi-layered condition evaluation: (1) application format validation, (2) discount condition code matching against service groups, (3) individual service code validation, (4) target contracted service count verification, and (5) simultaneous availability (併用可否) compatibility checking. The method follows a **dispatch/filter routing pattern** — it iterates over all candidate discount services retrieved from the system, applies a cascading series of validation checks organized around service groupings, and ultimately returns only those services that pass every condition and are simultaneously applicable. As a shared utility called by `execute()`, it serves as the core filtering engine for discount service simulation, enabling downstream price calculation components to work exclusively with the subset of eligible, compatible discount services.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["chkMainWribSvc(commonInfo)"])
    STEP1["makeSvcGrpList<br/>Create discount service group list"]
    STEP2["searchWribSvc<br/>Fetch all discount services"]
    LOOP1_START{"Has next discount service?"}
    NEXT1["Get next wribSvcMap"]
    STEP3["chkGetAplyInfo<br/>Validate application info"]
    STEP4{"chkGetAplyInfo pass?"}
    STEP5["getSvcGrpList<br/>Get matching service groups"]
    STEP6["searchWrisvcTgSvc<br/>Search target services"]
    LOOP2_START{"Has next svcGrpInfo?"}
    NEXT2["Get next svcGrpInfoMap"]
    LOOP3_START{"Has next wribTgSvc?"}
    NEXT3["Get next wribTgSvcMap"]
    LOOP4_START{"Has next svcInfo?"}
    NEXT4["Get next svcInfoMap"]
    STEP7["chkVariSvcCd<br/>Validate service codes"]
    STEP8["chkTrgtKeiSvcCnt<br/>Check target service count"]
    STEP9{"chkTrgtKeiSvcCnt pass?"}
    STEP10["wribMatchList.clear"]
    STEP11["Put TRGT_KEI_SVC_KEI_CNT"]
    STEP12["chkAplyJokenCd<br/>Check application condition"]
    STEP13{"chkAplyJokenCd pass?"}
    STEP14["Add matchWribSvcGrpMap<br/>to matchWribSvcGrpList"]
    STEP15{"matchWribSvcGrpList empty?"}
    STEP16["printlnEjbLog<br/>Service code check log"]
    STEP17["dataCopy<br/>Copy discount service info"]
    STEP18["Put MATCH_WRIB_SVC_GRP_LIST"]
    STEP19["Add matchWribSvcMap<br/>to matchWribSvcList"]
    STEP20["jdgDojiAplyKh<br/>Check simultaneous availability"]
    END(["Return dojiOKList"])

    START --> STEP1
    START --> STEP2
    STEP2 --> LOOP1_START
    LOOP1_START -->|true| NEXT1
    LOOP1_START -->|false| STEP20
    NEXT1 --> STEP3
    STEP3 --> STEP4
    STEP4 -->|false| LOOP1_START
    STEP4 -->|true| STEP5
    STEP5 --> STEP6
    STEP6 --> LOOP2_START
    LOOP2_START -->|true| NEXT2
    LOOP2_START -->|false| STEP15
    NEXT2 --> LOOP3_START
    LOOP3_START -->|true| NEXT3
    LOOP3_START -->|false| LOOP2_START
    NEXT3 --> LOOP4_START
    LOOP4_START -->|true| NEXT4
    LOOP4_START -->|false| STEP8
    NEXT4 --> STEP7
    STEP7 --> LOOP4_START
    STEP7 --> STEP8
    STEP8 --> STEP9
    STEP9 -->|false| STEP10
    STEP9 -->|true| STEP11
    STEP10 --> STEP11
    STEP11 --> LOOP3_START
    STEP12 --> STEP13
    STEP13 -->|true| STEP14
    STEP13 -->|false| LOOP2_START
    STEP14 --> LOOP2_START
    STEP15 -->|true| STEP16
    STEP15 -->|false| STEP17
    STEP16 --> LOOP1_START
    STEP17 --> STEP18
    STEP18 --> STEP19
    STEP19 --> LOOP1_START
    STEP20 --> END
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `commonInfo` | `HashMap<String, Object>` | The central data carrier holding all screen input parameters and session state. Contains the user's service selection context including service codes, condition codes (e.g., WRIB_ADD_JOKEN_CD — discount registration condition codes), and application metadata needed for eligibility validation. It is shared across multiple called methods as the single source of truth for the current simulation session. |

**Instance / external fields read:**
| Field | Type | Business Description |
|-------|------|---------------------|
| `SVC_LIST` | `String` (private static) | Key `"svc_list"` used to access the nested list of service info maps within a service group. |
| `GRP_NUMBER` | `String` (private static) | Key `"grp_number"` used to identify the service group number in matched group maps. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `searchWribSvc` | (internal) | Discount service registry | Reads all candidate discount services to evaluate eligibility |
| R | `getSvcGrpList` | (internal) | In-memory service group list | Reads matching service groups filtered by discount condition code |
| R | `searchWrisvcTgSvc` | (internal) | Target service data | Reads target discount-eligible services for the current discount service |
| R | `getSerial` | (internal) | - | Generates serial identifiers for logging and indexing purposes |
| R | `getSvcGrpList` (caller) | (internal) | In-memory data | Retrieves the service group list built by `makeSvcGrpList` |
| C | `makeSvcGrpList` | (internal) | In-memory structure | Creates the service group list for discount condition categorization |
| C | `jdgDojiAplyKh` | (internal) | Simultaneous availability rules | Creates filtered list of services compatible for simultaneous application |
| - | `chkGetAplyInfo` | (internal) | Application validation | Validates application format and required fields for the discount service |
| - | `chkVariSvcCd` | (internal) | Service code rules | Validates individual service codes against business rules |
| - | `chkTrgtKeiSvcCnt` | (internal) | Target count rules | Checks if the count of matched target services meets the required threshold |
| - | `chkAplyJokenCd` | (internal) | Application condition rules | Validates whether the discount service's application conditions are satisfied |
| - | `dataCopy` | (internal) | - | Copies field values from source map to destination map |
| - | `printlnEjbLog` | (internal) | - | Logs service code validation status to the EJB log |

## 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: `jdgDojiAplyKh` [-], `dataCopy` [-], `printlnEjbLog` [-], `chkAplyJokenCd` [-], `chkTrgtKeiSvcCnt` [-], `chkVariSvcCd` [-], `searchWrisvcTgSvc` [R], `getSerial` [R], `getSvcGrpList` [R], `chkGetAplyInfo` [-], `makeSvcGrpList` [-], `searchWribSvc` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JKKPrcSimulationCC.execute()` | `execute()` -> `chkMainWribSvc` | `jdgDojiAplyKh [-]`, `dataCopy [-]`, `printlnEjbLog [-]`, `chkAplyJokenCd [-]`, `chkTrgtKeiSvcCnt [-]`, `chkVariSvcCd [-]`, `searchWrisvcTgSvc [R]`, `getSerial [R]`, `getSvcGrpList [R]`, `chkGetAplyInfo [-]`, `makeSvcGrpList [C]`, `searchWribSvc [R]` |

## 6. Per-Branch Detail Blocks

**Block 1** — INIT `(none)` (L469)
> Initializes the result list that will hold all discount services passing the filtering criteria.

| # | Type | Code |
|---|------|------|
| 1 | SET | `matchWribSvcList = new ArrayList<>()` // 割引サービス成立条件合致リスト — Discount service matching results list |

**Block 2** — INIT `(none)` (L473)
> Builds the service group list by grouping services according to discount condition codes. The original comment reads: 割引登録条件コードのグループ分け — Grouping by discount registration condition code.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `allSvcGrpList = makeSvcGrpList(commonInfo)` // 割引登録条件コードのグループ分け — Grouping by discount registration condition code |

**Block 3** — INIT `(none)` (L478)
> Retrieves all candidate discount services from the data layer.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `wribSvcList = searchWribSvc(commonInfo)` // 割引サービスリスト作成 — Create discount service list |

**Block 4** — FOR-EACH `(ite_wribSvcList hasNext)` (L482)
> Outer loop iterating over each candidate discount service. The original comment reads: 適用対象の割引サービスをを取得 — Get the discount services applicable to the application.

| # | Type | Code |
|---|------|------|
| 1 | SET | `index1 = 0` // Loop index counter |
| 2 | SET | `ite_wribSvcList = wribSvcList.iterator()` // Iterator over discount services |
| 3 | WHILE | `ite_wribSvcList.hasNext()` // 適用対象の割引サービスをを取得 — Get discount services for the application |
| | > **Block 4.1** — SET `(inside loop start)` (L484) |

| # | Type | Code |
|---|------|------|
| 1 | SET | `index1++` // Increment counter |
| 2 | SET | `matchWribSvcGrpList = new ArrayList<>()` // 成立条件合致サービスグループリスト — Matching condition service group list |
| 3 | SET | `wribSvcMap = ite_wribSvcList.next()` // Get current discount service map |
| 4 | SET | `wribSvcCd = wribSvcMap.get(KKSV0553_KKSV0553OP_WORK_WRISVC.WRIB_SVC_CD)` // 割引サービスコード — Discount service code (key: `"wrib_svc_cd"`) |

**Block 5** — IF `(!chkGetAplyInfo(...))` (L492)
> Validates the application info for the current discount service. If validation fails, the service is skipped (continue to next). The original comment reads: 申請形態コードチェック — Application form code check.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `result = chkGetAplyInfo(commonInfo, wribSvcMap, getSerial(index1, wribSvcList.size()))` // 申請形態コードチェック — Application form code check |
| 2 | IF | `!result` |
| | > **Block 5.1** — EXEC `(inside if)` (L494) |

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `continue` // Skip to next discount service — apply to next iteration |

**Block 6** — INIT `(none)` (L501)
> Retrieves the service groups associated with the current discount service's discount condition code. The original comment reads: 割引サービス対象サービス条件チェック — Discount service target service condition check, then 対象サービスグループ取得 — Get target service group.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `svcGrpList = getSvcGrpList(allSvcGrpList, wribSvcMap.get(WRIB_ADD_JOKEN_CD))` // 割引サービス対象サービス条件チェック — Discount service target service condition check; WRIB_ADD_JOKEN_CD = `"wrib_add_joken_cd"` (割引登録条件コード — Discount registration condition code) |
| 2 | CALL | `wribTgSvcList = searchWrisvcTgSvc(wribSvcCd, getSerial(index1, svcGrpList.size()))` // 対象サービス取得 — Get target services |

**Block 7** — FOR-EACH `(ite_svcGrpList hasNext)` (L506)
> Iterates over each service group. The original comment reads: 対象サービスグループの処理 — Process target service group.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ite_svcGrpList = svcGrpList.iterator()` // 対象サービスグループの処理 — Process target service group |
| 2 | WHILE | `ite_svcGrpList.hasNext()` |
| | > **Block 7.1** — SET `(inside loop start)` (L508) |

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcGrpInfoMap = ite_svcGrpList.next()` // 対象サービスグループの情報 — Target service group info |

**Block 8** — FOR-EACH `(ite_wribTgSvcList hasNext)` (L512)
> Nested loop iterating over each target discount service within the current service group. The original comment reads: 対象サービスグループの処理 — Process target service group (same comment as parent block).

| # | Type | Code |
|---|------|------|
| 1 | SET | `ite_wribTgSvcList = wribTgSvcList.iterator()` // 対象サービスグループの処理 — Process target service group |
| 2 | WHILE | `ite_wribTgSvcList.hasNext()` |
| | > **Block 8.1** — SET `(inside loop start)` (L514) |

| # | Type | Code |
|---|------|------|
| 1 | SET | `wribTgSvcMap = ite_wribTgSvcList.next()` // 対象サービス — Target service |
| 2 | SET | `wribMatchList = new ArrayList<>()` // 割引サービス対象サービス合致サービスリスト — Discount service target service matching list |

**Block 9** — SET `(none)` (L521)
> Retrieves the list of service info entries from the current service group using the `SVC_LIST` key (`"svc_list"`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcList = svcGrpInfoMap.get(SVC_LIST)` // B 対象サービスリスト — B: Target service list; `SVC_LIST = "svc_list"` |

**Block 10** — FOR-EACH `(ite_svcList hasNext)` (L525)
> Innermost loop iterating over each service info within the target service list. The original comment reads: 各種サービスコードチェック — Various service code check.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ite_svcList = svcList.iterator()` // 各種サービスコードチェック — Various service code check |
| 2 | WHILE | `ite_svcList.hasNext()` |
| | > **Block 10.1** — SET `(inside loop start)` (L527) |

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcInfoMap = ite_svcList.next()` // 各種サービスコードチェック — Various service code check |

**Block 11** — IF `chkVariSvcCd` (L532)
> Validates various service codes for the current service info against the target service. Results are accumulated into `wribMatchList`. The original comment reads: 各種サービスコードチェック — Various service code check.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `chkVariSvcCd(wribTgSvcMap, svcInfoMap, wribMatchList)` // 各種サービスコードチェック — Various service code check |

**Block 12** — INIT `(none)` (L538)
> After checking all services in the group, verifies the count of matching target services meets the required threshold. The original comment reads: 割引サービス対象サービス合致サービス数チェック — Discount service target service matching service count check.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `pass = JKKWrisvcDchskmCommonUtil.chkTrgtKeiSvcCnt(wribTgSvcMap, wribMatchList.size())` // 割引サービス対象サービス合致サービス数チェック — Discount service target service matching service count check |
| 2 | IF | `!pass` |
| | > **Block 12.1** — EXEC `(inside if)` (L540) |

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `wribMatchList.clear()` // Clear the match list if count check fails |
| 2 | EXEC | `wribTgSvcMap.put(JKKWrisvcDchskmCommonUtil.TRGT_KEI_SVC_KEI_CNT, wribMatchList.size())` // Set TRGT_KEI_SVC_KEI_CNT = `"trgt_kei_svc_kei_cnt"` (対象契約サービス契約数 — Target contracted service count) |

**Block 13** — IF `(chkAplyJokenCd)` (L547)
> Checks whether the discount service's application condition codes are satisfied by the current target services. The original comment reads: 適用条件コードチェック — Application condition code check.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `result = JKKWrisvcDchskmCommonUtil.chkAplyJokenCd(wribSvcMap, wribTgSvcList)` // 適用条件コードチェック — Application condition code check |
| 2 | IF | `result == true` |
| | > **Block 13.1** — SET `(inside if)` (L549) |

> Creates a group-level match map and adds it to the `matchWribSvcGrpList`. The original comment reads: 成立条件合致サービスグループリストに追加 — Add to matching condition service group list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `matchWribSvcGrpMap = new HashMap<>()` // 成立条件合致サービスグループ情報作成 — Create matching condition service group info |
| 2 | SET | `matchWribSvcGrpMap.put(GRP_NUMBER, svcGrpInfoMap.get(GRP_NUMBER))` // 成立条件合致サービスグループ情報作成 — Create matching condition service group info; `GRP_NUMBER = "grp_number"` |
| 3 | SET | `matchWribSvcGrpMap.put(CHK_WRIB_SVC_TGT_SVC_LIST, wribTgSvcList)` // 成立条件合致サービスグループ情報作成 — Create matching condition service group info; `CHK_WRIB_SVC_TGT_SVC_LIST = "chk_wrib_svc_tgt_svc_list"` |
| 4 | EXEC | `matchWribSvcGrpList.add(matchWribSvcGrpMap)` // 成立条件合致サービスグループリストに追加 — Add to matching condition service group list |

**Block 14** — IF `(matchWribSvcGrpList.isEmpty())` (L562)
> After evaluating all service groups for the current discount service, determines whether any groups matched. The original comment reads: 併用可否チェック用にリストを作成 — Create list for simultaneous availability check.

| # | Type | Code |
|---|------|------|
| 1 | IF | `matchWribSvcGrpList.isEmpty()` // 併用可否チェック用にリストを作成 — Create list for simultaneous availability check |
| | > **Block 14.1** — EXEC `(inside else-branch: has matches)` (L567) |

> A discount service has passed all conditions. Copy its info into the final result list. The original comment reads: 割引サービス成立条件合致情報 — Discount service condition matching info.

| # | Type | Code |
|---|------|------|
| 1 | SET | `matchWribSvcMap = new HashMap<>()` // 割引サービス成立条件合致情報 — Discount service condition matching info |
| 2 | CALL | `dataCopy(matchWribSvcMap, wribSvcMap)` // 割引サービスの設定内容をコピー — Copy discount service settings |
| 3 | SET | `matchWribSvcMap.put(MATCH_WRIB_SVC_GRP_LIST, matchWribSvcGrpList)` // 成立条件合致サービスグループリスト — Matching condition service group list; `MATCH_WRIB_SVC_GRP_LIST = "match_wrib_svc_grp_list"` |
| 4 | EXEC | `matchWribSvcList.add(matchWribSvcMap)` // Add to final result list |

**Block 15** — INIT `(none)` (L582)
> After iterating over all candidate discount services, performs the final simultaneous availability check. The original comment reads: 併用可否チェック — Simultaneous availability check.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dojiOKList = jdgDojiAplyKh(matchWribSvcList)` // 併用可否チェック — Simultaneous availability check |
| 2 | RETURN | `dojiOKList` // Returns only services that are compatible for simultaneous application |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| 割引サービス (wrib_svc_cd) | Field | Discount service — a service eligible for discounted pricing based on bundled conditions. The field `wrib_svc_cd` holds the service code. |
| 割引登録条件コード (wrib_add_joken_cd) | Field | Discount registration condition code — classifies the conditions under which a discount service can be registered (e.g., `"wrib_add_joken_cd"`). |
| 申請形態コード (aply_info) | Field | Application form code — describes the type of application (new registration, change, cancellation, etc.). |
| 対象サービス (wrib_svc_tgt_svc) | Field | Target service — a service that is subject to the discount condition evaluation. |
| 対象契約サービス契約数 (trgt_kei_svc_kei_cnt) | Field | Target contracted service count — the number of contracted services within a target category, used to verify minimum bundle requirements. |
| 成立条件合致 (seiritsu joken gatchi) | Field | Condition matching — the state where all eligibility conditions for a discount service are satisfied. |
| 割引サービスグループ (wrib_svc_grp) | Field | Discount service group — a collection of services grouped by their discount registration condition codes. |
| 併用可否チェック (byouyou kahou check) | Field | Simultaneous availability check — validation determining whether multiple discount services can be applied to the same customer simultaneously without conflict. |
| grp_number | Field | Group number — an internal sequential identifier for each service group within the discount condition grouping. |
| svc_list | Field | Service list — the nested list of service info maps contained within each service group. |
| CHK_WRIB_SVC_TGT_SVC_LIST | Field | Check discount service target service list — holds the list of target services used during the eligibility validation phase. |
| MATCH_WRIB_SVC_GRP_LIST | Field | Match discount service group list — holds the final list of service groups that passed all condition checks for a matching discount service. |
| `searchWribSvc` | Method | Fetches all candidate discount services from the data source for the current simulation context. |
| `makeSvcGrpList` | Method | Groups services by their discount registration condition codes, building an index for rapid eligibility lookup. |
| `chkGetAplyInfo` | Method | Validates the application format and required fields for the discount service against business rules. |
| `chkVariSvcCd` | Method | Validates individual service codes (variety codes) against the target service to ensure compatibility. |
| `chkTrgtKeiSvcCnt` | Method | Utility check verifying the count of matched target services meets the minimum required threshold. |
| `chkAplyJokenCd` | Method | Utility check verifying the discount service's application condition codes are satisfied by the current target services. |
| `jdgDojiAplyKh` | Method | Judgment of simultaneous application compatibility (併用可否判定) — determines which discount services can coexist in the same subscription. |
| `dataCopy` | Method | Performs a shallow copy of key-value pairs from a source map to a destination map. |
