# Business Logic — JBSbatTUBmpKojiFinTrn.execute() [51 LOC]

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

## 1. Role

### JBSbatTUBmpKojiFinTrn.execute()

This method is the **main batch processing entry point** for completing a **banpo (番口, front-line terminal/NTT junction) work order** in the K-Opticom customer base system. It handles the finalization of field installation work performed on NTT-owned equipment at the subscriber's premises.

The method performs a **three-phase sequential operation**: (1) It updates the banpo work table (`TU_T_BMP_KOJI`) to mark the work as finished (`BMP_KOJI_FIN`) using the operator's business date. (2) If the order includes a service contract detail work number (`SVC_KEI_UCWK_NO`), it inserts associated banpo work child data (such as phone number assignment records) into the output/detail records. (3) For **cancellation orders from individual customers in "implementation pending" state**, it builds and prepares file output data for downstream processing — specifically when the customer type is individual (`HOJIN_KOJIN_CD = "1"`), the request type is cancellation (`BMP_MSKMSHO_TYPE_CD = "3"`), and the work status is "implementation pending" (`BMP_KOJI_STAT = "031"`).

The method implements a **delegation pattern**, delegating the primary update logic to `executeTU_T_BMP_KOJI_PKUPDATE` and child record insertion to `insertBmpKoji`, while composing the output through `setOutMap`. It is **not called from any external screen or batch** — it is an internal batch processing entry point invoked as part of a larger work-order finalization batch job (the class itself has no external callers).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execute(inMap)"])
    STEP1["Prepare setParam
BMP_KOJI_FIN and opeDate"]
    STEP2["Prepare whereParam
BMP_KOJI_NO and GENE_ADD_DTM"]
    STEP3["executeTU_T_BMP_KOJI_PKUPDATE"]
    COND1{"SVC_KEI_UCWK_NO
isNotNull"}
    STEP4["insertBmpKoji"]
    COND2{"HOJIN_KOJIN_CD=1
AND BMP_MSKMSHO_TYPE_CD=3
AND BMP_KOJI_STAT=031"}
    STEP5["Build output
setOutMap and addOutMapList"]
    STEP6["Return outItem"]
    END_NODE(["Return outItem"])

    START --> STEP1 --> STEP2 --> STEP3 --> COND1
    COND1 -- Yes --> STEP4
    COND1 -- No --> COND2
    STEP4 --> COND2
    COND2 -- Yes --> STEP5 --> END_NODE
    COND2 -- No --> END_NODE
```

**Processing Flow:**

1. **Phase 1 — Work table finish update (L96–L110)**: Prepares the set parameters (work status code and operator date) and where parameters (work number and generation timestamp), then calls `executeTU_T_BMP_KOJI_PKUPDATE` to update the `TU_T_BMP_KOJI` table, marking the work order as finished.

2. **Phase 2 — Child record insertion (L112–L118)**: Checks if the incoming map contains a non-null `SVC_KEI_UCWK_NO` (service contract detail work number). If present, calls `insertBmpKoji(inMap)` to insert associated banpo work child/detail records.

3. **Phase 3 — File output data preparation (L121–L140)**: Checks a three-condition guard — the order must be from an **individual customer** (`HOJIN_KOJIN_CD = "1"`), with **cancellation as the request type** (`BMP_MSKMSHO_TYPE_CD = "3"`), and the work must be in **"implementation pending" state** (`BMP_KOJI_STAT = "031"`). If all three conditions match, builds an output map from the input, sets the output flag to true, adds it to the output item list, and returns it.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | The input message carrying banpo work order data. Contains fields identifying the work order (work number, status, generation timestamp), the customer type (individual vs. corporate code), the request type (e.g., cancellation), the service contract detail work number (optional, triggers child record insertion), and various subscriber/contact attributes needed for downstream file output. |

**Instance/External State read by this method:**

| Source | Description |
|--------|-------------|
| `super.commonItem.getOpeDate()` | Retrieves the operator's business date (business day) used to set the work-finish timestamp in the update operation |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `JBSbatTUBmpKojiFinTrn.executeTU_T_BMP_KOJI_PKUPDATE` | — | `TU_T_BMP_KOJI` | Updates the banpo work table to mark the work order as finished (`BMP_KOJI_FIN`) with the operator date, using the work number and generation timestamp as the key. |
| C | `JBSbatTUBmpKojiFinTrn.insertBmpKoji` | — | `TU_T_BMP_KOJI` (child/detail) | Inserts banpo work child/detail records when a service contract detail work number is present. |
| R | `JBSbatTUBmpKojiFinTrn.setOutMap` | — | — | Reads fields from the input map to build the output map for file output data preparation. |
| - | `JCCBatCommon.isNotNull` | — | — | Null-check utility call to validate input fields before branching. |
| R | `super.commonItem.getOpeDate` | — | — | Retrieves the business date from the common item for the update timestamp. |

### Detailed analysis:

**`executeTU_T_BMP_KOJI_PKUPDATE` — Update (U)**
- **Entity/DB**: `TU_T_BMP_KOJI` (番口工事 table — Front-line Terminal Work Order table)
- **Operation**: Updates the `BMP_KOJI_STAT` column to `BMP_KOJI_FIN` (work finished status) and sets the timestamp to the operator's business date. The WHERE clause uses the composite key of `BMP_KOJI_NO` (work number) and `GENE_ADD_DTM` (generation add date-time) to uniquely identify the record.

**`insertBmpKoji` — Create (C)**
- **Entity/DB**: `TU_T_BMP_KOJI` (child/detail records)
- **Operation**: Inserts banpo work detail records associated with the work order when a service contract detail work number (`SVC_KEI_UCWK_NO`) is provided. This handles the creation of secondary records such as phone number assignment entries.

## 5. Dependency Trace

This method is a **batch service entry point** with no external callers found in the codebase. It is invoked internally as part of a work-order finalization batch job pipeline. The class name `JBSbatTUBmpKojiFinTrn` follows the naming convention `JBSbatTU*Trn` (Batch Service → TU segment → Work-related → Transaction), indicating it is called from the batch scheduling layer.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatTUJob` (inferred) | `BatchScheduler` → `JBSbatTUBmpKojiFinTrn.execute` | `executeTU_T_BMP_KOJI_PKUPDATE [U] TU_T_BMP_KOJI` |
| 2 | Batch: `JBSbatTUJob` (inferred) | `BatchScheduler` → `JBSbatTUBmpKojiFinTrn.execute` | `insertBmpKoji [C] TU_T_BMP_KOJI (child)` |

**Downstream chain from this method:**

| # | Called Method | CRUD | Entity/DB | Description |
|---|--------------|------|-----------|-------------|
| 1 | `executeTU_T_BMP_KOJI_PKUPDATE(setParam, whereParam)` | U | `TU_T_BMP_KOJI` | Updates banpo work order status to finished |
| 2 | `insertBmpKoji(inMap)` | C | `TU_T_BMP_KOJI` (detail) | Inserts banpo work child/detail records |

## 6. Per-Branch Detail Blocks

### Block 1 — SET (L95–L110)

> Prepares parameters and executes the banpo work table finish update.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam = new Object[2]` // Allocate 2-element parameter array [L96] |
| 2 | SET | `setParam[0] = JTUStrConst.BMP_KOJI_FIN [-> "Finished work status"]` // Banpo work status constant [L98] |
| 3 | SET | `setParam[1] = super.commonItem.getOpeDate()` // Banpo work finish date [L100] |
| 4 | SET | `whereParam = new Object[2]` // Allocate 2-element where clause array [L103] |
| 5 | SET | `whereParam[0] = inMap.get(JBSbatTU_T_BMP_KOJI.BMP_KOJI_NO)` // Banpo work number [L105] |
| 6 | SET | `whereParam[1] = inMap.get(JBSbatTU_T_BMP_KOJI.GENE_ADD_DTM)` // Generation add date-time [L107] |
| 7 | CALL | `executeTU_T_BMP_KOJI_PKUPDATE(setParam, whereParam)` // Update the work table to finished state [L110] |

### Block 2 — IF (Condition: `SVC_KEI_UCWK_NO isNotNull`) (L112–L118)

> If the service contract detail work number is present, inserts banpo work child records. This handles orders that include service-level work items (e.g., phone number assignment, service detail modifications).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JCCBatCommon.isNotNull(inMap.getString(JBSbatTU_T_BMP_KOJI.SVC_KEI_UCWK_NO))` // Check if service contract detail work number is not null [L112] |
| 2 | CALL | `insertBmpKoji(inMap)` // Banpo work child record insertion processing [L117] |

### Block 3 — SET (L121–L123)

> Initiates file output data preservation preparation (ANK-4494-00-00 ADD).

| # | Type | Code |
|---|------|------|
| 1 | SET | `outItem = new JBSbatOutputItem()` // File output data preservation item [L122] |

### Block 4 — IF (Condition: 3-part guard for file output) (L125–L137)

> [HOJIN_KOJIN_CD="1"] AND [BMP_MSKMSHO_TYPE_CD="3"] AND [BMP_KOJI_STAT="031"]
>
> File output information preservation items. When the customer code is "Individual: 1", AND the banpo application form type code is "Cancellation: 3", AND the banpo work status is "Implementation pending request: 031", this becomes the file output target.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JTUStrConst.KOJIN [-> "1"]` // Individual customer code [L126] |
| 2 | SET | `JTUStrConst.BMP_REQ_NAIYO_HAISHI [-> "3"]` // Banpo application form type: Cancellation [L127] |
| 3 | SET | `JTUStrConst.KOJI_JSSI_REQ_STAY [-> "031"]` // Banpo work status: Implementation pending request [L128] |
| 4 | SET | `outMap = setOutMap(inMap)` // File output content editing [L131] |
| 5 | EXEC | `outMap.setOutFlg(true)` // Set the output flag [L132] |
| 6 | EXEC | `outItem.addOutMapList(outMap)` // Add the output map to the output list [L133] |

### Block 5 — RETURN (L140)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return outItem` // Returns the output item (may be null if the guard condition was not met) [L140] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `TU_T_BMP_KOJI` | DB Table | Banpo Work Table — stores front-line terminal (NTT junction) work order records, including work status, customer information, and service contract details. "Banpo" (番口) refers to the NTT demarcation point at the subscriber's premises. |
| `BMP_KOJI_NO` | Field | Banpo work number — unique identifier for each banpo work order |
| `BMP_KOJI_STAT` | Field | Banpo work status — tracks the lifecycle of a work order (e.g., "031" = implementation pending, finish status) |
| `BMP_KOJI_FIN` | Constant | Banpo work finished status code — the value used to mark a work order as completed in the status column |
| `BMP_MSKMSHO_TYPE_CD` | Field | Banpo application form type code — classifies the type of request (e.g., "3" = Cancellation) |
| `GENE_ADD_DTM` | Field | Generation add date-time — the timestamp when this work order record was created, used as part of the composite key for updates |
| `SVC_KEI_UCWK_NO` | Field | Service detail work number — internal tracking ID for service contract line items; if non-null, triggers child record insertion |
| `HOJIN_KOJIN_CD` | Field |法人個人コード (Hojin/Kojin Code) — classifies the customer as corporate (法人, "法人") or individual (個人, "1"). "1" indicates an individual customer. |
| `KOJIN` | Constant | Individual customer code — value `"1"`, indicates a personal (non-corporate) subscriber |
| `BMP_REQ_NAIYO_HAISHI` | Constant | Banpo request content "Cancellation" — value `"3"`, indicates the work order is for cancellation of service |
| `KOJI_JSSI_REQ_STAY` | Constant | Banpo work status "Implementation pending" — value `"031"`, indicates the work has been requested but not yet completed in the field |
| `getOpeDate` | Method | Retrieves the operator's business date (business day, 営業日) — the reference date for batch processing operations |
| `JBSbatServiceInterfaceMap` | Class | Service interface map — a map-based data structure carrying business data between batch processing components, used as both input and output container |
| `JBSbatOutputItem` | Class | Batch output item — holds output data maps generated by the batch service, which are consumed by downstream processing or file output |
| `setOutMap` | Method | Builds an output map from the input, extracting and transforming fields needed for file output data preservation |
| `insertBmpKoji` | Method | Inserts banpo work child/detail records into the database when service-level work items exist |
| `executeTU_T_BMP_KOJI_PKUPDATE` | Method | Updates the `TU_T_BMP_KOJI` table using primary key-based update, setting the work status to finished and the timestamp to the operator date |
| ANK-4494-00-00 | Change ID | Internal change ticket number — added the file output data preservation logic for individual customer cancellation orders |
