# Business Logic — JKKKapKeiInfoCancelCC.underConstruction() [80 LOC]

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

## 1. Role

### JKKKapKeiInfoCancelCC.underConstruction()

This method determines whether a service contract line item (service detail / サービス契約詳細) is currently **under construction** (工事中) by performing a two-level inquiry: it first retrieves all work cases (工事案件) linked to the service, then for each work case it retrieves the associated indoor devices (屋内機器). It cross-references the device's service contract number against the provided `kktkSvcKeiNo` parameter, and checks the device's status against a range that signifies an active construction state — specifically, device status values from 130 (Received / 受注済) up to but not including 150 (Actual Measurement Confirmed / 実績確定済) indicate the work is in progress but not yet confirmed.

When a matching device is found with an in-progress status flag (`flgFind = true`), the method performs a second-level validation by checking the parent work case's own status, which must fall between 130 (Received) and 190 (not yet Completed / 未完了) to confirm the work case itself is still active. If both conditions hold, the work case number (工事案件番号) is returned as the identifier of the active construction. If no matching in-progress work case is found across all iterations, the method returns an empty string, indicating the service contract line item is not currently under construction.

The method implements a **nested loop with early-exit** pattern: it iterates over work cases and devices with short-circuit evaluation — if a match is found, it breaks out of the inner loop and validates the outer work case before returning. This design avoids unnecessary iterations once the first in-progress work case is identified.

The method's role in the larger system is as a **guard check** used during service contract cancellation workflows. It is called from `isExecKojiAnkenCancel` to determine whether equipment work cancellation (機器工事キャンセル) should be processed for each device in the deletion list — if a device's work case is still under construction, the cancellation logic must account for it.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["underConstruction start"])

    START --> CALL1["execEKU0011B030 - Work case list retrieval"]
    CALL1 --> CHECK1{Work case list<br>empty or null?}

    CHECK1 -->|Yes| END1["Return empty string<br>Not under construction"]
    CHECK1 -->|No| LOOP1["Loop through work cases"]

    LOOP1 --> GET_KOJI["Get work case number"]
    GET_KOJI --> CALL2["execEKU0141B010 - Device list"]
    CALL2 --> CHECK2{Device list<br>empty or null?}

    CHECK2 -->|Yes| CONT["continue next work case"]
    CHECK2 -->|No| LOOP2["Loop through devices"]

    LOOP2 --> GET_KKTK["Get device service contract number"]
    GET_KKTK --> GET_STAT["Get device status"]
    GET_STAT --> CHECK_KKTK{Service contract<br>number match?}

    CHECK_KKTK -->|No| CONT
    CHECK_KKTK -->|Yes| CHECK_DEV_STAT{Device status<br>130 <= stat lt 150<br>Received to Actual Measurement Confirmed}

    CHECK_DEV_STAT -->|Yes| SET_TRUE["flgFind true<br>break"]
    CHECK_DEV_STAT -->|No| CONT

    SET_TRUE --> CHECK_FLG{Flag found?}
    CHECK_FLG -->|No| CONT
    CHECK_FLG -->|Yes| GET_WK_STAT["Get work case status"]
    GET_WK_STAT --> CHECK_WK_STAT{Work case status<br>130 <= status lt 190<br>Received to Completed}

    CHECK_WK_STAT -->|Yes| RETURN_KOJI["Return work case number"]
    CHECK_WK_STAT -->|No| CONT

    CONT --> END2["Return empty string"]
    END1 --> END2
    RETURN_KOJI --> END2
```

**Processing flow:**
1. **Work case list retrieval** — Calls `execEKU0011B030` with empty status and sub-type codes to fetch ALL work cases associated with the service (工事案件一覧照会（複合検索）).
2. **Empty work case check** — If no work cases exist, the service is not under construction; return empty string immediately.
3. **Outer loop — iterate work cases** — For each work case, retrieve its number and fetch the device list.
4. **Device list retrieval** — Calls `execEKU0141B010` (工事内屋内機器一覧照会) to get all indoor devices for the current work case.
5. **Empty device check** — If no devices exist for a work case, skip to the next work case (`continue`).
6. **Inner loop — iterate devices** — For each device, retrieve the service contract number and device status.
7. **Service contract number match** — Compare the device's contract number against `kktkSvcKeiNo` (工事案件屋内機器).
8. **Device status range check** — If matched, check if device status is between 130 (Received / 受注済) inclusive and 150 (Actual Measurement Confirmed / 実績確定済) exclusive. Note: In v15.00.00, the threshold was changed from `< 190` to `< 150`.
9. **Flag and break** — If the device status is in-range, set `flgFind = true` and break out of the inner loop.
10. **Work case status validation** — If a flag was found, retrieve the work case's status and check if it is between 130 (Received) and 190 (Completed / 完工了) exclusive.
11. **Return** — If the work case status is in-range, return the work case number; otherwise continue.
12. **Fallback** — After exhausting all work cases without finding a match, return empty string.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Session handle for the current user session; used to establish context for CBS service calls. Carries the transaction session information needed by `callSC` to route service component requests. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | Service Component Request Invoker; the dispatch mechanism used to invoke CBS (Business Service) methods such as `execEKU0011B030` and `execEKU0141B010`. It abstracts the underlying service layer invocation. |
| 3 | `param` | `IRequestParameterReadWrite` | Request parameter read/write interface; provides access to the `dataMapKey`-based data map where service data (e.g., `svc_kei_no`) and intermediate results are stored during the cancellation workflow. |
| 4 | `dataMapKey` | `String` | The key used to access the shared data map (`ccMsg`) within `param`. This data map carries service-level context such as `svc_kei_no` (service detail number) which is passed to the CBS calls as input parameters. |
| 5 | `temporaryData` | `HashMap<String, Object>` | Temporary data store shared across method calls within the same workflow. Though not directly used in this method, it is passed through to called methods (e.g., `execEKU0141B010` may use it). The caller `isExecKojiAnkenCancel` uses it to hold `EKK0081A010_WORK` data. |
| 6 | `kktkSvcKeiNo` | `String` | Equipment-provided service contract number (機器提供サービス契約番号); the specific service contract line item identifier to match against the devices under each work case. This is the key discriminant that determines which device's status is evaluated. |

**External state referenced:**
- None — this method is stateless; it relies entirely on passed parameters and CBS query results.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `execEKU0011B030` | EKU0011B030SC | Work case table (工事案件マスタ) | Retrieves the list of all work cases for the service by calling the work case list CBS (工事案件一覧照会（複合検索）). Input includes service detail number from `dataMapKey`, with empty status and sub-type filters to fetch all. |
| R | `execEKU0141B010` | EKU0141B010SC | Indoor device table (屋内機器マスタ) | Retrieves the list of indoor devices associated with a specific work case. Input is the work case number (kojiakNo), search type "1" (full search), max search num "10000". |
| R | `getNullToStr` | Utility | - | Utility method that converts null values to empty strings; used defensively on all `CAANMsg.getString()` calls to prevent NPE. |

### Detailed call descriptions:

**EKU0011B030SC (Work Case List Inquiry — Compound Search)**
- **CRUD**: Read
- **Entity**: Work case master table (工事案件マスタ) — queried via `EKU0011B030CBSMsg`
- **Input**: `TEMPLATEID` (EKU0011B030), `FUNC_CODE` (1), `KEY_SVC_KEI_NO` (from `ccMsg.get("svc_kei_no")`), `KEY_KOJIAK_STAT` (empty string — no filter), `KEY_KOJIAK_SBT_CD` (empty string — no filter)
- **Business meaning**: Fetches all work cases associated with the current service. The empty status and sub-type code parameters mean it returns ALL work cases regardless of their state, enabling the method to search across the full set.

**EKU0141B010SC (Indoor Device List Inquiry — for Work Cases)**
- **CRUD**: Read
- **Entity**: Indoor device master table (屋内機器マスタ) — queried via `EKU0141B010CBSMsg`
- **Input**: `TEMPLATEID` (EKU0141B010), `FUNC_CODE` (1), `SEARCH_TYPE` ("1" = full search), `KEY_KOJIAK_NO` (specific work case number), `MAX_SEARCH_NUM` ("10000")
- **Business meaning**: For a given work case, retrieves all indoor devices that are targets of that work case. Used to check each device's status and service contract number.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: `JKKKapKeiInfoCancelCC.isExecKojiAnkenCancel` | `isExecKojiAnkenCancel` → loops over `delKikiList`, calls `underConstruction(kktsSvcKeiNo)` | `execEKU0011B030 [R] Work case table`<br>`execEKU0141B010 [R] Indoor device table`<br>`getNullToStr [R] Utility` |
| 2 | CBS: `JKKKikiIchiranIkkatsuCC.isUnderConstruction` | `isUnderConstruction` → calls similar work case + device list inquiry pattern (separate method, same pattern) | `EKU0011B030 [R] Work case table`<br>`EKU0141B010 [R] Indoor device table` |

**Note**: The primary and direct caller is `isExecKojiAnkenCancel`, which is itself a CBS-level helper method (not a screen entry point). It is called during the service contract cancellation workflow (`JKKKapKeiInfoCancelCC`) to determine whether equipment work cancellation should be processed for each device. The second caller (`isUnderConstruction` in `JKKKikiIchiranIkkatsuCC`) uses the same work-case-and-device inquiry pattern for a different business context (likely during bulk equipment inquiry operations).

**Entry point context**: The method is not directly called by any screen (KKSV*). It is a private helper method invoked by `isExecKojiAnkenCancel`, which in turn is called from the main cancellation processing flow of `JKKKapKeiInfoCancelCC`.

**Terminal operations reachable from this method:**
- `execEKU0011B030` [Read] Work case list — EKU0011B030SC
- `execEKU0141B010` [Read] Indoor device list — EKU0141B010SC
- `getNullToStr` [Read] Null-safe string conversion — utility

## 6. Per-Branch Detail Blocks

### Block 1 — CALL (L3364)
> Executes the work case list CBS inquiry (工事案件一覧照会（複合検索）) to retrieve all work cases for the current service.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `execEKU0011B030(handle, scCall, param, dataMapKey, "", "")` // Work case list retrieval with empty status and sub-type filters [-> EKU0011B030] |
| 2 | SET | `eku0011b030cbsMsg1list = result` // Stores work case array for iteration |

### Block 2 — IF (L3367)
> Checks if the work case list query returned any results. If empty, the service has no work cases and is therefore not under construction.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `eku0011b030cbsMsg1list == null || eku0011b030cbsMsg1list.length == 0` // Checks for empty work case results |

**Block 2.1 — IF branch: true (Not under construction)**
> No work cases exist; the service is confirmed not under construction.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return ""` // Not under construction; no work cases found |

**Block 2.2 — IF branch: false (Has work cases)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiAkArray = eku0011b030cbsMsg1list` // Assigns work case array for iteration |

### Block 3 — FOR LOOP (L3372)
> Outer loop: iterates over each work case in the retrieved list.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `for (CAANMsg kojiAk : kojiAkArray)` // Iterates over work case list [-> kojiAkArray from EKU0011B030] |

### Block 3.1 — EXEC (L3375)
> Retrieves the work case number (工事案件番号) for the current iteration.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiakNo = getNullToStr(kojiAk.getString(EKU0011B030CBSMsg1List.KOJIAK_NO))` // Work case number [-> KOJIAK_NO] |

### Block 3.2 — CALL (L3378)
> Calls the device list CBS inquiry (工事案件屋内機器一覧照会) to get all indoor devices for the current work case.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `execEKU0141B010(handle, scCall, param, dataMapKey, kojiakNo)` // Device list for this work case [-> EKU0141B010] |
| 2 | SET | `eku0141b010CbsMsg1List = result` // Stores device array |

### Block 3.3 — IF (L3381)
> Checks if the device list for the current work case is empty. If so, skip to the next work case.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `eku0141b010CbsMsg1List == null || eku0141b010CbsMsg1List.length == 0` // Empty device list check |

**Block 3.3.1 — IF branch: true (No devices)**

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `continue` // Skip to next work case; no devices under this work case |

**Block 3.3.2 — IF branch: false (Has devices)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiAkkikiArray = eku0141b010CbsMsg1List` // Assigns device array for iteration |
| 2 | SET | `flgFind = false` // Flags whether a matching in-progress device is found |

### Block 3.4 — FOR LOOP (L3386)
> Inner loop: iterates over each device under the current work case.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `for (CAANMsg kojiAkkiki : kojiAkkikiArray)` // Iterates over device list |

### Block 3.4.1 — SET (L3389)
> Retrieves the device's service contract number (機器提供サービス契約番号).

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktk_Svc_KeiNo = getNullToStr(kojiAkkiki.getString(EKU0141B010CBSMsg1List.KKTK_SVC_KEI_NO))` // Device service contract number [-> KKTK_SVC_KEI_NO] |

### Block 3.4.2 — SET (L3392)
> Retrieves the device's status code (屋内機器ステータス).

| # | Type | Code |
|---|------|------|
| 1 | SET | `taknkikiStat = getNullToStr(kojiAkkiki.getString(EKU0141B010CBSMsg1List.KOJIAK_TRGT_TAKNKIKI_STAT))` // Device status [-> KOJIAK_TRGT_TAKNKIKI_STAT] |

**Status code meanings:**
- 130 = 受注済 (Received / Ordered)
- 150 = 実績確定済 (Actual Measurement Confirmed)
- 190 = 工事了 (Completed)
- 200 = 完工了 (Finalized/Completely Done)

### Block 3.4.3 — IF (L3395)
> Checks if the device's service contract number matches the target `kktkSvcKeiNo`. Only matching devices proceed to status evaluation.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `kktkSvcKeiNo.equals(kktk_Svc_KeiNo)` // Target service contract number match |

**Block 3.4.3.1 — IF branch: true (Match found)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `stat = Integer.parseInt(taknkikiStat)` // Converts device status string to int |

**Block 3.4.3.1.1 — IF (L3403) [v15.00.00 Modified]**
> Checks if the device status is in the range 130 (Received) to less than 150 (Actual Measurement Confirmed). This indicates the device is actively being worked on but has not yet been confirmed as complete.

**Note**: In v15.00.00, this threshold was changed. Previously the code checked `stat < 190` (before Completed), but was tightened to `stat < 150` (before Actual Measurement Confirmed). This means the range now covers: Received (130) through a state just below Actual Measurement Confirmed (150), representing the active construction window.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `130 <= stat && stat < 150` // [ODR_NAIYO_CD_101 range] Device is in active construction (130: Received, 150: Actual Measurement Confirmed) |

**Block 3.4.3.1.1.1 — IF branch: true (In construction range)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `flgFind = true` // Sets flag indicating an in-progress device was found |
| 2 | EXEC | `break` // Exits inner loop; proceeds to work case status validation |

**Block 3.4.3.1.1.2 — IF branch: false (Not in construction range)**

| # | Type | Code |
|---|------|------|
| 1 | (implicit) | Continue to next device in the loop |

**Block 3.4.3.2 — IF branch: false (No match)**

| # | Type | Code |
|---|------|------|
| 1 | (implicit) | Continue to next device in the loop |

### Block 3.5 — IF (L3414)
> After the inner loop (with potential break), checks if a matching in-progress device was found. If not, skips work case status validation.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `flgFind` // True if a matching in-progress device was found in the inner loop |

**Block 3.5.1 — IF branch: true (Found in-progress device)**

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiakStat = getNullToStr(kojiAk.getString(EKU0011B030CBSMsg1List.KOJIAK_STAT))` // [v15.00.00] Work case status [-> KOJIAK_STAT] — Note: changed from using `eku0011b030cbsMsg1list[0]` to the current iteration's `kojiAk` for per-case accuracy |

| # | Type | Code |
|---|------|------|
| 2 | SET | `ikojiakStat = Integer.parseInt(kojiakStat)` // Converts status string to int |

**Block 3.5.1.1 — IF (L3421)**
> Checks if the work case's own status is in the in-progress range: 130 (Received) to less than 190 (Completed). This is the second-level validation confirming the work case is actively ongoing.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `130 <= ikojiakStat && ikojiakStat < 190` // Work case is in active construction (130: Received, 190: Completed) |

**Block 3.5.1.1.1 — IF branch: true (Work case also in-progress)**

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return kojiakNo` // Returns the work case number — this service contract line item IS under construction |

**Block 3.5.1.1.2 — IF branch: false (Work case not in range)**

| # | Type | Code |
|---|------|------|
| 1 | (implicit) | Continue to next work case; the device was in-progress but the work case itself is outside the in-progress range |

**Block 3.5.2 — IF branch: false (No device flag set)**

| # | Type | Code |
|---|------|------|
| 1 | (implicit) | Continue to next work case; no matching in-progress device found |

### Block 4 — RETURN (L3428)
> Final fallback: after iterating through all work cases and their devices without finding any in-progress match, returns empty string.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return ""` // Not under construction; no matching in-progress work case found across all iterations |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kojiakNo` / `KOJIAK_NO` | Field | Work case number (工事案件番号) — unique identifier for a construction work case assigned to a service contract line item |
| `svc_kei_no` | Field | Service detail number (サービス契約番号) — identifier for a service contract line item; used as the primary key for work case lookup |
| `kojiakStat` / `KOJIAK_STAT` | Field | Work case status (工事案件ステータス) — numeric status code representing the current state of a work case |
| `KOJIAK_TRGT_TAKNKIKI_STAT` | Field | Work case target indoor device status (工事案件対象屋内機器ステータス) — numeric status code for each indoor device under a work case |
| `KKTK_SVC_KEI_NO` | Field | Equipment-provided service contract number (機器提供サービス契約番号) — identifies which service contract a device belongs to; used to match devices against the target service line |
| `kktkSvcKeiNo` | Parameter | Equipment-provided service contract number — the specific service line to check for active construction |
| `kojiakSbtCd` | Field | Work case sub-type code (工事案件サブタイプコード) — classifies the type of work case |
| `delKikiList` | Field | Device deletion list (機器削除リスト) — list of devices scheduled for deletion during cancellation |
| `ido_div` | Field | Move/division indicator (移動区分) — categorizes the type of work (e.g., move, cancel) |
| `kojiakUpdRenkeiMap` | Field | Work case update linkage map (工事案件更新連携Map) — maps work case numbers to their associated device cancellation data |
| `flgFind` | Variable | Flag indicating whether a matching in-progress device was found |
| SOD | Acronym | Service Order Data — order fulfillment entity in telecom systems |
| EKU0011B030 | CBS Code | Work case list inquiry — compound search (工事案件一覧照会（複合検索）) |
| EKU0141B010 | CBS Code | Indoor device list inquiry for work cases (工事案件屋内機器一覧照会) |
| 受注済 (130) | Status | Received / Ordered — the initial confirmed state after order placement |
| 実績確定済 (150) | Status | Actual Measurement Confirmed — the state where field installation measurements have been confirmed as complete |
| 完工了 (200) | Status | Finalized/Completely Done — the terminal state indicating all work is fully completed |
| 工事中 | Business term | Under construction — the state where work is actively in progress but not yet confirmed or finalized |
| 工事案件 | Business term | Work case / Construction case — a unit of construction work associated with a service contract line item |
| 屋内機器 | Business term | Indoor device — customer-premises equipment installed by the contractor |
| 機器提供サービス契約番号 | Business term | Equipment-provided service contract number — ties a device back to a specific service contract line item |
| CAANMsg | Class | Message container class for CBS response data; holds typed field values accessible via `getString()` |
| callSC | Method | Service Component layer call method that dispatches a request to a CBS (Business Service Component) |
