# Business Logic — JBSbatKKDelKhChk.canDelIspNinsyoId() [51 LOC]

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

## 1. Role

### JBSbatKKDelKhChk.canDelIspNinsyoId()

This method performs the **deletion eligibility check** for ISP Authentication ID records in the K-Opticom customer base system. It is a private gatekeeping method invoked during the batch deletion process orchestrated by `JBSbatKKDelKhChk.execute()`, which handles the systematic removal of various customer credentials (ISP authentication IDs, mail addresses, PPP IDs, URLs, etc.).

The method implements a **two-phase conditional gate** pattern. In Phase 1, it queries the service contract detail table (`KK_T_SVC_KEI_UCWK`) to determine whether any active service line item still references the given ISP authentication ID. If a matching record exists, deletion is immediately rejected — an ISP ID tied to an active service must not be purged. In Phase 2 (conditionally entered only if Phase 1 permits deletion), the method verifies whether a **cancellation Service Order Data (SOD)** has been issued for the associated service contract. This Phase 2 check is only performed when the deletion target type is ISP Authentication ID (`DEL_TRGT_SBT_ISP_NINSYO_ID = "01"`), as added in ANK-2897-00-00. If no cancellation SOD exists, the method blocks deletion and logs a business error instructing the batch to skip the cancel order issuance step.

This method serves as a **shared deletion guard** called from the batch's main `execute()` dispatch logic. It ensures data integrity by preventing premature deletion of ISP credentials that are still in active use or lack the required cancellation workflow.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["canDelIspNinsyoId inMap"])
    
    START --> INIT["Initialize canDel false, nextRec null"]
    INIT --> BUILD1["Build selectWhereParam SVKEIUW_NO ISP_NINSHO_ID opeDate"]
    BUILD1 --> EXEC1["executeKK_T_SVC_KEI_UCWK_KK_SELECT_056 selectWhereParam"]
    EXEC1 --> FETCH1["nextRec db_KK_T_SVC_KEI_UCWK selectNext"]
    
    FETCH1 --> CHK1{nextRec null}
    CHK1 -->|"Yes"| SET_TRUE["canDel true"]
    CHK1 -->|"No"| SET_FALSE["canDel false"]
    
    SET_TRUE --> EARLY_CHK{canDel true}
    SET_FALSE --> EARLY_CHK
    
    EARLY_CHK -->|"No"| EARLY_RET["return canDel false"]
    EARLY_CHK -->|"Yes"| CHK_TYPE{DEL_TRGT_SBT_ISP_NINSYO_ID equals 01}
    
    CHK_TYPE -->|"Yes"| BUILD2["Build kk1041SelectWhereParam SVKEI_NO SVKEIUW_NO"]
    CHK_TYPE -->|"No"| FINAL_RET["Return canDel"]
    
    BUILD2 --> EXEC2["executeKK_T_ODR_SET_KK_SELECT_024 kk1041SelectWhereParam"]
    EXEC2 --> FETCH2["kk1041NextRec db_KK_T_ODR_SET selectNext"]
    
    FETCH2 --> CHK2{kk1041NextRec null}
    CHK2 -->|"Yes"| REJECT_DEL["canDel false"]
    CHK2 -->|"No"| FINAL_RET
    
    REJECT_DEL --> LOG_ERROR["Build log Cancel order not issued
  printBusinessErrorLog EKKB1200AI log"]
    LOG_ERROR --> FINAL_RET
    
    FINAL_RET --> END(["Return canDel"])
    EARLY_RET --> END
```

### Processing Description

1. **Initialization** — The method initializes `canDel = false` (default: deletion not permitted) and declares a `nextRec` variable for holding the next DB record from the cursor.

2. **Phase 1: Active Service Check** — A parameter array (`selectWhereParam`) is built using the service contract detail number (`SVKEIUW_NO`), the ISP authentication ID (`ISP_NINSHO_ID`), and the operational date (`opeDate`). This is passed to `executeKK_T_SVC_KEI_UCWK_KK_SELECT_056`, which executes a SELECT query against the `KK_T_SVC_KEI_UCWK` table. The method then calls `db_KK_T_SVC_KEI_UCWK.selectNext()` to fetch the next record. If no matching record is found (i.e., no active service line item references this ISP ID), `canDel` is set to `true`, meaning deletion is potentially allowed.

3. **Early Exit Guard** — If `canDel` remains `false` after Phase 1 (an active service record was found), the method returns `false` immediately without proceeding to Phase 2. This ensures the batch halts for this record, preventing deletion of an ISP ID that is still in active service.

4. **Phase 2: Cancellation SOD Check** — This phase is entered only when `canDel` is `true` after Phase 1. The method checks whether the deletion target type from the input map matches `DEL_TRGT_SBT_ISP_NINSYO_ID = "01"` (Delete Target Type: ISP Authentication ID). When true:
   - A second parameter array (`kk1041SelectWhereParam`) is built using the service contract number (`SVKEI_NO`) and service contract detail number (`SVKEIUW_NO`).
   - This is passed to `executeKK_T_ODR_SET_KK_SELECT_024`, which queries the `KK_T_ODR_SET` (Order Settings) table.
   - If no cancellation SOD record is found (`kk1041NextRec == null`), `canDel` is set to `false`, and a business error is logged via `commonItem.getLogPrint().printBusinessErrorLog("EKKB1200AI", ...)` with a message indicating that the cancellation order was not issued and the delete order issuance is being skipped.

5. **Return** — The method returns the `canDel` boolean. `true` means the ISP authentication ID can be safely deleted (no active service, and either no cancellation SOD exists or one has already been issued). `false` means deletion is blocked for one of the reasons above.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Input message containing customer service data for the deletion eligibility check. Carries the service contract detail number (`SVKEIUW_NO`), ISP authentication ID (`ISP_NINSHO_ID`), service contract number (`SVKEI_NO`), and deletion target type (`DEL_TRGT_SBT`) as extracted from the batch input item definition (`JBSbatKKIFM160`). |
| 2 | `opeDate` | `String` (instance field) | Operational date — the business date used as a filter for the `KK_T_SVC_KEI_UCWK` query. Represents the date on which the batch processing is executing, ensuring that only records valid as of that date are considered. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKDelKhChk.executeKK_T_SVC_KEI_UCWK_KK_SELECT_056` | KK_T_SVC_KEI_UCWK | `KK_T_SVC_KEI_UCWK` | Queries the service contract detail table to check for active records matching the ISP authentication ID, service contract detail number, and operational date. |
| R | `JBSbatCommonDBInterface.selectNext` | — | `KK_T_SVC_KEI_UCWK` | Fetches the next record from the cursor opened by `executeKK_T_SVC_KEI_UCWK_KK_SELECT_056`. |
| R | `JBSbatKKDelKhChk.executeKK_T_ODR_SET_KK_SELECT_024` | KK_T_ODR_SET | `KK_T_ODR_SET` | Queries the order settings table to check whether a cancellation SOD (Service Order Data) exists for the given service contract and detail numbers. |
| R | `JBSbatCommonDBInterface.selectNext` | — | `KK_T_ODR_SET` | Fetches the next record from the cursor opened by `executeKK_T_ODR_SET_KK_SELECT_024`. |
| - | `JBSbatKKEMoneyTktnIraiRnk.printBusinessErrorLog` | — | — | Calls `printBusinessErrorLog` to log a business error message (SC Code: EKKB1200AI) indicating that a cancellation order was not issued and the delete order is being skipped. |
| R | `JBSbatServiceInterfaceMap.getString` | — | — | Retrieves values from the input map by field key (e.g., `SVKEIUW_NO`, `ISP_NINSHO_ID`, `SVKEI_NO`, `DEL_TRGT_SBT`). |

## 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: `printBusinessErrorLog` [-], `printBusinessErrorLog` [-], `selectNext` [R], `selectNext` [R], `executeKK_T_ODR_SET_KK_SELECT_024` [-], `getString` [R], `getString` [R], `getString` [R], `getString` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKDelKhChk | `JBSbatKKDelKhChk.execute(inMap)` -> `canDelIspNinsyoId(inMap)` (when `DEL_TRGT_SBT` is "01" or "02") | `executeKK_T_SVC_KEI_UCWK_KK_SELECT_056 [R] KK_T_SVC_KEI_UCWK`<br>`executeKK_T_ODR_SET_KK_SELECT_024 [R] KK_T_ODR_SET`<br>`printBusinessErrorLog [-] EKKB1200AI` |

## 6. Per-Branch Detail Blocks

**Block 1** — [LOCAL VARIABLE DECLARATION] (L607–L610)

> Initializes the local variables used in the deletion eligibility check. `canDel` defaults to `false` (deletion not permitted), and `nextRec` is set to `null` for the cursor record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `canDel = false` // 消去可否 (deletion eligibility) |
| 2 | SET | `nextRec = null` // 次レコード (next record) |

**Block 2** — [SET] (L612–L616)

> Builds the parameter array for the Phase 1 query against the service contract detail table (`KK_T_SVC_KEI_UCWK`). The three parameters identify the specific service line item, the ISP authentication ID to check, and the operational date for filtering.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `inMap.getString(JBSbatKKIFM160.SVKEIUW_NO)` // サービス契約内線番号 (service contract detail number) | Identifies the service contract line item |
| 2 | SET | `inMap.getString(JBSbatKKIFM160.ISP_NINSHO_ID)` // ISP認証ID (ISP authentication ID) | The ISP credential being checked for deletion |
| 3 | SET | `opeDate` // 運用日 (operational date) | Business date filter for the query |

**Block 3** — [EXEC] (L618–L619)

> Executes the Phase 1 database query and retrieves the first matching record.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | CALL | `executeKK_T_SVC_KEI_UCWK_KK_SELECT_056(selectWhereParam)` | Queries `KK_T_SVC_KEI_UCWK` for active service records |
| 2 | CALL | `db_KK_T_SVC_KEI_UCWK.selectNext()` | Fetches next record from cursor |

**Block 4** — [IF] `(nextRec == null)` (L620–L623)

> If no active service record is found, the ISP authentication ID is not in use by any service line item, so deletion is permitted (`canDel = true`).

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `canDel = true` // 消去可否をtrueに設定 (set deletion eligibility to true) | No active service found; deletion allowed |

**Block 5** — [IF] `(!canDel)` — ANK-2897-00-00 ADD (L627–L630)

> Early exit guard: if `canDel` is `false` after Phase 1 (meaning an active service record exists), the method returns `false` immediately. This prevents unnecessary Phase 2 processing when deletion is already blocked.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | RETURN | `return canDel` // 消去不可のため処理終了 (return false: deletion not permitted) | Short-circuit: active service found, reject deletion |

**Block 6** — [IF] `(DEL_TRGT_SBT_ISP_NINSYO_ID.equals(inMap.getString(JBSbatKKIFM160.DEL_TRGT_SBT)))` — ANK-2897-00-00 ADD (L632–L654)

> `[DEL_TRGT_SBT_ISP_NINSYO_ID = "01"]` (消去対象種類: ISP認証ID / Delete Target Type: ISP Authentication ID)
>
> Phase 2: Cancellation SOD check. This block is only entered when the input deletion target type matches "01" (ISP Authentication ID). It verifies that a cancellation Service Order Data (SOD) has been issued before allowing deletion. If the cancellation SOD is missing, deletion is blocked and a business error is logged.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `kk1041NextRec = null` // 次レコード (next record) | Local variable for Phase 2 cursor |
| 2 | SET | `inMap.getString(JBSbatKKIFM160.SVKEI_NO)` // サービス契約番号 (service contract number) | Contract-level identifier for SOD query |
| 3 | SET | `inMap.getString(JBSbatKKIFM160.SVKEIUW_NO)` // サービス契約内線番号 (service contract detail number) | Detail-level identifier for SOD query |
| 4 | CALL | `executeKK_T_ODR_SET_KK_SELECT_024(kk1041SelectWhereParam)` | Queries `KK_T_ODR_SET` for cancellation SOD |
| 5 | CALL | `db_KK_T_ODR_SET.selectNext()` | Fetches next record from SOD cursor |

**Block 6.1** — [IF] `(kk1041NextRec == null)` (L640–L653)

> `[SOD not found]` If no cancellation SOD record exists for this service contract, deletion is blocked (`canDel = false`). A business error log is emitted to inform operators that the cancellation order was not issued and the delete order issuance has been skipped.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `canDel = false` // 消去不可 (deletion not permitted) | No cancellation SOD; block deletion |
| 2 | SET | `log = "解約オーダーが未発行のため消去オーダーの発行をスキップしました。サービス契約内線番号[" + inMap.getString(JBSbatKKIFM160.SVKEIUW_NO) + "]"` // 取消 order not issued, skipping delete order issuance (Japanese) | Constructs error message with the service contract detail number |
| 3 | CALL | `commonItem.getLogPrint().printBusinessErrorLog("EKKB1200AI", new String[]{log})` | Logs business error with SC Code EKKB1200AI |

**Block 7** — [RETURN] (L656)

> Returns the final `canDel` result: `true` if the ISP authentication ID can be safely deleted (no active service record, and either no cancellation SOD or one exists), `false` otherwise.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | RETURN | `return canDel` // 消去可否を返却 (return deletion eligibility) | Method exit with final decision |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `canDel` | Field | Deletion eligibility flag — `true` means the record can be safely deleted; `false` means deletion is blocked |
| `SVKEIUW_NO` | Field | Service Contract Detail Number — internal identifier for a service contract line item within a customer's account |
| `SVKEI_NO` | Field | Service Contract Number — top-level identifier for a customer's service contract |
| `ISP_NINSHO_ID` | Field | ISP Authentication ID — the credentials used by a customer to authenticate to the ISP (Internet Service Provider) network |
| `DEL_TRGT_SBT` | Field | Delete Target Type — classifies what kind of credential is being targeted for deletion |
| `opeDate` | Field | Operational Date — the business date used as a filtering criterion in database queries |
| `DEL_TRGT_SBT_ISP_NINSYO_ID` | Constant | Delete Target Type code `"01"` — identifies that the deletion target is an ISP Authentication ID |
| `DEL_TRGT_SBT_ISP_NINSYO_ID_OLD` | Constant | Delete Target Type code `"02"` — identifies the legacy ISP Authentication ID type |
| `KK_T_SVC_KEI_UCWK` | Table | Service Contract Detail table — stores line-item level details of customer service contracts |
| `KK_T_ODR_SET` | Table | Order Settings table — stores service order (SOD) records, including cancellation orders |
| SOD | Acronym | Service Order Data — a telecom order fulfillment record representing a service change request (registration, cancellation, modification, etc.) |
| `EKKB1200AI` | SC Code | Service Component code for the business error logging handler — logs operational warnings/errors during batch processing |
| `printBusinessErrorLog` | Method | Logs a business-level error or warning message to the batch error log, identified by SC code and message parameters |
| ANK-2897-00-00 | Change Request | JIRA/change ticket that added the cancellation SOD check (Phase 2) to prevent deletion when no cancellation order has been issued |
| 消去可否チェック | Japanese term | Deletion Eligibility Check — the overall batch process step that determines whether a record should be deleted |
| 解約SOD | Japanese term | Cancellation Service Order Data — the SOD record that represents a service cancellation request |
