# Business Logic — JDKCommon48CC.insertOdrHakkoJoken() [26 LOC]

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

## 1. Role

### JDKCommon48CC.insertOdrHakkoJoken()

This method performs **order condition registration** (オーダ発行条件登録処理), a critical step in the telecom service return/reconciliation workflow. When a customer returns a device (home appliance, router, or UQ equipment), the system must register corresponding order conditions — such as contract termination (解約), cancellation (消去), or service-specific events — into the order management database. The method acts as a **delegation bridge**: it populates the order condition data payload by calling `setValueOdrHakkoJoken`, then dispatches the CBS (Common Business Service) `EKK1081D010CBS` via the `ServiceComponentRequestInvoker` to persist the record.

The method implements a **guard-clause pattern**: if the incoming request carries Function Code `2`, processing is skipped entirely (the condition is already registered elsewhere). Otherwise, it builds the CBS input template, executes the registration CBS, and validates the result — throwing an `SCCallException` on failure. This method is called during return-processing flows for three device categories: optical phone VDSL (device type code `50`), BBWare router (device type code `F0`), and UQ (device type code `J0`), each with distinct order types, service order codes, and request type codes.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["insertOdrHakkoJoken called"])

    START --> GET_IN_MAP["Get inMap from param.getData"]

    GET_IN_MAP --> CHECK_FUNC_CODE["Check FUNC_CODE equals 2?"]

    CHECK_FUNC_CODE -->|Yes| EARLY_RETURN["Return - skip processing"]

    CHECK_FUNC_CODE -->|No| SET_VALUES["Call setValueOdrHakkoJoken"]

    SET_VALUES --> BUILD_TEMPLATE["Build EKK1081D010CBSMsg template"]

    BUILD_TEMPLATE --> EDIT_IN_MSG["Call EKK1081D010BSMapper.editInMsg"]

    EDIT_IN_MSG --> DEBUG_LOG["Print debug log"]

    DEBUG_LOG --> RUN_CBS["Call scCall.run with EKK1081D010CBS"]

    RUN_CBS --> EDIT_RESULT["Call EKK1081D010BSMapper.editResultRP"]

    EDIT_RESULT --> CHECK_ERROR["Check JDKBPCommon.hasError"]

    CHECK_ERROR -->|Yes| THROW_ERROR["Throw SCCallException - registration failure"]

    CHECK_ERROR -->|No| NORMAL_RETURN["Return - success"]

    EARLY_RETURN --> END_NODE(["End"])
    NORMAL_RETURN --> END_NODE
    THROW_ERROR --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `kikiInfoMap` | `Map` | Return device information map containing device-specific fields: service contract number (`SVC_KEI_NO`), device provision service contract number (`KKTK_SVC_KEI_NO`), order type code, service order code, request type code, multi-function router broadband contract line detail number (`SVC_KEI_KAISEN_UCWK_NO`), and when applicable, home appliance model code (`TAKNKIKI_MODEL_CD`) and device serial number (`KIKI_SEIZO_NO`). This is the primary data source for the order condition payload. |
| 2 | `orderSbtCd` | `String` | Order type code — classifies the kind of order event being registered. Values vary by device type: `"2"` for optical phone VDSL (光電話VDSL), `"1"` for BBWare router (ルータ), `"3"` for UQ. Determines the business category of the order condition record. |
| 3 | `svcOrderCd` | `String` | Service order code (OLS) — specifies the service order subtype. Values: `"20"` for optical phone VDSL, `"0A"` for BBWare router, `"02"` for UQ. Works in conjunction with `orderSbtCd` and `yokyuSbtCd` to fully specify the registration event. |
| 4 | `yokyuSbtCd` | `String` | Request type code — indicates the nature of the request. Value `"03"` means termination (解約), value `"08"` means cancellation (消去). Together with the other codes, defines whether this registers a new termination/cancellation event. |
| 5 | `sameTrnNo` | `String` | Same transaction number — a unique identifier ensuring all order conditions and order information registrations for a single return operation are correlated. Used for atomicity and audit trail across the entire return workflow. |
| 6 | `handle` | `SessionHandle` | Database session handle for executing the CBS. Provides connection context and transaction scope for the `scCall.run` execution. |
| 7 | `param` | `IRequestParameterReadWrite` | Request/response parameter object. Used to read the `DKSV005005CC` HashMap (home device transfer movement information), pass to `setValueOdrHakkoJoken` for data population, and receive the CBS result via `editResultRP`. After CBS execution, its error state is checked via `JDKBPCommon.hasError`. |
| 8 | `scCall` | `ServiceComponentRequestInvoker` | Service component invocation bridge. Executes the CBS `EKK1081D010CBS` with the built input map. The result is the registered order condition data from the database. |

**No instance fields** are directly read by this method (the method is `private` and does not reference `this.` except for the `setValueOdrHakkoJoken` call, which is an internal delegation).

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `DKSV0050_DKSV0050OP_EKK1081D010BSMapper.editInMsg` | EKK1081D010SC | - | Builds the CBS input message template (`EKK1081D010CBSMsg`) from the populated `inMap` (order condition data) and `param` (function code, template ID, operator ID, operate date). |
| C | `EKK1081D010BSMapper.run (via scCall)` | EKK1081D010CBS | KK_T_ODR_HAKKO_JOKEN | Executes the order condition registration CBS. Inserts a new record into the order condition header table with order type, service order code, request type code, service contract number, device provision number, home appliance model code, device serial number, and other fields. |
| U | `DKSV0050_DKSV0050OP_EKK1081D010BSMapper.editResultRP` | EKK1081D010SC | - | Processes the CBS response. Updates `param` with result data including error codes and return messages. |
| - | `JDKBPCommon.hasError` | - | - | Checks whether the CBS execution resulted in an error condition by inspecting the `returnCode` in `param`'s control map data. |
| - | `JDKCommon48CC.setValueOdrHakkoJoken` | - | - | Populates the order condition data map (SOD work area) by extracting service contract numbers, device info, and provider codes from `kikiInfoMap`, SOD work maps, and `DKSV005005CC`. |
| R | `param.getData` | - | - | Reads the `DKSV005005CC` HashMap containing home device transfer movement information from the request parameter. |

## 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: `hasError` [-], `editResultRP` [U], `run` [-], `editInMsg` [U], `setValueOdrHakkoJoken` [-], `getData` [R]  # NOSONAR

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CC:JDKCommon48CC | `JDKCommon48CC.processReturnSOD` -> `JDKCommon48CC.insertOdrHakkoJoken` | `EKK1081D010CBS [C] KK_T_ODR_HAKKO_JOKEN` |
| 2 | CC:JDKCommon08CC | `JDKCommon08CC.processReturnSOD` -> `JDKCommon08CC.insertOdrHakkoJoken` | `EKK1081D010CBS [C] KK_T_ODR_HAKKO_JOKEN` |

**Note:** Batch jobs in `JBSbatKKDelRun` and `JBSbatKKRsvTokiHak` define separate methods named `insertOdrHakkoJoken` with different signatures (batch-specific, not the CC method documented here).

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(FUNC_CODE equals "2")` (L1155-1158)

> Early-return guard: if the request's function code is "2", skip all registration processing. This prevents duplicate registration when the order condition has already been set up by a preceding step.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inMap = (HashMap) param.getData(DKSV005005CC)` // Retrieve home device transfer movement info map [-> DKSV005005CC="DKSV005005CC"] |
| 2 | CHECK | `if ("2".equals(inMap.get(EKK1081D010CBSMsg.FUNC_CODE)))` // Guard: skip if function code is "2" |
| 3 | RETURN | `return;` // Early return — no processing performed |

**Block 2** — [EXEC] `setValueOdrHakkoJoken(...)` (L1162)

> Populates the order condition data map by extracting service contract numbers, device information, and provider codes. This block delegates to `setValueOdrHakkoJoken` which performs complex data assembly (detailed below).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `this.setValueOdrHakkoJoken(kikiInfoMap, orderSbtCd, svcOrderCd, yokyuSbtCd, sameTrnNo, param)` // Populates SOD work area with order condition data |

**Block 2.1** — [nested within setValueOdrHakkoJoken] SOD data assembly and data population (L786-944)

> Extracts SOD work map, builds `inMap`, and populates all order condition fields based on device type.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sodWorkMap = (HashMap) this.getSodWorkMap(param)` // Get SOD work area |
| 2 | SET | `inMap = new HashMap<String, String>()` // Initialize order condition data map |
| 3 | SET | `ekk0081A010OutMap = (HashMap) sodWorkMap.get(EKK0081A010BSMapper.TEMPLATE_ID)` // Get service contract agreement header data |
| 4 | SET | `ekk0081A010CbsMsg1List = (ArrayList) ekk0081A010OutMap.get(EKK0081A010CBSMsg.EKK0081A010CBSMSG1LIST)` // Extract detail list |
| 5 | IF | `ekk0081A010CbsMsg1List.size() > 0` // If service contract agreement has records |
| 6 | SET | `inMap.put(SVC_KEI_NO, ekk0081A010CbsMsg1List.get(0).get(SVC_KEI_NO))` // Set service contract number |
| 7 | SET | `inMap.put(KKTK_SVC_KEI_NO, kikiInfoMap.get(KKTK_SVC_KEI_NO))` // Set device provision service contract number |
| 8 | SET | `inMap.put(ORDER_SBT_CD, orderSbtCd)` // Set order type code |
| 9 | SET | `inMap.put(SVC_ORDER_CD, svcOrderCd)` // Set service order code (OLS) |
| 10 | SET | `inMap.put(YOKYU_SBT_CD, yokyuSbtCd)` // Set request type code (termination/cancellation) |
| 11 | SET | `inMap.put(ODR_HAKKO_JOKEN_CD, "01")` // Set order condition code: "01" = immediate issuance [-> ODR_HAKKO_JOKEN_CD = "01" (即時発行)] |
| 12 | SET | `inMap.put(SAME_TRN_NO, sameTrnNo)` // Set same transaction number |
| 13 | IF | `dksv00505cc != null && containsKey("taknkiki_model_cd")` // If home appliance model code exists |
| 14 | SET | `inMap.put(TAKNKIKI_MODEL_CD, dksv00505cc.get("taknkiki_model_cd"))` // Set home appliance model code |
| 15 | IF | `dksv00505cc != null && containsKey("kiki_seizo_no")` // If device serial number exists |
| 16 | SET | `inMap.put(KIKI_SEIZO_NO, dksv00505cc.get("kiki_seizo_no"))` // Set device serial number |
| 17 | SET | `ezm0411A010CbsMsg1List = (ArrayList) ezm0411A010OutMap.get(EZM0411A010CBSMsg.EZM0411A010CBSMSG1LIST)` // Get home appliance type detail |
| 18 | SET | `tkniKikiSbtCd = ezm0411A010CbsMsg.get(TAKNKIKI_SBT_CD)` // Get home appliance type code |
| 19 | IF | `TAKNKIKI_SBT_CD_TAKINORT.equals(tkniKikiSbtCd) || TAKNKIKI_SBT_CD_HGW.equals(tkniKikiSbtCd)` // Multi-function router or home gateway |
| 20 | SET | `inMap.put(SVC_KEI_KAISEN_UCWK_NO, kikiInfoMap.get(SVC_KEI_KAISEN_UCWK_NO))` // Set service contract line detail number |
| 21 | IF | `"J0".equals(tkniKikiSbtCd)` // UQ case |
| 22 | SET | `ekk0161B004Map = (HashMap) sodWorkMap.get(EKK0161B004BSMapper.TEMPLATEID)` // Get service contract line detail list |
| 23 | WHILE | `ekk0161B004CbsMsg1List.iterator.hasNext()` // Iterate through service contract line records |
| 24 | SET | `pcrsCd = ekk0161B004CbsMsg.get(PCRS_CD)` // Get provider code |
| 25 | IF | `CD00134_MOB_WIMAX.equals(pcrsCd)` // WiMAX authentication ID |
| 26 | SET | `inMap.put(SVC_KEI_UCWK_NO, ekk0161B004CbsMsg.get(SVC_KEI_UCWK_NO))` // Set service contract line detail number for WiMAX |
| 27 | SET | `inMap.put(TAKNKIKI_MODEL_CD, null)` // Clear home appliance model code for UQ |
| 28 | SET | `inMap.put(KIKI_SEIZO_NO, null)` // Clear device serial number for UQ |
| 29 | SET | `sodWorkMap.put(EKK1081D010BSMapper.TEMPLATEID, inMap)` // Set inMap into SOD work area |

**Block 3** — [EXEC] CBS template construction (L1163)

> Calls `EKK1081D010BSMapper.editInMsg` to build the CBS input message by creating an `EKK1081D010CBSMsg` template and populating it with the order condition data from `DKSV005005CC`, along with the function code, template ID, operator ID, and operate date from the request parameter.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `ekk1081D010Map = EKK1081D010BSMapper.editInMsg(param)` // Build CBS input message template with order condition data |

**Block 4** — [EXEC] CBS execution (L1165)

> Prints a debug log entry, then invokes the CBS `EKK1081D010CBS` via the service component request invoker. The CBS receives the populated template and executes the database insert for the order condition record.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JSYejbLog.println(JSYejbLog.DEBUG, this.getClass(), "オーダ発行条件登録処理の実行")` // Debug log: "Execution of order condition registration processing" [-> DEBUG log level] |
| 2 | CALL | `ekk1081D010Result = scCall.run(ekk1081D010Map, handle)` // Execute CBS to register order condition |

**Block 5** — [EXEC] Result processing (L1166)

> Processes the CBS result back into the parameter object, extracting error codes, messages, and any returned data.

| # | Type | Code |
|---|------|------|
| 1 | SET | `param = EKK1081D010BSMapper.editResultRP(ekk1081D010Result, param)` // Update param with CBS result |

**Block 6** — [IF-ELSE] `(JDKBPCommon.hasError(param))` (L1167-1172)

> Error handling: if the CBS execution resulted in an error (indicated by a non-zero `returnCode` in the control map), throw an `SCCallException` with a Japanese error message and the return code. Otherwise, return normally.

| # | Type | Code |
|---|------|------|
| 1 | CHECK | `if (JDKBPCommon.hasError(param))` // Check if CBS returned an error |
| 2 | THROW | `throw new SCCallException("オーダ発行条件登録処理失敗", "0", Integer.parseInt(param.getControlMapData("returnCode").toString()))` // Error: "Order condition registration processing failed" [-> SCCallException with returnCode from param] |
| 3 | RETURN | *(implicit)* // Fall through — normal return on success |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `odrHakkoJoken` | Field/Acronym | Order Issuance Condition — the set of criteria that determine whether and how an order should be issued. In this context, it refers to the registration of termination/cancellation order conditions in the system. |
| `kikiInfoMap` | Field | Return Device Information Map — carries information about the device being returned, including service contract numbers, device provision codes, and home appliance details. |
| `orderSbtCd` | Field | Order Type Code — classifies the order event: "1" for BBWare router, "2" for optical phone VDSL, "3" for UQ. |
| `svcOrderCd` | Field | Service Order Code (OLS) — specifies the service order subtype: "20" for optical phone VDSL, "0A" for BBWare router, "02" for UQ. |
| `yokyuSbtCd` | Field | Request Type Code — indicates the request nature: "03" means termination (解約), "08" means cancellation (消去). |
| `sameTrnNo` | Field | Same Transaction Number — a unique correlation ID ensuring all order conditions for a single return operation are grouped together. |
| `SVC_KEI_NO` | Field | Service Contract Number — the primary identifier for a customer's service contract line item. |
| `KKTK_SVC_KEI_NO` | Field | Device Provision Service Contract Number — links the returned device to its service contract line. |
| `SVC_KEI_KAISEN_UCWK_NO` | Field | Service Contract Line Detail Number (Multi-function Router) — internal tracking ID for multi-function router service contract details. |
| `SVC_KEI_UCWK_NO` | Field | Service Contract Line Detail Number — sub-line item identifier within a service contract, used for UQ/WiMAX cases. |
| `TAKNKIKI_MODEL_CD` | Field | Home Appliance Model Code — the model identifier for a home appliance being returned. |
| `KIKI_SEIZO_NO` | Field | Device Serial Number — unique serial number of the returned hardware device. |
| `ODR_HAKKO_JOKEN_CD` | Field | Order Issuance Condition Code — "01" means immediate issuance (即時発行), indicating the order condition takes effect immediately. |
| `FUNC_CODE` | Field | Function Code — identifies the processing function; "2" indicates the condition was already registered, triggering a skip. |
| `DKSV005005CC` | Constant | Home Device Transfer Movement Information — a HashMap stored in the request parameter carrying home device transfer/inter-device movement data including model codes and serial numbers. |
| `EKK1081D010CBS` | CBS | Order Condition Registration CBS — the Common Business Service that performs the database insert for order condition records into `KK_T_ODR_HAKKO_JOKEN`. |
| `KK_T_ODR_HAKKO_JOKEN` | Table | Order Condition Header Table — database table storing order condition records including order type, service order code, request type code, service contract numbers, and device information. |
| VDSL | Business term | Virtual Multiplex Digital Subscriber Line — broadband internet access technology used by NTT for optical phone VDSL services. |
| BBWare | Business term | BBWare — NTT's broadband router service brand. In this system, refers to router-based service contracts. |
| UQ | Business term | UQ Communications — a mobile broadband (WiMAX) service provider. Device type code "J0" indicates UQ-related processing. |
| 光電話 (Koutenwa) | Business term | Optical Phone — NTT's fiber-optic telephone service. Device type code "50" refers to optical phone VDSL returns. |
| 解約 (Kaiyaku) | Business term | Termination — cancellation of an existing service contract. Request type code "03". |
| 消去 (Shoushi) | Business term | Cancellation — removal of a previously registered order condition. Request type code "08". |
| ルータ (Ruuta) | Business term | Router — network routing device. Device type code "F0". |
| ホームゲートウェイ (Home Gateway) | Business term | A combined router and modem device for home broadband connectivity. Treated as a multi-function router variant. |
| SOD | Acronym | Service Order Data — the work area containing data related to service order processing, including contract information, device details, and order conditions. |
| SOD work area | Technical term | A `HashMap<String, Object>` stored in the request parameter that holds all service order data for the current operation, including templates and extracted records. |
| SC | Acronym | Service Component — a modular business logic unit invoked via the service component request invoker pattern. |
| CBS | Acronym | Common Business Service — a reusable business logic component invoked via the SC framework. Typically performs CRUD operations on database tables. |
| OLS | Acronym | Service Order System — NTT's order management system for telecom services. |
| `CD00134_MOB_WIMAX` | Constant | WiMAX authentication ID provider code — identifies WiMAX service in the provider code system. |
| `TAKNKIKI_SBT_CD_TAKINORT` | Constant | Multi-function router type code constant — indicates a multi-function router device type. |
| `TAKNKIKI_SBT_CD_HGW` | Constant | Home gateway type code constant — indicates a home gateway device type. |
| SCCallException | Exception | Custom exception thrown when a service component call fails, containing an error message, error type ("0"), and return code. |
