# Business Logic — JBSbatKKKojiKnrnInfCheck.checkEquipRyuyo() [208 LOC]

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

## 1. Role

### JBSbatKKKojiKnrnInfCheck.checkEquipRyuyo()

This method performs the **equipment routing validation** (設備流用工事案件チェック) for a work order case that is flagged as requiring equipment transfer from a prior service. In the K-Opticom telecom billing and service management system, when a customer switches premises or reconfigures services, equipment such as ONUs (Optical Network Units) or V-ONUs (Video ONUs for TV services) must be routed — i.e., transferred — from the old (prior) service to the new one, rather than being newly provisioned. This method ensures that **all prior service contracts associated with the equipment have been fully terminated or cancelled** before the system permits the equipment routing information to be output to downstream work order processing.

The method handles **two service/device categories** based on the routing flags found in the work order case: **(1) Network + Telephone work** (dummy ONU, equipment subtype D0) and **(2) Television work** (dummy V-ONU, equipment subtype E0). If the work order is not flagged for equipment routing at all, the method immediately returns `true` (pass), since there is nothing to validate.

It implements a **validation-with-early-exit pattern** — querying the database multiple times in a gatekeeper sequence, returning `true` (skip) on any invalid or missing state, and only building the equipment routing output record when all checks pass. When routing is required, it additionally delegates the output validity check to `checkKojiFinKikiRyuyoInfOutPut()` and enforces deduplication via the `kojiakNoTaihiSet` instance field. A v72 enhancement (ANK-4577-00-00) added a critical check to reject routing if an active service contract (KK_T_SVC_KEI) still exists for the service line — preventing equipment routing to terminated services.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["checkEquipRyuyo data String array"]) --> SETUP["SETUP: Extract svcKeiNo, kaisenUcwkNo, kojiakNo from data array"]
    SETUP --> QUERY_KOJIAK["CALL selectKjakPK with kojiakNo"]
    QUERY_KOJIAK --> CHECK_NULL1{Kojiaak result null?}
    CHECK_NULL1 -->|Yes| SKIP_RETURN1["Return true: skip equipment routing check"]
    CHECK_NULL1 -->|No| READ_EQUIP["Read equipRyuyoUm, vonuRyuyoUm, ryuyoMotoKjakNo from KU_T_KOJIAK"]
    READ_EQUIP --> CHECK_EQUIP{equipRyuyoUm equals<br/>CD_DIV_UM_ARI?}
    CHECK_EQUIP -->|No| SKIP_RETURN2["Return true: no equipment routing"]
    CHECK_EQUIP -->|Yes| CHECK_VONU{vonuRyuyoUm null or empty?}
    CHECK_VONU -->|Yes| NET_TEL["SET modelCd=dummyOnuModelCd, taknkikiSbtCd=D0, netTelKojiFlg=true"]
    CHECK_VONU -->|No| CHECK_VONU_EXIST{vonuRyuyoUm equals<br/>CD_DIV_UM_ARI?}
    CHECK_VONU_EXIST -->|Yes| TV_WORK["SET modelCd=dummyVOnuModelCd, taknkikiSbtCd=E0"]
    CHECK_VONU_EXIST -->|No| SKIP_RETURN3["Return true: unexpected vonuRyuyoUm value"]
    NET_TEL --> QUERY_ONU["CALL selectKktkSvcKei245 with kaisenUcwkNo and modelCd"]
    TV_WORK --> QUERY_ONU
    QUERY_ONU --> CHECK_NULL2{Device contract result null?}
    CHECK_NULL2 -->|Yes| SKIP_RETURN4["Return true: no valid device contract"]
    CHECK_NULL2 -->|No| QUERY_RYUYO["CALL selectKktkSvcKei246 with taknkikiSbtCd and ryuyoMotoKjakNo"]
    QUERY_RYUYO --> CHECK_NULL3{Routing device info null?}
    CHECK_NULL3 -->|Yes| SKIP_RETURN5["Return true: no routing device info"]
    CHECK_NULL3 -->|No| QUERY_SVC["CALL selectSvcKei383 with svcKeiNo"]
    QUERY_SVC --> CHECK_SVC{Svc contract exists?}
    CHECK_SVC -->|Yes active| SKIP_RETURN6["Return true: service contract still active - routing rejected"]
    CHECK_SVC -->|No: null| OUTPUT_PREP["SET outputFlg=true"]
    OUTPUT_PREP --> CHECK_NET{netTelKojiFlg true?}
    CHECK_NET -->|Yes| CALL_CHECK["CALL checkKojiFinKikiRyuyoInfOutPut with kojiakNo and svcKeiNo"]
    CHECK_NET -->|No| SET_OUTPUT["SET outputFlg stays true"]
    CALL_CHECK --> CHECK_OUTPUT{outputFlg true?}
    SET_OUTPUT --> CHECK_OUTPUT
    CHECK_OUTPUT -->|Yes| CHECK_TAIHI{kojiakNo in<br/>kojiakNoTaihiSet?}
    CHECK_OUTPUT -->|No| RETURN_END["Return true: end of check"]
    CHECK_TAIHI -->|Yes| SKIP_RETURN7["Return true: already processed"]
    CHECK_TAIHI -->|No| READ_KKTK["Read ryuyoSakiKktkSvcKeiNo from selectKktkSvcKei245 result"]
    READ_KKTK --> BUILD_RECORD["CALL setKojiFinKikiRyuyoInfRec to build output record"]
    BUILD_RECORD --> TRANSFER["CALL setKojiFinKikiRyuyoInfData to write to kojiFinKikiRyuyoInf"]
    TRANSFER --> ADD_SET["Add kojiakNo to kojiakNoTaihiSet"]
    ADD_SET --> RETURN_END
    SKIP_RETURN1 --> RETURN_END
    SKIP_RETURN2 --> RETURN_END
    SKIP_RETURN3 --> RETURN_END
    SKIP_RETURN4 --> RETURN_END
    SKIP_RETURN5 --> RETURN_END
    SKIP_RETURN6 --> RETURN_END
    SKIP_RETURN7 --> RETURN_END
```

**CRITICAL — Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|-----------------|
| `JKKStrConst.CD_DIV_UM_ARI` | `"1"` | "Yes" / "Exists" — flag indicating a particular resource or routing item is present |
| `JKKStrConst.TAKNKIKI_SBT_CD_ONU` | `"D0"` | Residential equipment subtype code for ONU (Optical Network Unit) — used for network + telephone work |
| `JKKStrConst.TAKNKIKI_SBT_CD_VONU` | `"E0"` | Residential equipment subtype code for V-ONU (Video Optical Network Unit) — used for television work |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `data` | `String[]` | Work completion information data array — a flat record extracted from a delimited work order file. Contains at minimum: `data[0]` = service contract number (svcKeiNo), `data[1]` = service contract line item number (kaisenUcwkNo), `data[6]` = work order case number (kojiakNo). |

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

| Field | Type | Business Description |
|-------|------|---------------------|
| `dummyOnuModelCd` | `String` | Dummy ONU model code, configured from `ZM_M_WORK_PARAM_KNRI` table (business parameter management) |
| `dummyVOnuModelCd` | `String` | Dummy V-ONU model code, similarly configured from `ZM_M_WORK_PARAM_KNRI` table |
| `kojiakNoTaihiSet` | `Set<String>` | Work order case number deduplication set — tracks cases already processed to avoid duplicate routing output within the same batch run |
| `kojiFinKikiRyuyoInf` | `StringBuilder` | StringBuilder accumulator holding the formatted equipment routing output text records for the completed-work equipment |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKKojiKnrnInfCheck.selectKjakPK` | KK_SELECT_022 (KU_T_KOJIAK) | `KU_T_KOJIAK` | Reads work order case data by primary key (KOJIAK_NO) to check equipment routing flags |
| R | `JBSbatKKKojiKnrnInfCheck.selectKktkSvcKei245` | KK_SELECT_245 | `KK_T_KKTK_SVC_KEI` | Reads device-provided service contract data for the kaisenUcwkNo (line item) and dummy model code to validate device existence |
| R | `JBSbatKKKojiKnrnInfCheck.selectKktkSvcKei246` | KK_SELECT_246 | `KK_T_KKTK_SVC_KEI` | Reads equipment routing source device information (ONU/V-ONU) by equipment subtype and prior work case number |
| R | `JBSbatKKKojiKnrnInfCheck.selectSvcKei383` | KK_SELECT_383 | `KK_T_SVC_KEI` | Reads service contract to verify no active contract exists for this svcKeiNo (v72 ANK-4577-00-00 add) |
| - | `JBSbatKKKojiKnrnInfCheck.checkKojiFinKikiRyuyoInfOutPut` | N/A | N/A | Checks whether the completed-work equipment routing output is valid; returns boolean flag |
| - | `JBSbatKKKojiKnrnInfCheck.setKojiFinKikiRyuyoInfData` | N/A | N/A | Sets/transfers the built equipment routing record string into the `kojiFinKikiRyuyoInf` StringBuilder accumulator |
| - | `JBSbatKKKojiKnrnInfCheck.setKojiFinKikiRyuyoInfRec` | N/A | N/A | Builds the formatted equipment routing output record string from the input data and routing info |
| - | `JBSbatCommonDBInterface.getString` | N/A | N/A | Reads individual field values from DB result maps |
| - | `JBSbatStringUtil.Rtrim` | N/A | N/A | Trims trailing whitespace from string values |
| - | `JBCBatCommon.printDebugLog` | N/A | N/A | Debug logging — logs START and END of method execution |

**Additional CRUD inferred from code analysis:**

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Set.add` | N/A | N/A | Adds processed `kojiakNo` to `kojiakNoTaihiSet` to prevent duplicate output within batch scope |

**How to classify:**
- **R (Read)**: All DB queries (`selectKjakPK`, `selectKktkSvcKei245`, `selectKktkSvcKei246`, `selectSvcKei383`) and `getString` calls on DB result interfaces read data from tables.
- **No C/R/U/D**: The internal methods (`checkKojiFinKikiRyuyoInfOutPut`, `setKojiFinKikiRyuyoInfData`, `setKojiFinKikiRyuyoInfRec`) are intra-class processing helpers that operate on in-memory data structures (StringBuilder, Set, boolean flags) rather than performing direct DB operations.

## 5. Dependency Trace

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

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

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKKojiKnrnInfCheck.kojiFinInfOutPut()` | `execute()` -> `kojiFinInfOutPut(mid_dir_kk)` -> `checkEquipRyuyo(data)` | `selectKjakPK [R] KU_T_KOJIAK`, `selectKktkSvcKei245 [R] KK_T_KKTK_SVC_KEI`, `selectKktkSvcKei246 [R] KK_T_KKTK_SVC_KEI`, `selectSvcKei383 [R] KK_T_SVC_KEI` |

**Explanation:** This method is invoked during the work completion information output phase (`kojiFinInfOutPut`) of the batch job. The batch job's `execute()` method orchestrates multiple output stages (survey results, design results, transmission equipment, work completion, cancellation, etc.), and `checkEquipRyuyo` is one of the validation filters applied before outputting equipment routing data for completed work orders.

## 6. Per-Branch Detail Blocks

**Block 1** — [SETUP] (L4899–L4918)

> Initializes local variables and extracts three key identifiers from the input data array.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dummyTaknkikiModelCd = ""` // Dummy residential equipment model code |
| 2 | SET | `taknkikiSbtCd = ""` // Residential equipment subtype code |
| 3 | SET | `netTelKojiFlg = false` // Network + telephone work flag |
| 4 | SET | `svcKeiNo = data[0]` // Service contract number |
| 5 | SET | `kaisenUcwkNo = data[1]` // Service contract line item number |
| 6 | SET | `kojiakNo = data[6]` // Work order case number |
| 7 | DEBUG | `logPrint.printDebugLog("checkEquipRyuyo_START")` // Debug log entry |

---

**Block 2** — [IF] `null == outMapKojiakPK` (L4922–L4930)

> Retrieves work order case information from `KU_T_KOJIAK` via PK lookup. If no work order case record is found, the equipment routing check is complete and passes (return true), since there is no case to route equipment for.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outMapKojiakPK = selectKjakPK(kojiakNo)` // Query: `KK_SELECT_022` on `KU_T_KOJIAK` |
| 2 | IF | `null == outMapKojiakPK` |
| 2.1 | RETURN | `return true` // No work order case found — skip routing check |

---

**Block 3** — [SETUP] Equipment routing flags extraction (L4931–L4940)

> Reads the equipment routing presence flags from the KU_T_KOJIAK result set.

| # | Type | Code |
|---|------|------|
| 1 | SET | `equipRyuyoUm = JBSbatStringUtil.Rtrim(outMapKojiakPK.getString(JBSbatKU_T_KOJIAK.EQUIP_RYUYO_UM))` // Equipment routing existence flag |
| 2 | SET | `vonuRyuyoUm = JBSbatStringUtil.Rtrim(outMapKojiakPK.getString(JBSbatKU_T_KOJIAK.VONU_RYUYO_UM))` // V-ONU routing existence flag |
| 3 | SET | `ryuyoMotoKjakNo = JBSbatStringUtil.Rtrim(outMapKojiakPK.getString(JBSbatKU_T_KOJIAK.RYUYO_MOTO_KJAK_NO))` // Prior routing work case number |

---

**Block 4** — [IF-ELSE-IF-ELSE] Equipment routing flag check (L4942–L4982)

> Determines the type of equipment routing based on the flags. If `equipRyuyoUm` is "1" (CD_DIV_UM_ARI — routing exists), branches further based on whether V-ONU routing is set. Otherwise returns true (skip).

| # | Type | Code |
|---|------|------|
| 1 | IF | `JKKStrConst.CD_DIV_UM_ARI.equals(equipRyuyoUm)` `[CD_DIV_UM_ARI = "1"]` (L4944) |
| 1.1 | [ELSE-IF nested] | `null == vonuRyuyoUm || "".equals(vonuRyuyoUm)` (L4947) |
| 1.1.1 | SET | `dummyTaknkikiModelCd = dummyOnuModelCd` // Use dummy ONU model code |
| 1.1.2 | SET | `taknkikiSbtCd = JKKStrConst.TAKNKIKI_SBT_CD_ONU` `[TAKNKIKI_SBT_CD_ONU = "D0"]` // ONU = network + telephone work |
| 1.1.3 | SET | `netTelKojiFlg = true` // Mark as network + telephone work |
| 1.2 | [ELSE-IF] | `JKKStrConst.CD_DIV_UM_ARI.equals(vonuRyuyoUm)` `[CD_DIV_UM_ARI = "1"]` (L4960) |
| 1.2.1 | SET | `dummyTaknkikiModelCd = dummyVOnuModelCd` // Use dummy V-ONU model code |
| 1.2.2 | SET | `taknkikiSbtCd = JKKStrConst.TAKNKIKI_SBT_CD_VONU` `[TAKNKIKI_SBT_CD_VONU = "E0"]` // V-ONU = television work |
| 1.3 | [ELSE] (L4967) | Unexpected vonuRyuyoUm value |
| 1.3.1 | RETURN | `return true` // V-ONU flag present but not "1" — skip |
| 2 | [ELSE] (L4975) | `equipRyuyoUm` is not "1" |
| 2.1 | RETURN | `return true` // No equipment routing flag set — skip |

---

**Block 5** — [IF] Device contract existence check (L4986–L4993)

> Queries `KK_T_KKTK_SVC_KEI` via SQL key `KK_SELECT_245` to verify that a device-provided service contract exists for the given kaisenUcwkNo and the determined dummy model code. If no contract exists, skip routing.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outMapKktkSvcKei245 = selectKktkSvcKei245(kaisenUcwkNo, dummyTaknkikiModelCd)` // Query: `KK_SELECT_245` on `KK_T_KKTK_SVC_KEI` |
| 2 | IF | `null == outMapKktkSvcKei245` (L4989) |
| 2.1 | RETURN | `return true` // No device contract found — skip routing check |

---

**Block 6** — [IF] Equipment routing source device info check (L4996–L5004)

> Queries `KK_T_KKTK_SVC_KEI` via SQL key `KK_SELECT_246` to retrieve the routing source device (prior ONU/V-ONU) information using the equipment subtype and the prior work case number. If not found, skip.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outMapKktkSvcKei246 = selectKktkSvcKei246(taknkikiSbtCd, ryuyoMotoKjakNo)` // Query: `KK_SELECT_246` on `KK_T_KKTK_SVC_KEI` |
| 2 | IF | `null == outMapKktkSvcKei246` (L4999) |
| 2.1 | RETURN | `return true` // No routing device info found — skip routing check |

---

**Block 7** — [IF] Service contract active check (v72 ANK-4577-00-00) (L5008–L5017)

> Queries `KK_T_SVC_KEI` via SQL key `KK_SELECT_383` to check if the service contract (svcKeiNo) is still active. If the contract exists (not null), routing is rejected — this ensures equipment is not routed while the original service is still active. This is a v72 addition for eo Light "Simple Plan" support.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `outMapSvcKei383 = selectSvcKei383(svcKeiNo)` // Query: `KK_SELECT_383` on `KK_T_SVC_KEI` |
| 2 | IF | `null != outMapSvcKei383` (L5011) |
| 2.1 | RETURN | `return true` // Service contract still exists — reject equipment routing |

---

**Block 8** — [IF-ELSE] Output preparation and routing data output (L5050–L5085)

> After all validation checks pass, this block prepares the equipment routing output. If the work is network + telephone type, it delegates to `checkKojiFinKikiRyuyoInfOutPut` for additional validation. Then, if output is valid and the case is not already deduplicated, it builds and writes the routing record.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outputFlg = true` // Initialize output flag |
| 2 | IF | `netTelKojiFlg` (L5054) — Network + telephone work path |
| 2.1 | SET | `outputFlg = checkKojiFinKikiRyuyoInfOutPut(kojiakNo, svcKeiNo)` // Delegates output validity check |
| 3 | IF | `outputFlg` (L5060) |
| 3.1 | IF | `kojiakNoTaihiSet.contains(kojiakNo)` (L5064) |
| 3.1.1 | RETURN | `return true` // Already processed in this batch run — skip duplicate |
| 3.2 | SET | `ryuyoSakiKktkSvcKeiNo = JBSbatStringUtil.Rtrim(outMapKktkSvcKei245.getString(JBSbatKK_T_KKTK_SVC_KEI.KKTK_SVC_KEI_NO))` |
| 3.3 | CALL | `kojiFinKikiRyuyoData = setKojiFinKikiRyuyoInfRec(data, ryuyoSakiKktkSvcKeiNo, ryuyoMotoKjakNo, outMapKktkSvcKei246)` // Build routing record |
| 3.4 | CALL | `setKojiFinKikiRyuyoInfData(kojiFinKikiRyuyoData, kojiFinKikiRyuyoInf)` // Write to StringBuilder accumulator |
| 3.5 | EXEC | `kojiakNoTaihiSet.add(kojiakNo)` // Mark as processed for dedup |
| 4 | DEBUG | `logPrint.printDebugLog("checkEquipRyuyo_END")` |
| 5 | RETURN | `return true` // All checks passed — routing output prepared |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `equipRyuyoUm` | Field | Equipment routing existence flag — indicates whether this work order case requires equipment transfer (値: "1"=有/routing required, "0"=無/no routing) |
| `vonuRyuyoUm` | Field | V-ONU routing existence flag — indicates whether a V-ONU (video ONU for TV services) is also being routed alongside the primary equipment (値: "1"=有, null/empty=未設定/not set) |
| `ryuyoMotoKjakNo` | Field | Prior routing work case number — the work order case number of the original/prior service from which equipment is being transferred |
| `svcKeiNo` | Field | Service contract number (サービス契約番号) — unique identifier for a telecom service contract line |
| `kaisenUcwkNo` | Field | Service contract line item number (サービス契約回線内訳番号) — identifies a specific line within a service contract (used to link to device contracts) |
| `kojiakNo` | Field | Work order case number (工事案件番号) — unique identifier for a work order case in the KOJIAK table |
| `taknkikiSbtCd` | Field | Residential equipment subtype code (宅内機器種別コード) — classifies the type of indoor equipment: D0=ONU (network+telephone), E0=V-ONU (television) |
| `dummyOnuModelCd` | Field | Dummy ONU model code — a configured placeholder model code for ONU equipment, loaded from `ZM_M_WORK_PARAM_KNRI` parameter table |
| `dummyVOnuModelCd` | Field | Dummy V-ONU model code — a configured placeholder model code for V-ONU equipment, loaded from `ZM_M_WORK_PARAM_KNRI` parameter table |
| `netTelKojiFlg` | Field | Network + telephone work flag — true when this is a network/telephone type work order requiring ONU equipment routing |
| `outputFlg` | Local | Output validity flag — determines whether equipment routing output should proceed |
| `kojiakNoTaihiSet` | Instance | Work order case number exclusion set — HashSet of processed cases to prevent duplicate routing output within a single batch execution |
| `kojiFinKikiRyuyoInf` | Instance | StringBuilder holding the formatted equipment routing output text records for completed-work equipment |
| `CD_DIV_UM_ARI` | Constant | "1" — Code meaning "有" (exists/present) — used to indicate routing flags are set |
| `TAKNKIKI_SBT_CD_ONU` | Constant | "D0" — Equipment subtype code for ONU (Optical Network Unit) used in network + telephone services |
| `TAKNKIKI_SBT_CD_VONU` | Constant | "E0" — Equipment subtype code for V-ONU (Video Optical Network Unit) used in television services |
| KU_T_KOJIAK | DB Table | Work Order Case table — stores work order case header information including equipment routing flags |
| KK_T_KKTK_SVC_KEI | DB Table | Device-Provided Service Contract table — stores service contracts associated with equipment/provided devices |
| KK_T_SVC_KEI | DB Table | Service Contract table — master table for service contracts; checking existence here determines if a contract is still active |
| ZM_M_WORK_PARAM_KNRI | DB Table | Business Parameter Management table — stores configurable system parameters including dummy ONU/V-ONU model codes |
| ONU | Acronym | Optical Network Unit — fiber-optic customer premises equipment for eo-hikari (fiber) services |
| V-ONU | Acronym | Video Optical Network Unit — specialized ONU for delivering TV/video services over fiber infrastructure |
| 設備流用 (Setobi Ryuyo) | Domain term | Equipment routing / equipment reassignment — the business process of transferring existing customer equipment (ONU/V-ONU) from an old/prior service to a new service, avoiding redundant provisioning |
| 工事案件 (Koji Anken) | Domain term | Work order case — a project/case in the field work management system for installation, repair, or modification tasks |
| 工事完了 (Koji Kanryou) | Domain term | Work completion — the state indicating field installation/work has been finished |
| KK_SELECT_245 | SQL Key | DB query to retrieve device-provided service contract by kaisenUcwkNo and equipment model code |
| KK_SELECT_246 | SQL Key | DB query to retrieve equipment routing source device info by equipment subtype and prior work case number |
| KK_SELECT_383 | SQL Key | DB query to check if a service contract record exists (used to verify no active contract — v72 ANK-4577-00-00) |
| KK_SELECT_022 | SQL Key | DB query to retrieve work order case by primary key (KOJIAK_NO) |
