# Business Logic — KKW02519SFLogic.checkOtokuChkResult() [53 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW02519SF.KKW02519SFLogic` |
| Layer | Web Logic (Controller layer — part of the webview logic tier under `eo.web.webview`) |
| Module | `KKW02519SF` (Package: `eo.web.webview.KKW02519SF`) |

## 1. Role

### KKW02519SFLogic.checkOtokuChkResult()

This method performs **discount check result processing** for the "eo光電話" (eo Light Phone) service contract update screen. It determines whether any promotional discounts (お得, *otoku*) are applicable to the customer's current service configuration, and if discount errors exist, it builds localized error messages specifying which discount package the customer was attempting to access.

The method follows a **query-then-route** pattern. It delegates to the `KKSV0369_KKSV0369OPDBMapper.getKKSV036917CC` method to retrieve the pre-computed discount check results (set by the back-end operation layer `KKSV0369OPOperation.executeOtokuCheck`), then reads the error flag and applicable service code from the response DataBean. Based on these values, it routes to one of four error message templates: **eo光電話パック3** (eo Light Phone Pack 3, for FTTH Auth Registration with the Pack 3 plan), **eo光電話パック7** (eo Light Phone Pack 7, for FTTH Auth Change with the Pack 7 plan), **あんしん電話パック** (Anshin Phone Pack, a safety/wellness phone service plan), or a generic fallback message for other single-service orders.

This method is a shared utility called exclusively from `actionInitUpdTran` during both **service contract reinstatement** (`OP_TRAN_DIV_KAIHK`) and **reservation cancellation** (`OP_TRAN_DIV_RSV_CL`) transaction divisions on the KKW02519SF screen. It plays a critical role in the customer communication path: when a discount eligibility conflict is detected upstream, this method ensures the user receives a clear, package-specific error message before the transaction can proceed.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["checkOtokuChkResult start"])
    GET_COMMON["Get commonInfoBean"]
    INIT1["Initialize otoku_chk_err_flg"]
    INIT2["Initialize otoku_chk_wrib_svc_cd"]
    CREATE_MAPPER["Create KKSV0369_KKSV0369OPDBMapper"]
    CALL_17CC["Call getKKSV036917CC"]
    GET_ERR_FLG["Get OTOKU_CHK_ERR_FLG from paramBean"]
    GET_WRIB_CD["Get OTOKU_WRIB_SVC_CD from paramBean"]
    COND_FLG{Flag is null or empty}
    COND_ERR1{Flag equals 1}
    COND_SVC1{svc_cd equals W00000007}
    COND_SVC2{svc_cd equals W00000008}
    COND_SVC3{svc_cd equals W00000023}
    SET_CHAR1["err_char = eo光電話パック3"]
    SET_CHAR2["err_char = eo光電話パック7"]
    SET_CHAR3["err_char = あんしん電話パック"]
    SET_CHAR4["err_char = 単品お申し込み"]
    SET_STR["Set str array with err_char"]
    CALL_SET_MSG["Call setMessageInfo with EKBE131-KW"]
    END_NODE(["Return / Next"])
    START --> GET_COMMON
    GET_COMMON --> INIT1
    INIT1 --> INIT2
    INIT2 --> CREATE_MAPPER
    CREATE_MAPPER --> CALL_17CC
    CALL_17CC --> GET_ERR_FLG
    GET_ERR_FLG --> GET_WRIB_CD
    GET_WRIB_CD --> COND_FLG
    COND_FLG --> false:END_NODE
    COND_FLG --> true:COND_ERR1
    COND_ERR1 --> false:END_NODE
    COND_ERR1 --> true:COND_SVC1
    COND_SVC1 --> true:SET_CHAR1
    SET_CHAR1 --> SET_STR
    COND_SVC1 --> false:COND_SVC2
    COND_SVC2 --> true:SET_CHAR2
    SET_CHAR2 --> SET_STR
    COND_SVC2 --> false:COND_SVC3
    COND_SVC3 --> true:SET_CHAR3
    SET_CHAR3 --> SET_STR
    COND_SVC3 --> false:SET_CHAR4
    SET_CHAR4 --> SET_STR
    SET_STR --> CALL_SET_MSG
    CALL_SET_MSG --> END_NODE
```

**Processing flow:**

1. **Initialize local state:** Gets the common info bean (unused beyond context) and initializes two local String variables — `otoku_chk_err_flg` and `otoku_chk_wrib_svc_cd` — to `null`.
2. **Query discount check results:** Creates a new `KKSV0369_KKSV0369OPDBMapper` instance and calls `getKKSV036917CC(paramBean, outputMap)` to retrieve the discount check results computed by the back-end operation layer. The mapper maps data from the `KKSV036917CC` key in `outputMap` (populated by `KKSV0369OPOperation.executeOtokuCheck`) into the paramBean's DataBean fields.
3. **Extract error flag and service code:** Reads the `OTOKU_CHK_ERR_FLG` ("お得チェックエラーフラグ") and `OTOKU_WRIB_SVC_CD` ("お得チェック割引サービスコード") values from `paramBean[0]` using `sendMessageString(..., DATABEAN_GET_VALUE)`.
4. **Check for errors:** If the error flag is present and non-empty, enters the error handling branch.
5. **Check if error severity is "1":** A flag value of `"1"` means a discount error has occurred (お徳チェックエラー). If not "1" or null, processing skips to the end.
6. **Determine error message content by service code:** Routes to one of four error message strings based on the discount service code:
   - `"W00000007"` (折割引サービスコード eo光電話パック3) → `"eo光電話パック3"` (eo Light Phone Pack 3)
   - `"W00000008"` (折割引サービスコード eo光電話パック7) → `"eo光電話パック7"` (eo Light Phone Pack 7)
   - `"W00000023"` (折割引サービスコード あんしん電話パック) → `"あんしん電話パック"` (Anshin Phone Pack)
   - `else` (fallback, added per OM-2020-0001366) → `"単品でお申し込みいただく方"` (Customers applying for a single product separately)
7. **Output error message:** Calls `JCCWebCommon.setMessageInfo(this, "EKBE131-KW", str)` to display the localized error message to the user with the specific package name interpolated.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `paramBean` | `X31SDataBeanAccess[]` | Array of screen DataBean objects carrying field-level data between the web tier and business logic. Element `[0]` is the primary form bean for the "eo Light Phone" service contract update screen. After the `getKKSV036917CC` call, it is populated with `otoku_chk_err_flg` (discount error flag) and `otoku_chk_wrib_svc_cd` (discount check service code) values retrieved from the back-end mapper. |
| 2 | `outputMap` | `HashMap<String, Object>` | Upward data map used for cross-layer data transfer. It carries the `KKSV036917CC` key whose value is a `HashMap` containing the back-end computed discount check results (`otoku_chk_err_flg`, `pack_mirai_flg`, `wrib_svc_cd`) produced by `KKSV0369OPOperation.executeOtokuCheck`. |

**External state / instance fields read:**
- None directly — this method is purely stateless; it relies entirely on its parameters and creates new mapper instances internally.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `KKSV0369_KKSV0369OPDBMapper.getKKSV036917CC` | KKSV036917CC | — (mapper) | Retrieves pre-computed discount check results from the `outputMap` (key `KKSV036917CC`). This mapper reads `otoku_chk_err_flg`, `pack_mirai_flg`, and `wrib_svc_cd` values populated by the back-end operation layer `KKSV0369OPOperation.executeOtokuCheck`, which executes SC code `KKSV036916SC` to query discount eligibility data. |
| - | `JCCWebCommon.setMessageInfo` | — | — | Displays localized error message (message code `EKBE131-KW`) to the user via the web common framework, with the package-specific error string interpolated into the message template. |
| - | `X31SDataBeanAccess.sendMessageString` (GET) | — | — | Reads field values (`OTOKU_CHK_ERR_FLG`, `OTOKU_WRIB_SVC_CD`) from the DataBean at `paramBean[0]`. |
| - | `super.getCommonInfoBean()` | — | — | Retrieves the common information DataBean (used for context but not directly consumed in this method). |

**How SC Codes are resolved:**

The mapper's `getKKSV036917CC` delegates to a pre-built `outputMap` entry keyed as `KKSV036917CC`. That entry is populated upstream by the `KKSV0369OPOperation.executeOtokuCheck` method in the EJB module (`source/koptBp/ejbModule/com/fujitsu/futurity/bp/custom/bpm/kksv0369/KKSV0369OPOperation.java`), which:
1. Initializes a `dataMapOtokuChk` HashMap with `otoku_chk_err_flg = "0"` (initialized: no error).
2. Executes `param.setData("KKSV036916SC", dataMapOtokuChk)` — the actual service call that queries discount eligibility.
3. Reads back results and sets `otoku_chk_err_flg` to `"1"` when a conflict is detected (line 1132: `dataMapOtokuChk.put("otoku_chk_err_flg", "1")`).

The `KKSV036916SC` is the SC Code performing the actual discount eligibility check. Its Entity/DB tables are not directly visible at this web logic layer since the logic is encapsulated in the EJB operation layer.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: `setMessageInfo` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `getKKSV036917CC` [R], `getKKSV036917CC` [R], `getKKSV036917CC` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKW02519 | `KKW02519SFLogic.<init>` -> `KKW02519SFLogic.actionInitUpdTran` -> `KKW02519SFLogic.checkOtokuChkResult` | `getKKSV036917CC [R] KKSV036916SC (discount eligibility)` |
| 2 | Screen:KKW02519 | `KKW02519SFLogic.<init>` -> `KKW02519SFLogic.actionInitUpdTran` -> `checkOtokuChkResult` (reinstatement path: OP_TRAN_DIV_KAIHK) | `setMessageInfo [EXEC] EKBE131-KW (error display)` |
| 3 | Screen:KKW02519 | `KKW02519SFLogic.<init>` -> `KKW02519SFLogic.actionInitUpdTran` -> `checkOtokuChkResult` (cancellation path: OP_TRAN_DIV_RSV_CL) | `setMessageInfo [EXEC] EKBE131-KW (error display)` |

**Call chain details:**
- Entry point: The screen `KKW02519` (電話オプションサービス契約更新 — Phone Option Service Contract Update) routes through the constructor which calls `actionInitUpdTran(svcFormBean, screenId, tranDiv)`.
- `actionInitUpdTran` branches on `tranDiv`: when `OP_TRAN_DIV_KAIHK` (reinstatement) or `OP_TRAN_DIV_RSV_CL` (reservation cancellation), it calls `checkOtokuChkResult`.
- The back-end flow continues via the `KKSV036917CC` mapper → `KKSV036916SC` (discount eligibility check SC) → EJB operation layer `KKSV0369OPOperation.executeOtokuCheck` which queries service contract and discount eligibility tables.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET/INIT] Initialize local variables (L1285–L1288)

> Initializes the local variables that will hold the discount check results. `getCommonInfoBean()` retrieves the common context bean (unused in this method but present as an artifact of the refactoring pattern).

| # | Type | Code |
|---|------|------|
| 1 | SET | `commonBean = super.getCommonInfoBean()` // Get common context DataBean [-> KKW02519SFConst.OTOKU_CHK_ERR_FLG="お得チェックエラーフラグ"] |
| 2 | SET | `otoku_chk_err_flg = null` // Discount check error flag [-> KKW02519SFConst.OTOKU_CHK_ERR_FLG="お得チェックエラーフラグ"] |
| 3 | SET | `otoku_chk_wrib_svc_cd = null` // Discount check discount service code [ANK-3754-00-00 ADD] [-> KKW02519SFConst.OTOKU_WRIB_SVC_CD="お得チェック割引サービスコード"] |

**Block 2** — [EXEC] Query discount check results (L1289–L1292)

> Creates the mapper and calls `getKKSV036917CC` to retrieve discount check results from the `outputMap`. The back-end operation `KKSV0369OPOperation.executeOtokuCheck` (which calls SC code `KKSV036916SC`) pre-populates `outputMap` with `otoku_chk_err_flg` ("0" = no error, "1" = error), `pack_mirai_flg`, and `wrib_svc_cd`.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `KKSV0369_KKSV0369OPDBMapper mapper = new KKSV0369_KKSV0369OPDBMapper()` // Create mapper instance |
| 2 | CALL | `mapper.getKKSV036917CC(paramBean, outputMap)` // Map back-end discount check results into paramBean |

**Block 3** — [EXEC] Extract error flag and service code from paramBean (L1293–L1298)

> Reads the discount check error flag and the applicable service code from the first element of `paramBean[0]` using `sendMessageString` with `DATABEAN_GET_VALUE`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `otoku_chk_err_flg = paramBean[0].sendMessageString(OTOKU_CHK_ERR_FLG, X31CWebConst.DATABEAN_GET_VALUE)` // Read error flag ["お得チェックエラーフラグ"] [-> KKW02519SFConst.OTOKU_CHK_ERR_FLG="お得チェックエラーフラグ"] |
| 2 | SET | `otoku_chk_wrib_svc_cd = paramBean[0].sendMessageString(OTOKU_WRIB_SVC_CD, X31CWebConst.DATABEAN_GET_VALUE)` // Read discount service code [ANK-3754-00-00 ADD] [-> KKW02519SFConst.OTOKU_WRIB_SVC_CD="お得チェック割引サービスコード"] |

**Block 4** — [IF] Check for error flag presence (L1299–L1300, old code commented out)

> The commented-out code (ANK-3754-00-00 MOD START/END) shows a previous simpler approach: if the error flag was non-empty and equal to "1", it displayed message code `EKBE129-KW`. This was replaced by the more detailed package-specific routing logic.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | (commented out) `if (otoku_chk_err_flg != null && !otoku_chk_err_flg.equals(""))` // Old error check |
| 2 | EXEC | (commented out) `if ("1".equals(otoku_chk_err_flg))` // If error |
| 3 | EXEC | (commented out) `JCCWebCommon.setMessageInfo(this, "EKBE129-KW")` // Generic error message |

**Block 5** — [IF] Process error flag if non-empty (L1301–L1334)

> Condition: `otoku_chk_err_flg != null && !otoku_chk_err_flg.equals("")` — There is an error to report.

| # | Type | Code |
|---|------|------|
| 1 | SET | `otoku_chk_err_char = ""` // Initialize error character string |
| 2 | EXEC | (inner IF block — see Block 5.1) |

**Block 5.1** — [IF] Nested: error severity equals "1" (L1303, `[OTOKU_CHK_ERR_FLG="1"]`)

> Condition: `"1".equals(otoku_chk_err_flg)` — The flag value "1" means a discount check error occurred (お徳チェックエラー). "0" indicates no error and would not enter this branch.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | (nested IF for service code routing — see Block 5.1.1) |

**Block 5.1.1** — [IF/ELSE-IF/ELSE] Determine error message by discount service code (L1305–L1320, `[WRIB_SVC_CD_PACK3="W00000007"]`)

> Condition: Routes the error message based on which discount package the customer was attempting to access. The service code indicates which promotional plan was in conflict.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if ("W00000007".equals(otoku_chk_wrib_svc_cd))` [-> KKW02519SFConst.WRIB_SVC_CD_PACK3="W00000007" (eo光電話パック3)] |
| 2 | SET | `otoku_chk_err_char = "eo光電話パック3"` // eo Light Phone Pack 3 |
| 3 | ELSE-IF | `else if ("W00000008".equals(otoku_chk_wrib_svc_cd))` [-> KKW02519SFConst.WRIB_SVC_CD_PACK7="W00000008" (eo光電話パック7)] |
| 4 | SET | `otoku_chk_err_char = "eo光電話パック7"` // eo Light Phone Pack 7 |
| 5 | ELSE-IF | `else if ("W00000023".equals(otoku_chk_wrib_svc_cd))` (あんしん電話パック) |
| 6 | SET | `otoku_chk_err_char = "あんしん電話パック"` // Anshin Phone Pack (safety phone service plan) |
| 7 | ELSE | `else` [OM-2020-0001366 ADD] (fallback for other service codes) |
| 8 | SET | `otoku_chk_err_char = "単品でお申し込みいただく方"` // Customers applying for a single product separately |

**Block 6** — [SET/EXEC] Output error message to user (L1322–L1324)

> Constructs a string array with the error character code and calls the web common framework to display the localized error message. The message code `EKBE131-KW` is a resource bundle key that contains a template with a placeholder for the package name.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String[] str = { "", otoku_chk_err_char }` // Error message parameter array |
| 2 | CALL | `JCCWebCommon.setMessageInfo(this, "EKBE131-KW", str)` // Display error message [-> Message Code EKBE131-KW with interpolated package name] |
| 3 | RETURN | `// void return — next step handled by caller actionInitUpdTran` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `otoku_chk_err_flg` | Field | Discount check error flag — indicates whether a promotional discount conflict exists. `"0"` = no error (initial default), `"1"` = error detected. |
| `otoku_chk_wrib_svc_cd` | Field | Discount check discount service code — the specific service code (e.g., `W00000007`) identifying which discount package the customer was attempting to apply. |
| `wrib_svc_cd` | Field | Discount service code — same concept as `otoku_chk_wrib_svc_cd`, stored in the back-end `outputMap` under the `KKSV036917CC` key. |
| `pack_mirai_flg` | Field | Future pack presence flag — indicates whether a future/next-generation service pack is available (set by `getKKSV036917CC` mapper but not used directly in this method). |
| OTOKU_CHK_ERR_FLG | Constant | "お得チェックエラーフラグ" — DataBean field key for reading the discount check error flag value. |
| OTOKU_WRIB_SVC_CD | Constant | "お得チェック割引サービスコード" — DataBean field key for reading the discount check discount service code. |
| WRIB_SVC_CD_PACK3 | Constant | "W00000007" — Service code for eo Light Phone Pack 3 (FTTH Auth Registration plan). |
| WRIB_SVC_CD_PACK7 | Constant | "W00000008" — Service code for eo Light Phone Pack 7 (FTTH Auth Change plan). |
| otoku (お得) | Business term | Promotional discount — refers to special pricing or promotional offers on telecom services. In this context, "otoku check" validates whether a customer's service combination qualifies for or conflicts with promotional pricing. |
| eo光電話 (eo Hikari Denwa) | Business term | eo Light Phone — NTT East's fiber-optic bundled telephone service. The screen KKSV02519 handles service contract updates for this offering. |
| パック (Pack) | Business term | Service bundle/package — refers to bundled service plans (e.g., Pack 3, Pack 7) that combine internet, phone, and other services at a promotional rate. |
| あんしん電話 (Anshin Denwa) | Business term | Anshin Phone — a safety/wellness phone service plan with emergency assistance features. |
| 単品お申し込み | Business term | Single-service application — customers who apply for a standalone product rather than a bundled package. Used as the fallback error message when the service code does not match any known pack. |
| KKSV036916SC | SC Code | Discount eligibility check service code — the SC layer that queries service contract data to determine whether promotional discounts apply or conflict. |
| KKSV036917CC | CC Code | Mapper code — the web-mapping component that transfers discount check results between the EJB operation layer and the web layer. |
| EKBE131-KW | Message Code | Error message resource key — displays the package-specific discount error message to the user. The `-KW` suffix indicates it is a screen-specific Japanese message. |
| EKBE129-KW | Message Code | (Deprecated) Generic discount error message key — was used before package-specific routing was introduced. Now commented out. |
| OP_TRAN_DIV_KAIHK | Constant | Operation transaction division — reinstatement (恢复) — the branch where a previously cancelled/reinstated service contract is being processed. |
| OP_TRAN_DIV_RSV_CL | Constant | Operation transaction division — reservation cancellation (予約取消) — the branch where a service reservation is being cancelled. |
| KKW02519SF | Module | Phone Option Service Contract Update Screen — the web module handling service contract modifications for phone option services. |
| KKSV0369OPOperation | Class | Back-end EJB operation class — contains `executeOtokuCheck` which performs the actual discount eligibility query and sets results into the `outputMap`. |
| X31SDataBeanAccess | Class | X31 framework DataBean access class — the base class for screen form data beans that carry field-level data between web and business layers. |
| JCCWebCommon | Class | Web Common Component — shared utility class for web-layer operations including message display (`setMessageInfo`). |
