# Business Logic — JBSbatKKBndWdtOvrSendMl.initial() [40 LOC]

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

## 1. Role

### JBSbatKKBndWdtOvrSendMl.initial()

This method performs the initialization step for the **Bandwidth-Controlled Communication Volume Overuse Notification Mail** batch (`JBSbatKKBndWdtOvrSendMl`), which is responsible for generating and sending email notifications to customers who have exceeded their carrier-controlled data usage limits on FTTH (Fiber To The Home) broadband services. The method serves as the **lifecycle entry point** called by the batch framework before the main `execute()` processing phase runs. Its business purpose is to bootstrap all runtime state required for the subsequent mail-sending work: it registers shared common parameters via the parent class, instantiates SQL access layers for five database tables used throughout the batch lifecycle (service contracts, contract details, option service contracts, FTTH overuse records, and mail master data), and initializes two output file writers — one for producing a count file (enumerating notification recipients) and one for producing a flag file (tracking processing status). This method is a **delegation pattern** entry point: it sets up infrastructure but defers all actual business logic (data retrieval, mail content generation, and transmission) to the `execute()` method. The batch is triggered based on the `SEND_KBN` (send classification) field being `2` (actual notification) and only on days other than the 1st of the month (since bandwidth restrictions are not enforced on the first day per OM-2015-0000836).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["initial(commonItem)"])
    START --> CALL_SET["CALL: super.setCommonInfo(commonItem)"]
    CALL_SET --> INIT_DB1["SET: db_KK_T_SVC_KEI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_SVC_KEI)"]
    INIT_DB1 --> INIT_DB2["SET: db_KK_T_SVC_KEI_UCWK = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_SVC_KEI_UCWK)"]
    INIT_DB2 --> INIT_DB3["SET: db_KK_T_OP_SVC_KEI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_OP_SVC_KEI)"]
    INIT_DB3 --> INIT_DB4["SET: db_KK_T_FTTH_TSRCK_JSK = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_FTTH_TSRCK_JSK)"]
    INIT_DB4 --> INIT_DB5["SET: db_CC_M_MAIL = new JBSbatSQLAccess(commonItem, D_TBL_NAME_CC_M_MAIL)"]
    INIT_DB5 --> PARSE_FREE["EXEC: mfreeItem = super.freeItem.split(';')"]
    PARSE_FREE --> SET_CNT_PATH["SET: BndWdtOvrTchiCntFilePath = mfreeItem[0]"]
    SET_CNT_PATH --> SET_FLG_PATH["SET: BndWdtOvrTchiFlgFilePath = mfreeItem[1]"]
    SET_FLG_PATH --> INIT_CNT_FILE["SET: BndWdtOvrTchiCntFile = new JBSbatOutputFileUtil(BndWdtOvrTchiCntFilePath)"]
    INIT_CNT_FILE --> SET_CNT_ENCODE["EXEC: BndWdtOvrTchiCntFile.setEncode(JKKBatConst.SJIS)"]
    SET_CNT_ENCODE --> SET_CNT_LINE["EXEC: BndWdtOvrTchiCntFile.setLine(LF)"]
    SET_CNT_LINE --> CREATE_CNT_WRITER["EXEC: BndWdtOvrTchiCntFile.createWriter()"]
    CREATE_CNT_WRITER --> INIT_FLG_FILE["SET: BndWdtOvrTchiFlgFile = new JBSbatOutputFileUtil(BndWdtOvrTchiFlgFilePath)"]
    INIT_FLG_FILE --> SET_FLG_ENCODE["EXEC: BndWdtOvrTchiFlgFile.setEncode(JKKBatConst.SJIS)"]
    SET_FLG_ENCODE --> SET_FLG_LINE["EXEC: BndWdtOvrTchiFlgFile.setLine(LF)"]
    SET_FLG_LINE --> CREATE_FLG_WRITER["EXEC: BndWdtOvrTchiFlgFile.createWriter()"]
    CREATE_FLG_WRITER --> END_NODE(["Return / Next"])
```

**CRITICAL — Constant Resolution:**

| Constant in Code | Resolved Value | Business Meaning |
|------------------|---------------|------------------|
| `JKKBatConst.SJIS` | `"Shift-JIS"` | Japanese character encoding standard [-> SJIS="Shift-JIS" (JKKBatConst.java:47)] |
| `LF` (field) | `"LF"` | Line-feed delimiter for output files [-> LF="LF" (JBSbatKKBndWdtOvrSendMl.java:121)] |

**Processing flow summary:**
1. **Common parameter setup** — delegates to parent `JBSbatBusinessService.setCommonInfo()` to synchronize batch metadata (operation date, batch user ID, etc.) from `commonItem` into instance fields.
2. **Database access layer initialization** — creates five `JBSbatSQLAccess` wrappers, one per database table needed during the batch lifecycle (service contracts, contract details, option service contracts, FTTH overuse records, and mail master).
3. **Free-item parsing** — splits the semi-colon-delimited `freeItem` string (provided via the batch common parameters) into file paths for the count file and flag file.
4. **Output file writer initialization (count file)** — creates a `JBSbatOutputFileUtil` with Shift-JIS encoding and LF line endings, then opens the writer.
5. **Output file writer initialization (flag file)** — same setup as the count file, for a separate flag/status file.
6. Returns (void) — the batch framework proceeds to call `execute()`.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `commonItem` | `JBSbatCommonItem` | Batch common parameter message — carries shared batch execution context including the operation date (`opeDate`), batch user ID, and the `freeItem` field which contains a semi-colon-delimited list of file paths for the notification count output and flag output. This object is the single conduit through which the batch framework passes all runtime configuration into service methods. |

**Instance fields read by this method:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `super.freeItem` | `String` | Inherited free-form parameter string from `JBSbatBusinessService` containing semi-colon-separated file paths for batch output configuration |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `JBSbatBusinessService.setCommonInfo` | - | - | Sets common batch parameters (operation date, user ID) from `commonItem` into parent instance fields |
| - | `JBSbatSQLAccess` constructor (×5) | - | `KK_T_SVC_KEI`, `KK_T_SVC_KEI_UCWK`, `KK_T_OP_SVC_KEI`, `KK_T_FTTH_TSRCK_JSK`, `CC_M_MAIL` | Instantiates SQL access layers for five database tables — read-only accessor setup, no DB operation yet |
| - | `JBSbatOutputFileUtil` constructor (×2) | - | File system | Creates file output utility wrappers for count and flag output files |
| - | `JBSbatOutputFileUtil.setEncode` (×2) | - | File system | Configures Shift-JIS encoding for both output files [-> SJIS="Shift-JIS" (JKKBatConst.java:47)] |
| - | `JBSbatOutputFileUtil.setLine` (×2) | - | File system | Configures LF line delimiter for both output files [-> LF="LF" (JBSbatKKBndWdtOvrSendMl.java:121)] |
| - | `JBSbatOutputFileUtil.createWriter` (×2) | - | File system | Opens file writers ready for subsequent data output in the `execute()` phase |

**Database tables accessed (via SQLAccess wrappers):**

| Table Name | Business Description |
|------------|---------------------|
| `KK_T_SVC_KEI` | Service contract table — stores main service contract records |
| `KK_T_SVC_KEI_UCWK` | Service contract detail table — stores line-item/detail records for service contracts |
| `KK_T_OP_SVC_KEI` | Option service contract table — stores option/add-on service contract records |
| `KK_T_FTTH_TSRCK_JSK` | FTTH communication volume overuse records table — stores actual FTTH data usage data for overuse detection |
| `CC_M_MAIL` | Mail master table — stores mail template and configuration metadata |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: `JBSbatKKBndWdtOvrSendMl` | Batch framework lifecycle → `initial(commonItem)` | `setCommonInfo[JBSbatBusinessService]`, `db_KK_T_SVC_KEI[R] KK_T_SVC_KEI`, `db_KK_T_SVC_KEI_UCWK[R] KK_T_SVC_KEI_UCWK`, `db_KK_T_OP_SVC_KEI[R] KK_T_OP_SVC_KEI`, `db_KK_T_FTTH_TSRCK_JSK[R] KK_T_FTTH_TSRCK_JSK`, `db_CC_M_MAIL[R] CC_M_MAIL`, `BndWdtOvrTchiCntFile[C] Count File`, `BndWdtOvrTchiFlgFile[C] Flag File` |

**Notes on caller analysis:**
- This method is the **batch framework entry point** — it is called by the underlying `JBSbatBusinessService` batch execution framework as the first lifecycle phase before `execute()` is invoked. There are no explicit screen-level or CBS-level callers in the codebase that directly invoke `initial()`. It is an internal lifecycle hook, analogous to a constructor+init phase combined.
- The method is the initialization half of a two-phase batch: `initial()` prepares state, `execute()` performs the actual business processing (mail data extraction, SOD issuance, and file output).

## 6. Per-Branch Detail Blocks

### Block 1 — CALL `(common parameter setup)` (L167)

> Sets common batch parameters by delegating to the parent class. This ensures that the batch operation date, user ID, and other shared metadata are synchronized into the service instance from the incoming `commonItem` envelope.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `super.setCommonInfo(commonItem);` // Set common parameters [-> setCommonInfo() delegates to JBSbatBusinessService] |

### Block 2 — CALL `(DB access class generation)` (L170-177)

> Instantiates SQL access layer wrappers for five database tables. These are factory-style object creation calls — no actual SQL is executed yet. The wrappers are stored in instance fields for reuse during the `execute()` phase.

| # | Type | Code |
|---|------|------|
| 1 | SET | `db_KK_T_SVC_KEI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_SVC_KEI);` // DB access class (service contract) [-> D_TBL_NAME_KK_T_SVC_KEI="KK_T_SVC_KEI" (JBSbatKKBndWdtOvrSendMl.java:64)] |
| 2 | SET | `db_KK_T_SVC_KEI_UCWK = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_SVC_KEI_UCWK);` // DB access class (service contract details) [-> D_TBL_NAME_KK_T_SVC_KEI_UCWK="KK_T_SVC_KEI_UCWK" (JBSbatKKBndWdtOvrSendMl.java:67)] |
| 3 | SET | `db_KK_T_OP_SVC_KEI = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_OP_SVC_KEI);` // DB access class (option service contract) [-> D_TBL_NAME_KK_T_OP_SVC_KEI="KK_T_OP_SVC_KEI" (JBSbatKKBndWdtOvrSendMl.java:70)] |
| 4 | SET | `db_KK_T_FTTH_TSRCK_JSK = new JBSbatSQLAccess(commonItem, D_TBL_NAME_KK_T_FTTH_TSRCK_JSK);` // DB access class (FTTH overuse records) [-> D_TBL_NAME_KK_T_FTTH_TSRCK_JSK="KK_T_FTTH_TSRCK_JSK" (JBSbatKKBndWdtOvrSendMl.java:73)] |
| 5 | SET | `db_CC_M_MAIL = new JBSbatSQLAccess(commonItem, D_TBL_NAME_CC_M_MAIL);` // DB access class (mail master) [-> D_TBL_NAME_CC_M_MAIL="CC_M_MAIL" (JBSbatKKBndWdtOvrSendMl.java:120)] |

### Block 3 — EXEC `(free item field acquisition)` (L182)

> Parses the semi-colon-delimited `freeItem` parameter provided by the batch framework to extract file system paths for the two output files (count file and flag file).

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `String[] mfreeItem = super.freeItem.split(";");` // Free item acquisition (semi-colon delimited) |

### Block 4 — SET `(count file path extraction)` (L184)

> Extracts the file path for the bandwidth overuse notification count file from index 0 of the parsed array. This file will later contain a count of customers who exceeded their data usage.

| # | Type | Code |
|---|------|------|
| 1 | SET | `this.BndWdtOvrTchiCntFilePath = mfreeItem[0];` // Bandwidth-controlled communication volume overuse notification (count) file path storage [-> BndWdtOvrTchiCntFilePath is private String field] |

### Block 5 — SET `(flag file path extraction)` (L186)

> Extracts the file path for the bandwidth overuse notification flag file from index 1 of the parsed array. This file will later contain processing flag/status data.

| # | Type | Code |
|---|------|------|
| 1 | SET | `this.BndWdtOvrTchiFlgFilePath = mfreeItem[1];` // Bandwidth-controlled communication volume overuse notification (flag) file path storage [-> BndWdtOvrTchiFlgFilePath is private String field] |

### Block 6 — IF `[count file initialization]` (L189-192)

> Creates and configures the output file utility for the notification count file, then opens the file writer.

| # | Type | Code |
|---|------|------|
| 1 | SET | `BndWdtOvrTchiCntFile = new JBSbatOutputFileUtil(this.BndWdtOvrTchiCntFilePath);` // Bandwidth-controlled communication volume overuse notification (count) file |
| 2 | EXEC | `BndWdtOvrTchiCntFile.setEncode(JKKBatConst.SJIS);` // Set encoding to Shift-JIS [-> SJIS="Shift-JIS" (JKKBatConst.java:47)] |
| 3 | EXEC | `BndWdtOvrTchiCntFile.setLine(LF);` // Set line delimiter [-> LF="LF" (JBSbatKKBndWdtOvrSendMl.java:121)] |
| 4 | EXEC | `BndWdtOvrTchiCntFile.createWriter();` // Open the file writer |

### Block 7 — IF `[flag file initialization]` (L195-198)

> Creates and configures the output file utility for the notification flag file, then opens the file writer. Same configuration as the count file (Shift-JIS encoding, LF line endings).

| # | Type | Code |
|---|------|------|
| 1 | SET | `BndWdtOvrTchiFlgFile = new JBSbatOutputFileUtil(this.BndWdtOvrTchiFlgFilePath);` // Bandwidth-controlled communication volume overuse notification (flag) file |
| 2 | EXEC | `BndWdtOvrTchiFlgFile.setEncode(JKKBatConst.SJIS);` // Set encoding to Shift-JIS [-> SJIS="Shift-JIS" (JKKBatConst.java:47)] |
| 3 | EXEC | `BndWdtOvrTchiFlgFile.setLine(LF);` // Set line delimiter [-> LF="LF" (JBSbatKKBndWdtOvrSendMl.java:121)] |
| 4 | EXEC | `BndWdtOvrTchiFlgFile.createWriter();` // Open the file writer |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `BndWdtOvrTchiCntFilePath` | Field | Bandwidth-Controlled Communication Volume Overuse Notification (Count) File Path — file system path for the output file that will hold the count of overuse notification recipients |
| `BndWdtOvrTchiFlgFilePath` | Field | Bandwidth-Controlled Communication Volume Overuse Notification (Flag) File Path — file system path for the output flag/status file |
| `BndWdtOvrTchiCount` | Field | Bandwidth-Controlled Communication Volume Overuse Notification count — integer counter tracking how many notification recipients have been processed |
| `BndWdtOvrTchiCntFile` | Field | Bandwidth-Controlled Communication Volume Overuse Notification (Count) File — output file utility for writing the count file |
| `BndWdtOvrTchiFlgFile` | Field | Bandwidth-Controlled Communication Volume Overuse Notification (Flag) File — output file utility for writing the flag file |
| `freeItem` | Field | Free-form batch parameter — semi-colon-delimited string carrying configuration data (file paths) from the batch framework |
| `KK_T_SVC_KEI` | Table | Service Contract Table — stores main service contract header records in the telecom billing system |
| `KK_T_SVC_KEI_UCWK` | Table | Service Contract Detail Table — stores line-item/detail records for service contracts (UCWK = utility work / contract line items) |
| `KK_T_OP_SVC_KEI` | Table | Option Service Contract Table — stores optional/add-on service contract records linked to main contracts |
| `KK_T_FTTH_TSRCK_JSK` | Table | FTTH Communication Volume Overuse Records Table — stores actual FTTH data usage records for overuse detection and notification purposes (TSRCK_JSK = usage record actual) |
| `CC_M_MAIL` | Table | Mail Master Table — master data for email templates, mail codes, and mail configuration |
| `KK_SELECT_180` | SQL Key | SQL definition key for querying `KK_T_SVC_KEI` (service contract) |
| `KK_SELECT_069` | SQL Key | SQL definition key for querying `KK_T_SVC_KEI_UCWK` (service contract details) |
| `KK_SELECT_054` | SQL Key | SQL definition key for querying `KK_T_OP_SVC_KEI` (option service contracts) |
| `KK_SELECT_006` | SQL Key | SQL definition key for querying `KK_T_FTTH_TSRCK_JSK` (FTTH overuse records) |
| `KK_SELECT_004` | SQL Key | SQL definition key for querying `CC_M_MAIL` (mail master) |
| MAIL_CD_YKK | Constant | Mail code for warning notifications: `"KKM1000007"` (previously `"KK00000001"`, changed in v4.00 / IT1-2012-0002548) [-> MAIL_CD_YKK="KKM1000007" (JBSbatKKBndWdtOvrSendMl.java:84)] |
| MAIL_CD_JSHI | Constant | Mail code for actual implementation notifications: `"KKM1000008"` (previously `"KK00000011"`, changed in v4.00) [-> MAIL_CD_JSHI="KKM1000008" (JBSbatKKBndWdtOvrSendMl.java:88)] |
| SEND_KBN_YOKOKU | Constant | Send classification code `"1"` — warning notification (pre-advisory before actual enforcement) [-> SEND_KBN_YOKOKU="1" (JBSbatKKBndWdtOvrSendMl.java:91)] |
| SEND_KBN_JISHI | Constant | Send classification code `"2"` — actual notification (enforcement notification) [-> SEND_KBN_JISHI="2" (JBSbatKKBndWdtOvrSendMl.java:94)] |
| USECASE_ID_KKSV0571 | Constant | User case ID `"KKSV0571"` — identifies the bandwidth restriction enforcement use case [-> USECASE_ID_KKSV0571="KKSV0571" (JBSbatKKBndWdtOvrSendMl.java:97)] |
| SYORI_DIV_011 | Constant | Processing division code `"011"` — bandwidth restriction enforcement [-> SYORI_DIV_011="011" (JBSbatKKBndWdtOvrSendMl.java:103)] |
| RETURN_CODE_SUCCESS | Constant | Return code `"0"` — indicates success from the service IF call [-> RETURN_CODE_SUCCESS="0" (JBSbatKKBndWdtOvrSendMl.java:106)] |
| MAIL_SEND_PATTERN_CD_02 | Constant | Mail send pattern code `"02"` — mail plan format send pattern [-> MAIL_SEND_PATTERN_CD_02="02" (JBSbatKKBndWdtOvrSendMl.java:80)] |
| CC_TITLE_JKKHAKKOSODCC | Constant | CC Title `"JKKHakkoSODCC"` — service order issuance CC title [-> CC_TITLE_JKKHAKKOSODCC="JKKHakkoSODCC" (JBSbatKKBndWdtOvrSendMl.java:100)] |
| LF | Constant | Line delimiter `"LF"` — line feed character used as record separator in output files [-> LF="LF" (JBSbatKKBndWdtOvrSendMl.java:121)] |
| SJIS | Constant | `"Shift-JIS"` — Japanese character encoding standard for file output [-> SJIS="Shift-JIS" (JKKBatConst.java:47)] |
| FTTH | Business term | Fiber To The Home — fiber-optic broadband internet service provided by K-Opticom |
| SOD | Acronym | Service Order Data / Service Order Document — order issuance document for telecom service changes |
| CC | Acronym | Common Component — shared reusable service component layer (e.g., JKKHakkoSODCC for service order issuance) |
| ESCB | Acronym | ESB (Enterprise Service Bus) Interface — the service interface layer for inter-system communication |
| `svc_kei_no` | Field | Service contract number — unique identifier for a customer's service contract |
| `sysid` | Field | System ID — identifies the originating system in inter-system communication |
| `keiShaNm` | Field | Customer name — the contracted customer's name (KEISHA = customer/contractor) |
| `mlad` | Field | Mail address — the customer's email address for notification delivery |
| `tchiTshiryo` | Field | Communication volume — the amount of data usage that triggered the overuse notification (TIKI = bandwidth control, SHIRYO = volume) |
| `sendKbn` | Field | Send classification — distinguishes between warning notification (`"1"`) and actual enforcement notification (`"2"`) |
| `opeDate` | Field | Operation date — batch execution date in YYYYMMDD format (inherited from parent) |
| Bandwidth-Controlled Communication Volume Overuse | Business term | A threshold breach event where a customer's data usage exceeds their carrier-mandated data cap, triggering automated notification |
| JBSbatBusinessService | Class | Abstract batch base service class — provides common batch lifecycle methods including `setCommonInfo()`, `execute()`, and framework hooks |
| JBSbatSQLAccess | Class | Database SQL access wrapper — creates parameterized access layers for specific database tables |
| JBSbatOutputFileUtil | Class | Output file writer utility — manages file output with configurable encoding and line delimiters |
