# Business Logic — JKKCancelSvcKeiMapperCC.editMapWrisvcAutoAply() [130 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `com.fujitsu.futurity.bp.custom.common.JKKCancelSvcKeiMapperCC` |
| Layer | CC / Common Component |
| Module | `common` (Package: `com.fujitsu.futurity.bp.custom.common`) |

## 1. Role

### JKKCancelSvcKeiMapperCC.editMapWrisvcAutoAply()

This method performs **discounted-service automatic application mapping** -- it prepares the CAANMsg data structure required by the service component before executing a service contract cancellation. Specifically, it acts as a **data mapper** (in the data-mapping pattern) that transforms the retrieved service-contract lookup result (`ekk0081a010Map`) and supplementary work fields into a flat output map (`outMap`) with a nested service-contract group list (`svc_kei_grp_list`). The method determines the cancellation rationale based on the **current status of the existing service contract**: if the contract is in a settled or otherwise non-active state (settled, service-providing, paused, or suspended), it records a standard termination reason code and an "additional-change code" for settled status (`03`); otherwise it records the cancellation-reason code pulled from the work field. The method is a shared utility component called by the main cancel-execution logic (`JKKCancelSvcKeiCC.executeWribAutoAplyCC`) and the DSL execution runner (`JKKDslRun.dslTjitu`), enabling the downstream cancel-service-component to process the cancellation with all necessary context.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["editMapWrisvcAutoAply(params)"])
    SvcEndymdSet["Set svcEndymd = oPE_DATE"]
    SvcChrgEndymdSet["Set svcChrgEndymd = oPE_DATE"]
    GetOutMap["Get outMap = param.getData(fixedText)"]
    PutSysid["Set outMap.sysid = ekk0081a010Map.sysid"]
    CheckSvcKeiStat{"Check svc_kei_stat"}
    IsCncOrHalted["SVC_KEI_STAT_CNC_ZM=030 | SVC_KEI_STAT_SVCTK_CHU=100 | SVC_KEI_STAT_STAT_PAUSE=210 | SVC_KEI_STAT_STAT_STP=220"]
    SetAddChgeDiv03["Set outMap.add_chge_div = 03"]
    SetSvcDlreCd["Set outMap.svc_dlre_cd = SVC_DLRE_CD_NORMAL=01"]
    SetAddChgeDiv05["Set outMap.add_chge_div = 05"]
    SetSvcCancelRsn["Set outMap.svc_cancel_rsn_cd = workField.CANCEL_RSN_CD"]
    PutMskmNo["Set outMap.mskm_no = mskmNo"]
    PutMskmSbtCd["Set outMap.mskm_sbt_cd = MKSBT_CD_CANCEL=00006"]
    PutIdoDiv["Set outMap.ido_div = idoDiv"]
    PutFuncCode["Set outMap.func_code = FUNC_CD_1"]
    InitSvcKeiArray["Init workSvcKeiArray = ArrayList"]
    InitSvcKeiMap["Init workSvcKeiMap = HashMap"]
    SetGrpDiv["Set workSvcKeiMap.grp_div = GRP_DIV_STDARD=00"]
    InitSvcKeiList["Init workSvcKeiList = ArrayList"]
    InitSvcKeiData["Init workSvcKeiData = HashMap"]
    SetWorkDataSysid["Set workSvcKeiData.sysid = ekk0081a010Map.sysid"]
    SetTgKeiSkbtCd["Set workSvcKeiData.tg_kei_skbt_cd = TG_KEI_SKBT_CD_SVC_KEI=01"]
    SetSvcKeiNo["Set workSvcKeiData.svc_kei_no = ekk0081a010Map.svc_kei_no"]
    SetSvcKeiStat["Set workSvcKeiData.svc_kei_stat = ekk0081a010Map.svc_kei_stat"]
    SetSvcCd["Set workSvcKeiData.svc_cd = ekk0081a010Map.svc_cd"]
    SetPrcGrpCd["Set workSvcKeiData.prc_grp_cd = ekk0081a010Map.prc_grp_cd"]
    SetPcrsCd["Set workSvcKeiData.pcrs_cd = ekk0081a010Map.pcrs_cd"]
    SetPplanCd["Set workSvcKeiData.pplan_cd = ekk0081a010Map.pplan_cd"]
    CheckSvcEndYmd{"svcEndymd is null or empty?"}
    SetSvcEndFromMap["Set workSvcKeiData.svc_endymd = ekk0081a010Map.svc_endymd"]
    SetSvcEndFromVar["Set workSvcKeiData.svc_endymd = svcEndymd"]
    CheckSvcChrgEndYmd{"svcChrgEndymd is null or empty?"}
    SetChrgEndFromMap["Set workSvcKeiData.svc_chrg_endymd = ekk0081a010Map.svc_chrg_endymd"]
    SetChrgEndFromVar["Set workSvcKeiData.svc_chrg_endymd = svcChrgEndymd"]
    AddSvcKeiToList["workSvcKeiList.add(workSvcKeiData)"]
    SetSvcKeiListInMap["workSvcKeiMap.svc_kei_list = workSvcKeiList"]
    AddSvcKeiMapToArray["workSvcKeiArray.add(workSvcKeiMap)"]
    SetSvcKeiGrpList["outMap.svc_kei_grp_list = workSvcKeiArray"]
    END(["Return / Next"])

    START --> SvcEndymdSet --> SvcChrgEndymdSet --> GetOutMap --> PutSysid --> CheckSvcKeiStat
    CheckSvcKeiStat --> |Match any status| IsCncOrHalted --> SetAddChgeDiv03 --> SetSvcDlreCd --> PutMskmNo
    CheckSvcKeiStat --> |No match| SetAddChgeDiv05 --> SetSvcCancelRsn --> PutMskmNo
    SetSvcDlreCd --> PutMskmNo
    SetSvcCancelRsn --> PutMskmNo --> PutMskmSbtCd --> PutIdoDiv --> PutFuncCode --> InitSvcKeiArray --> InitSvcKeiMap --> SetGrpDiv --> InitSvcKeiList --> InitSvcKeiData --> SetWorkDataSysid --> SetTgKeiSkbtCd --> SetSvcKeiNo --> SetSvcKeiStat --> SetSvcCd --> SetPrcGrpCd --> SetPcrsCd --> SetPplanCd --> CheckSvcEndYmd
    CheckSvcEndYmd --> |yes| SetSvcEndFromMap --> CheckSvcChrgEndYmd
    CheckSvcEndYmd --> |no| SetSvcEndFromVar --> CheckSvcChrgEndYmd
    CheckSvcChrgEndYmd --> |yes| SetChrgEndFromMap --> AddSvcKeiToList
    CheckSvcChrgEndYmd --> |no| SetChrgEndFromVar --> AddSvcKeiToList
    AddSvcKeiToList --> SetSvcKeiListInMap --> AddSvcKeiMapToArray --> SetSvcKeiGrpList --> END
```

**CRITICAL -- Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|-----------------|
| `SVC_KEI_STAT_CNC_ZM` | `"030"` | Service contract status: Settled (completed settlement, no active service yet) |
| `SVC_KEI_STAT_SVCTK_CHU` | `"100"` | Service contract status: Service-providing (active service in progress) |
| `SVC_KEI_STAT_STAT_PAUSE` | `"210"` | Service contract status: Paused/Suspended (service temporarily stopped) |
| `SVC_KEI_STAT_STAT_STP` | `"220"` | Service contract status: Stopped (permanently halted) |
| `SVC_DLRE_CD_NORMAL` | `"01"` | Service termination reason code: Normal termination |
| `MKSBT_CD_CANCEL` | `"00006"` | Order subtype code: Cancellation |
| `GRP_DIV_STDARD` | `"00"` | Group division: Standard group |
| `TG_KEI_SKBT_CD_SVC_KEI` | `"01"` | Target contract identification code: Service contract |
| `JPCModelConstant.FUNC_CD_1` | `"1"` | Functional code: Standard operation |
| `oPE_DATE` | `""` | Operation date (instance field, resolved at runtime via setter) |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `param` | `IRequestParameterReadWrite` | Business data input/output interface; provides access to the CAANMsg message structure via `getData()`. Used to retrieve and modify the message map for the given `fixedText` key. |
| 2 | `fixedText` | `String` | User-defined string used as a key/identifier to retrieve the specific sub-map from `param.getData()`. Acts as a message-segment identifier for multi-segment CAANMsg structures. |
| 3 | `idoDiv` | `String` | Change/alteration division code. Identifies the type of service change operation (e.g., DSL cancellation, cancellation, address change). Passed through to the output map as `ido_div`. |
| 4 | `mskmNo` | `String` | Order/application number (申込番号). Unique identifier for the service order or application being cancelled. Maps to `mskm_no` in the output. |
| 5 | `ekk0081a010Map` | `HashMap` | Service contract one-agreement lookup result. Contains the full record of the existing service contract retrieved by the EKK0081A010CBS query -- includes service contract number, status, service code, pricing group code, pricing course code, pricing plan code, end dates, and sysid. This is the primary data source for mapping service contract details. |
| 6 | `workField` | `HashMap<String,Object>` | Supplementary work field map carrying cancellation-related context from the caller. Used to retrieve the cancellation-reason code (`CANCEL_RSN_CD`) when the service contract is not in a settled state. |

**Instance fields / external state read by the method:**

| Field | Type | Description |
|-------|------|-------------|
| `oPE_DATE` | `String` | Operation date set via setter; used as the service end date and service charge end date values |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `param.getData(fixedText)` | - | - | Retrieves the CAANMsg sub-map identified by `fixedText` key. Reads existing message data to prepare for mapping. |

**Notes:** This method performs **pure data mapping** -- it does not invoke any Service Components (SC), Call-by-Service (CBS), or direct database operations. It reads data from the input `param` interface and the `ekk0081a010Map` / `workField` HashMaps, performs conditional logic to set cancellation classification fields, and assembles nested ArrayList/HashMap structures representing the service-contract group list. All data is mapped into the output CAANMsg structure (`outMap`) for downstream consumption by the cancel-service-component.

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 15 methods.
Terminal operations from this method: `getData` [R], `getData` [R], `getData` [R], `getData` [R], `getData` [R]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JKKCancelSvcKeiCC.executeWribAutoAplyCC()` | `JKKCancelSvcKeiCC.executeWribAutoAplyCC` -> `JKKCancelSvcKeiMapperCC.editMapWrisvcAutoAply` | `param.getData [R] CAANMsg` |
| 2 | `JKKDslRun.dslTjitu()` | `JKKDslRun.dslTjitu` -> `JKKCancelSvcKeiMapperCC.editMapWrisvcAutoAply` | `param.getData [R] CAANMsg` |

**Notes:** The two direct callers above represent the primary entry points:
- **JKKCancelSvcKeiCC.executeWribAutoAplyCC**: The main service-component cancel execution logic, called from screen operations (e.g., service contract cancellation screens like KKSV0004).
- **JKKDslRun.dslTjitu**: DSL (Data Service Layer) execution runner, invoked for batch/automated processing scenarios.

## 6. Per-Branch Detail Blocks

**Block 1** -- [INITIALIZATION] `(L3737-3739)`

Initialize operation date variables for service end date and service charge end date.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcEndymd = oPE_DATE` // Operation date -- used as service end date [-> oPE_DATE=""] |
| 2 | SET | `svcChrgEndymd = oPE_DATE` // Operation date -- used as service charge end date [-> oPE_DATE=""] |

**Block 2** -- [EXEC] `(L3741)`

Retrieve the output message map from the parameter interface using `fixedText` as the key.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `outMap = param.getData(fixedText)` // Retrieve CAANMsg sub-map [-> getData(R)] |

**Block 3** -- [SET] `(L3744)`

Set the system ID from the lookup result into the output map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("sysid", ekk0081a010Map.get(EKK0081A010CBSMsg1List.SYSID))` // Copy sysid from lookup result |

**Block 4** -- [IF/ELSE] `[SVC_KEI_STAT_CNC_ZM="030" \| SVC_KEI_STAT_SVCTK_CHU="100" \| SVC_KEI_STAT_STAT_PAUSE="210" \| SVC_KEI_STAT_STAT_STP="220"] (L3747-3766)`

Determine cancellation classification based on the current service-contract status. This was modified in IT1-2019-0000085 (2019/12/16) to include service-providing, paused, and stopped states (previously only checked for "settled" state).

- **If** the service contract status is any of: Settled (030), Service-providing (100), Paused (210), or Stopped (220) -- meaning the service is either fully settled or otherwise non-active:

**Block 4.1** -- [IF TRUE] "Settled or non-active status" `(L3752-3755)`

The service contract's pre-processing status is "settled" or equivalent non-active state. Set additional-change division to `03` (settled-change category) and service-termination reason code to `01` (normal termination). (処理実施前のサービス契約ステータスが「締結済」の場合 / When the service contract status before processing is "settled")

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("add_chge_div", "03")` // Registration/Change division: settled status [-> "03"] |
| 2 | SET | `outMap.put("svc_dlre_cd", SVC_DLRE_CD_NORMAL)` // Service termination reason code [-> SVC_DLRE_CD_NORMAL="01"] |

- **Else** (the service contract is in a non-settled, non-active state -- e.g., effectively only exists but has not yet been settled):

**Block 4.2** -- [ELSE] "Non-settled status" `(L3758-3762)`

The service contract is not in a settled state (i.e., only exists in a non-settled status). Set additional-change division to `05` and pull the cancellation reason code from the work field. (処理実施前サービス契約ステータスが「締結済」以外の場合(実質照查しか存在しない) / When the service contract status before processing is other than "settled" (effectively only a lookup exists))

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("add_chge_div", "05")` // Registration/Change division: non-settled status [-> "05"] |
| 2 | SET | `outMap.put("svc_cancel_rsn_cd", workField.get(JKKCancelSvcKeiCC.CANCEL_RSN_CD))` // Service cancellation reason code [-> CANCEL_RSN_CD="cancel_rsn_cd"] |

**Block 5** -- [SET] `(L3769-3773)`

Set the core order and change-division identification fields in the output map.

| # | Type | Code |
|---|------|------|
| 1 | SET | `outMap.put("mskm_no", mskmNo)` // Order number (申込番号) |
| 2 | SET | `outMap.put("mskm_sbt_cd", MKSBT_CD_CANCEL)` // Order subtype code [-> MKSBT_CD_CANCEL="00006" (Cancellation)] |
| 3 | SET | `outMap.put("ido_div", idoDiv)` // Change division code passed from caller |
| 4 | SET | `outMap.put("func_code", JPCModelConstant.FUNC_CD_1)` // Functional code [-> FUNC_CD_1="1"] |

**Block 6** -- [INITIALIZATION] `(L3780-3781)`

Initialize the nested service-contract group-list structure for the CAANMsg payload.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `workSvcKeiArray = new ArrayList<HashMap>()` // Service-contract group list (outer) |
| 2 | EXEC | `workSvcKeiMap = new HashMap<String, Object>()` // Service-contract group-level map |

**Block 7** -- [SET] `(L3784)`

Set the group division code for the service-contract group.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workSvcKeiMap.put("grp_div", JKKDslRun.GRP_DIV_STDARD)` // Group division [-> GRP_DIV_STDARD="00" (Standard)] |

**Block 8** -- [INITIALIZATION] `(L3788-3789)`

Initialize the service-contract list and the individual service-contract data map.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `workSvcKeiList = new ArrayList<HashMap>()` // Service-contract list (inner) |
| 2 | EXEC | `workSvcKeiData = new HashMap<String, Object>()` // Individual service-contract data |

**Block 9** -- [MAPPING] `(L3793-3837)`

Map all service-contract fields from the lookup result (`ekk0081a010Map`) to the service-contract data map. This mirrors the structure expected by the CAANMsg service-contract entity.

| # | Type | Code |
|---|------|------|
| 1 | SET | `workSvcKeiData.put("sysid", ekk0081a010Map.get(EKK0081A010CBSMsg1List.SYSID))` // System ID |
| 2 | SET | `workSvcKeiData.put("tg_kei_skbt_cd", JKKDslRun.TG_KEI_SKBT_CD_SVC_KEI)` // Target contract ID [-> TG_KEI_SKBT_CD_SVC_KEI="01" (Service contract)] |
| 3 | SET | `workSvcKeiData.put("svc_kei_no", ekk0081a010Map.get(EKK0081A010CBSMsg1List.SVC_KEI_NO))` // Service contract number |
| 4 | SET | `workSvcKeiData.put("svc_kei_stat", ekk0081a010Map.get(EKK0081A010CBSMsg1List.SVC_KEI_STAT))` // Service contract status |
| 5 | SET | `workSvcKeiData.put("svc_cd", ekk0081a010Map.get(EKK0081A010CBSMsg1List.SVC_CD))` // Service code |
| 6 | SET | `workSvcKeiData.put("prc_grp_cd", ekk0081a010Map.get(EKK0081A010CBSMsg1List.PRC_GRP_CD))` // Pricing group code |
| 7 | SET | `workSvcKeiData.put("pcrs_cd", ekk0081a010Map.get(EKK0081A010CBSMsg1List.PCRS_CD))` // Pricing course code |
| 8 | SET | `workSvcKeiData.put("pplan_cd", ekk0081a010Map.get(EKK0081A010CBSMsg1List.PPLAN_CD))` // Pricing plan code |

**Block 9.1** -- [IF/ELSE] `[svcEndymd is null or empty] (L3814-3822)`

Map the service end date -- prefer the operation date (`svcEndymd`) if set, otherwise use the lookup result value.

| # | Type | Code |
|---|------|------|
| 1 | IF | `svcEndymd == null || "".equals(svcEndymd)` |
| 1.1 | SET [IF TRUE] | `workSvcKeiData.put("svc_endymd", ekk0081a010Map.get(EKK0081A010CBSMsg1List.SVC_ENDYMD))` // Service end date from lookup |
| 1.2 | SET [IF FALSE] | `workSvcKeiData.put("svc_endymd", svcEndymd)` // Service end date from operation date [-> oPE_DATE=""] |

**Block 9.2** -- [IF/ELSE] `[svcChrgEndymd is null or empty] (L3826-3834)`

Map the service charge end date -- prefer the operation date (`svcChrgEndymd`) if set, otherwise use the lookup result value.

| # | Type | Code |
|---|------|------|
| 1 | IF | `svcChrgEndymd == null || "".equals(svcChrgEndymd)` |
| 1.1 | SET [IF TRUE] | `workSvcKeiData.put("svc_chrg_endymd", ekk0081a010Map.get(EKK0081A010CBSMsg1List.SVC_CHRG_ENDYMD))` // Service charge end date from lookup |
| 1.2 | SET [IF FALSE] | `workSvcKeiData.put("svc_chrg_endymd", svcChrgEndymd)` // Service charge end date from operation date [-> oPE_DATE=""] |

**Block 10** -- [COMPOSITION] `(L3836-3840)`

Assemble the nested ArrayList/HashMap structure: service-contract data -> list -> group map -> group array -> output map.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `workSvcKeiList.add(workSvcKeiData)` // Add service-contract data to list |
| 2 | SET | `workSvcKeiMap.put("svc_kei_list", workSvcKeiList)` // Set list in group map |
| 3 | EXEC | `workSvcKeiArray.add(workSvcKeiMap)` // Add group map to array |
| 4 | SET | `outMap.put("svc_kei_grp_list", workSvcKeiArray)` // Set group array in output map |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svc_kei_ucwk_no` | Field | Service detail work number -- internal tracking ID for service contract line items |
| `svc_kei_no` | Field | Service contract number -- unique identifier for a service contract record |
| `svc_kei_stat` | Field | Service contract status -- code indicating the lifecycle state of a service contract |
| `svc_dlre_cd` | Field | Service termination reason code -- reason why the service contract is being terminated |
| `svc_cancel_rsn_cd` | Field | Service cancellation reason code -- reason for cancellation, sourced from work field |
| `svc_endymd` | Field | Service end date/year-month-day -- the date when the service contract expires or ends |
| `svc_chrg_endymd` | Field | Service charge end date/year-month-day -- the date when service-related billing ends |
| `svc_cd` | Field | Service code -- identifies the type of telecom service (e.g., FTTH, Mail, ENUM) |
| `mskm_no` | Field | Order/application number (申込番号) -- unique identifier for the customer order or application |
| `mskm_sbt_cd` | Field | Order subtype code (申込種別コード) -- classifies the type of order (e.g., cancellation = "00006") |
| `ido_div` | Field | Change/alteration division code -- indicates the type of service change operation |
| `add_chge_div` | Field | Registration/change division -- classifies the nature of the change (settled vs non-settled) |
| `grp_div` | Field | Group division -- categorizes the service-contract group (e.g., "00" = standard) |
| `tg_kei_skbt_cd` | Field | Target contract identification code -- identifies what type of contract is targeted (e.g., "01" = service contract) |
| `prc_grp_cd` | Field | Pricing group code -- groups pricing structures for a service |
| `pcrs_cd` | Field | Pricing course code -- identifies the specific pricing course/tier |
| `pplan_cd` | Field | Pricing plan code -- identifies the specific pricing plan within a course |
| `sysid` | Field | System ID -- identifies the system that owns the data record |
| `func_code` | Field | Functional code -- identifies the type of business operation/function |
| `oPE_DATE` | Field | Operation date -- system date set at runtime, used as the effective service end date |
| CNC_ZM | Business term | 締結済 (Teiketsu-zumi) -- Settled/Completed settlement; contract is fully registered but service may not have started |
| SVCTK_CHU | Business term | サービス提供中 (Saabii Teikyou-chu) -- Service-providing; service is actively being delivered to the customer |
| STAT_PAUSE | Business term | 休止・中断中 (Kiusu·Chudan-chu) -- Paused/Interrupted; service is temporarily suspended |
| STAT_STP | Business term | 停止中 (Teishi-chu) -- Stopped; service is halted (potentially permanently) |
| DLC_ZM | Business term | 解除済 (Kaijo-zumi) -- Cancellation completed; service contract has been fully cancelled |
| DSL_ZM | Business term | 解約済 (Kaiya-zumi) -- Termination completed; subscription has been terminated |
| CANCEL_ZM | Business term | キャンセル済 (Kyanseru-zumi) -- Cancellation completed (pending status) |
| MKSBT_CD_CANCEL | Constant | Order subtype code "00006" -- represents a cancellation order type |
| SVC_DLRE_CD_NORMAL | Constant | Normal termination reason code "01" -- standard cancellation (not due to specific cause) |
| GRP_DIV_STDARD | Constant | Standard group division "00" -- default grouping for service contracts |
| CAANMsg | Technical term | Fujitsu's message/data transfer structure used for inter-component communication in the BPM framework |
| EKK0081A010 | CBS | Service contract one-agreement inquiry CBS -- queries the service contract record for a given contract number |
| CC | Abbreviation | Common Component -- a reusable business logic component shared across screens and batch processes |
| SC Code | Abbreviation | Service Component code (e.g., EKK0081A010SC) -- identifies the backend service component for database operations |
| CAAN | Business term | Fujitsu's application message framework (CAAN = Component Application ANimation) for structured data transfer between tiers |
| FTTH | Business term | Fiber To The Home -- fiber-optic broadband internet service offered by K-Opticom |
| CAABMsg | Technical term | CAAN-based message structure for service component calls; holds mapped data ready for CBS invocation |
