# Business Logic — JBSbatKKSkaLckDteEdit.execSvc() [111 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKSkaLckDteEdit` |
| Layer | Service (Batch Service Component) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKSkaLckDteEdit.execSvc()

This method performs **Spare Key Information Operation** — a batch service that forwards reserved move data to the Spare Key Information Operation Component (`KKSV1052`) for processing. The Spare Key mechanism is used in K-Opticom's telecom fulfillment system to manage provisional contract reservations tied to fiber-optic or other service installations, where a "Spare Key" tracks the contractual line item while the actual service provisioning is being prepared.

The method acts as a **delegation/dispatcher** pattern: it extracts reservation fields from the input `idoDivDataMap`, constructs a structured request payload (`KKSV1052DataMap`), determines whether the reservation applies in the current operational period or the next month based on a date comparison, and then invokes the external Spare Key service via `JCCBatchEsbInterface.invokeService`.

The method handles three conditional branches for the spare application standard date determination: if the reservation application date (`rsvAplyYmd`) is on or before the current operational date (`opeDate`), it is classified as **JST (current day)** with value `"1"`; otherwise, it is classified as **NXTM (next month)** with value `"2"`.

It implements robust error handling with two distinct error paths: (1) business-level errors from the invoked service, captured via `returnCode` and `errCd`, which are logged with `EKKB0010CW` and raise `JBSbatBusinessError` if the service return code is not success; and (2) infrastructure-level exceptions caught in a try-catch block, logged with `EKKB1010CW`. In either error case, the method sets the error flag on `commonItem` and returns `false`. On success, it returns `true`.

This method is the core batch processing engine called from `execute()` and serves as the bridge between the internal batch job and the external Spare Key Information Operation CBS (Common Business Service).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execSvc funcCd, shoriCd, idoDivDataMap"])

    START --> R1["Extract fields from idoDivDataMap"]

    R1 --> INIT["Initialize maps
paramMap inputMap outputMap"]

    INIT --> PUT1["KKSV1052DataMap.put
func_cd shori_cd svc_kei_no
old_pcrs new_pcrs"]

    PUT1 --> OPE["Get opeDate from commonItem"]

    OPE --> COND{"rsvAplyYmd <= opeDate?"}

    COND -->|"Yes"| JST["sptv_aply_stdardymd_div = 1
JST"]

    COND -->|"No"| NXT["sptv_aply_stdardymd_div = 2
NXTM"]

    JST --> INPUT["inputMap.put
SPTVKEYINFOOPERATECC"]

    NXT --> INPUT

    INPUT --> INVOKE["JCCBatchEsbInterface.invokeService
commonItem paramMap inputMap outputMap"]

    INVOKE --> RETCODE["getReturnCode outputMap"]

    RETCODE --> RETCOND{"returnCode equals SUCCESS?"}

    RETCOND -->|"No"| THROW["throw new JBSbatBusinessError"]

    RETCOND -->|"Yes"| EXTRACT["Extract resultMap from outputMap
errCd from resultMap"]

    EXTRACT --> ERRCOND{"errCd is null or blank?"}

    ERRCOND -->|"No"| LOGERR["Log error EKKB0010CW
setErrFlg true
return false"]

    ERRCOND -->|"Yes"| EXIT["return true"]

    THROW --> CATCH["catch Exception ex"]

    CATCH --> LOGEX["Log error EKKB1010CW
setErrFlg true
return false"]

    LOGERR --> END(["Return / Next"])
    EXIT --> END
    LOGEX --> END
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `funcCd` | `String` | Function code — indicates the operation mode for the Spare Key edit batch. Possible values: `"1"` (update, `FUNC_CD_UPD`), `"2"` (check only, `FUNC_CD_CHK`). Determines whether the Spare Key service should perform actual modifications or a validation-only check. |
| 2 | `shoriCd` | `String` | Process code — specifies the type of service change being processed. Possible value: `"2"` (corresponds to `SHORI_CD_CRS_CHG`, i.e., "Change" — service contract line item rate change). |
| 3 | `idoDivDataMap` | `JBSbatCommonDBInterface` | Move reservation data interface — a map-like object carrying the core reservation fields extracted from the move reservation table (`KK_T_IDO_RSV`). Contains the reservation number, move classification, reservation detail code, service contract number, old/new PCRS codes, and reservation application date. |

**Instance fields / external state read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `commonItem` | `JBSbatCommonItem` | Common operational item carrying system-wide settings including the operational date (`getOpeDate()`) and error flag (`setErrFlg(true)`). |
| `logPrint` | `JKKBatOneTimeLogWriter` | Business error logger used to write error messages to the batch log with message code `EKKB0010CW` or `EKKB1010CW`. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCBatchEsbInterface.getOpeDate` | - | - | Calls `getOpeDate` on `commonItem` to retrieve the current operational date for comparison against `rsvAplyYmd` |
| C | `JCCBatchEsbInterface.invokeService` | - | KK_T_IDO_RSV | Invokes the Spare Key Information Operation CBS (`KKSV1052`) with the constructed payload. This service processes the move reservation data and updates the Spare Key information in the reservation table. |
| R | `JCCBatchEsbInterface.getReturnCode` | - | - | Retrieves the return code from the service output map to determine success or failure of the invoked CBS. |
| - | `JCCBatchEsbInterface.setErrFlg` | - | - | Sets the error flag on `commonItem` to `true` when an error is encountered. |
| - | `JKKStringUtil.isNullBlank` | - | - | Utility call to check if the error code (`errCd`) is null or blank. |
| - | `JKKBatOneTimeLogWriter.printBusinessErrorLog` | - | - | Writes business error log entries using message codes `EKKB0010CW` (service error) and `EKKB1010CW` (exception/error). |
| - | `JBSbatBusinessError` | - | - | Thrown as a business-level exception when the service return code is not success. |

## 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: `setErrFlg` [-], `setErrFlg` [-], `printBusinessErrorLog` [-], `printBusinessErrorLog` [-], `isNullBlank` [-], `getReturnCode` [R], `invokeService` [C], `getOpeDate` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKSkaLckDteEdit.execute()` | `JBSbatKKSkaLckDteEdit.execute()` -> `JBSbatKKSkaLckDteEdit.execSvc(funcCd, shoriCd, idoDivDataMap)` | `invokeService [C] KK_T_IDO_RSV`, `setErrFlg [-]`, `printBusinessErrorLog [-]`, `getReturnCode [R]`, `isNullBlank [-]`, `getOpeDate [R]` |

## 6. Per-Branch Detail Blocks

**Block 1** — [EXTRACTION] (L131)

> Extract key reservation fields from the `idoDivDataMap` interface. These fields represent the core move reservation data stored in the `KK_T_IDO_RSV` table.

| # | Type | Code |
|---|------|------|
| 1 | SET | `idoRsvNo = idoDivDataMap.getString(IDO_RSV_NO)` // Move reservation number (異動予約番号) |
| 2 | SET | `idoDiv = idoDivDataMap.getString(IDO_DIV)` // Move classification (異動区分) |
| 3 | SET | `idoRsvDtlCd = idoDivDataMap.getString(IDO_RSV_DTL_CD)` // Move reservation detail code (異動予約詳細コード) |
| 4 | SET | `svcKeiNo = idoDivDataMap.getString(SVC_KEI_NO)` // Service contract number (サービス契約番号) |
| 5 | SET | `oldPcrs = idoDivDataMap.getString(OLD_PCRS_CD)` // Old PCRS code (旧料金コード) |
| 6 | SET | `newPcrs = idoDivDataMap.getString(NEW_PCRS_CD)` // New PCRS code (新料金コード) |
| 7 | SET | `rsvAplyYmd = idoDivDataMap.getString(RSV_APLY_YMD)` // Reservation application date (予約適用年月日) |

**Block 2** — [INITIALIZATION] (L139)

> Initialize HashMap structures for the batch processing pipeline. `paramMap` carries Telegram routing metadata. `inputMap` holds the service input payload. `KKSV1052DataMap` is the nested payload for the Spare Key operation.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap = new HashMap<Object, Object>()` // Telegram routing parameters |
| 2 | EXEC | `paramMap.put(TELEGRAM_INFO_USECASE_ID, "KKSV1052")` // Set use case ID for tracking |
| 3 | EXEC | `paramMap.put(TELEGRAM_INFO_OPERATION_ID, "KKSV1052OP")` // Set operation ID |
| 4 | SET | `inputMap = new HashMap<String, Object>()` // Service input map |
| 5 | SET | `KKSV1052DataMap = new HashMap<String, Object>()` // Service payload map |

**Block 3** — [PAYLOAD BUILDING] (L148)

> Populate the service payload map with function code, process code, service contract number, old/new PCRS codes, and determine the spare application standard date based on the date comparison in Block 4.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `KKSV1052DataMap.put("func_cd", funcCd)` // Function code |
| 2 | EXEC | `KKSV1052DataMap.put("shori_cd", shoriCd)` // Process code |
| 3 | EXEC | `KKSV1052DataMap.put("svc_kei_no", svcKeiNo)` // Service contract number |
| 4 | EXEC | `KKSV1052DataMap.put("old_pcrs", oldPcrs)` // Old PCRS code |
| 5 | EXEC | `KKSV1052DataMap.put("new_pcrs", newPcrs)` // New PCRS code |
| 6 | SET | `opeDate = commonItem.getOpeDate()` // Current operational date |

**Block 4** — [IF] `(rsvAplyYmd.compareTo(opeDate) <= 0)` [SPTV_APLY_STDARDYMD_DIV_JST="1"] (L162)

> If the reservation application date is on or before the current operational date, classify the spare application standard as **JST (current day / 即時)**. This means the reservation takes effect in the current operational period.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `KKSV1052DataMap.put("sptv_aply_stdardymd_div", SPTV_APLY_STDARDYMD_DIV_JST)` // = "1" — current day (即時) |

**Block 5** — [ELSE] (L166)

> If the reservation application date is after the operational date, classify the spare application standard as **NXTM (next month / 翌月)**. The reservation will take effect starting the next month.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `KKSV1052DataMap.put("sptv_aply_stdardymd_div", SPTV_APLY_STDARDYMD_DIV_NXTM)` // = "2" — next month (翌月) |

**Block 6** — [PAYLOAD REGISTRATION] (L178)

> Register the completed payload map under the service key in the input map, making it available to the invoked CBS.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `inputMap.put(SPTVKEYINFOOPERATECC, KKSV1052DataMap)` // SPTVKEYINFOOPERATECC = "SPTVKEYINFOOPERATECC" |
| 2 | SET | `outputMap = new HashMap<Object, Object>()` // Service output map |

**Block 7** — [TRY] (L183)

> Enter the protected block for the service invocation. This block handles both business-level errors (non-success return codes) and infrastructure-level exceptions.

**Block 7.1** — [CALL] `invokeService` (L186)

> Invoke the Spare Key Information Operation CBS (`KKSV1052`) via the ESB interface. Passes the common item, parameter map, input map, and output map.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JCCBatchEsbInterface.invokeService(super.commonItem, paramMap, inputMap, outputMap)` // Invoke Spare Key CBS |

**Block 7.2** — [RETRIEVE RETURN CODE] (L188)

> Get the return code from the service output map to verify the CBS execution result.

| # | Type | Code |
|---|------|------|
| 1 | SET | `returnCode = JCCBatchEsbInterface.getReturnCode(outputMap)` // Service return code |

**Block 7.3** — [IF] `(returnCode != SUCCESS)` (L190)

> If the service returned a non-success code, throw a business-level error that will be caught by the exception handler.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `throw new JBSbatBusinessError()` // Business error — caught by catch block below |

**Block 7.4** — [EXTRACT ERROR CODE] (L193)

> After a successful return code, extract the detailed error code from the result map if present. This allows the service to report specific errors even when the overall return code indicates success.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultMap = null` |
| 2 | SET | `errCd = ""` |
| 3 | IF | `outputMap.containsKey(SPTVKEYINFOOPERATECC)` // Check if output contains result map |

**Block 7.4.1** — [IF] `(resultMap != null)` (L197)

> Retrieve the error code from the result map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errCd = (String) resultMap.get("err_cd")` // Error code from service response |

**Block 7.5** — [IF] `(!JKKStringUtil.isNullBlank(errCd))` (L201)

> If an error code was returned by the service, log the error with full context (service contract number, move reservation number, move classification, move reservation detail code, and error code), set the error flag, and return `false`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sb = new StringBuilder()` // Build error message |
| 2 | EXEC | `sb.append("登録状態エラー")` // "Registration state error" |
| 3 | EXEC | `sb.append("(サービス契約番号:")` // Append service contract number context |
| 4 | EXEC | `sb.append(svcKeiNo)` |
| 5 | EXEC | `sb.append("/異動予約番号:")` // Append move reservation number |
| 6 | EXEC | `sb.append(idoRsvNo)` |
| 7 | EXEC | `sb.append("/異動区分:")` // Append move classification |
| 8 | EXEC | `sb.append(idoDiv)` |
| 9 | EXEC | `sb.append("/異動予約詳細コード:")` // Append move reservation detail code |
| 10 | EXEC | `sb.append("/エラーコード:")` // Append error code |
| 11 | EXEC | `sb.append(errCd)` |
| 12 | CALL | `super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0010CW, new String[]{sb.toString()})` // Log business error |
| 13 | EXEC | `super.commonItem.setErrFlg(true)` |
| 14 | RETURN | `return false` |

**Block 8** — [CATCH Exception ex] (L213)

> Catch any unexpected exceptions during the service invocation (e.g., communication failures, serialization errors, timeouts). Log the exception with the service contract number and return `false`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB1010CW, new String[]{"スパキー鍵情報操作 サービス契約番号：" + svcKeiNo})` // Log infrastructure error — "Spare key info operation" |
| 2 | EXEC | `super.commonItem.setErrFlg(true)` |
| 3 | RETURN | `return false` |

**Block 9** — [SUCCESS RETURN] (L222)

> The service completed successfully with no errors. Return `true` to indicate normal completion.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `idoRsvNo` | Field | Move reservation number (異動予約番号) — unique identifier for a service move/provisional reservation record in the `KK_T_IDO_RSV` table. |
| `idoDiv` | Field | Move classification (異動区分) — type/category of the move operation (e.g., new connection, transfer, cancellation). |
| `idoRsvDtlCd` | Field | Move reservation detail code (異動予約詳細コード) — specific sub-type of the move operation. |
| `svcKeiNo` | Field | Service contract number (サービス契約番号) — unique identifier for a customer's service contract line item. |
| `oldPcrs` | Field | Old PCRS code (旧料金コード) — the previous pricing rate plan code before the change. |
| `newPcrs` | Field | New PCRS code (新料金コード) — the new pricing rate plan code after the change. |
| `rsvAplyYmd` | Field | Reservation application date (予約適用年月日) — the date from which the reservation becomes effective (YYYYMMDD format). |
| `opeDate` | Field | Operational date (運用日付) — the current batch processing date obtained from the common item settings. |
| `sptv_aply_stdardymd_div` | Field | Spare application standard date classification — determines whether the reservation applies in the current period (`"1"` / JST = 即時 = current day) or the next month (`"2"` / NXTM = 翌月 = next month). |
| Spare Key | Business term | A provisional contractual key used in K-Opticom's telecom fulfillment to track service reservation line items while actual provisioning is being prepared. Enables deferred service activation. |
| PCRS | Acronym | Pricing Rate Plan System — the customer's telephone rate plan (pricing tier/plan). |
| KKSV1052 | Process ID | Spare Key Information Operation CBS — the service component responsible for processing Spare Key information updates, invoked via `JCCBatchEsbInterface.invokeService`. |
| SPTVKEYINFOOPERATECC | Constant | Spare Key Information Operation CC key — the map key (`"SPTVKEYINFOOPERATECC"`) used to identify the Spare Key service input/output payload within the ESB communication. |
| SPTV_APLY_STDARDYMD_DIV_JST | Constant | Spare application standard date classification — current day ("1"), meaning the reservation application date is on or before the operational date. |
| SPTV_APLY_STDARDYMD_DIV_NXTM | Constant | Spare application standard date classification — next month ("2"), meaning the reservation application date is after the operational date. |
| FUNC_CD_UPD | Constant | Function code "1" — Update mode (機能コード：更新). The service performs actual modifications. |
| FUNC_CD_CHK | Constant | Function code "2" — Check mode (機能コード：チェックのみ). The service performs validation-only. |
| SHORI_CD_CRS_CHG | Constant | Process code "2" — Change (処理コード：変更). Service contract line item rate change operation. |
| EKKB0010CW | Message Code | Business error log message — "Registration state error" logged when the Spare Key CBS returns a non-zero error code. |
| EKKB1010CW | Message Code | Infrastructure error log message — logged when an unexpected exception occurs during the Spare Key information operation. |
| JCCBatchEsbInterface | Class | ESB (Enterprise Service Bus) interface for batch service invocation — provides `invokeService()`, `getReturnCode()`, and telegram info constants. |
| KK_T_IDO_RSV | DB Table | Move reservation table (異動予約テーブル) — database table storing service move reservation data. |
| KK_SELECT_114 | SQL Key | SQL definition key for accessing the move reservation table. |
