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

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

## 1. Role

### JBSbatKKSodUpdInfCst.getLogMsgKojiStop()

This method generates a formatted log message containing the **SYSID** (system identifier) and the associated **service contract numbers** (サービス契約番号) for an address change (住所変更) operation. It operates during a "Koji" (工事 — construction/maintenance work) stop or cancellation workflow, producing a human-readable summary string for audit logging purposes.

The method performs a **Read-only** query against the `KK_T_ADCHG_DTL` (address change detail table) to retrieve all service contract lines (sub-type "01" — サービス契約) associated with the given address change number. For each row, it applies business rules to determine which contract number is relevant based on the **moto** (元 — original/transfer-from) and **saki** (先 — destination/transfer-to) service contract line internal numbers.

It implements a **filter-and-collect pattern**: rows where both moto and saki are null are skipped (irrelevant data); rows where only one is null indicate an Addition (追加) or Cancellation/Hold (解約・保留); rows where both exist indicate either a Reuse (再利用 — same number on both sides) or a Transfer scenario (転居 — move, where cancellation of the old and new registration occur simultaneously).

When the SYSID cannot be determined from other means, the method delegates to `getSysId()` to query the `KK_T_SVC_KEI` (service contract table) and retrieve the SYSID for the resolved contract number. The final message is returned as a single formatted string in the format ` SYSID:{sysId} サービス契約番号:{svcKeiNo}` or ` SYSID:{sysId} サービス契約番号(転居元・先):{moto} / {saki}`.

The method is declared `private` and is currently **commented out** in all known caller locations across the codebase (JBSbatKKPlaceNoChgRnkiInfCst, JBSbatKKFmtcelSodUpdInfCst, JBSbatKKAdChgAddDataCst, JBSbatKKSodUpdInfCst, JBSbatKKSmtvlRnkiInfCst), suggesting it is reserved utility code for future Koji stop logging use cases.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["getLogMsgKojiStop adchgNo"])
    INIT["Initialize msgSvcKei, sysId to empty strings"]
    PARAM["Create paramList with adchgNo and ADCHG_DTL_SBT_CD_SVC_KEI_NO"]
    SELECT["Query KK_T_ADCHG_DTL selectBySqlDefine KK_SELECT_003"]
    NEXT["Get next row adchgDtl"]
    NULL_CHECK{"adchgDtl == null?"}
    FETCH["Fetch motoSvcKeiNo and sakiSvcKeiNo"]
    BOTH_NULL{"Both null?"}
    CONTINUE["Skip row continue"]
    ONE_NULL{"Only one null?"}
    MOTO_NULL{"motoSvcKeiNo == null?"}
    ADDITION["sakiSvcKeiNo service contract number
Addition"]
    CANCEL["motoSvcKeiNo service contract number
Cancellation Hold"]
    MSG_ADD["msgSvcKei += service contract number"]
    MSG_CANCEL["msgSvcKei += service contract number"]
    BOTH_EXIST{"Both exist?"}
    EQUAL{"motoSvcKeiNo equals sakiSvcKeiNo?"}
    REUSE["msgSvcKei += service contract number
Reuse"]
    TRANSFER["msgSvcKei += transfer origin destination
New after transfer"]
    GET_SYSID{"sysId is empty?"}
    GETSYSID_CALL["getSysId svcKeiNo
Queries KK_T_SVC_KEI"]
    RETURN["Return SYSID and msgSvcKei"]

    START --> INIT
    INIT --> PARAM
    PARAM --> SELECT
    SELECT --> LOOP_CHECK{While loop}
    LOOP_CHECK --> NEXT
    NEXT --> NULL_CHECK
    NULL_CHECK -- "Yes" --> RETURN
    NULL_CHECK -- "No" --> FETCH
    FETCH --> BOTH_NULL
    BOTH_NULL -- "Yes" --> CONTINUE
    CONTINUE --> LOOP_CHECK
    BOTH_NULL -- "No" --> ONE_NULL
    ONE_NULL -- "Yes" --> MOTO_NULL
    ONE_NULL -- "No" --> BOTH_EXIST
    MOTO_NULL -- "Yes" --> ADDITION
    MOTO_NULL -- "No" --> CANCEL
    ADDITION --> MSG_ADD
    CANCEL --> MSG_CANCEL
    MSG_ADD --> LOOP_CHECK
    MSG_CANCEL --> LOOP_CHECK
    BOTH_EXIST -- "Yes" --> EQUAL
    EQUAL -- "Yes" --> REUSE
    EQUAL -- "No" --> TRANSFER
    REUSE --> GET_SYSID
    TRANSFER --> GET_SYSID
    GET_SYSID -- "Yes" --> GETSYSID_CALL
    GETSYSID_CALL --> LOOP_CHECK
    GET_SYSID -- "No" --> LOOP_CHECK
```

**CRITICAL — Constant Resolution:**
- `ADCHG_DTL_SBT_CD_SVC_KEI_NO = "01"` — Address Change Detail Sub-type Code for Service Contract (サービス契約). Used to filter the address change detail table to only service contract lines.
- `KK_T_ADCHG_DTL_KK_SELECT_003 = "KK_SELECT_003"` — SQL Definition Key for querying the KK_T_ADCHG_DTL table with adchgNo and sub-type filters.
- `JBSbatKK_T_ADCHG_DTL.CHBF_SKBT_NO` — Source field constant (CHBF = 元番号) for the original (transfer-from) service contract line internal number.
- `JBSbatKK_T_ADCHG_DTL.CHAF_SKBT_NO` — Destination field constant (CHAF = 先番号) for the destination (transfer-to) service contract line internal number.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `adchgNo` | `String` | Address change number (住所変更番号) — the unique identifier for an address change record. Used as the primary filter key when querying the `KK_T_ADCHG_DTL` table to retrieve all service contract lines associated with this specific address change. |

**Instance fields / external state read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `db_KK_T_ADCHG_DTL` | `JBSbatSQLAccess` | Database access object for the `KK_T_ADCHG_DTL` (address change detail) table. Used to execute the `KK_SELECT_003` SQL query. |
| `db_KK_T_SVC_KEI` | `JBSbatSQLAccess` | Database access object for the `KK_T_SVC_KEI` (service contract) table. Used by the internal `getSysId()` call to fetch the SYSID. |
| `KK_T_SVC_KEI_KK_SELECT_023` | `String` (constant) | SQL definition key for querying KK_T_SVC_KEI to retrieve the SYSID by service contract line internal number. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `db_KK_T_ADCHG_DTL.selectBySqlDefine` | - | `KK_T_ADCHG_DTL` | Reads address change detail rows filtered by adchgNo and sub-type code "01" (service contract) via SQL definition `KK_SELECT_003`. |
| R | `db_KK_T_ADCHG_DTL.selectNext` | - | `KK_T_ADCHG_DTL` | Fetches the next row from the address change detail result set within the iteration loop. |
| R | `JBSbatCommonDBInterface.getString` | - | - | Extracts field values (moto/saki service contract line internal numbers) from the returned data row. |
| R | `JBSbatKKSodUpdInfCst.getSysId` | - | `KK_T_SVC_KEI` | Delegates to retrieve the SYSID from the service contract table for the resolved contract number. |
| R | `db_KK_T_SVC_KEI.selectBySqlDefine` | - | `KK_T_SVC_KEI` | Queries the service contract table using SYSID lookup SQL definition `KK_SELECT_023` with service contract line number and operation date. |
| R | `db_KK_T_SVC_KEI.selectNext` | - | `KK_T_SVC_KEI` | Fetches the service contract row containing the SYSID. |
| R | `JBSbatCommonDBInterface.getString` | - | - | Extracts the SYSID value from the service contract row. |

**CRUD Summary:**
- **Read (R)**: 2 database tables — `KK_T_ADCHG_DTL` (address change details) and `KK_T_SVC_KEI` (service contracts)
- **Create (C)**: 0
- **Update (U)**: 0
- **Delete (D)**: 0

This method is **purely read-only**. It queries the address change detail table to collect service contract information and, if needed, queries the service contract table for the SYSID. No data is written, created, updated, or deleted.

## 5. Dependency Trace

The `getLogMsgKojiStop` method is currently **not actively called** — all callers in the codebase have this call commented out. The method is defined identically across 5 similar constant/batch service classes:

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKPlaceNoChgRnkiInfCst | `JBSbatKKPlaceNoChgRnkiInfCst.getLogMsgKojiStop` (commented out) | `KK_T_ADCHG_DTL [R]`, `KK_T_SVC_KEI [R]` |
| 2 | Batch: JBSbatKKFmtcelSodUpdInfCst | `JBSbatKKFmtcelSodUpdInfCst.getLogMsgKojiStop` (commented out) | `KK_T_ADCHG_DTL [R]`, `KK_T_SVC_KEI [R]` |
| 3 | Batch: JBSbatKKAdChgAddDataCst | `JBSbatKKAdChgAddDataCst.getLogMsgKojiStop` (commented out) | `KK_T_ADCHG_DTL [R]`, `KK_T_SVC_KEI [R]` |
| 4 | Batch: JBSbatKKSodUpdInfCst | `JBSbatKKSodUpdInfCst.getLogMsgKojiStop` (commented out) | `KK_T_ADCHG_DTL [R]`, `KK_T_SVC_KEI [R]` |
| 5 | Batch: JBSbatKKSmtvlRnkiInfCst | `JBSbatKKSmtvlRnkiInfCst.getLogMsgKojiStop` (commented out) | `KK_T_ADCHG_DTL [R]`, `KK_T_SVC_KEI [R]` |

**Note:** All callers have the method invocation commented out (`// msg += getLogMsgKojiStop(inAdchgNo);`), indicating this is reserved utility code for future Koji stop logging functionality across multiple address change processing batch services. The method itself is `private`, so it is not accessible from outside its defining class.

## 6. Per-Branch Detail Blocks

**Block 1** — INIT (Initialization) (L1062)

> Initializes the local variables for the log message and SYSID. Both start as empty strings.

| # | Type | Code |
|---|------|------|
| 1 | SET | `msgSvcKei = ""` // Log message accumulator for service contract numbers |
| 2 | SET | `sysId = ""` // SYSID placeholder, resolved later if needed |

**Block 2** — PARAM (Parameter Setup) (L1067)

> Creates and populates the database query parameter object with the address change number and the service contract sub-type filter code.

| # | Type | Code |
|---|------|------|
| 1 | SET | `paramList = new JBSbatCommonDBInterface()` |
| 2 | EXEC | `paramList.setValue(adchgNo)` |
| 3 | EXEC | `paramList.setValue(ADCHG_DTL_SBT_CD_SVC_KEI_NO)` [-> `ADCHG_DTL_SBT_CD_SVC_KEI_NO = "01"`] |
| 4 | CALL | `db_KK_T_ADCHG_DTL.selectBySqlDefine(paramList, KK_T_ADCHG_DTL_KK_SELECT_003)` [queries KK_T_ADCHG_DTL] |

**Block 3** — LOOP (While Loop) (L1069)

> Iterates through all address change detail rows returned by the query. Processes each row to extract and format service contract information.

| # | Type | Code |
|---|------|------|
| 1 | SET | `adchgDtl = db_KK_T_ADCHG_DTL.selectNext()` |
| 2 | IF | See Block 3.1 — null check |
| 3 | IF | See Block 3.2 — both null check |
| 4 | IF | See Block 3.3 — one null check |
| 5 | IF | See Block 3.4 — both exist, equal vs. transfer |
| 6 | IF | See Block 3.5 — SYSID lazy resolution |

**Block 3.1** — IF (Null Row Check) (L1072)

> Checks if the current row is null, indicating end of result set. Breaks out of the loop.

| # | Type | Code |
|---|------|------|
| 1 | IF | `adchgDtl == null` |
| 2 | EXEC | `break` // Exit the while loop |

**Block 3.2** — IF (Both Null Skip) (L1078)

> When both the source and destination service contract line numbers are null, the row is irrelevant and skipped. This filters out non-service-contract data entries.

| # | Type | Code |
|---|------|------|
| 1 | IF | `motoSvcKeiNo == null && sakiSvcKeiNo == null` |
| 2 | EXEC | `continue` // Skip to next row |

**Block 3.3** — IF (One Null — Addition or Cancellation/Hold) (L1081)

> Exactly one of moto or saki is null, meaning a single-direction operation (addition or cancellation/hold).

| # | Type | Code |
|---|------|------|
| 1 | IF | `motoSvcKeiNo == null \|\| sakiSvcKeiNo == null` |
| 2 | IF | See Block 3.3.1 — which one is null |

**Block 3.3.1** — IF (Moto Null = Addition) (L1083)

> Original (moto) is null, destination (saki) is set — this is an **Addition (追加)** operation. The new service contract number comes from saki.

| # | Type | Code |
|---|------|------|
| 1 | IF | `motoSvcKeiNo == null` |
| 2 | SET | `svcKeiNo = sakiSvcKeiNo` |
| 3 | SET | `msgSvcKei += " サービス契約番号:" + svcKeiNo` [-> `サービス契約番号` = Service Contract Number] |

**Block 3.3.2** — ELSE-IF (Saki Null = Cancellation/Hold) (L1085)

> Destination (saki) is null, original (moto) is set — this is a **Cancellation/Hold (解約・保留)** operation. The service contract number comes from moto.

| # | Type | Code |
|---|------|------|
| 1 | ELSE-IF | `motoSvcKeiNo != null && sakiSvcKeiNo == null` (implied) |
| 2 | SET | `svcKeiNo = motoSvcKeiNo` |
| 3 | SET | `msgSvcKei += " サービス契約番号:" + svcKeiNo` [-> `サービス契約番号` = Service Contract Number] |

**Block 3.4** — IF (Both Exist — Reuse or Transfer) (L1089)

> Both source and destination have values. This indicates a transfer (転居) scenario. If both numbers are the same, it is a **Reuse (再利用)** — the contract is being carried over to the new address. If different, it is a **Cancellation + New (解約＋新規)** — old contract cancelled, new one created.

| # | Type | Code |
|---|------|------|
| 1 | ELSE | `// Both moto and saki are non-null` |
| 2 | IF | See Block 3.4.1 — numbers equal vs. different |

**Block 3.4.1** — IF (Numbers Equal = Reuse) (L1091)

> The original and destination service contract numbers are identical. This is a **Reuse (再利用)** — the same contract is being maintained at a new address.

| # | Type | Code |
|---|------|------|
| 1 | IF | `motoSvcKeiNo.equals(sakiSvcKeiNo)` |
| 2 | SET | `msgSvcKei += " サービス契約番号:" + motoSvcKeiNo` [-> `サービス契約番号` = Service Contract Number] |

**Block 3.4.2** — ELSE (Numbers Different = Transfer/New) (L1094)

> The original and destination service contract numbers differ. This is a **Transfer with New Registration (転居：解約＋新規)** — the old contract is cancelled and a new one is created. The message shows both numbers.

| # | Type | Code |
|---|------|------|
| 1 | ELSE | `// Transfer: cancellation + new registration` |
| 2 | SET | `msgSvcKei += " サービス契約番号(転居元・先):" + motoSvcKeiNo + " / " + sakiSvcKeiNo` [-> `転居元・先` = Transfer origin & destination] |
| 3 | SET | `svcKeiNo = motoSvcKeiNo` // Use original number for SYSID lookup |

**Block 3.5** — IF (SYSID Lazy Resolution) (L1098)

> Only resolves the SYSID once (the first time `svcKeiNo` is available). Subsequent rows reuse the already-fetched SYSID. The `getSysId()` method queries `KK_T_SVC_KEI` to look up the SYSID.

| # | Type | Code |
|---|------|------|
| 1 | IF | `"".equals(sysId)` |
| 2 | SET | `sysId = getSysId(svcKeiNo)` [calls `db_KK_T_SVC_KEI.selectBySqlDefine` with `KK_SELECT_023`] |

**Block 4** — RETURN (L1101)

> Returns the formatted log message containing the SYSID (if resolved) and all collected service contract number strings.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return " SYSID:" + sysId + msgSvcKei` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `adchgNo` | Field | Address change number (住所変更番号) — unique identifier for an address change operation in the system |
| `moto` (元) | Field | Original/transfer-from — the source service contract line internal number before an address transfer |
| `saki` (先) | Field | Destination/transfer-to — the target service contract line internal number after an address transfer |
| `svcKeiNo` (サービス契約番号) | Field | Service contract number (サービス契約番号) — the internal identifier for a service contract line item |
| `CHBF_SKBT_NO` | Field | Contract Before Service Business Type Number (契約前サービス業務種別番号) — source service contract line internal number in the address change detail table |
| `CHAF_SKBT_NO` | Field | Contract After Service Business Type Number (契約後サービス業務種別番号) — destination service contract line internal number in the address change detail table |
| `ADCHG_DTL_SBT_CD_SVC_KEI_NO` | Constant | Address Change Detail Sub-type Code for Service Contract = "01" — filters detail rows to service contract lines only |
| SYSID | Field | System identifier (システムID) — unique system-level identifier for a service contract, stored in KK_T_SVC_KEI |
| KK_T_ADCHG_DTL | Table | Address Change Detail table (住所変更明細) — stores line-level details of address change operations |
| KK_T_SVC_KEI | Table | Service Contract table (サービス契約) — stores service contract header information including SYSID |
| Koji (工事) | Business term | Construction/Maintenance work — refers to field installation or maintenance work for telecom services |
| Addition (追加) | Business term | New service contract line added during an address change — original number is null, destination is set |
| Cancellation (解約) | Business term | Service contract line cancelled or held during an address change — destination number is null, original is set |
| Hold (保留) | Business term | Service contract line placed on hold (temporarily suspended) during an address change |
| Transfer (転居) | Business term | Address transfer — customer moves from one address to another, potentially with new or existing service contracts |
| Reuse (再利用) | Business term | Same contract number on both source and destination — the existing contract is maintained at the new address |
| KK_SELECT_003 | Constant | SQL definition key for querying KK_T_ADCHG_DTL by address change number and sub-type code |
| KK_SELECT_023 | Constant | SQL definition key for querying KK_T_SVC_KEI to retrieve SYSID by service contract line number |
| JBSbatKKSodUpdInfCst | Class | Service Order Update Information Constant — batch service class handling service order update information extraction and processing |
| JBSbatCommonDBInterface | Class | Common database interface — parameter/result object for SQL queries, used to pass parameters and retrieve field values |
| JBSbatSQLAccess | Class | SQL access object — database access layer wrapper for executing SQL queries against specific tables |
