# Business Logic — JBSbatKKSmtvlRnkiInfCst.isSurrenderService() [20 LOC]

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

## 1. Role

### JBSbatKKSmtvlRnkiInfCst.isSurrenderService()

The `isSurrenderService` method performs a **service contract surrender status check** within the address change batch processing system. It determines whether a given service contract (`svcNo`) has already been surrendered (cancelled/closed) by querying the service contract header table (`KK_T_SVC_KEI`). This is a critical guard method used during address change (住所変更) batch processing — specifically within the `execute` method — to decide whether downstream processing (such as installment payment modification) should be skipped for a surrendered service contract.

The method implements the **guard pattern**: it returns early with `false` (not surrendered) when no service number is provided, preventing NPEs and unnecessary DB access. When a valid service number is provided, it delegates to a SQL-based read operation and returns `true` only if a matching record exists in the service contract header table, indicating the contract line is present and thus not surrendered. If no record is found, it returns `false`, indicating the service has been surrendered.

The Japanese javadoc adds an important nuance: the method does not treat address-change-type transfers (異動区分が住所変更) as surrendered, even if a record might otherwise suggest cancellation. This method serves as a shared utility (private method within the batch service class) called by the `execute` method during address change processing. Its role is to filter out surrendered service contracts so that installment adjustment logic does not erroneously process contracts that have already been terminated.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["isSurrenderService(svcNo)"])
    COND_BLANK{svcNo is null or blank?}
    INIT_PARAM["Create paramList with svcNo and opeDate"]
    DB_QUERY["DB Access: selectBySqlDefine(KK_SELECT_251) on KK_T_SVC_KEI"]
    COND_ROW{Record found?}
    RETURN_FALSE["Return false — not surrendered"]
    RETURN_TRUE["Return true — surrendered"]

    START --> COND_BLANK
    COND_BLANK -->|"Yes"| RETURN_FALSE
    COND_BLANK -->|"No"| INIT_PARAM
    INIT_PARAM --> DB_QUERY
    DB_QUERY --> COND_ROW
    COND_ROW -->|"null — no record"| RETURN_FALSE
    COND_ROW -->|"record exists"| RETURN_TRUE
```

**CRITICAL — Constant Resolution:**
- The SQL key constant `KK_T_SVC_KEI_KK_SELECT_251` resolves to `"KK_SELECT_251"`. This is the SQL definition key used to query the service contract header table (`KK_T_SVC_KEI`) for the given service number and operation date.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcNo` | `String` | Service contract number (`サービス契約番号`) — the unique identifier of a service contract line item used to look up whether the contract has been surrendered (cancelled). It is extracted from the address change detail record (`JBSbatKK_T_ADCHG_DTL.CHBF_SKBT_NO`). |

| # | Type | Description |
|---|------|-------------|
| 1 | Instance Field | `opeDate` — the operation date (`String`) used as a query parameter alongside `svcNo` to filter the service contract header query. This is the batch processing date. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKStringUtil.isNullBlank` | - | - | Calls `isNullBlank` to check if `svcNo` is null or blank (validation) |
| - | `JBSbatCommonDBInterface.setValue` | - | - | Sets `svcNo` and `opeDate` values into the parameter list |
| R | `JBSbatSQLAccess.selectBySqlDefine` | KK_T_SVC_KEI | KK_T_SVC_KEI | Executes the SQL query using key `KK_SELECT_251` against the service contract header table |
| R | `JBSbatSQLAccess.selectNext` | KK_T_SVC_KEI | KK_T_SVC_KEI | Fetches the next record from the query result set to check if a surrendered contract exists |

**Classification rationale:**
- **R (Read)**: Both `selectBySqlDefine` and `selectNext` are read-only database operations that query the `KK_T_SVC_KEI` (Service Contract Header) table to determine surrender status.
- **R (Read)**: `isNullBlank` is a utility read operation that checks whether the input string is null or blank.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch:JBSbatKKSmtvlRnkiInfCst.execute() | `execute()` → `isSurrenderService()` | `selectBySqlDefine [R] KK_T_SVC_KEI` |
| 2 | Batch:JBSbatKKSmtvlRnkiInfCst.execute() (commented) | `execute()` → `isSurrenderService()` | `selectBySqlDefine [R] KK_T_SVC_KEI` |

**Notes:**
- The method is called from `JBSbatKKSmtvlRnkiInfCst.execute()` at line 280 (active call) and line 323 (active call), both passing the transfer-from service contract number (`CHBF_SKBT_NO`) from the address change detail.
- Line 234 shows a commented-out call — legacy code that previously filtered surrendered contracts before adding output records.
- The caller is the batch processing entry point (`execute`) within the same class, which handles address change batch processing (住所変更バッチ処理).

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(JKKStringUtil.isNullBlank(svcNo))` (L495)

> Guard clause: If the service contract number is null or blank, the method assumes the service has NOT been surrendered and returns false immediately. This prevents unnecessary database access and protects against null pointer exceptions.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JKKStringUtil.isNullBlank(svcNo)` // Check if svcNo is null or blank [-> JKKStringUtil utility] |
| 2 | RETURN | `return false;` // Not surrendered (no service number means no surrender record exists) |

**Block 2** — [SEQUENCE] (L499–L503)

> Building the parameter list and executing the database query to look up the service contract surrender status.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` // Generate a new parameter list object [-> local variable] |
| 2 | SET | `paramList.setValue(svcNo)` // Set the service contract number into paramList [-> svcNo parameter] |
| 3 | SET | `paramList.setValue(opeDate)` // Set the operation date into paramList [-> instance field opeDate] |
| 4 | CALL | `db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_251)` // Execute SQL query with key "KK_SELECT_251" on KK_T_SVC_KEI table |

**Block 3** — [IF] `(db_KK_T_SVC_KEI.selectNext() == null)` (L505)

> Check if the query returned any records. If no record is found for the given service number, it means the service contract has been surrendered (deleted from the active contract table).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `db_KK_T_SVC_KEI.selectNext()` // Fetch next record from query result [-> returns null if no record] |
| 2 | RETURN | `return false;` // Not surrendered — no record found [-> "解約済みではない" / Not a completed surrender] |

**Block 4** — [RETURN] (L508)

> A record was found for the service contract number, meaning the contract still exists in the active table. The method returns true, indicating the service is considered "surrendered" in the context of this batch processing.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true;` // Surrendered — record found [-> "解約済み" / Completed surrender] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcNo` | Field | Service contract number — unique identifier for a service contract line item in the telecom billing system |
| `opeDate` | Field | Operation date — the batch processing date used as a query filter |
| `KK_T_SVC_KEI` | DB Table | Service Contract Header table — stores the master records for service contracts (the table queried to check surrender status) |
| `KK_T_SVC_KEI_KK_SELECT_251` | Constant | SQL definition key (`"KK_SELECT_251"`) — the SQL query identifier used to look up service contract header records |
| `JBSbatCommonDBInterface` | Class | Database interface parameter container — holds key-value parameters for SQL query execution |
| `JBSbatSQLAccess` | Class | SQL access wrapper class — handles database SELECT/INSERT/UPDATE/DELETE operations |
| `JBSbatKKSmtvlRnkiInfCst` | Class | Address change notification information constant class — batch service class for processing address change notifications in the ClarisAuth telecom billing system |
| `CHBF_SKBT_NO` | Field | Transfer-from service contract number — the original service contract number before an address change transfer |
| `isNullBlank` | Method | Null/blank check utility — returns true if a string is null, empty, or contains only whitespace |
| 解約 (Kaiyaku) | Japanese | Surrender / Cancellation — the business concept of cancelling or terminating a service contract |
| 住所変更 (Juusho Henkou) | Japanese | Address change — the business process of updating a customer's registered address in the telecom system |
| 異動区分 (Idou Kumbun) | Japanese | Transfer classification — categorizes the type of service transfer (e.g., address change vs. other transfer types) |
| 移転元 (Itenmoto) | Japanese | Transfer source — the original service contract before being transferred/moved |
| 住所変更バッチ (Juusho Henkou Batch) | Japanese | Address change batch — the batch processing job that handles address change operations in the ClarisAuth system |
