# Business Logic — JBSbatKKCourseChgeTstaDayChsht.selectSeteKj() [100 LOC]

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

## 1. Role

### JBSbatKKCourseChgeTstaDayChsht.selectSeteKj()

The `selectSeteKj` method performs the **setting work search processing** (設定工事の検索処理) for installation/construction work associated with a work case number. Its primary business purpose is to query the setup work table (`KU_T_SETTE_KOJI`) for a given work case number (`kojiAkNo`) and extract the work completion date and work result code. Regardless of whether a matching record is found or the completion date field is populated, the method always sets the `checkFlg` to `true` and resolves the work result code to `"0"` (工事なし / No Work Performed), which was standardized in v20.00.00. If a completion date exists in the database, it is used as the work completion date; otherwise, the operational date (`super.opeDate`) is substituted. The method follows a **delegation and data extraction pattern** — it delegates the actual SQL execution to `executeKU_T_SETTE_KOJI_KK_SELECT_001`, retrieves the result via `selectNext()`, then sets output values through the `outmap` interface. This method serves as a shared query utility called by the `execute()` entry point within the same class, forming part of the batch workflow that processes course changes scheduled for the next business day.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["selectSeteKj outmap, kojiAkNo"])
    INIT["Initialize checkFlg, kjFinYmd, kojiRslt"]
    WHERE["Build whereSeteKjParam array with kojiAkNo"]
    EXEC_QUERY["executeKU_T_SETTE_KOJI_KK_SELECT_001 whereSeteKjParam"]
    SELECT_NEXT["seteKjMap_001 = db_KU_T_SETTE_KOJI.selectNext"]
    COND_RESULT{seteKjMap_001_not_null}
    COND_EMPTY{setteKjFinDtm_empty}
    SETTE_TRUE["checkFlg=true, kjFinYmd=setteKjFinDtm, kojiRslt=KKIFM151_KOJI_RSLT_0"]
    ELSE_TRUE["checkFlg=true, kjFinYmd=super.opeDate, kojiRslt=KKIFM151_KOJI_RSLT_0"]
    NO_RESULT["checkFlg=true, kjFinYmd=super.opeDate, kojiRslt=KKIFM151_KOJI_RSLT_0"]
    SET_OUT["outmap.setString KOJI_RSLT to kojiRslt"]
    SET_OUT_DTM["outmap.setString KOJIAK_FIN_YMD to kjFinYmd"]
    DEBUG_LOG["super.logPrint.printDebugLog debug output"]
    RETURN_TRUE["return checkFlg true"]

    START --> INIT --> WHERE --> EXEC_QUERY --> SELECT_NEXT --> COND_RESULT
    COND_RESULT -->|true| GET_FIN_DTMS["setteKjFinDtm = Rtrim getString SETTE_KOJI_FIN_YMD"] --> COND_EMPTY
    COND_EMPTY -->|false, data exists| SETTE_TRUE
    COND_EMPTY -->|true, no data| ELSE_TRUE
    COND_RESULT -->|false, no result| NO_RESULT
    SETTE_TRUE --> SET_OUT
    ELSE_TRUE --> SET_OUT
    NO_RESULT --> SET_OUT
    SET_OUT --> SET_OUT_DTM --> DEBUG_LOG --> RETURN_TRUE
```

**Conditional Branch Summary:**

| Branch | Condition | Business Meaning | Outcome |
|--------|-----------|-----------------|---------|
| Branch A | `seteKjMap_001 != null` AND `setteKjFinDtm` is not empty | A setup work record exists AND has a recorded completion date | Set completion date from DB, result = "0" (No Work Performed) |
| Branch B | `seteKjMap_001 != null` AND `setteKjFinDtm` is empty | A setup work record exists BUT has no completion date | Set completion date to operational date (`super.opeDate`), result = "0" |
| Branch C | `seteKjMap_001 == null` | No setup work record found for the given work case number | Set completion date to operational date (`super.opeDate`), result = "0" |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `outmap` | `JBSbatServiceInterfaceMap` | Output interface object used to set the search result values. After the method executes, `outmap` receives the work result code (`KOJI_RSLT`) and work completion date (`KOJIAK_FIN_YMD`). This is the contract through which the caller (`execute()`) retrieves the method's output. |
| 2 | `kojiAkNo` | `String` | Work case number (工事案件番号) — a unique identifier that identifies a specific work case. Used as the WHERE clause filter parameter to query the setup work table (`KU_T_SETTE_KOJI`). The method wraps this value in a `String[]` array as the query parameter. |

**Instance fields accessed:**

| Field | Type | Business Meaning |
|-------|------|------------------|
| `db_KU_T_SETTE_KOJI` | `JBSbatCommonDBInterface` (table interface) | Database access handle for the `KU_T_SETTE_KOJI` (setting work) table. Used to execute the search query and retrieve the next result record. |
| `super.opeDate` | `String` (inherited) | Operational date (運用年月日) — the business date for the batch run. Used as a fallback work completion date when the database has no completion date or no record exists. |
| `super.logPrint` | `JBSbatLogUtil` (inherited) | Logging utility used to emit debug-level log entries when debug mode is enabled. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKCourseChgeTstaDayChsht.executeKU_T_SETTE_KOJI_KK_SELECT_001` | (internal query execution) | `KU_T_SETTE_KOJI` | Executes SQL query against the setup work table using `kojiAkNo` as the filter parameter to retrieve setup work records. |
| R | `JBSbatCommonDBInterface.selectNext` | (internal) | `KU_T_SETTE_KOJI` | Retrieves the next row from the query result set of the setup work table into `seteKjMap_001`. |
| R | `JBSbatCommonDBInterface.getString` | (internal) | `KU_T_SETTE_KOJI` | Extracts the `SETTE_KOJI_FIN_YMD` (setup work completion date) string value from the result map. |
| R | `JBSbatStringUtil.Rtrim` | JBSbatStringUtil | - | Trims trailing whitespace from the completion date string. |
| - | `JBSbatKKConst.KKIFM151_KOJI_RSLT_0` | JBSbatKKConst | - | Constant reference: resolves to `"0"` meaning "工事なし" (No Work Performed). |
| - | `outmap.setString` | JBSbatInterface | - | Sets the work result code (`KOJI_RSLT`) to the output interface map. |
| - | `outmap.setString` | JBSbatInterface | - | Sets the work completion date (`KOJIAK_FIN_YMD`) to the output interface map. |
| - | `super.logPrint.printDebugLog` | JBSbatLogUtil | - | Emits debug log entries for work result and completion date when debug level is enabled. |
| - | `super.logPrint.chkLogLevel` | JBSbatLogUtil | - | Checks whether debug-level logging is enabled before emitting debug log entries. |

## 5. Dependency Trace

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

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.execute()` | `JBSbatKKCourseChgeTstaDayChsht.execute()` -> `JBSbatKKCourseChgeTstaDayChsht.selectSeteKj()` | `executeKU_T_SETTE_KOJI_KK_SELECT_001 [R] KU_T_SETTE_KOJI` |

**Terminal operations reached from this method:**

| # | Terminal Method | Operation | Entity / Target |
|---|----------------|-----------|-----------------|
| 1 | `executeKU_T_SETTE_KOJI_KK_SELECT_001` | R (Read) | `KU_T_SETTE_KOJI` — Setup work table |
| 2 | `db_KU_T_SETTE_KOJI.selectNext` | R (Read) | `KU_T_SETTE_KOJI` — Setup work table result set |
| 3 | `JBSbatCommonDBInterface.getString` | R (Read) | `KU_T_SETTE_KOJI.SETTE_KOJI_FIN_YMD` field |
| 4 | `super.logPrint.printDebugLog` | - | Debug log output |

## 6. Per-Branch Detail Blocks

**Block 1** — [LOCAL VARIABLES] (L1762)

> Initializes local variables for tracking the result, completion date, and work status before the query is executed.

| # | Type | Code |
|---|------|------|
| 1 | SET | `checkFlg = false` // Discrimination flag — initially false |
| 2 | SET | `kjFinYmd = ""` // Work completion date (工事完了日) |
| 3 | SET | `kojiRslt = ""` // Work result (工事結果) |
| 4 | SET | `seteKjMap_001 = null` // SQL execution result map (setup work info retrieval) |
| 5 | SET | `whereSeteKjParam = {kojiAkNo}` // WHERE clause parameter array |

**Block 2** — [METHOD CALL] (L1774)

> Executes the setup work search query, delegating to `executeKU_T_SETTE_KOJI_KK_SELECT_001`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKU_T_SETTE_KOJI_KK_SELECT_001(whereSeteKjParam)` |

**Block 3** — [METHOD CALL] (L1777)

> Retrieves the next row from the query result set into `seteKjMap_001`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `seteKjMap_001 = db_KU_T_SETTE_KOJI.selectNext()` |

**Block 4** — [IF] `(null != seteKjMap_001)` (L1780)

> Branch A: Setup work search result exists (setup work record was found for the given `kojiAkNo`).

**Block 4.1** — [IF / ELSE-IF / ELSE] `(!"".equals(setteKjFinDtm))` (L1783)

> Nested condition: The setup work completion date field has data. This checks whether `SETTE_KOJI_FIN_YMD` is populated.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setteKjFinDtm = Rtrim(getString(JBSbatKU_T_SETTE_KOJI.SETTE_KOJI_FIN_YMD))` // Setup work completion date (設定工事完了年月日) |
| 2 | SET | `checkFlg = true` // Sets discrimination flag to true |
| 3 | SET | `kjFinYmd = setteKjFinDtm` // Sets the completion date from DB to work completion date |
| 4 | SET | `kojiRslt = JBSbatKKConst.KKIFM151_KOJI_RSLT_0` // Work result = "0" (工事なし / No Work Performed) [-> CONSTANT="0"] |

**Block 4.2** — [ELSE] (L1805)

> Nested condition: The setup work completion date field is empty. The record exists but has no completion date recorded.

| # | Type | Code |
|---|------|------|
| 1 | SET | `checkFlg = true` // Sets discrimination flag to true |
| 2 | SET | `kjFinYmd = super.opeDate` // Uses operational date as fallback work completion date |
| 3 | SET | `kojiRslt = JBSbatKKConst.KKIFM151_KOJI_RSLT_0` // Work result = "0" (工事なし / No Work Performed) [-> CONSTANT="0"] |

**Block 5** — [ELSE] `(null == seteKjMap_001)` (L1817)

> Branch C: No setup work search result found. No record matched the `kojiAkNo` filter.

| # | Type | Code |
|---|------|------|
| 1 | SET | `checkFlg = true` // Sets discrimination flag to true |
| 2 | SET | `kjFinYmd = super.opeDate` // Uses operational date as fallback work completion date |
| 3 | SET | `kojiRslt = JBSbatKKConst.KKIFM151_KOJI_RSLT_0` // Work result = "0" (工事なし / No Work Performed) [-> CONSTANT="0"] |

**Block 6** — [METHOD CALLS] (L1830)

> Sets the resolved work result and completion date into the output interface map.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `outmap.setString(JBSbatKKIFM151.KOJI_RSLT, kojiRslt)` // Sets work result (工事結果) [-> field="KOJI_RSLT"] |
| 2 | EXEC | `outmap.setString(JBSbatKKIFM151.KOJIAK_FIN_YMD, kjFinYmd)` // Sets work completion date (工事完了年月日) [-> field="KOJIAK_FIN_YMD"] |

**Block 7** — [IF] `(super.logPrint.chkLogLevel(JBSbatLogUtil.MODE_DEBUG))` (L1834)

> Conditional debug logging. Only executed when debug-level logging is enabled.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog("設定工事検索（工事結果）： " + kojiRslt)` // Debug log: setup work search (work result) |
| 2 | EXEC | `super.logPrint.printDebugLog("設定工事検索（工事完了年月日）： " + kjFinYmd)` // Debug log: setup work search (work completion date) |

**Block 8** — [RETURN] (L1840)

> Returns the discrimination flag, which is always `true` regardless of which branch was taken.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return checkFlg` // Always returns true |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `seteKj` | Field | Setup work (設定工事) — installation/construction work that sets up service infrastructure |
| `kojiAkNo` | Field | Work case number (工事案件番号) — unique identifier for a work case in the batch processing system |
| `KOJI_RSLT` | Field | Work result (工事結果) — output field code indicating the status of the work (e.g., "0" = No Work Performed, "1" = Work Completed, "2" = Work Corrected, "3" = Work Cancellation, "4" = Work Cancelled) |
| `KOJIAK_FIN_YMD` | Field | Work completion date (工事完了年月日) — output field code for the date the setup work was completed, formatted as year/month/day |
| `KOJIAK_NO` | Field | Work case number (工事案件番号) — field code for the unique work case identifier used as the query filter |
| `SETTE_KOJI_FIN_YMD` | Field | Setup work completion date (設定工事完了年月日) — database field in the `KU_T_SETTE_KOJI` table storing the date the setup work was completed |
| `KU_T_SETTE_KOJI` | Table | Setup work table (設定工事テーブル) — database table storing records of setup/installation work performed on service contracts |
| `opeDate` | Field | Operational date (運用年月日) — the business date for the current batch run, used as a fallback when database values are unavailable |
| `checkFlg` | Field | Discrimination flag (判別フラグ) — result flag indicating whether the search processing completed; always set to `true` in this method |
| `kkif151_koji_rslt_0` | Constant | Work result code "0" (工事なし / No Work Performed) — indicates no work was performed for the given case |
| `kkif151_koji_rslt_1` | Constant | Work result code "1" (工事完了 / Work Completed) |
| `kkif151_koji_rslt_2` | Constant | Work result code "2" (工事的正 / Work Corrected) |
| `kkif151_koji_rslt_3` | Constant | Work result code "3" (工事完了取消 / Work Cancellation) |
| `kkif151_koji_rslt_4` | Constant | Work result code "4" (工事取消 / Work Cancelled) |
| `JBSbatKKCourseChgeTstaDayChsht` | Class | Course change for next-day scheduled setup work — batch service class handling setup work changes scheduled for the following business day |
| `JBSbatKKIFM151` | Utility | IFM (Interface Message) field constant class for IFM151 — defines output field codes for the work result and completion date interface |
| `JBSbatKU_T_SETTE_KOJI` | Table Interface | Database column constant class for the `KU_T_SETTE_KOJI` table — defines field names for accessing the setup work table |
| `executeKU_T_SETTE_KOJI_KK_SELECT_001` | Method | Internal query execution method that runs the SQL SELECT against `KU_T_SETTE_KOJI` filtered by work case number |
| `JBSbatServiceInterfaceMap` | Class | Service interface map — data transfer object used to pass output values between batch service methods and callers |
| `JBSbatLogUtil.MODE_DEBUG` | Constant | Debug mode flag — enables detailed logging when the batch run is in debug mode |
