# Business Logic — JBSbatKKIntrCdIkaAdd.addEfileAndDlFileKanri() [25 LOC]

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

## 1. Role

### JBSbatKKIntrCdIkaAdd.addEfileAndDlFileKanri()

This method performs end-to-end electronic file (denshi file) management registration for the brokerage code integration add batch. It creates a denshi file from a temporary file path using the system's common denshi file creation service, then registers the resulting file metadata into the download file management table (`ZM_T_DL_FILE_KANRI`). The denshi file creation process also determines a file deletion date by adding one month to the current operation date (`opeDate`), ensuring automatic cleanup of the temporary file at a future date. After the denshi file is created, the method generates the final filename by replacing a timestamp placeholder in the provided `fileNameTemplate` with the current system date-time, and logs the resulting file number and registration timestamp for audit purposes. The method acts as a bridge between the temporary-file processing stage of the batch and the permanent file-management tracking layer, ensuring every denshi file is tracked with its management number, filename, record count, and metadata. It follows a linear sequential processing pattern with no conditional branches, making it a deterministic utility method invoked by the main `execute()` entry point of the batch service.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addEfileAndDlFileKanri params"])
    START --> STEP1["Set method parameters
arg0 = commonItem
arg1 = FILE_CD = '0000'
arg2 = tmpFilePath
arg3 = adjustMonth(opeDate, 1)"]
    STEP1 --> STEP2["Create electronic file
JCCBatCommon.createDenshiFile
Returns: rc[0] fileNo, rc[1] sysDateTime"]
    STEP2 --> STEP3["Log result
printDebugLog with fileNo and sysDateTime"]
    STEP3 --> STEP4["Generate filename
replaceAll timestamp placeholder
with getSysDateTime()"]
    STEP4 --> STEP5["Build insert param array
[0] trnKanriNo
[1] fileName
[2] recordCount
[3] rc[0]
[4] rc[1]"]
    STEP5 --> STEP6["Execute DB insert
executeZM_T_DL_FILE_KANRI_KK_INSERT_002
Writes to ZM_T_DL_FILE_KANRI"]
    STEP6 --> END(["Return"])
```

**CRITICAL — Constant Resolution:**
- `FILE_CD = "0000"` — The internal file code identifying this as an electronic file management file type.
- `FILE_TIMESTAMP_FORMAT = "yyyyMMddHHmmssSSS"` — The timestamp placeholder pattern used in the filename template, replaced with the current system date-time (year, month, day, hour, minute, second, milliseconds).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `tmpFilePath` | `String` | The full file system path to the temporary file that was generated during batch processing and needs to be registered as a permanent electronic (denshi) file. This is the source file passed to `createDenshiFile` for archival. |
| 2 | `fileNameTemplate` | `String` | A filename template string containing a timestamp placeholder (`yyyyMMddHHmmssSSS`) that will be replaced with the actual system date-time to produce the final managed filename. Represents the naming convention for the registered file. |
| 3 | `trnKanriNo` | `String` | The transaction processing management number — a unique batch transaction identifier used to correlate the file management record with the specific batch execution instance. Links the file to its originating processing run. |
| 4 | `recordCount` | `String` | The total number of data records (data件数) contained in the electronic file. Provides a data integrity checksum for downstream verification and reporting. |

**Instance fields / external state read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `commonItem` | `JBSbatCommonItem` | Batch common electronic document parameters — carries shared batch context (system info, operation date, connection settings) injected via `initial()`. |
| `FILE_CD` | `static final String` | File code constant = `"0000"`, identifying the electronic file management file type. |
| `opeDate` | (inherited from `JBSbatBusinessService`) | The operation date — used to compute the file deletion date (operation date + 1 month). |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCBatCommon.createDenshiFile` | JCCBatCommon | Denshi file storage | Creates a permanent electronic (denshi) file from the temp file, returning the electronic file management number and system registration date-time. |
| R | `JCCBatCommon.getSysDateTime` | JCCBatCommon | System clock | Retrieves the current system date-time string for filename timestamp generation. |
| R | `JBSbatDateUtil.adjustMonth` | JBSbatDateUtil | - | Adjusts the operation date forward by 1 month to compute the file deletion (retention expiry) date. |
| C | `JBSbatKKIntrCdIkaAdd.executeZM_T_DL_FILE_KANRI_KK_INSERT_002` | JBSbatKKIntrCdIkaAdd | `ZM_T_DL_FILE_KANRI` | Inserts a new record into the download file management table, registering the electronic file metadata (management number, filename, record count, denshi file number, registration timestamp). |
| - | `JBSbatLogPrint.printDebugLog` | JBSbatLogPrint | - | Logs the electronic file management number and system registration date-time for operational audit. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKIntrCdIkaAdd.execute()` | `JBSbatKKIntrCdIkaAdd.execute` -> `JBSbatKKIntrCdIkaAdd.addEfileAndDlFileKanri` | `executeZM_T_DL_FILE_KANRI_KK_INSERT_002 [C] ZM_T_DL_FILE_KANRI`, `createDenshiFile [R] Denshi file storage`, `getSysDateTime [R] System clock` |

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENTIAL PROCESSING] (L473)

> Initialize method parameters and create the electronic (denshi) file. The method binds the common item context, file code, temporary file path, and adjusted operation date into local argument variables before delegating to the shared denshi file creation service.

| # | Type | Code |
|---|------|------|
| 1 | SET | `arg0 = commonItem` // Business common electronic document (commonItem) [-> commonItem is JBSbatCommonItem] |
| 2 | SET | `arg1 = FILE_CD` // File code [-> FILE_CD = "0000"] |
| 3 | SET | `arg2 = tmpFilePath` // File path (parameter) |
| 4 | SET | `arg3 = JBSbatDateUtil.adjustMonth(super.opeDate, 1)` // File deletion year-month (operation date + 1 month) [-> adjustMonth adds 1 month to opeDate] |
| 5 | CALL | `JCCBatCommon.createDenshiFile(arg0, arg1, arg2, arg3)` // Returns String[] rc: rc[0]=electronic file management number, rc[1]=system registration date-time |

**Block 2** — [SEQUENTIAL PROCESSING] (L483)

> Log the result of the electronic file creation, recording the file number and system registration timestamp for operational audit visibility.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `super.logPrint.printDebugLog(...)` // Print debug log with file number (rc[0]) and system registration date-time-seconds (rc[1]) |

**Block 3** — [SEQUENTIAL PROCESSING] (L486)

> Generate the final filename by replacing the timestamp placeholder in the filename template with the current system date-time.

| # | Type | Code |
|---|------|------|
| 1 | SET | `fileName = fileNameTemplate.replaceAll(FILE_TIMESTAMP_FORMAT, JCCBatCommon.getSysDateTime())` // Replace 'yyyyMMddHHmmssSSS' placeholder with actual system date-time [-> FILE_TIMESTAMP_FORMAT = "yyyyMMddHHmmssSSS"] |

**Block 4** — [SEQUENTIAL PROCESSING] (L489)

> Build the insert parameter array with 5 fields representing the complete metadata for the download file management record. This array is then passed to the database insert method.

| # | Type | Code |
|---|------|------|
| 1 | SET | `insertSetParam2 = new String[5]` // New array for 5 fields |
| 2 | SET | `insertSetParam2[0] = trnKanriNo` // Processing management number (parameter) |
| 3 | SET | `insertSetParam2[1] = fileName` // Filename (generated in Block 3) |
| 4 | SET | `insertSetParam2[2] = recordCount` // Data record count (parameter) |
| 5 | SET | `insertSetParam2[3] = rc[0]` // Electronic file management number (from createDenshiFile return) |
| 6 | SET | `insertSetParam2[4] = rc[1]` // System registration date-time (from createDenshiFile return) |
| 7 | CALL | `executeZM_T_DL_FILE_KANRI_KK_INSERT_002(insertSetParam2)` // Insert file management record into ZM_T_DL_FILE_KANRI table [-> C operation on ZM_T_DL_FILE_KANRI] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `denshi file` | Business term | Electronic file — a permanent file created from a temporary file as part of batch processing, managed through the shared Denshi file creation service. |
| `FILE_CD` | Field | File code — a constant `"0000"` identifying the electronic file management file type. |
| `FILE_TIMESTAMP_FORMAT` | Field | Timestamp format pattern `"yyyyMMddHHmmssSSS"` used as a placeholder in filenames, replaced with actual system date-time at runtime. |
| `tmpFilePath` | Field | Temporary file path — the file system path to a temporary file generated during batch processing that will be registered as a permanent denshi file. |
| `fileNameTemplate` | Field | Filename template — a string pattern with a timestamp placeholder that becomes the final managed filename after replacement. |
| `trnKanriNo` | Field | Transaction processing management number — a unique batch transaction ID that correlates file management records with their originating batch run. |
| `recordCount` | Field | Data record count (データ件数) — the total number of records in the electronic file, used for data integrity verification. |
| `opeDate` | Field | Operation date — the batch execution date inherited from the parent `JBSbatBusinessService`, used to compute the file retention/deletion date. |
| `commonItem` | Field | Batch common electronic document (業務共通電文) — a `JBSbatCommonItem` object carrying shared batch context including system info, connection settings, and operation date. |
| `ZM_T_DL_FILE_KANRI` | DB Table | Download File Management table — the database table storing electronic file metadata including management number, filename, record count, denshi file number, and registration timestamp. |
| `ZM_T_DL_FILE_KANRI_KK_INSERT_002` | SQL Key | SQL definition key for the insert operation on the `ZM_T_DL_FILE_KANRI` table. |
| `createDenshiFile` | Method | Denshi file creation service — a shared utility that promotes a temporary file to a permanent electronic file and returns the management number and registration timestamp. |
| `adjustMonth` | Method | Date adjustment utility — adds a specified number of months to a date (used here to add 1 month for file retention expiry calculation). |
| `getSysDateTime` | Method | System date-time retrieval — returns the current system date-time as a formatted string. |
| `JBSbatCommonItem` | Class | Common batch item — framework class carrying shared batch execution context (system ID, operation date, connection parameters). |
| `logPrint` | Field | Debug log printer — a logger instance for writing operational audit entries via `printDebugLog`. |