---

# Business Logic — JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop() [47 LOC]

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

## 1. Role

### JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop()

This method constructs a log message string that captures the SYSID and service contract numbers associated with a work order stop (工事中止). It is a utility method used when a new construction work order is halted and the system needs to log traceable identifiers for audit and operational purposes. Specifically, it queries the `KK_T_ADCHG_DTL` (address change detail) table using the address change number (`adchgNo`) to identify service contract relationships across address change records. For each detail row, it determines whether the address change represents an addition (追加), cancellation/hold (解約・保留), or transfer (引越) of service contracts by comparing the "before" (motodanchi) and "after" (sakidanchi) service contract detail numbers (`CHBF_SKBT_NO` and `CHAF_SKBT_NO`). It aggregates all relevant service contract numbers into a single message string and retrieves the SYSID for the first identified service contract number. The method returns a formatted log message of the form ` SYSID:xxx サービス契約番号:yyy ...` that is appended to business error logs during work order stop processing. It serves as a shared utility called by batch screen logic that handles stopped work orders.

**Japanese Javadoc translation:** "Acquire message for log output (SYSID, service contract number)"

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getLogMsgKojiStop adchgNo"])
    START --> INIT["Initialize msgSvcKei empty sysId empty"]
    INIT --> CREATE_PARAM["Create JBSbatCommonDBInterface paramList"]
    CREATE_PARAM --> SET_ADCHG["paramList setValue adchgNo"]
    SET_ADCHG --> SET_SVC_TYPE["paramList setValue ADCHG_DTL_SBT_CD_SVC_KEI_NO = 01"]
    SET_SVC_TYPE --> DB_SELECT["db_KK_T_ADCHG_DTL selectBySqlDefine KK_SELECT_003"]
    DB_SELECT --> LOOP_START{"Start iteration"}
    LOOP_START --> GET_NEXT["adchgDtl selectNext"]
    GET_NEXT --> IS_NULL{adchgDtl null?}
    IS_NULL -->|yes| BUILD_RETURN["Build return string"]
    IS_NULL -->|no| GET_FIELDS["Get motoSvcKeiNo sakiSvcKeiNo"]
    GET_FIELDS --> BOTH_NULL{Both null?}
    BOTH_NULL -->|yes| CONTINUE_LOOP["continue"]
    CONTINUE_LOOP --> LOOP_START
    BOTH_NULL -->|no| EITHER_NULL{One null?}
    EITHER_NULL -->|yes| DETERMINE_SVC["Determine svcKeiNo"]
    EITHER_NULL -->|no| TRANSFER_CASE["Both non null"]
    DETERMINE_SVC --> APPEND_MSG_1["msgSvcKei append svcKeiNo"]
    APPEND_MSG_1 --> LOOP_START
    TRANSFER_CASE --> SAME_SVC{Equal?}
    SAME_SVC -->|yes| APPEND_MSG_2["msgSvcKei append motoSvcKeiNo"]
    SAME_SVC -->|no| APPEND_MSG_3["msgSvcKei append both"]
    APPEND_MSG_2 --> SET_SVC_KEY
    APPEND_MSG_3 --> SET_SVC_KEY
    SET_SVC_KEY --> NEED_SYSID{sysId empty?}
    NEED_SYSID -->|yes| CALL_GETSYSID["getSysId svcKeiNo"]
    CALL_GETSYSID --> LOOP_START
    NEED_SYSID -->|no| LOOP_START
    BUILD_RETURN --> END_NODE(["Return log message string"])
```

### Branch Constant Resolution:

- `ADCHG_DTL_SBT_CD_SVC_KEI_NO = "01"` — Address change detail type code for service contract number (住所変更明細種別コード（サービス契約番号）). This filters the address change detail query to rows relevant to service contracts.

### Logic Summary:

1. **Initialization**: Creates an empty message accumulator `msgSvcKei` and empty `sysId`.
2. **DB Query Setup**: Builds a `JBSbatCommonDBInterface` parameter list with the address change number and service contract type code `"01"`, then executes SQL define `KK_SELECT_003` against the `KK_T_ADCHG_DTL` table.
3. **Iterate**: Loops over all returned detail records. If no more records (`selectNext()` returns null), exits the loop.
4. **Extract Fields**: Retrieves the "before" service contract detail number (`CHBF_SKBT_NO`) and "after" service contract detail number (`CHAF_SKBT_NO`) from each detail record.
5. **Skip Empty**: If both are null, skips the record (the `continue` statement).
6. **Single-side Changes (Addition / Cancellation / Hold)**: If only one of the two fields is populated:
   - Addition (追加): `motoSvcKeiNo` is null, `sakiSvcKeiNo` is populated → service contract is new.
   - Cancellation/Hold (解約・保留): `motoSvcKeiNo` is populated, `sakiSvcKeiNo` is null → existing service contract cancelled or put on hold.
7. **Transfer (引越)**: If both fields are populated:
   - Same number: the service contract remained at the same location → log as a regular service contract number.
   - Different numbers: the service contract moved from one contract to another → log with both the "before" and "after" numbers.
8. **SYSID Fetch**: Only the first iteration where a valid `svcKeiNo` is determined triggers a call to `getSysId(svcKeiNo)` to retrieve the SYSID for that service contract. Subsequent iterations skip this call.
9. **Return**: Constructs the final log message in the format ` SYSID:{sysId} サービス契約番号:{svcKeiNo} ...`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `adchgNo` | `String` | Address change number — the unique identifier for an address change transaction that groups service contract modifications (additions, cancellations, transfers). Used to query the `KK_T_ADCHG_DTL` table to find all service contract detail rows associated with this address change. |

### Instance fields read:

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_ADCHG_DTL` | `JBSbatSQLAccess` | Database access object initialized for the `KK_T_ADCHG_DTL` (address change detail) table, used to execute the select query. |

## 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 address change number on parameter list |
| R | `JBSbatCommonDBInterface.setValue` | JBSbatCommonDBInterface | - | Sets service contract detail type code `"01"` on parameter list |
| R | `db_KK_T_ADCHG_DTL.selectBySqlDefine` | KK_T_ADCHG_DTL | KK_T_ADCHG_DTL | Selects address change detail rows matching the address change number and service contract detail type code using SQL define `KK_SELECT_003` |
| R | `db_KK_T_ADCHG_DTL.selectNext` | KK_T_ADCHG_DTL | KK_T_ADCHG_DTL | Retrieves the next address change detail record from the query result set |
| R | `JBSbatCommonDBInterface.getString` | JBSbatCommonDBInterface | - | Extracts the "before" service contract detail number (`CHBF_SKBT_NO`) from the detail record |
| R | `JBSbatCommonDBInterface.getString` | JBSbatCommonDBInterface | - | Extracts the "after" service contract detail number (`CHAF_SKBT_NO`) from the detail record |
| R | `JBSbatKKSmtvlRnkiInfCst.getSysId` | - | KK_T_SVC_KEI | Calls `getSysId` to retrieve the SYSID for a service contract by its service contract detail number. Internally queries `KK_T_SVC_KEI` using SQL define `KK_SELECT_023`. |
| R | `db_KK_T_SVC_KEI.selectBySqlDefine` | KK_T_SVC_KEI | KK_T_SVC_KEI | (Called via getSysId) Selects service contract record by service contract detail number and operating date |
| R | `db_KK_T_SVC_KEI.selectNext` | KK_T_SVC_KEI | KK_T_SVC_KEI | (Called via getSysId) Retrieves the next service contract record from the result set |

### Summary by Entity:

| Entity / DB | Operations | Description |
|-------------|-----------|-------------|
| `KK_T_ADCHG_DTL` (Address Change Detail) | R (Read) | Read address change detail rows filtered by address change number and service contract detail type code `"01"` |
| `KK_T_SVC_KEI` (Service Contract) | R (Read) | Read service contract record to obtain SYSID for a given service contract detail number |

## 5. Dependency Trace

The `getLogMsgKojiStop` method is a **private** utility method defined in `JBSbatKKSmtvlRnkiInfCst`. All references found in the codebase are **commented-out** calls, meaning the method was historically called during work order stop error logging but the call sites have since been commented out.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKSmtvlRnkiInfCst` | `JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop` (private method, defined in same class) | `db_KK_T_ADCHG_DTL.selectBySqlDefine [R] KK_T_ADCHG_DTL`<br>`getSysId [R] KK_T_SVC_KEI` |
| 2 | Batch: `JBSbatKKPlaceNoChgRnkiInfCst` | `getLogMsgKojiStop(inAdchgNo)` (commented out, line 238) | `db_KK_T_ADCHG_DTL.selectBySqlDefine [R] KK_T_ADCHG_DTL`<br>`getSysId [R] KK_T_SVC_KEI` |
| 3 | Batch: `JBSbatKKFmtcelSodUpdInfCst` | `getLogMsgKojiStop(inAdchgNo)` (commented out, line 208) | `db_KK_T_ADCHG_DTL.selectBySqlDefine [R] KK_T_ADCHG_DTL`<br>`getSysId [R] KK_T_SVC_KEI` |
| 4 | Batch: `JBSbatKKAdChgAddDataCst` | `getLogMsgKojiStop(inAdchgNo)` (commented out, line 320) | `db_KK_T_ADCHG_DTL.selectBySqlDefine [R] KK_T_ADCHG_DTL`<br>`getSysId [R] KK_T_SVC_KEI` |
| 5 | Batch: `JBSbatKKSodUpdInfCst` | `getLogMsgKojiStop(inAdchgNo)` (commented out, line 256) | `db_KK_T_ADCHG_DTL.selectBySqlDefine [R] KK_T_ADCHG_DTL`<br>`getSysId [R] KK_T_SVC_KEI` |

**Note:** All call sites referenced in other classes are commented out (`// msg += getLogMsgKojiStop(inAdchgNo);`), indicating the method was originally part of the work order stop error logging flow but those invocations have since been disabled. The method is currently invoked only within `JBSbatKKSmtvlRnkiInfCst` itself (internal call chain: the method definition itself).

## 6. Per-Branch Detail Blocks

### Block 1 — [INITIALIZATION] (L521)

> Initialize local variables to empty strings before building the log message.

| # | Type | Code |
|---|------|------|
| 1 | SET | `msgSvcKei = ""` // Message accumulator for service contract numbers |
| 2 | SET | `sysId = ""` // SYSID for the first identified service contract |

### Block 2 — [DB PARAMETER SETUP] (L523–L528)

> Prepare the database query parameters and execute the address change detail selection.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` // Create parameter object [L523] |
| 2 | EXEC | `paramList.setValue(adchgNo)` // Set address change number as query parameter [L524] |
| 3 | EXEC | `paramList.setValue(ADCHG_DTL_SBT_CD_SVC_KEI_NO)` // Set detail type code → `[-> ADCHG_DTL_SBT_CD_SVC_KEI_NO="01"]` [L525] |
| 4 | CALL | `db_KK_T_ADCHG_DTL.selectBySqlDefine(paramList, KK_T_ADCHG_DTL_KK_SELECT_003)` // Execute select query → `[-> KK_SELECT_003]` [L526] |

### Block 3 — [WHILE LOOP] (L527–L560)

> Iterate over all address change detail records matching the query. Loop exits when `selectNext()` returns null.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `adchgDtl = db_KK_T_ADCHG_DTL.selectNext()` // Fetch next detail record [L528] |
| 2 | IF | `adchgDtl == null` → break out of loop [L529] |

#### Block 3.1 — [IF: Record is null → Exit loop] (L529)

| # | Type | Code |
|---|------|------|
| 1 | RETURN/EXIT | `break` // End iteration, fall through to return [L530] |

#### Block 3.2 — [Extract Fields] (L532–L534)

> Extract service contract detail numbers before and after the address change.

| # | Type | Code |
|---|------|------|
| 1 | SET | `motoSvcKeiNo = adchgDtl.getString(JBSbatKK_T_ADCHG_DTL.CHBF_SKBT_NO)` // "Before" service contract detail number (住所変更前サービス契約詳細番号) [L532] |
| 2 | SET | `sakiSvcKeiNo = adchgDtl.getString(JBSbatKK_T_ADCHG_DTL.CHAF_SKBT_NO)` // "After" service contract detail number (住所変更後サービス契約詳細番号) [L533] |
| 3 | SET | `svcKeiNo = null` // Local variable for the determined service contract detail number [L534] |

#### Block 3.3 — [IF: Both fields are null] (L535)

> Skip records where neither before nor after service contract number is populated — these are not relevant to service contract operations.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `continue` // Skip to next record [L536] |

#### Block 3.4 — [IF-ELSE: Only one field is populated (Addition or Cancellation/Hold)] (L538–L547)

> When exactly one side has a service contract detail number, the address change represents either an addition of a new service contract or a cancellation/hold of an existing one.

| # | Type | Code |
|---|------|------|
| 1 | IF | `motoSvcKeiNo == null` (Addition - 追加) [L540] |
| 1.1 | SET | `svcKeiNo = sakiSvcKeiNo` // Use the "after" number [L541] |
| 1.2 | EXEC | `msgSvcKei += " サービス契約番号:" + svcKeiNo` // Append service contract number to message [L542] |
| 2 | ELSE | (Cancellation/Hold - 解約・保留) [L543] |
| 2.1 | SET | `svcKeiNo = motoSvcKeiNo` // Use the "before" number [L544] |
| 2.2 | EXEC | `msgSvcKei += " サービス契約番号:" + svcKeiNo` // Append service contract number to message [L545] |

#### Block 3.5 — [ELSE: Both fields populated (Transfer - 引越)] (L547–L557)

> When both before and after numbers exist, the address change represents a service contract transfer. Determine whether the contract number changed (substantive transfer) or stayed the same.

| # | Type | Code |
|---|------|------|
| 1 | IF | `motoSvcKeiNo.equals(sakiSvcKeiNo)` (Same number — regular transfer) [L550] |
| 1.1 | EXEC | `msgSvcKei += " サービス契約番号:" + motoSvcKeiNo` // Log as single service contract number [L551] |
| 2 | ELSE | (Different numbers — cancellation + new, 解約＋新規) [L553] |
| 2.1 | EXEC | `msgSvcKei += " サービス契約番号(転居元・先):" + motoSvcKeiNo + " / " + sakiSvcKeiNo` // Log both before and after numbers [L554] |
| 3 | SET | `svcKeiNo = motoSvcKeiNo` // Set for SYSID lookup [L557] |

#### Block 3.6 — [IF: SYSID not yet obtained] (L558–L560)

> Fetch the SYSID from the service contract table using the first valid `svcKeiNo`. Only done once — subsequent iterations skip because `sysId` will no longer be empty.

| # | Type | Code |
|---|------|------|
| 1 | IF | `"".equals(sysId)` [L558] |
| 1.1 | SET | `sysId = getSysId(svcKeiNo)` // Query KK_T_SVC_KEI to get SYSID [L559] |

### Block 4 — [RETURN] (L561)

> Construct and return the final log message string.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `" SYSID:" + sysId + msgSvcKei` // Format: " SYSID:{sysId} サービス契約番号:{no} ..." [L561] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `adchgNo` | Field | Address change number (住所変更番号) — unique identifier for an address change transaction |
| `adchgDtl` | Field | Address change detail object — holds individual rows of the address change detail table |
| `motoSvcKeiNo` | Field | "Before" service contract detail number (住所変更前サービス契約詳細番号) — the service contract detail number prior to the address change |
| `sakiSvcKeiNo` | Field | "After" service contract detail number (住所変更後サービス契約詳細番号) — the service contract detail number after the address change |
| `svcKeiNo` | Field | Service contract detail number (サービス契約詳細番号) — internal tracking ID for a service contract line item |
| `msgSvcKei` | Field | Accumulated message string containing service contract number information for logging |
| `sysId` | Field | System identifier (システムID) — unique system identifier for the service contract, used for cross-system correlation |
| `KK_T_ADCHG_DTL` | Entity | Address change detail table (住所変更明細テーブル) — stores detail rows for address change transactions including before/after service contract references |
| `KK_T_SVC_KEI` | Entity | Service contract table (サービス契約テーブル) — stores service contract master data including the SYSID |
| `ADCHG_DTL_SBT_CD_SVC_KEI_NO` | Constant | Address change detail type code for service contract number = "01" (住所変更明細種別コード（サービス契約番号）) |
| `KK_SELECT_003` | SQL Define | SQL query definition for selecting address change details by address change number and detail type code |
| `KK_SELECT_023` | SQL Define | SQL query definition for selecting service contract by service contract detail number (used internally by `getSysId`) |
| `CHBF_SKBT_NO` | Field | Address change before service contract detail number column (住所変更前サービス契約詳細番号カラム) |
| `CHAF_SKBT_NO` | Field | Address change after service contract detail number column (住所変更後サービス契約詳細番号カラム) |
| SYSID | Business term | System ID — a unique identifier assigned to a service contract for system-level tracking and cross-module correlation |
| 工事中止 (Koji-chuushi) | Business term | Work order stop / construction work cancellation — a state where a new construction work order is halted |
| 追加 (Tsuika) | Business term | Addition — a service contract line item being newly added during an address change |
| 解約 (Kaikyo) | Business term | Cancellation — a service contract line item being cancelled during an address change |
| 保留 (Hoyuu) | Business term | Hold — a service contract line item being placed on hold during an address change |
| 引越 (Hikoshi) | Business term | Transfer — a service contract line item being transferred from one address/contract to another during an address change |
| 転居元・先 (Tenkyamoto/Saki) | Business term | Transfer origin and destination — the "before" and "after" service contract numbers shown when a substantive transfer occurs (different numbers) |
| `JBSbatCommonDBInterface` | Class | Common database interface — parameter container for SQL query inputs and result extraction |
| `JBSbatSQLAccess` | Class | SQL access utility — database access object wrapping SQL execution for specific tables |
| JBSbatKKSmtvlRnkiInfCst | Class | Batch processing service component for service contract notification information (サービス契約通知情報) |

---
