# Business Logic — KKW02701SFLogic.searchCourseRk() [93 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.web.webview.KKW02701SF.KKW02701SFLogic` |
| Layer | Controller (Web view logic layer) |
| Module | `KKW02701SF` (Package: `eo.web.webview.KKW02701SF`) |

## 1. Role

### KKW02701SFLogic.searchCourseRk()

This method performs the **course history list search processing** (コース履歴一覧の検索処理) for the KKW02701 screen, which displays a customer's contract course change history in a tabular view. The method orchestrates a three-phase flow: (1) prepares and sends a service request to the KKSV0394 SC (Service Component) to retrieve course history records, (2) handles errors by displaying message information and aborting if the service call fails, and (3) on success, maps the service output back to the screen bean and applies **popup-mode-aware button control logic** — when a course change is applicable to a net service customer who is not under a mansion contract, the method enables discount-eligible course change buttons and hides the standard return/close buttons. The method acts as the central controller for the "Course Change History" screen, serving as the entry point for both forward navigation and back-navigation flows. It implements the **screen logic delegation pattern**, where the bulk of data retrieval is offloaded to the `KKSV0394_KKSV0394OPDBMapper` and the `KKSV0394` SC, while this method focuses on coordination, error handling, and UI-level control flag management.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["searchCourseRk()"])
    START --> INIT["Initialize inputMap, outputMap, paramMap, mapper"]
    INIT --> GET_BEAN["Get service form bean svcFormBean"]
    GET_BEAN --> SET_DATE["Set operational date via getOpeDate"]
    SET_DATE --> SET_PARAM["Set service upper items paramBean array"]
    SET_PARAM --> MAP_SET["mapper.setKKSV039401CC paramBean inputMap"]
    MAP_SET --> PUT_TELEGRAM["Put TELEGRAM_INFO_USECASE_ID into paramMap"]
    PUT_TELEGRAM --> INVOKE["invokeService paramMap inputMap outputMap"]
    INVOKE --> CHECK_ERROR{msgResult not null}
    CHECK_ERROR -->|Yes| SET_MSG["JCCWebCommon.setMessageInfo"]
    SET_MSG --> RETURN_FALSE["Return false"]
    CHECK_ERROR -->|No| MAP_GET["mapper.getKKSV039401CC paramBean outputMap"]
    MAP_GET --> CHECK_POPUP{setPopupValue true}
    CHECK_POPUP -->|Yes| SET_BUTTON0["Set BTN_CTRL_FLG and CTRL_BUTTON_FLG to 0"]
    SET_BUTTON0 --> SET_FORWARD1["setForwardInfo to KKW02701"]
    SET_FORWARD1 --> RETURN_TRUE1["Return true"]
    CHECK_POPUP -->|No| GET_CUST["Get customer bean from list"]
    GET_CUST --> GET_FIELDS["Extract idoDiv svcCd man_flg svc_kei_status"]
    GET_FIELDS --> CHECK_WRIB{WRIB flag null or empty}
    CHECK_WRIB -->|Yes| SET_FALSE["bool_wrib_auto_aply_tg_gai_flg false"]
    CHECK_WRIB -->|No| CHECK_WRIB0{WRIB flag equals 0}
    CHECK_WRIB0 -->|Yes| SET_FALSE2["bool_wrib_auto_aply_tg_gai_flg false"]
    CHECK_WRIB0 -->|No| SET_TRUE["bool_wrib_auto_aply_tg_gai_flg true"]
    SET_FALSE --> GET_CP["Get cp_disp_flg"]
    SET_FALSE2 --> GET_CP
    SET_TRUE --> GET_CP
    GET_CP --> CHECK_MAIN{All conditions met}
    CHECK_MAIN -->|Yes| SET_NET["Set WRIB flag BTN_CTRL_FLG=3 CTRL_BUTTON_FLG=3"]
    SET_NET --> SET_FORWARD2["setForwardInfo to KKW02701"]
    SET_FORWARD2 --> RETURN_TRUE2["Return true"]
    CHECK_MAIN -->|No| SET_DEFAULT["Set BTN_CTRL_FLG=2 CTRL_BUTTON_FLG=1"]
    SET_DEFAULT --> SET_FORWARD3["setForwardInfo to KKW02701"]
    SET_FORWARD3 --> RETURN_TRUE3["Return true"]
```

**Processing flow summary:**

1. **Initialization** — Creates three `HashMap` instances for input/output/data parameter passing, and instantiates the `KKSV0394_KKSV0394OPDBMapper` for data mapping.
2. **Operational date setup** — Fetches the current operational date via `JCCWebCommon.getOpeDate()` and sets it into the service form bean under the key `UNYO_YMD` ("運用年月日" / Operational Year-Month-Day).
3. **Service request preparation** — Wraps the service form bean into a `paramBean` array and uses the mapper to populate `inputMap` with service upper items (service request parameters) via `setKKSV039401CC()`. Sets the use case ID to `"KKSV0394"` in the parameter map.
4. **Service invocation** — Calls `invokeService()` to execute the `KKSV0394` service, which queries course history data.
5. **Error handling** — If the service returns a non-null `msgResult`, the error message is set and the method returns `false`.
6. **Output mapping** — On success, maps the `outputMap` back into the service form bean via `getKKSV039401CC()`.
7. **Popup mode check** — If `setPopupValue()` returns `true` (indicating popup mode), the button control flags are set to `"0"` (standard display), skipping the course change-specific logic.
8. **Course change eligibility logic** (non-popup mode):
   - Extracts customer migration division (`idoDiv`), service code (`svcCd`), mansion flag (`man_flg`), service contract status (`svc_kei_status`), and discount flag (`bool_wrib_auto_aply_tg_gai_flg`).
   - Determines whether the "discount auto-application target exclusion flag" (割引自動適用対象外フラグ) is active.
   - Checks all course change eligibility conditions in a single compound if: the service is **Net** (`SVC_CD_NET = "01"`), **not a mansion** (`MANSION_FLAG_0 = "0"`), migration division is **Course Change** (`IDO_DIV_VALUE_00009 = "00009"`), service status is **active** (`svc_kei_status >= 100`), and the **course change fee reduction CP is eligible** (`CP_DISP_FLG_1 = "1"`).
   - If all conditions are met: enables the discount auto-application flag, sets `BTN_CTRL_FLG = "3"` and `CTRL_BUTTON_FLG = "3"` (enables course change-specific action buttons including "Return" and "Close" in popup mode).
   - Otherwise: sets `BTN_CTRL_FLG = "2"` and `CTRL_BUTTON_FLG = "1"` (hides action buttons, standard display).
9. **Forward navigation** — Sets the forward destination to the KKW02701 screen and returns `true`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no explicit parameters. It operates entirely on instance state (service form bean) and class-level fields inherited from its parent class. |

**Instance fields / external state read:**

| # | Field / Source | Business Description |
|---|---------------|---------------------|
| 1 | `super.getServiceFormBean()` — returns `X31SDataBeanAccess` | The screen's data bean, carrying all form fields, display flags, and service data for the KKW02701 screen. This is the primary data vessel throughout the method. |
| 2 | `this` (pass to `getOpeDate`, `setMessageInfo`) | The logic class instance itself, used as context for operational date resolution and message info setting. |
| 3 | `setPopupValue()` result | An inherited method that returns `true` if the screen is currently in popup mode. Controls whether course change-specific button logic is applied. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCWebCommon.getOpeDate` | JCCBPCommon | — | Reads the current operational date for the system |
| - | `KKSV0394_KKSV0394OPDBMapper.setKKSV039401CC` | KKSV0394 | — | Maps service upper items (request parameters) from the form bean into the input map for the KKSV0394 service |
| - | `KKW02701SFLogic.invokeService` | KKSV0394SC | KK_T_HKTGI_CUST_KEI, KK_T_KRS_RK (Course History) | Invokes the KKSV0394 service to search and retrieve course history list records; this is the core Read operation that queries the customer contract migration/course history tables |
| - | `KKSV0394_KKSV0394OPDBMapper.getKKSV039401CC` | KKSV0394 | — | Maps the service output (course history list) back into the form bean for screen display |
| - | `OneStopDataBeanAccess.sendMessageString` | — | — | Reads/writes individual data bean fields (idoDiv, svcCd, man_flg, svc_kei_status, etc.) |
| - | `KKW02701SFLogic.setPopupValue` | — | — | Checks whether the current screen is displayed in popup mode |
| - | `KKW02701SFLogic.setForwardInfo` | — | — | Sets the forward destination screen information (KKW02701) |

**CRUD Classification of the KKSV0394 service:**

The underlying `KKSV0394` service component performs a **Read (R)** operation — it queries the course history records from the database and returns them as a list. The tables involved are the customer contract migration tables (e.g., `KK_T_HKTGI_CUST_KEI`) and course history/ranking tables (e.g., `KK_T_KRS_RK`) that store course change events.

## 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: `setForwardInfo` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-], `sendMessageString` [-]

### Caller Analysis

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKW02701SF | `KKW02701SFLogic.init()` -> `searchCourseRk()` | `KKSV0394 [R] KK_T_HKTGI_CUST_KEI, KK_T_KRS_RK` |
| 2 | Screen:KKW02701SF | `KKW02701SFLogic.forwardBack()` -> `searchCourseRk()` | `KKSV0394 [R] KK_T_HKTGI_CUST_KEI, KK_T_KRS_RK` |

**Trace explanation:**
- The method is called from within the same class (`KKW02701SFLogic`) by two other methods: `init()` (initialization upon first screen entry) and `forwardBack()` (navigation from back/forward operations).
- The entry point to the KKW02701SF screen ultimately routes to `searchCourseRk()` as the core data loading and processing logic.
- The terminal operation is the `KKSV0394` service, which performs a **Read** from the customer contract and course history entity tables.

## 6. Per-Branch Detail Blocks

### Block 1 — INITIALIZATION (L590)

> Initializes data containers and retrieves the service form bean.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inputMap = new HashMap<String, Object>()` // Service input parameter map |
| 2 | SET | `outputMap = new HashMap<String, Object>()` // Service output result map |
| 3 | SET | `paramMap = new HashMap<String, String>()` // Service invocation parameter map |
| 4 | SET | `mapper = new KKSV0394_KKSV0394OPDBMapper()` // Data bean mapper for KKSV0394 |
| 5 | CALL | `svcFormBean = super.getServiceFormBean()` // Retrieves the screen data bean |

### Block 2 — OPERATIONAL DATE SETUP (L596)

> Sets the operational date (運用年月日) into the service form bean using the system operational date.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JCCWebCommon.getOpeDate(this, null)` // Gets current operational date |
| 2 | SET | `svcFormBean.sendMessageString(KKW02701SFConst.UNYO_YMD, X31CWebConst.DATABEAN_SET_VALUE, ...)` // [-> UNYO_YMD="運用年月日"] Stores operational date in bean |

### Block 3 — SERVICE REQUEST PREPARATION (L599–L603)

> Prepares service upper items (サービスの上り項目) for the KKSV0394 service call.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramBean = new X31SDataBeanAccess[] { svcFormBean }` // Wraps form bean in array |
| 2 | CALL | `mapper.setKKSV039401CC(paramBean, inputMap, "")` // Maps form bean data into inputMap |
| 3 | SET | `paramMap.put(X31CWebConst.TELEGRAM_INFO_USECASE_ID, "KKSV0394")` // Sets use case ID |

### Block 4 — SERVICE INVOCATION (L604)

> Calls the KKSV0394 service with the prepared parameters.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `msgResult = invokeService(paramMap, inputMap, outputMap)` // Invokes KKSV0394 service |

### Block 5 — ERROR HANDLING BRANCH (L607–L613)

> If the service returns a non-null message result, it indicates an error.

| # | Type | Code |
|---|------|------|
| 1 | IF | `null != msgResult` [msgResult contains error info] (L607) |
| 2 | CALL | `JCCWebCommon.setMessageInfo(this, msgResult)` // Displays error message to user |
| 3 | RETURN | `return false` // Aborts processing |

### Block 6 — OUTPUT MAPPING (L616)

> Maps the service output back into the screen bean for display.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `mapper.getKKSV039401CC(paramBean, outputMap)` // Transfers service output to form bean |

### Block 7 — POPUP MODE CHECK (L619)

> Determines if the screen is in popup mode. If so, skips course change-specific logic.

| # | Type | Code |
|---|------|------|
| 1 | IF | `setPopupValue()` returns true (popup mode) (L619) |
| 2 | SET | `svcFormBean.sendMessageString(KKW02701SFConst.CTRL_BUTTON_FLG, X31CWebConst.DATABEAN_SET_VALUE, "0")` // [-> CTRL_BUTTON_FLG="戻るボタン制御フラグ"] Standard button mode |
| 3 | (else skipped) | — |

### Block 7.1 — POPUP MODE: SKIP COURSE CHANGE LOGIC (L622, else branch of Block 7)

> When NOT in popup mode, proceeds with course change eligibility determination.

#### Block 7.1.1 — CUSTOMER DATA EXTRACTION (L624–L630)

> Extracts key customer and service fields from the data bean.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `custbean = paramBean[0].getDataBeanArray(JKKCommonConst.HKTGI_CUST_KEI_HKTGI_LIST).getDataBean(0)` // [-> HKTGI_CUST_KEI_HKTGI_LIST="顧客契約引継リスト"] Gets first customer record |
| 2 | SET | `idoDiv = custbean.sendMessageString("異動区分", X31CWebConst.DATABEAN_GET_VALUE)` // [-> "異動区分"/Migration Division] e.g., "00009" = Course Change |
| 3 | SET | `svcCd = svcFormBean.sendMessageString("サービスコード", X31CWebConst.DATABEAN_GET_VALUE)` // [-> "サービスコード"/Service Code] e.g., "01" = Net |
| 4 | SET | `man_flg = svcFormBean.sendMessageString("マンションフラグ", X31CWebConst.DATABEAN_GET_VALUE)` // [-> "マンションフラグ"/Mansion Flag] |
| 5 | SET | `svc_kei_status = svcFormBean.sendMessageString("サービス契約ステータス", X31CWebConst.DATABEAN_GET_VALUE)` // [-> "サービス契約ステータス"/Service Contract Status] |

#### Block 7.1.2 — DISCOUNT FLAG EVALUATION (L632–L644)

> Determines whether the discount auto-application target exclusion flag is set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `bool_wrib_auto_aply_tg_gai_flg = false` // Default: not excluded |
| 2 | IF | `custbean.sendMessageString("割引自動適用対象外フラグ", ...) == null || "".equals(...)` [-> WRIB_AUTO_APLY_TG_GAI_FLG="割引自動適用対象外フラグ"] (L633) |
| 3 | SET | `bool_wrib_auto_aply_tg_gai_flg = false` // Null/empty = not excluded |
| 4 | ELSE-IF | `"0".equals(...)` [-> "0" means NOT excluded] (L637) |
| 5 | SET | `bool_wrib_auto_aply_tg_gai_flg = false` // Explicit "0" = not excluded |
| 6 | ELSE | (L640) |
| 7 | SET | `bool_wrib_auto_aply_tg_gai_flg = true` // Any other value = excluded |

#### Block 7.1.3 — COURSE CHANGE FEE DISPLAY FLAG (L647)

> Reads the course change fee reduction display flag.

| # | Type | Code |
|---|------|------|
| 1 | SET | `cp_disp_flg = svcFormBean.sendMessageString("コース変更手数料減額表示", X31CWebConst.DATABEAN_GET_VALUE)` // [-> CP_DISP_FLG="コース変更手数料減額表示"] |

#### Block 7.1.4 — MAIN COURSE CHANGE ELIGIBILITY CHECK (L651–L664)

> EOU Net && Not Mansion && Migration=Course Change && Status >= 100 && CP Eligible

| # | Type | Code |
|---|------|------|
| 1 | IF | **Compound condition** (L651–L657): |
| 1a | COMPARE | `JKKCommonConst.SVC_CD_NET.equals(svcCd)` [-> SVC_CD_NET="01" (Net service)] |
| 1b | COMPARE | `MANSION_FLAG_0.equals(man_flg)` [-> MANSION_FLAG_0="0" (Not mansion-type)] |
| 1c | COMPARE | `JKKCommonConst.IDO_DIV_VALUE_00009.equals(idoDiv)` [-> IDO_DIV_VALUE_00009="00009" (Migration=Course Change)] |
| 1d | COMPARE | `Integer.parseInt(svc_kei_status) >= 100` [Service contract status is active/in-progress] |
| 1e | COMPARE | `CP_DISP_FLG_1.equals(cp_disp_flg)` [-> CP_DISP_FLG_1="1" (Course change fee reduction CP eligible)] |
| 2 | SET | `svcFormBean.sendMessageBoolean(KKW02701SFConst.WRIB_AUTO_APLY_TG_GAI_FLG, X31CWebConst.DATABEAN_SET_VALUE, bool_wrib_auto_aply_tg_gai_flg)` // [-> WRIB_AUTO_APLY_TG_GAI_FLG="割引自動適用対象外フラグ"] |
| 3 | SET | `svcFormBean.sendMessageString(KKW02701SFConst.BTN_CTRL_FLG, X31CWebConst.DATABEAN_SET_VALUE, "3")` // [-> BTN_CTRL_FLG="ボタン制御フラグ", "3"=Show action buttons] |
| 4 | SET | `svcFormBean.sendMessageString(KKW02701SFConst.CTRL_BUTTON_FLG, X31CWebConst.DATABEAN_SET_VALUE, "3")` // [-> CTRL_BUTTON_FLG="戻るボタン制御フラグ", "3"=Show return/close buttons] |
| 5 | ELSE | (L661) |
| 6 | SET | `svcFormBean.sendMessageString(KKW02701SFConst.BTN_CTRL_FLG, X31CWebConst.DATABEAN_SET_VALUE, "2")` // "2"=Hide action buttons |
| 7 | SET | `svcFormBean.sendMessageString(KKW02701SFConst.CTRL_BUTTON_FLG, X31CWebConst.DATABEAN_SET_VALUE, "1")` // "1"=Hide return/close buttons |

### Block 8 — FORWARD NAVIGATION (L672)

> Sets the forward destination screen and completes processing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `setForwardInfo(JKKScreenConst.SCREEN_ID_KKW02701, JKKScreenConst.SCREEN_NAME_KKW02701)` // Sets forward to KKW02701 |
| 2 | RETURN | `return true` // Processing succeeded |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `searchCourseRk` | Method | Course History Search — retrieves and displays a customer's course change history records |
| コース履歴一覧 | Japanese | Course History List — a tabular view of all past course (plan) changes for a customer's contract |
| `KKSV0394` | Service Code | Screen Component for Course History List Search — the SC that queries customer course change records from the database |
| `UNYO_YMD` | Field | Operational Year-Month-Day (運用年月日) — the system date used as the operational reference date |
| `IDO_DIV` / 異動区分 | Field | Migration Division Code — classifies the type of customer contract change. `"00009"` = Course Change (コース変更) |
| `SVC_CD` / サービスコード | Field | Service Code — identifies the service type. `"01"` = Net (EO光ネット / K-Opticom Internet) |
| `MAN_FLG` / マンションフラグ | Field | Mansion Flag — indicates whether the customer's premises is a mansion (multi-unit dwelling) type. `"0"` = Not mansion |
| `SVC_KEI_STATUS` / サービス契約ステータス | Field | Service Contract Status — numeric status of the service contract. Values `>= 100` indicate the service is actively provided (サービス提供中) |
| `WRIB_AUTO_APLY_TG_GAI_FLG` / 割引自動適用対象外フラグ | Field | Discount Auto-Application Target Exclusion Flag — indicates whether discounts are excluded from auto-application. `true` = excluded, `false` = not excluded |
| `CP_DISP_FLG` / コース変更手数料減額表示 | Field | Course Change Fee Reduction Display Flag — indicates whether a course change fee discount coupon/promotion is applicable. `"1"` = eligible |
| `BTN_CTRL_FLG` / ボタン制御フラグ | Field | Button Control Flag — controls visibility of action buttons on the screen. `"0"`=standard, `"1"`=hidden, `"2"`=hide action, `"3"`=show action buttons |
| `CTRL_BUTTON_FLG` / 戻るボタン制御フラグ | Field | Return Button Control Flag — controls visibility of the "Return" (戻る) and "Close" (閉じる) buttons in popup mode |
| `HKTGI_CUST_KEI_HKTGI_LIST` / 顧客契約引継リスト | Field | Customer Contract Inheritance List — the bean list containing customer contract migration/change records |
| `invokeService` | Method | Service invocation method — sends a request to a CBS/SC service and returns a message result |
| `JCCWebCommon.getOpeDate` | Method | Gets the system operational date — returns the current business date used for date-stamping operations |
| `setPopupValue` | Method | Checks if the screen is displayed in popup mode — returns `true` when the screen is a popup dialog |
| `setForwardInfo` | Method | Sets the forward navigation destination — specifies which screen to display next |
| EOU Net | Business term | EO光ネット (Eclipse Optical Internet) — K-Opticom's fiber-optic broadband internet service |
| Net service (`SVC_CD_NET="01"`) | Business term | The fiber-optic internet service line, as opposed to TV, phone, or other service lines |
| Course Change (コース変更) | Business term | A customer's request to change their subscribed service plan/course to a different tier or package |
| Mansion contract | Business term | A service contract tied to a multi-unit dwelling (apartment/mansion), which may have different pricing and promotional rules |
| `KKSV039401CC` | Mapping Code | Data mapping configuration for KKSV0394 — maps input/output between the form bean and service parameters |
| `KKSV0394_KKSV0394OPDBMapper` | Class | Object-Database mapper for KKSV0394 — handles data conversion between screen beans and service maps |
| KKW02701 | Screen Code | Course Change History screen — displays the course history list and handles course change selections |
