# Business Logic — JBSbatKKCourseChgeTstaDayChsht.alartKojiTeisei() [67 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKCourseChgeTstaDayChsht` |
| Layer | Batch (package: `eo.business.service`, source: `koptBatch`) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKCourseChgeTstaDayChsht.alartKojiTeisei()

This method performs **work order correction alert logging** — it detects a discrepancy between a transfer reservation's effective application start date (`rsvAplyYmd`) and the actual work completion implementation date (`KOJIAK_JSSI_YMD`) stored in the work completion work information table (`KK_T_KJ_FIN_WK`). When the two dates do not match, it logs a business error with code `EKKB0010CW` and increments an error count, signaling that the application start date was changed in a way that is not synchronized with the physical work completion date. The method implements a **gateway/routing design pattern**: it resolves a work case number (`KOJIAK_NO`) through two possible lookup paths (direct parameter or database query via `selectMskmDtlKojiAk`), validates that all required keys are present, queries the work completion work table, and conditionally emits an alert. It serves as a **data integrity guardrail** within the batch processing pipeline for daily course change transfer status (`KKCourseChgeTstaDayChsht`), ensuring that date anomalies arising from service contract corrections or address changes are surfaced for downstream investigation. The method is **private**, called exclusively by the batch's `execute()` method, making it an internal validation step rather than a shared utility.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["alartKojiTeisei(svcKeiNo, idoRsvNo, mskmDtlNo, rsvAplyYmd, idoRsvKojiakNo)"])

    START --> INIT["Initialize tempKojiakNo and tempKojiakJssiYmd"]

    INIT --> COND1{idoRsvKojiakNo<br/>is not empty}

    COND1 -->|"Yes"| ASSIGN1["tempKojiakNo = idoRsvKojiakNo"]

    ASSIGN1 --> COND3{svcKeiNo or<br/>tempKojiakNo is empty}

    COND1 -->|"No"| COND2{mskmDtlNo<br/>is empty}

    COND2 -->|"Yes"| EARLY_RETURN_1["Return - no key item"]
    COND2 -->|"No"| SELECT_KOJIAK["selectMskmDtlKojiAk(mskmDtlNo)"]

    SELECT_KOJIAK --> COND3

    COND3 -->|"Yes"| EARLY_RETURN_2["Return - no svc/kojiake"]
    COND3 -->|"No"| SET_PARAM["whereKjFinParam = svcKeiNo, tempKojiakNo"]

    SET_PARAM --> EXEC_SQL["executeKK_T_KJ_FIN_WK_KK_SELECT_007"]

    EXEC_SQL --> SELECT_NEXT["db_KK_T_KJ_FIN_WK.selectNext"]

    SELECT_NEXT --> COND4{kktKjFinWkMap_007<br/>is null}

    COND4 -->|"Yes"| EARLY_RETURN_3["Return - no result"]
    COND4 -->|"No"| GET_JSSI_YMD["Get KOJIAK_JSSI_YMD from result"]

    GET_JSSI_YMD --> COND5{rsvAplyYmd !=<br/>tempKojiakJssiYmd}

    COND5 -->|"No"| END_MATCH["Return - dates match, no alert"]

    COND5 -->|"Yes"| BUILD_MSG["Build alert message with all IDs"]

    BUILD_MSG --> LOG_ERROR["printBusinessErrorLog(EKKB0010CW, mesInfo)"]

    LOG_ERROR --> INC_ERROR["commonItem.addErrorCount(1)"]

    INC_ERROR --> END_MATCH
```

### Branch Summary

| Branch | Condition | Business Meaning |
|--------|-----------|-----------------|
| A | `idoRsvKojiakNo` is not empty | The work case number is directly available from the transfer reservation parameter — use it as-is |
| B | `idoRsvKojiakNo` is empty, `mskmDtlNo` is empty | No key item (order detail number) to look up from — bail out early |
| C | `idoRsvKojiakNo` is empty, `mskmDtlNo` is populated | Query the order detail work case information table to retrieve the work case number |
| D | `svcKeiNo` or resolved `tempKojiakNo` is empty | Missing required key data — bail out |
| E | No result from work completion query | No work completion record exists — bail out |
| F | `rsvAplyYmd` equals `tempKojiakJssiYmd` | Dates match — no discrepancy, no alert needed |
| G | `rsvAplyYmd` does not equal `tempKojiakJssiYmd` | **Discrepancy detected** — log alert and increment error count |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `svcKeiNo` | `String` | Service Contract Number — the unique identifier for a service contract line. Serves as a key field in querying the work completion work table (`KK_T_KJ_FIN_WK`). Must not be empty for alert processing to proceed. |
| 2 | `idoRsvNo` | `String` | Transfer Reservation Number — the unique identifier for a transfer (relocation) reservation record. Used exclusively in the alert message text to correlate the logged error with a specific reservation. |
| 3 | `mskmDtlNo` | `String` | Order Detail Number — the unique identifier for an order detail (application detail) record. Used as a lookup key to retrieve the associated work case number when `idoRsvKojiakNo` is not directly available. |
| 4 | `rsvAplyYmd` | `String` | Reservation Application Start Date — the date (YYYYMMDD format) when the transfer reservation's service becomes effective. This is the expected application start date that gets compared against the actual work completion date. |
| 5 | `idoRsvKojiakNo` | `String` | Work Case Number (Transfer Reservation) — the work case identifier directly associated with the transfer reservation. If present, it bypasses the database lookup and is used directly as the work case number. |

### Instance Fields / External State

| Field | Type | Access Pattern | Description |
|-------|------|----------------|-------------|
| `db_KK_T_KJ_FIN_WK` | `JBSbatCommonDBInterface` | WRITE (query target) | Database interface for the work completion work table (`KK_T_KJ_FIN_WK`). Used to execute and retrieve query results. |
| `super.logPrint` | inherits from parent | READ (method call target) | Logging utility (inherited from parent class). Delegates to `JKKBatOneTimeLogWriter.printBusinessErrorLog` to write the alert. |
| `commonItem` | inherits from parent | READ (method call target) | Common batch processing item context. Provides `addErrorCount(1)` to increment the batch error counter. |
| `isEmpty(...)` | inherited utility | READ (method call) | Utility method to check if a String is null, empty, or blank. Used for guarding against null parameter values. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `selectMskmDtlKojiAk` | (internal) | `KK_T_MSKM_DTLC` (order detail table) | Reads the work case number from the order detail (application detail) record using the order detail number as key. |
| R | `executeKK_T_KJ_FIN_WK_KK_SELECT_007` | (internal) | `KK_T_KJ_FIN_WK` (work completion work table) | Executes a SQL query (`KK_SELECT_007`) to retrieve work completion work information filtered by service contract number and work case number. |
| R | `db_KK_T_KJ_FIN_WK.selectNext` | (internal) | `KK_T_KJ_FIN_WK` (work completion work table) | Fetches the next row from the previously executed query result set. Returns the single-row work completion record. |
| R | `JBSbatCommonDBInterface.getString` | (internal) | in-memory (result row) | Retrieves the `KOJIAK_JSSI_YMD` (work case implementation date) string value from the query result map. |
| - | `JBSbatStringUtil.Rtrim` | (internal) | - | Trims trailing whitespace from the implementation date string. |
| - | `JKKBatOneTimeLogWriter.printBusinessErrorLog` | (inherited) | - | Logs a business-level error with error code `EKKB0010CW` and the composed alert message. |
| - | `commonItem.addErrorCount` | (inherited) | - | Increments the batch processing error counter by 1. |

### Detailed CRUD Classification

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `selectMskmDtlKojiAk(String)` | (internal CBS) | `KK_T_MSKM_DTLC` (Order Detail Table) | Reads the work case number (`KOJIAK_NO`) from the order detail record matching the given order detail number (`mskmDtlNo`). Returns the work case number as a String. |
| R | `executeKK_T_KJ_FIN_WK_KK_SELECT_007(String[])` | (internal CBS) | `KK_T_KJ_FIN_WK` (Work Completion Work Table) | Executes SQL query `KK_SELECT_007` against the work completion work table, filtering by service contract number (`svcKeiNo`) and work case number (`tempKojiakNo`) in the WHERE clause. Sets up the result set for subsequent `selectNext()` retrieval. |
| R | `db_KK_T_KJ_FIN_WK.selectNext()` | (internal CBS) | `KK_T_KJ_FIN_WK` (Work Completion Work Table) | Retrieves the next row from the query result set established by `executeKK_T_KJ_FIN_WK_KK_SELECT_007`. Returns a `JBSbatCommonDBInterface` containing column values for the matched work completion record. |
| R | `JBSbatCommonDBInterface.getString(String)` | (internal) | in-memory (result row) | Extracts the `KOJIAK_JSSI_YMD` (Work Case Implementation Date) field value from the current result row. Returns a String representing the date in YYYYMMDD format. |
| - | `JBSbatStringUtil.Rtrim(String)` | (internal) | - | Trims trailing whitespace from the implementation date string. Utility-only, no side effects. |
| - | `JKKBatOneTimeLogWriter.printBusinessErrorLog(String, String[])` | (inherited CBS) | - | Writes a business error log entry with error code `EKKB0010CW` and the composed alert message. This is a terminal logging operation. |
| - | `commonItem.addErrorCount(int)` | (inherited CBS) | - | Increments the batch job's error count tracker. Used for monitoring and post-processing aggregation. |

## 5. Dependency Trace

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKCourseChgeTstaDayChsht` | `JBSbatKKCourseChgeTstaDayChsht.execute()` → `alartKojiTeisei(svcKeiNo, idoRsvNo, mskmDtlNo, rsvAplyYmd, idoRsvKojiakNo)` | `printBusinessErrorLog` [-], `addErrorCount` [-], `selectMskmDtlKojiAk` [R] `KK_T_MSKM_DTLC`, `executeKK_T_KJ_FIN_WK_KK_SELECT_007` [R] `KK_T_KJ_FIN_WK`, `selectNext` [R] `KK_T_KJ_FIN_WK`, `getString` [R] `KOJIAK_JSSI_YMD` |

### Call Chain Details

- **Caller**: `JBSbatKKCourseChgeTstaDayChsht.execute()` — the main batch execution entry point for daily course change transfer status processing.
- **Call**: `alartKojiTeisei()` is invoked as a private validation step within `execute()`, passing the service contract number, transfer reservation number, order detail number, reservation application date, and work case number (transfer reservation).
- **Termination**: The method terminates via either an early return (no discrepancy or missing data) or by logging a business error alert (discrepancy detected).

## 6. Per-Branch Detail Blocks

**Block 1** — [Variable Declaration] (L2172)

> Initialize temporary variables for work case number and work case implementation date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `tempKojiakNo = ""` // Work case number (empty default) |
| 2 | SET | `tempKojiakJssiYmd = ""` // Work case implementation date (empty default) |

---

**Block 2** — [IF] `(idoRsvKojiakNo is not empty)` (L2176)

> Primary path: the work case number is directly provided as a parameter. Use it without database lookup.

| # | Type | Code |
|---|------|------|
| 1 | SET | `tempKojiakNo = idoRsvKojiakNo` // Assign directly from transfer reservation parameter |

---

**Block 3** — [ELSE] `(idoRsvKojiakNo is empty)` (L2183)

> Fallback path: the work case number is not directly available. Attempt to resolve it from the order detail table.

**Block 3.1** — [IF - nested] `(mskmDtlNo is empty)` (L2187)

> No order detail number is available to perform the lookup. Bail out early — there is no key item to resolve.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // Exit — no key item (order detail number) to look up work case from |

**Block 3.2** — [ELSE - nested, implicit] `(mskmDtlNo is not empty)` (L2193)

> The order detail number is available. Query the order detail work case information to retrieve the work case number.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `tempKojiakNo = selectMskmDtlKojiAk(mskmDtlNo)` // Query order detail table for work case number |

---

**Block 4** — [IF] `(svcKeiNo is empty OR tempKojiakNo is empty)` (L2198)

> Validate that both the service contract number and the resolved work case number are present. If either is missing, the method cannot proceed with work completion query.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // Exit — missing required key data (service contract number or work case number) |

---

**Block 5** — [Variable Declaration + Parameter Setup] (L2204-L2206)

> Prepare the WHERE clause parameter array for the work completion query.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kktKjFinWkMap_007 = null` // SQL execution result map (work completion work info retrieval) |
| 2 | SET | `whereKjFinParam = new String[]{svcKeiNo, tempKojiakNo}` // [0]=service contract number, [1]=work case number |

---

**Block 6** — [Method Call] (L2209)

> Execute the work completion work query.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_KJ_FIN_WK_KK_SELECT_007(whereKjFinParam)` // SQL execution against KK_T_KJ_FIN_WK |

---

**Block 7** — [Method Call] (L2212)

> Retrieve the next (and expected only) row from the query result set.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `kktKjFinWkMap_007 = db_KK_T_KJ_FIN_WK.selectNext()` // Fetch next row from work completion query result |

---

**Block 8** — [IF] `(kktKjFinWkMap_007 == null)` (L2215)

> No work completion record was found matching the service contract number and work case number.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // Exit — no work completion result found |

---

**Block 9** — [Assignment] (L2219-L2220)

> Extract the work case implementation date from the query result.

| # | Type | Code |
|---|------|------|
| 1 | SET | `tempKojiakJssiYmd = JBSbatStringUtil.Rtrim(kktKjFinWkMap_007.getString(JBSbatKK_T_KJ_FIN_WK.KOJIAK_JSSI_YMD))` // KOJIAK_JSSI_YMD = "KOJIAK_JSSI_YMD" (Work Case Implementation Date) |

---

**Block 10** — [IF] `(!rsvAplyYmd.equals(tempKojiakJssiYmd))` (L2225)

> **Core alert logic**: The reservation application date does not match the work case implementation date. This indicates that the application start date was changed (possibly due to a service contract correction or address change) but the physical work completion date was not synchronized.

| # | Type | Code |
|---|------|------|
| 1 | SET | `mesInfo = "適用開始日の変更が連携されました。(" + svcKeiNo + " " + idoRsvNo + " " + rsvAplyYmd + " " + tempKojiakNo + " " + tempKojiakJssiYmd + ")"` // Alert message: "The application start date has been synchronized. (Service Contract No: X, Transfer Reservation No: Y, Application Date: Z, Work Case No: A, Work Case Implementation Date: B)" |
| 2 | CALL | `super.logPrint.printBusinessErrorLog("EKKB0010CW", new String[]{mesInfo})` // Log business error with code EKKB0010CW |
| 3 | CALL | `commonItem.addErrorCount(1)` // Increment batch error count by 1 |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svcKeiNo` | Field | Service Contract Number — unique identifier for a service contract line item in the telecom order fulfillment system. |
| `idoRsvNo` | Field | Transfer Reservation Number — unique identifier for a reservation to transfer (relocate) a service, typically triggered by address change. |
| `mskmDtlNo` | Field | Order Detail Number — unique identifier for an order detail (application detail) record that links to work case information. |
| `rsvAplyYmd` | Field | Reservation Application Start Date — the date (YYYYMMDD) when the transferred service is expected to become effective. `Ymd` = Year/Month/Day in Japanese naming convention. |
| `idoRsvKojiakNo` | Field | Work Case Number (Transfer Reservation) — the work case identifier directly associated with the transfer reservation. `Kojiak` = 工事案件 (work case/project). |
| `tempKojiakNo` | Field | Temporary Work Case Number — internal working variable holding the resolved work case number (either from parameter or database lookup). |
| `tempKojiakJssiYmd` | Field | Temporary Work Case Implementation Date — internal working variable holding the actual work completion date from the work completion work table. `Jssi` = 実施 (implementation). |
| `KOJIAK_JSSI_YMD` | Field | Work Case Implementation Date — the column name constant in `KK_T_KJ_FIN_WK` table storing the actual date when the work was physically implemented. |
| `KK_T_KJ_FIN_WK` | Table | Work Completion Work Table — stores records of completed work operations, including service contract numbers, work case numbers, and implementation dates. `KJ` = 工事 (work), `FIN` = Finished, `WK` = Work table. |
| `KK_T_MSKM_DTLC` | Table | Order Detail (Case File) Table — stores order detail records including associated work case numbers. Used to resolve work case numbers when not directly provided. |
| `EKKB0010CW` | SC Code | Business error code — the error code emitted when a work correction date discrepancy is detected. `EKKB` = Error Knowledge KB (batch error domain). |
| `executeKK_T_KJ_FIN_WK_KK_SELECT_007` | Method | SQL execution method — executes query `KK_SELECT_007` against the work completion work table with service contract number and work case number as filter criteria. |
| `selectMskmDtlKojiAk` | Method | Order detail work case lookup — queries the order detail table to retrieve the work case number associated with a given order detail number. |
| `printBusinessErrorLog` | Method | Business error logging — writes a structured error log entry with an error code and message payload. |
| `addErrorCount` | Method | Error count increment — increases the batch job's error counter for monitoring and aggregation purposes. |
| `JBSbatStringUtil.Rtrim` | Utility | Right-trim utility — removes trailing whitespace from a string value. |
| `db_KK_T_KJ_FIN_WK` | Field | Database interface for `KK_T_KJ_FIN_WK` — managed by the batch framework, used to execute and iterate query results. |
| `commonItem` | Field | Common batch processing context — inherited field providing shared batch utilities including error counting. |
| `alartKojiTeisei` | Method | Alert Work Correction — the method name itself (with intentional "alart" spelling). Alerts when work correction dates are out of sync. |
| 工事訂正 | Japanese | Work Correction — the business operation of modifying a previously completed work record. |
| 異動予約 | Japanese | Transfer Reservation — a reservation to relocate a service to a different address. |
| 申込明細 | Japanese | Order Detail (Application Detail) — the detail line of a service order application. |
| 予約適用年月日 | Japanese | Reservation Application Year/Month/Day — the effective start date of the reservation. |
| 工事案件番号 | Japanese | Work Case Number — the identifier for a work project/case. |
| 工事完了 | Japanese | Work Completion — the state when a work operation has been finished. |
| 工事完了ワーク | Japanese | Work Completion Work — the work table (`KK_T_KJ_FIN_WK`) tracking completed work records. |
| 適用開始日 | Japanese | Application Start Date — the date from which the transferred service is active. |
