# Business Logic — JKKIntrInfoChgCfmCC.chgWribIntrInfo() [68 LOC]

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

## 1. Role

### JKKIntrInfoChgCfmCC.chgWribIntrInfo()

This method performs **introduction (referral) information update processing** (紹介コード更新処理) on service contract lines that are associated with discount services (割引サービス). It is invoked from `chgIntrInfo()` as a targeted update path specifically for contract lines that have an introduction/referral code attached.

The method follows a **per-contract-line dispatch pattern**: it iterates over each discount service contract number (割引サービス契約番号) collected via `isWrib()`, performs a service lookup to resolve the upstream/introducer contract number (被紹介者契約番号), verifies the service is in an active/provisioned state, then routes each line into either **registration** (登録処理) or **deletion** (削除処理) based on the change transaction division (処理区分) determined by `checkChgTrnDiv()`.

Its **design pattern** is a gated pipeline — for each candidate contract line, it applies a series of filters: duplicate detection (`bkSvcWList.contains`), pre-provision state check (`isSvcKeiStart`), and finally CRUD routing (`insertTrn` / `deleteTrn`). Its **role** is a shared business component called internally by `chgIntrInfo()`; it is not a screen entry point but rather a focused data mutation path for introduction-code-associated service contracts.

The method handles three distinct branches per contract line:
1. **Skip duplicate** — if the contract number was already processed in this session, skip to the next.
2. **Pre-provision skip** — if the service has not yet started (`isSvcKeiStart` returns false), log and skip.
3. **Registration or Deletion** — if `checkChgTrnDiv` returns true, perform `insertTrn` (register); otherwise `deleteTrn` (delete).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["chgWribIntrInfo call"])
    START --> LOG1["printlnEjbLog start"]
    LOG1 --> INIT["Create tWorkMap, eWorkMap work maps"]
    INIT --> GETDATA["param.getData(fixedText) - Get user data inMap"]
    GETDATA --> BKLIST["Create bkSvcWList backup list"]
    BKLIST --> ISWRIB["isWrib - Get discount service list wList"]
    ISWRIB --> FORLOOP["For each wSvcKeiNo in wList"]
    FORLOOP --> CALLSC["callEKK0481B001SC - Lookup service contract"]
    CALLSC --> RETNO["retSvcKeiNo - Extract svcKeiNo"]
    RETNO --> DUPCHK{"bkSvcWList contains svcKeiNo?"}
    DUPCHK -->|Yes| CLEAR1["eWorkMap.clear"]
    DUPCHK -->|No| HIPUT["inMap.put hi_svc_kei_no"]
    HIPUT --> CALL0081["callEKK0081A010SC - Service contract status"]
    CALL0081 --> SVCCHK{"isSvcKeiStart? (Service active?)"}
    SVCCHK -->|No| MSG1["printlnEjbLog: Service before provision"]
    MSG1 --> CONT1["continue - skip to next"]
    CONT1 --> CLEAR1
    SVCCHK -->|Yes| CALL2891["callEKK2891A010SC - Post-intro channel consent"]
    CALL2891 --> TRNCHK{"checkChgTrnDiv?"}
    TRNCHK -->|True - Register| INSERT["insertTrn - Registration processing"]
    TRNCHK -->|False - Delete| DELETE["deleteTrn - Deletion processing"]
    INSERT --> BKADD["bkSvcWList.add - Save processed svcKeiNo"]
    DELETE --> BKADD
    BKADD --> CLEAR2["eWorkMap.clear"]
    CLEAR2 --> FORLOOP
    CLEAR1 --> FORLOOP
    FORLOOP --> LOG2["printlnEjbLog end"]
    LOG2 --> RET["Return param"]
    RET --> END(["End"])
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `handle` | `SessionHandle` | Database session handle providing transaction context and persistence connectivity for all DB operations (service lookups, inserts, deletes) executed during the update. |
| 2 | `param` | `IRequestParameterReadWrite` | Request/response parameter object carrying user-submitted form data. It holds the introduction code payload keyed by `fixedText` and serves as both input (via `getData`) and output (mutated fields like `hi_svc_kei_no`) across all SC calls and CRUD operations. |
| 3 | `fixedText` | `String` | A string key used to retrieve the specific block of user data from `param`. It identifies which introduction data section to process — effectively a namespace within the multi-block request payload for this screen's introduction code fields. |

**Instance fields / external state read:**
- None explicitly read as instance fields in this method. All state is passed through parameters or constructed locally (`tWorkMap`, `eWorkMap`, `bkSvcWList`, `wList`).

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKIntrInfoChgCfmCC.callEKK0081A010SC` | EKK0081A010SC | - | Calls `callEKK0081A010SC` to query service contract status and populate `eWorkMap` with status data |
| R | `JKKIntrInfoChgCfmCC.callEKK0481B001SC` | EKK0481B001SC | - | Calls `callEKK0481B001SC` to lookup service contract details for the given `wSvcKeiNo` |
| R | `JKKIntrInfoChgCfmCC.callEKK2891A010SC` | EKK2891A010SC | - | Calls `callEKK2891A010SC` to confirm post-introduction channel consent (後紹介キャンペーン同意) |
| - | `JKKIntrInfoChgCfmCC.checkChgTrnDiv` | - | - | Determines whether this contract line should be registered or deleted based on change transaction division (処理区分) |
| C | `JKKIntrInfoChgCfmCC.insertTrn` | - | - | Registers (inserts) the updated introduction information into the database |
| D | `JKKIntrInfoChgCfmCC.deleteTrn` | - | - | Deletes (cancels) the existing introduction information from the database |
| - | `JKKIntrInfoChgCfmCC.isSvcKeiStart` | - | - | Checks if the service contract line has started (active/provisioned) |
| - | `JKKIntrInfoChgCfmCC.isWrib` | - | - | Identifies which service contract numbers are discount services (割引サービス) and returns them |
| - | `JKKIntrInfoChgCfmCC.printlnEjbLog` | - | - | Utility method for EJB log output |
| - | `JKKIntrInfoChgCfmCC.retSvcKeiNo` | - | - | Extracts the service contract number (`svcKeiNo`) from a returned list of maps |
| - | `JCCcomFileSearchUtil.clear` | - | - | Clears a map/list instance |
| - | `JZMAdEdit.clear` | - | - | Clears a map/list instance |
| - | `KKA17101SFLogic.clear` | - | - | Clears a map/list instance |
| - | `KKA17401SFLogic.clear` | - | - | Clears a map/list instance |
| - | `KKA17601SFLogic.clear` | - | - | Clears a map/list instance |
| R | `KKW12701SFLogic.getData` | - | - | Retrieves data from the logic layer |

**CRUD classification for this method's direct calls:**

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `callEKK0081A010SC` | EKK0081A010SC | Service contract entity | Queries the service contract status and populates `eWorkMap` with status fields for the `isSvcKeiStart` check |
| R | `callEKK0481B001SC` | EKK0481B001SC | Service contract lookup entity | Looks up service contract details using `wSvcKeiNo`, returning a list of maps for downstream processing |
| R | `callEKK2891A010SC` | EKK2891A010SC | Post-introduction campaign entity | Performs post-introduction (referral) campaign consent check and processing |
| C | `insertTrn` | - | Introduction information table | Registers new introduction information for the contract line |
| D | `deleteTrn` | - | Introduction information table | Deletes existing introduction information for the contract line |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Controller: `JKKIntrInfoChgCfmCC.chgIntrInfo` | `chgIntrInfo` -> `chgWribIntrInfo` | `callEKK0081A010SC [R]`, `callEKK0481B001SC [R]`, `callEKK2891A010SC [R]`, `insertTrn [C]`, `deleteTrn [D]` |

This method is called exclusively from `chgIntrInfo()` within the same class (`JKKIntrInfoChgCfmCC`), serving as a focused subsidiary processing path that handles introduction/referral code updates specifically for discount-associated service contract lines.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] Initialize work maps and retrieve user data (L466-L470)

This block sets up the local working storage and extracts user-submitted introduction data from the request parameter object.

| # | Type | Code |
|---|------|------|
| 1 | SET | `tWorkMap = new HashMap<String, Object>()` // Work map for introduction processing (作業用マップ) |
| 2 | SET | `eWorkMap = new HashMap<String, Object>()` // Work map for service contract data (作業用work初期化) |
| 3 | SET | `inMap = (HashMap) param.getData(fixedText)` // User data info (ユーザデータ情報) — retrieves the data block keyed by `fixedText` |

**Block 2** — [SET] Create backup list and identify discount services (L472-L474)

Initializes the backup list to track processed contract numbers, then calls `isWrib()` to determine which service contracts are discount services (割引サービス契約番号を特定).

| # | Type | Code |
|---|------|------|
| 1 | SET | `bkSvcWList = new ArrayList<String>()` // Backup list for processed service contract numbers (保持用) |
| 2 | CALL | `wList = isWrib(param, handle, tWorkMap, inMap)` // Identifies discount service contract numbers (割引サービス契約番号を特定) |

**Block 3** — [FOR] Iterate over discount service contract numbers (L476-L524)

Loops through each discount service contract number found by `isWrib()`. For each one, it resolves the actual service contract number, applies filters, performs status checks, and routes to registration or deletion.

| # | Type | Code |
|---|------|------|
| 1 | SET | `wSvcKeiNo` = element of `wList` // Discount service contract number (割引サービス契約番号) |
| 2 | SET | `svcKeiNo = retSvcKeiNo(callEKK0481B001SC(param, handle, eWorkMap, inMap, wSvcKeiNo))` // Resolve actual contract number (サービス契約番号特定) |
| 3 | IF | See Block 3.1 below — Duplicate check |
| 4 | SET | `inMap.put("hi_svc_kei_no", svcKeiNo)` // Upstream service contract number (上書き[inMap 被紹介者サービス契約番号]) |
| 5 | CALL | `callEKK0081A010SC(param, handle, eWorkMap, inMap)` // Query service contract status (サービス契約ステータス判定用) |
| 6 | IF | See Block 3.2 below — Service start check |
| 7 | CALL | `callEKK2891A010SC(param, handle, eWorkMap, inMap)` // Post-introduction channel consent (後紹介キャンペーン同意) |
| 8 | IF | See Block 3.3 below — Transaction division check |
| 9 | SET | `bkSvcWList.add(svcKeiNo)` // Save processed contract number (処理済サービス契約番号を保持) |
| 10 | EXEC | `eWorkMap.clear()` // Clear work map for next iteration (作業用work初期化) |

**Block 3.1** — [IF] Duplicate service contract number check (L480)

Skips processing if this contract number was already handled in a prior iteration.

| # | Type | Code |
|---|------|------|
| 1 | IF | `bkSvcWList.contains(svcKeiNo)` // Has this contract number already been processed? |
| 2 | EXEC | `continue` // Skip to next iteration (同一サービスはスキップ) |

**Block 3.2** — [IF] Service start state check (L491-L495)

Verifies that the service contract line is in an active/provisioned state. Services that have not yet started are skipped to avoid writing introduction information for non-active contracts.

| # | Type | Code |
|---|------|------|
| 1 | IF | `!isSvcKeiStart(eWorkMap)` // Is service NOT yet started? |
| 2 | EXEC | `printlnEjbLog("isSvcKeiStart サービス提供以前")` // Log: before service provision (サービス提供以前) |
| 3 | EXEC | `continue` // Skip to next iteration |

**Block 3.3** — [IF/ELSE] Transaction division: registration vs deletion (L499-L515)

Routes each contract line into either registration (when `checkChgTrnDiv` returns true) or deletion (when false), based on the change transaction division (処理区分) for this introduction update.

| # | Type | Code |
|---|------|------|
| 1 | IF | `checkChgTrnDiv(inMap)` // Is this a registration transaction? (処理区分を判定) |
| 2 | EXEC | `printlnEjbLog("checkChgTrnDiv 登録処理")` // Log: registration processing (登録処理) |
| 3 | CALL | `insertTrn(param, handle, eWorkMap, inMap)` // Register the introduction information (登録の場合) |
| 4 | ELSE | — |
| 5 | EXEC | `printlnEjbLog("checkChgTrnDiv 削除処理")` // Log: deletion processing (削除処理) |
| 6 | CALL | `deleteTrn(param, handle, eWorkMap, inMap)` // Delete the introduction information (削除の場合) |

**Block 4** — [SET] Log completion and return (L526-L528)

Final logging and returns the modified parameter object.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `printlnEjbLog("chgWribIntrInfo end")` // End marker log |
| 2 | RETURN | `return param` // Returns the updated request parameter object |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `chgWribIntrInfo` | Method | Change introduction/referral information — updates introduction codes on service contract lines |
| `wrib` | Abbreviation | Discount / reduction (割引) — refers to service contracts associated with discount promotions |
| `intrInfo` | Abbreviation | Introduction information (紹介情報) — referral code/data associated with a service contract |
| `isWrib` | Method | Identify whether a service contract is a discount service and return its contract numbers |
| `wSvcKeiNo` | Field | Discount service contract number (割引サービス契約番号) — the contract number of a service that qualifies for a discount |
| `svcKeiNo` | Field | Service contract number (サービス契約番号) — the actual resolved service contract line identifier |
| `hi_svc_kei_no` | Field | Upstream / introducer service contract number (被紹介者サービス契約番号) — the contract number of the introducing/referring service, set in `inMap` |
| `bkSvcWList` | Field | Backup list of processed service contract numbers — prevents duplicate processing of the same contract line within a single invocation |
| `tWorkMap` | Field | Temporary work map (作業用マップ) — local working storage for introduction processing |
| `eWorkMap` | Field | Extended work map — stores service contract status data retrieved from SC calls; cleared each iteration |
| `inMap` | Field | Input map containing user data (ユーザデータ情報) — extracted from `param.getData(fixedText)`, carries the introduction code fields |
| `fixedText` | Parameter | String key for selecting the introduction data block from the request payload |
| `EKK0481B001SC` | SC Code | Service Component for service contract lookup — resolves contract details for a given service contract number |
| `EKK0081A010SC` | SC Code | Service Component for service contract status query — retrieves status fields to determine if service has started |
| `EKK2891A010SC` | SC Code | Service Component for post-introduction campaign consent (後紹介キャンペーン同意) — processes referral campaign confirmation |
| `isSvcKeiStart` | Method | Checks if a service contract line is in a started/provisioned state (サービス提供開始判定) |
| `checkChgTrnDiv` | Method | Determines the change transaction division (処理区分) — true means register, false means delete |
| `insertTrn` | Method | Registration processing (登録処理) — inserts new introduction information into the database |
| `deleteTrn` | Method | Deletion processing (削除処理) — removes existing introduction information from the database |
| `chgIntrInfo` | Method | Parent method that orchestrates overall introduction information change processing |
| `printlnEjbLog` | Method | EJB-level logging utility — writes debug/trace messages to the application log |
