# CRW03401SFLogic

## Purpose

`CRW03401SFLogic` is the central screen-level business logic controller for the **Comprehensive Inquiry Response Main Screen** (総合案内問合せ対応画面) in a web-based customer service application. It handles the initial display, tab navigation, link-based sub-screen navigation, and various transactional actions (reject, accept, close, restart) for an inquiry response workflow. It exists as the glue between the XML-defined screen controller and the backend services, coordinating data retrieval, screen transitions, and state management within the X31 web framework.

## Design

`CRW03401SFLogic` follows the **screen logic controller** pattern, extending `JCCWebBusinessLogic` — the framework's base class for screen-level business logic. It implements the X31 web framework's standard six-phase action method lifecycle:

1. **Acquire inherited info** (`getScreenInfo`)
2. **Configure service form bean** (reset button states, set defaults)
3. **Invoke backend service** (via `invokeService` with mapping mappers, or delegate to `JCRWebCommon` helpers)
4. **Configure service results** (process returned data into the form bean)
5. **Set inherited info for next screen** (`setScreenId` + `setScreenInfo`)
6. **Configure shared form bean** (`NEXT_SCREEN_ID`, `NEXT_SCREEN_NAME`)

Most methods follow this template verbatim, delegating to helper methods in `JCRWebCommon`, `JCCWebCommon`, and `JZMWebCommon` for service invocation, screen setup, and date manipulation respectively. The class uses mapping mappers (`CRSV0084_CRSV0084OPDBMapper`, `CRSV0281_CRSV0281OPDBMapper`) for direct service invocations.

```mermaid
flowchart TD
    Sub["WEBGAMEN_CRW034010PJP.xml<br>Web Screen Action"] --> CRW["CRW03401SFLogic<br>Screen Logic Controller"]
    Sub2["x31business_logic_CRW03401SF.xml<br>Business Logic XML"] --> CRW
    CRW --> JCC["JCCWebBusinessLogic<br>Base Class"]
    CRW --> JCR["JCRWebCommon<br>Web Common Helpers"]
    CRW --> JCC2["JCCWebCommon<br>Screen Common Helpers"]
    CRW --> JZM["JZMWebCommon<br>Date Helpers"]
    CRW --> CRS["CRSV0084 Mapper<br>Service Mapping"]
    CRW --> CRS2["CRSV0281 Mapper<br>Re-issue Service"]
    CRW --> JAC["JACScreenConst<br>Screen ID Constants"]
    CRW --> JCR2["JCRScreenConst<br>Screen ID Constants"]
    CRW --> JKK["JKKScreenConst<br>Screen ID Constants"]
```

## Key Methods

### Screen Lifecycle

#### `init()` → boolean
Performs the initial display setup for the Comprehensive Inquiry Response screen. This is the most complex method in the class (160+ lines) and handles:

- Retrieving the service form bean and common info bean
- Calling `JCRWebCommon.getScreenInfo(this)` to load inherited screen information
- Resetting button/link states via `JCRWebCommon.resetButtonStatus`
- Clearing multiple message list arrays from the bean (campaign, equipment, progress, phone, billing message lists)
- Setting a display flag if service contract number (`SVC_KEI_NO`) or SYSID is present in the inherited info
- Setting operational parameters: operation date, and various work parameter IDs for equipment business (`KIKI`), progress business (`SNTYK`), phone business (`TELL`), campaign business (`CNP`), domain business (`TIK`), and form business (`BMP`)
- Loading main inquiry response common info
- If no inherited service contract number and SYSID are set, setting next screen navigation info and returning early
- Otherwise, building a comprehensive service invocation using the `CRSV0084_CRSV0084OPDBMapper` mapping class with 16+ mapping set/get methods, invoking the service via `invokeService(paramMap, dataMap, outputMap)`, and processing all results back into the bean arrays
- Calculating transaction fees via `JCRWebCommon.getJimFee` using ICJ settlement code, fee amount, and temporary payment amount
- Replacing placeholder date `20991231` with "blank" values for multiple date fields (service end date, agreement date, payment dates, equipment delivery dates) via `JZMWebCommon.replaceTendymd`
- Calling `getMainData()` to sync inquiry main data to a dedicated table
- Setting up shared form bean next-screen navigation

Returns `true` on success. Throws `Exception` on service errors.

#### `receiveMessageWeb(X31CID arg0, Object arg1, EventObject arg2)` → boolean
Overrides the framework's message receive method. Currently returns `false` without implementation — appears to be a framework-required override that this screen does not override behavior for. The comment indicates this is an automatically generated method that overrides the parent class's `receiveMessageWeb` from `X31BWebBusinessLogic`.

### Navigation & Link Actions

#### `clickLinkSeikyYm()` → boolean
Displays the billing details screen (請求明細画面) as a pop-up. Retrieves the selected row index from the service bean to get the specific billing detail data (contract number, billing month, billing number), then sets up screen navigation to `SCREEN_ID_CHW00105`. Passes the billing contract number, billing month, and billing number as inherited parameters.

#### `clickLinkMyboxCnt()` → boolean
Displays the MYBOX list screen (MYBOX一覧画面) as a pop-up. Sets screen ID to `SCREEN_ID_CRW01301` and passes screen info using `JCRWebCommon.copyBeanToMyBOX(bean, commoninfoBean)` to prepare data for the MYBOX sub-screen.

#### `clickLinkQueboxCnt()` → boolean
Displays the QUEBOX list screen (キューBOX一覧画面) as a pop-up. Sets screen ID to `SCREEN_ID_CRW01401` and passes screen info using `JCRWebCommon.copyBeanToQueBOX(bean, commoninfoBean)`.

#### `clickLinkMailCnt()` → boolean
Displays the mail simplified send screen (メール簡易送信画面) as a pop-up. Sets screen ID to `SCREEN_ID_CRW10301` and passes screen info using `JCRWebCommon.copyBeanToSendMail(bean, commoninfoBean)`.

#### `clickTab()` → boolean
Handles tab clicks on the main screen. First refreshes MYBOX/QUEBOX/mail counts via `JCRWebCommon.getMyboxQueboxMailCnt`. If the clicked tab is the main screen tab itself (`SENYO_TAB_ID`), delegates to `init()` for a full re-initialization. Otherwise, sets the parent screen ID (`SENYO_TAB_ID`) as the previous screen for all 15 possible sub-screens (MYBOX, QUEBOX, SENDMAIL, INQUIRY_INSERT, INQUIRY_UPDATE, ESCALATION, CANCEL, PROSCST_EDIT, PROSCST_SEARCH, HOTVOICE, SEND_SYRIO, PROSCST_VIEW, MEMO, MAIL_RETURN, MAIL_TRANSFER, and CRW01601), then sets screen info for the target tab screen using `JCRWebCommon.copyBeanToNextTab(bean, commoninfoBean)`.

#### `execute()` → boolean
Displays other system screens. Calls `JCRWebCommon.execute(bean, commoninfoBean, this)` which handles the "wan Tai password registration" process (ワンタイムパスワード登録処理). Sets next screen back to the current screen ID/name for self-navigation.

#### `display()` → boolean
Calls the service for MYBOX, QUEBOX, and mail count retrieval. This appears to be the "Ask Inquiry Response Main Common Screen read-in" (問合せ対応メイン共通画面読み込み) service. It invokes `JCRWebCommon.getMyboxQueboxMailCnt(paramBean, this)` with both the service bean and common info bean. Returns `true`.

#### `transferToMain()` → boolean
Returns to the inquiry response main screen (問合せ対応メイン画面). Acquires screen info, sets screen info for `SCREEN_ID_CRW01201` (the main screen) using `JCRWebCommon.copyBeanToInitMain(bean, commoninfoBean)`, and navigates back to the main screen from which the inquiry response screen was originally launched.

#### `clickLinkMskmshoNoUk()` → boolean
Handles the "Application Number (Receipt) Link Press" (申込書番号(受付)リンク押下処理) action. Retrieves a base URL from application constants for document reference VRL, calls `JCRWebCommon.getOnetPwdImgSys` for one-time password image system setup, constructs the image system URL with the application change receipt number and one-time password, sets the URL and display flag in the bean, and navigates back to the current screen.

#### `clickLinkTrank()` → boolean
Handles the "Member Rank Link Press" (会員ランクリンク押下処理) action. Sets up screen navigation to `JKKScreenConst.SCREEN_ID_KKW00196` (member rank screen) using `JCRWebCommon.clickLinkTrank(bean, commoninfoBean, this)` to prepare the sub-screen data, then sets the next screen ID/name to the member rank screen.

#### `clickLinkVcms()` → boolean
Handles the "Reset Contract Screen Navigation Link Press" (リセット契約画面へ遷移リンク押下処理) action. Sets up screen navigation to the reset contract screen. Passes the current screen ID as the previous screen to the target.

#### `openCrw10901()` → boolean
Displays the inquiry history screen. Sets up screen navigation to `JCRScreenConst.SCREEN_ID_CRW10901` with the current screen as the previous screen, passes screen info via `JCRWebCommon.copyBeanToNextTab(bean, commoninfoBean)`, and sets next screen navigation.

### Sub-screen Openers (12 methods)

The following methods all follow an identical pattern: set the parent screen ID, set screen info with a `copyBeanToXxx` helper, and set the next screen ID/name in the shared form bean.

| Method | Sub-screen | Screen ID | Bean Copier | Description |
|--------|-----------|-----------|-------------|-------------|
| `openCrw00101Ins()` | Inquiry Entry | `CRW00101` | `copyBeanToToiawaseIns` | Display inquiry entry screen |
| `openCrw00101Upd()` | Inquiry Update | `CRW00101` | `copyBeanToToiawaseUpd` | Display inquiry update screen |
| `openCrw04001()` | Escalation Execution | `CRW04001` | `copyBeanToEscalation` | Display escalation execution screen |
| `openCrw03901()` | Inquiry Cancellation Registration | `CRW03901` | `copyBeanToCancel` | Display inquiry cancellation registration screen |
| `openCrw02603()` | Inquiry Customer Edit | `CRW02603` | `copyBeanToProscstUpd` | Display inquiry customer edit screen (with conditional screen ID logic) |
| `openCrw00401()` | Hotvoice Registration | `CRW00401` | `copyBeanToHotvoice` | Display hotvoice registration screen |
| `openCrw04101()` | Document Send Registration | `CRW04101` | `copyBeanToSendSiryo` | Display document send registration screen |
| `openCrw02401()` | Inquiry Customer List View | `CRW02401` | `copyBeanToProscstSearch` | Display inquiry customer list view screen |
| `openCrw00601()` | Memo Registration | `CRW00601` | `copyBeanToMemo` | Display memo registration screen |
| `openCrw00701()` | Mail Return | `CRW00701` | `copyBeanToMailHensin` | Display mail return screen |
| `openCrw00801()` | Mail Transfer | `CRW00801` | `copyBeanToMailTenso` | Display mail transfer screen |

**Note on `openCrw02603()`:** This method has special conditional logic. If neither inquiry customer number (`PROSCST_NO`) nor service contract number (`SVC_KEI_NO`) is set, it navigates to `SCREEN_ID_CRW02602` (parent) → `SCREEN_ID_CRW02601` (child). Otherwise it navigates to `SCREEN_ID_CRW02604` (parent) → `SCREEN_ID_CRW02603` (child). This appears to differentiate between new customer edit and existing customer edit scenarios.

### Transactional Actions (5 methods)

These methods invoke backend services to perform state changes on inquiry records, then refresh the screen:

#### `closeToiawase()` → boolean
Invokes the inquiry close service (`JCRWebCommon.execClose`) to close an inquiry record. After service execution, calls `refresh()` to update the screen.

#### `reject()` → boolean
Invokes the inquiry reject service (`JCRWebCommon.execReject`) to reject (回退) an inquiry record. After service execution, calls `refresh()` to update the screen.

#### `accept()` → boolean
Invokes the inquiry accept service (`JCRWebCommon.execAccept`) to approve (承認) an inquiry record. After service execution, calls `refresh()` to update the screen.

#### `getKyosei()` → boolean
Invokes the forced recovery service (`JCRWebCommon.execGetKyosei`) to perform a forced recovery (強制取得) / re-open operation on an inquiry record. After service execution, calls `refresh()`.

#### `restart()` → boolean
Invokes the inquiry re-open service (`JCRWebCommon.execRestart`) to re-open (再開) an inquiry record. After service execution, calls `refresh()`.

All five methods follow the same pattern: get beans, create paramBean array, invoke the service through `JCRWebCommon`, and call `refresh()` on completion.

#### `insertEasyMemo()` → boolean
Updates the easy memo (簡易メモ) for the current inquiry. Invokes `JCRWebCommon.execInsertEasyMemo` with the service bean, then calls `refresh()` to re-display the updated screen.

### Screen Refresh & Utilities

#### `refresh()` → boolean
Performs a full screen refresh of the inquiry response main screen. It:
1. Reloads screen info via `JCCWebCommon.getScreenInfo`
2. Calls `JCRWebCommon.refreshPage(bean, commoninfoBean, this)` to reload the inquiry history list screen data
3. Sets next screen navigation back to the current screen
4. If the previous screen was the document send registration screen (`CRW04101`), displays a specific info message (`EKB4390__I`) with the document send registration label and sets the screen ID back
5. Calls `init()` to fully re-initialize the screen

#### `getMainData()` → void
A private method that syncs inquiry response main data to a dedicated table. It gets the service form bean and sets the `STATUS` field in the bean to the value from `SHINSA_STA_NM` (審査ステータス名称 — approval status name). This is called at the end of `init()` as part of the mapping processing.

#### `openCrw03410()` → boolean
Displays the ID certificate re-issue information output screen (ID登録証再発行情報出力画面). Sets the `CRW03410_OPN_FLG` flag in the bean to `false`, then constructs a parameter map with URL info, web access NS key, web access NS key password, and expiration datetime from the bean. Sets the screen ID and passes these parameters as screen info to `SCREEN_ID_CRW03410`.

#### `executeCis()` → boolean
Handles the power CIS (New Electricity) button press (電力CISボタン押下処理). Delegates to `JCRWebCommon.executeCis(bean, commoninfoBean, this)` for the power CIS button processing, then sets next screen back to the current screen for self-navigation.

#### `executeKis()` → boolean
Handles the kis (light electricity) button press (光ボタン押下処理). Delegates to `JCRWebCommon.executeKis(bean, commoninfoBean, this)` for the light electricity button processing, then sets next screen back to the current screen.

#### `clickSaihakko()` → boolean
Handles the re-issue button press (再発行ボタン押下処理). Sets the `CRW03410_OPN_FLG` to `false`, sets the next screen to the current screen, and invokes the service via `CRSV0281_CRSV0281OPDBMapper` with user case ID `CRSV0281`. The mapping includes `setADDWEBACCESSNSKEYCC` for web access NS key setup. After service execution:

- If the result has an `err_info` flag set to `true` (indicating the SYSID is not a master member), displays an error message about the member type not being a master member (individual or corporate) and the re-issue action, then returns `true` to stay on the current screen.
- If there's a message result from the service invocation, displays the message and sets next screen info.

## Relationships

```mermaid
sequenceDiagram
    participant UI as UI Browser
    participant XML as XML Controller
    participant LOGIC as CRW03401SFLogic
    participant SVC as Backend Service
    participant COMMON as JCRWebCommon

    UI->>XML: User action button click
    XML->>LOGIC: execute action method
    LOGIC->>LOGIC: getServiceFormBean
    LOGIC->>LOGIC: getCommonInfoBean

    alt init or refresh flow
        LOGIC->>COMMON: getScreenInfo
        LOGIC->>COMMON: resetButtonStatus
        LOGIC->>SVC: invokeService with CRSV0084 mapper
        SVC-->>LOGIC: output data map
        LOGIC->>LOGIC: process results
        LOGIC->>COMMON: getJimFee
        LOGIC->>COMMON: replaceTendymd for date fields
        LOGIC->>LOGIC: getMainData
    else navigation flow
        LOGIC->>COMMON: setScreenId
        LOGIC->>COMMON: setScreenInfo
        LOGIC->>COMMON: copyBeanToXxx helper
    else action flow
        LOGIC->>SVC: invokeService with action service
        SVC-->>LOGIC: result
        LOGIC->>LOGIC: setMessageInfo on error
        LOGIC->>LOGIC: refresh self
    end

    COMMON-->>LOGIC: data returned
    LOGIC-->>XML: true
    XML-->>UI: next screen
```

### Inbound (2 dependents)

| Dependent | Type | Role |
|-----------|------|------|
| `WEBGAMEN_CRW034010PJP.xml` | XML | Web screen action definition that references this logic class to handle user interactions on the screen |
| `x31business_logic_CRW03401SF.xml` | XML | Business logic mapping that configures which methods are invoked for which screen actions |

### Outbound (1 dependency)

| Dependency | Type | Role |
|-----------|------|------|
| `JCCWebBusinessLogic` | Java base class | Provides the framework infrastructure: `getServiceFormBean()`, `getCommonInfoBean()`, `invokeService()`, and common message handling |

### Key Collaborators (via delegation)

The class delegates heavily to utility classes rather than containing business logic itself:

- **`JCRWebCommon`** — Screen info setup, bean copying helpers (over 15 `copyBeanToXxx` methods), service wrappers for actions (reject, accept, close, restart, etc.), MYBOX/QUEBOX/mail count refresh, easy memo, CIS/KIS processing, one-time password setup, screen refresh
- **`JCCWebCommon`** — Screen info retrieval, button status reset, message info display, screen ID management
- **`JZMWebCommon`** — Date placeholder replacement (`replaceTendymd`)
- **`JCRWebCommon.getJimFee()`** — Transaction fee calculation from settlement code, fee, and payment amount

## Usage Example

A typical user flow on the inquiry response main screen follows this pattern:

```
1. User arrives at screen → init() called → Full data load via CRSV0084 mapper
2. User clicks a tab → clickTab() → Updates counts, sets up sub-screen navigation
3. User clicks MYBOX link → clickLinkMyboxCnt() → Opens MYBOX pop-up screen
4. User clicks Reject button → reject() → Calls execClose service → refresh()
5. Screen re-initializes → init() called again → Fresh data from backend
```

The `init()` method is the entry point that performs the most work: it loads inherited screen state, resets UI button/link states, clears all message list arrays, determines whether to show the display flag based on inherited service contract number and SYSID, invokes a comprehensive CRSV0084 service that maps 16+ data structures between the form bean and the backend, processes results back into bean arrays, calculates fees, normalizes dates, and syncs the status to a dedicated table.

Screen transitions always follow the same template: set the parent screen ID via `setScreenId`, prepare sub-screen data via a `copyBeanToXxx` helper, set the sub-screen info via `setScreenInfo`, and register the next screen's ID and name in the shared common info bean. This pattern is consistent across all 12 sub-screen openers and the navigation methods.

## Notes for Developers

- **Thread safety:** The class has no instance fields (no mutable state). The static constants `SENYO_TAB_ID` and `SENYO_TAB_NAME` are immutable. Each method invocation is independent, relying on bean state passed through the framework. Thread safety depends on the framework's bean management.

- **The `init()` method is the most critical code path** — it handles the entire initial data load from the backend service. It uses a mapping class with 16+ set/get methods that map between the service form bean and a data map, then invokes the service and maps results back. If you need to add new data fields to the initial load, you'll need to add corresponding `set...SC` and `get...SC` methods to the `CRSV0084_CRSV0084OPDBMapper`.

- **The `refresh()` method always calls `init()` at the end** — this means any refresh operation triggers a full re-initialization of the screen with all data from the backend. Be aware that this is a potentially expensive operation.

- **The `openCrw02603()` method has unique conditional logic** that differs from all other sub-screen openers. It branches based on whether `PROSCST_NO` and `SVC_KEI_NO` are null, selecting different parent/child screen ID pairs. This is the only method in the class that doesn't use a `copyBeanToXxx` pattern for the bean copy.

- **Date placeholder replacement:** The class uses `20991231` as a sentinel value that gets replaced with blank via `JZMWebCommon.replaceTendymd`. This is a convention used throughout the application for date fields that have no meaningful end date.

- **Action methods (`reject`, `accept`, `closeToiawase`, `getKyosei`, `restart`, `insertEasyMemo`) always call `refresh()` after service execution** — this ensures the screen is fully reloaded after any state-changing operation. None of them navigate to a different screen; they all stay on the current screen with refreshed data.

- **Service invocation uses mapping mappers:** Direct service calls use the `CRSV0084_CRSV0084OPDBMapper` (for init) and `CRSV0281_CRSV0281OPDBMapper` (for re-issue). All other actions delegate to `JCRWebCommon` helper methods. The `invokeService(paramMap, dataMap, outputMap)` method sets the user case ID in `paramMap` and is called through the framework's service invocation infrastructure.

- **Error handling in `clickSaihakko()`:** This method has special error handling that checks for the `err_info` flag in the output map and displays a specific error message if the SYSID is not a master member. This is one of the few methods that does meaningful error handling beyond calling `setMessageInfo` on the message result.

- **Japanese comments throughout:** The source code is extensively commented in Japanese. The comments follow a consistent 6-section structure matching the action method lifecycle. Code change identifiers (e.g., `OM-2018-0000279`, `ANK-2267-00-00`) appear in comments marking feature additions and modifications.

- **`receiveMessageWeb` is intentionally empty:** This overridden method returns `false` and does nothing. It's a framework-required override that simply prevents the parent class from handling messages that this screen doesn't need to process directly.

- **The class manages navigation to 15+ distinct sub-screens** from a single main screen. Each sub-screen has its own dedicated `copyBeanToXxx` helper method in `JCRWebCommon`, which prepares the data that the sub-screen will need.
