# Business Logic — JKKKddiKeishaInfoCC.getTelKeiyakuJotai() [128 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKKddiKeishaInfoCC` |
| Layer | CC / Common Component (Shared utility class for telecom customer information processing) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKKddiKeishaInfoCC.getTelKeiyakuJotai()

This method determines and returns the **display contract status** for a telephone service contract. It performs a multi-stage resolution pipeline: first reading the raw service contract status from the input message, then enriching it with work project details from the customer work project management system. If the contract is in a pre-completed or pending state, it consults the work project list and consent data to check for active construction projects that would affect the display. The method applies a set of business rules to potentially override the raw status — for example, converting a pre-completed status ("010") to active ("000"), or overriding to "canceled" ("910") when there is a temporary cancellation flag on an active new-construction work project. Finally, it looks up the resolved numeric code as a human-readable name from the code name management table and returns it. The method serves as a shared utility called by other CC classes in the telephone customer information domain to present contract status on screens.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getTelKeiyakuJotai"])
    R1["Read svcKeiUcwkStat from targetSvcKeiUcwkTel"]
    R2["Read svcKeiNo from svcKeiData"]
    R3["Read svcKeiUcwkNo from targetSvcKeiUcwkTel"]
    INIT["Initialize work project fields to empty strings"]
    BLD["Build kojiStatList with valid statuses CD00474_140-190"]
    CALL1["Call getEKU0081B010 to get work project list"]
    C1{cAANMsgCust != null?}
    C1B{cAANMsgCust.length != 0?}
    R4["Extract kojiakNo from cAANMsgCust[0]"]
    CALL2["Call getEKU0011A010 to get project consent"]
    C2{cAANMsgKoji != null?}
    R5["Read KOJIAK_STAT"]
    R6["Read KOJIAK_SBT_CD"]
    R7["Read KJ_KR_CNCL_FLG"]
    C3{svcKeiUcwkStat = 010?}
    U1["Set svcKeiUcwkStat = 000"]
    C4{svcKeiUcwkStat = 020 or 030?}
    C5{isUcwkShosaOK and status 020?}
    U2["Set svcKeiUcwkStat = 910 contract canceled"]
    C6{kojiakSbtCd=001 and validStat and kjKrCnclFlg=1?}
    U3["Set svcKeiUcwkStat = 910 canceled new project"]
    CALL3["Call getEZM0171A010 for code name lookup"]
    RET["Return CD_DIV_NM"]

    START --> R1
    R1 --> R2
    R2 --> R3
    R3 --> INIT
    INIT --> BLD
    BLD --> CALL1
    CALL1 --> C1
    C1 -->|yes| C1B
    C1 -->|no| C3
    C1B -->|yes| R4
    C1B -->|no| C3
    R4 --> CALL2
    CALL2 --> C2
    C2 -->|yes| R5
    C2 -->|no| C3
    R5 --> R6
    R6 --> R7
    R7 --> C3
    C3 -->|yes| U1
    C3 -->|no| C4
    U1 --> C4
    C4 -->|yes| C5
    C4 -->|no| CALL3
    C5 -->|no + status 020| U2
    C5 -->|yes| C6
    U2 --> CALL3
    C6 -->|yes| U3
    C6 -->|no| CALL3
    U3 --> CALL3
    CALL3 --> RET
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle providing transaction and connection context for service component calls. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter object carrying screen input values and routing data for downstream service calls. |
| 3 | `fixedText` | `String` | Fixed text label used in screen display and error messages — passed through to called methods for UI rendering. |
| 4 | `ccMsg` | `HashMap<String, Object>` | Message passing container for error codes and status messages within the common component layer. |
| 5 | `targetSvcKeiUcwkTel` | `CAANMsg` | Message object containing the target telephone service contract details, including the raw service contract status (`SVC_KEI_UCWK_STAT`), work detail number (`SVC_KEI_UCWK_NO`). This is the primary input for status resolution. |
| 6 | `svcKeiData` | `CAANMsg` | Message object containing the service contract header data, notably the service contract number (`SVC_KEI_NO`). Used as a key to query work project lists. |

**External state read:**
- None — all state is passed through parameters or resolved from called service methods.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `getNullToStr` | N/A | - | Null-safe string extraction helper on `JKKKddiKeishaInfoCC` — returns empty string for null values. |
| R | `targetSvcKeiUcwkTel.getString(EKK0191B009CBSMsg1List.SVC_KEI_UCWK_STAT)` | EKK0191B009CBS | - | Reads the raw service contract status from the telephone service contract UCWK message. |
| R | `svcKeiData.getString(EKK0251B005CBSMsg1List.SVC_KEI_NO)` | EKK0251B005CBS | - | Reads the service contract number from the service data message. |
| R | `targetSvcKeiUcwkTel.getString(EKK0191B009CBSMsg1List.SVC_KEI_UCWK_NO)` | EKK0191B009CBS | - | Reads the service contract work detail number from the telephone UCWK message. |
| R | `getEKU0081B010` | EKU0081B010SC | Work project list (KOJIAK) | Retrieves the list of work projects associated with a service contract number. |
| R | `cAANMsgCust[0].getString(EKU0081B010CBSMsg1List.KOJIAK_NO)` | EKU0081B010CBS | - | Extracts the work project number from the first work project in the list. |
| R | `getEKU0011A010` | EKU0011A010SC | Work project consent (KOJIAK detail) | Retrieves the work project consent/agreement information for a given work project number. |
| R | `cAANMsgKoji.getString(EKU0011A010CBSMsg1List.KOJIAK_STAT)` | EKU0011A010CBS | - | Reads the work project status code from the consent message. |
| R | `cAANMsgKoji.getString(EKU0011A010CBSMsg1List.KOJIAK_SBT_CD)` | EKU0011A010CBS | - | Reads the work project type code (e.g., new construction "001", change, etc.). |
| R | `cAANMsgKoji.getString(EKU0011A010CBSMsg1List.KJ_KR_CNCL_FLG)` | EKU0011A010CBS | - | Reads the temporary cancellation flag ("1" = cancellation state applies). |
| - | `isUcwkShosaOK` | N/A | - | Validates whether the service contract work details pass inspection/approval checks. |
| R | `getEZM0171A010` | EZM0171A010SC | Code name management (CD table) | Looks up the human-readable display name for a code value from the code name management table. Code type: `CD01537`. |
| R | `cAANMsgCdNmKanri.getString(EZM0171A010CBSMsg1List.CD_DIV_NM)` | EZM0171A010CBS | - | Reads the code name (display label) for the resolved status code. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CC:JKKKddiKeishaInfoCC.setTelKeiSmartValueMskmKh | `setTelKeiSmartValueMskmKh` -> `getTelKeiyakuJotai` | `getEKU0081B010 [R] KOJIAK`, `getEKU0011A010 [R] KOJIAK detail`, `getEZM0171A010 [R] CD01537 code table` |

**Terminal operations reachable from this method:**
- `getEKU0081B010` [R] — Work project list query (KOJIAK entity)
- `getEKU0011A010` [R] — Work project consent query (KOJIAK detail entity)
- `getEZM0171A010` [R] — Code name management table query (CD01537)
- `isUcwkShosaOK` [-] — Work detail inspection approval validation
- `getNullToStr` [R] — Null-safe string extraction utility
- `getString` [R] — Message field extraction from multiple CAANMsg sources

## 6. Per-Branch Detail Blocks

### Block 1 — [SET] Initialize service contract status (L2810)

> Reads the raw service contract status from the telephone UCWK message, with null-safety.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiUcwkStat = getNullToStr(targetSvcKeiUcwkTel.getString(EKK0191B009CBSMsg1List.SVC_KEI_UCWK_STAT))` // Service contract status from target message [-> EKK0191B009CBSMsg1List.SVC_KEI_UCWK_STAT] |

### Block 2 — [SET] Read service contract number (L2814)

> IT1-2018-0000088 ADD — New parameter `svcKeiData` introduced to fetch the service contract number.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKeiNo = getNullToStr(svcKeiData.getString(EKK0251B005CBSMsg1List.SVC_KEI_NO))` // Service contract number from svcKeiData [-> EKK0251B005CBSMsg1List.SVC_KEI_NO] |
| 2 | SET | `svcKeiUcwkNo = getNullToStr(targetSvcKeiUcwkTel.getString(EKK0191B009CBSMsg1List.SVC_KEI_UCWK_NO))` // Service contract work detail number [-> EKK0191B009CBSMsg1List.SVC_KEI_UCWK_NO] |

### Block 3 — [SET] Initialize work project fields (L2820–L2830)

> OM-2018-0001092 MOD — Previously declared as nullable; changed to empty string initialization for work project fields.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiakNo = ""` // Work project number [-> empty string initial] |
| 2 | SET | `kojiakStat = ""` // Work project status [-> empty string initial] |
| 3 | SET | `kojiakSbtCd = ""` // Work project type code [-> empty string initial] |
| 4 | SET | `kjKrCnclFlg = ""` // Temporary cancellation flag [-> empty string initial] |

### Block 4 — [SET] Build valid work project status list (L2833–L2843)

> Constructs a list of valid work project statuses that indicate an active/ongoing construction process. Work project status constants from `JKKStrConst.CD00474_*`:

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiStatList = new LinkedList<String>()` |
| 2 | SET | `kojiStatList.add(JKKStrConst.CD00474_140)` // Status: "Under Request" (依頼中) [-> CD00474_140] |
| 3 | SET | `kojiStatList.add(JKKStrConst.CD00474_150)` // Status: "Survey Complete" (宅内調査完了済) [-> CD00474_150] |
| 4 | SET | `kojiStatList.add(JKKStrConst.CD00474_160)` // Status: "Contractor Decided" (工事会社決定済) [-> CD00474_160] |
| 5 | SET | `kojiStatList.add(JKKStrConst.CD00474_170)` // Status: "Equipment Pre-Registered" (宅内機器予定登録済) [-> CD00474_170] |
| 6 | SET | `kojiStatList.add(JKKStrConst.CD00474_180)` // Status: "Temporary Key Issue Requested" (仮鍵開発依頼済) [-> CD00474_180] |
| 7 | SET | `kojiStatList.add(JKKStrConst.CD00474_190)` // Status: "Field Work Complete" (現場作業完了済) [-> CD00474_190] |

### Block 5 — [CALL] Retrieve work project list (L2847)

> Calls the work project list inquiry service using the service contract number to find associated construction projects.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `cAANMsgCust = getEKU0081B010(handle, param, fixedText, svcKeiNo)` // Get work project list for service contract [-> EKU0081B010] |

### Block 6 — [IF] Work project list exists (L2849)

> Checks whether work projects were returned for the service contract number.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (cAANMsgCust != null)` // Check if work project list is not null [-> L2849] |

#### Block 6.1 — [IF] Work project list has records (L2851)

> OM-2018-0001092 ADD — Additional check for non-empty array length.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (cAANMsgCust.length != 0)` // Check if list has at least one record [-> L2851] |

##### Block 6.1.1 — [SET] Extract work project number (L2854)

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiakNo = getNullToStr(cAANMsgCust[0].getString(EKU0081B010CBSMsg1List.KOJIAK_NO))` // Work project number from first entry [-> EKU0081B010CBSMsg1List.KOJIAK_NO] |

##### Block 6.1.2 — [CALL] Get work project consent details (L2858)

> Calls the work project consent/agreement inquiry to get status, type, and cancellation flag.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `cAANMsgKoji = getEKU0011A010(handle, param, fixedText, kojiakNo)` // Get work project consent details [-> EKU0011A010] |

###### Block 6.1.2.1 — [IF] Consent details exist (L2860)

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (cAANMsgKoji != null)` // Check if consent details returned [-> L2860] |

####### Block 6.1.2.1.1 — [SET] Read consent fields (L2863–L2867)

| # | Type | Code |
|---|------|------|
| 1 | SET | `kojiakStat = getNullToStr(cAANMsgKoji.getString(EKU0011A010CBSMsg1List.KOJIAK_STAT))` // Work project status [-> EKU0011A010CBSMsg1List.KOJIAK_STAT] |
| 2 | SET | `kojiakSbtCd = getNullToStr(cAANMsgKoji.getString(EKU0011A010CBSMsg1List.KOJIAK_SBT_CD))` // Work project type code [-> EKU0011A010CBSMsg1List.KOJIAK_SBT_CD] |
| 3 | SET | `kjKrCnclFlg = getNullToStr(cAANMsgKoji.getString(EKU0011A010CBSMsg1List.KJ_KR_CNCL_FLG))` // Temporary cancellation flag [-> EKU0011A010CBSMsg1List.KJ_KR_CNCL_FLG] |

### Block 7 — [IF] Pre-completed status override (L2884)

> If the raw status is "010" (pre-completed/受付済), convert it to "000" (active) for display purposes. This ensures that contracts in the pre-completed state are displayed as active.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if ("010".equals(svcKeiUcwkStat))` // Pre-completed status check [-> "010"] |
| 2 | SET | `svcKeiUcwkStat = "000"` // Override to active status (契約中) [-> "000"] |

### Block 8 — [ELSE-IF] Verified/Completed status handling (L2899)

> If status is "020" (verified/照会済) or "030" (completed/締結済), apply complex business rules to determine the display status. The commented-out section from a previous version (v5.00.14) shows the evolution of this logic.

| # | Type | Code |
|---|------|------|
| 1 | ELSE-IF | `else if ("020".equals(svcKeiUcwkStat) || "030".equals(svcKeiUcwkStat))` // Verified or completed status [-> "020" or "030"] |

#### Block 8.1 — [IF] Inspection NOT OK for verified status (L2902)

> For verified contracts ("020") where the work detail inspection/check is NOT OK, override to "910" (canceled/解約済). This prevents contracts with failed inspection from showing as verified.

| # | Type | Code |
|---|------|------|
| 1 | IF | `if (!isUcwkShosaOK(handle, param, fixedText, svcKeiUcwkNo) && "020".equals(svcKeiUcwkStat))` // Inspection NG for verified status [-> status "020"] |
| 2 | SET | `svcKeiUcwkStat = "910"` // Override to canceled status (解約済) [-> "910"] |

#### Block 8.2 — [ELSE-IF] Temporary cancellation on active new construction (L2908)

> For contracts where inspection IS OK (or status is "030"), but there is a work project with new construction type ("001") in a valid ongoing status and a temporary cancellation flag set, override to "910" (canceled). This handles cases where a customer has requested cancellation while construction is still in progress.

| # | Type | Code |
|---|------|------|
| 1 | ELSE-IF | `else if ("001".equals(kojiakSbtCd) && kojiStatList.contains(kojiakStat) && "1".equals(kjKrCnclFlg))` // New construction + valid status + cancellation flag [-> KOJIAK_SBT_CD="001", kjKrCnclFlg="1"] |
| 2 | SET | `svcKeiUcwkStat = "910"` // Override to canceled status (解約済) — temporary cancellation state for new construction work [-> "910"] |

### Block 9 — [CALL] Code name lookup (L2917)

> Converts the resolved numeric status code into a human-readable display name using the code name management system.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `cAANMsgCdNmKanri = getEZM0171A010(handle, param, fixedText, "CD01537", svcKeiUcwkStat)` // Look up status code name in CD01537 [-> CD01537 code type] |

### Block 10 — [RETURN] Return display name (L2919)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return getNullToStr(cAANMsgCdNmKanri.getString(EZM0171A010CBSMsg1List.CD_DIV_NM))` // Human-readable contract status name [-> EZM0171A010CBSMsg1List.CD_DIV_NM] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svc_kei_ucwk_stat` | Field | Service contract status — numeric code representing the current state of a service contract line item |
| `svc_kei_no` | Field | Service contract number — unique identifier for the service contract header record |
| `svc_kei_ucwk_no` | Field | Service contract work detail number — internal tracking ID for service contract work details |
| `kojiak_no` | Field | Work project number — unique identifier for a work project (construction/installation project) |
| `kojiak_stat` | Field | Work project status — indicates the current stage of construction/installation work |
| `kojiak_sbt_cd` | Field | Work project type code — classifies the type of work project (e.g., "001" = new construction, 新設) |
| `kjKrCnclFlg` | Field | Temporary cancellation flag — "1" indicates the project is in a temporary cancellation state (仮キャンセル) |
| `cd_div_nm` | Field | Code division name — human-readable label for a code value in the code name management table |
| CD01537 | Constant | Code name management table type for service contract status display names |
| CD00474_140 | Constant | Work project status code: "Under Request" (依頼中) |
| CD00474_150 | Constant | Work project status code: "Survey Complete" (宅内調査完了済) |
| CD00474_160 | Constant | Work project status code: "Contractor Decided" (工事会社決定済) |
| CD00474_170 | Constant | Work project status code: "Equipment Pre-Registered" (宅内機器予定登録済) |
| CD00474_180 | Constant | Work project status code: "Temporary Key Issue Requested" (仮鍵開発依頼済) |
| CD00474_190 | Constant | Work project status code: "Field Work Complete" (現場作業完了済) |
| "000" | Status | Contract active (契約中) — the contract is in normal active state |
| "010" | Status | Pre-completed (受付済) — the contract has been received/accepted but not yet finalized |
| "020" | Status | Verified/Inquired (照会済) — the contract has been verified through inquiry checks |
| "030" | Status | Completed/Executed (締結済) — the contract has been finalized and executed |
| "910" | Status | Canceled (解約済) — the contract has been canceled; used as an override display status |
| "001" | Type code | New construction (新設) — the work project type is a new service installation |
| "1" | Flag value | Cancellation flag set (有) — the temporary cancellation state is active |
| `isUcwkShosaOK` | Method | Work detail inspection check — validates whether the service contract work details have passed inspection/approval |
| `getEKU0081B010` | Service | Work project list inquiry — retrieves all work projects associated with a service contract |
| `getEKU0011A010` | Service | Work project consent/agreement inquiry — retrieves detailed consent information for a specific work project |
| `getEZM0171A010` | Service | Code name management lookup — converts a code value to its human-readable display name from the code table |
| `getNullToStr` | Utility | Null-safe string conversion — returns empty string if the input is null, preventing null pointer exceptions |
| CAANMsg | Type | Common Application ANd Message — a generic message container used for data exchange between service components |
| KOJIAK | Entity | Work Project (工事案件) — the database entity/table storing construction/installation project data |
| CD01537 | Entity | Code name management table — stores human-readable labels for status/display codes |
