# Business Logic — JBSbatKKKDDIAnkenChsht.updateShoriIrai() [17 LOC]

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

## 1. Role

### JBSbatKKKDDIAnkenChsht.updateShoriIrai()

This method is the **delayed processing request result updater** — it finalizes the outcome of a batch file processing operation that was submitted for asynchronous (delayed) handling. Its business purpose is to record whether the delayed processing succeeded or failed, and persist that result to the database. When an error flag (`isSysErrFlg`) is set, the method performs a **database rollback** to undo any partial transaction state caused by the system error, and then records a system-error result code (`"3"`) for the specific delayed processing request. In the normal (no-error) path, it retrieves the delayed processing request number associated with the given file index, invokes the shared utility to update the processing request status, and commits the database transaction. This method implements a **unified completion pattern** — regardless of whether processing succeeded or failed, it ensures the delayed processing request record is updated and the transaction is properly finalized. It serves as a shared utility called from the batch entry point `execute()` to clean up and close out each file's processing lifecycle.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["updateShoriIrai fileCnt, isSysErrFlg"])

    START --> COND{isSysErrFlg<br>is true?}

    COND -- true --> RB[JBSbatBusinessBase.dbcon.rollback<br>DB Rollback]
    RB --> SET_RSLT[rsltCd = DLYD_TRN_RSLT_CD_SYS_ERR<br>Value 3 System Error]

    COND -- false --> GET_REQNO
    SET_RSLT --> GET_REQNO

    GET_REQNO[dlydTrnReqNo = dlydTrnMapList.get fileCnt DLYD_TRN_REQ_NO]

    GET_REQNO --> CALL_UPDATE[JKKBatCommon.updateShoriIraiResult<br>Delayed Processing Request Result Update]

    CALL_UPDATE --> CALL_COMMIT[JBSbatBusinessBase.dbcon.commit<br>DB Commit]

    CALL_COMMIT --> END(Return)
```

**CRITICAL — Constant Resolution:**
- `JKKStrConst.DLYD_TRN_RSLT_CD_SYS_ERR` = `"3"` (System Error result code)
- `JBSbatCC_T_DLYD_TRN_REQ.DLYD_TRN_REQ_NO` = `"ディレイド処理依頼番号"` (Delayed Processing Request Number — the lookup key within the map)
- Table: `CC_T_DLYD_TRN_REQ` (Delayed Processing Request constant table)

**Requirements:**
- Diamond nodes for conditions, rectangular nodes for processing steps.
- Show ALL branches — the `isSysErrFlg` condition has two branches (true → rollback + error code; false → normal flow).
- Both branches converge before the shared update/commit steps.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `fileCnt` | `int` | File count / file index — identifies which file's processing result to update. Used as an index into `dlydTrnMapList` to retrieve the delayed processing request number (`dlydTrnReqNo`) for this specific file. Represents the sequential position of the file being processed in a multi-file batch job. |
| 2 | `isSysErrFlg` | `boolean` | System error flag — indicates whether a system-level error occurred during delayed processing. When `true`, triggers a database rollback and sets the result code to system error (`"3"`). When `false`, proceeds with the normal success path (the result code `rsltCd` retains its prior value, typically indicating success). |

**Instance Fields Read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `dlydTrnMapList` | `List<Map<String, Object>>` | Delayed processing request map list — stores mapping data for each file's delayed processing requests. Contains keys like `DLYD_TRN_REQ_NO` (Delayed Processing Request Number). Indexed by `fileCnt`. |
| `rsltCd` | `String` | Result code — holds the processing result. Set to `"3"` (System Error) when `isSysErrFlg` is true; otherwise retains its existing value (typically a success code). |
| `commonItem` | Object | Common item — shared context/payload passed to the update utility method. Contains the transaction context needed by `JKKBatCommon.updateShoriIraiResult`. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatBusinessBase.dbcon.rollback` | - | - | Database rollback (undoes uncommitted transaction) |
| U | `JKKBatCommon.updateShoriIraiResult` | JKKBatCommon | `CC_T_DLYD_TRN_REQ` | Updates the delayed processing request result status in the database |
| - | `JBSbatBusinessBase.dbcon.commit` | - | - | Database commit (persists all transaction changes) |

**Detailed analysis:**

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatBusinessBase.dbcon.rollback` | - | - (transaction-level) | Rolls back the entire DB transaction when a system error is detected. Restores database state to pre-transaction consistency. No specific table — affects the whole active transaction. |
| U | `JKKBatCommon.updateShoriIraiResult(commonItem, dlydTrnReqNo, rsltCd, null)` | JKKBatCommon | `CC_T_DLYD_TRN_REQ` | Updates the processing request result (`shori_irai_result`) for the specific delayed processing request identified by `dlydTrnReqNo`. Sets the result code to `rsltCd` (success or error `"3"`). This is the core persistence operation of the method. |
| - | `JBSbatBusinessBase.dbcon.commit` | - | - (transaction-level) | Commits the database transaction, persisting the update to `CC_T_DLYD_TRN_REQ` permanently. Finalizes the processing result so downstream systems can observe the outcome. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKKDDIAnkenChsht | `execute()` -> `updateShoriIrai(fileCnt, isSysErrFlg)` | `updateShoriIraiResult [U] CC_T_DLYD_TRN_REQ`, `commit [-]`, `rollback [-]` |

**Instructions:**
- Caller: `JBSbatKKKDDIAnkenChsht.execute()` — this is a batch processing entry point. The `execute()` method orchestrates the overall batch workflow for a-knowledge (案件) handling, and calls `updateShoriIrai` to finalize each file's delayed processing result.
- Terminal operations from this method: `commit` (DB commit), `rollback` (DB rollback on error), `updateShoriIraiResult` [U] `CC_T_DLYD_TRN_REQ` (update delayed processing request result).

## 6. Per-Branch Detail Blocks

**Block 1** — [IF] `(isSysErrFlg)` (L599)

> Error handling branch — when a system error occurs, perform DB rollback and set the result code to system error.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JBSbatBusinessBase.dbcon.rollback()` // DBロールバック処理 (DB Rollback Processing) |
| 2 | SET | `rsltCd = JKKStrConst.DLYD_TRN_RSLT_CD_SYS_ERR` // エラーの場合 [-> "3" (System Error)] |

**Block 2** — [ELSE / Fall-through] `(isSysErrFlg is false)` (L606)

> Normal (no-error) path — result code `rsltCd` is not modified and retains its prior value (typically indicating success).

| # | Type | Code |
|---|------|------|
| 1 | *(no operation — falls through to shared block)* | |

**Block 3** — [SET / Shared after conditional] (L606)

> Retrieves the delayed processing request number for the given file index from the in-memory map list.

| # | Type | Code |
|---|------|------|
| 1 | SET | `dlydTrnReqNo = dlydTrnMapList.get(fileCnt).get(JBSbatCC_T_DLYD_TRN_REQ.DLYD_TRN_REQ_NO).toString()` // ディレイド処理依頼結果更新部品呼び出し出し (Delayed Processing Request Result Update Component Invocation) — Gets the delayed processing request number `[DLYD_TRN_REQ_NO = "ディレイド処理依頼番号"]` |

**Block 4** — [CALL] (L607)

> Invokes the shared utility to persist the processing result to the database.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `JKKBatCommon.updateShoriIraiResult(commonItem, dlydTrnReqNo, rsltCd, null)` // Updates the delayed processing request result with the result code (success or error "3") in entity `CC_T_DLYD_TRN_REQ` |

**Block 5** — [CALL] (L609)

> Finalizes the database transaction.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `JBSbatBusinessBase.dbcon.commit()` // DBコミット処理 (DB Commit Processing) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `dlydTrnReqNo` | Field | Delayed Processing Request Number — unique identifier for a delayed (asynchronous) processing request record. Used to look up and update the status of batch operations that are executed out-of-band. |
| `dlydTrnMapList` | Field | Delayed Processing Request Map List — in-memory list of maps, one entry per file, containing tracking data for delayed processing. Accessed by file index. |
| `rsltCd` | Field | Result Code — string indicating the outcome of processing. Value `"3"` means System Error. Other values typically indicate success or application-level errors. |
| `commonItem` | Field | Common Item — shared context object passed to utility methods containing transaction state, system info, and other common processing metadata. |
| `fileCnt` | Parameter | File Count / Index — zero-based (or one-based) index identifying which file in a multi-file batch job is being finalized. |
| `isSysErrFlg` | Parameter | System Error Flag — boolean flag set to `true` when a system-level error occurs during processing, triggering rollback behavior. |
| DLYD_TRN_RSLT_CD_SYS_ERR | Constant | Delayed Processing Transaction Result Code System Error — value `"3"`, the code used to mark a delayed processing request as failed due to a system error. |
| DLYD_TRN_REQ_NO | Constant | Delayed Processing Request Number — the map key (`"ディレイド処理依頼番号"`) used to retrieve the request number from the processing request map. |
| CC_T_DLYD_TRN_REQ | Table | Delayed Processing Request Table — database table storing records of asynchronous processing requests, including their status, timestamps, and job IDs. |
| ディレイド処理依頼結果更新処理 | Japanese Comment | Delayed Processing Request Result Update Processing — the business operation of recording the outcome of an asynchronous file processing job. |
| DBロールバック処理 | Japanese Comment | DB Rollback Processing — undoes all uncommitted database changes to restore consistency after an error. |
| DBコミット処理 | Japanese Comment | DB Commit Processing — permanently saves all changes in the current database transaction. |
| エラーの場合 | Japanese Comment | In case of error — indicates the error-handling conditional branch. |
| ディレイド処理依頼結果更新部品呼び出し | Japanese Comment | Delayed Processing Request Result Update Component Invocation — refers to calling the shared utility (`JKKBatCommon.updateShoriIraiResult`) that performs the actual database update. |
