# Business Logic — JBSbatKKIntrCdIkaAdd.updateDelaydTrnReq() [17 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKIntrCdIkaAdd` |
| Layer | Service (Batch) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKIntrCdIkaAdd.updateDelaydTrnReq()

This method updates the processing result status of a delayed transaction request (ディレイド処理依頼) within the Intermediary Code Unified Registration batch service (紹介コード一括登録品目). The batch service (`JBSbatKKIntrCdIkaAdd`) handles the bulk registration of intermediary codes — referral codes used in telecommunications customer contracting to track which sales channel or agent referred a new service subscriber. When processing errors occur during the intermediate steps of this batch (e.g., file read/write failures, validation errors), the main `execute()` method catches the exception and delegates to this method to record the error outcome in the delayed transaction request table, or to mark the request as completed if no error flag is raised. The method acts as a **result dispatcher** — it resolves the correct processing request number and routes the update to `JCCbatShoriIraiUtil` with either the application error code (「2」: Application Error) or the completion code (「1」: Complete), depending on the value of the `checkErrFlg` flag. It implements a simple conditional dispatch pattern with two branches (error vs. success) and delegates the actual database update to the shared processing request utility. Its role in the larger system is to ensure that the delayed transaction request tracking mechanism remains consistent with the batch's actual outcome, so that downstream monitoring or retry logic can correctly identify which requests succeeded and which failed.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateDelaydTrnReq(shoriIrai, checkErrFlg)"])
    STEP1["Extract shoriIraiNo from shoriIrai"]
    COND{"checkErrFlg is true?"}
    STEP_TRUE["Update result to APP_ERR"]
    STEP_FALSE["Update result to COMPLETE"]
    END_NODE(["Return / Next"])

    START --> STEP1 --> COND
    COND -->|true| STEP_TRUE --> END_NODE
    COND -->|false| STEP_FALSE --> END_NODE
```

**Processing Flow:**

1. **Extract `shoriIraiNo`**: Retrieves the delayed transaction request number (`DLYD_TRN_REQ_NO`) from the `shoriIrai` HashMap. This number uniquely identifies the delayed processing request record in the `JBSbatCC_T_DLYD_TRN_REQ` table.

2. **Conditional Branch on `checkErrFlg`**:
   - **If `checkErrFlg` is `true`** — An error occurred during batch processing. Updates the delayed transaction request result to `DLYD_TRN_RSLT_CD_APP_ERR = "2"` (Application Error / アプリケーションエラー).
   - **If `checkErrFlg` is `false`** — No error during batch processing. Updates the delayed transaction request result to `DLYD_TRN_RSLT_CD_COMPLETE = "1"` (Complete / 完了).

3. **Return**: After the update, the method returns `void` to the caller (typically the `execute()` method's catch block or the normal flow).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `shoriIrai` | `HashMap<String, Object>` | Processing request data carrier — a shared map passed through the batch execution chain that contains metadata for the current batch operation. Specifically, it carries the delayed transaction request number (`DLYD_TRN_REQ_NO`) which is the primary key reference for the delayed transaction request record that needs its status updated. This map is populated by the batch framework during initialization and threaded through `execute()` into this method. |
| 2 | `checkErrFlg` | `boolean` | Error check flag — determines the processing outcome to record. When `true`, it signals that an exception occurred during the main processing flow and the delayed transaction request should be marked with an application error status. When `false`, it indicates the batch completed successfully for this request and the status should be set to "Complete". This flag is typically set by the caller based on whether the batch reached its normal completion path or fell into an exception handler. |

**External State Read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `commonItem` | `JBSbatCommonItem` | Batch common item (protected inherited from `JBSbatBusinessService`) — carries the batch execution context including database connection, tenant information, and batch configuration. Passed as the first argument to `updateShoriIraiResult` to establish the operational context for the utility method. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `JCCbatShoriIraiUtil.updateShoriIraiResult` | JCCbatShoriIrai | - | Calls `updateShoriIraiResult` in `JCCbatShoriIraiUtil` |
| U | `JCCBatCommon.updateShoriIraiResult` | JCCBatCommon | - | Calls `updateShoriIraiResult` in `JCCBatCommon` |
| U | `JCCbatShoriIraiUtil.updateShoriIraiResult` | JCCbatShoriIrai | - | Calls `updateShoriIraiResult` in `JCCbatShoriIraiUtil` |
| U | `JDKEFileKanriBaseService.updateShoriIraiResult` | JDKEFileKanriBaseService | JDKEFileKanriBase | Calls `updateShoriIraiResult` in `JDKEFileKanriBaseService` |
| U | `JBSbatKKBankTohaigoInfIktAdd.updateShoriIraiResult` | JBSbatKKBankTohaigoInfIktAdd | - | Calls `updateShoriIraiResult` in `JBSbatKKBankTohaigoInfIktAdd` |


| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| U | `JCCbatShoriIraiUtil.updateShoriIraiResult` | JCCbatShoriIrai | DLYD_TRN_REQ (Delayed Transaction Request) | Updates the processing result status (to APP_ERR or COMPLETE) of the delayed transaction request record identified by `shoriIraiNo`. Called once — either with error code "2" or completion code "1" depending on `checkErrFlg`. |

**Classification Rationale:**
- The only direct method call is `JCCbatShoriIraiUtil.updateShoriIraiResult(...)`, which performs an **Update (U)** operation.
- The target entity is the delayed transaction request record, tracked in the table referenced by `JBSbatCC_T_DLYD_TRN_REQ.DLYD_TRN_REQ_NO`.
- SC Code is inferred as `JCCbatShoriIrai` from the utility class name.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKIntrCdIkaAdd.execute | `JBSbatKKIntrCdIkaAdd.execute` -> `updateDelaydTrnReq(shoriIrai, checkErrFlg)` | `updateShoriIraiResult [U] DLYD_TRN_REQ` |

**Caller Details:**

The sole caller of `updateDelaydTrnReq` is the `execute()` method of `JBSbatKKIntrCdIkaAdd` itself. The call occurs at line 397 within the normal processing flow of `execute()` — after the intermediary code unified registration error list has been closed, electronic file management has been registered, and temporary files have been deleted. At this point, the batch has successfully completed its intermediate processing steps and calls `updateDelaydTrnReq` to mark the delayed transaction request as complete (with `checkErrFlg = false`). If an exception occurs before reaching this call (in the catch block at line 401), the catch block calls a variant update directly (bypassing this method) to record a system error status.

**Terminal Operations:**
- `updateShoriIraiResult` [U] — Updates the delayed transaction request result code. This is the terminal database operation reached from this method.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `shoriIraiNo` extraction (L507)

> Extracts the delayed transaction request number from the processing request map. The key used is `JBSbatCC_T_DLYD_TRN_REQ.DLYD_TRN_REQ_NO = "DLYD_TRN_REQ_NO"`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `shoriIraiNo = (String) shoriIrai.get(JBSbatCC_T_DLYD_TRN_REQ.DLYD_TRN_REQ_NO)` // Delayed processing request number [-> DLYD_TRN_REQ_NO="DLYD_TRN_REQ_NO"] |

**Block 2** — [IF/ELSE] Error check flag branch (L509)

> Branches based on whether an error occurred during batch processing. The `if` branch handles application error recording; the `else` branch handles successful completion recording.

| # | Type | Code |
|---|------|------|
| 1 | COND | `if (checkErrFlg)` // チェックエラーフラグがtrueの場合 [Check error flag is true] |

**Block 2.1** — [IF-TRUE] Application error update (L512)

> When `checkErrFlg` is `true`, the batch encountered an error. Updates the delayed transaction request result code to `DLYD_TRN_RSLT_CD_APP_ERR = "2"` (Application Error / アプリケーションエラー) indicating the request should be retried or investigated.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JCCbatShoriIraiUtil.updateShoriIraiResult(commonItem, shoriIraiNo, JKKStrConst.DLYD_TRN_RSLT_CD_APP_ERR, null)` // デレイド処理依頼結果更新 - チェックエラーフラグがtrueの場合 [Delayed transaction request result update — when check error flag is true] [-> DLYD_TRN_RSLT_CD_APP_ERR="2"] |

**Block 2.2** — [ELSE] Completion update (L516)

> When `checkErrFlg` is `false`, the batch processing completed normally. Updates the delayed transaction request result code to `DLYD_TRN_RSLT_CD_COMPLETE = "1"` (Complete / 完了) indicating the request has been processed successfully.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JCCbatShoriIraiUtil.updateShoriIraiResult(commonItem, shoriIraiNo, JKKStrConst.DLYD_TRN_RSLT_CD_COMPLETE, null)` // チェックエラーフラグがfalseの場合 [When check error flag is false] [-> DLYD_TRN_RSLT_CD_COMPLETE="1"] |

**Block 3** — [RETURN] Method exit (L521)

> The method is `void` and has no explicit return statement. It simply returns to the caller after completing the update.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `(implicit void return)` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `shoriIrai` | Field | Processing request — the shared HashMap that carries batch execution metadata between methods, including the delayed transaction request number |
| `checkErrFlg` | Field | Check error flag — a boolean flag indicating whether an error occurred during batch processing; `true` means error, `false` means success |
| `shoriIraiNo` | Field | Processing request number — the unique identifier for the current batch processing request record |
| `shoriIraiNo` (Japanese: 処理依頼番号) | Field | Processing request number — internal tracking number assigned to each batch processing request |
| `dlyd_trn_req_no` (Japanese: デレイド処理依頼番号) | Field | Delayed transaction request number — unique key referencing a record in the delayed transaction request table for deferred/asynchronous processing |
| `dlyd_trn_rslt_cd` (Japanese: デレイド処理依頼結果コード) | Field | Delayed transaction request result code — status code indicating the outcome of a delayed transaction request |
| `commonItem` | Field | Batch common item — inherited from `JBSbatBusinessService`, carries the batch execution context (database connection, tenant info, batch config) |
| `JCCbatShoriIraiUtil` | Class | Processing request utility — shared utility class for updating processing request status across batch services |
| `updateShoriIraiResult` | Method | Update processing request result — utility method that updates the result code of a processing request record in the database |
| `DLYD_TRN_REQ_NO` | Constant | Delayed transaction request number key — the HashMap key used to retrieve the delayed transaction request number; value: `"DLYD_TRN_REQ_NO"` |
| `DLYD_TRN_RSLT_CD_COMPLETE` | Constant | Delayed transaction request result code Complete — value: `"1"`, indicates successful completion of the delayed transaction request |
| `DLYD_TRN_RSLT_CD_APP_ERR` | Constant | Delayed transaction request result code Application Error — value: `"2"`, indicates the delayed transaction request failed with an application-level error |
| `DLYD_TRN_RSLT_CD_SYS_ERR` | Constant | Delayed transaction request result code System Error — value: `"3"`, indicates a system-level error (not used in this method, but defined for batch-wide use) |
| JBSbatKKIntrCdIkaAdd | Class | Intermediary Code Unified Registration Batch — the batch service that handles bulk registration of intermediary/referral codes for telecommunications customer contracts |
| 紹介コード (Shoukai Code) | Business term | Referral code / intermediary code — a code used to track which sales channel or agent referred a new service subscriber in the telecom business |
| デレイド処理 (Deiredo Shori) | Business term | Delayed processing — asynchronous or deferred processing that may be executed at a later time, tracked via the delayed transaction request table |
| 処理依頼 (Shori Irae) | Business term | Processing request — a batch processing unit of work that carries metadata including request number, status, and results |
| アプリケーションエラー (Apuri keshon Erro) | Business term | Application error — an error caused by business logic or data validation failure (as opposed to a system infrastructure failure) |
| 完了 (Kanryou) | Business term | Complete — indicates that the processing request has been successfully finished |
| システムエラー (Shisutemu Erro) | Business term | System error — a low-level infrastructure error (e.g., database connection failure) |
