# Business Logic — JKKCancelSvcWribCC.editInEKK0451C070() [100 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKCancelSvcWribCC` |
| Layer | CC/Common Component (Package: `com.fujitsu.futurity.bp.custom.common`) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKCancelSvcWribCC.editInEKK0451C070()

This method performs the **upper mapping processing** (上りマッピング処理 — upstream data mapping) for discount service contract cancellation. It is the data preparation step that transforms incoming work-area business data into a structured CAANMsg template (EKK0451C070CBSMsg) ready to be passed downstream to a Service Component (SC) for actual cancellation execution.

The method follows a **delegation + templating pattern**: it instantiates a strongly-typed response template (CAANMsg), populates it with control data (operator ID, operate date, function code) pulled from the request parameter map, then iteratively maps each business-relevant field from a source HashMap (`workBeanListMap`) into the template — or nullifies it when the source field is missing, null, or empty. This ensures the downstream SC receives a well-formed, always-initialized message regardless of data quality upstream.

It serves as a **shared utility method** within the discount/writable service cancellation subsystem, called by `JKKCancelSvcWribCC.cancelSvcWrib()` — the main cancellation orchestrator. The method does not perform any database access or service calls itself; it is purely a data transformation layer. The `kbn=1` flag in `getDtmMax()` indicates this handler is specialized for the **discount (writable) / coupon** service type, as opposed to `kbn=2` which handles the **accommodation/alternate** service type.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editInEKK0451C070(params)"])

    START --> CREATE_TEMPLATE["Create CAANMsg template (EKK0451C070CBSMsg)"]

    CREATE_TEMPLATE --> SET_TEMPLATEID["Set TEMPLATEID = \"EKK0451C070\""]
    SET_TEMPLATEID --> SET_FUNC_CODE["Set FUNC_CODE = func_code param"]

    SET_FUNC_CODE --> SET_OPERATOR["Set OPERATOR_ID, OPERATE_DATE, OPERATE_DATETIME from param"]

    SET_OPERATOR --> INIT_WORKMAP["Get / init workMap from param"]

    INIT_WORKMAP --> CHECK_WRIB["workBeanListMap == null || wrib_svc_kei_no empty?"]
    CHECK_WRIB -->|Yes| SET_NULL_WRIB["setNull(WRIB_SVC_KEI_NO)"]
    CHECK_WRIB -->|No| SET_WRIB["set(WRIB_SVC_KEI_NO, value)"]
    SET_NULL_WRIB --> CHECK_MSKM
    SET_WRIB --> CHECK_MSKM["workBeanListMap == null || mskm_dtl_no empty?"]

    CHECK_MSKM -->|Yes| SET_NULL_MSKM["setNull(MSKM_DTL_NO)"]
    CHECK_MSKM -->|No| SET_MSKM["set(MSKM_DTL_NO, value)"]
    SET_NULL_MSKM --> CHECK_RSN
    SET_MSKM --> CHECK_RSN["workBeanListMap == null || svc_cancel_rsn_cd empty?"]

    CHECK_RSN -->|Yes| SET_NULL_RSN["setNull(SVC_CANCEL_RSN_CD)"]
    CHECK_RSN -->|No| SET_RSN["set(SVC_CANCEL_RSN_CD, value)"]
    SET_NULL_RSN --> CHECK_IDO
    SET_RSN --> CHECK_IDO["workBeanListMap == null || ido_div empty?"]

    CHECK_IDO -->|Yes| SET_NULL_IDO["setNull(IDO_DIV)"]
    CHECK_IDO -->|No| SET_IDO["set(IDO_DIV, value)"]
    SET_NULL_IDO --> CHECK_CNCL
    SET_IDO --> CHECK_CNCL["workBeanListMap == null || wrib_dsl_cncl_opty_cd empty?"]

    CHECK_CNCL -->|Yes| SET_NULL_CNCL["setNull(WRIB_DSL_CNCL_OPTY_CD)"]
    CHECK_CNCL -->|No| SET_CNCL["set(WRIB_DSL_CNCL_OPTY_CD, value)"]
    SET_NULL_CNCL --> CALL_GETDTM
    SET_CNCL --> CALL_GETDTM["Call getDtmMax(param, 1, listNo, wribSvcCdList)"]

    CALL_GETDTM --> CHECK_MAXDTM["maxDtm == empty?"]

    CHECK_MAXDTM -->|Yes| CHECK_UPD_BF["workBeanListMap == null || upd_dtm_bf empty?"]
    CHECK_UPD_BF -->|Yes| SET_NULL_UPD["setNull(UPD_DTM_BF)"]
    CHECK_UPD_BF -->|No| SET_UPD_BF["set(UPD_DTM_BF, value from workBeanListMap)"]
    SET_NULL_UPD --> END_RETURN
    SET_UPD_BF --> END_RETURN

    CHECK_MAXDTM -->|No| SET_UPD_MAX["set(UPD_DTM_BF, maxDtm)"]
    SET_UPD_MAX --> END_RETURN

    END_RETURN(["Return template"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter container carrying control data (operator ID, operate date/time) and the mapping work area. It serves as the bidirectional bridge between the caller's request context and the mapped output template. |
| 2 | `workBeanListMap` | `HashMap` | A HashMap holding the business data fields for a single discount service contract cancellation record. Keys include `wrib_svc_kei_no` (discount service contract number), `mskm_dtl_no` (application detail number), `svc_cancel_rsn_cd` (service cancellation reason code), `ido_div` (migration division), `wrib_dsl_cncl_opty_cd` (discount contract cancellation opportunity code), and `upd_dtm_bf` (update date/time before). This is the primary source of data mapped into the output template. |
| 3 | `func_code` | `String` | The function code identifying the business operation type. Typically `"1"` indicating the discount/writable service cancellation function. Passed through verbatim into the template's FUNC_CODE field. |
| 4 | `listNo` | `String` | The list entry number used as a key to match records within `wribSvcCdList`. Used by `getDtmMax()` to find the relevant service contract records in the list and determine the latest update timestamp. |
| 5 | `wribSvcCdList` | `ArrayList` | An ArrayList of HashMaps containing the service contract records for the discount/writable service type. Each entry has `list_no`, `svc_kei_no`, and `upd_dtm_bf` fields. Used by `getDtmMax()` (with `kbn=1`) to find the maximum update date across matching records, which determines the canonical cancellation timestamp. |

**Instance fields read by the method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `wribSvcKei` | `HashMap<String, String>` | Stores service contract numbers mapped to their latest update date/time for discount (writable) services (kbn=1). Used internally by `getDtmMax()` to accumulate per-contract timestamps. |
| `hanyoSvcKei` | `HashMap<String, String>` | Stores service contract numbers mapped to their latest update date/time for accommodation/alternate services (kbn=2). Not used in this method's execution path (kbn=1 only), but accessed within `getDtmMax()`. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKCancelSvcWribCC.getDtmMax` | - | - | Calls `getDtmMax` in `JKKCancelSvcWribCC` — reads service contract data to find the maximum (latest) update timestamp for a given list entry. Delegates to `JKKBpCommon.getLastDtmBySvcKeiNo`. |
| R | `JKKBpCommon.getLastDtmBySvcKeiNo` | - | - | Called internally by `getDtmMax` — retrieves the last update datetime by service contract number from the work area. |
| - | `EKK0451C070CBSMsg` | EKK0451C070 | - | The CBS message schema/template class. Fields `WRIB_SVC_KEI_NO`, `MSKM_DTL_NO`, `SVC_CANCEL_RSN_CD`, `IDO_DIV`, `WRIB_DSL_CNCL_OPTY_CD`, `UPD_DTM_BF` are set or nullified into this template. |

### Analysis Notes:

This method is a **pure data mapper** — it does not directly perform any database CRUD. All data retrieval flows through `getDtmMax()` → `JKKBpCommon.getLastDtmBySvcKeiNo()` which reads from the work area / session. The downstream SC (EKK0451C070CBS) that receives this template is responsible for the actual database operations (read, update, or cancel the discount service contract).

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `getDtmMax` (via `getLastDtmBySvcKeiNo`) | - | Work area / session data | Reads the latest update datetime for a service contract to determine the canonical cancellation timestamp. |
| - | `CAANMsg template` (EKK0451C070CBSMsg schema) | EKK0451C070 | - | Constructs output template with control data (TEMPLATEID="EKK0451C070", FUNC_CODE, OPERATOR_ID, OPERATE_DATE, OPERATE_DATETIME) and mapped business fields. |

## 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: `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `getDtmMax` [R], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-], `setNull` [-]  # NOSONAR

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0568 | `KKSV0568OPOperation.target3` (CCRequestBroker) → `JKKCancelSvcWribCC.cancelSvcWrib` → `editInEKK0451C070` | `CAANMsg template (EKK0451C070CBSMsg)` |
| 2 | Screen:KKSV0082 | `KKSV0082OPOperation.target66` (CCRequestBroker) → `JKKCancelSvcWribCC.cancelSvcWrib` → `editInEKK0451C070` | `CAANMsg template (EKK0451C070CBSMsg)` |

**Caller Details:**
- **KKSV0568**: Screen for discount/writable service cancellation (KKSV056801CC). Invokes `cancelSvcWrib` which iterates over `wribSvcCdList`, groups by `listNo`, and calls `editInEKK0451C070` for each unique list entry.
- **KKSV0082**: Screen for service contract change/cancellation (KKSV008254CC). Similar invocation pattern through `cancelSvcWrib` to process discount service contract cancellations.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] (L182-L192)

> Instantiate the CAANMsg template and set control/header fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `template = new CAANMsg(EKK0451C070CBSMsg.class.getName())` // Create CBS message template [-> EKK0451C070] |
| 2 | SET | `template.set(EKK0451C070CBSMsg.TEMPLATEID, "EKK0451C070")` // Set template ID [-> "EKK0451C070"] |
| 3 | SET | `template.set(EKK0451C070CBSMsg.FUNC_CODE, func_code)` // Set function code [from param] |
| 4 | SET | `operatorId = param.getControlMapData(SCControlMapKeys.OPERATOR_ID)` // Get operator ID [from control map] |
| 5 | SET | `template.set(JCMConstants.OPERATOR_ID_KEY, operatorId)` // Set operator ID in template |
| 6 | SET | `operateDate = param.getControlMapData(SCControlMapKeys.OPE_DATE)` // Get operate date [from control map] |
| 7 | SET | `template.set(JCMConstants.OPERATE_DATE_KEY, operateDate)` // Set operate date in template |
| 8 | SET | `operateDateTime = param.getControlMapData(SCControlMapKeys.OPE_TIME)` // Get operate date/time [from control map] |
| 9 | SET | `template.set(JCMConstants.OPERATE_DATETIME_KEY, operateDateTime)` // Set operate datetime in template |

**Block 2** — [SET / IF-ELSE] (L195-L199)

> Initialize the work area mapping. If null, create an empty HashMap.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workMap = param.getMappingWorkArea()` // Get work area mapping from param |
| 2 | IF | `workMap == null` [L196] |
| 2.1 | SET | `workMap = new HashMap()` // [-> L197: create new empty HashMap] |
| 2.2 | EXEC | `param.setMappingWorkArea(workMap)` // [-> L198: set into param] |

**Block 3** — [IF-ELSE chain] — WRIB_SVC_KEI_NO (discount service contract number) (L201-L206)

> Map the discount service contract number. Nullifies if the source is missing/null/empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `workBeanListMap == null \|\| workBeanListMap.get("wrib_svc_kei_no") == null \|\| "".equals(workBeanListMap.get("wrib_svc_kei_no"))` [L201] |
| 1.1 | SET | `template.setNull(EKK0451C070CBSMsg.WRIB_SVC_KEI_NO)` // [-> L202: nullify field] |
| 1.2 | ELSE | [L204] |
| 1.2.1 | SET | `template.set(EKK0451C070CBSMsg.WRIB_SVC_KEI_NO, (String)workBeanListMap.get("wrib_svc_kei_no"))` // [-> L205: set value] |

**Block 4** — [IF-ELSE chain] — MSKM_DTL_NO (application detail number) (L207-L212)

> Map the application detail number. Nullifies if the source is missing/null/empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `workBeanListMap == null \|\| workBeanListMap.get("mskm_dtl_no") == null \|\| "".equals(workBeanListMap.get("mskm_dtl_no"))` [L207] |
| 1.1 | SET | `template.setNull(EKK0451C070CBSMsg.MSKM_DTL_NO)` // [-> L208: nullify field] |
| 1.2 | ELSE | [L210] |
| 1.2.1 | SET | `template.set(EKK0451C070CBSMsg.MSKM_DTL_NO, (String)workBeanListMap.get("mskm_dtl_no"))` // [-> L211: set value] |

**Block 5** — [IF-ELSE chain] — SVC_CANCEL_RSN_CD (service cancellation reason code) (L213-L218)

> Map the service cancellation reason code. Nullifies if the source is missing/null/empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `workBeanListMap == null \|\| workBeanListMap.get("svc_cancel_rsn_cd") == null \|\| "".equals(workBeanListMap.get("svc_cancel_rsn_cd"))` [L213] |
| 1.1 | SET | `template.setNull(EKK0451C070CBSMsg.SVC_CANCEL_RSN_CD)` // [-> L214: nullify field] |
| 1.2 | ELSE | [L216] |
| 1.2.1 | SET | `template.set(EKK0451C070CBSMsg.SVC_CANCEL_RSN_CD, (String)workBeanListMap.get("svc_cancel_rsn_cd"))` // [-> L217: set value] |

**Block 6** — [IF-ELSE chain] — IDO_DIV (migration division) (L219-L224)

> Map the migration division field. Nullifies if the source is missing/null/empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `workBeanListMap == null \|\| workBeanListMap.get("ido_div") == null \|\| "".equals(workBeanListMap.get("ido_div"))` [L219] |
| 1.1 | SET | `template.setNull(EKK0451C070CBSMsg.IDO_DIV)` // [-> L220: nullify field] |
| 1.2 | ELSE | [L222] |
| 1.2.1 | SET | `template.set(EKK0451C070CBSMsg.IDO_DIV, (String)workBeanListMap.get("ido_div"))` // [-> L223: set value] |

**Block 7** — [IF-ELSE chain] — WRIB_DSL_CNCL_OPTY_CD (discount contract cancellation opportunity code) (L225-L230)

> Map the discount contract cancellation opportunity code. Nullifies if the source is missing/null/empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `workBeanListMap == null \|\| workBeanListMap.get("wrib_dsl_cncl_opty_cd") == null \|\| "".equals(workBeanListMap.get("wrib_dsl_cncl_opty_cd"))` [L225] |
| 1.1 | SET | `template.setNull(EKK0451C070CBSMsg.WRIB_DSL_CNCL_OPTY_CD)` // [-> L226: nullify field] |
| 1.2 | ELSE | [L228] |
| 1.2.1 | SET | `template.set(EKK0451C070CBSMsg.WRIB_DSL_CNCL_OPTY_CD, (String)workBeanListMap.get("wrib_dsl_cncl_opty_cd"))` // [-> L229: set value] |

**Block 8** — [CALL] — GetDtmMax (L233)

> Retrieve the maximum (latest) update datetime for service contracts matching the given listNo from wribSvcCdList. The `kbn=1` flag specifies this is for discount/writable services (割引). Internally calls `JKKBpCommon.getLastDtmBySvcKeiNo` for each matching record and tracks the latest timestamp.

| # | Type | Code |
|---|------|------|
| 1 | SET | `maxDtm = getDtmMax(param, 1, listNo, wribSvcCdList)` // kbn=1 means discount (割引) / coupon [-> L233] |

**Block 9** — [IF-ELSE chain] — UPD_DTM_BF (update date/time before) (L236-L249)

> Map the update date/time before field. If `maxDtm` was returned (non-empty) by `getDtmMax`, use that as the authoritative timestamp. Otherwise, fall back to the value from `workBeanListMap`, nullifying if it's also empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `"".equals(maxDtm)` [L236 — "maxDtm is empty" branch] |
| 1.1 | IF | `workBeanListMap == null \|\| workBeanListMap.get("upd_dtm_bf") == null \|\| "".equals(workBeanListMap.get("upd_dtm_bf"))` [L237] |
| 1.1.1 | SET | `template.setNull(EKK0451C070CBSMsg.UPD_DTM_BF)` // [-> L238: nullify field] |
| 1.1.2 | ELSE | [L240] |
| 1.1.2.1 | SET | `template.set(EKK0451C070CBSMsg.UPD_DTM_BF, (String)workBeanListMap.get("upd_dtm_bf"))` // [-> L241: set value from workBeanListMap] |
| 1.2 | ELSE | [L245 — maxDtm has a value] |
| 1.2.1 | SET | `template.set(EKK0451C070CBSMsg.UPD_DTM_BF, maxDtm)` // [-> L246: use the maxDtm from getDtmMax as authoritative update time] |

**Block 10** — [RETURN] (L251)

> Return the fully populated CAANMsg template to the caller.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return template` // Returns the mapped CAANMsg ready for SC invocation [-> L251] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `wrib_svc_kei_no` | Field | Discount service contract number — the unique identifier for a discount/writable service line item in the telecom billing system. "Wrib" is shorthand for "writable" (割引情報 — discount information). |
| `mskm_dtl_no` | Field | Application detail number — the line-level detail identifier for a service contract application record. Tracks individual application entries. |
| `svc_cancel_rsn_cd` | Field | Service cancellation reason code — a coded value indicating the reason for service cancellation (e.g., customer request, service discontinuation, etc.). |
| `ido_div` | Field | Migration division — indicates the migration type or category for the service contract (e.g., new connection, transfer between services). |
| `wrib_dsl_cncl_opty_cd` | Field | Discount contract cancellation opportunity code — identifies the business opportunity or campaign context for the discount cancellation. |
| `upd_dtm_bf` | Field | Update date/time before (before update) — the timestamp of the last update prior to the current cancellation operation. Used for optimistic concurrency control. |
| `kbn` | Field | Classification (区分) — a binary flag where `1` = discount/writable (割引) service and `2` = accommodation/alternate (漢用) service. |
| `listNo` | Field | List entry number — an index/key identifying which entry within a batch of service contracts is being processed. |
| `wribSvcCdList` | Field | Discount service code list — ArrayList of HashMaps containing all service contract records for the discount/writable service type in the current batch. |
| `func_code` | Field | Function code — identifies the business function being invoked (typically "1" for discount service cancellation). |
| EKK0451C070 | SC Code | Discount service contract cancellation CBS message schema — the Service Component / CBS message definition for processing discount service contract cancellations. |
| CAANMsg | Type | Canonical message wrapper — the standard message container class in the Futurity framework, used to pass structured data between CC (Common Component) and SC (Service Component) layers. |
| CC | Acronym | Common Component — a reusable business logic component in the Fujitsu Futurity framework that sits between screens and Service Components. `JKKCancelSvcWribCC` is a custom CC for discount service cancellation. |
| SC | Acronym | Service Component — the data access / business processing layer that executes against the database. EKK0451C070CBS is the SC for discount service contract cancellation. |
| CBS | Acronym | Core Business System — refers to the CBS message (cbsmsg) classes that define the schema for data exchanged between application layers. EKK0451C070CBSMsg defines the field structure. |
| JKKBpCommon | Class | Joint-Kyodo BP Common utility class — shared utility for business process operations, providing helper methods like `getLastDtmBySvcKeiNo` for datetime retrieval. |
| WRIB | Domain term | Writable (割引) — refers to discount pricing/service information in the K-Opticom telecom billing system. Covers promotional pricing, coupon-based services, and bundled discounts. |
| HANYO | Domain term | Accommodation / Alternate (漢用) — refers to alternate or accommodation service processing (non-discount service lines). Used as kbn=2 in `getDtmMax()`. |
| SCControlMapKeys | Class | Control map key constants — contains keys like `OPERATOR_ID`, `OPE_DATE`, `OPE_TIME` for extracting runtime context from the request parameter. |
| JCMConstants | Class | JCM common constants — contains keys like `OPERATOR_ID_KEY`, `OPERATE_DATE_KEY`, `OPERATE_DATETIME_KEY` for the CAANMsg template field mapping. |
