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

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

## 1. Role

### JBSbatKKFmtcelSodUpdInfCst.isSurrenderService()

This method determines whether a given telecom service contract line has been surrendered (cancelled / terminated). It operates as a shared utility predicate — called from multiple locations within the batch processing flow `execute()` — to decide whether a service contract should be considered active or already terminated. The method performs a single database read against the `KK_T_SVC_KEI` (Service Contract Line) table, using the service contract number (`svcNo`) and the operating date (`opeDate`) as lookup keys. If no matching record is found in the table for the given service contract and date range, the method concludes the service has **not** been surrendered (returns `false`). If a matching record exists, it concludes the service **has** been surrendered (returns `true`). 

The Javadoc notes a special business rule: even if a record indicates surrender status, if the transfer classification (`idouto kubun`) is a "change of address" (address modification, code `00019`), the method would not treat it as a true surrender — though this filtering logic is evaluated at a higher layer, not within this method itself. This predicate is critical for the batch's routing logic: only non-surrendered service contracts proceed to further processing (e.g., line migration), while surrendered ones are silently skipped.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["isSurrenderService(svcNo)"])
    COND_NULL{"svcNo is null/blank?"}
    INIT["Create JBSbatCommonDBInterface paramList"]
    SET_SVC["paramList.setValue(svcNo)"]
    SET_OPE["paramList.setValue(opeDate)"]
    EXEC_SELECT["db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_SELECT_251)"]
    COND_RESULT{"selectNext() returns null?"}
    RET_FALSE(["Return false (not surrendered)"])
    RET_TRUE(["Return true (surrendered)"])

    START --> COND_NULL
    COND_NULL -- Yes --> RET_FALSE
    COND_NULL -- No --> INIT
    INIT --> SET_SVC
    SET_SVC --> SET_OPE
    SET_OPE --> EXEC_SELECT
    EXEC_SELECT --> COND_RESULT
    COND_RESULT -- Yes --> RET_FALSE
    COND_RESULT -- No --> RET_TRUE
```

**Constant Resolution:**
- `KK_T_SVC_KEI_KK_SELECT_251 = "KK_SELECT_251"` — SQL define key for querying the `KK_T_SVC_KEI` (Service Contract Line) table to check surrender status. This is a private static final string constant defined at line 85 of `JBSbatKKFmtcelSodUpdInfCst`.
- `opeDate` — Instance field (operating date) representing the batch processing date used as a lookup parameter.

**Processing Flow Summary:**
1. **Null-check guard**: If the input `svcNo` is null or blank, immediately return `false` (the service is not surrendered — there is no contract to surrender).
2. **Parameter list initialization**: Create a `JBSbatCommonDBInterface` container and populate it with the service contract number and the operating date.
3. **Database query**: Execute an SQL select against the `KK_T_SVC_KEI` table using the SQL define key `KK_SELECT_251`, which is configured to look up surrender status for a given service contract and date.
4. **Result judgment**: If `selectNext()` returns `null` (no matching record found), the service is not surrendered. If a record is found, the service is surrendered.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcNo` | `String` | Service contract number — the unique identifier for a service contract line item in the telecom billing system. It is used as the primary key to look up surrender status in the `KK_T_SVC_KEI` table. If null or blank, the method short-circuits to `false` since there is no contract to evaluate. |

**Instance Fields Read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `opeDate` | `String` | Operating date — the batch processing date used as a lookup parameter for the service contract surrender query. Typically set to the current batch execution date. |
| `db_KK_T_SVC_KEI` | `JBSbatSQLAccess` | Database access handler for the `KK_T_SVC_KEI` (Service Contract Line) table. Used to execute the SQL select query. Initialized in the class constructor/setter with `D_TBL_NAME_KK_T_SVC_KEI`. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `db_KK_T_SVC_KEI.selectBySqlDefine` | `-` | `KK_T_SVC_KEI` (Service Contract Line) | Queries the Service Contract Line table using SQL define key `KK_SELECT_251` to check if a surrender record exists for the given service contract number and operating date. |
| R | `db_KK_T_SVC_KEI.selectNext` | `-` | `KK_T_SVC_KEI` (Service Contract Line) | Fetches the next row from the result set of the previous select query. Returns `null` if no record matches (i.e., no surrender record found). |
| - | `JBSbatCommonDBInterface.setValue` | `-` | `-` | Sets values into the parameter list container — first `svcNo`, then `opeDate`. |
| - | `JBSbatCommonDBInterface.<init>` | `-` | `-` | Creates a new parameter container for passing arguments to the SQL query. |

**Classification Rationale:**
- This method performs **Read-only** database operations. It queries the `KK_T_SVC_KEI` table to determine surrender status but does not modify any data.
- The SQL define key `KK_SELECT_251` is a string constant; the actual SQL statement is defined externally in the SQL definition XML/properties file associated with this batch module.
- No other service components (SC) or business service (CBS) methods are called directly.

## 5. Dependency Trace

### Direct callers:

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKFmtcelSodUpdInfCst | `execute()` -> `isSurrenderService(inSvcKeiNo)` (Line 231) | `selectBySqlDefine [R] KK_T_SVC_KEI` |
| 2 | Batch: JBSbatKKFmtcelSodUpdInfCst | `execute()` -> `isSurrenderService(inSvcKeiNo)` (Line 265) | `selectBySqlDefine [R] KK_T_SVC_KEI` |
| 3 | Batch: JBSbatKKFmtcelSodUpdInfCst | `execute()` -> `isSurrenderService(inSvcKeiNo)` (Line 301) | `selectBySqlDefine [R] KK_T_SVC_KEI` |
| 4 | Batch: JBSbatKKFmtcelSodUpdInfCst | `execute()` -> `isSurrenderService(inSvcKeiNo)` (Line 339) | `selectBySqlDefine [R] KK_T_SVC_KEI` |

**Call Context Summary:**

The method `isSurrenderService()` is called from within the `execute()` method of the same class at 4 distinct points (lines 231, 265, 301, 339). In each case, it is invoked as a **gate check** — the result is negated (`!isSurrenderService(...)`) to determine whether the service contract is **not** surrendered. Only non-surrendered contracts proceed to further processing (e.g., being added to the output list for line migration). This pattern indicates the method serves as a **filter/qualifier** in the batch's main processing loop.

**Same-class implementations:** Note that `isSurrenderService()` is also defined in 4 other batch service classes (`JBSbatKKPlaceNoChgRnkiInfCst`, `JBSbatKKAdChgAddDataCst`, `JBSbatKKSodUpdInfCst`, `JBSbatKKSmtvlRnkiInfCst`) with identical logic — indicating this is a commonly duplicated pattern across multiple batch processing flows in the system.

## 6. Per-Branch Detail Blocks

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

> Guard clause: If the service contract number is null or blank, the method immediately returns `false` (not surrendered). This prevents null-pointer exceptions and correctly handles the case where no contract exists.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JKKStringUtil.isNullBlank(svcNo)` // Check if svcNo is null or empty string |
| 2 | RETURN | `return false;` // No contract number means no surrender |

**Block 2** — [SEQUENCE] (L547–549)

> Parameter list initialization: Create a `JBSbatCommonDBInterface` container and populate it with the service contract number and the operating date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface paramList = new JBSbatCommonDBInterface();` // Create parameter container |
| 2 | EXEC | `paramList.setValue(svcNo);` // Set service contract number as first parameter |
| 3 | EXEC | `paramList.setValue(opeDate);` // Set operating date as second parameter |

**Block 3** — [SEQUENCE] (L551–552)

> Database query execution: Execute the SQL select against `KK_T_SVC_KEI` using the pre-configured SQL define key.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_251)` // KK_SELECT_251 = "KK_SELECT_251" — SQL define key for surrender status check |

**Block 4** — [IF] `(db_KK_T_SVC_KEI.selectNext() == null)` (L553)

> Result judgment: If `selectNext()` returns `null`, no surrender record was found for this service contract and date — therefore, the service is **not** surrendered.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `db_KK_T_SVC_KEI.selectNext()` // Fetch next row from query result set |
| 2 | RETURN | `return false;` // Not surrendered — no matching record found |

**Block 5** — [RETURN] (L555)

> Implicit else: If the code reaches this point, `selectNext()` returned a non-null value, meaning a surrender record exists for this service contract.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true;` // Surrendered — a matching record was found |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcNo` | Field | Service contract number — unique identifier for a service contract line item |
| `opeDate` | Field | Operating date — the batch processing date, used as a query parameter for time-based lookups |
| `KK_T_SVC_KEI` | Table | Service Contract Line table — stores service contract line item records including surrender status |
| `KK_SELECT_251` | SQL Define Key | SQL definition key referencing the configured select query for checking service contract surrender status |
| `JBSbatCommonDBInterface` | Class | Database parameter container — a structured list used to pass query parameters to SQL execution methods |
| `JBSbatSQLAccess` | Class | SQL access wrapper — provides `selectBySqlDefine()` and `selectNext()` methods for executing database queries |
| `JKKStringUtil.isNullBlank` | Method | Utility method that checks if a string is null, empty, or contains only whitespace |
| `SVC_KEI` | Acronym | Service Kei (Service Line) — refers to individual service contract line items in the telecom billing domain |
| Surrender | Business term | 解約 (Kaiyaku) — cancellation or termination of a telecom service contract. A surrendered service is no longer active. |
| `execute()` | Method | Main batch processing entry point in `JBSbatKKFmtcelSodUpdInfCst` that iterates over service contract lines and delegates to utility methods like `isSurrenderService()` |
| `idouto kubun` | Field (JP) | Transfer classification — indicates the type of service contract change (e.g., new, address change). Code `00019` = address change/registration |
| Address Change | Business term | 住所変更 (Jusho Henkou) — a transfer classification where a customer's address is updated but the service contract remains active (not a true surrender) |
