# Business Logic — JBSbatKKKDDIAnkenChsht.isCreateKDDIRslt() [48 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `eo.business.service.JBSbatKKKDDIAnkenChsht` |
| Layer | Batch (Service component within batch processing layer) |
| Module | `service` (Package: `eo.business.service`) |

## 1. Role

### JBSbatKKKDDIAnkenChsht.isCreateKDDIRslt()

This method is responsible for creating and initializing the **KDDI order case result file infrastructure** (KDDI取次案件結果リスト作成 — KDDI Order Case Result List Creation). It operates as a **lazy-initialization / singleton-guard pattern**: it checks whether the result file object and its definition object have already been set up; if not, it retrieves the file name from the work parameter table, builds a timestamped file path, creates the output directory, instantiates the CSV output writer, and creates the file definition wrapper. The method acts as a **shared setup utility** called by the batch's result-insertion flow, ensuring the file writing machinery exists before data is written. If the preconditions are not met — specifically, if the work parameter holding the result file name has not been configured, or the free-item field containing the base output directory is missing — the method returns `false` to signal that the result file cannot be created, effectively blocking further processing.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["Start: isCreateKDDIRslt()"])
    COND1{"kddiRsltFileObj == null
&& kddiRsltFileDef == null"}
    GET_WORK["Get work param:
JKKBatCommon.getWorkParamSetteValue()
with KDDI_WORK_PARAM_ID_RSLT = \"KK_FILE_NM_KDDI_RSLT\""]
    CHECK_WORK{"kddiTrkmRslt != null
AND
commonItem.getFreeItem() != null"}
    PROCESS_DATE["Replace timestamp placeholder
KDDI_DATE_YMDHMS = \"yyyyMMddHHmmssSSS\"
with system datetime stamp"]
    PROCESS_FILE["Truncate filename to 23 chars
append \".csv\" extension"]
    CREATE_DIR["Create output directory
with timestamp path
via JCCFileUtil.createDir()"]
    CREATE_OBJ["Create JBSbatOutputFileUtil
for CSV file output"]
    SET_JOBID["Set JobID on file object
from commonItem.getJobid()"]
    GET_DEFNAME["Build definition filename
getAplConstValue(OTD) + KKIFE218 + \".def\""]
    CREATE_DEF["Create JBSbatDefFileUtil
with definition and output object"]
    CREATE_WRITER["Create file writer
via kddiRsltFileObj.createWriter()"]
    RETURN_TRUE["Return true
No error - KDDI result list is ready"]
    RETURN_FALSE["Return false
Error - work param not set
or required value missing"]

    START --> COND1
    COND1 -->|true| GET_WORK
    COND1 -->|false| RETURN_TRUE
    GET_WORK --> CHECK_WORK
    CHECK_WORK -->|true| PROCESS_DATE
    CHECK_WORK -->|false| RETURN_FALSE
    PROCESS_DATE --> PROCESS_FILE
    PROCESS_FILE --> CREATE_DIR
    CREATE_DIR --> CREATE_OBJ
    CREATE_OBJ --> SET_JOBID
    SET_JOBID --> GET_DEFNAME
    GET_DEFNAME --> CREATE_DEF
    CREATE_DEF --> CREATE_WRITER
    CREATE_WRITER --> RETURN_TRUE
```

**Constant Resolution:**

| Constant | Resolved Value | Business Meaning |
|----------|---------------|------------------|
| `JKKStrConst.KDDI_WORK_PARAM_ID_RSLT` | `"KK_FILE_NM_KDDI_RSLT"` | Work parameter ID for the KDDI order case result file name |
| `JKKStrConst.KDDI_FILE_ID_ANKEN_RSLT` | `"KKIFE218"` | KDDI order case result file definition ID |
| `JKKStrConst.KDDI_BAT_ID_OTD` | `"OTD"` | KDDI batch application constant prefix for OTD (order-type dispatch) |
| `KDDI_DATE_YMDHMS` | `"yyyyMMddHHmmssSSS"` | Date-time-stamp-milliseconds format string for filename substitution |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It operates on instance fields and the class's inherited `commonItem` (a `JBSbatCommonItem` set during `initial()`). |

**Instance fields / external state read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `kddiRsltFileObj` | `JBSbatOutputFileUtil` | The KDDI order case result file output object; `null` indicates not yet initialized |
| `kddiRsltFileDef` | `JBSbatDefFileUtil` | The KDDI order case result file definition object; `null` indicates not yet initialized |
| `commonItem` | `JBSbatCommonItem` | Inherited batch common parameter containing shared context: `getFreeItem()` returns the base output directory path, `getJobid()` returns the batch job identifier |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JKKBatCommon.getWorkParamSetteValue` | JKKBatCommon | `ZM_M_WORK_PARAM_KNRI` | Retrieves the KDDI result file name from the work parameter management table (ZM_M_WORK_PARAM_KNRI) using the parameter ID `KK_FILE_NM_KDDI_RSLT` |
| R | `JKKBatCommon.isNotNull` | JCCBatCommon | - | Null-check utility for validating retrieved work parameter value |
| R | `commonItem.getFreeItem` | JCCBatCommon | - | Reads the base output directory path from the batch common item |
| R | `commonItem.getJobid` | ApiCommonItem | - | Reads the batch job ID for associating with the output file |
| R | `JBSbatAplConst.getAplConstValue` | JBSbatAplConst | - | Reads application-level constants (KDDI batch ID prefix for OTD) |
| - | `JKKBatCommon.getSysDateTimeStamp` | JCCBatCommon | - | System utility to get current date-time stamp for filename generation |
| - | `JKKAdEdit.substring` | JKKAdEdit | - | String truncation utility for filename component (23-character limit) |
| C | `JCCFileUtil.createDir` | JCCFile | - | Creates the timestamped output directory on the file system before writing the result file |
| - | `JBSbatOutputFileUtil.<init>` | JBSbatOutputFileUtil | - | Instantiates the CSV output file writer with the full file path |
| - | `JBSbatOutputFileUtil.setJobID` | JBSbatOutputFileUtil | - | Associates the batch job ID with the output file object |
| - | `JBSbatDefFileUtil.<init>` | JBSbatDefFileUtil | - | Instantiates the file definition wrapper linking the `.def` definition file to the output object |
| - | `JBSbatOutputFileUtil.createWriter` | JBSbatOutputFileUtil | - | Creates and opens the actual file writer (output stream) for CSV writing |

## 5. Dependency Trace

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

Direct callers found: 1 method.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKKDDIAnkenChsht.setKDDIRslt()` | `setKDDIRslt()` -> `isCreateKDDIRslt()` | `getWorkParamSetteValue [R] ZM_M_WORK_PARAM_KNRI`, `getSysDateTimeStamp [-]`, `createDir [C] -`, `getJobid [R] -`, `createWriter [-]` |

**Terminal operations from this method:** `getWorkParamSetteValue [R] ZM_M_WORK_PARAM_KNRI`, `getSysDateTimeStamp [-]`, `isNotNull [-]`, `createDir [C] -`, `getJobid [R] -`, `getAplConstValue [-]`, `createWriter [-]`, `substring [-]`

## 6. Per-Branch Detail Blocks

**Block 1** — IF `(kddiRsltFileObj == null && kddiRsltFileDef == null)` (L252)

> Initialization guard: If neither the output file object nor the definition file object have been created, proceed to build the KDDI result file infrastructure from scratch.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `kddiTrkmRslt = JKKBatCommon.getWorkParamSetteValue(commonItem, KKKStrConst.KDDI_WORK_PARAM_ID_RSLT ("KK_FILE_NM_KDDI_RSLT"), db_ZM_M_WORK_PARAM_KNRI)` // KDDI order case result file name retrieval |
| 2 | EXEC | `JKKBatCommon.isNotNull(kddiTrkmRslt)` // Null-check on work param value |
| 3 | CALL | `commonItem.getFreeItem()` // Null-check on base output directory path |
| 4 | RETURN | `return false;` // Values not available — cannot create file |
| 5 | SET | `kddiDateYMDHMS = kddiTrkmRslt.replace(KDDI_DATE_YMDHMS ("yyyyMMddHHmmssSSS"), JKKBatCommon.getSysDateTimeStamp())` // Replace timestamp placeholder with actual system datetime |
| 6 | SET | `kddiRsltFileName = kddiDateYMDHMS.substring(0, 23) + ".csv"` // Truncate to 23 chars and append .csv extension |
| 7 | SET | `kddiDirYMDHMS = JKKBatCommon.getSysDateTimeStamp()` // Store directory timestamp for path construction |
| 8 | CALL | `JCCFileUtil.createDir(commonItem.getFreeItem() + "/" + kddiDirYMDHMS + "/" + kddiRsltFileName)` // Create the timestamped output directory |
| 9 | SET | `kddiRsltFileObj = new JBSbatOutputFileUtil(commonItem.getFreeItem() + "/" + kddiDirYMDHMS + "/" + kddiRsltFileName)` // Instantiate the CSV output file object with full path |
| 10 | EXEC | `kddiRsltFileObj.setJobID(commonItem.getJobid())` // Set the batch job ID on the output object |
| 11 | SET | `kddiRsltFileDefName = JBSbatAplConst.getAplConstValue(JKKStrConst.KDDI_BAT_ID_OTD ("OTD")) + JKKStrConst.KDDI_FILE_ID_ANKEN_RSLT ("KKIFE218") + ".def"` // Build definition filename: OTD + KKIFE218 + .def |
| 12 | SET | `kddiRsltFileDef = new JBSbatDefFileUtil(kddiRsltFileDefName, kddiRsltFileObj)` // Instantiate the file definition wrapper |
| 13 | EXEC | `kddiRsltFileObj.createWriter()` // Create and open the file writer for CSV writing |

**Block 2** — ELSE (implicit — both `kddiRsltFileObj` and `kddiRsltFileDef` are already non-null) (L295)

> Early-return path: The result file infrastructure was already initialized by a prior call. No further action is needed.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return true;` // No error — KDDI result list is ready |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `kddiRsltFileObj` | Field | KDDI order case result file output object — holds the writer for the CSV result file |
| `kddiRsltFileDef` | Field | KDDI order case result file definition object — holds the `.def` schema definition for the output file |
| `kddiRsltFileName` | Field | KDDI order case result file name — the generated CSV filename (e.g., `20250701120000123456.csv`) |
| `kddiDateYMDHMS` | Field | Date-time-stamp string used for constructing timestamped output paths |
| `kddiDirYMDHMS` | Field | Directory timestamp component for organizing result files by time |
| `commonItem` | Field | Batch common item — shared context object containing job ID, output directory, and other batch-wide parameters |
| `getFreeItem()` | Field | Base output directory path from the batch common item |
| `getJobid()` | Field | Batch job identifier — associates the output file with a specific batch execution |
| `KDDI_WORK_PARAM_ID_RSLT` | Constant | `"KK_FILE_NM_KDDI_RSLT"` — work parameter ID used to look up the KDDI order case result file name in the work parameter table |
| `KDDI_FILE_ID_ANKEN_RSLT` | Constant | `"KKIFE218"` — the KDDI order case result file definition ID |
| `KDDI_BAT_ID_OTD` | Constant | `"OTD"` — KDDI batch application constant prefix for order-type dispatch processing |
| `KDDI_DATE_YMDHMS` | Constant | `"yyyyMMddHHmmssSSS"` — date-time-stamp-milliseconds format string |
| `ZM_M_WORK_PARAM_KNRI` | Entity/DB | Work parameter management table — stores configuration parameters including file name templates |
| KDDI | Business term | Docomo (NTT Docomo) — Japanese telecommunications carrier; this module handles KDDI-specific order case result file processing |
| 取次案件結果 | Japanese field | Order case result — the result of processing an order case, output as a CSV file |
| 案件結果リスト作成 | Japanese term | Result list creation — the process of generating the structured result file |
| OTD | Acronym | Order Type Dispatch — the batch application ID prefix for KDDI order processing |
| JBSbatOutputFileUtil | Class | Output file utility — manages CSV output file creation, writing, and closing |
| JBSbatDefFileUtil | Class | Definition file utility — wraps a `.def` file schema definition for output file validation |
| JBSbatAplConst | Class | Application constant utility — provides runtime-accessible application-level constants |
| ZM_M | Table prefix | Work parameter management table prefix — `ZM` refers to the master/work data management schema |
