---

# Business Logic — JBSbatKKDelKhChk.agingTrgtGai() [76 LOC]

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

## 1. Role

### JBSbatKKDelKhChk.agingTrgtGai()

The `agingTrgtGai` method determines whether a customer account deletion target is **excluded from aging processing**. In the context of Kopt (Kanta Otsureshimai = proactive customer retention) batch processing, aging refers to the state transition tracking of customer records that are pending cancellation or deletion. Before a deletion target is actually removed from the system, the batch checks whether it is subject to aging; if so, the aging update process will handle the status transition and the deletion can proceed once aging completes. If this method returns `true`, the deletion target is **not** a subject of aging (エイジング対象外), and the batch may proceed with deletion immediately.

The method implements a **conditional dispatch pattern** based on the deletion target subtype (`delTrgtSbt`). It handles two distinct service categories: (1) **eoID-based deletions** (subtype "11"), where the method queries the customer master table (`CK_T_CUST`) to verify whether the current eoID matches the initial (assignment) eoID, or whether the eoID is a special 12-digit number starting with "51"; and (2) **OABJ (Operator Assigned) telephone number deletions** (subtype "09"), where the method queries the aging management table (`ZM_T_AGING`) to check whether an aging record with status "aging in progress" (300) already exists for the given telephone number.

This method serves as a **shared utility** within the deletion check subsystem, called by `JBSbatKKDelKhChk.execute()`, which is the main batch entry point for deletion target validation. Its role is to short-circuit aging checks for records that should bypass aging processing entirely, ensuring that certain deletion types (initial account creations, 51-prefix numbers, and in-progress aging targets) are handled correctly without double-processing.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["agingTrgtGai inMap"])
    CHECK_RET_FLG(["Initialize retFlg equals false"])
    CHECK_DEL_TRGT_SBT(["Get delTrgtSbt from inMap DEL_TRGT_SBT"])
    
    COND_DEL_TYPE{"delTrgtSbt equals constant?"}
    
    BRANCH_EOID["DEL_TRGT_SBT_EOID equals 11"]
    BRANCH_OABJ_TELNO["DEL_TRGT_SBT_OABJ_TELNO equals 09"]
    
    BRANCH_EOID_STEP1["Query CK_T_CUST selectNext"]
    BRANCH_EOID_STEP2["Get shkEoid initial eoID"]
    BRANCH_EOID_STEP3["Get tmpEoid current eoID"]
    
    COND_EOID_MATCH{"shkEoid equals tmpEoid?"}
    COND_EOID_FORMAT_1{"tmpEoid valid format?"}
    
    COND_EOID_VALID{"tmpEoid valid"}
    COND_EOID_PREFIX{"tmpEoid starts with 51"}
    COND_EOID_DIGIT{"All digits count 12"}
    COND_EOID_HANKAKU{"All half-width"}
    
    SET_RET_TRUE_EOID["retFlg equals true - Initial eoID match"]
    SET_RET_TRUE_EOID2["retFlg equals true - 51-prefix 12-digit"]
    
    BRANCH_OABJ_STEP1["Set aging params"]
    BRANCH_OABJ_STEP2["Query ZM_T_AGING selectNext"]
    BRANCH_OABJ_STEP3["Get nextRec from db_ZM_T_AGING"]
    
    COND_OABJ_NEXT{"nextRec not null?"}
    
    SET_RET_TRUE_OABJ["retFlg equals true - Aging in progress"]
    
    RETURN["return retFlg"]
    
    START --> CHECK_RET_FLG --> CHECK_DEL_TRGT_SBT --> COND_DEL_TYPE
    COND_DEL_TYPE -->|delTrgtSbt equals 11| BRANCH_EOID_STEP1
    COND_DEL_TYPE -->|delTrgtSbt equals 09| BRANCH_OABJ_STEP1
    COND_DEL_TYPE -->|Other| RETURN
    
    BRANCH_EOID_STEP1 --> BRANCH_EOID_STEP2 --> BRANCH_EOID_STEP3 --> COND_EOID_MATCH
    COND_EOID_MATCH -->|Yes| SET_RET_TRUE_EOID --> RETURN
    COND_EOID_MATCH -->|No| COND_EOID_FORMAT_1
    
    COND_EOID_FORMAT_1 --> COND_EOID_VALID
    COND_EOID_VALID -->|Yes| COND_EOID_PREFIX
    COND_EOID_VALID -->|No| RETURN
    COND_EOID_PREFIX -->|Yes| COND_EOID_DIGIT
    COND_EOID_PREFIX -->|No| RETURN
    COND_EOID_DIGIT -->|Yes| COND_EOID_HANKAKU
    COND_EOID_DIGIT -->|No| RETURN
    COND_EOID_HANKAKU -->|Yes| SET_RET_TRUE_EOID2 --> RETURN
    COND_EOID_HANKAKU -->|No| RETURN
    
    BRANCH_OABJ_STEP1 --> BRANCH_OABJ_STEP2 --> BRANCH_OABJ_STEP3 --> COND_OABJ_NEXT
    COND_OABJ_NEXT -->|Yes| SET_RET_TRUE_OABJ --> RETURN
    COND_OABJ_NEXT -->|No| RETURN
```

**Business logic summary:**

1. The method initializes `retFlg = false` (default: IS a subject of aging / 対象).
2. It reads the deletion target subtype (`delTrgtSbt`) from the input map.
3. If the subtype is **"11" (eoID)**, it queries the customer master to retrieve the initial (assignment) eoID (`SHK_EOID`) and compares it against the current eoID. If they match, the record is excluded from aging (returns `true`). Additionally, if the eoID is a 12-digit number starting with "51" (all half-width digits), it is also excluded — this represents a special legacy pattern (OM-2018-0000709, 2018/07/19).
4. If the subtype is **"09" (OABJ telephone number)**, it queries the aging management table for any aging record with status "aging in progress" (300). If a matching record exists, the deletion is excluded from aging (returns `true`) because the aging update is already underway — this avoids double-processing. This branch was added in ANK-4494-00-00 (2024/11/13).
5. For any other subtype, the method returns `false` (default: IS a subject of aging).

**CRITICAL — Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|------------------|
| `DEL_TRGT_SBT_EOID` | `"11"` | Delete target subtype: eoID-based deletion |
| `DEL_TRGT_SBT_OABJ_TELNO` | `"09"` | Delete target subtype: OABJ (Operator Assigned) telephone number deletion |
| `AGING_SBT_CD_TELNO` | `"001"` | Aging subtype code: OABJ telephone number |
| `AGING_STAT_AGING_CHU` | `"300"` | Aging status: Aging in progress (エイジング中) |
| `MK_FLG_YK` | `"0"` | Mark flag: Use/Yes (yield/availability indicator) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | A service interface map carrying the deletion target context. It contains key data fields including `DEL_TRGT_SBT` (deletion target subtype code that determines which exclusion branch to follow), `SYSID` (system ID for customer identification), `EOID` (the current enterprise account ID), `OABJ_TELNO` (the operator-assigned telephone number being deleted). The values in this map are used to query the customer master and aging tables to determine whether aging processing should be bypassed. |

**Instance fields and external state read:**

| Field | Source | Business Description |
|-------|--------|---------------------|
| `opeDate` | Instance field of `JBSbatKKDelKhChk` | Operation date — the current batch run date used as a filter when querying the customer master table |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatKKDelKhChk.executeCK_T_CUST_KK_SELECT_002` | CK_T_CUST_SELECT_002 | `CK_T_CUST` | Queries the customer master table to retrieve the initial (assignment) eoID (`SHK_EOID`) for a given system ID and operation date. Used in the eoID exclusion branch. |
| R | `JBSbatCommonDBInterface selectNext` | db_CK_T_CUST | `CK_T_CUST` | Retrieves the next row from the result set of the customer master query. Returns the `shkEoid` (initial eoID). |
| R | `JBSbatKKDelKhChk.executeZM_T_AGING_KK_SELECT_002` | ZM_T_AGING_SELECT_002 | `ZM_T_AGING` | Queries the aging management table to check for existing aging records matching the service subtype, target value, aging status, and mark flag. Used in the OABJ telephone number exclusion branch. |
| R | `JBSbatKKDelKhChk.getAgingParam` | internal utility | - | Builds an Object[] array of aging query parameters (service subtype code, target value, aging status, mark flag). Internal helper method. |
| R | `JBSbatCommonDBInterface selectNext` | db_ZM_T_AGING | `ZM_T_AGING` | Retrieves the next row from the aging management query result set. If not null, it indicates aging is in progress. |
| R | `JBSbatServiceInterfaceMap.getString` | inMap access | - | Reads string values from the input service map: `SYSID`, `EOID`, `OABJ_TELNO`, `DEL_TRGT_SBT`. |
| R | `JBSbatCheckUtil.invoke` | utility | - | String validation utility: checks if the eoID string matches pattern criteria (digit count = 12, all half-width digits). Used for the special 51-prefix exclusion. |
| - | `JKKAdEdit.substring` | utility | - | Extracts the first 2 characters of the eoID to check if it starts with "51". |

**How to classify:**
- **R** (Read): All operations are queries (`SELECT`) against database tables or reads from input maps. No create, update, or delete operations occur in this method.
- The method is a **pure read-check** — it never mutates any data.

## 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: JBSbatKKDelKhChk.execute() | `JBSbatKKDelKhChk.execute` -> `agingTrgtGai(inMap)` | `executeCK_T_CUST_KK_SELECT_002 [R] CK_T_CUST`, `executeZM_T_AGING_KK_SELECT_002 [R] ZM_T_AGING` |

**Instructions:**
- Caller `execute()` in `JBSbatKKDelKhChk` is a batch method that validates deletion targets before proceeding with account deletion processing. It calls `agingTrgtGai(inMap)` at line 500 and checks the returned flag at line 503 to determine whether aging exclusion applies.
- The method terminates with reads from two database tables: `CK_T_CUST` (customer master) and `ZM_T_AGING` (aging management).

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] (L1322)

Initialize return flag. The default is `false` meaning "IS a subject of aging" (対象). If the method finds an exclusion condition, it sets this to `true` meaning "NOT a subject of aging" (対象外).

| # | Type | Code |
|---|------|------|
| 1 | SET | `retFlg = false;` // Default: aging subject (対象) — if true, excluded (対象外) |

**Block 2** — [SET] (L1325)

Read the deletion target subtype from the input map. This code determines which exclusion branch the method will take.

| # | Type | Code |
|---|------|------|
| 1 | SET | `delTrgtSbt = (String) inMap.get(JBSbatKKIFM160.DEL_TRGT_SBT);` // Delete target subtype item — determines processing path |

**Block 3** — [IF] `(delTrgtSbt equals "11" [DEL_TRGT_SBT_EOID])` (L1330)

If the deletion target subtype is "11" (eoID), the method checks whether the current eoID matches the initial (assignment) eoID from the customer master, or whether the eoID is a special 12-digit number starting with "51". Both cases indicate the record should be excluded from aging processing.

| # | Type | Code |
|---|------|------|
| 1 | SET | `selectWhereParam[0] = inMap.getString(JBSbatKKIFM160.SYSID);` // System ID for customer lookup |
| 2 | SET | `selectWhereParam[1] = opeDate;` // Operation date — batch run date filter |
| 3 | CALL | `executeCK_T_CUST_KK_SELECT_002(selectWhereParam);` // Query CK_T_CUST table with SYSID and opeDate |
| 4 | CALL | `custMap = db_CK_T_CUST.selectNext();` // Get the next customer record from the query result |
| 5 | SET | `shkEoid = custMap.getString(JBSbatCK_T_CUST.SHK_EOID);` // Get initial (assignment) eoID — the original eoID assigned to the account |
| 6 | SET | `tmpEoid = inMap.getString(JBSbatKKIFM160.EOID);` // Get current eoID from the input map |

**Block 3.1** — [IF] `(shkEoid.equals(tmpEoid))` (L1340)

If the initial (assignment) eoID matches the current eoID, the account has not been transferred or reassigned since creation. Per business rule, initial eoID accounts are excluded from aging processing (エイジング対象外). This is the primary exclusion check for the eoID branch.

> Business meaning: An account that retains its original eoID has not undergone any porting or reassignment. Such accounts should bypass aging because there is no prior account state to reconcile.

| # | Type | Code |
|---|------|------|
| 1 | SET | `retFlg = true;` // Exclusion confirmed: initial eoID matches current — not subject to aging (エイジング対象外) |

**Block 3.2** — [ELSE-IF] `(tmpEoid valid format AND starts with "51" AND 12 digits AND all half-width)` (L1344)

Added in change request OM-2018-0000709 (2018/07/19). If the current eoID is a 12-digit number starting with "51" (all half-width digits), the account is excluded from aging. This handles a special legacy pattern where eoIDs beginning with "51" represent a specific account category that should not go through aging.

> Business meaning: The "51" prefix indicates a special account type (likely a pre-provisioned or reserved account block) where aging is not applicable. The validation ensures the value is exactly 12 half-width digits to avoid false positives.

| # | Type | Code |
|---|------|------|
| 1 | SET | `// Validate: tmpEoid != null` |
| 2 | SET | `// Validate: !"".equals(tmpEoid)` — not empty string |
| 3 | SET | `// Validate: tmpEoid.length() >= 2` — at least 2 characters |
| 4 | SET | `// Validate: "51".equals(tmpEoid.substring(0, 2))` — starts with "51" |
| 5 | SET | `// Validate: JBSbatCheckUtil.invoke(tmpEoid, ["ketasuu1", "12"])` — all numeric digits and digit count equals 12 |
| 6 | SET | `// Validate: JBSbatCheckUtil.invoke(tmpEoid, ["hannkakusuuji1"])` — all half-width characters |
| 7 | SET | `retFlg = true;` // Exclusion confirmed: special 51-prefix 12-digit pattern — not subject to aging (エイジング対象外) |

**Block 4** — [ELSE-IF] `(delTrgtSbt equals "09" [DEL_TRGT_SBT_OABJ_TELNO])` (L1374)

Added in ANK-4494-00-00 Step 2 (2024/11/13). If the deletion target subtype is "09" (OABJ telephone number), the method checks whether an aging record already exists with status "aging in progress" (300). If such a record exists, the deletion is excluded from aging because the aging update is already underway — this avoids double-processing of the same telephone number.

> Business meaning: When a port-out cancellation (他社受付) of an operator-assigned telephone number is being processed, the aging status transition may have already been triggered. Detecting this prevents redundant aging updates.

| # | Type | Code |
|---|------|------|
| 1 | SET | `agingSbtCd = JBSbatKKConst.AGING_SBT_CD_TELNO;` // Aging subtype code: "001" (OABJ telephone number) |
| 2 | SET | `agingTrgtValue = inMap.getString(JBSbatKKIFM160.OABJ_TELNO);` // Aging target value: the OABJ telephone number being deleted |
| 3 | SET | `agingStat = JBSbatKKConst.AGING_STAT_AGING_CHU;` // Aging status: "300" (Aging in progress / エイジング中) |
| 4 | CALL | `executeZM_T_AGING_KK_SELECT_002(getAgingParam(agingSbtCd, agingTrgtValue, agingStat, JBSbatKKConst.MK_FLG_YK));` // Query ZM_T_AGING for matching aging records |
| 5 | CALL | `nextRec = db_ZM_T_AGING.selectNext();` // Get the next aging record from query result |

**Block 4.1** — [IF] `(nextRec != null)` (L1385)

If a matching aging record exists with status "aging in progress", the deletion target is excluded from aging. The aging update is already in flight, so this method allows the deletion to proceed without additional aging intervention.

> Business meaning: This acts as a guard against concurrent aging processing. When aging has already been triggered for a telephone number, the deletion process should not re-initiate aging.

| # | Type | Code |
|---|------|------|
| 1 | SET | `retFlg = true;` // Exclusion confirmed: aging already in progress — not subject to aging (エイジング対象外) |

**Block 5** — [RETURN] (L1393)

Return the exclusion flag. `true` means the deletion target is excluded from aging (エイジング対象外 — 対象外), and `false` means it is subject to aging (対象 — 対象).

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return retFlg;` // true = excluded from aging, false = subject to aging |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `agingTrgtGai` | Method | Aging target exclusion check — determines whether a deletion target should bypass aging processing |
| エイジング対象外 | Japanese term | Excluded from aging (エイジング = aging, 対象外 = not a target) — the record does not go through aging status transitions |
| 対象 | Japanese term | Subject / target — the record IS subject to aging processing |
| 消去処理 | Japanese term | Deletion processing / erasure processing — the batch operation that removes customer account records |
| 消去対象種別 | Japanese term | Delete target subtype — classifies the type of deletion (eoID, OABJ telephone number, etc.) |
| eoID | Business term | Enterprise ID — a unique identifier assigned to an enterprise customer account in the KDDI system |
| SHK_EOID | Field | Shift/assignment eoID — the initial (original assignment) eoID stored in the customer master, used to detect if an account has been reassigned |
| SYSID | Field | System ID — a system-level identifier for customer identification across tables |
| OABJ telephone number | Business term | Operator Assigned telephone number — a telephone number assigned by the operator (as opposed to customer-selectable numbers), referenced as OABJ (Operator Assignment) in the code |
| `delTrgtSbt` | Field | Delete target subtype — internal code classifying what kind of entity is being deleted (e.g., "11" = eoID, "09" = OABJ telephone number) |
| CK_T_CUST | Database table | Customer master table — stores customer account information including the initial (assignment) eoID |
| ZM_T_AGING | Database table | Aging management table — tracks aging status transitions for customer records during the retention/cancellation lifecycle |
| AGING_STAT_AGING_CHU | Constant | "300" — Aging status: "Aging in progress" (エイジング中) — the account is currently undergoing aging state transition |
| AGING_SBT_CD_TELNO | Constant | "001" — Aging subtype code: OABJ telephone number |
| MK_FLG_YK | Constant | "0" — Mark flag: Use/Yes — an availability flag used as a filter in aging queries |
| JBSbatKKConst | Class | Batch service constant definition class for the Kopt (Kanta Otsureshimai) service |
| JBSbatCheckUtil | Class | Batch check utility class — provides string validation methods for format checks |
| ketasuu1 | Pattern name | Digit count validation pattern — verifies the string length equals the specified number (12) and all characters are digits |
| hannkakusuuji1 | Pattern name | Half-width digit validation pattern — verifies all characters in the string are half-width (ASCII) digits |
| opeDate | Field | Operation date — the current batch run date used as a filter in queries |

---
