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

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

## 1. Role

### JBSbatKKSodUpdInfCst.isSurrenderService()

The `isSurrenderService()` method performs a **service surrender (cancellation) status check** within K-Opticom's customer core batch system. It determines whether a given service contract has been formally surrendered (解約 — kaiyaku, i.e., terminated or cancelled). This method acts as a **shared guard query** called by the parent class's own `execute()` method, serving as a conditional gate within the SOD (Service Order Data) update information processing pipeline — specifically during address change workflows where knowing whether a line item has already been surrendered is critical to avoiding duplicate surrender processing.

The method implements a **gate-and-query pattern**: it first validates the input (early return for null/blank service numbers), then delegates to a DB access layer to look up the service contract record. The Javadoc documents a key business nuance — even if the service appears surrendered in the database, if the change classification (異動区分 — idou kubun) is an address change (住所変更 — jusho henkou), the system explicitly treats it as NOT surrendered. This prevents double-processing of surrender events that coincide with address updates.

This method is a **private utility** scoped within the batch service component, used by the same class's execution flow to conditionally branch processing based on surrender status. It returns a simple boolean: `true` if the service contract record is found (indicating surrendered status), `false` otherwise (including when no record exists or the input is blank).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["isSurrenderService(svcNo)"])
    COND_BLANK{"JKKStringUtil.isNullBlank(svcNo)"}
    NODE_PARAM["paramList = new JBSbatCommonDBInterface()"]
    NODE_SVC["paramList.setValue(svcNo)"]
    NODE_DATE["paramList.setValue(opeDate)"]
    NODE_SELECT["db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_251)"]
    NODE_NEXT{"db_KK_T_SVC_KEI.selectNext() == null"}
    RET_FALSE1(["return false (not surrendered)"])
    RET_FALSE2(["return false (not surrendered)"])
    RET_TRUE(["return true (surrendered)"])

    START --> COND_BLANK
    COND_BLANK -->|"true"| RET_FALSE1
    COND_BLANK -->|"false"| NODE_PARAM
    NODE_PARAM --> NODE_SVC
    NODE_SVC --> NODE_DATE
    NODE_DATE --> NODE_SELECT
    NODE_SELECT --> NODE_NEXT
    NODE_NEXT -->|"true"| RET_FALSE2
    NODE_NEXT -->|"false"| RET_TRUE
```

**CRITICAL — Constant Resolution:**
- `KK_T_SVC_KEI_KK_SELECT_251 = "KK_SELECT_251"` — SQL define key used to identify the DB query that retrieves the service contract (KK_T_SVC_KEI) record for the given service number and operation date. This SQL define maps to a SELECT statement targeting the `KK_T_SVC_KEI` table.

**Processing Flow:**
1. **Guard check** — If `svcNo` is null, empty, or blank, the method returns `false` immediately, treating an absent service number as "not surrendered."
2. **Parameter setup** — A `JBSbatCommonDBInterface` list is created and populated with the `svcNo` (service contract number) and `opeDate` (operation date) as bind parameters.
3. **DB query execution** — The `db_KK_T_SVC_KEI` SQL access object executes a SELECT via the `KK_SELECT_251` SQL define, querying the `KK_T_SVC_KEI` table (service contract line items) for a matching record.
4. **Result evaluation** — If `selectNext()` returns `null` (no matching record found), the service is **not surrendered** (returns `false`). If a record exists, the service **is surrendered** (returns `true`).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcNo` | `String` | Service Contract Number — the unique identifier for a service contract line item. Used to look up the corresponding record in the `KK_T_SVC_KEI` (service contract line details) table. If null, blank, or empty, the method returns `false` (not surrendered). |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `opeDate` | `String` | Operation Date — the processing date used as a query parameter to filter the service contract lookup. Typically set to the current batch processing date. |
| `db_KK_T_SVC_KEI` | `JBSbatSQLAccess` | DB Access object for the `KK_T_SVC_KEI` table (Service Contract line details). Wraps SQL execution and result set navigation for the service contract table. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JKKStringUtil.isNullBlank` | - | - | Validates that `svcNo` is not null, empty, or blank. Utility call for input guard. |
| R | `db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_251)` | KK_T_SVC_KEI | `KK_T_SVC_KEI` | Executes a SELECT query against the Service Contract line details table using SQL define `KK_SELECT_251`. Queries for a record matching the given `svcNo` and `opeDate`. |
| R | `db_KK_T_SVC_KEI.selectNext()` | KK_T_SVC_KEI | `KK_T_SVC_KEI` | Advances to the next row of the result set produced by the preceding `selectBySqlDefine()` call. Returns `null` if no record was found, indicating the service is not surrendered. |

**CRUD Summary:**
- This method performs **only read (R)** operations against the `KK_T_SVC_KEI` (Service Contract line details) table.
- No create, update, or delete operations are performed.
- The SQL define `KK_SELECT_251` resolves the DB query that checks for the existence of a surrendered service contract record.

## 5. Dependency Trace

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

Direct callers found: 1 methods.
Terminal operations from this method: `selectBySqlDefine` [-], `selectNext` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKSodUpdInfCst | `JBSbatKKSodUpdInfCst.execute()` -> `JBSbatKKSodUpdInfCst.isSurrenderService(svcNo)` | `selectBySqlDefine [R] KK_T_SVC_KEI`, `selectNext [R] KK_T_SVC_KEI` |

**Details:**
- This method is called by `execute()` within the same class `JBSbatKKSodUpdInfCst`.
- `execute()` is the main batch execution entry point for this Service Component, responsible for processing SOD (Service Order Data) update information.
- The terminal operations reach only the `KK_T_SVC_KEI` table (read) via the SQL access object `db_KK_T_SVC_KEI`.

## 6. Per-Branch Detail Blocks

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

> Input validation: guard clause to return false when the service contract number is missing. If the service number is null, empty, or blank, the method treats the service as not surrendered and exits early.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JKKStringUtil.isNullBlank(svcNo)` // Input validation: checks if svcNo is null, empty, or whitespace-only |
| 2 | RETURN | `return false;` // Not surrendered (service number is absent) |

**Block 2** — [ELSE-IMPLICIT] `(svcNo is valid)` (L1043)

> The service number is present. Prepare the query parameters and execute the DB lookup.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` // Instantiate parameter list for SQL bind variables |
| 2 | EXEC | `paramList.setValue(svcNo)` // Bind service contract number to parameter list |
| 3 | EXEC | `paramList.setValue(opeDate)` // Bind operation date to parameter list [-> opeDate = batch processing date] |
| 4 | CALL | `db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_251)` // Execute SELECT on KK_T_SVC_KEI table using SQL define "KK_SELECT_251" |
| 5 | IF | `db_KK_T_SVC_KEI.selectNext() == null` // Check if query returned no matching records |

**Block 2.1** — [IF: no matching record] (L1049)

> No service contract record was found for the given `svcNo` at the `opeDate`. The service is considered not surrendered.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return false;` // Not surrendered — no record found in KK_T_SVC_KEI |

**Block 2.2** — [ELSE: matching record found] (L1052)

> A service contract record was found for the given `svcNo` at the `opeDate`. The service is considered surrendered (has been terminated).

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true;` // Surrendered — record exists in KK_T_SVC_KEI |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcNo` | Field | Service Contract Number — unique identifier for a service contract line item in the `KK_T_SVC_KEI` table. Used to look up surrender status. |
| `opeDate` | Field | Operation Date — the batch processing date used as a query filter. Represents the effective date for the surrender status check. |
| 解約 (Kaiyaku) | Japanese Term | Service Surrender/Cancellation — the formal termination of a service contract. When a service is surrendered, the contract is closed and no further charges apply. |
| 住所変更 (Jusho Henkou) | Japanese Term | Address Change — a type of service modification where the customer's registered address is updated. Per Javadoc, even if surrendered, address changes are NOT treated as surrenders to avoid double-processing. |
| 異動区分 (Idou Kubun) | Japanese Term | Change Classification — a category that identifies the type of service modification (e.g., new registration, address change, surrender). |
| KK_T_SVC_KEI | DB Table | Service Contract Line Details — the core table storing service contract line item records including surrender status. Query target of this method. |
| KK_T_SVKEI_KAISEN_UW | DB Table | Service Contract Line History — a history/working table for service contract line changes, used elsewhere in this component. |
| KK_SELECT_251 | SQL Define | SQL definition key mapped to a SELECT statement on `KK_T_SVC_KEI`. Used to query for the existence of a service contract record given svcNo and opeDate. |
| JBSbatSQLAccess | Class | SQL Access framework class — provides DB query execution (`selectBySqlDefine`) and result navigation (`selectNext`) methods. Wraps database connectivity and result set handling. |
| JBSbatCommonDBInterface | Class | Common DB Interface — a parameter list class used to bind values (e.g., svcNo, opeDate) for SQL query parameters. |
| JKKStringUtil.isNullBlank | Method | Utility method that checks if a string is null, empty, or blank (whitespace-only). Returns true if the string has no meaningful content. |
| SOD | Acronym | Service Order Data — the domain entity representing service order information in the K-Opticom system. |
| JBSbatKKSodUpdInfCst | Class | SOD Update Information Component — the batch-side service component that processes service order data updates, including address changes and surrender handling. |
| KK_T_ADCHG | DB Table | Address Change — table storing address change records, referenced elsewhere in this component. |
| KK_T_ADCHG_DTL | DB Table | Address Change Details — table storing detailed records of address changes. |
