# Business Logic — JBSbatKKSvkeiuwDelTgCst.setDelTrgtDataTel() [112 LOC]

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

## 1. Role

### JBSbatKKSvkeiuwDelTgCst.setDelTrgtDataTel()

This method is the **deletion-target data setup processing for telephone services** (消去対象データ設定処理（電話サービス）). It is invoked by the `execute()` method of the same class when the incoming service code identifies a **telephone service** (電話サービス) as opposed to a net service. Its purpose is to determine which telephone-related data fields (an OABJ telephone number and a SIP user ID) should be marked for deletion (消去) as part of a service contract termination or revision workflow.

The method implements a **routing/dispatch pattern** within the telephone service branch: it first checks whether the service contract has passed its recovery-possible period (a grace-period safeguard). If the contract is still within the allowable window, it queries the OABJ telephone number from `KK_T_SVKEIUW_EOH_TEL` and, if found, validates it against a deletion-target filter (`isDelTrgtNoDataTel`). If the telephone number qualifies, it builds an output map with `DEL_TRGT_SBT_OABJ_TLN` ("09") and adds it to the output. Separately, it then queries the SIP user ID from the same table and, if found, builds a second output map with `DEL_TRGT_SBT_SIP_USER_ID` ("17") and adds it. Both output maps use `DEL_TRAN_SBT_AGING_UPD` ("2") as the deletion process type, indicating an aging update operation rather than a full SOD cancellation.

This method acts as a **shared data-preparation utility** called from the batch entry point `execute()`. It does not directly modify the database; rather, it assembles structured output maps that downstream processing will consume to perform the actual deletions or aging updates. The method was originally introduced in v1.00.00 (2012/04/19) and extended in v5.00.01 (2013/02/13) to add SIP user ID support.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["setDelTrgtDataTel(inMap, outputBean)"])
    START --> INIT["Initialize outmap, outmap2, nextRec"]
    INIT --> PRC_GRP_SET["Set PRC_GRP_CD from inMap"]
    PRC_GRP_SET --> PRC_GRP_SELECT["executeKK_M_PRC_GRP_KK_SELECT_008"]
    PRC_GRP_SELECT --> PRC_GRP_FETCH["db_KK_M_PRC_GRP.selectNext()"]
    PRC_GRP_FETCH --> PRC_GRP_NULL{nextRec is null?}
    PRC_GRP_NULL -->|Yes| END_RETURN(["Return / end"])
    PRC_GRP_NULL -->|No| FETCH_FIELDS["Fetch svcEndYmd and kaihkPsbPrd"]
    FETCH_FIELDS --> OVER_DATE_CHECK{"isOverDate(svcEndYmd, kaihkPsbPrd)?"}
    OVER_DATE_CHECK -->|true| END_RETURN
    OVER_DATE_CHECK -->|false| TEL_SELECT["executeKK_T_SVKEIUW_EOH_TEL_KK_SELECT_018"]
    TEL_SELECT --> TEL_FETCH["db_KK_T_SVKEIUW_EOH_TEL.selectNext()"]
    TEL_FETCH --> TEL_NULL{nextRec is null?}
    TEL_NULL -->|Yes| CALL_SIP_SELECT
    TEL_NULL -->|No| DEL_TRGT_CHECK{"isDelTrgtNoDataTel(oabjTelno)?"}
    DEL_TRGT_CHECK -->|true| CALL_SIP_SELECT
    DEL_TRGT_CHECK -->|false| BUILD_OUTMAP_09["Build outmap: DEL_TRGT_SBT_OABJ_TLN"]
    BUILD_OUTMAP_09 --> SET_OUTMAP_FLG_09["outmap.setOutFlg(true)"]
    SET_OUTMAP_FLG_09 --> ADD_OUTMAP_09["outputBean.addOutMapList(outmap)"]
    ADD_OUTMAP_09 --> CALL_SIP_SELECT
    CALL_SIP_SELECT["executeKK_T_SVKEIUW_EOH_TEL_KK_SELECT_037"]
    CALL_SIP_SELECT --> SIP_FETCH["db_KK_T_SVKEIUW_EOH_TEL.selectNext()"]
    SIP_FETCH --> SIP_NULL{nextRec is null?}
    SIP_NULL -->|Yes| END_RETURN
    SIP_NULL -->|No| BUILD_OUTMAP_17["Build outmap2: DEL_TRGT_SBT_SIP_USER_ID"]
    BUILD_OUTMAP_17 --> SET_OUTMAP_FLG_17["outmap2.setOutFlg(true)"]
    SET_OUTMAP_FLG_17 --> ADD_OUTMAP_17["outputBean.addOutMapList(outmap2)"]
    ADD_OUTMAP_17 --> END_RETURN
```

**Branch semantics:**
- The recovery-period check (`isOverDate`) acts as a **grace-period guard**: if the service end date plus the recovery-possible period has already passed (current date >= end date + recovery period), the method returns immediately — no deletion targets are set.
- The OABJ telephone number query may return no record; in that case, only the SIP user ID path is pursued.
- If the telephone number IS found but fails the `isDelTrgtNoDataTel` filter, the record is excluded from the output (no `addOutMapList` call) but processing continues to the SIP user ID query.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | The input command envelope carrying the service contract data for the current batch processing unit. It contains the service contract number (`SVC_KEI_NO`), service contract sub-details number (`SVC_KEI_UCWK_NO`), service end date (`SVC_ENDYMD`), generation/addition datetime (`GENE_ADD_DTM`), and the price group code (`PRC_GRP_CD`) needed to look up the recovery-possible period from the price group master. |
| 2 | `outputBean` | `JBSbatOutputItem` | The output collection to which prepared deletion-target maps are appended. Each map added here will be consumed by downstream processing to determine what data needs to be deleted or aged updated for the telephone service contract. |

**Instance fields read by this method:**

| # | Field | Source Class | Business Description |
|---|-------|-------------|---------------------|
| 1 | `super.opeDate` | `JBSbatBusinessService` | The operation date (current batch processing date) used as a filter parameter for the SQL queries. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKK_M_PRC_GRP_KK_SELECT_008` | KK_SELECT_008 | `KK_M_PRC_GRP` (Price Group Master) | Queries the recovery-possible period (`KAIHK_PSB_PRD`) for the given price group code |
| R | `JBSbatKK_T_SVKEIUW_EOH_TEL_KK_SELECT_018` | KK_SELECT_018 | `KK_T_SVKEIUW_EOH_TEL` (Service Contract Details <EO Telecom>) | Queries the OABJ telephone number record by service contract sub-details number, generation date, and operation date |
| R | `JBSbatKK_T_SVKEIUW_EOH_TEL_KK_SELECT_037` | KK_SELECT_037 | `KK_T_SVKEIUW_EOH_TEL` (Service Contract Details <EO Telecom>) | Queries the SIP user ID record using the same key parameters as SELECT_018 |
| - | `JBSbatKKGetCTITelno.addOutMapList` | - | - | Calls `addOutMapList` on the output bean (write-side output accumulation) |
| - | `JBSbatACIcjknTrkmRsltHenshu.setOutFlg` | - | - | Calls `setOutFlg` on `outmap` / `outmap2` to mark the record as valid output |
| - | `JBSbatServiceInterfaceMap.setString` | - | - | Calls `setString` on `outmap` and `outmap2` to populate deletion-type, deletion-target-type, service contract number, generation datetime, sub-details number, generation datetime, and the data field (telephone number or SIP user ID) |
| - | `JBSbatKKSvkeiuwDelTgCst.isDelTrgtNoDataTel` | - | - | Calls the internal method that checks whether a telephone number should be excluded from deletion targets |
| - | `JBSbatKKSvkeiuwDelTgCst.isOverDate` | - | - | Calls the internal date-comparison method to evaluate if the service end date plus recovery period has been exceeded |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: `addOutMapList` [C], `setOutFlg` [-], `setOutFlg` [-], `setString` [-], `setString` [-], `setString` [-], `setString` [-], `setString` [-], `setString` [-], `getString` [R], `getString` [R], `getString` [R], `getString` [R], `getString` [R], `setString` [-], `setString` [-], `setString` [-], `setString` [-], `setString` [-], `getString` [R], `getString` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKSvkeiuwDelTgCst.execute | `JBSbatKKSvkeiuwDelTgCst.execute` (svcCd=="xx" branch) -> `setDelTrgtDataTel(inMap, outputBean)` | `executeKK_M_PRC_GRP_KK_SELECT_008 [R] KK_M_PRC_GRP`, `executeKK_T_SVKEIUW_EOH_TEL_KK_SELECT_018 [R] KK_T_SVKEIUW_EOH_TEL`, `executeKK_T_SVKEIUW_EOH_TEL_KK_SELECT_037 [R] KK_T_SVKEIUW_EOH_TEL`, `addOutMapList [C] outputBean`, `setOutFlg [-] outmap/outmap2` |

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `nextRec != null` (from `db_KK_M_PRC_GRP.selectNext()`) (L343)

> After executing the price group query and fetching the next record, check if a valid recovery-possible-period record was returned.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcEndYmd = inMap.getString(JBSbatKK_T_SVC_KEI.SVC_ENDYMD);` // Service end date — the date the service contract ends |
| 2 | SET | `kaihkPsbPrd = nextRec.getString(JBSbatKK_M_PRC_GRP.KAIHK_PSB_PRD);` // Recovery-possible period (in days) from the price group master table |

**Block 1.1** — [IF] `isOverDate(svcEndYmd, kaihkPsbPrd)` (L347)

> Grace-period guard: if the current operation date has exceeded `svcEndYmd + kaihkPsbPrd`, abort all deletion-target setup for this contract.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // Early exit — recovery period has passed, no deletion targets set |

**Block 1.2** — [IF] `nextRec != null` (from `db_KK_T_SVKEIUW_EOH_TEL.selectNext()` after SELECT_018) (L367)

> After querying the OABJ telephone number, check if a record was found in the telecom details table.

| # | Type | Code |
|---|------|------|
| 1 | SET | `selectWhereParam[0] = inMap.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO);` // Service contract sub-details number |
| 2 | SET | `selectWhereParam[1] = inMap.getString("UCWK_GENE");` // Generation datetime (ST1-2012-0000591: using "UCWK_GENE" as distinct alias) |
| 3 | SET | `selectWhereParam[2] = super.opeDate;` // Operation date (filter) |
| 4 | SET | `selectWhereParam[3] = super.opeDate;` // Operation date (filter) |
| 5 | CALL | `executeKK_T_SVKEIUW_EOH_TEL_KK_SELECT_018(selectWhereParam);` // Query OABJ telephone number |
| 6 | EXEC | `nextRec = db_KK_T_SVKEIUW_EOH_TEL.selectNext();` // Fetch the result row |

**Block 1.2.1** — [IF] `!isDelTrgtNoDataTel(inMap, nextRec.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO))` (L374)

> Deletion-target filter: if the OABJ telephone number is NOT excluded (i.e., it IS a deletion target), build an output map entry with deletion-target type "09" (OABJ telephone number).
> Note: Per IT1-2013-0000285, this was modified in v5.00.01 — previously the check was inverted and returned early; now non-qualifying records are excluded but processing continues to the SIP user ID path.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap.setString(JBSbatKKIFM160.DEL_TRAN_SBT, DEL_TRAN_SBT_AGING_UPD);` // [DEL_TRAN_SBT_AGING_UPD="2"] Deletion process type: Aging Update (not full SOD cancellation) |
| 2 | SET | `outmap.setString(JBSbatKKIFM160.DEL_TRGT_SBT, DEL_TRGT_SBT_OABJ_TLN);` // [DEL_TRGT_SBT_OABJ_TLN="09"] Deletion target type: OABJ Telephone Number |
| 3 | SET | `outmap.setString(JBSbatKKIFM160.SVKEI_NO, inMap.getString(JBSbatKK_T_SVC_KEI.SVC_KEI_NO));` // Service contract number |
| 4 | SET | `outmap.setString(JBSbatKKIFM160.SVKEI_GADTM, inMap.getString(JBSbatKK_T_SVC_KEI.GENE_ADD_DTM));` // Service contract generation registration datetime |
| 5 | SET | `outmap.setString(JBSbatKKIFM160.SVKEIUW_NO, inMap.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO));` // Service contract sub-details number |
| 6 | SET | `outmap.setString(JBSbatKKIFM160.SVKEIUW_GADTM, inMap.getString("UCWK_GENE"));` // Service contract sub-details generation registration datetime |
| 7 | SET | `outmap.setString(JBSbatKKIFM160.OABJ_TELNO, nextRec.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.TELNO));` // OABJ telephone number (from DB query result) |
| 8 | EXEC | `outmap.setOutFlg(true);` // Flag this map as valid output |
| 9 | CALL | `outputBean.addOutMapList(outmap);` // Append to the output collection |

**Block 1.3** — [AFTER Block 1.2 chain] SIP User ID path (L387)

> Regardless of whether an OABJ telephone number was found (or whether it passed the deletion filter), the SIP user ID is independently queried from the same table and, if present, a second output map is built with deletion-target type "17" (SIP User ID).
> Added in IT1-2013-0000285 v5.00.01.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_SVKEIUW_EOH_TEL_KK_SELECT_037(selectWhereParam);` // Query SIP user ID (same key params as SELECT_018) |
| 2 | EXEC | `nextRec = db_KK_T_SVKEIUW_EOH_TEL.selectNext();` // Fetch the result row |

**Block 1.3.1** — [IF] `nextRec != null` (from SIP user ID query) (L391)

> If a SIP user ID record was found, build a second output map entry with deletion-target type "17" (SIP User ID).

| # | Type | Code |
|---|------|------|
| 1 | SET | `outmap2.setString(JBSbatKKIFM160.DEL_TRAN_SBT, DEL_TRAN_SBT_AGING_UPD);` // [DEL_TRAN_SBT_AGING_UPD="2"] Deletion process type: Aging Update |
| 2 | SET | `outmap2.setString(JBSbatKKIFM160.DEL_TRGT_SBT, DEL_TRGT_SBT_SIP_USER_ID);` // [DEL_TRGT_SBT_SIP_USER_ID="17"] Deletion target type: SIP User ID |
| 3 | SET | `outmap2.setString(JBSbatKKIFM160.SVKEI_NO, inMap.getString(JBSbatKK_T_SVC_KEI.SVC_KEI_NO));` // Service contract number |
| 4 | SET | `outmap2.setString(JBSbatKKIFM160.SVKEI_GADTM, inMap.getString(JBSbatKK_T_SVC_KEI.GENE_ADD_DTM));` // Service contract generation registration datetime |
| 5 | SET | `outmap2.setString(JBSbatKKIFM160.SVKEIUW_NO, inMap.getString(JBSbatKK_T_SVC_KEI_UCWK.SVC_KEI_UCWK_NO));` // Service contract sub-details number |
| 6 | SET | `outmap2.setString(JBSbatKKIFM160.SVKEIUW_GADTM, inMap.getString("UCWK_GENE"));` // Service contract sub-details generation registration datetime |
| 7 | SET | `outmap2.setString(JBSbatKKIFM160.SIP_USER_ID, nextRec.getString(JBSbatKK_T_SVKEIUW_EOH_TEL.SIP_USER_ID));` // SIP User ID (from DB query result) |
| 8 | EXEC | `outmap2.setOutFlg(true);` // Flag this map as valid output |
| 9 | CALL | `outputBean.addOutMapList(outmap2);` // Append to the output collection |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `setDelTrgtDataTel` | Method | Deletion-target data setup processing for telephone services — prepares output records identifying which fields should be deleted/aged for telecom contract cancellations |
| `svcEndYmd` | Field | Service end date (YYYYMMDD) — the date the service contract is scheduled to end |
| `kaihkPsbPrd` | Field | Recovery-possible period — the number of days after service end during which the contract can still be restored; if this window has passed, deletion processing is skipped |
| `PRC_GRP_CD` | Field | Price group code — classifies the billing group for the service (e.g., eo光ネット home type, eo Mobile, eo ADSL); used to look up the recovery-possible period |
| `SVC_KEI_NO` | Field | Service contract number — unique identifier for a service contract line |
| `SVC_KEI_UCWK_NO` | Field | Service contract sub-details number — unique identifier for a sub-line within a service contract (e.g., an individual telephone number line under a bundled internet + phone package) |
| `GENE_ADD_DTM` / `UCWK_GENE` | Field | Generation/addition datetime — the timestamp when the service contract (or sub-details) was originally registered in the system |
| `OABJ_TELNO` | Field | OABJ telephone number — the primary telephone number associated with the telecom service contract; "OABJ" is an internal code for the main subscriber number |
| `SIP_USER_ID` | Field | SIP User ID — the Session Initiation Protocol user identifier used for VoIP service authentication and routing |
| `DEL_TRAN_SBT` | Field | Deletion process type — classifies the kind of deletion operation; "2" means Aging Update (エージング更新), meaning the data is flagged for aging rather than immediate removal |
| `DEL_TRAN_SBT_AGING_UPD` | Constant | "2" — Deletion process type: Aging Update (消去処理種類: エージング更新). The record is marked for aging processing, not outright deletion. |
| `DEL_TRGT_SBT` | Field | Deletion target type — classifies what kind of data is being deleted |
| `DEL_TRGT_SBT_OABJ_TLN` | Constant | "09" — Deletion target type: OABJ Telephone Number (消去対象種類: OABJ電話番号) |
| `DEL_TRGT_SBT_SIP_USER_ID` | Constant | "17" — Deletion target type: SIP User ID (消去対象種類: SIPユーザーID) |
| `KK_M_PRC_GRP` | Table | Price Group Master table — stores billing group definitions and their recovery-possible periods |
| `KK_T_SVKEIUW_EOH_TEL` | Table | Service Contract Details (EO Telecom) table — stores telecom service contract sub-details records including telephone numbers and SIP user IDs |
| `db_KK_M_PRC_GRP` | Instance field | Database access object for the price group master table |
| `db_KK_T_SVKEIUW_EOH_TEL` | Instance field | Database access object for the telecom service contract details table |
| `isOverDate` | Method | Internal date-comparison helper — returns true if `svcEndYmd + recoveryPeriod <= opeDate` |
| `isDelTrgtNoDataTel` | Method | Internal deletion-target filter — returns true if the given telephone number should be EXCLUDED from deletion processing |
| `SVC_CD_TEL_SVC` | Constant | Service code for telephone service (电话サービス), used in `execute()` to dispatch to `setDelTrgtDataTel` |
| `opecDate` | Field | Operation date (current batch processing date) — inherited from the parent `JBSbatBusinessService` class |
| `JBSbatOutputItem` | Class | Output collection bean — accumulates deletion-target maps to be passed to downstream processing |
| `JBSbatServiceInterfaceMap` | Class | Key-value map used to pass structured data between service methods |
