# Business Logic — JBSbatKKSkaWrkCnclProc.execSvc() [99 LOC]

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

## 1. Role

### JBSbatKKSkaWrkCnclProc.execSvc()

This method serves as the **service invocation bridge** for port number change cancellation (KKS — *Koshiki Denwa* / Landline) work cancellation processing within the batch job system. It encapsulates the end-to-end execution of the **SPTVKEYINFOOPERATECC** service (Special Service / Telephony Key Information Operation), which is responsible for registering and updating optional service contract details in the core CAS (Customer Account System).

The method implements a **delegation + retry-guard pattern**. It constructs a tightly scoped input payload (`KKSV1053DataMap`), swaps the old and new PCRS (Portability / PC — *Phone Number Retention System*) codes before dispatch, invokes the external service via `JCCBatchEsbInterface.invokeService`, and then inspects the structured output for business-level error codes. The caller (`execute()`) orchestrates two phases: a **check-first** phase (using `FUNC_CD_CHK = "2"`) to validate CAS data integrity, followed by an **update** phase (using `FUNC_CD_UPD = "1"`) that only executes if the check succeeds.

Its role in the larger system is that of a **shared internal gateway** — it is called exclusively by `JBSbatKKSkaWrkCnclProc.execute()` but parameterized by `funcCd` and `shoriCd` so the same invocation logic can serve both validation and registration flows without duplicating the service dispatch, error handling, and logging code.

## 2. Processing Pattern (Detailed Business Logic)

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

    START --> EXTRACT["Extract fields from<br/>idoDivDataMap<br/>idoRsvNo, idoDiv,<br/>idoRsvDtlCd, svcKeiNo,<br/>oldPcrs, newPcrs"]

    EXTRACT --> BUILD_PARAM["Build paramMap<br/>TELEGRAM_INFO_USECASE_ID = KKSV1053<br/>TELEGRAM_INFO_OPERATION_ID = KKSV1053OP"]

    BUILD_PARAM --> BUILD_INPUT["Build KKSV1053DataMap<br/>func_cd, shori_cd,<br/>svc_kei_no,<br/>old_pcrs = newPcrs (swapped)<br/>new_pcrs = oldPcrs (swapped)"]

    BUILD_INPUT --> PUT_INPUT["Put KKSV1053DataMap into<br/>inputMap keyed by SPTVKEYINFOOPERATECC"]

    PUT_INPUT --> INVOKE["JCCBatchEsbInterface.invokeService<br/>commonItem, paramMap, inputMap, outputMap"]

    INVOKE --> GET_RC["JCCBatchEsbInterface.getReturnCode(outputMap)"]

    GET_RC --> CHECK_RC{"returnCode equals<br/>RETURN_CODE_SUCCESS?"}

    CHECK_RC -->|No| THROW_BUSINESS["throw JBSbatBusinessError"]

    CHECK_RC -->|Yes| CHECK_KEY{"outputMap contains<br/>SPTVKEYINFOOPERATECC?"}

    THROW_BUSINESS --> CATCH["Catch Exception<br/>Log EKKB1010CW<br/>setErrFlg = true<br/>return false"]

    CHECK_KEY -->|Yes| GET_RESULT["resultMap = outputMap.get(SPTVKEYINFOOPERATECC)"]

    GET_RESULT --> CHECK_RM{"resultMap != null?"}

    CHECK_RM -->|Yes| GET_ERR_CD["errCd = resultMap.get(err_cd)"]

    CHECK_RM -->|No| CHECK_ERR

    GET_ERR_CD --> CHECK_ERR{"errCd is not<br/>null or blank?"}

    CHECK_ERR -->|Yes| LOG_ERR["Build error detail string<br/>Log EKKB0010CW<br/>setErrFlg = true<br/>return false"]

    CHECK_ERR -->|No| RETURN_TRUE["return true"]

    LOG_ERR --> RETURN_TRUE
```

**Constant Resolution Reference:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `FUNC_CD_UPD` | `"1"` | Function code for **update** (register/modify) |
| `FUNC_CD_CHK` | `"2"` | Function code for **check only** (validation, no write) |
| `SHORI_CD_CRS_CHG_CL` | `"3"` | Process code for **port number change cancellation** |
| `SPTVKEYINFOOPERATECC` | `"SPTVKEYINFOOPERATECC"` | Service key for **Special Service / Telephony Key Information Operation** — the CBS service that manages optional service contracts |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `funcCd` | `String` | **Function code** that determines whether the invoked service performs a validation check (`"2"` — check-only) or a data update (`"1"` — register/modify). Controls the write/read semantics of the CAS operation. |
| 2 | `shoriCd` | `String` | **Process code** that identifies the specific business operation. For this class, always `"3"` (port number change cancellation — *Koushin Henshu Torikeshi*). Passed through to the invoked service so it can route to the correct internal handler. |
| 3 | `idoDivDataMap` | `JBSbatCommonDBInterface` | **Migration reservation data map** containing all context fields extracted from the `KK_T_IDO_RSV` (Migration Reservation) database table: migration reservation number, migration classification, reservation detail code, service contract number, and the old/new PCRS (portability) codes. This is the single source of truth for the batch record being processed. |

**External state / instance fields read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `super.commonItem` | `JBSbatCommonItem` | Batch common item carrying shared runtime context (session, tenant, error flag, system ID). Required as the first argument to `invokeService`. |
| `super.logPrint` | `JPCBatchLogPrint` | Business error log writer. Used to emit `EKKB0010CW` (application error with detail context) and `EKKB1010CW` (service-level infrastructure exception). |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JCCBatchEsbInterface.invokeService` | (ESB Bridge) | — | Invokes the **SPTVKEYINFOOPERATECC** CBS service, which internally performs R/U/D operations on CAS data for optional service contract management. |
| R | `JCCBatchEsbInterface.getReturnCode` | — | — | Extracts the return code from the service output map to determine success or failure. |
| R | `idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.IDO_RSV_NO)` | — | `KK_T_IDO_RSV` | Reads the **migration reservation number** — the unique identifier for the migration reservation record. |
| R | `idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.IDO_DIV)` | — | `KK_T_IDO_RSV` | Reads the **migration classification** — indicates the type of migration (e.g., new, change, cancellation). |
| R | `idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.IDO_RSV_DTL_CD)` | — | `KK_T_IDO_RSV` | Reads the **migration reservation detail code** — provides granular classification of the reservation action. |
| R | `idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.SVC_KEI_NO)` | — | `KK_T_IDO_RSV` | Reads the **service contract number** — the key linking to the customer's service contract record. |
| R | `idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.OLD_PCRS_CD)` | — | `KK_T_IDO_RSV` | Reads the **old PCRS code** — the portability reference code before the change/cancellation. |
| R | `idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.NEW_PCRS_CD)` | — | `KK_T_IDO_RSV` | Reads the **new PCRS code** — the portability reference code after the change/cancellation. |
| - | `JCCBatchEsbInterface.getReturnCode` | — | — | Retrieves the standardized return code from the service output to check for success (`RETURN_CODE_SUCCESS`). |
| - | `JKKStringUtil.isNullBlank` | — | — | Utility check to determine whether `errCd` contains meaningful data (null, blank, or whitespace-only). |
| - | `JPCBatchLogPrint.printBusinessErrorLog` | — | — | Writes a business-level error log entry with message key `EKKB0010CW` (registration status error with detail context) or `EKKB1010CW` (service invocation exception). |
| - | `JBSbatCommonItem.setErrFlg` | — | — | Sets the batch-level error flag to `true`, signaling downstream processing that this record has failed. |

**Invocation flow summary:** The method performs **6 Read operations** from the `KK_T_IDO_RSV` table (all via `idoDivDataMap.getString`) and delegates all Create/Update/Delete work to the external **SPTVKEYINFOOPERATECC** CBS service, which manages the CAS optional service contract tables on behalf of the batch. The method itself acts as a pure orchestration wrapper with no direct DB persistence.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKSkaWrkCnclProc.execute()` | `execute()` -> `execSvc(FUNC_CD_CHK, SHORI_CD_CRS_CHG_CL, idoDivDataMap_115)` -> `execSvc(FUNC_CD_UPD, SHORI_CD_CRS_CHG_CL, idoDivDataMap_115)` | `invokeService -> SPTVKEYINFOOPERATECC CBS [R/U] KK_T_IDO_RSV, KK_T_OP_SVC_KEI` |

**Call chain detail:**

The `execute()` method (the primary entry point of `JBSbatKKSkaWrkCnclProc`) performs the following sequence:

1. Queries `KK_T_IDO_RSV` by reservation number to retrieve the migration reservation record.
2. Calls `execSvc(FUNC_CD_CHK = "2", SHORI_CD_CRS_CHG_CL = "3", ...)` — **check phase**: validates CAS data integrity without writing.
3. If the check succeeds, calls `execSvc(FUNC_CD_UPD = "1", SHORI_CD_CRS_CHG_CL = "3", ...)` — **update phase**: registers/modifies CAS optional service contract data.
4. If the update succeeds, proceeds to query CAS card management data (`KK_T_CASCD_KNRI`, `KK_T_OP_SVC_KEI`) and update optional service contract records.

**Terminal operations from this method:**

| # | Terminal Operation | Type | Entity / Target |
|---|-------------------|------|-----------------|
| 1 | `setErrFlg(true)` | Update | `JBSbatCommonItem` (batch error flag) |
| 2 | `printBusinessErrorLog(EKKB0010CW)` | Log | Business error log — registration status error with detail string |
| 3 | `printBusinessErrorLog(EKKB1010CW)` | Log | Business error log — service invocation exception |
| 4 | `JCCBatchEsbInterface.invokeService` | Invoke | `SPTVKEYINFOOPERATECC` CBS (optional service contract management) |
| 5 | `JCCBatchEsbInterface.getReturnCode` | Read | Service return code from output map |

## 6. Per-Branch Detail Blocks

**Block 1** — [EXTRACT] `(All fields from idoDivDataMap)` (L233)

> Extracts six fields from the migration reservation data map. All keys are defined in `JBSbatKK_T_IDO_RSV`.

| # | Type | Code |
|---|------|------|
| 1 | GET | `idoRsvNo = idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.IDO_RSV_NO)` // Migration reservation number [-> "IDO_RSV_NO"] |
| 2 | GET | `idoDiv = idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.IDO_DIV)` // Migration classification [-> "IDO_DIV"] |
| 3 | GET | `idoRsvDtlCd = idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.IDO_RSV_DTL_CD)` // Migration reservation detail code [-> "IDO_RSV_DTL_CD"] |
| 4 | GET | `svcKeiNo = idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.SVC_KEI_NO)` // Service contract number [-> "SVC_KEI_NO"] |
| 5 | GET | `oldPcrs = idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.OLD_PCRS_CD)` // Old PCRS code [-> "OLD_PCRS_CD"] |
| 6 | GET | `newPcrs = idoDivDataMap.getString(JBSbatKK_T_IDO_RSV.NEW_PCRS_CD)` // New PCRS code [-> "NEW_PCRS_CD"] |

**Block 2** — [BUILD] `(paramMap construction)` (L242)

> Builds the telegram info parameter map with hardcoded use-case and operation identifiers for the KKSV1053 batch job.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramMap = new HashMap<Object, Object>()` // Empty parameter map |
| 2 | SET | `paramMap.put(JCCBatchEsbInterface.TELEGRAM_INFO_USECASE_ID, "KKSV1053")` // Use case ID for batch [-> "KKSV1053"] |
| 3 | SET | `paramMap.put(JCCBatchEsbInterface.TELEGRAM_INFO_OPERATION_ID, "KKSV1053OP")` // Operation ID [-> "KKSV1053OP"] |

**Block 3** — [BUILD] `(inputMap and KKSV1053DataMap construction)` (L247)

> Constructs the business data payload. **Critical:** old and new PCRS codes are **swapped** (`old_pcrs` receives `newPcrs`, and `new_pcrs` receives `oldPcrs`). This reversal is intentional — the CAS service expects the "from" code at the `old_pcrs` key and the "to" code at the `new_pcrs` key, but the batch data map already has them in post-change order.

| # | Type | Code |
|---|------|------|
| 1 | SET | `inputMap = new HashMap<String, Object>()` // Empty input map for service dispatch |
| 2 | SET | `KKSV1053DataMap = new HashMap<String, Object>()` // Payload for SPTVKEYINFOOPERATECC |
| 3 | SET | `KKSV1053DataMap.put("func_cd", funcCd)` // Pass through function code from caller |
| 4 | SET | `KKSV1053DataMap.put("shori_cd", shoriCd)` // Pass through process code from caller |
| 5 | SET | `KKSV1053DataMap.put("svc_kei_no", svcKeiNo)` // Service contract number |
| 6 | SET | `KKSV1053DataMap.put("old_pcrs", newPcrs)` // Swapped: new goes to old field [-> "old_pcrs"] |
| 7 | SET | `KKSV1053DataMap.put("new_pcrs", oldPcrs)` // Swapped: old goes to new field [-> "new_pcrs"] |
| 8 | SET | `inputMap.put(SPTVKEYINFOOPERATECC, KKSV1053DataMap)` // Key = "SPTVKEYINFOOPERATECC" |

**Block 4** — [INVOKE] `(try block: service invocation)` (L297)

> Invokes the SPTVKEYINFOOPERATECC CBS service and validates the return code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outputMap = new HashMap<Object, Object>()` // Empty output map to receive service response |
| 2 | CALL | `JCCBatchEsbInterface.invokeService(super.commonItem, paramMap, inputMap, outputMap)` // CBS invocation |
| 3 | CALL | `returnCode = JCCBatchEsbInterface.getReturnCode(outputMap)` // Extract return code [-> R] |

**Block 4.1** — [IF] `(returnCode != RETURN_CODE_SUCCESS)` (L303)

> If the CBS service did not return a success code, throw a business error.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `throw new JBSbatBusinessError()` // Non-success return code triggers business exception |

**Block 4.2** — [POST-CHECK] `(result extraction after successful invoke)` (L307)

> After a successful invoke, extract the error code from the output map if present.

| # | Type | Code |
|---|------|------|
| 1 | SET | `resultMap = null` // Initialize result reference |
| 2 | SET | `errCd = ""` // Initialize error code string |

**Block 4.2.1** — [IF] `(outputMap.containsKey(SPTVKEYINFOOPERATECC))` (L310)

> Check if the service returned data under the expected key.

| # | Type | Code |
|---|------|------|
| 1 | GET | `resultMap = (HashMap)outputMap.get(SPTVKEYINFOOPERATECC)` // Cast to HashMap |

**Block 4.2.2** — [IF] `(resultMap != null)` (L314)

> Extract the business error code from the result map if it exists.

| # | Type | Code |
|---|------|------|
| 1 | GET | `errCd = (String) resultMap.get("err_cd")` // Business-level error code from CAS |

**Block 4.3** — [IF] `(!JKKStringUtil.isNullBlank(errCd))` (L319)

> If a business error code was returned from CAS, log the error with full context and abort.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sb = new StringBuilder()` // Build detail string |
| 2 | EXEC | `sb.append("登録状態エラー (svc_kei_no: + svcKeiNo / idoRsvNo: + idoRsvNo / idoDiv: + idoDiv / idoRsvDtlCd: + idoRsvDtlCd / errCd: + errCd)` // Japanese: "Registration status error" with all context fields |
| 3 | CALL | `super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0010CW, new String[]{sb.toString()})` // Log detail error [-> Log] |
| 4 | CALL | `super.commonItem.setErrFlg(true)` // Set batch error flag [-> U] |
| 5 | RETURN | `return false` // Abort processing |

**Block 5** — [CATCH] `(Exception ex)` (L327)

> Catches any exception from the service invocation (network, CBS error, serialization failure, etc.). Logs the infrastructure-level error and aborts.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB1010CW, new String[]{"SPTVKEYINFOOPERATECC service contract number: " + svcKeiNo})` // Japanese: Service invocation error [-> Log] |
| 2 | CALL | `super.commonItem.setErrFlg(true)` // Set batch error flag [-> U] |
| 3 | RETURN | `return false` // Abort processing |

**Block 6** — [RETURN] `(normal completion)` (L331)

> All checks passed and no exceptions occurred.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true` // Service executed successfully |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `funcCd` | Field | Function code — controls whether the service performs a check (`"2"`) or update (`"1"`) |
| `shoriCd` | Field | Process code — identifies the specific business operation (`"3"` = port number change cancellation) |
| `idoDivDataMap` | Field | Migration reservation data map — carries all context from the `KK_T_IDO_RSV` table for the current batch record |
| `idoRsvNo` | Field | Migration reservation number — unique key for the migration reservation record in `KK_T_IDO_RSV` |
| `idoDiv` | Field | Migration classification — indicates the type of migration operation |
| `idoRsvDtlCd` | Field | Migration reservation detail code — granular classification of the reservation action |
| `svcKeiNo` | Field | Service contract number — key linking to the customer's service contract record in CAS |
| `oldPcrs` | Field | Old PCRS code — the portability reference code before the port number change |
| `newPcrs` | Field | New PCRS code — the portability reference code after the port number change |
| `old_pcrs` | Field | Input field name sent to SPTVKEYINFOOPERATECC — receives the **new** PCRS value (swapped from `oldPcrs`) |
| `new_pcrs` | Field | Input field name sent to SPTVKEYINFOOPERATECC — receives the **old** PCRS value (swapped from `newPcrs`) |
| `errCd` | Field | Error code — returned by the CAS service in the output map indicating application-level failure |
| `SPTVKEYINFOOPERATECC` | Constant | Special Service / Telephony Key Information Operation — the CBS service key for managing optional service contracts in CAS |
| `KKSV1053` | Constant | Use case identifier — the screen/use-case code that triggered this batch processing |
| `KKSV1053OP` | Constant | Operation identifier — the specific operation within the KKSV1053 use case |
| `FUNC_CD_UPD` | Constant | Function code = `"1"` — update (register/modify) mode |
| `FUNC_CD_CHK` | Constant | Function code = `"2"` — check-only (validation without write) mode |
| `SHORI_CD_CRS_CHG_CL` | Constant | Process code = `"3"` — port number change cancellation (*Koushin Henshu Torikeshi*) |
| PCRS | Acronym | Portability / PC (Phone Number Retention System) — Japanese number portability reference system |
| CAS | Acronym | Customer Account System — the core billing/customer management system |
| CBS | Acronym | Core Business System — the service layer that hosts business functions like SPTVKEYINFOOPERATECC |
| ESB | Acronym | Enterprise Service Bus — the messaging framework (`JCCBatchEsbInterface`) used for inter-service communication |
| `KK_T_IDO_RSV` | Table | Migration Reservation table — stores migration reservation records including reservation number, classification, detail code, and service contract info |
| `KK_T_CASCD_KNRI` | Table | CAS Number Possession table — stores CAS numbers associated with service contracts |
| `KK_T_OP_SVC_KEI` | Table | Optional Service Contract table — stores optional service contract details |
| EKKB0010CW | Log key | Business error log — registration status error with detailed context string |
| EKKB1010CW | Log key | Business error log — service invocation exception (infrastructure-level error) |
| JBSbatBusinessError | Exception | Custom business error thrown when CBS return code indicates failure |
| Return Code | Concept | Standardized response code from CBS service; `RETURN_CODE_SUCCESS` indicates the service completed successfully |
