# Business Logic — JDKCommon08CC.approve() [571 LOC]

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

## 1. Role

### JDKCommon08CC.approve()

The `approve` method is the central business orchestration engine for the **Return Device Approval** screen (DKSV0081) in the eo Customer Core System. It performs a multi-phase return device approval workflow that validates, verifies, and processes return equipment data submitted by operators at retail stores. The method handles two primary business operations: **Approval** (`HMPIN_KIKI_STAT_SHONIN` = "003"), where return devices are formally approved and their contract/device records are updated; and **Cancellation** (`HMPIN_KIKI_STAT_TORIKESHI` = "004"), where return processing is rolled back.

The method implements a **routing/dispatch design pattern**, branching its processing based on the `updateStat` (return device status) and the `func_code` (function code) to determine which sub-workflows to execute. It orchestrates seven distinct service component (SC) calls across multiple BS Mapper classes to interact with the broader system: receiving-unreceived device queries, equipment service contract verifications, return device approvals (with and without service contract numbers), storage information deletions, home device verifications, and return SOD (Service Order Data) issuance. Additionally, the method supports **automatic unlink processing** for STB and CCAS devices during approval (when `func_code` is not "2"), which handles the decoupling of equipment from the customer's service contract.

Its role in the larger system is that of a **shared business controller component** — it is invoked exclusively by the DKSV0081OPOperation (Return Device Approval Operation), which is triggered from the DKSV0081 BPM flow. This method acts as the authoritative gateway that consolidates all validation checks and side-effects before a return device is approved, ensuring data consistency across service contracts, device registrations, and SOD issuance.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["approve() Start"])

    INIT["Initialize: scCall, ukeireParamMap, get contractData, get approveDatas, get updateStat"]
    PREP["Prepare cancelWorkMap, workList"]
    INMSG1["EDK0301B090BSMapper.editInMsg(param)"]

    CHECK1{"ukeireParamMap has argument?"}
    RUN1["scCall.run(ukeireParamMap, handle) - Unreceived device list"]
    EDIT1["EDK0301B090BSMapper.editResultRP()"]

    ERR_LIST{"Has kktk_svc_kiy_no_err_list?"}
    ADD_ERR1["addError: key_hmpin_kiki_no_err"]
    THROW1["Throw SCCallException - Approval failure"]

    HAS_ERR2{"JDKBPCommon.hasError(param)?"}
    THROW2["Throw SCCallException - Return approval failure"]

    KIKI_CD["kikiTeikyoCds(param) - Get service code map"]
    INIT_ERR["Init errors/error2/error3/error5/error6/error7, checkMap, tmpParamMap, unlinkMap"]

    LOOP_START["For each data in approveDatas"]
    SKIP_EMPTY{"data.kktk_svc_kei_no equals empty?"}

    STAT_SHONIN{"updateStat equals HMPIN_KIKI_STAT_SHONIN (003)?"}
    SUB_CHK{"data.key_hmpin_kbn equals SUBSTITUTE (3) or BROKEN (4)?"}
    ADD_SUB_ERR["Add substitute/broken error to errors and errors3"]

    CONTRACT_CALL["EKK0341B514BSMapper.editInMsg()"]
    RUN2["scCall.run(contractsParamMap, handle) - Equipment service contract list"]
    EDIT2["EKK0341B514BSMapper.editResultRP()"]

    CHK_ERR3{"JDKBPCommon.hasError(param)?"}
    THROW3["Throw SCCallException - Equipment service approval failure"]

    GET_DTLIST["Get dataList from EKK0341B514CBSMsg1List"]
    DTLIST_CHK{"dataList null or empty?"}

    ADD_NODATA_ERR["Add no-data error to errors and errors5"]

    SVC_STAT_SVTEIKYO{"kktk_svc_kei_stat equals SVC_KEI_STAT_SVTEIKYO (100) or SVC_KEI_STAT_TEIKETSU (030) AND gene_add_dtm not empty?"}

    SVC_STAT_CANCEL{"kktk_svc_kei_stat equals SVC_KEI_STAT_KAIYAKU (910) or SVC_KEI_STAT_CANCEL (920)?"}

    SVC_STAT_HENKOU_CANCEL{"kktk_svc_kei_stat equals SVC_KEI_STAT_HENKOU (110) AND rsv_aply_cd equals TORIKESHI (3)?"}

    SVC_STAT_OTHER{"kktk_svc_kei_stat equals SVC_KEI_STAT_SHOSA (020) or SVC_KEI_STAT_HENKOU (110) or SVC_KEI_STAT_KYUSHI (210) or SVC_KEI_STAT_TEISHI (220)?"}

    DTIME_CHK{"gene_add_dtm equals data.key_kktk_svc_gene_add_dtm?"}

    RENTAL_CHK{"svcNoAndTkCds.get() equals RENTAL (2)?"}
    ADD_RENTAL_ERR["Add rental error to errors, errors2"]

    LOOP_END["Next data in approveDatas"]

    SKIP_EMPTY -- Yes --> LOOP_END
    SKIP_EMPTY -- No --> STAT_SHONIN
    STAT_SHONIN -- Yes --> SUB_CHK
    STAT_SHONIN -- No --> CONTRACT_CALL

    SUB_CHK -- Yes --> ADD_SUB_ERR --> LOOP_END
    SUB_CHK -- No --> CONTRACT_CALL

    CONTRACT_CALL --> RUN2 --> EDIT2 --> CHK_ERR3
    CHK_ERR3 -- Yes --> THROW3
    CHK_ERR3 -- No --> GET_DTLIST

    DTLIST_CHK -- No --> ADD_NODATA_ERR --> LOOP_END
    DTLIST_CHK -- Yes --> SVC_STAT_SVTEIKYO

    SVC_STAT_SVTEIKYO -- Yes AND gene not empty --> LOOP_END
    SVC_STAT_SVTEIKYO -- No --> SVC_STAT_CANCEL

    SVC_STAT_CANCEL -- Yes --> LOOP_END
    SVC_STAT_CANCEL -- No --> SVC_STAT_HENKOU_CANCEL

    SVC_STAT_HENKOU_CANCEL -- Yes --> LOOP_END
    SVC_STAT_HENKOU_CANCEL -- No --> SVC_STAT_OTHER

    SVC_STAT_OTHER -- Yes --> DTIME_CHK
    SVC_STAT_OTHER -- No --> RENTAL_CHK

    DTIME_CHK -- Yes --> RENTAL_CHK
    DTIME_CHK -- No --> LOOP_END

    RENTAL_CHK -- Yes --> ADD_RENTAL_ERR
    RENTAL_CHK -- No --> LOOP_END
    ADD_RENTAL_ERR --> LOOP_END
    LOOP_END --> LOOP_START

    CHECK1 -- No --> KIKI_CD
    CHECK1 -- Yes --> RUN1 --> EDIT1 --> ERR_LIST
    ERR_LIST -- Yes --> ERR_CANCEL_CHK
    ERR_LIST -- No --> KIKI_CD
    ERR_CANCEL_CHK -- Yes AND updateStat=TORIKESHI --> ADD_ERR1 --> THROW1
    ERR_CANCEL_CHK -- No --> HAS_ERR2
    HAS_ERR2 -- Yes --> THROW2
    HAS_ERR2 -- No --> KIKI_CD --> INIT_ERR --> LOOP_START

    LOOP_START --> ERR_EMPTY{"errors list is empty?"}
    ERR_EMPTY -- No --> ERR_STORE["Store errors to contractData lists"]

    ERR_STORE --> ERR_CANCEL_CHK2{"updateStat equals HMPIN_KIKI_STAT_TORIKESHI (004)?"}
    ERR_CANCEL_CHK2 -- Yes --> THROW1
    ERR_CANCEL_CHK2 -- No --> ERR_UNLINK6{"errors6 size > 0?"}

    ERR_UNLINK6 -- Yes --> THROW_UNLINK["setExceptionErr - Unlink Unyo error + Throw"]
    ERR_UNLINK6 -- No --> ERR_UNLINK7{"errors7 size > 0?"}

    ERR_UNLINK7 -- Yes --> THROW_UNLINK2["setExceptionErr - Unlink Link error + Throw"]
    ERR_UNLINK7 -- No --> INMSG2["EDK0301A010BSMapper.editInMsg(param) - Return device approval"]

    INMSG2 --> CHK_ARG2{"hmpinParamMap has argument?"}
    CHK_ARG2 -- Yes --> RUN3["scCall.run(hmpinParamMap, handle)"]
    CHK_ARG2 -- No --> INMSG3["EDK0301C070BSMapper.editInMsg(param) - Unreceived return approval"]

    RUN3 --> EDIT3["EDK0301A010BSMapper.editResultRP()"]
    EDIT3 --> INMSG3

    INMSG3 --> CHK_ARG3{"miukeireHmpinParamMap has argument?"}
    CHK_ARG3 -- Yes --> RUN4["scCall.run(miukeireHmpinParamMap, handle)"]
    CHK_ARG3 -- No --> INMSG4["EDK0301E010BSMapper.editInMsg(param) - Storage info deletion"]

    RUN4 --> EDIT4["EDK0301C070BSMapper.editResultRP()"]
    EDIT4 --> INMSG4

    INMSG4 --> CHK_ARG4{"kuraireDeleteInput has argument?"}
    CHK_ARG4 -- Yes --> RUN5["scCall.run(kuraireDeleteInput, handle)"]
    CHK_ARG4 -- No --> INMSG5["EDK0301C030BSMapper.editInMsg(param) - Return device approval (no svc no)"]

    RUN5 --> EDIT5["EDK0301E010BSMapper.editResultRP()"]
    EDIT5 --> INMSG5

    INMSG5 --> CHK_ARG5{"approveParamMap has argument?"}
    CHK_ARG5 -- Yes --> RUN6["scCall.run(approveParamMap, handle)"]
    CHK_ARG5 -- No --> SHONIN_CHK

    RUN6 --> EDIT6["EDK0301C030BSMapper.editResultRP()"]
    EDIT6 --> SHONIN_CHK{"updateStat equals HMPIN_KIKI_STAT_SHONIN (003)?"}

    SHONIN_CHK -- Yes --> UPD_STB["updateSTB(param, unlinkMap, scCall, handle)"]
    SHONIN_CHK -- No --> TORIKESHI_CHK

    UPD_STB --> TAKUNAI["EDKA0010008BSMapper.editInMsg(param) - Home device list"]
    TAKUNAI --> TK_CNT_CHK{"tkCnt > 0?"}

    TK_CNT_CHK -- Yes --> RUN7["scCall.run(takunaiKikiMap, handle)"]
    TK_CNT_CHK -- No --> STOCK

    RUN7 --> EDIT7["EDKA0010008BSMapper.editResultRP()"]
    EDIT7 --> THROW_SC["throwScExceptionIfHasError - Return approval restart code error"]
    THROW_SC --> CNT_CHECK{"tkRequestCnt != tkResultCnt?"}

    CNT_CHECK -- Yes --> ADD_SKY_ERR["addError: kiki_seizo_no_err"]
    CNT_CHECK -- No --> STOCK
    ADD_SKY_ERR --> THROW_SKY["Throw SCCallException - Data existence check error"]

    STOCK["EDKA0010005BSMapper.editInMsg(param) - Home device return info update"]
    STOCK --> RUN8["scCall.run(stockMap, handle)"]
    RUN8 --> EDIT8["EDKA0010005BSMapper.editResultRP()"]
    EDIT8 --> ADD_SOD["addHmpinSodHakko(approveDatas, handle, param, scCall) - Return SOD issuance"]
    ADD_SOD --> TORIKESHI_CHK

    TORIKESHI_CHK{"updateStat equals HMPIN_KIKI_STAT_TORIKESHI (004)?"}
    TORIKESHI_CHK -- Yes --> CANCEL_LOOP["For each data in cancelWorkList"]
    TORIKESHI_CHK -- No --> END_NODE

    CANCEL_LOOP --> HMPIN_RE["EDK0301A010_01BSMapper.editInMsg(param, key_hmpin_kiki_no) - Return consent info"]
    HMPIN_RE --> RUN9["scCall.run(hmpinReMap, handle)"]
    RUN9 --> EDIT9["EDK0301A010_01BSMapper.editResultRP()"]

    EDIT9 --> FUNC_CHK{"func_code equals 1?"}
    FUNC_CHK -- Yes --> INMSG6["EDK0301D010BSMapper.editInMsg(param) - Return device receipt"]
    FUNC_CHK -- No --> CANCEL_LOOP_END

    INMSG6 --> RUN10["scCall.run(hmpinInsMap, handle)"]
    RUN10 --> EDIT10["EDK0301D010BSMapper.editResultRP()"]
    EDIT10 --> CANCEL_LOOP_END["Next cancelWorkList data"]

    CANCEL_LOOP_END --> CANCEL_LOOP
    CANCEL_LOOP --> END_NODE(["Return param"])

    END_NODE --> FINISH(["approve() End"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle providing the connection context for all service component (SC) calls. Represents the active database session for the current BPM flow execution. |
| 2 | `param` | `IRequestParameterReadWrite` | Request parameter object carrying all business data for the return device approval operation. Contains the `DKSV008101CC` data block with `key_hmpin_kiki_list` (list of return device records to approve), `func_code` (function code identifying the operation type), and various error result maps. Mutated throughout processing with error lists, approval results, and work data. |
| 3 | `fixedText` | `String` | Template text for error messages and system output. Passed through to support consistent message formatting across the application. Not directly used within this method's logic. |

**Instance fields / external state read:**
- `HMPIN_KBN` (HashSet) — Set of return type values that are excluded from processing (cancel items and rental items). Used in `kikiTeikyoCds()` to skip non-target device types.
- `DKSV008101CC` (static constant) — Key used to access the main contract data map from `param`.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `EDK0301B090BSMapper.editInMsg` | EDK0301B090BS | - | Maps input parameters for return-unreceived-device-list inquiry SC |
| R | `scCall.run(ukeireParamMap)` | EDK0301B090SC | - | Runs SC to retrieve list of unreceived return devices |
| U | `EDK0301B090BSMapper.editResultRP` | EDK0301B090BS | - | Maps SC result back to param for return-unreceived-device-list inquiry |
| R | `EKK0341B514BSMapper.editInMsg` | EKK0341B514BS | - | Maps input parameters for equipment service contract list inquiry (equipment change number) |
| R | `scCall.run(contractsParamMap)` | EKK0341B514SC | - | Runs SC to verify equipment service contract status for each return device |
| U | `EKK0341B514BSMapper.editResultRP` | EKK0341B514BS | - | Maps SC result back to param for equipment service contract list |
| R | `EDK0301A010BSMapper.editInMsg` | EDK0301A010BS | - | Maps input parameters for return device approval SC |
| R | `scCall.run(hmpinParamMap)` | EDK0301A010SC | - | Runs SC to approve return devices with service contract numbers |
| U | `EDK0301A010BSMapper.editResultRP` | EDK0301A010BS | - | Maps SC result back to param for return device approval |
| R | `EDK0301C070BSMapper.editInMsg` | EDK0301C070BS | - | Maps input parameters for unreceived return device approval SC |
| R | `scCall.run(miukeireHmpinParamMap)` | EDK0301C070SC | - | Runs SC to approve unreceived return devices |
| U | `EDK0301C070BSMapper.editResultRP` | EDK0301C070BS | - | Maps SC result back to param for unreceived return approval |
| R | `EDK0301E010BSMapper.editInMsg` | EDK0301E010BS | - | Maps input parameters for storage information deletion SC |
| R | `scCall.run(kuraireDeleteInput)` | EDK0301E010SC | - | Runs SC to delete storage information for approved return devices |
| U | `EDK0301E010BSMapper.editResultRP` | EDK0301E010BS | - | Maps SC result back to param for storage info deletion |
| R | `EDK0301C030BSMapper.editInMsg` | EDK0301C030BS | - | Maps input parameters for return device approval (no service contract number) SC |
| R | `scCall.run(approveParamMap)` | EDK0301C030SC | - | Runs SC to approve return devices without service contract numbers |
| U | `EDK0301C030BSMapper.editResultRP` | EDK0301C030BS | - | Maps SC result back to param for return device approval (no svc no) |
| U | `updateSTB` | - | - | Updates STB information including unlink processing for STB/CCAS devices |
| R | `EDKA0010008BSMapper.editInMsg` | EDKA0010008BS | - | Maps input parameters for home device list inquiry (manufacturing number) SC |
| R | `scCall.run(takunaiKikiMap)` | EDKA0010008SC | - | Runs SC to verify home devices with manufacturing numbers |
| U | `EDKA0010008BSMapper.editResultRP` | EDKA0010008BS | - | Maps SC result back to param for home device list |
| R | `EDKA0010005BSMapper.editInMsg` | EDKA0010005BS | - | Maps input parameters for home device return info update SC |
| R | `scCall.run(stockMap)` | EDKA0010005SC | - | Runs SC to update home device return information |
| U | `EDKA0010005BSMapper.editResultRP` | EDKA0010005BS | - | Maps SC result back to param for home device return info update |
| C | `addHmpinSodHakko` | - | - | Issues Service Order Data (SOD) for return processing |
| R | `EDK0301A010_01BSMapper.editInMsg` | EDK0301A010_01BS | - | Maps input parameters for return consent info retrieval (cancel received original net info) SC |
| R | `scCall.run(hmpinReMap)` | EDK0301A010_01SC | - | Runs SC to retrieve return consent info during cancellation |
| U | `EDK0301A010_01BSMapper.editResultRP` | EDK0301A010_01BS | - | Maps SC result back to param for return consent info retrieval |
| R | `EDK0301D010BSMapper.editInMsg` | EDK0301D010BS | - | Maps input parameters for return device receipt SC |
| R | `scCall.run(hmpinInsMap)` | EDK0301D010SC | - | Runs SC to register return device receipt |
| U | `EDK0301D010BSMapper.editResultRP` | EDK0301D010BS | - | Maps SC result back to param for return device receipt |
| C | `unlink` | - | - | Processes automatic unlink of equipment from service contract |
| C | `JDKBPCommon.addError` | - | - | Adds error to param error list |
| C | `JDKBPCommon.hasError` | - | - | Checks if param contains any errors |
| C | `JDKBPCommon.throwScExceptionIfHasError` | - | - | Throws exception if param has restart code errors |
| C | `setExceptionErr` | - | - | Sets exception error information on contractData |
| R | `kikiTeikyoCds` | - | - | Retrieves equipment provision code list (internal method) |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:DKSV0081 | `DKSV0081Flow` -> `DKSV0081OPOperation.run` -> `CCRequestBroker(target4, approve)` -> `JDKCommon08CC.approve` | `scCall.run(x7)` -> `EDK0301B090SC`, `EKK0341B514SC`, `EDK0301A010SC`, `EDK0301C070SC`, `EDK0301E010SC`, `EDK0301C030SC`, `EDKA0010008SC`, `EDKA0010005SC`, `EDK0301A010_01SC`, `EDK0301D010SC`; `unlink(C)`, `addHmpinSodHakko(C)` |

## 6. Per-Branch Detail Blocks

**Block 1** — [VARIABLE] Initialization (L241)

> Create service component invoker and extract contract data from the parameter.

| # | Type | Code |
|---|------|------|
| 1 | SET | `scCall = new ServiceComponentRequestInvoker()` |
| 2 | SET | `ukeireParamMap = new HashMap<String, Object>()` |
| 3 | SET | `contractData = (Map)param.getData("DKSV008101CC")` |
| 4 | SET | `approveDatas = (List<Map>)contractData.get("key_hmpin_kiki_list")` |
| 5 | SET | `updateStat = (String) approveDatas.get(0).get("key_hmpin_kiki_stat")` |
| 6 | SET | `funcCode = (String) contractData.get("func_code")` |
| 7 | SET | `cancelWorkMap = new HashMap<String, Object>()` |
| 8 | SET | `workList = new ArrayList()` |
| 9 | SET | `cancelWorkMap.put("workList", workList)` |
| 10 | EXEC | `param.setData("workMap", cancelWorkMap)` |

**Block 2** — [IF] Unreceived device list inquiry (L287)

> Retrieves the list of unreceived return devices via SC when there is received data.

| # | Type | Code |
|---|------|------|
| 1 | SET | `ukeireParamMap = EDK0301B090BSMapper.editInMsg(param)` |
| 2 | IF | `hasArgument(ukeireParamMap)` (L288) |
| 3 | EXEC | `ukeireResult = scCall.run(ukeireParamMap, handle)` |
| 4 | EXEC | `EDK0301B090BSMapper.editResultRP(ukeireResult, param)` |
| 5 | IF | `updateStat equals HMPIN_KIKI_STAT_TORIKESHI ("004") AND contractData.containsKey("kktk_svc_kiy_no_err_list")` (L293) |
| 6 | CALL | `JDKBPCommon.addError(param, "key_hmpin_kiki_no_err", "EB", "EDK0301C030", RELATION_ERR, 0)` |
| 7 | EXEC | `throw new SCCallException("Approval processing failure")` |
| 8 | IF | `JDKBPCommon.hasError(param)` (L300) |
| 9 | EXEC | `throw new SCCallException("Return approval processing failure", returnCode)` |

**Block 3** — [SET] Service code map and error list initialization (L308-L336)

> Prepares error collection lists and processing maps for the device iteration loop.

| # | Type | Code |
|---|------|------|
| 1 | SET | `svcNoAndTkCds = kikiTeikyoCds(param)` |
| 2 | SET | `errors = new ArrayList<Map<String, Object>>()` |
| 3 | SET | `errors2 = new ArrayList<Map<String, Object>>()` |
| 4 | SET | `errors3 = new ArrayList<Map<String, Object>>()` |
| 5 | SET | `errors5 = new ArrayList<Map<String, Object>>()` |
| 6 | SET | `errors6 = new ArrayList<Map<String, Object>>()` |
| 7 | SET | `errors7 = new ArrayList<Map<String, Object>>()` |
| 8 | SET | `checkMap = new HashSet<String>()` |
| 9 | SET | `tmpParamMap = new HashMap<String, Object>()` |
| 10 | SET | `unlinkMap = new ArrayList<HashMap<String, Object>>()` |

**Block 4** — [FOR] Iterate over approveDatas (L338)

> Core loop: processes each return device record for validation, contract verification, and service type handling.

| # | Type | Code |
|---|------|------|
| 1 | FOR | `for (Map data : approveDatas)` (L338) |
| 2 | IF | `updateStat equals HMPIN_KIKI_STAT_SHONIN ("003")` (L342) |
| 3 | IF | `data.get("key_hmpin_kbn") equals SUBSTITUTE ("3") or BROKEN ("4")` (L345) |
| 4 | SET | `svcKiyNo = new HashMap` with `kktk_svc_kiy_no_hmpin_kbn` and `svc_kiy_no_hmpin_kbn` |
| 5 | EXEC | `errors.add(svcKiyNo)` |
| 6 | SET | `svcKiyNo3 = new HashMap` with `key_hmpin_kiki_no` |
| 7 | EXEC | `errors3.add(svcKiyNo3)` |
| 8 | EXEC | `continue` (skip this record) |
| 9 | IF | `data.get("key_kktk_svc_kei_no").equals("")` (L365) |
| 10 | EXEC | `continue` |
| 11 | SET | `contractsParamMap = EKK0341B514BSMapper.editInMsg(param, data)` |
| 12 | EXEC | `contractResult = scCall.run(contractsParamMap, handle)` |
| 13 | EXEC | `EKK0341B514BSMapper.editResultRP(contractResult, param)` |
| 14 | IF | `JDKBPCommon.hasError(param)` (L381) |
| 15 | EXEC | `throw new SCCallException("Equipment service contract approval failure", returnCode)` |
| 16 | SET | `dataList = (ArrayList<Map>)contractData.get("EKK0341B514CBSMsg1List")` |
| 17 | IF | `dataList != null && dataList.size() > 0` (L388) |
| 18 | IF | `dataList.get(0).get("taknkiki_sbt_cd") equals STB ("A0") or CCAS ("C0")` (L390) |
| 19 | IF | `updateStat equals HMPIN_KIKI_STAT_SHONIN ("003") AND funcCode NOT equals FUNC_CODE_2 ("2")` (L396) |
| 20 | SET | `tmpParamMap = unlink(param, tkMdlCd, kkSeizoNo, svcKeiNo, checkMap, scCall, handle, hmpinKikiNo)` |
| 21 | IF | `tmpParamMap contains key_unlink_unyo_hmpin_kiki_no AND not empty` (L402) |
| 22 | SET | `svcKiyNo6 = new HashMap` with `key_unlink_unyo_hmpin_kiki_no` |
| 23 | EXEC | `errors.add(svcKiyNo6)`, `errors6.add(svcKiyNo6)` |
| 24 | IF | `tmpParamMap contains key_unlink_link_hmpin_kiki_no AND not empty` (L409) |
| 25 | SET | `svcKiyNo7 = new HashMap` with `key_unlink_link_hmpin_kiki_no` |
| 26 | EXEC | `errors.add(svcKiyNo7)`, `errors7.add(svcKiyNo7)` |
| 27 | IF | `tmpParamMap.size() > 0 AND does NOT contain key_unlink_unyo_hmpin_kiki_no AND key_unlink_link_hmpin_kiki_no AND key_not_unlink_flg` (L418) |
| 28 | EXEC | `unlinkMap.add(tmpParamMap)` |
| 29 | IF | `dataList == null OR dataList.size() == 0` (L471) |
| 30 | IF | `updateStat equals HMPIN_KIKI_STAT_TORIKESHI ("004")` (L473) |
| 31 | CALL | `JDKBPCommon.addError(param, "key_hmpin_kiki_no_err", "EE", "EDK0301C030", RELATION_ERR, 0)` |
| 32 | SET | `svcKiyNo = new HashMap` with `kktk_svc_kiy_no_nodata` and `svc_kiy_no_nodata` |
| 33 | EXEC | `errors.add(svcKiyNo)` |
| 34 | SET | `svcKiyNo5 = new HashMap` with `key_hmpin_kiki_no` |
| 35 | EXEC | `errors5.add(svcKiyNo5)` |
| 36 | EXEC | `continue` |
| 37 | IF | `kktk_svc_kei_stat equals SVC_KEI_STAT_SVTEIKYO ("100") or SVC_KEI_STAT_TEIKETSU ("030") AND gene_add_dtm not empty` (L485) |
| 38 | EXEC | `continue` |
| 39 | IF | `kktk_svc_kei_stat equals SVC_KEI_STAT_KAIYAKU ("910") or SVC_KEI_STAT_CANCEL ("920")` (L502) |
| 40 | EXEC | `continue` |
| 41 | IF | `kktk_svc_kei_stat equals SVC_KEI_STAT_HENKOU ("110") AND rsv_aply_cd equals TORIKESHI ("3")` (L508) |
| 42 | EXEC | `continue` |
| 43 | IF | `kktk_svc_kei_stat equals SVC_KEI_STAT_SHOSA ("020") or SVC_KEI_STAT_HENKOU ("110") or SVC_KEI_STAT_KYUSHI ("210") or SVC_KEI_STAT_TEISHI ("220")` (L515) |
| 44 | IF | `gene_add_dtm does NOT equal data.key_kktk_svc_gene_add_dtm` (L521) |
| 45 | EXEC | `continue` |
| 46 | SET | `teikyoCd = svcNoAndTkCds.get(data.get("key_kktk_svc_kei_no"))` |
| 47 | IF | `teikyoCd equals RENTAL ("2")` (L528) |
| 48 | IF | `updateStat equals HMPIN_KIKI_STAT_TORIKESHI ("004")` (L530) |
| 49 | CALL | `JDKBPCommon.addError(param, "key_hmpin_kiki_no_err", "EC", "EDK0301C030", RELATION_ERR, 0)` |
| 50 | SET | `svcKiyNo = new HashMap` with `kktk_svc_kiy_no` and `svc_kiy_no` |
| 51 | EXEC | `errors.add(svcKiyNo)` |
| 52 | SET | `svcKiyNo2 = new HashMap` with `kktk_svc_kei_stat` and `key_hmpin_kiki_no` |
| 53 | EXEC | `errors2.add(svcKiyNo2)` |
| 54 | EXEC | `continue` (end of loop body) |

**Block 5** — [IF] Error handling and storage (L538)

> After the loop, processes collected errors. If errors exist, stores them and throws an exception for cancellation or unlink errors.

| # | Type | Code |
|---|------|------|
| 1 | IF | `!errors.isEmpty()` (L538) |
| 2 | SET | `contractData.put("kktk_svc_kiy_no_err_list", errors)` |
| 3 | SET | `contractData.put("kktk_svc_kiy_stat_err_list", errors2)` |
| 4 | SET | `contractData.put("kktk_svc_kiy_hen_err_list", errors3)` |
| 5 | SET | `contractData.put("kktk_svc_kiy_son_err_list", errors5)` |
| 6 | IF | `updateStat equals HMPIN_KIKI_STAT_TORIKESHI ("004")` (L550) |
| 7 | EXEC | `throw new SCCallException("Approval processing failure", RELATION_ERR)` |
| 8 | IF | `errors6.size() > 0` (L556) |
| 9 | CALL | `setExceptionErr(param, contractData, "EZM0411A010", "kktk_svc_kiy_unlink_unyo_err_list")` |
| 10 | SET | `contractData.put("err_cd", "1")`, `contractData.put("kktk_svc_kiy_unlink_unyo_err_list", errors6)` |
| 11 | EXEC | `throw new SCCallException("Approval processing failure", RELATION_ERR)` |
| 12 | IF | `errors7.size() > 0` (L563) |
| 13 | CALL | `setExceptionErr(param, contractData, "EZM0411A010", "kktk_svc_kiy_unlink_link_err_list")` |
| 14 | SET | `contractData.put("err_cd", "2")`, `contractData.put("kktk_svc_kiy_unlink_link_err_list", errors7)` |
| 15 | EXEC | `throw new SCCallException("Approval processing failure", RELATION_ERR)` |

**Block 6** — [IF] Return device approval (with service contract) (L571)

> Approves return devices that have service contract numbers entered.

| # | Type | Code |
|---|------|------|
| 1 | SET | `hmpinParamMap = EDK0301A010BSMapper.editInMsg(param)` |
| 2 | IF | `hasArgument(hmpinParamMap)` (L572) |
| 3 | EXEC | `hempinResult = scCall.run(hmpinParamMap, handle)` |
| 4 | EXEC | `EDK0301A010BSMapper.editResultRP(hempinResult, param)` |
| 5 | IF | `JDKBPCommon.hasError(param)` (L579) |
| 6 | SET | `contractData.put("kktk_svc_kiy_no_err_list", errors)` |
| 7 | EXEC | `throw new SCCallException("Return approval processing failure", returnCode)` |

**Block 7** — [IF] Unreceived return device approval (L588)

> Approves return devices that have service contract numbers but are unreceived.

| # | Type | Code |
|---|------|------|
| 1 | SET | `miukeireHmpinParamMap = EDK0301C070BSMapper.editInMsg(param)` |
| 2 | IF | `hasArgument(miukeireHmpinParamMap)` (L590) |
| 3 | EXEC | `miukeireHempinResult = scCall.run(miukeireHmpinParamMap, handle)` |
| 4 | EXEC | `EDK0301C070BSMapper.editResultRP(miukeireHempinResult, param)` |
| 5 | IF | `JDKBPCommon.hasError(param)` (L597) |
| 6 | SET | `contractData.put("kktk_svc_kiy_no_err_list", errors)` |
| 7 | EXEC | `throw new SCCallException("Return approval processing failure", returnCode)` |

**Block 8** — [IF] Storage information deletion (L606)

> Deletes storage information for approved return devices that have service contract numbers.

| # | Type | Code |
|---|------|------|
| 1 | SET | `kuraireDeleteInput = EDK0301E010BSMapper.editInMsg(param)` |
| 2 | IF | `hasArgument(kuraireDeleteInput)` (L608) |
| 3 | EXEC | `kuraireDeleteResult = scCall.run(kuraireDeleteInput, handle)` |
| 4 | EXEC | `EDK0301E010BSMapper.editResultRP(kuraireDeleteResult, param)` |
| 5 | IF | `JDKBPCommon.hasError(param)` (L615) |
| 6 | SET | `contractData.put("kktk_svc_kiy_no_err_list", errors)` |
| 7 | EXEC | `throw new SCCallException("Return approval processing failure", returnCode)` |

**Block 9** — [IF] Return device approval without service contract (L624)

> Approves return devices that do NOT have service contract numbers.

| # | Type | Code |
|---|------|------|
| 1 | SET | `approveParamMap = EDK0301C030BSMapper.editInMsg(param)` |
| 2 | IF | `hasArgument(approveParamMap)` (L626) |
| 3 | EXEC | `approveResult = scCall.run(approveParamMap, handle)` |
| 4 | EXEC | `param = EDK0301C030BSMapper.editResultRP(approveResult, param)` |
| 5 | IF | `JDKBPCommon.hasError(param)` (L633) |
| 6 | SET | `contractData.put("kktk_svc_kiy_no_err_list", errors)` |
| 7 | EXEC | `throw new SCCallException("Return approval processing failure", returnCode)` |

**Block 10** — [IF] Approval path (SHONIN) — STB update, home device check, SOD issuance (L642)

> Executes when the return device status is "Approved". Updates STB info, verifies home devices, updates return info, and issues SOD.

| # | Type | Code |
|---|------|------|
| 1 | IF | `updateStat equals HMPIN_KIKI_STAT_SHONIN ("003")` (L642) |
| 2 | CALL | `updateSTB(param, unlinkMap, scCall, handle)` — Update STB/unlink info |
| 3 | SET | `takunaiKikiMap = EDKA0010008BSMapper.editInMsg(param)` — Home device list |
| 4 | IF | `Integer.parseInt(takunaiKikiMap.get("tkCnt")) > 0` (L650) |
| 5 | EXEC | `takunaiResult = scCall.run(takunaiKikiMap, handle)` |
| 6 | EXEC | `param = EDKA0010008BSMapper.editResultRP(takunaiResult, param)` |
| 7 | IF | `JDKBPCommon.hasError(param)` (L655) |
| 8 | EXEC | `throw new SCCallException("Return approval failure", returnCode)` |
| 9 | CALL | `JDKBPCommon.throwScExceptionIfHasError("Return approval restart code error", param)` |
| 10 | SET | `tkRequestCnt = takunaiKikiMap.get("tkCnt")` |
| 11 | SET | `dataMap = (Map)param.getData("DKSV008101CC")` |
| 12 | SET | `tkResultCnt = dataMap.get("resultCnt")` |
| 13 | IF | `Integer.parseInt(tkRequestCnt) != Integer.parseInt(tkResultCnt)` (L670) |
| 14 | CALL | `JDKBPCommon.addError(param, "kiki_seizo_no_err", "EA", "EDKA0010008", 1100, 0)` |
| 15 | EXEC | `throw new SCCallException("Home device list check data existence error", RELATION_ERR)` |
| 16 | SET | `stockMap = EDKA0010005BSMapper.editInMsg(param)` |
| 17 | EXEC | `takunaiResult = scCall.run(stockMap, handle)` |
| 18 | EXEC | `param = EDKA0010005BSMapper.editResultRP(takunaiResult, param)` |
| 19 | IF | `JDKBPCommon.hasError(param)` (L683) |
| 20 | EXEC | `throw new SCCallException("Return approval failure", returnCode)` |
| 21 | CALL | `addHmpinSodHakko(approveDatas, handle, param, scCall)` |
| 22 | CALL | `JDKBPCommon.throwScExceptionIfHasError("Return approval restart code error", param)` |

**Block 11** — [IF] Cancellation path (TORIKESHI) — Return device receipt (L692)

> Executes when the return device status is "Cancelled". Iterates over the cancelWorkList to retrieve consent info and optionally register receipts.

| # | Type | Code |
|---|------|------|
| 1 | IF | `updateStat equals HMPIN_KIKI_STAT_TORIKESHI ("004")` (L692) |
| 2 | SET | `cancelWorkMap = (HashMap)param.getData("workMap")` |
| 3 | SET | `cancelWorkList = (List<Map>)cancelWorkMap.get("workList")` |
| 4 | FOR | `for (Map data : cancelWorkList)` (L695) |
| 5 | SET | `hmpinReMap = EDK0301A010_01BSMapper.editInMsg(param, data.get("key_hmpin_kiki_no"))` |
| 6 | EXEC | `hmpinReResult = scCall.run(hmpinReMap, handle)` |
| 7 | EXEC | `EDK0301A010_01BSMapper.editResultRP(hmpinReResult, param)` |
| 8 | IF | `JDKBPCommon.hasError(param)` (L705) |
| 9 | EXEC | `throw new SCCallException("Return consent info retrieval failure", returnCode)` |
| 10 | IF | `func_code equals "1"` (L712) |
| 11 | SET | `hmpinInsMap = EDK0301D010BSMapper.editInMsg(param)` |
| 12 | EXEC | `hmpinInsResult = scCall.run(hmpinInsMap, handle)` |
| 13 | EXEC | `EDK0301D010BSMapper.editResultRP(hmpinInsResult, param)` |
| 14 | IF | `JDKBPCommon.hasError(param)` (L721) |
| 15 | EXEC | `throw new SCCallException("Return device receipt failure", returnCode)` |
| 16 | EXEC | `continue` (end of cancelWorkList loop) |
| 17 | EXEC | `return param` (end of method) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `approveDatas` | Field | List of return device records to process in the approval workflow |
| `updateStat` | Field | Return device status code — determines whether the operation is approval ("003") or cancellation ("004") |
| `funcCode` | Field | Function code identifying the operation type (e.g., "1" = return receipt, "2" = return cancellation) |
| `key_hmpin_kiki_list` | Field | List of return device entries — each entry contains device info including service contract number, manufacturing number, and return type |
| `key_hmpin_kiki_stat` | Field | Return device status field within each approval data record |
| `key_hmpin_kbn` | Field | Return type — identifies the device type as cancel item ("1"), rental ("2"), substitute ("3"), or broken ("4") |
| `key_hmpin_kiki_no` | Field | Return device number — unique identifier for the return device record |
| `key_kktk_svc_kei_no` | Field | K-opt telekom service contract number — identifies the service contract associated with the return device |
| `svc_kei_no` | Field | Service contract line item number |
| `key_tk_mdl_cd` | Field | Equipment model code — identifies the type of equipment (STB, CCAS, etc.) |
| `key_kk_seizo_no` | Field | Equipment manufacturing number — serial number of the physical device |
| `gene_add_dtm` | Field | Gene addition datetime — timestamp of the latest contract change record, used to detect stale data |
| `key_kktk_svc_gene_add_dtm` | Field | Expected gene addition datetime — the datetime the operator expects, used to validate data freshness |
| `rsv_aply_cd` | Field | Reservation application code — indicates whether a reservation change has been cancelled ("3" = TORIKESHI) |
| `kktk_svc_kei_stat` | Field | K-opt telekom service contract status — current state of the service contract |
| `taknkiki_sbt_cd` | Field | Equipment provision sub-type code — classifies the type of equipment provided (STB = "A0", CCAS = "C0", etc.) |
| `key_unlink_unyo_hmpin_kiki_no` | Field | Unlink operation return device number — device that failed to unlink during automatic unlink processing |
| `key_unlink_link_hmpin_kiki_no` | Field | Unlink link return device number — device that remained linked during automatic unlink processing |
| `key_not_unlink_flg` | Field | Not-unlink flag — indicates that unlink was not required |
| `HMPIN_KBN` | Field | Set of excluded return types — cancel and rental items are excluded from processing |
| `tkCnt` | Field | Home device inquiry count — number of home devices to verify by manufacturing number |
| `resultCnt` | Field | Inquiry result count — actual number of results returned, compared against tkCnt to detect missing devices |
| HMPIN_KIKI_STAT_UKETSUKE | Constant | Return device status: "001" — Received (accepted at store) |
| HMPIN_KIKI_STAT_KURAIRE | Constant | Return device status: "002" — Stored (placed in warehouse) |
| HMPIN_KIKI_STAT_SHONIN | Constant | Return device status: "003" — Approved (return approved for processing) |
| HMPIN_KIKI_STAT_TORIKESHI | Constant | Return device status: "004" — Cancelled (return processing cancelled) |
| SUBSTITUTE | Constant | Return type: "3" — Substitute device |
| BROKEN | Constant | Return type: "4" — Broken device |
| RENTAL | Constant | Return type: "2" — Rental device |
| FUNC_CODE_2 | Constant | Function code: "2" — Return cancellation operation |
| SVC_KEI_STAT_UKETSUKE | Constant | Service contract status: "010" — Received |
| SVC_KEI_STAT_SHOSA | Constant | Service contract status: "020" — Reviewed |
| SVC_KEI_STAT_TEIKETSU | Constant | Service contract status: "030" — Settlement completed |
| SVC_KEI_STAT_SVTEIKYO | Constant | Service contract status: "100" — Service providing (active service) |
| SVC_KEI_STAT_HENKOU | Constant | Service contract status: "110" — Change in progress |
| SVC_KEI_STAT_KYUSHI | Constant | Service contract status: "210" — Suspension/termination in progress |
| SVC_KEI_STAT_TEISHI | Constant | Service contract status: "220" — Stopped |
| SVC_KEI_STAT_KAIYAKU | Constant | Service contract status: "910" — Canceled |
| SVC_KEI_STAT_CANCEL | Constant | Service contract status: "920" — Contract cancelled |
| STB | Constant | Equipment type: "A0" — Set-Top Box |
| CCAS | Constant | Equipment type: "C0" — Conditional Access System card |
| TORIKESHI | Constant | Reservation application code: "3" — Cancelled reservation (used to skip records with cancelled changes) |
| EDK0301B090 | SC Code | Unreceived device list inquiry — retrieves list of devices that have not been physically received |
| EKK0341B514 | SC Code | Equipment service contract list inquiry (equipment change number) — verifies current service contract status |
| EDK0301A010 | SC Code | Return device approval SC — approves return devices with service contract numbers |
| EDK0301C070 | SC Code | Unreceived return device approval SC — approves unreceived return devices |
| EDK0301E010 | SC Code | Storage information deletion SC — deletes storage info for approved return devices |
| EDK0301C030 | SC Code | Return device approval (no service contract) SC — approves return devices without service contract numbers |
| EDKA0010008 | SC Code | Home device list inquiry (manufacturing number) SC — verifies home devices by serial number |
| EDKA0010005 | SC Code | Home device return info update SC — updates return device information in home device records |
| EDK0301A010_01 | SC Code | Return consent info retrieval (cancel received original net info) SC — retrieves consent data during cancellation |
| EDK0301D010 | SC Code | Return device receipt SC — registers return device receipt |
| DKSV0081 | Screen Code | Return Device Approval screen — the retail store screen where operators process return device approvals |
| SOD | Acronym | Service Order Data — telecom order fulfillment document created for return processing |
| BPM | Acronym | Business Process Management — workflow engine that orchestrates the return device approval process |
| SC | Acronym | Service Component — backend service layer that executes database operations and business logic |
| BS Mapper | Acronym | Business Service Mapper — mapping class that transforms between request parameters and SC messages |
| STB | Acronym | Set-Top Box — cable decoder device provided to eo customers |
| CCAS | Acronym | Conditional Access System — smart card used for content access control |
| SCCallException | Exception | Exception thrown when a service component call fails with a relation error or business error |
