# Business Logic — JKKKapKeiInfoCancelCC.execKktkSvcKeWariCC() [85 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKKapKeiInfoCancelCC` |
| Layer | Common Component (CC) — Shared business logic component within the BP (Business Process) module |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKKapKeiInfoCancelCC.execKktkSvcKeWariCC()

This method executes the equipment-provided service contract discount application processing (機器提供サービス契約割引CCを実行します). Its core responsibility is to gather service contract cancellation or termination data from previously invoked CBS (Common Business Service) response messages, assemble a structured service discount application payload, and dispatch it to the `JKKWrisvcAutoAplyCC` (Write-in Service Auto-Apply CC) for automated discount application decisions.

The method handles two distinct business scenarios controlled by the `flg` parameter: cancellation (キャンセル) when `flg` equals `"1"`, and termination (解約) in all other cases. For cancellation, it sets the add/change division to "05" (cancellation code) and applies a cancellation reason code of "01". For termination, it uses add/change division "03" (DSL/termination code) and a termination reason code of "01".

This method implements a **builder + delegation pattern**: it first builds a complex data structure (the `outMap` with service contract group list) by extracting fields from CBS response messages and the original request parameters, then delegates the actual discount logic to the `JKKWrisvcAutoAplyCC.execute()` service component.

In the larger system, this is a shared CC method called during the contract cancellation/termination workflow — specifically, it was originally invoked within the equipment progress registration S-IF processing (around line 566 of the same class), though it is currently commented out in v5.00.05 because contract T discount contract termination is handled in batch (契約Tの割賃契約解除バッチで処理するように割引CCを実行しないようにする).

## 2. Processing Pattern (Detailed Business Logic)

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

    START --> GET1["Get CAANMsg ekk0341a010cbsMsg
from temporaryData"]
    GET1 --> GET2["Get CAANMsg ekk0021a010cbsMsg
from temporaryData"]
    GET2 --> SETUP["Create WRI_SVC_AUTO_APLY
param.setData"]
    SETUP --> GETMAPS["Get ccMsg and outMap
from param.getData"]
    GETMAPS --> SYSID["Put sysid
from CBS message"]
    SYSID --> COND1{"flg equals 1?"}
    COND1 -->|Yes| CANCEL["Add Change Division = CANCEL
ADD_CHGE_DIV_CANCEL = 05
Put svc_cancel_rsn_cd"]
    COND1 -->|No| DSL["Add Change Division = DSL
ADD_CHGE_DIV_DSL = 03
Put svc_dlre_cd"]
    CANCEL --> PUT_COMMON["Put mskm_no, mskm_sbt_cd, ido_div, func_code"]
    DSL --> PUT_COMMON
    PUT_COMMON --> BUILD_SVC["Build workSvcKeiArray
with svc_kei_list details"]
    BUILD_SVC --> PUT_SVC["Put svc_kei_grp_list
into outMap"]
    PUT_SVC --> CALL_CC["Create JKKWrisvcAutoAplyCC
and execute"]
    CALL_CC --> CLEANUP["Remove WRI_SVC_AUTO_APLY
data from param"]
    CLEANUP --> END_NODE(["Return"])
```

**Constant Resolution:**

| Constant | Actual Value | Business Meaning |
|----------|-------------|------------------|
| `TEMPLATE_ID_EKK0341A010` | `"EKK0341A010"` | Equipment service contract list sync CBS template ID |
| `TEMPLATE_ID_EKK0021A010` | `"EKK0021A010"` | Order details agreement sync CBS template ID |
| `WRI_SVC_AUTO_APLY` | `"WrisvcAutoAplyCC"` | Key for the write-in service auto-apply map in param |
| `ADD_CHGE_DIV_CANCEL` | `"05"` | Add/change division code for cancellation |
| `ADD_CHGE_DIV_DSL` | `"03"` | Add/change division code for termination (DSL) |
| `SVC_CANCEL_RSN_CD` | `"01"` | Service cancellation reason code |
| `SVC_DLRE_CD` | `"01"` | Service termination reason code |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle providing the transaction context for CBS/service component invocations. |
| 2 | `scCall` | `ServiceComponentRequestInvoker` | Service component request invoker used to dispatch CBS/SC calls. Not directly used within this method but available for synchronous invocations. |
| 3 | `param` | `IRequestParameterReadWrite` | Request parameter read/write interface — the data carrier used to stage the discount application payload (`WRI_SVC_AUTO_APLY` key) and retrieve input data (`dataMapKey`). Acts as the primary inter-component data exchange mechanism. |
| 4 | `dataMapKey` | `String` | Key to retrieve the original input message map (`ccMsg`) from `param.getData()`. This map contains the original request parameters such as `ido_div` (displacement division) and `func_code` (function code) from the calling screen or CBS. |
| 5 | `temporaryData` | `HashMap<String, Object>` | Temporary data map holding CBS response messages keyed by template ID. Contains `CAANMsg` objects for `EKK0341A010` (equipment service contract list sync) and `EKK0021A010` (order details agreement sync) that provide the source data for building the discount application payload. |
| 6 | `flg` | `String` | Flag controlling the business operation type. `"1"` triggers cancellation processing (キャンセル) with cancellation-specific codes. Any other value triggers termination processing (解約) with termination-specific codes. This is the primary conditional branch selector for this method. |

**Instance fields / external state read:** None — this method is stateless with respect to instance fields. All data is sourced from parameters.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JKKWrisvcAutoAplyCC.execute` | JKKWrisvcAutoAplyCC | WrisvcAutoAply (Write-in Service Auto-Apply) | Creates/dispatches the assembled discount application payload to the auto-apply service component, which evaluates and applies appropriate service discounts based on contract terms and cancellation/termination reasons. |
| R | `CAANMsg.getString` (EKK0341A010CBSMsg1List) | EKK0341A010CBS | Equipment service contract table | Reads equipment service contract data (sysid, contract number, status, cost code, plan code, service code, service type code) from the previously invoked CBS response message. |
| R | `CAANMsg.getString` (EKK0021A010CBSMsg1List) | EKK0021A010CBS | Order details table | Reads order details data (application number, MSKM number) from the previously invoked CBS response message. |
| R | `JKKKapKeiInfoCancelCC.getMskmSbtCd` | Internal | Lookup table (MSKM_SBT_CD_LIST) | Maps displacement division code (`ido_div`) to the corresponding application type code (`mskm_sbt_cd`) using the static lookup array `MSKM_SBT_CD_LIST`. |

Note: CBS messages (EKK0341A010CBS and EKK0021A010CBS) are already loaded into `temporaryData` by the caller method before this method is invoked. This method only reads from them.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV (equipment progress registration S-IF) | `execEKK1091D010` (caller context, line ~566) -> `execKktkSvcKeWariCC` (currently commented out in v5.00.05) | `JKKWrisvcAutoAplyCC.execute [C] WrisvcAutoAply` |

**Note:** The caller is within the same class `JKKKapKeiInfoCancelCC`, specifically in the equipment progress registration S-IF processing section around line 566. The call is currently commented out with a v5.00.05 fix comment indicating that contract T discount contract termination is now handled in batch, so the discount CC execution was suppressed.

## 6. Per-Branch Detail Blocks

**Block 1** — [EXTRACT] CBS messages from temporaryData (L1387-L1389)

> Retrieves CBS response messages from the temporary data map. Both messages are CAANMsg objects previously populated by the caller.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `CAANMsg ekk0341a010cbsMsg = (CAANMsg)temporaryData.get(TEMPLATE_ID_EKK0341A010)` // Get equipment service contract list sync result [-> TEMPLATE_ID_EKK0341A010 = "EKK0341A010"] |
| 2 | EXEC | `CAANMsg ekk0021a010cbsMsg = (CAANMsg)temporaryData.get(TEMPLATE_ID_EKK0021A010)` // Get order details agreement sync result [-> TEMPLATE_ID_EKK0021A010 = "EKK0021A010"] |

**Block 2** — [SETUP] Create discount application map (L1392-L1396)

> Initializes the write-in service auto-apply parameter and retrieves the input and output maps.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `param.setData(WRI_SVC_AUTO_APLY, new HashMap<String, Object>())` // Create discount CC input parameter map [-> WRI_SVC_AUTO_APLY = "WrisvcAutoAplyCC"] |
| 2 | EXEC | `HashMap<String, Object> ccMsg = (HashMap<String, Object>)param.getData(dataMapKey)` // Get original input message map |
| 3 | EXEC | `HashMap<String, Object> outMap = (HashMap<String, Object>)param.getData(WRI_SVC_AUTO_APLY)` // Get the output map for building the discount application payload |

**Block 3** — [SYSTEM_ID] Set system ID (L1399)

> Sets the system ID extracted from the equipment service contract CBS response.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("sysid", ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.SYSID))` // System ID from equipment service contract CBS |

**Block 4** — [IF/ELSE-IF/ELSE] Conditional branch on cancellation flag `flg` (L1401-L1420)

> Determines whether this is a cancellation (キャンセル) or termination (解約) operation. This is the primary business logic branch.

**Block 4.1** — [IF] Cancellation branch: `flg.equals("1")` (L1403-L1407)

> Equipment-provided service contract cancellation (機器提供サービス契約のキャンセル) path. Sets cancellation-specific codes.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("add_chge_div", ADD_CHGE_DIV_CANCEL)` // Add/change division code [-> ADD_CHGE_DIV_CANCEL = "05" (Cancellation)] |
| 2 | SET | `outMap.put("svc_cancel_rsn_cd", SVC_CANCEL_RSN_CD)` // Service cancellation reason code [-> SVC_CANCEL_RSN_CD = "01"] |

**Block 4.2** — [ELSE] Termination branch (L1409-L1417)

> Service contract termination (サービス解約) path. Sets termination-specific codes.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("add_chge_div", ADD_CHGE_DIV_DSL)` // Add/change division code [-> ADD_CHGE_DIV_DSL = "03" (Termination/DSL)] |
| 2 | EXEC | `outMap.put("svc_dlre_cd", SVC_DLRE_CD)` // Service termination reason code [-> SVC_DLRE_CD = "01"] |
| 3 | SET | `//outMap.put("svc_dlre_cd", "00")` // Commented out — was previously "00" |
| 4 | SET | `//outMap.put("svc_cancel_rsn_cd", SVC_CANCEL_RSN_CD)` // Commented out — cancellation reason not used for termination |

**Block 5** — [POST-CONDITION SETS] Set common fields (L1419-L1428)

> These fields are set regardless of which branch was taken. They populate the order/application details and operational metadata.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("mskm_no", ekk0021a010cbsMsg.getString(EKK0021A010CBSMsg1List.MSKM_NO))` // Application number (申込番号) from order details CBS |
| 2 | SET | `outMap.put("mskm_sbt_cd", getMskmSbtCd((String)ccMsg.get("ido_div")))` // Application type code (申込種類コード), mapped from displacement division (異動区分) via getMskmSbtCd lookup |
| 3 | SET | `outMap.put("ido_div", (String)ccMsg.get("ido_div"))` // Displacement division (異動区分) — operation type classification |
| 4 | SET | `outMap.put("func_code", (String)ccMsg.get("func_code"))` // Function code (機能コード) — identifies the calling function/screen |

**Block 6** — [BUILD STRUCTURE] Build service contract group list (L1430-L1453)

> Constructs the nested data structure for the service contract details. This is a three-level hierarchy: group list -> group -> service list -> service data.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workSvcKeiArray = new ArrayList<HashMap<String, Object>>()` // Service contract group list container |
| 2 | SET | `workSvcKeiMap = new HashMap<String, Object>()` // Service contract group map |
| 3 | SET | `workSvcKeiMap.put("grp_div", "00")` // Group division code — "00" (standard group) |
| 4 | SET | `workSvcKeiList = new ArrayList<HashMap<String, Object>>()` // Service contract list within the group |
| 5 | SET | `workSvcKeiData = new HashMap<String, Object>()` // Individual service contract data map |
| 6 | SET | `workSvcKeiData.put("tg_kei_skbt_cd", "06")` // Target contract identifier code — "06" (equipment-provided service contract) [-> "06"] |
| 7 | SET | `workSvcKeiData.put("kktk_svc_kei_no", ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.KKTK_SVC_KEI_NO))` // Equipment-provided service contract number (機器提供サービス契約番号) |
| 8 | SET | `workSvcKeiData.put("kktk_svc_kei_stat", ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.KKTK_SVC_KEI_STAT))` // Equipment-provided service contract status (機器提供サービス契約ステータス) |
| 9 | SET | `workSvcKeiData.put("pcrs_cd", ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.PCRS_CD))` // Cost code (料金コースコード) |
| 10 | SET | `workSvcKeiData.put("pplan_cd", ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.PPLAN_CD))` // Plan code (料金プランコード) |
| 11 | SET | `workSvcKeiData.put("kktk_svc_cd", ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.KKTK_SVC_CD))` // Equipment-provided service code (機器提供サービスコード) |
| 12 | SET | `workSvcKeiData.put("kktk_sbt_cd", ekk0341a010cbsMsg.getString(EKK0341A010CBSMsg1List.KKTK_SBT_CD))` // Equipment-provided type code (機器提供種類コード) |
| 13 | EXEC | `workSvcKeiList.add(workSvcKeiData)` // Add service data to service list |
| 14 | SET | `workSvcKeiMap.put("svc_kei_list", workSvcKeiList)` // Attach service list to group map |
| 15 | EXEC | `workSvcKeiArray.add(workSvcKeiMap)` // Attach group to group list |
| 16 | SET | `outMap.put("svc_kei_grp_list", workSvcKeiArray)` // Attach group list to output map |

**Block 7** — [INVOKE] Execute discount auto-apply CC (L1455-L1462)

> Instantiates and executes the write-in service auto-apply CC, which processes the assembled discount application data.

| # | Type | Code |
|---|------|------|
| 1 | SET | `JKKWrisvcAutoAplyCC wrisvcAutoAplyCC = new JKKWrisvcAutoAplyCC()` // Create auto-apply CC instance |
| 2 | CALL | `wrisvcAutoAplyCC.execute(handle, param, WRI_SVC_AUTO_APLY)` // Execute discount auto-apply processing [-> WRI_SVC_AUTO_APLY = "WrisvcAutoAplyCC"] |

**Block 8** — [CLEANUP] Remove temp data (L1464)

> Cleans up the temporary discount application parameter from the param store.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `param.removeData(WRI_SVC_AUTO_APLY)` // Remove auto-apply map from param |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kktk_svc_kei_no` | Field | Equipment-provided service contract number (機器提供サービス契約番号) — unique identifier for a service contract line item associated with equipment provisioning |
| `kktk_svc_kei_stat` | Field | Equipment-provided service contract status (機器提供サービス契約ステータス) — current lifecycle state of the service contract (e.g., active, cancelled, terminated) |
| `kktk_svc_cd` | Field | Equipment-provided service code (機器提供サービスコード) — code identifying the type of equipment-provided service (e.g., router, ONT, set-top box) |
| `kktk_sbt_cd` | Field | Equipment-provided type code (機器提供種類コード) — classification code for the equipment provisioning category |
| `pcrs_cd` | Field | Cost code (料金コースコード) — pricing plan tier code determining the cost structure of the service |
| `pplan_cd` | Field | Plan code (料金プランコード) — specific billing plan code associated with the service contract |
| `mskm_no` | Field | Application number (申込番号) — unique identifier for the service order/application |
| `mskm_sbt_cd` | Field | Application type code (申込種類コード) — classification of the application type, mapped from displacement division code |
| `ido_div` | Field | Displacement division code (異動区分) — indicates the type of operation or displacement (e.g., new installation, modification, cancellation) |
| `func_code` | Field | Function code (機能コード) — identifies the calling function or screen module |
| `svc_cancel_rsn_cd` | Field | Service cancellation reason code (サービスキャンセル理由コード) — reason for service cancellation |
| `svc_dlre_cd` | Field | Service termination reason code (サービス解約理由コード) — reason for service termination |
| `add_chge_div` | Field | Add/change division code (登録／変更区分) — categorizes the operation as registration, modification, cancellation, or termination |
| `sysid` | Field | System ID — identifies the source system in the multi-system environment |
| `tg_kei_skbt_cd` | Field | Target contract identifier code (対象契約識別コード) — identifies the type of contract being targeted; "06" means equipment-provided service contract |
| `grp_div` | Field | Group division code (グループ区分) — structural grouping code within the service contract group list; "00" represents a standard group |
| `svc_kei_grp_list` | Field | Service contract group list (サービス契約グループリスト) — hierarchical structure containing groups of service contracts with their details |
| `WRI_SVC_AUTO_APLY` | Constant | Write-in service auto-apply map key (割引サービス自動適用CC実行処理) — parameter map key for the discount application payload |
| `TEMPLATE_ID_EKK0341A010` | Constant | Equipment service contract list sync CBS template ID (機器提供サービス契約照会統合) — template identifier for the EKK0341A010 CBS that retrieves equipment service contract data |
| `TEMPLATE_ID_EKK0021A010` | Constant | Order details agreement sync CBS template ID (申請明細照会統合) — template identifier for the EKK0021A010 CBS that retrieves order detail data |
| EKK0341A010CBS | CBS | Equipment service contract list sync CBS (機器提供サービス契約照会統合CBS) — common business service for querying equipment-provided service contract information |
| EKK0021A010CBS | CBS | Order details agreement sync CBS (申請明細照会統合CBS) — common business service for querying order detail/agreement information |
| JKKWrisvcAutoAplyCC | Component | Write-in service auto-apply CC (割引サービス自動適用CC) — component that automatically evaluates and applies service discounts based on contract conditions and cancellation/termination reasons |
| JKKKapKeiInfoCancelCC | Component | Equipment-provided service contract info cancellation CC (機器提供サービス契約情報取消CC) — component handling cancellation/termination of equipment-provided service contracts |
| CAANMsg | Type | CBS message response wrapper — generic message container used to pass structured data between CBS layers |
| `ADD_CHGE_DIV_CANCEL` | Constant | "05" — Add/change division code for cancellation (登録／変更区分 キャンセル) |
| `ADD_CHGE_DIV_DSL` | Constant | "03" — Add/change division code for termination/DSL (登録／変更区分 解約) |
| `SVC_CANCEL_RSN_CD` | Constant | "01" — Service cancellation reason code (サービスキャンセル理由コード) |
| `SVC_DLRE_CD` | Constant | "01" — Service termination reason code (サービス解約理由コード) |
| `mskm_sbt_cd` | Field | Application type code (申込種類コード) — derived from displacement division, represents the type of service application |
| Cancel (キャンセル) | Business term | Service cancellation — customer-initiated cancellation of a service before or shortly after activation |
| Termination (解約) | Business term | Service termination — end of a service contract, typically after a commitment period or by mutual agreement |
| Discount application (割引適用) | Business term | Process of automatically determining and applying price discounts to service contracts based on cancellation/termination reasons, contract type, and promotional conditions |
