# Business Logic — JKKWrisvcAutoAplyCC.createWribsvkDchskmstAdd() [569 LOC]

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

## 1. Role

### JKKWrisvcAutoAplyCC.createWribsvkDchskmstAdd()

This method is the central dispatch engine for registering discount service contracts (割引サービス契約) and data extraction item settings (データ抽出項目設定) during the automatic application process in the K-Opticom customer base system. It acts as a type-based router that bifurcates processing along two major branches identified by the `wribDchsSkbtFlag`: **Discount Service** (flag = "1") and **Data Extraction Item** (flag = "2").

For the **Discount Service branch**, the method handles two distinct business scenarios. When `addChgeDiv` equals `KAIHK` ("04", Recovery), it processes service recovery: it inquires discount service details, applies conditional logic around integrated corporate plans (一括CP) and work charge discount types, and when applicable, creates cancellation/restore records by iterating through the `wribsvkDchskmstKaisenList` (discount service item history list). It then handles special work charge inheritance flows for both NET-based and TEL-based service codes, updating application counts via EKK2361B010/EKK2361C020 interfaces. For non-recovery cases, it delegates overlap removal and registers discount service target contracts.

For the **Data Extraction Item branch**, the method similarly removes overlapping target contract records before either registering them in a batch (when `removeOverLapTgKei` returns a non-null key) or performing full item registration including inquiry service confirmation, item record creation, and a loop to register all target contracts with generated sequence numbers.

The method implements the **routing/dispatch pattern**, delegating to sub-methods for each concern (cancel/restore creation, overlap removal, service inquiry, registration, work charge update). It is a shared CC component called by `addWribsvkDchskmst` during the automatic application processing screen flow, and plays a critical role in the service contract lifecycle — handling creation, recovery, and cancellation of discount services and their associated data extraction settings.

## 2. Processing Pattern (Detailed Business Logic)

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

    START --> C1{wribDchsSkbtFlag check}

    C1 -- Flag equals 1 --> WRIB_BRANCH["Discount Service Branch"]
    C1 -- Flag equals 2 --> DCHS_BRANCH["Data Extraction Branch"]

    WRIB_BRANCH --> A1{addChgeDiv check}

    A1 -- KAIHK = 04 --> RECOVERY_PATH["Recovery processing path"]
    A1 -- else --> NORMAL_ADD_PATH["Normal add path"]

    RECOVERY_PATH --> R1["setMsgMap: message map generation"]
    R1 --> R2["callWribSvcKeiIchiiShokai: inquiry discount service"]
    R2 --> R3["restore MSKM_DTL_NO"]
    R3 --> R4["setMaxLastUpdDtm: set update datetime"]

    R4 --> IKT_CHECK{hasIktCp and KOJIHI_CP_NET check}
    IKT_CHECK -- false --> IKT_SKIP["Skip skip: continue"]
    IKT_CHECK -- true --> IKT_SKIP

    IKT_SKIP --> R5["setMskmDtlNo: set application detail number"]

    R5 --> R6{wribSvcKeiStat check}

    R6 -- CNCL_ZM = 920 --> R7["callWribsvkCanselRecover: pre-cancel recover"]
    R6 -- else --> R8["callWribsvkRecover: recover service"]

    R7 --> R9["get wribSvcCd and firstSeikySvcKeiNo"]

    R8 --> R9

    R9 --> R10{KOJIHI_CP_NET or KOJIHI_WRBK_CP check}

    R10 -- true --> DSL_LOOP["DSL cancel loop over kaisen list"]
    R10 -- false --> R11{KOJIHI_CP_KAP_TEL check}

    DSL_LOOP --> D1["loop through kaisen list"]
    D1 --> D2{matching KOJIHI_CP_NET and KOJIHI_CP_KAP_TEL}
    D2 -- true --> D3["create cancel record"]
    D3 --> D4{statDel == UK_ZM = 010}
    D4 -- true --> D5["set cancel rsn code OTHER"]
    D4 -- false --> D6{statDel == SVC_TK_CHU = 100}
    D6 -- true --> D7["set dlre code TUJYO_DSL and end dates"]
    D6 -- false --> D8["break loop"]
    D5 --> D9["createWribsvkDchskmstDslCncl"]
    D7 --> D9
    D9 --> D10["callEKK2361B010: get apply count"]
    D10 --> D11["callEKK2361B010: get saki list"]
    D11 --> D12["callEKK2361C020: update apply count"]
    D12 --> D13["break inner"]

    D2 -- false --> DSL_CANCLE_END["DSL cancel loop end"]
    D13 --> DSL_CANCLE_END

    DSL_CANCLE_END --> R11

    R11 -- true --> TEL_PATH["KOJIHI_CP_TEL processing"]
    R11 -- false --> AFTER_KOJIHI["After kojihi cp check"]

    TEL_PATH --> T1["get wrisvcTgKeiList from inMap"]
    T1 --> T2["callEKK0081B029: inquiry service contract"]
    T2 --> T3["loop ekk0081B029List"]
    T3 --> T4["callSvcKeiIchiiShokai: inquiry service contract"]
    T3 --> T5{svcCd == CD00130_01 or CD00130_02}
    T5 -- false --> T3_CONT["continue loop"]
    T5 -- true --> T6["add svcKeiNo to list"]

    T6 --> T7{svcKeiNoList not empty}

    T7 -- true --> T8["getKojihiKapCpNew: get max application"]
    T8 --> T9{motoWribAplyCnt not 0}

    T9 -- true --> T10["callEKK2361B010: get saki list"]
    T10 --> T11{moto greater saki apply}
    T11 -- true --> T12["callEKK2361C020: update apply count"]

    T7 -- false --> AFTER_KOJIHI

    T9 -- false --> AFTER_KOJIHI

    AFTER_KOJIHI --> N1{wribSvcKeiNo != null}

    N1 -- true --> N2["loop wrisvcTgKeiList for registration"]
    N2 --> N3["set getLastUpdDtm: set update datetime"]

    N3 --> N4{ADD_CHGE_DIV_KAIHK and WRIB_SET_NET check}

    N4 -- true --> N3_CONT2["continue loop"]
    N4 -- false --> N5["callWribsvkTgKeiAdd: register target"]

    N5 --> N6["Return Next"]

    N1 -- false --> N7["setMsgMap: message map generation"]
    N7 --> N8["setMaxLastUpdDtm: set update datetime"]
    N8 --> N9["setMskmDtlNo: set application detail number"]

    N9 --> N10{sakiWribSvcCd in ALL_KOJIHI_CP}

    N10 -- true --> N11_1["call hktgWribUpdate: work charge discount"]
    N10 -- false --> N12["callWribsvKeiAdd: register discount service"]

    N12 --> N6

    DCHS_BRANCH --> D14["removeOverLapTgKei: remove overlap"]

    D14 --> D15{dchskmstNo != null}

    D15 -- true --> D16["loop dchskmstTgKeiList"]
    D16 --> D17["set update datetime from inMap"]
    D17 --> D18["callDchskmstTgKeiAdd: register extraction target"]
    D18 --> D19["Return Next"]

    D15 -- false --> D20["setMaxLastUpdDtm: set update datetime"]
    D20 --> D21["setMskmDtlNo: set application detail number"]
    D21 --> D22["callDchskmIchiiShokai: data extraction inquiry"]
    D22 --> D23["callDchskmstAdd: register data extraction"]

    D23 --> D24["get dchskmstNo and dchskmstTgKeiList"]
    D24 --> D25["calcRenbanDigitSize: calculate digit size"]
    D25 --> D26["loop dchskmstTgKeiList"]
    D26 --> D27["generate renbanNoForTgKei with 01 group"]
    D27 --> D28["set getLastUpdDtm: set update datetime"]
    D28 --> D29["callDchskmstTgKeiAdd: register target contract"]
    D29 --> D30["Return Next"]
```

**Constant Resolution:**

| Constant | Value | Business Meaning |
|----------|-------|-----------------|
| `WRIB_DCHS_SKBT_FLAG_WRIB` | `"1"` | Discount Service identifier flag |
| `WRIB_DCHS_SKBT_FLAG_DCHS` | `"2"` | Data Extraction Item identifier flag |
| `ADD_CHGE_DIV_KAIHK` | `"04"` | Recovery (add/change distinction: recovery) |
| `WRIB_SVC_KEI_STAT_CNCL_ZM` | `"920"` | Pre-cancel status (before confirmation cancel) |
| `WRIB_SVC_KEI_STAT_UK_ZM` | `"010"` | Unbilled status (受注済) |
| `WRIB_SVC_KEI_STAT_SVC_TK_CHU` | `"100"` | Service in progress (サービス提供中) |
| `CD01390_CL_TEISE` | `"20"` | Cancellation Correction (取消（訂正）) |
| `SVC_CANCEL_RSN_CD_OTHER` | `"05"` | Other reason cancellation (その他理由によるキャンセル) |
| `SVC_DLRE_CD_TUJYO_DSL` | `"01"` | Normal termination (通常解約) |
| `CD00130_01` | `"01"` | Net service type |
| `CD00130_02` | `"02"` | Phone service type |
| `WRIBSVK_DCHSKMST_GRP_SET` | `"01"` | Group set identifier for discount service item settings |
| `DCHSKM_ICHII_FUNC_CD` | `"2"` | Data extraction item inquiry function code |
| `WRIB_SVC_KEI_ICHII_FUNC_CD` | `"2"` | Discount service contract inquiry function code |
| `SVC_KEI_ICHII_FUNC_CD` | `"2"` | Service contract inquiry function code |

**List Constants:**

| Constant | Contents |
|----------|----------|
| `KOJIHI_CP_NET_LIST` | `["W00000001" (NET), "W00000015" (NET_24)]` |
| `KOJIHI_CP_KAP_TEL_LIST` | `["W00000002" (TEL), "W00000014" (TEL_24)]` |
| `ALL_KOJIHI_CP_LIST` | `["W00000001" (NET), "W00000002" (TEL), "W00000015" (NET_24), "W00000014" (TEL_24), "W00000013" (TEL_IKT)]` |
| `WRIB_SET_NET_AND_MOVA` | `["W00000005"]` |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `ccMap` | `HashMap<String, Object>` | Work area (作業領域) — the shared processing context map carrying session-level data including function code, operation date, recovery maps, and various flag states |
| 2 | `inMapWribsvkDchskmst` | `HashMap<String, Object>` | Discount service contract map (割引サービス契約マップ) — contains the core business data for the discount service item being registered, including service code, status, target contracts, and update timestamps |
| 3 | `havingWribsvcList` | `ArrayList<HashMap<String, Object>>` | Already-applied discount service contract list (適用済み割引サービス契約リスト) — list of existing contracts to check for overlaps and determine which ones need cancellation/restore processing |
| 4 | `wribDchsSkbtFlag` | `String` | Discount service / Data extraction item identification flag (割引サービス／データ抽出項目識別フラグ) — routes processing: `"1"` = Discount Service, `"2"` = Data Extraction Item |
| 5 | `funcCd` | `String` | Function code (機能コード) — identifies the calling screen/business function for audit and routing |
| 6 | `renbanNo` | `String` | SC map serial number (SCマップ連番) — sequence number used in service component calls for audit trail correlation |
| 7 | `wribsvkDchskmstKaisenList` | `ArrayList<HashMap<String, Object>>` | Discount service item history list (割引サービス契約履歴リスト) — added in IT1-2018-0000073; replaced `havingWribsvcList` for cancellation/restore iteration, contains historical records of discount service items |

**Instance/External State Read:**
- `this.seikyYm` — operation year-month (referenced in commented-out code paths)

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCBPCommon.getOpeDate` | - | - | Gets the current operation date for service end dates (SVC_ENDYMD, SVC_CHRG_ENDYMD) |
| R | `JKKWrisvcAutoAplyCC.calcRenbanDigitSize` | - | - | Calculates the digit size needed for the renban (serial number) based on list count |
| R | `JKKWrisvcAutoAplyCC.getKojihiKapCpNew` | - | - | Gets the maximum work charge discount application info for TEL-based services |
| R | `JKKWrisvcAutoAplyCC.getLastUpdDtm` | - | - | Gets the latest update datetime for a target contract map |
| R | `JKKWrisvcAutoAplyCC.getMapper` | - | - | Returns the mapper instance for service component calls |
| R | `JKKWrisvcAutoAplyCC.retMsgMap` | - | - | Returns a message map from key/value arrays for error/notification display |
| R | `JKKWrisvcAutoAplyCC.retWribAddYmd` | - | - | Returns the registration date (YYYYMMDD) for discount service registration |
| R | `EKK0081B029CBSMsg1List.SVC_KEI_NO` (via `callEKK0081B029`) | EKK0081B029CBS | KK_M_SVC_KEI (Service Contract Master) | Reads service contract records by service contract number to enumerate linked contracts |
| R | `EKK0081A010CBSMsg1List.SVC_CD` (via `callSvcKeiIchiiShokai`) | EKK0081A010CBS | KK_M_SVC_KEI (Service Contract Master) | Inquires service contract details to retrieve the service code |
| R | `EKK2361B010CBSMsg1List.WRIB_APLY_CNT` (via `callEKK2361B010`) | EKK2361B010CBS | KK_T_WRIB_SVC_KEI_UCWK (Discount Service Target Contract Work) | Reads the application count and last update datetime for the discount service target contract |
| R | `EKK2361B010CBSMsg1List.WRIB_SVC_KEI_NO` (via `callEKK2361B010`) | EKK2361B010CBS | KK_T_WRIB_SVC_KEI_UCWK | Reads discount service target contract number and work detail number |
| R | `EKK2361B010CBSMsg1List.LAST_UPD_DTM` (via `callEKK2361B010`) | EKK2361B010CBS | KK_T_WRIB_SVC_KEI_UCWK | Reads last update datetime for count comparison |
| C | `JKKWrisvcAutoAplyCC.createWribsvkDchskmstDslCncl` | - | KK_T_WRIB_SVC_KEI_DSL_CNCL (Discount Service Target Contract DSL Cancel) | Creates a cancellation/restore record for a discount service target contract |
| C | `getMapper().callWribsvkTgKeiAdd` | EKK0451A010SC / EKK0361A010SC | KK_T_WRIB_SVC_KEI_TRGT (Discount Service Target Contract) | Registers discount service target contract records after overlap removal |
| C | `getMapper().callWribsvKeiAdd` | EKK0451A010SC | KK_T_WRIB_SVC_KEI (Discount Service Contract) | Registers the main discount service contract record |
| C | `getMapper().callDchskmstAdd` | EKK0361A010SC | KK_T_DCHSKMST (Data Extraction Item Setting) | Registers the data extraction item setting record |
| C | `getMapper().callDchskmstTgKeiAdd` | EKK0361A010SC | KK_T_DCHSKMST_TG_KEI (Data Extraction Item Target Contract) | Registers data extraction item target contract records in a loop |
| U | `JKKWrisvcAutoAplyCC.hktgWribUpdate` | - | KK_T_WRIB_SVC_KEI (Discount Service Contract) | Updates work charge discount inheritance (工事費割引継承) — applies service discount rate changes |
| U | `getMapper().callEKK2361C020` | EKK2361C020CBS | KK_T_WRIB_SVC_KEI_UCWK | Updates the application count (WRIB_APLY_CNT) when inherited count exceeds current count |
| D | `JKKWrisvcAutoAplyCC.removeOverLapTgKei` | - | - | Removes overlapping target contract records from the registration list (returns non-null if overlap was found) |
| R | `getMapper().callWribSvcKeiIchiiShokai` | EKK0451A010CBS | KK_T_WRIB_SVC_KEI (Discount Service Contract) | Inquires discount service contract details before recovery processing |
| S | `getMapper().callWribsvkCanselRecover` | EKK0451A010CBS | KK_T_WRIB_SVC_KEI (Discount Service Contract) | Pre-cancel recover service IF — restores a contract that was pre-cancelled |
| S | `getMapper().callWribsvkRecover` | EKK0451A010CBS | KK_T_WRIB_SVC_KEI (Discount Service Contract) | Recovery service IF — processes service recovery |
| S | `getMapper().callDchskmIchiiShokai` | EKK0361A010CBS | KK_T_DCHSKMST (Data Extraction Item Setting) | Data extraction item inquiry service IF |
| R | `JKKBatClarisAuthCrdt.isNullBlank` | - | - | Utility null/blank check |
| R | `JBSbatACEoElectPrcInfoTrkm.isNullBlank` | - | - | Utility null/blank check |
| R | `JBSbatACTrgtSvcKeiMake.isNullBlank` | - | - | Utility null/blank check |
| R | `JBSbatCHKssaidkCvsNkinInfoAdd.isNullBlank` | - | - | Utility null/blank check |
| R | `JBSbatCHMakeEoElecKyseKiykList.isNullBlank` | - | - | Utility null/blank check |
| R | `JBSbatFUCaseFileRnkData.getString` | - | - | Reads a string value from a message object |
| R | `JBSbatFUMoveNaviData.getString` | - | - | Reads a string value from a message object |
| R | `JBSbatZMAdDataSet.getString` | - | - | Reads a string value from a message object |
| - | `JKKSmtvlInfHktgiCC.callEKK0081B029` | EKK0081B029CBS | KK_M_SVC_KEI (Service Contract Master) | Service component call for service contract inquiry |
| - | `JKKSmtvlUpdCC.callEKK0081B029` | EKK0081B029CBS | KK_M_SVC_KEI (Service Contract Master) | Service component call for service contract inquiry |
| - | `JKKWrisvcAutoAplyCC.isNullBlank` | - | - | Internal null/blank check utility |
| - | `JKKWrisvcAutoAplyCC.nullToBlank` | - | - | Internal null-to-blank string conversion utility |
| - | `JKKWrisvcAutoAplyCC.setMsgMap` | - | - | Sets a message map in the ccMap for error/notification display |
| - | `JKKWrisvcAutoAplyCC.setMaxLastUpdDtm` | - | - | Sets the update datetime in the input map |
| - | `JKKWrisvcAutoAplyCC.setMskmDtlNo` | - | - | Sets the application detail number in the input map |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `addWribsvkDchskmst` | `addWribsvkDchskmst` -> `createWribsvkDchskmstAdd` | `callWribsvkTgKeiAdd [C] KK_T_WRIB_SVC_KEI_TRGT`, `callEKK2361C020 [U] KK_T_WRIB_SVC_KEI_UCWK`, `callWribsvKeiAdd [C] KK_T_WRIB_SVC_KEI`, `callDchskmstAdd [C] KK_T_DCHSKMST` |
| 2 | `autoApplyProcessing` | `autoApplyProcessing` -> `addWribsvkDchskmst` -> `createWribsvkDchskmstAdd` | See above |

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(wribDchsSkbtFlag equals WRIB_DCHS_SKBT_FLAG_WRIB = "1")` (L5693)

> Discount Service branch: processes registration of discount service contracts.

| # | Type | Code |
|---|------|------|
| 1 | SET | `addChgeDiv = (String)ccMap.get(KKSV0313_KKSV0313OP_WORK.ADD_CHGE_DIV)` // Retrieve add/change distinction |
| 2 | IF | `ADD_CHGE_DIV_KAIHK = "04" (Recovery)` (L5737) |

**Block 1.1** — [IF-THEN] `(addChgeDiv == ADD_CHGE_DIV_KAIHK = "04")` Recovery path (L5737)

> Recovery processing: handles service recovery for discount services.

| # | Type | Code |
|---|------|------|
| 1 | SET | `key[] = {WRIB_SVC_NM}` // Message key for error display |
| 2 | SET | `val[] = {inMapWribsvkDchskmst.get(WRIB_SVC_NM)}` // Message value |
| 3 | EXEC | `setMsgMap(retMsgMap(key, val), true, wribDchsSkbtFlag)` // Generate message map [-> KAIHK = "04"] |
| 4 | SET | `bkMskmDtlNo = inMapWribsvkDchskmst.get(MSKM_DTL_NO)` // Backup MSKM detail number |
| 5 | CALL | `getMapper().callWribSvcKeiIchiiShokai(ccMap, inMapWribsvkDchskmst, WRIB_SVC_KEI_ICHII_FUNC_CD = "2", renbanNo)` // Inquiry discount service details |
| 6 | EXEC | `inMapWribsvkDchskmst.put(MSKM_DTL_NO, bkMskmDtlNo)` // Restore MSKM detail number |
| 7 | CALL | `setMaxLastUpdDtm(ccMap, inMapWribsvkDchskmst, wribDchsSkbtFlag, renbanNo)` // Set update datetime |
| 8 | SET | `hasIktCp = false` // Initialize integrated CP flag |
| 9 | FOR | `(int i = 0; i < wribsvkDchskmstKaisenList.size(); i++)` // Loop through kaisen list to find integrated corporate plan |
| 10 | IF | `JKKStrConst.WRIB_SVC_KOJIHI_KAP_CP_TEL_IKT.equals(...WRIB_SVC_CD)` (L5767) // Check for TEL integrated CP |
| 11 | SET | `hasIktCp = true; break` // Mark as having integrated CP |
| 12 | IF | `!(hasIktCp && KOJIHI_CP_NET_LIST.contains(inMapWribsvkDchskmst.get(WRIB_SVC_CD)))` (L5773) // Check: skip if has integrated CP AND is KOJIHI_CP_NET |
| 13 | EXEC | `setMskmDtlNo(ccMap, inMapWribsvkDchskmst, wribDchsSkbtFlag, renbanNo)` // Set application detail number |
| 14 | SET | `wribSvcKeiStat = inMapWribsvkDchskmst.get(WRIB_SVC_KEI_STAT)` // Get service contract status |
| 15 | IF | `WRIB_SVC_KEI_STAT_CNCL_ZM = "920" (Pre-cancel)` (L5781) |
| 16 | CALL | `getMapper().callWribsvkCanselRecover(ccMap, inMapWribsvkDchskmst, funcCd, renbanNo)` // Pre-cancel recover service IF |
| 17 | ELSE | `callWribsvkRecover(ccMap, inMapWribsvkDchskmst, funcCd, renbanNo)` (L5786) // Recovery service IF |
| 18 | SET | `wribSvcCd = inMapWribsvkDchskmst.get(WRIB_SVC_CD)` // Get discount service code |
| 19 | SET | `hjnkjhMap = (HashMap)ccMap.get(HJNKJH_MAP)` // Get first billing map |
| 20 | SET | `firstSeikySvcKeiNo = ""` // Initialize first billing service contract number |
| 21 | IF | `hjnkjhMap != null` (L5800) // Check if first billing map exists |
| 22 | SET | `firstSeikySvcKeiNo = JKKStringUtil.nullToBlank(hjnkjhMap.get(FIRST_SEIKY_SVC_KEI_NO))` // Extract first billing service contract number |
| 23 | IF | `(KOJIHI_CP_NET_LIST.contains(wribSvcCd) OR (isNullBlank(firstSeikySvcKeiNo) AND WRIB_SVC_KOJIHI_WRBK_CP_NET_24))` (L5807) // Check: KOJIHI_CP_NET or KOJIHI_WRBK_CP_NET_24 with blank first billing |
| 24 | FOR | `(int j = 0; j < wribsvkDchskmstKaisenList.size(); j++)` // Loop through kaisen list [-> IT1-2018-0000073 MOD] |
| 25 | IF | `(KOJIHI_CP_NET_LIST.contains(wribSvcCd) AND KOJIHI_CP_KAP_TEL_LIST.contains(kaisenList[j].WRIB_SVC_CD)) OR ((isNullBlank(firstSeikySvcKeiNo) AND WRIB_SVC_KOJIHI_WRBK_CP_NET_24) AND JKKStrConst.WRIB_SVC_KOJIHI_WRBK_CP_TEL_24.equals(kaisenList[j].WRIB_SVC_CD))` (L5823) // Check matching KOJIHI_CP pairs |
| 26 | SET | `wribSvcKeiStatDel = kaisenList[j].get(WRIB_SVC_KEI_STAT)` // Get target service contract status |
| 27 | SET | `hashMap = new HashMap(kaisenList[j])` // Create copy of target record [-> IT1-2018-0000073 MOD] |
| 28 | EXEC | `hashMap.put(SVC_CANCEL_RSN_CD, CD01390_CL_TEISE = "20")` // Set cancel rsn: Cancellation Correction |
| 29 | IF | `WRIB_SVC_KEI_STAT_UK_ZM = "010" (Unbilled)` (L5845) |
| 30 | EXEC | `hashMap.put(SVC_CANCEL_RSN_CD, SVC_CANCEL_RSN_CD_OTHER = "05")` // Set cancel rsn: Other reason |
| 31 | ELSE-IF | `WRIB_SVC_KEI_STAT_SVC_TK_CHU = "100" (Service in progress)` (L5852) |
| 32 | EXEC | `hashMap.put(SVC_DLRE_CD, SVC_DLRE_CD_TUJYO_DSL = "01")` // Set service termination rsn: Normal termination |
| 33 | EXEC | `hashMap.put(SVC_ENDYMD, JCCBPCommon.getOpeDate(null))` // Set service end date |
| 34 | EXEC | `hashMap.put(SVC_CHRG_ENDYMD, JCCBPCommon.getOpeDate(null))` // Set service charge end date |
| 35 | ELSE | `break` (L5867) // Unknown status: break loop |
| 36 | CALL | `createWribsvkDchskmstDslCncl(ccMap, hashMap, wribDchsSkbtFlag, funcCd, renbanNo)` // Create DSL cancel record |
| 37 | CALL | `motoList[] = getMapper().callEKK2361B010(kaisenList[j].WRIB_SVC_KEI_NO)` // Get original apply count [-> IT1-2018-0000073 MOD] |
| 38 | SET | `motoWribAplyCnt = motoList[0].getString(WRIB_APLY_CNT)` // Read application count |
| 39 | CALL | `sakiList[] = getMapper().callEKK2361B010(inMapWribsvkDchskmst.WRIB_SVC_KEI_NO)` // Get target list |
| 40 | SET | `updDtmBf = sakiList[0].getString(LAST_UPD_DTM)` // Read last update datetime |
| 41 | FOR | `for (CAANMsg mapWrisvcKeiUcwk : sakiWrisvcKeiUcwkList)` // Iterate saki list |
| 42 | SET | `wribSvcKeiNo = mapWrisvcKeiUcwk.getString(WRIB_SVC_KEI_NO)` // Get discount service contract number |
| 43 | SET | `wribSvcKeiUcwkNo = mapWrisvcKeiUcwk.getString(WRIB_SVC_KEI_UCWK_NO)` // Get work detail number |
| 44 | CALL | `updDtmBf = getMapper().callEKK2361C020(wribSvcKeiNo, wribSvcKeiUcwkNo, motoWribAplyCnt, updDtmBf, funcCd)` // Update apply count |
| 45 | BREAK | `break` // Exit loop after first iteration |
| 46 | BREAK | `break` // Exit outer loop after cancellation processed |
| 47 | ELSE-IF | `KOJIHI_CP_KAP_TEL_LIST.contains(wribSvcCd)` (L5895) // KOJIHI_CP_TEL processing |
| 48 | SET | `wrisvcTgKeiList = inMapWribsvkDchskmst.get(WRISVC_TG_KEI_LIST)` // Get target contract list |
| 49 | SET | `ccMapWrisvcTgKei = wrisvcTgKeiList.get(0)` // Get first element |
| 50 | SET | `sakiSvcKeiNo = ccMapWrisvcTgKei.get(SVC_KEI_NO)` // Get service contract number |
| 51 | SET | `svcKeiNoList = new ArrayList()` // Initialize service contract number list |
| 52 | CALL | `ekk0081B029List[] = getMapper().callEKK0081B029(sakiSvcKeiNo)` // Inquiry service contract |
| 53 | FOR | `for (CAANMsg ekk0081B029Map : ekk0081B029List)` // Loop through EKK0081B029 results |
| 54 | SET | `svcKeiNo = ekk0081B029Map.getString(SVC_KEI_NO)` // Get service contract number |
| 55 | CALL | `sakiSvcKeiMap = getMapper().callSvcKeiIchiiShokai(ccMap, svcKeiNo, SVC_KEI_ICHII_FUNC_CD = "2", renbanNo)` // Inquiry service contract details |
| 56 | SET | `svcCd = sakiSvcKeiMap.get(SVC_CD)` // Get service code |
| 57 | IF | `!(CD00130_01 = "01" (Net) OR CD00130_02 = "02" (Phone))` (L5912) // Skip non-Net/Phone services |
| 58 | CONTINUE | `continue` // Skip non-matching service type |
| 59 | EXEC | `svcKeiNoList.add(svcKeiNo)` // Add service contract number to list |
| 60 | IF | `svcKeiNoList.size() != 0` (L5924) // Check if any service contracts found |
| 61 | CALL | `kojihiKapMaxMap = getKojihiKapCpNew(ccMap, svcKeiNoList)` // Get max work charge discount application info [-> IT1-2018-0000086 ADD] |
| 62 | SET | `motoWribAplyCnt = kojihiKapMaxMap.get(wribAplyCntMax)` // Get max application count [-> IT1-2018-0000086 MOD] |
| 63 | IF | `JKKStringUtil.isNullBlank(motoWribAplyCnt)` (L5942) |
| 64 | SET | `motoWribAplyCnt = "0"` // Default to zero if blank |
| 65 | IF | `!motoWribAplyCnt.equals("0")` (L5946) // Check if inherited count is non-zero |
| 66 | CALL | `sakiList[] = getMapper().callEKK2361B010(inMapWribsvkDchskmst.WRIB_SVC_KEI_NO)` // Get target list |
| 67 | SET | `sakiWribAplyCnt = sakiList[0].getString(WRIB_APLY_CNT)` // Read saki apply count |
| 68 | SET | `updDtmBf = sakiList[0].getString(LAST_UPD_DTM)` // Read last update datetime |
| 69 | IF | `JKKStringUtil.isNullBlank(sakiWribAplyCnt)` (L5958) |
| 70 | SET | `sakiWribAplyCnt = "0"` // Default to zero if blank |
| 71 | IF | `Integer.valueOf(motoWribAplyCnt) > Integer.valueOf(sakiWribAplyCnt)` (L5964) // Inherited count > current count |
| 72 | FOR | `for (CAANMsg mapWrisvcKeiUcwk : sakiWrisvcKeiUcwkList)` // Iterate saki list |
| 73 | SET | `wribSvcKeiNo = mapWrisvcKeiUcwk.getString(WRIB_SVC_KEI_NO)` // Get discount service contract number |
| 74 | SET | `wribSvcKeiUcwkNo = mapWrisvcKeiUcwk.getString(WRIB_SVC_KEI_UCWK_NO)` // Get work detail number |
| 75 | CALL | `updDtmBf = getMapper().callEKK2361C020(wribSvcKeiNo, wribSvcKeiUcwkNo, motoWribAplyCnt, updDtmBf, funcCd)` // Update apply count |
| 76 | ELSE | Normal add path (non-recovery) (L6072)

**Block 1.2** — [IF-ELSE] `(addChgeDiv != ADD_CHGE_DIV_KAIHK)` Normal add path (L6072)

> Normal discount service registration: handles registration when not in recovery mode.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `wribSvcKeiNo = removeOverLapTgKei(inMapWribsvkDchskmst, havingWribsvcList, wribDchsSkbtFlag)` // Remove overlapping target contracts |
| 2 | IF | `wribSvcKeiNo != null` (L6080) // Check if overlap removal returned a key |
| 3 | SET | `wrisvcTgKeiList = inMapWribsvkDchskmst.get(WRISVC_TG_KEI_LIST)` // Get target contract list |
| 4 | FOR | `for (HashMap wrisvcTgKeiMap : wrisvcTgKeiList)` // Loop through target contracts |
| 5 | EXEC | `wrisvcTgKeiMap.put(UPD_DTM_WRIB_SVC_TRGT_KEI, getLastUpdDtm(ccMap, wrisvcTgKeiMap, renbanNo))` // Set update datetime |
| 6 | SET | `wribSvcCd = inMapWribsvkDchskmst.get(WRIB_SVC_CD)` // Get discount service code |
| 7 | SET | `motoAddChgeDiv = ccMap.get(MOTO_ADD_CHGE_DIV)` // Get original add/change distinction |
| 8 | IF | `ADD_CHGE_DIV_KAIHK == "04" AND !WRIB_SET_NET_AND_MOVA.contains(wribSvcCd)` (L6095) // Skip non-NET/MOVA during recovery |
| 9 | CONTINUE | `continue` // Skip this target contract |
| 10 | CALL | `getMapper().callWribsvkTgKeiAdd(ccMap, wrisvcTgKeiMap, wribSvcKeiNo, funcCd, renbanNo)` // Register discount service target contract |
| 11 | ELSE | `wribSvcKeiNo == null` (L6107) // No overlap: full registration |
| 12 | SET | `key[] = {WRIB_SVC_NM}` // Message key |
| 13 | SET | `val[] = {inMapWribsvkDchskmst.get(WRIB_SVC_NM)}` // Message value |
| 14 | EXEC | `setMsgMap(retMsgMap(key, val), true, wribDchsSkbtFlag)` // Generate message map |
| 15 | CALL | `setMaxLastUpdDtm(ccMap, inMapWribsvkDchskmst, wribDchsSkbtFlag, renbanNo)` // Set update datetime |
| 16 | CALL | `setMskmDtlNo(ccMap, inMapWribsvkDchskmst, wribDchsSkbtFlag, renbanNo)` // Set application detail number |
| 17 | SET | `sakiWribSvcCd = inMapWribsvkDchskmst.get(WRIB_SVC_CD)` // Get discount service code |
| 18 | SET | `kojihiKapOperateStat = ccMap.get(kojihi_kap_operate_stat)` // Get work charge discount operate stat |
| 19 | IF | `ALL_KOJIHI_CP_LIST.contains(sakiWribSvcCd) AND JKKStringUtil.isNullBlank(kojihiKapOperateStat)` (L6142) // Check: KOJIHI_CP and not operated |
| 20 | CALL | `hktgWribUpdate(ccMap, inMapWribsvkDchskmst, wribDchsSkbtFlag, retWribAddYmd(ccMap, inMapWribsvkDchskmst), funcCd, renbanNo)` // Work charge discount inheritance update |
| 21 | ELSE | `callWribsvKeiAdd(ccMap, inMapWribsvkDchskmst, retWribAddYmd(ccMap, inMapWribsvkDchskmst), funcCd, renbanNo)` (L6152) // Register discount service contract |

**Block 2** — [ELSE-IF] `(wribDchsSkbtFlag equals WRIB_DCHS_SKBT_FLAG_DCHS = "2")` (L6166)

> Data Extraction Item branch: processes registration of data extraction item settings.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `dchskmstNo = removeOverLapTgKei(inMapWribsvkDchskmst, havingWribsvcList, wribDchsSkbtFlag)` // Remove overlapping target contracts |
| 2 | IF | `dchskmstNo != null` (L6174) // Check if overlap removal returned a key |
| 3 | SET | `dchskmstTgKeiList = inMapWribsvkDchskmst.get(DCHSKMST_TG_KEI_LIST)` // Get data extraction target contract list |
| 4 | FOR | `for (HashMap dchskmstTgKeiMap : dchskmstTgKeiList)` // Loop through target contracts |
| 5 | EXEC | `dchskmstTgKeiMap.put(UPD_DTM_DCHSKMST_TG_KEI, inMapWribsvkDchskmst.get(UPD_DTM_DCHSKMST))` // Set update datetime |
| 6 | SET | `dchskmCd = inMapWribsvkDchskmst.get(DCHSKM_CD)` // Get data extraction item code |
| 7 | CALL | `getMapper().callDchskmstTgKeiAdd(ccMap, dchskmstTgKeiMap, dchskmstNo, dchskmCd, funcCd, renbanNo)` // Register data extraction target contract |
| 8 | ELSE | `dchskmstNo == null` (L6186) // No overlap: full registration |
| 9 | CALL | `setMaxLastUpdDtm(ccMap, inMapWribsvkDchskmst, wribDchsSkbtFlag, renbanNo)` // Set update datetime |
| 10 | CALL | `setMskmDtlNo(ccMap, inMapWribsvkDchskmst, wribDchsSkbtFlag, renbanNo)` // Set application detail number |
| 11 | CALL | `getMapper().callDchskmIchiiShokai(ccMap, inMapWribsvkDchskmst, DCHSKM_ICHII_FUNC_CD = "2", renbanNo)` // Data extraction item inquiry |
| 12 | SET | `key[] = {DCHSKM_NM}` // Message key |
| 13 | SET | `val[] = {inMapWribsvkDchskmst.get(DCHSKM_NM)}` // Message value |
| 14 | EXEC | `setMsgMap(retMsgMap(key, val), true, wribDchsSkbtFlag)` // Generate message map |
| 15 | CALL | `getMapper().callDchskmstAdd(ccMap, inMapWribsvkDchskmst, funcCd, renbanNo)` // Register data extraction item setting |
| 16 | SET | `dchskmstNo = inMapWribsvkDchskmst.get(DCHSKMST_NO)` // Get data extraction item setting number |
| 17 | SET | `dchskmstTgKeiList = inMapWribsvkDchskmst.get(DCHSKMST_TG_KEI_LIST)` // Get target contract list |
| 18 | SET | `renbanForTgKei = 0` // Initialize sequence counter |
| 19 | SET | `digitSize = calcRenbanDigitSize(dchskmstTgKeiList.size())` // Calculate digit size for renban |
| 20 | FOR | `for (HashMap mapDchskmstTgKei : dchskmstTgKeiList)` // Loop through data extraction target contracts |
| 21 | SET | `renbanForTgKei++` // Increment sequence |
| 22 | SET | `renbanNoForTgKei = WRIBSVK_DCHSKMST_GRP_SET = "01" + String.format("%0" + digitSize + "d", renbanForTgKei)` // Generate renban with group prefix |
| 23 | EXEC | `mapDchskmstTgKei.put(UPD_DTM_DCHSKMST_TG_KEI, getLastUpdDtm(ccMap, mapDchskmstTgKei, renbanNo))` // Set update datetime |
| 24 | SET | `dchskmCd = inMapWribsvkDchskmst.get(DCHSKM_CD)` // Get data extraction item code |
| 25 | CALL | `getMapper().callDchskmstTgKeiAdd(ccMap, mapDchskmstTgKei, dchskmstNo, dchskmCd, funcCd, renbanNo + renbanNoForTgKei)` // Register data extraction target contract |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|-----------------|
| `wr` | Prefix | Discount Service (割引サービス) — abbreviation from Japanese ワリビ |
| `wrib` | Prefix | Discount Service (割引サービス) — full abbreviation |
| `dchs` | Prefix | Data Extraction (抽出) |
| `skbt` | Prefix | Item Category / Service Type (項目種別) |
| `dchskmst` | Field | Data Extraction Item Setting (データ抽出項目設定) |
| `wribSvcCd` | Field | Discount Service Code (割引サービスコード) — identifies the type of discount service (e.g., NET, TEL, NET_24, TEL_24) |
| `wribSvcKeiNo` | Field | Discount Service Contract Number (割引サービス契約番号) |
| `wribSvcKeiUcwkNo` | Field | Discount Service Target Contract Work Detail Number (割引サービス対象契約作業詳細番号) |
| `wribSvcKeiStat` | Field | Discount Service Contract Status (割引サービス契約ステータス) — e.g., "010" Unbilled, "100" Service in Progress, "920" Pre-cancel |
| `wribDchsSkbtFlag` | Field | Discount Service / Data Extraction Item Identification Flag (割引サービス／データ抽出項目識別フラグ) — "1" = Discount Service, "2" = Data Extraction Item |
| `addChgeDiv` | Field | Add/Change Distinction (追加変更区分) — "04" = Recovery (回復) |
| `mskmDtlNo` | Field | Application Detail Number (申請明細番号) |
| `motoWribAplyCnt` | Field | Original Application Count (元の適用回数) — application count of the source/inherited contract |
| `sakiWribAplyCnt` | Field | Target Application Count (先の適用回数) — application count of the target/updated contract |
| `sakiSvcKeiNo` | Field | Target Service Contract Number (先サービス契約番号) |
| `kojihiKapCp` | Field | Work Charge Discount Corporate Plan (工事費割引キャンペーン) |
| `kojihiKapOperateStat` | Field | Work Charge Discount Operate Status (工事費割引操作ステータス) |
| `hktgWribUpdate` | Method | Work Charge Discount Update (工事費割引更新) — performs service discount inheritance processing |
| `removeOverLapTgKei` | Method | Remove Overlapping Target Contracts (重複対象契約削除) — removes target contract records that overlap with already-registered ones |
| `kaisenList` | Field | History List (履歴リスト) — list of historical discount service item records (IT1-2018-0000073) |
| `firstSeikySvcKeiNo` | Field | First Billing Service Contract Number (初回請求サービス契約番号) |
| `wr` | Service | Discount Service (割引サービス) — promotional discount applied to telecommunications service charges |
| `NET` | Service | Internet service (ネット) — identified by service code CD00130_01 = "01" |
| `TEL` | Service | Telephone service (電話) — identified by service code CD00130_02 = "02" |
| `NET_24` | Service | Standard work charge discount 24-times (NET) (標準工事費割引キャンペーン（24回）（ネット用）) |
| `TEL_24` | Service | Standard work charge discount 24-times (TEL) (標準工事費割引キャンペーン（24回）（電話用）) |
| `TEL_IKT` | Service | TEL integrated corporate plan (電話一括CP) |
| `TEL_WRBK_24` | Service | Standard work charge discount 24-times (TEL backup) (標準工事費割引キャンペーン（24回）（電話用バックアップ）) |
| `JKKStrConst` | Class | Japanese string constants class containing predefined service codes, status codes, and cancellation reasons |
| `KKSV0313` | Screen | Discount Service Auto-Application screen (割引サービス自動設定画面) — the screen module calling this method |
| `funcCd` | Field | Function Code (機能コード) — identifies the calling screen/business function |
| `renbanNo` | Field | Serial Number (連番) — sequence number for audit trail correlation in service component calls |
| `EKK0451A010CBS` | CBS | Discount Service Contract Inquiry Service Component — inquires discount service contract records |
| `EKK0081B029CBS` | CBS | Service Contract Inquiry CBS — inquires service contract master records |
| `EKK2361B010CBS` | CBS | Discount Service Target Contract Work Read CBS — reads discount service target contract work records |
| `EKK2361C020CBS` | CBS | Discount Service Target Contract Work Update CBS — updates discount service target contract work application counts |
| `SVC_KEI_ICHII_SHOKAI` | Service | Service Contract Inquiry (サービス契約一覧照会) — general service contract master inquiry service |
| `DCHSKM_ICHII_FUNC_CD` | Constant | Data Extraction Item Inquiry Function Code — value "2" |
| `WRIB_SVC_KEI_ICHII_FUNC_CD` | Constant | Discount Service Contract Inquiry Function Code — value "2" |
| `SVC_KEI_ICHII_FUNC_CD` | Constant | Service Contract Inquiry Function Code — value "2" |
| `CD00130_01` | Constant | Net service type code — "01" |
| `CD00130_02` | Constant | Phone service type code — "02" |
| `CD01390_CL_TEISE` | Constant | Cancellation Correction reason code — "20" (取消（訂正）) |
| `SVC_CANCEL_RSN_CD_OTHER` | Constant | Other reason cancellation code — "05" (その他理由によるキャンセル) |
| `SVC_DLRE_CD_TUJYO_DSL` | Constant | Normal termination code — "01" (通常解約) |
| `WRIB_SET_NET_AND_MOVA` | Constant | List of NET and MOVA service codes — ["W00000005"] |
| `ALL_KOJIHI_CP_LIST` | Constant | All work charge discount corporate plan service codes — includes NET, TEL, NET_24, TEL_24, TEL_IKT |
| `KOJIHI_CP_NET_LIST` | Constant | Work charge discount (NET) list — ["W00000001", "W00000015"] |
| `KOJIHI_CP_KAP_TEL_LIST` | Constant | Work charge discount (TEL) list — ["W00000002", "W00000014"] |
| `WRIBSVK_DCHSKMST_GRP_SET` | Constant | Group set identifier for discount service item settings — "01" |
| `ccMap` | Field | Work Area (作業領域) — shared processing context carrying session-level data |
| `inMapWribsvkDchskmst` | Field | Discount Service Contract Map (割引サービス契約マップ) — input data map for the discount service item |
| `havingWribsvcList` | Field | Already-Applied Discount Service List (適用済み割引サービス契約リスト) — existing contracts for overlap checking |
| `hjnkjhMap` | Field | First Billing Map (初回請求マップ) — carries first billing service contract number information |
| `EKK3131B060CBSMsg1List.FIRST_SEIKY_SVC_KEI_NO` | Field | First Billing Service Contract Number from CBS message |
| `WRIB_APLY_CNT` | Field | Discount Service Application Count (割引サービス適用回数) — number of times a discount has been applied |
