# Business Logic — JKKCancelSvcWribCC.getDtmMax() [51 LOC]

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

## 1. Role

### JKKCancelSvcWribCC.getDtmMax()

This method identifies the service contract number with the most recent update timestamp among a filtered set of service items stored in a list. It operates within the **service cancellation** subsystem (キャンセル品目), which handles the cancellation of discount information (割引情報) and cancellation confirmation (キャンセル確認) for customer service contracts in the K-Opticom customer core system (eo顧客基幹システム). The method supports two business categories controlled by the `kbn` discriminant: **discount services** (kbn=1, 割引) and **general/other services** (kbn=2, 汎用). For each matching service item, it queries the last update datetime by delegating to `JKKBpCommon.getLastDtmBySvcKeiNo`, then compares that timestamp against the previously seen maximum to determine which contract was modified most recently. After identifying the overall newest contract, the method also stores a mapping of every matching contract number to its last update datetime in an instance-level HashMap — routing into either `wribSvcKei` for discount services or `hanyoSvcKei` for general services — enabling downstream cancellation logic to correlate contracts with their modification times. It implements a **sequential scan with running maximum** pattern, iterating over a list to find the single record with the highest timestamp. Its role as a shared utility is evidenced by its two callers within the same component (`editInEKK0451C070` and `editInEKK1391C040`), both of which process service contract lines during cancellation workflows.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getDtmMax param kbn listNo svcCdList"])
    START --> INIT["Initialize svcCdListCnt workBeanListMap1 null prevRecDtm empty maxSvcKeiNo empty maxDtm empty"]
    INIT --> FOR_CHECK{i < svcCdListCnt?}
    FOR_CHECK -->|Yes| GET_ITEM["Get workBeanListMap1 from svcCdList[iCnt]"]
    GET_ITEM --> GET_ADDLIST["Extract addlistNo from workBeanListMap1 get list_no"]
    GET_ADDLIST --> LIST_MATCH{listNo equals addlistNo?}
    LIST_MATCH -->|No| NEXT_ITER["iCnt++"]
    NEXT_ITER --> FOR_CHECK
    LIST_MATCH -->|Yes| CALL_GETLASTDTM["CALL JKKBpCommon.getLastDtmBySvcKeiNo svc_kei_no upd_dtm_bf"]
    CALL_GETLASTDTM --> COMPARE_DTM{lastDtm compareTo prevRecDtm > 0?}
    COMPARE_DTM -->|No| UPDATE_PREV["prevRecDtm = lastDtm"]
    UPDATE_PREV --> NEXT_ITER
    COMPARE_DTM -->|Yes| SAVE_MAX["maxSvcKeiNo = svc_kei_no maxDtm = lastDtm"]
    SAVE_MAX --> KBN_CHECK{kbn equals 1?}
    KBN_CHECK -->|Yes Discount| SAVE_WRIB["wribSvcKei put svc_kei_no lastDtm"]
    KBN_CHECK -->|No| KBN2_CHECK{kbn equals 2?}
    KBN2_CHECK -->|Yes General| SAVE_HANYO["hanyoSvcKei put svc_kei_no lastDtm"]
    KBN2_CHECK -->|No| AFTER_KBN["Skip storage kbn != 1 and kbn != 2"]
    SAVE_WRIB --> UPDATE_PREV3["prevRecDtm = lastDtm"]
    SAVE_HANYO --> UPDATE_PREV4["prevRecDtm = lastDtm"]
    AFTER_KBN --> UPDATE_PREV5["prevRecDtm = lastDtm"]
    UPDATE_PREV3 --> NEXT_ITER2["iCnt++"]
    UPDATE_PREV4 --> NEXT_ITER2
    UPDATE_PREV5 --> NEXT_ITER2
    NEXT_ITER2 --> FOR_CHECK
    FOR_CHECK -->|No| RETURN_DTMR["Return maxDtm"]
    RETURN_DTMR --> END(["End"])
```

**Processing flow summary:**

1. **Initialization phase**: Sets up the list count, temporary map reference, and tracking variables for the running maximum datetime (`prevRecDtm`), the contract number associated with the maximum (`maxSvcKeiNo`), and the maximum datetime itself (`maxDtm`).
2. **Iteration**: Loops over each entry in `svcCdList`, a list of HashMaps where each map represents a service contract item.
3. **List number filter**: For each item, extracts the `list_no` field and checks if it matches the requested `listNo`. Only items on the matching list are processed — this allows the caller to selectively evaluate a subset of service items.
4. **Datetime fetch**: Delegates to `JKKBpCommon.getLastDtmBySvcKeiNo` to retrieve the last update datetime for the service contract number (`svc_kei_no`) in this item, using the previous update datetime (`upd_dtm_bf`) as context.
5. **Running maximum comparison**: Compares the fetched datetime against the previously seen maximum (`prevRecDtm`). If it is newer, updates both `maxDtm` and `maxSvcKeiNo` to track the contract with the absolute newest update timestamp.
6. **Category-based routing**: Based on the `kbn` parameter value, stores the contract number and its last update datetime into one of two instance-level HashMaps: `wribSvcKei` for discount services (割引) or `hanyoSvcKei` for general services (汎用). This enables downstream cancellation operations to access contract-to-timestamp mappings.
7. **State update and next iteration**: Updates `prevRecDtm` to the current item's datetime and advances to the next list entry.
8. **Return**: After iterating through all items, returns `maxDtm` — the maximum update datetime found, which the caller uses to determine the most recently modified service contract.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | The request parameter object that carries business data between CBS (Call Back Service) components and Common Components. Contains session-scoped data used by downstream service calls. |
| 2 | `kbn` | `int` | Type discriminant (区分値) that determines which service category this operation targets. Value `1` = Discount service (割引サービス) — cancellation of promotional pricing. Value `2` = General service (汎用サービス) — cancellation of other/non-promotional services. Directs which instance HashMap receives the contract-timestamp mapping. |
| 3 | `listNo` | `String` | List number used to filter service items. Only entries within `svcCdList` whose `list_no` field matches this value are processed. This enables selective evaluation of service items belonging to a specific list grouping (e.g., different cancellation batches). |
| 4 | `svcCdList` | `ArrayList` | A list of HashMap entries, where each HashMap represents a service contract item containing fields: `svc_kei_no` (service contract number), `list_no` (list number for grouping), `upd_dtm_bf` (previous update datetime). This is the working dataset from which the method scans to find the newest contract. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `wribSvcKei` | `HashMap<String, String>` | Instance-level map storing service contract numbers as keys and their last update datetimes as values, specifically for **discount services** (割引情報キャンセル). Populated when `kbn == 1`. |
| `hanyoSvcKei` | `HashMap<String, String>` | Instance-level map storing service contract numbers as keys and their last update datetimes as values, specifically for **general services** (汎用キャンセル). Populated when `kbn == 2`. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKBpCommon.getLastDtmBySvcKeiNo` | JKKBpCommon | Service contract entity | Reads last update datetime for a service contract number by delegating to `JKKHdlSvkeiWorkArea.getLastDtmBySvcKeiNo` |
| R | `JKKHdlSvkeiWorkArea.getLastDtmBySvcKeiNo` | JKKHdlSvkeiWorkArea | Service contract work area entity | Retrieves the last update datetime by service contract number from the work area data |

**Detailed analysis:**

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `getLastDtmBySvcKeiNo` | JKKBpCommon | Service contract (work area) | Reads the most recent update datetime for a given service contract number. Called with `svc_kei_no` (service contract number) and `upd_dtm_bf` (previous update datetime) as inputs. Delegates to `JKKHdlSvkeiWorkArea.getLastDtmBySvcKeiNo` which performs the actual lookup. |

## 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: `getLastDtmBySvcKeiNo` [R], `getLastDtmBySvcKeiNo` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: EKK0451C070 | `cancelSvcWrib` → `editInEKK0451C070` → `getDtmMax` | `getLastDtmBySvcKeiNo [R] Service contract entity` |
| 2 | CBS: EKK1391C040 | `cancelSvcWrib` → `editInEKK1391C040` → `getDtmMax` | `getLastDtmBySvcKeiNo [R] Service contract entity` |

**Call chain context:**
- Both callers (`editInEKK0451C070` and `editInEKK1391C040`) are private methods within `JKKCancelSvcWribCC` that are invoked from the main entry point `cancelSvcWrib`.
- `editInEKK0451C070` processes discount service (割引情報) cancellation — specifically top-up mapping (上りマッピング).
- `editInEKK1391C040` processes general service (汎用) cancellation — also top-up mapping (上りマッピング).
- `getDtmMax` is called within these CBS-level cancellation operations to determine the most recently updated service contract for comparison/correlation purposes during cancellation workflows.

## 6. Per-Branch Detail Blocks

**Block 1** — [VARIABLE DECLARATIONS] Initialization (L1412)

> Sets up iteration variables and tracking state for finding the maximum datetime.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcCdListCnt = svcCdList.size()` |
| 2 | SET | `workBeanListMap1 = null` |
| 3 | SET | `prevRecDtm = ""` |
| 4 | SET | `maxSvcKeiNo = ""` |
| 5 | SET | `maxDtm = ""` |

**Block 2** — [FOR LOOP] Iterate over service code list (L1416)

> Loops through each service item in the list to find the one with the newest update timestamp.

| # | Type | Code |
|---|------|------|
| 1 | SET | `iCnt = 0; iCnt < svcCdListCnt; iCnt++` |
| 2 | EXEC | `workBeanListMap1 = (HashMap)(svcCdList).get(iCnt)` // Cast and retrieve list item |

**Block 3** — [IF] Match list number (L1419)

> Filters service items by `list_no`. Only items whose `list_no` matches the target `listNo` are processed.

| # | Type | Code |
|---|------|------|
| 1 | SET | `addlistNo = (String)workBeanListMap1.get("list_no")` |
| 2 | EXEC | `listNo.equals(addlistNo)` |

**Block 4** — [IF body: listNo match] Fetch last update datetime and compare (L1423)

> Retrieves the last update datetime for this service contract via a service call, then compares it against the running maximum.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JKKBpCommon.getLastDtmBySvcKeiNo(param, (String)workBeanListMap1.get("svc_kei_no"), (String)workBeanListMap1.get("upd_dtm_bf"))` // Fetch last update datetime from work area [-> service delegation to JKKHdlSvkeiWorkArea] |
| 2 | SET | `lastDtm = ...` |

**Block 5** — [IF] New maximum datetime found (L1432)

> Compares the fetched datetime against the previously seen maximum. If newer, updates the tracking variables to record this contract as the most recently modified.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `0 < lastDtm.compareTo(prevRecDtm)` // true if lastDtm is newer than prevRecDtm |
| 2 | SET | `maxSvcKeiNo = (String)workBeanListMap1.get("svc_kei_no")` // Store contract number [-> Service Contract Number] |
| 3 | SET | `maxDtm = lastDtm` // Store maximum datetime |

**Block 6** — [IF-ELSE] kbn category routing (L1438)

> Routes storage of the contract-timestamp mapping based on service category discriminant.

**Block 6.1** — [IF-ELSEIF] kbn == 1 (Discount service) (L1440) [-> kbn = "1" (割引 / Discount)]

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `1 == kbn` |
| 2 | CALL | `wribSvcKei.put((String)workBeanListMap1.get("svc_kei_no"), lastDtm)` // Store contract number and last update datetime in discount service HashMap [-> wribSvcKei (割引情報キャンセル用ワーク)] |

**Block 6.2** — [ELSE-IF] kbn == 2 (General service) (L1444) [-> kbn = "2" (汎用 / General)]

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `2 == kbn` |
| 2 | CALL | `hanyoSvcKei.put((String)workBeanListMap1.get("svc_kei_no"), lastDtm)` // Store contract number and last update datetime in general service HashMap [-> hanyoSvcKei (汎用キャンセル用ワーク)] |

**Block 7** — [STATE UPDATE] Advance running maximum (L1450)

> Updates the running maximum tracker for the next iteration's comparison.

| # | Type | Code |
|---|------|------|
| 1 | SET | `prevRecDtm = lastDtm` |

**Block 8** — [FOR LOOP END] Return result (L1453)

> After all items have been processed, return the maximum datetime found.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return maxDtm` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svc_kei_no` | Field | Service contract number — unique identifier for a service contract line item within the K-Opticom customer core system |
| `list_no` | Field | List number — grouping identifier used to categorize service items into logical groups (e.g., cancellation batches) |
| `upd_dtm_bf` | Field | Previous update datetime (before) — the last known update timestamp carried in the service item, used as context for retrieving the current update datetime |
| `prevRecDtm` | Field | Previous record datetime — running maximum tracker that holds the newest datetime seen so far during iteration |
| `maxSvcKeiNo` | Field | Maximum service contract number — the contract number associated with the newest update timestamp found |
| `maxDtm` | Field | Maximum datetime — the newest update datetime found across all processed service items |
| `wribSvcKei` | Field | Work HashMap for discount service contracts — stores contract-to-timestamp mappings for discount (割引) service cancellation operations |
| `hanyoSvcKei` | Field | Work HashMap for general service contracts — stores contract-to-timestamp mappings for general (汎用) service cancellation operations |
| `kbn` | Parameter | Type discriminant (区分値) — integer flag indicating service category: 1 = discount service (割引), 2 = general service (汎用) |
| IKKCancelSvcWribCC | Class | Cancellation service writing Common Component — handles cancellation of discount information (割引情報) and cancellation confirmation (キャンセル確認) for service contracts |
| cancelSvcWrib | Method | Main cancellation processing entry point — orchestrates the cancellation workflow for discount and general service items |
| JKKBpCommon | Class | Shared business component — provides common utility methods for service contract operations across the cancellation subsystem |
| JKKHdlSvkeiWorkArea | Class | Service detail work area handler — manages work area data for service contracts including update datetime lookups |
| getLastDtmBySvcKeiNo | Method | Get last datetime by service contract number — retrieves the most recent update timestamp for a given service contract |
| IRequestParameterReadWrite | Interface | Request parameter read-write interface — contract for passing structured business data between CBS and CC components |
| CB | Acronym | Call Back — enterprise integration pattern used in this system for CBS (Call Back Service) component invocation |
| CC | Acronym | Common Component — shared utility/component layer providing reusable business logic across screens and CBS operations |
| SC | Acronym | Service Component — layer that handles specific business logic execution, often with database access |
| 割引 (warihiki) | Japanese | Discount — promotional pricing service type in the telecom billing domain |
| 汎用 (hanyo) | Japanese | General — non-promotional, standard service type (catch-all category for non-discount services) |
| キャンセル (kyanseru) | Japanese | Cancellation — the business operation of canceling service contracts or their associated information |
