# Business Logic — JBSbatKKSmtvlRnkiInfCst.getSysId() [16 LOC]

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

## 1. Role

### JBSbatKKSmtvlRnkiInfCst.getSysId()

This method serves as a **data lookup utility** that retrieves the system identifier (SYSID) associated with a given service contract detail number (`svcKeiNo`). The SYSID is a unique system-assigned primary key for records in the `KK_T_SVC_KEI` (Service Contract) table. In business terms, the service contract (`KK_T_SVC_KEI`) represents an agreement between K-Opticom (the telecommunications provider) and a customer for a specific service line. The SYSID acts as the canonical reference for that contract throughout the system's batch processing lifecycle.

This method implements the **delegate/repository pattern** — it encapsulates all SQL query logic and result parsing behind a simple key-value lookup, shielding callers from the underlying database access framework (`JBSbatSQLAccess`). It acts as a **shared utility** within the batch processing module, called by other methods in the same class (e.g., `getLogMsgKojiStop`) and by higher-level management screens (e.g., `JBSbatKKMansIfSksi.insertCust`). The method is designed to be resilient: when the contract record is not found, it returns an empty string rather than throwing an exception, allowing callers to handle the missing-data case gracefully.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getSysId(svcKeiNo)"])
    SETUP["Create paramList<br/>set svcKeiNo and opeDate"]
    SELECT["selectBySqlDefine<br/>KK_SELECT_023"]
    NEXT["selectNext()"]
    CHECK{"svcKei != null?"}
    FOUND["Return svcKei.getString(SYSID)"]
    NOT_FOUND["Return empty string"]
    END_RETURN(["Return"])

    START --> SETUP
    SETUP --> SELECT
    SELECT --> NEXT
    NEXT --> CHECK
    CHECK --> |"true"| FOUND
    CHECK --> |"false"| NOT_FOUND
    FOUND --> END_RETURN
    NOT_FOUND --> END_RETURN
```

**Processing Description:**

1. **Setup**: A new `JBSbatCommonDBInterface` instance (`paramList`) is created to serve as the SQL query parameter holder. The service contract detail number (`svcKeiNo`) and the operational date (`opeDate`, inherited from the parent batch class) are both set as positional parameters on this interface.

2. **Query Execution**: The `db_KK_T_SVC_KEI` SQL access object executes a SELECT query defined by the SQL key `KK_SELECT_023`, passing `paramList` as the parameter set. This query searches the `KK_T_SVC_KEI` table for a matching service contract record.

3. **Result Navigation**: `selectNext()` retrieves the first (and expected to be only) result row from the query output.

4. **Branch — Record Found**: If the query returns a non-null result, the SYSID field value is extracted via `getString(JBSbatKK_T_SVC_KEI.SYSID)` and returned. Here, `SYSID` resolves to the column name `"SYSID"`.

5. **Branch — Record Not Found**: If the query yields no matching record (`svcKei == null`), the method returns an empty string `""` as a safe default.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiNo` | `String` | Service contract detail number — the unique business identifier for a specific service contract line item. This is the primary key used to locate the customer's service agreement record in the `KK_T_SVC_KEI` table. It carries the value assigned during contract registration. |

**Instance Fields Read:**

| Field Name | Type | Business Description |
|------------|------|---------------------|
| `db_KK_T_SVC_KEI` | `JBSbatSQLAccess` | Database access object for the `KK_T_SVC_KEI` (Service Contract) table. Initialized during `initial()` with the batch's shared connection context. |
| `opeDate` | `String` | Operational date — the processing date for the current batch run. Inherited from the parent `JBSbatBusinessService` class via `setCommonInfo()`. Used as a query filter parameter alongside `svcKeiNo`. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatCommonDBInterface.setValue` | JBSbatCommonDBInterface | - | Sets the `svcKeiNo` parameter value on the query parameter holder |
| R | `JBSbatCommonDBInterface.setValue` | JBSbatCommonDBInterface | - | Sets the `opeDate` (operational date) parameter value on the query parameter holder |
| R | `db_KK_T_SVC_KEI.selectBySqlDefine` | (framework) | `KK_T_SVC_KEI` | Executes the SELECT query (`KK_SELECT_023`) against the Service Contract table |
| R | `db_KK_T_SVC_KEI.selectNext` | (framework) | `KK_T_SVC_KEI` | Retrieves the next row from the query result set |
| R | `svcKei.getString` | (framework) | `KK_T_SVC_KEI` | Extracts the SYSID column value from the result row |

**CRUD Analysis:**

This method performs exclusively **Read (R)** operations against the `KK_T_SVC_KEI` (Service Contract) table. It does not create, update, or delete any data. The method is a pure data lookup — it takes a service contract detail number, queries the database for the matching record, and returns the associated system ID.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `selectBySqlDefine` | (Framework) | `KK_T_SVC_KEI` | Executes SQL query KK_SELECT_023 to locate the service contract record by svcKeiNo and opeDate |
| R | `selectNext` | (Framework) | `KK_T_SVC_KEI` | Fetches the first matching row from the result set |
| R | `getString(SYSID)` | (Framework) | `KK_T_SVC_KEI` | Reads the SYSID column value from the retrieved row |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: `getString` [R], `getString` [R]  # NOSONAR

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JBSbatKKMansIfSksi.insertCust()` | `JBSbatKKMansIfSksi.insertCust` -> `JBSbatKKSmtvlRnkiInfCst.getSysId` | `getString [R] KK_T_SVC_KEI.SYSID` |
| 2 | `JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop()` | `JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop` -> `JBSbatKKSmtvlRnkiInfCst.getSysId` | `getString [R] KK_T_SVC_KEI.SYSID` |

**Trace Notes:**

- **`JBSbatKKMansIfSksi.insertCust()`**: A management screen integration class that handles customer insertion workflows. It calls `getSysId()` to obtain the system ID of a service contract during the customer registration process.
- **`JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop()`**: An internal method of the same class that generates log messages for processing stop situations. It calls `getSysId()` to include the service contract's system ID in the log output.

## 6. Per-Branch Detail Blocks

**Block 1** — [SETUP] (L573)

> Creates the SQL query parameter holder and populates it with the service contract detail number and operational date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface();` // Instantiate query parameter holder |
| 2 | SET | `paramList.setValue(svcKeiNo);` // Set service contract detail number [Parameter from caller] |
| 3 | SET | `paramList.setValue(opeDate);` // Set operational date [Inherited from parent batch class] |

**Block 2** — [EXEC] (L577)

> Executes the SQL SELECT query against the Service Contract table using the pre-built parameter set.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `db_KK_T_SVC_KEI.selectBySqlDefine(paramList, KK_T_SVC_KEI_KK_SELECT_023);` // Query KK_T_SVC_KEI table with SQL key KK_SELECT_023 |

**Block 3** — [EXEC] (L578)

> Retrieves the next result row from the executed query.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcKei = db_KK_T_SVC_KEI.selectNext();` // Fetch first result row [Returns JBSbatCommonDBInterface or null] |

**Block 4** — [IF-ELSE] `(svcKei != null)` (L579)

> Conditional branch: checks whether the query returned a matching service contract record.

**Block 4.1** — [IF] `(svcKei != null)` [Record Found] (L580)

> The service contract record was found. Extract and return its system ID.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return svcKei.getString(JBSbatKK_T_SVC_KEI.SYSID);` // Return SYSID column value [JBSbatKK_T_SVC_KEI.SYSID = "SYSID"] |

**Block 4.2** — [ELSE] `(svcKei == null)` [Record Not Found] (L583)

> No matching service contract record exists for the given `svcKeiNo`. Return an empty string as a safe default.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return "";` // Return empty string as default when contract not found |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiNo` | Field | Service Contract Detail Number — the unique business identifier for a service contract line item. Used to look up the contract record. |
| `opeDate` | Field | Operational Date — the processing date of the current batch run, inherited from the parent batch service class. Used as a query filter parameter. |
| SYSID | Field | System ID — the internal system-assigned primary key for a record in the `KK_T_SVC_KEI` table. Canonical reference used throughout the system to identify a service contract. |
| `KK_T_SVC_KEI` | Table | Service Contract Table — the core database table storing customer service contract records. Each row represents a service agreement between K-Opticom and a customer. |
| `KK_SELECT_023` | SQL Key | SQL definition key — the identifier for the SELECT query used to search the `KK_T_SVC_KEI` table by service contract detail number and operational date. |
| `JBSbatCommonDBInterface` | Framework | Common Database Interface — a parameter holder class used to pass positional parameters to SQL query methods in the batch framework. |
| `JBSbatSQLAccess` | Framework | SQL Access Object — the database access layer class that executes SQL queries and manages result sets for a specific table. |
| `JBSbatBusinessService` | Framework | Base Business Service — the parent class for all batch business services, providing common initialization and data access utilities. |
| K-Opticom | Business term | A Japanese telecommunications company providing fiber-optic internet (FTTH) and other communication services to residential and business customers. |
| KK (prefix) | Naming convention | Abbreviation for K-Opticom — used as a prefix in table and class names to indicate K-Opticom-specific domain entities. |
