# Eo / Web / Webview / Kkw22501sf

## Overview

The `KKW22501SF` package is the view logic layer for the **Dealer Event CP Setting Screen** (代理店イベントCP設定画面). It provides a web interface for managing data extraction item settings for campaigns associated with dealers. Users can search for existing settings, create new ones, modify them, and delete them — all within a single screen backed by the X31/X33 web framework.

The module acts as the bridge between the JSP view (`KKW225010PJP.jsp`) and the underlying business service (`KKSV0940`), handling screen initialization, search operations, CRUD actions, and Ajax-driven campaign name lookups.

## Key Classes and Interfaces

### [KKW22501SFLogic](source/koptWebB/src/eo/web/webview/KKW22501SF/KKW22501SFLogic.java) — View Business Logic

This is the core controller class, extending `JCCWebBusinessLogic`. It orchestrates every user action on the Dealer Event CP Setting screen.

**Key methods:**

- **`actionInit()`** — Initial screen display processing. Retrieves screen info into the service form bean, sets the screen name in the shared info bean, initializes the detail display flag to `"0"` (hidden), and logs the DataBean state.

- **`actionSearch()`** — Search processing. Sets screen migration metadata, calls `beforeSearch()` to clear all list arrays, then delegates to `execSearch()` which maps form data to service parameters via [KKSV0940_KKSV0940OPDBMapper](source/koptWebB/src/eo/web/webview/mapping/KKSV0940_KKSV0940OPDBMapper.java), invokes the `KKSV0940/KKSV0940OP` business service, and maps results back. After search, it sets a default "receipt end date" of `20991231` and checks for empty results, setting error messages (`EKB0740_KW` for no dealer, `EKBF310__I` for no data).

- **`actionAdd()`** — Register (create) processing. Validates the receipt start date is not before the operation date (error `EKB0260_NW`), then calls `isUkYmdCheck()` to ensure no date range overlaps with existing entries. Verifies at least one of three result keys (`rslt_kbn_1`, `rslt_kbn_2`, `rslt_kbn_3`) is populated — otherwise throws `EKBE121_KW`. After calling the service, sets confirmation messages based on which operation type (register/change/delete) actually occurred.

- **`actionReset()`** — Reset button handler. Clears all search fields and list arrays, hides the detail section, and calls `actionInit()` to return the screen to its initial state.

- **`searchCampaignCdAjax()`** — Ajax handler for asynchronously retrieving campaign names when a campaign code is entered. Validates the campaign code is at least 8 characters long, then calls `getCampaignCdInfo()` to query the service with process type `"02"` (CP search).

- **`isUkYmdCheck()`** — Date overlap validation. Iterates through all non-deleted rows in the data extraction item setting list and checks whether the proposed start date falls within any existing entry's `[start, end]` range. If an overlap is found, it returns `false` and sets error `EKBF320_NW`.

**Process type constants:**
| Constant | Value | Meaning |
|---|---|---|
| `PROCESS_KBN_01` | `"01"` | Search |
| `PROCESS_KBN_02` | `"02"` | CP search (Ajax) |
| `PROCESS_KBN_03` | `"03"` | Register / Change / Delete |

### [KKW22501SFBean](source/koptWebB/src/eo/web/webview/KKW22501SF/KKW22501SFBean.java) — Main Form View Bean

This is the primary form bean, extending `X33VViewBaseBean` and implementing `X33VListedBeanInterface` and `X31CBaseBean`. It holds all screen-level properties: search conditions, flags, buttons, and the three data lists that drive the table display.

**Constructor** initializes three `X33VDataTypeList` collections: `dchskm_sete_jkn_list_list`, `bf_dchskm_sete_jkn_list_list`, and `dchskm_list_list`.

**Search condition fields** (each with `update`, `value`, and `state` variants):
- `search_agnt_cd` — Dealer code
- `search_campaign_cd` — Data extraction item code (display)
- `search_dchskm_cd` — Data extraction item code (for registration)
- `search_campaign_nm` — Data extraction item name
- `agnt_set_campaign_staymd` / `agnt_set_campaign_endymd` — Receipt start/end year-month

**Flag fields** (with `enabled` property for button states):
- `search_flg` / `del_flg` / `reset_flg` — Action button flags
- `dtl_dsp_flg` — Detail display flag
- `search_err_flg_zero` — Search error flag (default `"1"`)
- `process_kbn` — Process type discriminator

**List fields** (rendered as data-type-bean lists):
- `dchskm_sete_jkn_list_list` — Data extraction item setting list (Event CP) detail
- `bf_dchskm_sete_jkn_list_list` — Pre-change data extraction item setting list (Event CP) detail
- `dchskm_list_list` — Data extraction item list detail

**`loadModelData(String key, String subkey)`** — A comprehensive dynamic accessor. It supports multiple access patterns:
- Simple key with subkey (`"value"`, `"enable"`, `"state"`) for scalar properties
- Indexed key (`"Key/0/value"`) for accessing individual items within a list
- Wildcard key (`"Key/*"`) to get list sizes
- Shared info bean keys prefixed with `//`

### [KKW22501SF01DBean](source/koptWebB/src/eo/web/webview/KKW22501SF/KKW22501SF01DBean.java) — Detail List Item Bean

This bean represents a single row in the **data extraction item setting list (Event CP) detail** table. It implements `X33VDataTypeBeanInterface`, enabling it to be stored inside `X33VDataTypeList` collections.

**Properties per row:**
| Property | Type | Description |
|---|---|---|
| `agnt_cd` | String | Dealer code (with `enabled`, `state`) |
| `agnt_nm` | String | Dealer name (with `enabled`, `state`) |
| `dsp_dchskm_cd` | String | Display data extraction item code (with `enabled`, `state`) |
| `uk_sta_ymdhm` | String | Usage start date-time (with `enabled`, `state`) |
| `uk_end_ymdhm` | String | Usage end date-time (with `enabled`, `state`) |
| `dchskm_cd` | String | Data extraction item code (for change) |
| `dchskm_sete_jkn_no` | String | Data extraction item setting number (for change) |
| `upd_dtm` | String | Update date-time |
| `del_check` | Boolean | Delete checkbox (with `enabled`, `state`) |
| `index` | int | Row index |

**Dynamic access methods:**
- **`loadModelData(key, subkey)`** — Returns field values by key (e.g., `"dealer code"/"value"` → `agnt_cd_value`). Supports `"value"`, `"enable"`, and `"state"` subkeys.
- **`storeModelData(key, subkey, in_value)`** — Sets field values by key.
- **`listKoumokuIds()`** — Returns the list of valid field keys: `"dealer code"`, `"dealer name"`, `"display data extraction item code"`, etc.
- **`typeModelData(key, subkey)`** — Returns the `Class<?>` type for a given field (e.g., `String.class` for values, `Boolean.class` for enable flags).

### [KKW22501SF02DBean](source/koptWebB/src/eo/web/webview/KKW22501SF/KKW22501SF02DBean.java) — Data Extraction Item Bean

Similar to `01DBean` but represents the **data extraction item list detail** — a simpler structure with only three fields:
| Property | Type | Description |
|---|---|---|
| `dchskm_cd` | String | Data extraction item code (with `enabled`, `state`) |
| `dchskm_nm` | String | Data extraction item name (with `enabled`, `state`) |
| `upd_dtm` | String | Update date-time |

Also implements `X33VDataTypeBeanInterface` and provides `loadModelData`, `storeModelData`, `listKoumokuIds`, and `typeModelData` for dynamic field access.

### [KKW22501SFChecker](source/koptWebB/src/eo/web/webview/KKW22501SF/KKW22501SFChecker.java) — GUI Checker

Implements `X31SGuiCheckBase`. At present, the `checkMethod` simply returns `true` for all pattern IDs — it is a **stub** with no actual validation logic. This class is wired into the XML configuration for screen-level GUI checks but currently delegates all validation to the business logic methods in `KKW22501SFLogic`.

### [KKW22501SFConst](source/koptWebB/src/eo/web/webview/KKW22501SF/KKW22501SFConst.java) — Constants

Holds all field key constants used throughout the module as String keys for DataBean access. Examples:
- `SEARCH_AGNT_CD` — `"dealer code"`
- `DCHSKM_SETE_JKN_LIST` — `"data extraction item setting list (Event CP) detail"`
- `DTL_DSP_FLG` — `"detail display flag"`
- `PROCESS_KBN` — `"process discriminator"`
- `AGNT_CD_01` through `DEL_CHECK_01` — Keys for the 01DBean row fields
- `DCHSKM_CD_02`, `DCHSKM_NM_02`, `UPD_DTM_02` — Keys for the 02DBean fields

## How It Works

### Request Flow

```mermaid
flowchart TD
    subgraph Views["JSP View Layer"]
        JSP["KKW225010PJP.jsp"]
    end

    subgraph Forms["Form Beans"]
        Bean["KKW22501SFBean<br/>Main form view bean"]
        DBean01["KKW22501SF01DBean<br/>Detail list item bean"]
        DBean02["KKW22501SF02DBean<br/>Extraction item bean"]
    end

    subgraph Logic["Logic Layer"]
        Logic["KKW22501SFLogic<br/>View business logic"]
        Checker["KKW22501SFChecker<br/>GUI checker (stub)"]
    end

    subgraph Constants["Constants"]
        Const["KKW22501SFConst<br/>Field key constants"]
    end

    subgraph Services["External Services"]
        Mapper["KKSV0940_KKSV0940OPDBMapper"]
        Service["KKSV0940 / KKSV0940OP<br/>Business service"]
    end

    JSP -->|uses| Bean
    JSP -->|uses| DBean01
    Bean -->|contains| DBean01
    Bean -->|contains| DBean02
    Bean -->|called by| Logic
    Logic -->|instantiates| DBean01
    Logic -->|instantiates| DBean02
    Logic -->|calls| Mapper
    Mapper -->|maps| Service
    Logic -->|references| Const
    Checker -->|implements| Logic
```

### Screen Initialization (`actionInit`)

1. Reads screen info from the shared context.
2. Sets the next screen name in the common info bean.
3. Initializes the detail display flag to `"0"` (hidden).
4. Logs the DataBean state for debugging.

### Search Flow (`actionSearch`)

1. `beforeSearch()` hides the detail section and clears all three list arrays (`dchskm_sete_jkn_list`, `bf_dchskm_sete_jkn_list`, `dchskm_list`), ensuring a clean slate.
2. Sets `process_kbn` to `"01"` (search mode).
3. `execSearch()` maps the search condition DataBean fields to service input parameters via `KKSV0940_KKSV0940OPDBMapper.setKKSV094001CC()`, invokes the service, and maps output back.
4. Sets the default receipt end date to `20991231`.
5. If no dealer was found (`dtl_dsp_flg == "0"`), displays error `EKB0740_KW`. If results exist but the first row has an empty code, displays error `EKBF310__I`.

### Add Flow (`actionAdd`)

1. Maps form data to the service input map.
2. Sets `process_kbn` to `"03"` (CRUD mode).
3. Validates the receipt start date is not before the operation date (`EKB0260_NW`).
4. Validates no date range overlaps with existing entries via `isUkYmdCheck()` (`EKBF320_NW`).
5. Skips rows marked with `del_check = true`.
6. Validates at least one of `rslt_kbn_1`/`rslt_kbn_2`/`rslt_kbn_3` is populated — otherwise throws `EKBE121_KW` (no input data).
7. Invokes the service and sets appropriate confirmation messages.
8. Calls `actionReset()` to return the screen to initial state.

### Reset Flow (`actionReset`)

1. Clears all search condition fields.
2. Clears all list arrays and sets `dtl_dsp_flg` to `"0"`.
3. Calls `actionInit()` to restore the initial screen state.

### Ajax Campaign Lookup (`searchCampaignCdAjax`)

1. Sets self-screen ID.
2. Retrieves the campaign code from the form bean.
3. Validates the code is at least 8 characters long.
4. Calls `getCampaignCdInfo()` which invokes the same service with `process_kbn = "02"` (CP search).
5. Maps the result back to populate the campaign name field.

### Date Overlap Validation (`isUkYmdCheck`)

For each non-deleted row in the data extraction item setting list, compares the proposed start date against that row's `[start, end]` range. If `proposed_start >= row_start && proposed_start <= row_end`, an overlap error is raised for that row's `uk_end_ymdhm` field.

## Data Model

The module manages three primary data structures, all backed by `X33VDataTypeList`:

### dchskm_sete_jkn_list (Event CP setting detail)

The primary working list, stored as `X33VDataTypeList` of `KKW22501SF01DBean` instances. Each row represents one data extraction item setting:

```
dchskm_sete_jkn_list[0] = KKW22501SF01DBean {
    agnt_cd_value = "A001",
    agnt_nm_value = "Dealer A",
    dsp_dchskm_cd_value = "ITEM001",
    uk_sta_ymdhm_value = "20240101000000",
    uk_end_ymdhm_value = "20241231235959",
    dchskm_cd_value = "ITEM001",
    dchskm_sete_jkn_no_value = "1",
    upd_dtm_value = "20240101000000",
    del_check_value = false,
    index = 0
}
```

### bf_dchskm_sete_jkn_list (Pre-change data extraction item setting)

Stores the original values before a change operation. Uses the same structure as the main setting list but reflects the state before the user's edits.

### dchskm_list (Data extraction item detail)

A simpler list of `KKW22501SF02DBean` instances used to display available data extraction items:

```
dchskm_list[0] = KKW22501SF02DBean {
    dchskm_cd_value = "ITEM001",
    dchskm_nm_value = "Item Name One",
    upd_dtm_value = "20240101000000"
}
```

Each property in the DBeans follows a consistent pattern with three variants: `value` (the actual data), `enabled` (boolean for UI control), and `state` (status string for validation feedback). The `update` variants track whether a field was modified.

## Dependencies and Integration

### Inbound (who uses this module)

| Consumer | Uses |
|---|---|
| `KKW225010PJP.jsp` | `KKW22501SF01DBean`, `KKW22501SFBean` |
| `WEBGAMEN_KKW225010PJP.xml` | `KKW22501SFBean`, `KKW22501SFLogic` |
| `x31business_logic_KKW22501SF.xml` | `KKW22501SFLogic` |

### Outbound (what this module depends on)

| Dependency | Usage |
|---|---|
| `KKSV0940_KKSV0940OPDBMapper` | Maps DataBean fields to/from the `KKSV0940` business service |
| `KKSV0940 / KKSV0940OP` | The underlying business service for data extraction item operations |
| `JCCWebBusinessLogic` | Base class providing `invokeService()`, `getServiceFormBean()`, etc. |
| `JPCOnlineMessageConstant` | Error message constant keys (`EKB0260_NW`, `EKB0740_KW`, etc.) |
| `JPCDateUtil` | Date comparison utilities (e.g., `subtractDay()`) |
| `JKKWebCommon`, `JKKGetDataUtil`, `JKKScreenConst` | Shared screen utilities and constants |
| `CommonInfoCF.CommonInfoCFConst` | Shared information bean constants |

## Notes for Developers

- **GUI Checker is a stub.** `KKW22501SFChecker.checkMethod()` always returns `true`. All validation logic lives in `KKW22501SFLogic` methods (`isUkYmdCheck`, date comparisons, etc.). If you need to add GUI-level validation, this is where it would go.

- **Process type routing.** The module uses `process_kbn` to tell the backend service what operation to perform: `"01"` for search, `"02"` for CP search (Ajax), `"03"` for CRUD. This single field controls the entire operation flow.

- **Date overlap validation is row-level.** `isUkYmdCheck()` checks each proposed date against all non-deleted rows. The error message targets the specific `uk_end_ymdhm_` field of the conflicting row, so the user can identify which entry causes the overlap.

- **Default end date.** After every search, the receipt end date is hardcoded to `"20991231"`. This is a placeholder indicating no effective end date until one is explicitly set.

- **List access pattern.** All three `X33VDataTypeList` fields support dynamic access via `loadModelData(key/subkey)`. To access an indexed item, use the format `"ListName/index/field"`. To get the list size, use `"ListName/*"`. This pattern is consistent across `KKW22501SFBean`, `KKW22501SF01DBean`, and `KKW22501SF02DBean`.

- **Three result keys.** The `actionAdd()` method checks `rslt_kbn_1`, `rslt_kbn_2`, and `rslt_kbn_3` to determine whether the service performed a register, change, or delete operation. All three must be empty to trigger the "no data" error.

- **All source files are auto-generated.** The bean classes (`*Bean.java`) are generated by the Web Client tool / DataBean definition tool. The logic class (`KKW22501SFLogic.java`) is the only hand-written file. Avoid modifying generated bean properties directly — use the provided getter/setter methods or the `loadModelData`/`storeModelData` dynamic accessors.
