# Business Logic — JKKTVSvcKeiKaihukuCC.henpinKikiCancel() [99 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKTVSvcKeiKaihukuCC` |
| Layer | Service Component (Common CC — shared business logic component) |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKTVSvcKeiKaihukuCC.henpinKikiCancel()

This method implements the **Return Equipment Cancellation** business process within the broader service contract recovery workflow. When a telecommunications service contract is cancelled (status "910" — 解約済 / Resolved), the associated return equipment cancellation records must be cleaned up. The method retrieves all equipment items tied to the current service contract line, filters them by application detail number (`mskmDtlNo`), cross-references with any pending return equipment cancellation records, and deletes matching return equipment cancellation entries from the system.

The method acts as a **delegation component** within the recovery flow (`kaihuku()` CBS). It is not a screen entry point but rather a shared utility method invoked exclusively by the contract recovery processing, ensuring data consistency between the service contract state and its associated equipment return records. It implements a **two-stage filtering-and-delete pattern**: first querying equipment from the service contract, then querying and deleting corresponding return equipment cancellation records.

The method contains several conditional filters: (1) it excludes parent equipment with service type code "02" unless the equipment subtype is V-ONU ("E0"), (2) it matches equipment by application detail number to ensure the correct line item is processed, and (3) it matches by equipment change number to ensure only the correct return equipment cancellation record is deleted.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START["henpinKikiCancel"]
    GET_DATA_MAP["Get ccMsg from param.getData"]
    GET_FUNC_CODE["Get func_code from ccMsg"]
    EKK0341B022_IN["Build EKK0341B022CBSMsg input
(func_code=1, svc_kei_no from ccMsg)"]
    CALL_EKK0341B022["callSC EKK0341B022CBS
(Service Equipment Contract Overview)"]
    LOOP1["Loop: for each curKitkInfo"]
    CHECK_SUB_SVC["curKitkInfo.OYA_KEI_SKBT_CD = 02?
AND curKitkInfo.TAKNKIKI_SBT_CD != E0?"]
    FILTER_SKIP["Skip (not V-ONU line equipment)"]
    CHECK_MSKM["curKitkInfo.MSKM_DTL_NO != mskmDtlNo?"]
    EDK0301B060_IN["Build EDK0301B060CBSMsg input
(svc_kei_no, kiki_stat=001)"]
    CALL_EDK0301B060["callSC EDK0301B060CBS
(Return Equipment Cancellation List)"]
    CHECK_RESULTS["edk0301B060OUT == null or empty?"]
    LOOP2["Loop: for each curHenpinKikiInfo"]
    CHECK_KIKI_CHG["curHenpinKikiInfo.KIKI_CHG_NO
!= curKitkInfo.KIKI_CHG_NO?"]
    EDK0301E010_IN["Build EDK0301E010CBSMsg input
(wms_hmpin_no, upd_dtm_bf, func_code)"]
    CALL_EDK0301E010["callSC EDK0301E010CBS
(Return Equipment Deletion)"]
    END_LOOP2["End inner loop"]
    END_LOOP1["End outer loop"]
    END_NODE["Return (void)"]

    START --> GET_DATA_MAP --> GET_FUNC_CODE --> EKK0341B022_IN --> CALL_EKK0341B022 --> LOOP1
    LOOP1 --> CHECK_SUB_SVC
    CHECK_SUB_SVC -- "true (filter out)" --> FILTER_SKIP --> END_LOOP1
    CHECK_SUB_SVC -- "false (continue)" --> CHECK_MSKM
    CHECK_MSKM -- "true (mismatch)" --> FILTER_SKIP
    CHECK_MSKM -- "false (match)" --> EDK0301B060_IN --> CALL_EDK0301B060 --> CHECK_RESULTS
    CHECK_RESULTS -- "true (empty)" --> END_LOOP1
    CHECK_RESULTS -- "false (has results)" --> LOOP2
    LOOP2 --> CHECK_KIKI_CHG
    CHECK_KIKI_CHG -- "true (mismatch)" --> END_LOOP2
    CHECK_KIKI_CHG -- "false (match)" --> EDK0301E010_IN --> CALL_EDK0301E010 --> END_LOOP2
    END_LOOP2 --> END_LOOP1
    END_LOOP1 --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle providing the transactional context for the method. Carries connection and security information for the current user session. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter object that carries data across service components. The method reads the `dataMapKey`-indexed HashMap (`ccMsg`) to obtain `func_code` and `svc_kei_no` (service contract number). |
| 3 | `scCall` | `ServiceComponentRequestInvoker` | The service component invocation bridge used to call external CBS/SC methods. This is the standard mechanism for invoking service components in the framework. |
| 4 | `dataMapKey` | `String` | The map key used to retrieve the shared data context (`ccMsg`) from `param`. This key identifies the business data map containing the function code and service contract number. |
| 5 | `mskmDtlNo` | `String` | Application detail number (申請明細番号 / Application Line Item Number) — identifies the specific application detail line to match against equipment records. Only equipment belonging to this line item will have its return equipment cancellation deleted. Added in v23.00.00 (OM-2019-0001439). |
| 6 | `curSvcKeiInfo` | `CAANMsg` | Current service contract information message. Although passed as a parameter, this method does not directly use it — it receives `svc_kei_no` from `ccMsg` instead. The caller (`kaihuku`) passes it for potential future use or logging. |

**External/Instance State Read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `callSC` (instance method) | `ServiceComponentRequestInvoker` | Internal method used to invoke CBS/SC components. Provides the common invocation wrapper that handles serialization, error propagation, and data mapping. |

## 4. CRUD Operations / Called Services

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

The method invokes three service component chains. Each chain follows a **query-then-delete** pattern for a specific sub-domain of the return equipment cancellation process.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `callSC(handle, scCall, param, dataMapKey, ekk0341b022IN)` | EKK0341B022CBS | KK_T_KKTK_SVC_KEI_ISM (Service Contract Equipment Line Master) | Calls EKK0341B022CBS (Service Equipment Contract Overview) to retrieve all equipment items associated with the service contract. Input includes func_code="1" and svc_kei_no. Returns a list of equipment records (EKK0341B022CBSMsg1List) that are iterated over. |
| R | `callSC(handle, scCall, param, dataMapKey, edk0301b060IN)` | EDK0301B060CBS | KK_T_HMPIN_KIKI (Return Equipment Cancellation Master) | Calls EDK0301B060CBS (Return Equipment Cancellation List) to retrieve return equipment cancellation records. Input includes func_code="1", the specific equipment's svc_kei_no, and kiki_stat="001" (cancellation status). Returns cancellation records matching the equipment. |
| D | `callSC(handle, scCall, param, dataMapKey, edk0301c040IN)` | EDK0301E010CBS | KK_T_HMPIN_KIKI (Return Equipment Cancellation Master) | Calls EDK0301E010CBS (Return Equipment Deletion) to delete a return equipment cancellation record. Input includes func_code, wms_hmpin_no (return equipment cancellation number from curHenpinKikiInfo), and upd_dtm_bf (last update timestamp). This is the actual deletion step. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | CBS:JKKTVSvcKeiKaihukuCC.kaihuku | `kaihuku` (status="910" / 解約済 branch) → `henpinKikiCancel(handle, param, scCall, dataMapKey, mskmDtlNo, curSvcKeiInfo)` | `callSC [R] EKK0341B022CBS → KK_T_KKTK_SVC_KEI_ISM`, `callSC [R] EDK0301B060CBS → KK_T_HMPIN_KIKI`, `callSC [D] EDK0301E010CBS → KK_T_HMPIN_KIKI` |

**Caller Details:**

The `henpinKikiCancel` method is called exclusively from `JKKTVSvcKeiKaihukuCC.kaihuku()` at line 624. This caller method handles the service contract recovery process. The call occurs when `curSvcKeiStat` equals "910" (解約済 / Resolved — the contract has been fully cancelled). At that point, after performing recovery processing (`recoveryKojiAk`, `recoveryToPauseStatus`, `recovery`, or `recoveryToConclusion` depending on pause/service start dates), the method invokes `henpinKikiCancel` to clean up the associated return equipment cancellation records. This ensures that when a contract is fully cancelled, the system also clears any pending or completed return equipment cancellation records.

**Note:** The old version (commented out at line 623) passed only 5 parameters without `mskmDtlNo`, indicating the method was updated in v23.00.00 (OM-2019-0001439) to add the application detail number filter for more precise matching.

## 6. Per-Branch Detail Blocks

**Block 1** — SET (data map extraction) (L1057)

> Extract the business data map and function code from the request parameter.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ccMsg = (HashMap<String, Object>) param.getData(dataMapKey)` // Work area (作業領域) — retrieves the shared data map |
| 2 | SET | `funcCode = (String) ccMsg.get("func_code")` // Function code from the data map |

**Block 2** — CALL (EKK0341B022CBS — Service Equipment Contract Overview) (L1062–L1072)

> Build the input message and call the service component to retrieve all equipment items tied to the current service contract. The equipment list is used as the outer iteration source.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ekk0341b022IN = new CAANMsg(EKK0341B022CBSMsg.class.getName())` |
| 2 | SET | `ekk0341b022IN.set(TEMPLATEID, TEMPLATE_ID_EKK0341B022)` // Template ID constant for EKK0341B022 |
| 3 | SET | `ekk0341b022IN.set(FUNC_CODE, "1")` // Fixed function code 1 (1) |
| 4 | SET | `ekk0341b022IN.set(KEY_SVC_KEI_NO, ccMsg.get("svc_kei_no"))` // Service contract number from the data map |
| 5 | EXEC | ~~`ekk0341b022IN.set(KEY_KKTK_SVC_KEI_STAT, "100")`~~ // REMOVED in OM-2019-0001439 — previously filtered by status code 100 |
| 6 | CALL | `ekk0341b022OUT = callSC(handle, scCall, param, dataMapKey, ekk0341b022IN).getCAANMsgList(EKK0341B022CBSMsg1List)` // Returns all equipment records for this service contract |

**Block 3** — LOOP (outer: for each curKitkInfo in ekk0341b022OUT) (L1074)

> Iterate over each piece of equipment associated with the service contract. Each iteration processes one equipment item.

| # | Type | Code |
|---|------|------|
| 1 | LOOP | `for (CAANMsg curKitkInfo : ekk0341b022OUT)` // curKitkInfo = current equipment info (現在の機器情報) |

**Block 3.1** — IF (V-ONU filter) (L1078–L1082)

> Equipment on the parent line (OYA_KEI_SKBT_CD = "02") is excluded unless it is a V-ONU device (TAKNKIKI_SBT_CD != "E0"). V-ONU is the fiber-optic ONU device installed at the customer premises. Equipment other than V-ONU on parent lines is not processed.

| # | Type | Code |
|---|------|------|
| 1 | IF | `[OYA_KEI_SKBT_CD = "02"]` AND `[TAKNKIKI_SBT_CD != "E0"]` — Filter out non-V-ONU parent line equipment (回線に紐づく機器はV-ONU以外処理対象外) |
| 2 | EXEC | `continue` // Skip this equipment, move to next |

**Block 3.2** — IF (mskmDtlNo match) (L1086–L1090)

> Only process equipment whose application detail number (mskmDtlNo) matches the input parameter. This ensures only the correct line item within a multi-line application is processed.

| # | Type | Code |
|---|------|------|
| 1 | IF | `[mskmDtlNo != curKitkInfo.getString(MSKM_DTL_NO)]` — Application detail number mismatch (申請明細番号が異なる場合は処理対象外) |
| 2 | EXEC | `continue` // Skip — different line item |

**Block 3.3** — CALL (EDK0301B060CBS — Return Equipment Cancellation List) (L1094–L1103)

> Query the return equipment cancellation records for this specific equipment. The status is fixed at "001" (likely indicating all statuses or a specific state).

| # | Type | Code |
|---|------|------|
| 1 | SET | `edk0301b060IN = new CAANMsg(EDK0301B060CBSMsg.class.getName())` |
| 2 | SET | `edk0301b060IN.set(TEMPLATEID, TEMPLATE_ID_EDK0301B060)` // Template ID constant for EDK0301B060 |
| 3 | SET | `edk0301b060IN.set(FUNC_CODE, "1")` // Fixed function code 1 |
| 4 | SET | `edk0301b060IN.set(KEY_KKTK_SVC_KEI_NO, curKitkInfo.getString(KKTK_SVC_KEI_NO))` // Equipment-level service contract number |
| 5 | SET | `edk0301b060IN.set(KEY_HMPIN_KIKI_STAT, "001")` // Return equipment cancellation status filter = "001" |
| 6 | CALL | `edk0301b060OUT = callSC(...).getCAANMsgList(EDK0301B060CBSMsg1List)` // Returns matching return cancellation records |

**Block 3.4** — IF (empty results check) (L1105–L1108)

> If no return equipment cancellation records exist for this equipment, skip to the next equipment item.

| # | Type | Code |
|---|------|------|
| 1 | IF | `[edk0301b060OUT == null || edk0301b060OUT.length == 0]` — No return cancellation records found |
| 2 | EXEC | `continue` // Skip — nothing to delete |

**Block 3.5** — LOOP (inner: for each curHenpinKikiInfo in edk0301b060OUT) (L1110)

> Iterate over each return equipment cancellation record found for this equipment.

| # | Type | Code |
|---|------|------|
| 1 | LOOP | `for (CAANMsg curHenpinKikiInfo : edk0301b060OUT)` // curHenpinKikiInfo = current return equipment cancellation info (現在の返品機器取消情報) |

**Block 3.5.1** — IF (equipment change number match) (L1114)

> The equipment change number (KIKI_CHG_NO) from the return cancellation record must match the equipment change number from the equipment record. This ensures the cancellation record belongs to the same equipment instance.

| # | Type | Code |
|---|------|------|
| 1 | IF | `[curHenpinKikiInfo.KIKI_CHG_NO != curKitkInfo.KIKI_CHG_NO]` — Equipment change number mismatch (機器変更番号が不一致の場合は処理対象外) |
| 2 | EXEC | `continue` // Skip — different equipment change instance |

**Block 3.5.2** — CALL (EDK0301E010CBS — Return Equipment Deletion) (L1125–L1138)

> This is the actual deletion operation. It was changed in v6.00.01 (旧 EDK0301C040 → EDK0301E010) and in v23.00.00 the data source changed from index-based to iteration-based.

| # | Type | Code |
|---|------|------|
| 1 | SET | ~~`edk0301c040IN = new CAANMsg(EDK0301C040CBSMsg.class.getName())`~~ // REMOVED in v6.00.01 — replaced with EDK0301E010 |
| 2 | SET | `edk0301c040IN = new CAANMsg(EDK0301E010CBSMsg.class.getName())` // Return Equipment Deletion CBS message (返品機器削除) |
| 3 | SET | `edk0301c040IN.set(TEMPLATEID, TEMPLATE_ID_EDK0301E010)` // Template ID constant |
| 4 | SET | `edk0301c040IN.set(FUNC_CODE, funcCode)` // Function code from the data map (business context) |
| 5 | SET | ~~`edk0301c040IN.set(KEY_WMS_HMPIN_NO, edk0301b060OUT[0].getString(HMPIN_KIKI_NO))`~~ // REMOVED in v23.00.00 — was index-based |
| 6 | SET | ~~`edk0301c040IN.set(UPD_DTM_BF, edk0301b060OUT[0].getString(UPD_DTM))`~~ // REMOVED in v23.00.00 |
| 7 | SET | `edk0301c040IN.set(KEY_WMS_HMPIN_NO, curHenpinKikiInfo.getString(HMPIN_KIKI_NO))` // Return equipment cancellation number from current iteration (v23.00.00 update) |
| 8 | SET | `edk0301c040IN.set(UPD_DTM_BF, curHenpinKikiInfo.getString(UPD_DTM))` // Last update timestamp from current iteration (v23.00.00 update) |
| 9 | CALL | `callSC(handle, scCall, param, dataMapKey, edk0301c040IN)` // Executes the deletion of this return equipment cancellation record |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `henpin` | Field (Japanese) | Return equipment (返品) — customer return of service equipment (e.g., ONU, router) when a service contract is cancelled |
| `kiki` | Field (Japanese) | Equipment (機器) — physical telecommunication device such as V-ONU or modem |
| `cancel` | Term | Cancellation — voiding or reversing a previously created record |
| `henpin_kiki` | Field | Return equipment — the combined concept of equipment returned by a customer |
| `henpin_kiki_no` | Field | Return equipment cancellation number (返品機器取消番号) — unique identifier for a return equipment cancellation record |
| `henpin_kiki_stat` | Field | Return equipment cancellation status (返品機器取消状態) — status code for the cancellation record ("001" = all/standard) |
| `mskmDtlNo` | Field | Application detail number (申請明細番号) — identifies a specific line item within a multi-line application |
| `svc_kei_no` | Field | Service contract number (サービス契約番号) — unique identifier for a service contract line item |
| `kktk_svc_kei_no` | Field | Equipment-provider service contract number (機器提供サービス契約番号) — service contract number at the equipment level |
| `curSvcKeiInfo` | Field | Current service contract information (現在のサービス契約情報) — CAANMsg carrying the state of the current service contract being recovered |
| `kiki_chg_no` | Field | Equipment change number (機器変更番号) — identifier for a specific equipment change instance; used to match cancellation records to equipment |
| `upd_dtm_bf` | Field | Update datetime before (更新日時前) — the last-modified timestamp used as a concurrency control check during deletion |
| `func_code` | Field | Function code — identifies the business context of the operation ("1" = standard) |
| `OYA_KEI_SKBT_CD` | Field | Parent line service type code (親回線サービス種別コード) — "02" = parent line equipment; filters determine which equipment is processed |
| `TAKNKIKI_SBT_CD` | Field | Equipment subtype code (機器種別コード) — "E0" = V-ONU (the fiber-optic ONU at customer premises) |
| V-ONU | Business term | Virtual/Subscriber ONU (光終端装置) — the fiber-optic network device installed at the customer location for FTTH service |
| EKK0341B022CBS | Service Component | Service Equipment Contract Overview (サービス対象機器提供サービス契約一覧照会) — queries equipment items associated with a service contract |
| EDK0301B060CBS | Service Component | Return Equipment Cancellation List (返品機器取消一覧照会) — queries return equipment cancellation records |
| EDK0301E010CBS | Service Component | Return Equipment Deletion (返品機器削除) — deletes a return equipment cancellation record |
| KK_T_KKTK_SVC_KEI_ISM | DB Table | Equipment Provider Service Contract Line Item Master — stores service contract equipment line item data |
| KK_T_HMPIN_KIKI | DB Table | Return Equipment Cancellation Master — stores return equipment cancellation records |
| 解約済 | Japanese term | Resolved / Cancelled — service contract status "910" indicating full contract cancellation |
| 復旧処理 | Japanese term | Recovery processing — the business process of restoring service contract state after cancellation |
| 作業領域 | Japanese term | Work area — temporary HashMap used for data sharing between service components |
| 申請明細番号 | Japanese term | Application detail number — line item identifier within a service application |
| 機器変更番号 | Japanese term | Equipment change number — tracks specific instances of equipment changes |
| CAANMsg | Technical term | Common Application ANd Message — the framework's message wrapper class for CBS/SC communication |
| SC Code | Technical term | Service Component Code — standardized code identifying a service component (e.g., EKK0341B022CBS) |
| `callSC` | Technical term | Common method to invoke CBS/SC components — handles serialization, error handling, and result processing |
