# Business Logic — JKKKisnUwHmdkAddCC.execUpdSvcKeiKaisenUcwk() [90 LOC]

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

## 1. Role

### JKKKisnUwHmdkAddCC.execUpdSvcKeiKaisenUcwk()

This method executes the **service contract line item consolidation** (併合処理 — heigou shori) workflow, which merges two service contract line items into a single consolidated record. In the telecommunications billing domain, line item consolidation is the process of combining a "make-up source" (併合元 — heigou moto) line item with a "consolidation target" (併合先 — heigou saki) line item so that the target absorbs the source's attributes and the source is effectively retired. The method delegates to four distinct service components: two reads via `EKK0251A010CBS` (service contract line item agreement lookup for both source and target), one update via `EKK0251C030CBS` (service contract line item content modification that merges target attributes with source fallback values), and optionally one insert via `EKU0281D010CBS` (vacancy information registration for the target when the source has vacancy data but the target lacks it). The method implements a **gate-and-merge** design pattern — early returns on missing data prevent orphaned partial updates, while the `editInMsgEKK0251C030` helper applies a source-fallback strategy that preserves target values whenever they exist, only substituting source values as a fallback. This method serves as a shared utility called by `execKisnHeigo()`, the parent line item consolidation orchestrator that coordinates multiple consolidation sub-operations.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execUpdSvcKeiKaisenUcwk(params)"])
    READ_MT_SVC["Read EKK0251A010CBS
(Make-up Source)"]
    CHECK_MT{"mtEkk0251a010Out
empty?"}
    READ_SK_SVC["Read EKK0251A010CBS
(Consolidation Target)"]
    CHECK_SK{"skEkk0251a010Out
empty?"}
    BUILD_UPDATE["Build editInMsgEKK0251C030
(Merge sk values, fallback to mt)"]
    UPDATE_SVC["Call SC EKK0251C030
(Service Contract Line Item Update)"]
    READ_MT_VAC["Read EKU0281A010CBS
(Make-up Source Vacancy)"]
    CHECK_VAC{"mtEku0281a010Out
has data?"}
    READ_SK_VAC["Read EKU0281A010CBS
(Target Vacancy)"]
    CHECK_SK_VAC{"skEku0281a010Out
empty?"}
    INSERT_VAC["Call SC EKU0281D010
(Target Vacancy Insert)"]
    END_NODE(["Return / Next"])

    START --> READ_MT_SVC --> CHECK_MT
    CHECK_MT -->|"Yes"| END_NODE
    CHECK_MT -->|"No"| READ_SK_SVC --> CHECK_SK
    CHECK_SK -->|"Yes"| END_NODE
    CHECK_SK -->|"No"| BUILD_UPDATE --> UPDATE_SVC --> READ_MT_VAC --> CHECK_VAC
    CHECK_VAC -->|"No"| END_NODE
    CHECK_VAC -->|"Yes"| READ_SK_VAC --> CHECK_SK_VAC
    CHECK_SK_VAC -->|"Yes"| END_NODE
    CHECK_SK_VAC -->|"No"| INSERT_VAC --> END_NODE
```

**Constant Resolution:**
- `TEMPLATE_ID_EKK0251A010 = "EKK0251A010"` — Service Contract Line Item Agreement (サービス契約回線内訳同意照会)
- `TEMPLATE_ID_EKK0251C030 = "EKK0251C030"` — Service Contract Line Item Content Modification (サービス契約回線内訳内容変更)
- `TEMPLATE_ID_EKU0281A010 = "EKU0281A010"` — Vacancy Information Agreement (申収容位置空き情報同意照会)
- `TEMPLATE_ID_EKU0281D010 = "EKU0281D010"` — Vacancy Information Registration (申収容位置空き情報登録)
- `FUNC_CODE = "2"` — Read/Inquiry function code (via `JPCModelConstant.FUNC_CD_2`)
- `FUNC_CODE = "1"` — Update/Modification function code (in `editInMsgEKK0251C030`)
- `mskmDtlNo` — Used as the update target key (未仕掛詳細番号 / uncompleted detail number)

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle for the current transaction context. Provides the connection and session state for executing service component calls. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | Service Component invocation dispatcher. Forwards service component requests to the appropriate backend CBS (Component-Based Service) layer for data operations. |
| 3 | `param` | `IRequestParameterReadWrite` | Request parameter object used to read/write business parameters across the service component boundary. Carries context data such as function codes and template IDs. |
| 4 | `fixedText` | `String` | Fixed text value passed through to service component calls. Typically used for error messages, log identifiers, or system-generated text that must remain constant across a single operation. |
| 5 | `ccMsg` | `HashMap<String, Object>` | Cross-component message carrier. Contains the consolidation keys: `"heigo_mt_svc_kei_kaisen_ucwk_no"` (make-up source line item work number) and `"heigo_sk_svc_kei_kaisen_ucwk_no"` (consolidation target line item work number), plus `"func_code"` for the vacancy insert operation. This map flows between consolidation sub-operations. |
| 6 | `mskmDtlNo` | `String` | Uncompleted detail number (未仕掛詳細番号 — mimisugashi shousai bangou). Identifies the specific detail record being updated in the service contract line item modification. Serves as the primary key for the update target in EKK0251C030. |

**External State / Instance Fields:**
- `TEMPLATE_ID_EKK0251A010` — constant, template ID for service contract line item agreement CBS
- `TEMPLATE_ID_EKK0251C030` — constant, template ID for service contract line item content modification CBS
- `TEMPLATE_ID_EKU0281A010` — constant, template ID for vacancy information agreement CBS
- `TEMPLATE_ID_EKU0281D010` — constant, template ID for vacancy information registration CBS
- `JPCModelConstant.FUNC_CD_2` — constant, value `"2"` meaning read/inquiry operation

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `callSC` (EKK0251A010CBS) | EKK0251A010SC | Service contract line item agreement table | Reads make-up source (併合元) line item agreement data by `heigo_mt_svc_kei_kaisen_ucwk_no` |
| R | `callSC` (EKK0251A010CBS) | EKK0251A010SC | Service contract line item agreement table | Reads consolidation target (併合先) line item agreement data by `heigo_sk_svc_kei_kaisen_ucwk_no` |
| U | `editInMsgEKK0251C030` + `callSC` (EKK0251C030CBS) | EKK0251C030SC | Service contract line item content table | Updates the consolidation target's line item details, merging target values with source fallback values for fields the target lacks |
| R | `callSC` (EKU0281A010CBS) | EKU0281A010SC | Vacancy information table (read) | Reads make-up source (併合元) vacancy information by `heigo_mt_svc_kei_kaisen_ucwk_no` |
| R | `callSC` (EKU0281A010CBS) | EKU0281A010SC | Vacancy information table (read) | Reads consolidation target (併合先) vacancy information by `heigo_sk_svc_kei_kaisen_ucwk_no` |
| C | `callSC` (EKU0281D010CBS) | EKU0281D010SC | Vacancy information table (insert) | Registers new vacancy record for consolidation target when target has no vacancy data but source does — copies `KOJIAK_NO`, `OYA_KIKI_SBT_CD`, `CT_NO`, `CT_AKI_UM` from source to target |

**How classified:**
- **R** (Read): SC codes containing `A010` suffix (agreement lookup) — these invoke read/inquiry operations
- **U** (Update): SC code `C030` suffix (content modification) — this invokes update/modify operations with func_code `"1"`
- **C** (Create): SC code `D010` suffix (registration) — this invokes insert/register operations
- `editInMsgEKK0251C030` is a private helper that builds the input array for the EKK0251C030 update call
- `callSC` is the internal delegation method that routes all service component calls in this class

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS: `JKKKisnUwHmdkAddCC.execKisnHeigo` | `execKisnHeigo` -> `execUpdSvcKeiKaisenUcwk` | `EKK0251A010SC [R] ×2, EKK0251C030SC [U], EKU0281A010SC [R] ×2, EKU0281D010SC [C]` |

**Notes:**
- `execKisnHeigo()` is the parent consolidation orchestrator that calls this method as one of its sub-operations during line item consolidation.
- The method does not have direct screen entry points within 8 hops — it is a component-level utility called from CBS layer methods.
- All terminal operations flow through `callSC` invocations to the CBS layer, which ultimately perform reads and writes against service contract line item and vacancy information database tables.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET / READ] `(Make-up Source: Service Contract Line Item Agreement Lookup)` (L1414)

> Reads the make-up source (併合元) service contract line item agreement data. Prepares the input message with template ID, function code "2" (read), and the source work number from ccMsg.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mtEkk0251a010In = {{TEMPLATE_ID_EKK0251A010, "EKK0251A010"}, {FUNC_CODE, "2"}, {KEY_SVC_KEI_KAISEN_UCWK_NO, ccMsg.get("heigo_mt_svc_kei_kaisen_ucwk_no")}}` // [-> TEMPLATE_ID_EKK0251A010="EKK0251A010", FUNC_CODE="2" (read/inquiry)] |
| 2 | CALL | `mtEkk0251a010Out = callSC(handle, scCall, param, fixedText, mtEkk0251a010In).getCAANMsgList(EKK0251A010CBSMsg.EKK0251A010CBSMSG1LIST)` // Reads make-up source line item agreement |

**Block 2** — [IF] `(mtEkk0251a010Out == null || mtEkk0251a010Out.length == 0)` (L1423)

> Early return if no make-up source data is found. This prevents consolidation with a non-existent source line item, ensuring data integrity.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // No make-up source data — abort consolidation |

**Block 3** — [SET / READ] `(Consolidation Target: Service Contract Line Item Agreement Lookup)` (L1428)

> Reads the consolidation target (併合先) service contract line item agreement data. Prepares input with template ID, function code "2", and target work number from ccMsg.

| # | Type | Code |
|---|------|------|
| 1 | SET | `skEkk0251a010In = {{TEMPLATE_ID_EKK0251A010, "EKK0251A010"}, {FUNC_CODE, "2"}, {KEY_SVC_KEI_KAISEN_UCWK_NO, ccMsg.get("heigo_sk_svc_kei_kaisen_ucwk_no")}}` // [-> FUNC_CODE="2" (read/inquiry)] |
| 2 | CALL | `skEkk0251a010Out = callSC(handle, scCall, param, fixedText, skEkk0251a010In).getCAANMsgList(EKK0251A010CBSMsg.EKK0251A010CBSMSG1LIST)` // Reads consolidation target line item agreement |

**Block 4** — [IF] `(skEkk0251a010Out == null || skEkk0251a010Out.length == 0)` (L1437)

> Early return if no consolidation target data is found. Prevents updating a non-existent target record.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // No consolidation target data — abort consolidation |

**Block 5** — [SET / READ] `(Service Contract Line Item Content Update)` (L1443)

> Prepares and executes the update of the consolidation target's line item details. The `editInMsgEKK0251C030` helper builds the input by merging target values with source fallback values for all modifiable fields.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `ekk0251c030In = editInMsgEKK0251C030(ccMsg, mtEkk0251a010Out[0], skEkk0251a010Out[0], mskmDtlNo)` // [-> FUNC_CODE="1" (update/modify); merges sk values with mt fallback via getUpdValue()] |
| 2 | CALL | `callSC(handle, scCall, param, fixedText, ekk0251c030In)` // Updates service contract line item content (EKK0251C030CBS) |

**Block 6** — [SET / READ] `(Make-up Source: Vacancy Information Agreement)` (L1447)

> IT2-2021-0000030 ADD: Reads vacancy information for the make-up source. Prepares input with template ID, function code "2" (read via `JPCModelConstant.FUNC_CD_2`), and source work number.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mtEku0281a010In = {{TEMPLATE_ID_EKU0281A010, "EKU0281A010"}, {FUNC_CODE, JPCModelConstant.FUNC_CD_2 ("2")}, {KEY_SVC_KEI_KAISEN_UCWK_NO, ccMsg.get("heigo_mt_svc_kei_kaisen_ucwk_no")}}` // IT2-2021-0000030 ADD — reads vacancy info |
| 2 | CALL | `mtEku0281a010Out = callSC(handle, scCall, param, fixedText, mtEku0281a010In).getCAANMsgList(EKU0281A010CBSMsg.EKU0281A010CBSMSG1LIST)` // Reads make-up source vacancy data |

**Block 7** — [IF] `(mtEku0281a010Out != null && mtEku0281a010Out.length > 0)` (L1455)

> The make-up source has vacancy information. This branch checks whether the consolidation target also has vacancy data. If the target lacks it, the source's vacancy data is copied to the target.

**Block 7.1** — [SET / READ] `(Consolidation Target: Vacancy Information Agreement)` (L1458)

> Reads vacancy information for the consolidation target using the same template and function code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `skEku0281a010In = {{TEMPLATE_ID_EKU0281A010, "EKU0281A010"}, {FUNC_CODE, JPCModelConstant.FUNC_CD_2 ("2")}, {KEY_SVC_KEI_KAISEN_UCWK_NO, ccMsg.get("heigo_sk_svc_kei_kaisen_ucwk_no")}}` // Reads target vacancy data |
| 2 | CALL | `skEku0281a010Out = callSC(handle, scCall, param, fixedText, skEku0281a010In).getCAANMsgList(EKU0281A010CBSMsg.EKU0281A010CBSMSG1LIST)` // Reads consolidation target vacancy info |

**Block 7.2** — [IF] `(skEku0281a010Out == null || skEku0281a010Out.length == 0)` (L1466)

> The consolidation target lacks vacancy information while the make-up source has it. This triggers registration of the source's vacancy data as a new record for the target — effectively migrating vacancy information from source to target during consolidation.

**Block 7.2.1** — [SET / CREATE] `(Consolidation Target: Vacancy Information Registration)` (L1471)

> Builds the insert payload by extracting key fields from the make-up source vacancy record and binding them to the target's work number. Uses `ccMsg.get("func_code")` as the function code (dynamically provided by caller).

| # | Type | Code |
|---|------|------|
| 1 | SET | `skEku0281D010In = {{TEMPLATE_ID_EKU0281D010, "EKU0281D010"}, {FUNC_CODE, ccMsg.get("func_code")}, {SVC_KEI_KAISEN_UCWK_NO, ccMsg.get("heigo_sk_svc_kei_kaisen_ucwk_no")}, {KOJIAK_NO, mtEku0281a010Out[0].getString(EKU0281A010CBSMsg1List.KOJIAK_NO)}, {OYA_KIKI_SBT_CD, mtEku0281a010Out[0].getString(EKU0281A010CBSMsg1List.OYA_KIKI_SBT_CD)}, {CT_NO, mtEku0281a010Out[0].getString(EKU0281A010CBSMsg1List.CT_NO)}, {CT_AKI_UM, mtEku0281a010Out[0].getString(EKU0281A010CBSMsg1List.CT_AKI_UM)}}` |
| 2 | CALL | `callSC(handle, scCall, param, fixedText, skEku0281D010In)` // Inserts vacancy record for target (EKU0281D010CBS) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| 併合 (heigou) | Business term | Line item consolidation — the process of merging a "make-up source" line item into a "consolidation target" line item, effectively retiring the source and absorbing its data into the target |
| 併合元 (heigou moto) | Business term | Make-up source — the line item being consolidated away; its data is read and used as fallback values during merge |
| 併合先 (heigou saki) | Business term | Consolidation target — the line item receiving the source's data; its existing values take priority, with source values as fallback |
| svc_kei_kaisen_ucwk_no | Field | Service contract line item work number — internal tracking identifier for a service contract line item record in the agreement table |
| mskmDtlNo | Field | Uncompleted detail number (未仕掛詳細番号) — identifies the specific detail record being updated during line item content modification |
| heigo_mt_svc_kei_kaisen_ucwk_no | Field | Map key — the make-up source work number stored in the ccMsg cross-component message carrier |
| heigo_sk_svc_kei_kaisen_ucwk_no | Field | Map key — the consolidation target work number stored in the ccMsg cross-component message carrier |
| EKK0251A010 | CBS | Service Contract Line Item Agreement (サービス契約回線内訳同意照会) — reads/inquires service contract line item details |
| EKK0251C030 | CBS | Service Contract Line Item Content Modification (サービス契約回線内訳内容変更) — updates service contract line item details; function code "1" = update |
| EKU0281A010 | CBS | Vacancy Information Agreement (申収容位置空き情報同意照会) — reads vacancy information (available installation location data) |
| EKU0281D010 | CBS | Vacancy Information Registration (申収容位置空き情報登録) — inserts new vacancy information records; function code varies by caller |
| func_code | Field | Function code discriminator — `"2"` for read/inquiry operations, `"1"` for update/modify operations |
| KOJIAK_NO | Field | Individual customer number (個人番号) — identifies the individual customer associated with the vacancy record |
| OYA_KIKI_SBT_CD | Field | Parent device subtype code (親機器サブタイプコード) — classifies the type of parent networking equipment |
| CT_NO | Field | Cable termination / cable type number (回線番号) — identifies the specific cable or circuit line |
| CT_AKI_UM | Field | Cable vacancy availability flag (回線空き有無) — indicates whether the cable line has available capacity for new service |
| TEMPLATE_ID | Field | Template identifier — the CBS template name (e.g., `"EKK0251A010"`) used to route service component requests to the correct backend handler |
| getUpdValue | Method | Source-fallback utility — returns the target value if non-null, otherwise returns the source value; implements the merge priority strategy in `editInMsgEKK0251C030` |
| ccMsg | Field | Cross-component message — HashMap carrying shared state between consolidation sub-operations |
| JPCModelConstant | Class | Global constant holder for shared model-layer constants (e.g., `FUNC_CD_2`) |
