# Business Logic — JDKCommon48CC.updateStock() [51 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JDKCommon48CC` |
| Layer | CC/Common Component — Business logic shared across BPM operations |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JDKCommon48CC.updateStock()

This method performs **return-stock shelf assignment and indoor appliance repair exchange information update** (返却登録宅内連携処理). It is invoked during the return processing flow for home appliance installations (HMPIN — Home Appliance Connection) where returned or replaced devices need to be assigned to the appropriate warehouse shelf (回送棚 or 修理棚) and their stock status updated in the backend system.

The method handles two distinct business scenarios: (1) when battery safety inspection is **completed** (`BTRYHOZN_COMPLETE`), the device is placed on the **return shelf** (Henpin Tana); (2) when the device is a **substitute/replacement unit** (`SUBSTITUTE`), it is also routed to the **return shelf**. In all other cases (device under repair), the shelf is set to **repair shelf** (Shuri Tana). For devices on the repair shelf, the goods status code is explicitly set to `-` (returned-but-not-yet-processed-other); for devices on the return shelf, the original goods status code from the SC response is preserved.

The method implements a **composite update pattern**: it first gathers device metadata (model code, serial number) from a prior CC result, enriches the work records with storage and shelf assignment information, conditionally queries the last update timestamp from the indoor appliance baseline data, and then invokes an SC (Service Component) `EDKA0010006CBS` to persist the updated repair/exchange information. Finally, it triggers the HMPIN service order creation (`addHmpinSodHakko`) and validates for errors before returning.

As a shared common component (CC), it is called by multiple BPM flows under the DKSV0050 screen family and serves as a bridge between the BPM orchestration layer and the underlying SC for indoor appliance inventory management.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateStock(handle, param, fixedText)"])
    
    START --> INV["Create ServiceComponentRequestInvoker scCall"]
    INV --> GET_DKCC["Get DKSV005005CC result map from param"]
    GET_DKCC --> GET_WORKS["Get works list from workArea.work"]
    GET_WORKS --> CHECK_BTRY["Check BTRYHOZN_STAT for COMPLETED"]
    CHECK_BTRY --> CHECK_SUB["Check hmpin_kbn for SUBSTITUTE"]
    CHECK_SUB --> PUT_MODEL["Put taknkiki_model_cd to works[0]"]
    PUT_MODEL --> PUT_SERIAL["Put kiki_seizo_no to works[0]"]
    PUT_SERIAL --> CHECK_SERIAL{"kiki_seizo_no is not null?"}
    CHECK_SERIAL -->|Yes| CALL_LASTDTM["Call JDKBPCommon.getLastUpdateDtm"]
    CHECK_SERIAL -->|No| PUT_SOKO["Put soko_cd from DKSV005001SC"]
    CALL_LASTDTM --> PUT_UPDDTTM["Put KIHON_UPD_DTTM from basements[0].KHN_MOD_DTTM"]
    PUT_UPDDTTM --> PUT_SOKO
    PUT_SOKO --> CHECK_SHELF["Evaluate: isCompletedBtryhozn || isDaitaiki"]
    CHECK_SHELF -->|True| SET_HENPIN["shelfCd = HENPIN_TANA = 005 (Return Shelf)"]
    CHECK_SHELF -->|False| SET_SHURI["shelfCd = SHURI_TANA = 008 (Repair Shelf)"]
    SET_HENPIN --> PUT_SHELF["Put shelfCd to works[0]"]
    SET_SHURI --> PUT_SHELF
    PUT_SHELF --> CHECK_SHURIFLAG{"shelfCd == SHURI_TANA?"}
    CHECK_SHURIFLAG -->|Yes| SET_GDSSTAT["gds_stat_cd = GDS_STAT_HMPINDNA_OTHER = '-' (Returned-Not-Processed-Other)"]
    CHECK_SHURIFLAG -->|No| GET_ORIG_GDS["gds_stat_cd = soko_cd from DKSV005001SC"]
    SET_GDSSTAT --> PUT_KNRI["Put TTM_DIV to KNRI_PLC_SKBT_CD"]
    GET_ORIG_GDS --> PUT_KNRI
    PUT_KNRI --> EDIT_IN["Call MAPPER.editInMsg(param)"]
    EDIT_IN --> LOG_PRINT["Print debug log: 宅内機器修理交換情報更新処理の実行"]
    LOG_PRINT --> SC_RUN["Call scCall.run(inMap, handle) → EDKA0010006CBS"]
    SC_RUN --> EDIT_RP["Call MAPPER.editResultRP(result, param)"]
    EDIT_RP --> ADD_SOD["Call this.addHmpinSodHakko(handle, param, scCall)"]
    ADD_SOD --> CHECK_ERR{"JDKBPCommon.hasError(param)?"}
    CHECK_ERR -->|Yes| THROW_ERR["Throw SCCallException: 宅内機器修理交換情報更新処理失敗"]
    CHECK_ERR -->|No| THROW_REMAIN["Call throwScExceptionIfHasError: リターンコード不正"]
    THROW_ERR --> END(["End"])
    THROW_REMAIN --> END
```

### Branch Descriptions:

- **Branch 1** (L145–152): The `if` block checks whether `kiki_seizo_no` (device serial number) is present. If present, it calls `JDKBPCommon.getLastUpdateDtm()` to query the last update timestamp for the indoor appliance basements, then writes the modification timestamp to the work record.

- **Branch 2** (L160): Ternary conditional — if battery safety inspection is completed OR the device is a substitute unit, set `shelfCd` to the **return shelf** (回送棚, code `"005"`); otherwise set it to the **repair shelf** (修理棚, code `"008"`).

- **Branch 3** (L162–165): Nested ternary — if the shelf is the repair shelf, set `gds_stat_cd` to `-` (goods status: returned-but-not-processed-other); if the shelf is the return shelf, preserve the original goods status code from the SC response.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle for the current user transaction. Carries the database connection context used for all SC calls and data reads within this method (e.g., `getLastUpdateDtm`). |
| 2 | `param` | `IRequestParameterReadWrite` | Business data payload and control map. Contains: (a) prior CC result (`DKSV005005CC`) with device metadata (model code, serial number, replacement type); (b) work area with `works` list of indoor appliance records to be updated; (c) storage code from `DKSV005001SC`; (d) control map for return codes and error flags. This object is mutated throughout the method — shelf assignment, goods status, update timestamps, and KNRI placement code are all written back here. |
| 3 | `fixedText` | `String` | Fixed text string used for exception judgment messages. Passed to the `CCRequestBroker` at the caller level; within this method it is not directly referenced but is part of the method signature for the common component contract. |

**Additional fields/state referenced:**

| Source | Description |
|--------|-------------|
| `param.getData("DKSV005005CC")` | Map containing prior CC result — provides `hmpin_kbn` (HMPIN classification — `SUBSTITUTE` indicates a replacement device) and `taknkiki_model_cd` / `kiki_seizo_no` (indoor appliance model code and serial number). |
| `param.getMappingWorkArea().get("work").get("works")` | List of maps — each entry represents an indoor appliance work record being processed. `works[0]` is the primary record updated. |
| `param.getData("DKSV005001SC")` | HashMap — storage code and original goods status code from the storage inquiry SC. |
| `list.get(0).get("btryhozn_stat")` | Battery safety inspection status code — compared against `BTRYHOZN_COMPLETE = "004"` to determine inspection completion. |
| `MAPPER` | `EDKA0010006BSMapper` — used to transform `param` into the SC request map (`inMap`) and process the SC response back into `param`. |
| `scCall` | `ServiceComponentRequestInvoker` — invokes the `EDKA0010006CBS` SC to persist the updated indoor appliance repair/exchange data. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JDKBPCommon.getLastUpdateDtm` | (utility) | Indoor appliance baseline table | Reads the last update timestamp for indoor appliance basements, filtered by model code and serial number. Used to populate the update timestamp field. |
| U | `DKSV0050_DKSV0050OP_EDKA0010006BSMapper.editInMsg` | (mapper) | — | Transforms `param` data into the request map (`inMap`) structure expected by `EDKA0010006CBS`. Performs field mapping and data preparation. |
| U | `EDKA0010006CBS` | EDKA0010006CBS | Indoor appliance repair/exchange table | The central CBS call that updates (edits) the indoor appliance repair/exchange stock information in the database. The CBS receives the prepared request map and persists changes. |
| U | `DKSV0050_DKSV0050OP_EDKA0010006BSMapper.editResultRP` | (mapper) | — | Processes the CBS response (`result`) and writes the response data back into `param`. Performs response-to-payload mapping. |
| C | `JDKCommon48CC.addHmpinSodHakko` | (CC internal) | SOD (Service Order Data) table | Creates a new HMPIN service order record. Invoked to register the service order data after the indoor appliance stock update completes. See ANK-2119-00-00 change request. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:DKSV0050 | `DKSV0050OPOperation.run` -> `getBPMOperator().run(target7, param, dbConInfo)` -> `CCRequestBroker.invokeCC` -> `JDKCommon48CC.updateStock` | `EDKA0010006CBS [U] indoor appliance repair/exchange table` + `addHmpinSodHakko [C] SOD table` |

**Explanation:** The method is invoked exclusively through the `CCRequestBroker` named `target7` in `DKSV0050OPOperation`. This operation belongs to the DKSV0050 BPM flow, which handles the indoor appliance (HMPIN) return processing screen. The `CCRequestBroker` resolves the class `JDKCommon48CC` at runtime, invokes the `updateStock` method, and passes the `DKSV005005CC` result data as part of the `param` payload.

## 6. Per-Branch Detail Blocks

**Block 1** — [ASSIGNMENT] `(Initialize objects and extract data)` (L141)

> Initialize the service component request invoker and extract prior CC result and work records from the parameter.

| # | Type | Code |
|---|------|------|
| 1 | SET | `scCall = new ServiceComponentRequestInvoker()` // Service component call runner |
| 2 | SET | `dksv00505cc = (HashMap)param.getData("DKSV005005CC")` // Prior CC result with device metadata [-> DKSV005005CC] |
| 3 | SET | `list = (List<Map>)((Map)param.getMappingWorkArea().get("work")).get("works")` // Work records list — indoor appliance items to be updated |
| 4 | SET | `isCompletedBtryhozn = JDKStrConst.BTRYHOZN_COMPLETE.equals(list.get(0).get("btryhozn_stat"))` // Check if battery safety inspection is done [-> BTRYHOZN_COMPLETE="004" (JDKStrConst.java:214)] |
| 5 | SET | `isDaitaiki = JDKStrConst.SUBSTITUTE.equals(dksv00505cc.get("hmpin_kbn"))` // Check if device is a substitute/replacement unit [-> SUBSTITUTE="3" (JDKStrConst.java:297)] |

**Block 2** — [ASSIGNMENT] `(Write device metadata to work record)` (L148)

> Populate the primary work record with the indoor appliance model code and serial number from the prior CC result.

| # | Type | Code |
|---|------|------|
| 1 | SET | `list.get(0).put("taknkiki_model_cd", dksv00505cc.get("taknkiki_model_cd"))` // Indoor appliance model code |
| 2 | SET | `list.get(0).put("kiki_seizo_no", dksv00505cc.get("kiki_seizo_no"))` // Device serial number |

**Block 3** — [IF] `(Conditional: kiki_seizo_no is not null)` (L149)

> If a serial number is present, query the last modification timestamp for indoor appliance basements and write it to the work record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `takunaiBasements = JDKBPCommon.getLastUpdateDtm(list, "taknkiki_model_cd", "kiki_seizo_no", handle, param)` // Query last update timestamp by model + serial |
| 2 | SET | `list.get(0).put(EDKA0010006CBSMsg1List.KEY_KIHON_UPD_DTTM, takunaiBasements.get(0).get(EDKA0010008CBSMsg1List.KHN_MOD_DTTM))` // Write modification timestamp from basement record [-> KEY_KIHON_UPD_DTTM, KHN_MOD_DTTM] |

**Block 4** — [ASSIGNMENT] `(Write storage code)` (L155)

> Fetch the storage code and original goods status code from the storage inquiry SC result (`DKSV005001SC`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `list.get(0).put("soko_cd", ((HashMap)param.getData("DKSV005001SC")).get("soko_cd"))` // Storage/warehouse code |

**Block 5** — [IF/TERNARY] `(Determine shelf assignment: Return vs Repair)` (L160)

> Conditional branch based on two criteria: (1) battery safety inspection status, (2) whether the device is a substitute. The business rule is: if inspection is complete OR device is substitute → return shelf; otherwise → repair shelf.

| # | Type | Code |
|---|------|------|
| 1 | SET | `shelfCd = (isCompletedBtryhozn || isDaitaiki) ? JDKStrConst.HENPIN_TANA : JDKStrConst.SHURI_TANA` // Ternary — HENPIN_TANA="005" (回送棚/Return Shelf) [-> HENPIN_TANA="005" (JDKStrConst.java:204)] or SHURI_TANA="008" (修理棚/Repair Shelf) [-> SHURI_TANA="008" (JDKStrConst.java:207)] |
| 2 | SET | `list.get(0).put("shelf_cd", shelfCd)` // Assign shelf to work record |

**Block 6** — [IF/TERNARY] `(Determine goods status code by shelf type)` (L162–165)

> If on the repair shelf, set goods status to `-` (returned-but-not-processed-other); if on the return shelf, keep the original goods status from storage SC.

| # | Type | Code |
|---|------|------|
| 1 | SET | `list.get(0).put(EDKA0010006CBSMsg1List.GDS_STAT_CD, SHURI_TANA.equals(shelfCd) ? JDKStrConst.GDS_STAT_HMPINDNA_OTHER : ((HashMap)param.getData("DKSV005001SC")).get("gds_stat_cd"))` // If repair shelf: status="-" [-> GDS_STAT_HMPINDNA_OTHER="-" (JDKStrConst.java:471)]; else: original status |

**Block 7** — [ASSIGNMENT] `(Write KNRI placement code)` (L167)

> Assign the KNRI (home appliance installation) placement division code from the prior CC result.

| # | Type | Code |
|---|------|------|
| 1 | SET | `list.get(0).put(EDKA0010006CBSMsg1List.KNRI_PLC_SKBT_CD, dksv00505cc.get(DKSV0050_DKSV0050OP_DKSV005005CC.TTM_DIV))` // KNRI placement sub-division code |

**Block 8** — [ASSIGNMENT + EXEC] `(Map param to SC request, invoke CBS, map response)` (L169–173)

> Convert the enriched work records into the CBS request structure, invoke the EDKA0010006CBS SC, and process the response.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = MAPPER.editInMsg(param)` // Map param to SC request map [-> EDKA0010006BSMapper.editInMsg] |
| 2 | EXEC | `JSYejbLog.println(JSYejbLog.DEBUG, ..., "宅内機器修理交換情報更新処理の実行")` // Debug log: "Execute indoor appliance repair/exchange info update processing" |
| 3 | SET | `result = scCall.run(inMap, handle)` // Invoke EDKA0010006CBS — indoor appliance repair/exchange data update |
| 4 | EXEC | `MAPPER.editResultRP(result, param)` // Map CBS response back to param [-> EDKA0010006BSMapper.editResultRP] |

**Block 9** — [CALL] `(HMPIN Service Order Creation)` (L176)

> Create the HMPIN service order data. This is part of change request ANK-2119-00-00.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `this.addHmpinSodHakko(handle, param, scCall)` // Create HMPIN service order record [ANK-2119-00-00] |

**Block 10** — [IF] `(Error check after CBS call)` (L179)

> If the parameter contains an error flag, throw an exception with the return code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `hasError = JDKBPCommon.hasError(param)` // Check if param has error flags set |
| 2 | RETURN | `throw new SCCallException("宅内機器修理交換情報更新処理失敗", "0", Integer.parseInt(param.getControlMapData("returnCode").toString()))` // Throw exception — return code from param [-> 宅内機器修理交換情報更新処理失敗 = "Indoor appliance repair/exchange update processing failed"] |

**Block 11** — [CALL] `(Remaining error check)` (L184)

> Validate no remaining errors exist after the CBS call.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JDKBPCommon.throwScExceptionIfHasError("宅内機器修理交換情報更新処理リターンコード不正", param)` // Throw if param still has errors — return code anomaly [-> 宅内機器修理交換情報更新処理リターンコード不正 = "Indoor appliance repair/exchange update return code invalid"] |

**Block 12** — [RETURN] `(Return updated param)` (L186)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return param` // Return the enriched parameter for the BPM flow to continue |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `updateStock` | Method | Return-stock shelf assignment and indoor appliance repair/exchange information update. Processes the stock status of returned or replaced home appliances. |
| HMPIN | Business term | Home Appliance Connection / Indoor Appliance — Fujitsu's home networking system integrating appliances within residential premises. HMPIN_KBN classifies the device relationship (e.g., SUBSTITUTE = replacement unit). |
| `btryhozn_stat` | Field | Battery safety inspection status — indicates the inspection state of the appliance's battery. `BTRYHOZN_COMPLETE="004"` means the battery safety check has been completed. |
| `hmpin_kbn` | Field | HMPIN classification type — identifies the relationship of the device (e.g., `SUBSTITUTE="3"` indicates a substitute/replacement unit provided to the customer). |
| `taknkiki_model_cd` | Field | Indoor appliance model code — identifies the specific model of the indoor appliance being processed. |
| `kiki_seizo_no` | Field | Device serial number — unique identifier for the physical indoor appliance unit. |
| `soko_cd` | Field | Storage/warehouse code — identifies which storage location the device belongs to. |
| `shelf_cd` | Field | Shelf code — indicates which warehouse shelf the device should be placed on. `HENPIN_TANA="005"` (回送棚/Return Shelf) for returned units; `SHURI_TANA="008"` (修理棚/Repair Shelf) for units under repair. |
| `gds_stat_cd` | Field | Goods status code — business status of the returned/processed device. `GDS_STAT_HMPINDNA_OTHER="-"` indicates a device that has been returned but not yet processed for other reasons. |
| `KNRI_PLC_SKBT_CD` | Field | KNRI (home appliance installation) placement sub-division code — further classifies how and where the KNRI device is placed. |
| `TTM_DIV` | Field | Installation division code — from DKSV005005CC, indicates the installation service division type. |
| `EDKA0010006CBS` | SC Code | Indoor appliance repair/exchange information update CBS (Closed Business System) — persists the shelf assignment and goods status changes for returned/replaced home appliances. |
| `EDKA0010006BSMapper` | Component | Mapper that converts between the BPM parameter structure and the CBS request/response data structures for EDKA0010006. |
| `EDKA0010008CBSMsg1List.KHN_MOD_DTTM` | Constant | Indoor appliance modification date/time — the timestamp when the indoor appliance baseline record was last modified. Used to set the key basic update date-time. |
| BTRYHOZN_COMPLETE | Constant | Battery safety inspection completed status code — value `"004"`. Indicates the battery safety check for the appliance has passed. |
| HENPIN_TANA | Constant | Return shelf code — value `"005"`. The warehouse shelf where returned (返却) devices are staged. |
| SHURI_TANA | Constant | Repair shelf code — value `"008"`. The warehouse shelf where devices under repair (修理) are placed. |
| SUBSTITUTE | Constant | Substitute/replacement device indicator — value `"3"`. Indicates the device was provided as a substitute for a faulty unit. |
| GDS_STAT_HMPINDNA_OTHER | Constant | Goods status for returned-but-not-processed-other — value `"-"`. Applied when a device is on the repair shelf and needs to be tracked as awaiting processing. |
| SCCallException | Class | Service Component call exception — thrown when the CBS call or subsequent processing fails. |
| ServiceComponentRequestInvoker | Class | Framework utility for invoking Service Component (SC) / CBS operations with a request map and session handle. |
| CCRequestBroker | Class | Framework utility that routes CC (Common Component) method calls through the BPM framework, handling class resolution and parameter passing. |
| DKSV0050 | Screen/BPM | Indoor appliance return/exchange processing BPM flow — the screen family that handles HMPIN (home appliance) return and repair workflows. |
| ANK-2119-00-00 | Change Request | Internal change request identifier for the feature that adds HMPIN service order creation (addHmpinSodHakko) to this method. |
| SOD | Acronym | Service Order Data — the entity/record representing a service order in the order fulfillment system. Created by `addHmpinSodHakko`. |
| KNRI | Acronym | Kaitai Nairetsu (撤去・配線) — removal and wiring/installation work for indoor appliances in home networking systems. |
