# Business Logic — JBSbatTUBmpHaishiSodHakTrn.execute() [156 LOC]

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

## 1. Role

### JBSbatTUBmpHaishiSodHakTrn.execute()

This method is the main processing entry point for the **Tariff Cancellation SOD (Service Order Data) Issuance** batch component, as defined in the class-level comment: "Tariff cancellation SOD issuance processing item" (番ポ廃止SOD発行処理部品). "Tariff cancellation" (番ポ廃止) refers to the business operation of cancelling a telephone number's assigned tariff/service plan when a customer terminates their contract or migrates to a different service provider.

The method implements a **conditional orchestration pattern**: it receives a phone number from batch input, performs a single-item validation check, then evaluates a sequence of three data existence conditions in order. Only when all three conditions are satisfied — the service contract status is "910" (cancellation completed), the EO Hikari Tel auxiliary record does NOT exist, and the phone number master record DOES exist — does the method construct and invoke an external SOD issuance service via ESB.

The method processes one record per invocation within a batch loop (tracking `recordCnt` and `errCnt`), acting as a **shared batch utility** called by the batch framework for each input record. It delegates validation to `SingleCheckTUIFM012_INF1`, data retrieval to three self-contained SELECT methods, and core business processing to the external ESB service call. If any step fails, the error count increments and the batch continues to the next record (non-fatal per-record error handling).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execute_start"])

    START --> LOG1["Log: execution starts with phone number"]
    LOG1 --> REC["recordCnt++"]
    REC --> CHECK1["SingleCheckTUIFM012_INF1"]
    CHECK1 --> GETTEL["NTT_KEI_TEL_KAISEN_NO = inMap.getString"]
    GETTEL --> WHERESVC["whereParamSvcKeiUcwk = phone + opeDate"]
    WHERESVC --> SELSVC["executeKK_T_SVC_KEI_UCWK_TU_SELECT_005"]
    SELSVC --> FETCSVC["mapSvcKeiUcwk = db_KK_T_SVC_KEI_UCWK.selectNext"]

    FETCSVC --> COND1{SVC_KEI_UCWK_STAT check}

    COND1 -- "Status = 910 (cancelled)" --> WHERETEL2["whereParamSvkeiuwEohTel = phone + opeDate x2"]
    COND1 -- "Status != 910" --> END_NORETURN["Log: execute_END"]

    WHERETEL2 --> SELTEL2["executeKK_T_SVKEIUW_EOH_TEL_TU_SELECT_002"]
    SELTEL2 --> FETCTEL2["mapSvkeiuwEohTel = db_KK_T_SVKEIUW_EOH_TEL.selectNext"]

    FETCTEL2 --> COND2{EO Hikari Tel record exists}

    COND2 -- No --> SELTELNO["executeZM_M_TELNO_TU_SELECT_002"]
    COND2 -- Yes --> END_NORETURN

    SELTELNO --> FETCTELNO["mapTelno = db_ZM_M_TELNO.selectNext"]

    FETCTELNO --> COND3{Phone master record exists}

    COND3 -- No --> ERROR1["errCnt++"]
    COND3 -- Yes --> BUILD["Build paramMap + inputMap for SOD invocation"]

    ERROR1 --> ERRLOG1["Print error: no phone table record"]
    ERRLOG1 --> LOG_END1["Log: execute_END"]
    LOG_END1 --> RETN1["return null"]

    BUILD --> INVOK["JCCBatchEsbInterface.invokeService"]
    INVOK --> RCVRC["getReturnCode"]
    RCVRC --> LOGRC["Log: RETURN_CODE"]
    LOGRC --> COND4{returnCode == SUCCESS}

    COND4 -- Yes --> LOG_END2["Log: execute_END"]
    COND4 -- No --> ERROR2["errCnt++"]

    ERROR2 --> ERRLOG2["Print error: tariff cancel SOD error"]
    ERRLOG2 --> LOG_END2

    LOG_END2 --> RETN2["return null"]

    RETN1 --> LOG_END3["Log: execute_END"]
    LOG_END3 --> RETN3["return null"]
```

**Conditional Branch Summary:**

| Branch | Condition | Action |
|--------|-----------|--------|
| Branch 1 | `SVC_KEI_UCWK_STAT` != `"910"` (not cancellation completed) | Skip all SOD processing; fall through to END |
| Branch 2 | `SVC_KEI_UCWK_STAT` = `"910"` AND EO Hikari Tel record EXISTS | Not "in transit" (tokinaka); skip SOD processing; fall through to END |
| Branch 3 | `SVC_KEI_UCWK_STAT` = `"910"` AND EO Hikari Tel record MISSING AND Phone Master MISSING | Error: record does not exist in phone table; `errCnt++`; log error `ETUB0620CE`; return null |
| Branch 4 | `SVC_KEI_UCWK_STAT` = `"910"` AND EO Hikari Tel record MISSING AND Phone Master EXISTS AND SOD invocation SUCCESS | SOD issued successfully; fall through to END |
| Branch 5 | `SVC_KEI_UCWK_STAT` = `"910"` AND EO Hikari Tel record MISSING AND Phone Master EXISTS AND SOD invocation FAILED | Error: `errCnt++`; log error `ETUB0630CW`; fall through to END |

**Constant Resolution:**

| Constant | Actual Value | Business Meaning |
|----------|-------------|------------------|
| `JKKStrConst.SVC_KEI_UCWK_STAT_DSLZUMI` | `"910"` | Service contract status: cancellation completed (解約済み) |
| `IDO_KNUB` | `"09001"` | Differentiation code (data value) — input validation requirement |
| `USECASE_ID` | `"TUSV0109"` | User case ID for the SOD issuance service |
| `CHK_ADD` | `"1"` | Check & Register (function code) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Batch input record map containing the phone number to process for tariff cancellation. Carries fields including the NTT telephone number after conversion (`NTT_KEI_TEL_KAISEN_NO`) and the differentiation classification (`IDO_KUBUN`, which must equal `"09001"`). Each map represents one telephone number record from the batch input file. |

**Instance Fields Read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `recordCnt` | `int` | Running record count incremented per record — used in error log to identify which record caused an error |
| `errCnt` | `int` | Cumulative error counter across all processed records — checked in `terminal()` to determine warning termination |
| `commonItem` | `JBSbatCommonItem` (inherited) | Batch common parameters including the operation date (`getOpeDate()`) used as a filter in all DB queries |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `executeKK_T_SVC_KEI_UCWK_TU_SELECT_005` | - | `KK_T_SVC_KEI_UCWK` | Query service contract detail table by phone number and operation date |
| R | `executeKK_T_SVKEIUW_EOH_TEL_TU_SELECT_002` | - | `KK_T_SVKEIUW_EOH_TEL` | Query Service Contract EO Tel (Service Contract: EO Hikari Telephone) table by phone number and operation date |
| R | `executeZM_M_TELNO_TU_SELECT_002` | - | `ZM_M_TELNO` | Query phone number master table by phone number |
| - | `JCCBatchEsbInterface.invokeService` | `TUSV010901SC` | External SOD Service | Invoke external ESB service for SOD issuance (tariff cancellation order) |
| - | `JCCBatchEsbInterface.getReturnCode` | - | - | Extract return code from SOD service response |
| - | `SingleCheckTUIFM012_INF1` | - | - | Single-item validation check for batch input fields (phone number, differentiation classification) |
| - | `printDebugLog` | - | - | Debug logging wrapper (inherited `logPrint`) |
| - | `printBusinessErrorLog` | - | - | Business error logging wrapper (inherited `logPrint`) |

**Classification rationale:**

- **R (Read):** All three `executeKK_T_*_TU_SELECT_*` methods query the database via `JBSbatSQLAccess.selectBySqlDefine` and `selectNext()`. These retrieve service contract details, EO Hikari Tel auxiliary records, and phone number master records respectively.
- **- (Non-CRUD):** `JCCBatchEsbInterface.invokeService` is an ESB service call (not a direct CRUD operation). It invokes the external SOD issuance service identified by SC Code `TUSV010901SC`. `SingleCheckTUIFM012_INF1` is a validation utility method, not a data operation.

## 5. Dependency Trace

This method is a **batch service component** invoked by the batch framework. No Java-level caller class was found referencing it directly — it is registered and invoked through batch configuration (e.g., batch job XML definition or framework-level dispatcher) by the use case ID `TUSV0109`.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: TUSV0109 | Batch Framework -> JBSbatTUBmpHaishiSodHakTrn.execute() | `KK_T_SVC_KEI_UCWK [R]`, `KK_T_SVKEIUW_EOH_TEL [R]`, `ZM_M_TELNO [R]`, External SOD [R] TUSV010901SC |

**Notes:**
- The batch use case ID `TUSV0109` is embedded as a constant (`USECASE_ID`) and used in the service invocation parameter map.
- The terminal operations consist entirely of READs from three database tables plus an external ESB service call for SOD issuance.

## 6. Per-Branch Detail Blocks

**Block 1** — [EXEC] `logPrint.printDebugLog("execute_START: " + phone number)` (L141)

> Log the start of processing along with the phone number being processed.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `super.logPrint.printDebugLog("execute_START: " + inMap.getString(JBSbatTUIFM012.NTT_KEI_TEL_KAISEN_NO))` |

**Block 2** — [EXEC] `recordCnt++` (L144)

> Increment the per-record counter for this batch run.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `recordCnt++` // Record count increment |

**Block 3** — [EXEC] `SingleCheckTUIFM012_INF1(...)` (L147)

> Perform single-item validation on the batch input record. Validates that the differentiation classification (`IDO_KUBUN`) equals `"09001"` and that the phone number field is present. If validation fails, throws `JBSbatBusinessError`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `SingleCheckTUIFM012_INF1(inMap.getMap(), null)` // Single-item check for input fields |

**Block 4** — [SET] Extract phone number from input map (L149)

| # | Type | Code |
|---|------|------|
| 1 | SET | `NTT_KEI_TEL_KAISEN_NO = inMap.getString(JBSbatTUIFM012.NTT_KEI_TEL_KAISEN_NO)` // Phone number after conversion |

**Block 5** — [SET] Build WHERE clause for service contract table (L152-L154)

> Set up query parameters: phone number and operation date to look up service contract details.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereParamSvcKeiUcwk[0] = NTT_KEI_TEL_KAISEN_NO` // Phone number |
| 2 | SET | `whereParamSvcKeiUcwk[1] = commonItem.getOpeDate()` // Operation date |

**Block 6** — [CALL] Query service contract table (L157-L158)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_SVC_KEI_UCWK_TU_SELECT_005(whereParamSvcKeiUcwk)` |
| 2 | SET | `mapSvcKeiUcwk = db_KK_T_SVC_KEI_UCWK.selectNext()` |

**Block 7** — [IF] Check if service contract status is "910" (cancellation completed) (L160) `[JKKStrConst.SVC_KEI_UCWK_STAT_DSLZUMI = "910"]`

> Business rule: Only proceed with SOD issuance if the service contract status indicates "cancellation completed" (解約済み). The constant `SVC_KEI_UCWK_STAT_DSLZUMI` resolves to `"910"`.

| # | Type | Code |
|---|------|------|
| 1 | IF | `JKKStrConst.SVC_KEI_UCWK_STAT_DSLZUMI.equals(mapSvcKeiUcwk.getString("SVC_KEI_UCWK_STAT"))` |

**Block 7.1** — [ELSE-IF-THEN branch] Status = "910" (L164-L240)

> The service contract is confirmed as cancelled. Now determine whether the phone number is "in transit" (tokinaka, 施工中) by checking the EO Hikari Tel auxiliary table.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereParamSvkeiuwEohTel[0] = NTT_KEI_TEL_KAISEN_NO` // Phone number |
| 2 | SET | `whereParamSvkeiuwEohTel[1] = commonItem.getOpeDate()` // Operation date |
| 3 | SET | `whereParamSvkeiuwEohTel[2] = commonItem.getOpeDate()` // Operation date (duplicate for 3-element array) |
| 4 | CALL | `executeKK_T_SVKEIUW_EOH_TEL_TU_SELECT_002(whereParamSvkeiuwEohTel)` |
| 5 | SET | `mapSvkeiuwEohTel = db_KK_T_SVKEIUW_EOH_TEL.selectNext()` |

**Block 7.1.1** — [IF] Check if EO Hikari Tel record exists (L177)

> Business rule: If the EO Hikari Tel auxiliary table has NO record for this phone number, the service is NOT "in transit" (tokinaka, 施工中). This means the phone number is available for SOD processing.

| # | Type | Code |
|---|------|------|
| 1 | IF | `mapSvkeiuwEohTel == null` // EO Hikari Tel record does NOT exist = not in transit |

**Block 7.1.1.1** — [THEN branch] EO Hikari Tel record MISSING — query phone master table (L183-L197)

> Query the phone number master table (`ZM_M_TELNO`) to retrieve the update timestamp and verify the phone number record exists.

| # | Type | Code |
|---|------|------|
| 1 | SET | `whereParamTelno[0] = NTT_KEI_TEL_KAISEN_NO` // Phone number |
| 2 | CALL | `executeZM_M_TELNO_TU_SELECT_002(whereParamTelno)` |
| 3 | SET | `mapTelno = db_ZM_M_TELNO.selectNext()` |

**Block 7.1.1.1.1** — [IF] Check if phone master record exists (L199)

> If the phone number master table has no record for the given phone number, the input is invalid. This is a fatal per-record error.

| # | Type | Code |
|---|------|------|
| 1 | IF | `mapTelno == null` // Phone master record does NOT exist |

**Block 7.1.1.1.1.1** — [THEN] Phone master record MISSING — error (L203-L207)

> Error case: The phone number exists in the service contract and EO Hikari Tel tables are absent, but the phone master table itself has no record. This indicates data inconsistency. Increment error count, log error `ETUB0620CE` with message "No record exists in phone number table", and return null (skip this record).

| # | Type | Code |
|---|------|------|
| 1 | SET | `errCnt++` // Increment error counter |
| 2 | CALL | `super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.EKKB0010CW, new String[]{"No record exists in phone number table. Phone number: " + NTT_KEI_TEL_KAISEN_NO})` // Error ETUB0620CE |
| 3 | CALL | `super.logPrint.printDebugLog("execute_END")` |
| 4 | RETURN | `return null` |

**Block 7.1.1.1.1.2** — [ELSE] Phone master record FOUND — build and invoke SOD service (L211-L242)

> All three data checks have passed. Construct the input parameter map for the external SOD issuance service, populate it with phone number, service contract details, and movement classification, then invoke the ESB service.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `super.logPrint.printDebugLog("Service invocation")` |
| 2 | SET | `paramMap = new HashMap<>()` // Use case ID map |
| 3 | SET | `paramMap.put(TELEGRAM_INFO_USECASE_ID, USECASE_ID)` // USECASE_ID = "TUSV0109" |
| 4 | SET | `inputMap = new HashMap<Object, Object>()` // Input data map |
| 5 | SET | `dataMap = new HashMap<Object, Object>()` // Data content map |
| 6 | SET | `dataMap.put(FUNC_CODE, CHK_ADD)` // CHK_ADD = "1" (Check & Register) |
| 7 | SET | `dataMap.put(TELNO, NTT_KEI_TEL_KAISEN_NO)` // Phone number |
| 8 | SET | `dataMap.put(LAST_UPD_DTM_BF, mapTelno.getString("UPD_DTM"))` // Previous update timestamp from phone master |
| 9 | SET | `trgtDataList = new ArrayList<HashMap<String, HashMap<String, String>>>()` // Target data list |
| 10 | SET | `sodMap = new HashMap<String, HashMap<String, String>>()` // SOD map |
| 11 | SET | `sodKihonInfo = new HashMap<String, String>()` // SOD basic info |
| 12 | SET | `sodKihonInfo.put(IDO_DIV, inMap.getString(JBSbatTUIFM012.IDO_KUBUN))` // Movement classification |
| 13 | SET | `sodKihonInfo.put(TELNO, NTT_KEI_TEL_KAISEN_NO)` // Phone number |
| 14 | SET | `sodMap.put(SOD_KIHON_INFO, sodKihonInfo)` // Set basic info into SOD map |
| 15 | SET | `svckeiinfo = new HashMap<String, String>()` // Service contract info |
| 16 | SET | `svckeiinfo.put(SVC_KEI_NO, mapSvcKeiUcwk.getString("SVC_KEI_NO"))` // Service contract number |
| 17 | SET | `sodMap.put(SVC_KEI_INFO, svckeiinfo)` // Set contract info into SOD map |
| 18 | SET | `trgtDataList.add(sodMap)` // Add SOD map to target list |
| 19 | SET | `dataMap.put(TRGT_DATA_LIST, trgtDataList)` // Set target list into data map |
| 20 | SET | `inputMap.put(TITLE_1, dataMap)` // Set data map under SC code key `TUSV010901SC` |
| 21 | SET | `outputMap = new HashMap<Object, Object>()` // Output result map |
| 22 | CALL | `JCCBatchEsbInterface.invokeService(commonItem, paramMap, inputMap, outputMap)` // Invoke external SOD service |
| 23 | SET | `returnCode = JCCBatchEsbInterface.getReturnCode(outputMap)` // Get return code |
| 24 | CALL | `super.logPrint.printDebugLog("RETURN_CODE:" + returnCode)` |

**Block 7.1.1.1.1.2.1** — [IF] Check SOD service return code (L244)

> If the external SOD service does not return a SUCCESS return code, log the error but continue processing (do not return early — the batch continues to the next record).

| # | Type | Code |
|---|------|------|
| 1 | IF | `!JCCBatchEsbInterface.RETURN_CODE_SUCCESS.equals(returnCode)` |

**Block 7.1.1.1.1.1.2.1.1** — [THEN] SOD invocation FAILED (L248-L250)

> Error case: The external SOD service returned a non-success return code. Increment error count and log error `ETUB0630CW` with the return code, record count, and phone number for troubleshooting.

| # | Type | Code |
|---|------|------|
| 1 | SET | `errCnt++` // Increment error counter |
| 2 | CALL | `super.logPrint.printBusinessErrorLog(JPCBatchMessageConstant.ETUB0630CW, new String[]{"Error occurred in tariff cancellation SOD issuance (return code):" + returnCode + ":" + recordCnt + ":" + NTT_KEI_TEL_KAISEN_NO})` // Error ETUB0630CW |

**Block 8** — [ELSE branch of Block 7] Status != "910" (L252)

> The service contract status is NOT "910" (cancellation completed). This means either the contract is still active or has a different status. Skip all SOD processing for this record. Fall through to the end.

**Block 9** — [EXEC] Final logging and return (L253-L254)

> Regardless of the branch taken, log completion and return null. The batch framework handles the null return and continues to the next record.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `super.logPrint.printDebugLog("execute_END")` |
| 2 | RETURN | `return null` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `NTT_KEI_TEL_KAISEN_NO` | Field | NTT line telephone number after conversion — the phone number identifier for the service contract line being processed |
| `SVC_KEI_UCWK_STAT` | Field | Service contract detail status — indicates the current state of a service contract line item (e.g., active, cancelled) |
| `IDO_KUBUN` | Field | Movement classification — distinguishes between different types of service movements or transitions |
| `SVC_KEI_NO` | Field | Service contract number — unique identifier for a service contract |
| `IDO_KNUB` | Field | Differentiation code (data value) — internal code `"09001"` used to differentiate batch input types |
| `UPD_DTM` | Field | Update date-time — timestamp of the last modification to the phone number master record |
| 番ポ廃止 (Banpo Haishi) | Business term | Tariff cancellation / telephone number plan cancellation — the business process of cancelling a telephone number's assigned tariff plan when a customer terminates their service |
| SOD | Acronym | Service Order Data — an order data structure used for telecom service fulfillment operations |
| ESB | Acronym | Enterprise Service Bus — middleware framework for integrating systems via service invocations |
| 解約済み (Kaishazumi) | Business term | Cancellation completed — the state where a service contract has been fully terminated (represented by status code `"910"`) |
| 施工中 (Shukouchuu) | Business term | In transit / in progress — the state where work is being performed on a service (represented by the presence of a record in the EO Hikari Tel auxiliary table) |
| eo電話 (eo Denwa) | Business term | eo Telephone — K-Opticom's telecommunications brand/service line |
| FTTH | Business term | Fiber To The Home — fiber-optic broadband service delivered to residential premises |
| KK_T_SVC_KEI_UCWK | DB Table | Service Contract Detail Table — stores service contract line item records including status, phone number, and contract number |
| KK_T_SVKEIUW_EOH_TEL | DB Table | Service Contract EO Hikari Telephone Table — auxiliary table tracking EO Hikari telephone service records, used to determine if work is in progress |
| ZM_M_TELNO | DB Table | Phone Number Master Table — master reference table for telephone numbers, containing phone number records and update timestamps |
| TUSV0109 | Constant | Use case ID for the tariff cancellation SOD issuance service |
| TUSV010901SC | Constant | SC (Service Component) code key used as the title key in the ESB input map for the SOD issuance service |
| ETUB0620CE | Error Code | Error indicating no record exists in the phone number table |
| ETUB0630CW | Error Code | Error indicating an error occurred during tariff cancellation SOD issuance |
| ETUB0640CI | Error Code | Warning termination message displayed when errors occurred for a specified number of records (checked in `terminal()`) |
| JBSbatBusinessService | Base Class | Base class for batch business services providing common functionality including `setCommonInfo`, `logPrint`, and `commonItem` |
| JBSbatServiceInterfaceMap | Class | Batch input record container — holds the key-value pairs for a single batch input record |
| JBSbatOutputItem | Class | Batch output item — return type for the execute method (always `null` in this implementation) |
| `FUNC_CODE` | Field | Function code — key for the `dataMap` in the ESB input structure; value `"1"` means Check & Register |
| `CHK_ADD` | Constant | Check & Register function code value = `"1"` |
| `TRGT_DATA_LIST` | Field | Target data list — key for the list of SOD data maps in the ESB input structure |
| `SOD_KIHON_INFO` | Field | SOD basic information — key for the basic SOD data map containing phone number and movement classification |
| `SVC_KEI_INFO` | Field | Service contract information — key for the service contract data map containing the contract number |
| `TELNO` | Field | Phone number — key for the phone number field in ESB data maps |
| `IDO_DIV` | Field | Movement division — key for the movement classification in the SOD basic info map |
| `LAST_UPD_DTM_BF` | Field | Last update date-time before — key for the previous update timestamp in the ESB data map |
| `TITLE_1` | Constant | Title key = `"TUSV010901SC"` — used as the key for the data map in the ESB input structure |
