# Business Logic — JBSbatKKBndWdtOvrSendMl.execute() [110 LOC]

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

## 1. Role

### JBSbatKKBndWdtOvrSendMl.execute()

This method is the main processing entry point of the **Bandwidth Limit Overflow Notification Mail Creation Component** (`帯域制御通信量超過通知メール作成部品`) in the K-Opticom customer core system. It orchestrates the notification workflow when a customer's usage exceeds their allocated bandwidth limit on FTTH (Fiber To The Home) service lines. The method first validates the input data (service contract number, customer name, email address, etc.), then determines the notification type — warning (`SEND_KBN_YOKOKU = "1"`) or implementation/actual execution (`SEND_KBN_JISHI = "2"`) — and routes accordingly. For implementation notifications (excluding the first day of the month per requirement OM-2015-0000836), it invokes an SOD (Service Order Data) execution service to trigger the bandwidth limit enforcement. Regardless of notification type, it updates the FTTH communication volume overflow record and, for both warning and implementation notifications, creates a mail sending record via the `insertTMailSend` method and returns the output file information. The method follows a **delegation and routing pattern**, using the `sendKbn` field to dispatch between parallel processing branches, and acts as a shared batch service component called by the KKSV0571 screen.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execute(inMap)"])

    START --> CHECK_SINGLE["isSingleCheckKKIFM207_INF1()"]

    CHECK_SINGLE --> FAIL_CHECK{"Check Pass?"}
    FAIL_CHECK -->|No| SET_ERR["super.commonItem.setErrFlg(true)"]
    SET_ERR --> RET_NULL_1["return null"]

    FAIL_CHECK -->|Yes| GET_SYS_DTM["JCCBatCommon.getSysDateTimeStamp()"]

    GET_SYS_DTM --> PARSE_DATE["Parse opeDate to year/month/day"]

    PARSE_DATE --> EXTRACT_FIELDS["Extract fields from inMap: svcKeiNo, sysId, keiShaNm, mlad, tchiTshiryo, sendKbn"]

    EXTRACT_FIELDS --> CHECK_SEND_KBN{"sendKbn == SEND_KBN_JISHI"}

    CHECK_SEND_KBN -->|No| SKIP_SOD["Skip SOD execution"]

    CHECK_SEND_KBN -->|Yes| JAN_1_CHECK{"opeDateDay == 01?"}
    JAN_1_CHECK -->|Yes| SKIP_SOD

    JAN_1_CHECK -->|No| BUILD_SOD_INPUT["Build inputMap with svcKeiNo, sysId"]

    BUILD_SOD_INPUT --> SET_SOD["setSodParam(svcKeiNo, sysId, inputMap)"]

    SET_SOD --> BUILD_PARAM["Build paramMap with USECASE_ID_KKSV0571"]

    BUILD_PARAM --> INVOKE_SVC["JCCBatchEsbInterface.invokeService()"]

    INVOKE_SVC --> CHECK_RETURN["Get returnCode from outputMap"]

    CHECK_RETURN --> RETURN_OK{"returnCode == RETURN_CODE_SUCCESS?"}
    RETURN_OK -->|No| LOG_ERR["logPrint.printBusinessErrorLog(EKKB0010CW)"]
    RETURN_OK -->|Yes| LOG_SOD_OK["printDebugLog: SOD execution completed"]

    LOG_ERR --> LOG_SOD_OK

    SKIP_SOD --> UPDATE_TS["updateFtthTsrckJsk(svcKeiNo, sendKbn)"]
    LOG_SOD_OK --> UPDATE_TS

    UPDATE_TS --> CHECK_FINAL_SEND{"sendKbn == YOKOKU OR JISHI?"}

    CHECK_FINAL_SEND -->|Yes| CREATE_OUTPUT["new JBSbatOutputItem()"]

    CREATE_OUTPUT --> INSERT_MAIL["insertTMailSend(...)"]

    INSERT_MAIL --> INC_COUNT["BndWdtOvrTchiCount++"]

    INC_COUNT --> RET_OUTPUT["return outputItem"]

    CHECK_FINAL_SEND -->|No| RET_NULL_2["return null"]
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `inMap` | `JBSbatServiceInterfaceMap` | Input message (入力電文) carrying the notification target customer data. It contains the service contract number (`SVC_KEI_NO`), SYSID (`SYSID`), customer name (`KEISHA_NM`), email address (`MLAD`), bandwidth limit notification communication volume (`TIKI_SGN_TCHI_TSHIRYO`), and send classification (`SEND_KBN`) which determines whether the notification is a warning (`"1"`) or actual implementation (`"2"`). |

**Inherited/Instance Fields Used:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `super.opeDate` | `String` | Batch operation date in `yyyyMMdd` format (e.g. `20150422`), extracted into year, month, day components. |
| `super.commonItem` | `JBSbatCommonItem` | Common batch item holding error flag, log printer, and shared state. |
| `BndWdtOvrTchiCount` | `int` | Counter tracking the number of bandwidth limit overflow notifications generated, incremented per processed record. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCBatCommon.getSysDateTimeStamp` | JCCBatCommon | - | Gets the current system date-time stamp as a string. |
| EXEC | `isSingleCheckKKIFM207_INF1` | JBSbatKKBndWdtOvrSendMl (local) | - | Performs item-level validation on input data (non-null checks and digit-length checks for SVC_KEI_NO, SYSID, KEISHA_NM, MLAD, TIKI_SGN_TCHI_TSHIRYO, SEND_KBN). Returns false if any validation fails. |
| EXEC | `getItemvalueMap` | JBSbatKKBndWdtOvrSendMl (local) | - | Returns the hardcoded error message value map used as parameter values in validation error logging. |
| C | `setSodParam` | JBSbatKKBndWdtOvrSendMl (local) | - | Constructs SOD (Service Order Data) parameter structure including basic info (SYSID, processing division `011`), and service contract info (SVC_KEI_NO) for bandwidth limit enforcement. |
| C | `JCCBatchEsbInterface.invokeService` | JCCBatchEsbInterface | - | Invokes the SOD execution service with use case ID `KKSV0571` (bandwidth limit enforcement). Triggers the actual bandwidth limit enforcement business logic in the service layer. |
| R | `JCCBatchEsbInterface.getReturnCode` | JCCBatchEsbInterface | - | Extracts the return code from the service output map. `"0"` indicates success; any other value indicates a service-level error. |
| U | `updateFtthTsrckJsk` | JBSbatKKBndWdtOvrSendMl (local) | `KK_T_FTTH_TSRCK_JSK` | Updates the FTTH communication volume overflow record (FTTH通信量超過実績) for the given service contract number and send classification. Internally uses SQLKEY `KK_SELECT_006` for selective update. |
| C | `insertTMailSend` | JBSbatKKBndWdtOvrSendMl (local) | `CC_M_MAIL`, `ZM_M_TCHI_MAIL_SENDS` | Registers the notification mail record. Queries mail master table (`CC_M_MAIL`) via SQLKEY `KK_SELECT_004` to retrieve mail template information based on send classification (warning = `"02"`), then prepares mail sending data with customer name, email, operation date, and notification details. |
| - | `logPrint.printBusinessErrorLog` | JBSbatCommonItem.LogPrint | - | Logs business-level error when SOD service returns a non-success return code. Error code `EKKB0010CW` with context message including the return code. |
| - | `commonItem.getLogPrint().printDebugLog` | JBSbatCommonItem.LogPrint | - | Logs debug message confirming SOD execution completion with the service contract number. |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen:KKSV0571 | `KKSV0571.invokeService` -> `JCCBatchEsbInterface.invokeService` -> `JBSbatKKBndWdtOvrSendMl.execute` | `updateFtthTsrckJsk [U] KK_T_FTTH_TSRCK_JSK`, `insertTMailSend [C] CC_M_MAIL/ZM_M_TCHI_MAIL_SENDS`, `invokeService [C] SOD Bandwidth Limit Enforcement` |

## 6. Per-Branch Detail Blocks

**Block 1** — IF (input validation check) (L213)

> Validates input data integrity using `isSingleCheckKKIFM207_INF1`. If any required field is null, empty, or has an invalid digit count (0-10 digits for SVC_KEI_NO and SYSID), an error is logged and processing halts.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `isSingleCheckKKIFM207_INF1(inMap.getMap(), getItemvalueMap())` // Input validation check [-> CHECK_SINGLE] |
| 2 | SET | `super.commonItem.setErrFlg(true)` // Set error flag [-> Error flag set to true] |
| 3 | RETURN | `return null` // Return null to indicate failure |

**Block 2** — PROCESSING (system date and field extraction) (L218)

> After successful validation, obtains the system date-time stamp and extracts all required notification target fields from the input message. The operation date is parsed into year, month, and day components from the `super.opeDate` field (format: `yyyyMMdd`).

| # | Type | Code |
|---|------|------|
| 1 | SET | `sysDateTime = JCCBatCommon.getSysDateTimeStamp()` // System date-time [-> JCCBatCommon.getSysDateTimeStamp()] |
| 2 | SET | `opeDateYear = super.opeDate.substring(0,4)` // Operation date year [-> opeDate substring 0-4] |
| 3 | SET | `opeDateMonth = super.opeDate.substring(4,6)` // Operation date month [-> opeDate substring 4-6] |
| 4 | SET | `opeDateDay = super.opeDate.substring(6,8)` // Operation date day [-> opeDate substring 6-8] |
| 5 | SET | `svcKeiNo = inMap.getString(JBSbatKKIFM207.SVC_KEI_NO)` // Service contract number [-> JBSbatKKIFM207.SVC_KEI_NO] |
| 6 | SET | `sysId = inMap.getString(JBSbatKKIFM207.SYSID)` // System ID [-> JBSbatKKIFM207.SYSID] |
| 7 | SET | `keiShaNm = inMap.getString(JBSbatKKIFM207.KEISHA_NM)` // Customer name [-> JBSbatKKIFM207.KEISHA_NM] |
| 8 | SET | `mlad = inMap.getString(JBSbatKKIFM207.MLAD)` // Email address [-> JBSbatKKIFM207.MLAD] |
| 9 | SET | `tchiTshiryo = inMap.getString(JBSbatKKIFM207.TIKI_SGN_TCHI_TSHIRYO)` // Bandwidth limit notification communication volume [-> JBSbatKKIFM207.TIKI_SGN_TCHI_TSHIRYO] |
| 10 | SET | `sendKbn = inMap.getString(JBSbatKKIFM207.SEND_KBN)` // Send classification (1=warning, 2=implementation) [-> JBSbatKKIFM207.SEND_KBN] |

**Block 3** — IF (SOD execution for bandwidth limit enforcement) (L241)

> Conditional SOD (Service Order Data) execution. Only triggered when `sendKbn == SEND_KBN_JISHI ("2")` (actual implementation notification) AND the operation day is NOT `"01"` (first day of the month, per requirement OM-2015-0000836 which excludes bandwidth limit enforcement on the 1st to avoid conflicts with monthly cycle processing).

| # | Type | Code |
|---|------|------|
| 1 | CALL | `SEND_KBN_JISHI.equals(sendKbn) && !"01".equals(opeDateDay)` // Send classification is implementation AND not first day of month [-> SEND_KBN_JISHI="2" (L98) and !"01" equals opeDateDay] |
| 2 | SET | `inputMap = new HashMap<String, Object>()` // Create input map for SOD execution |
| 3 | EXEC | `inputMap.put("svc_kei_no", svcKeiNo)` // Set service contract number [-> svc_kei_no] |
| 4 | EXEC | `inputMap.put("sysid", sysId)` // Set SYSID [-> sysid] |
| 5 | CALL | `setSodParam(svcKeiNo, sysId, inputMap)` // Configure SOD parameters [-> setSodParam(L645)] |
| 6 | SET | `paramMap = new HashMap<String, Object>()` // Create parameter map for service invocation |
| 7 | EXEC | `paramMap.put(JCCBatchEsbInterface.TELEGRAM_INFO_USECASE_ID, USECASE_ID_KKSV0571)` // Set use case ID to KKSV0571 [-> USECASE_ID_KKSV0571="KKSV0571" (L107)] |
| 8 | SET | `outputMap = new HashMap<String, Object>()` // Create output map to receive service result |
| 9 | CALL | `JCCBatchEsbInterface.invokeService(super.commonItem, paramMap, inputMap, outputMap)` // Invoke SOD execution service [-> JCCBatchEsbInterface.invokeService()] |
| 10 | SET | `returnCode = JCCBatchEsbInterface.getReturnCode(outputMap)` // Get return code [-> JCCBatchEsbInterface.getReturnCode()] |

**Block 3.1** — IF (SOD service error handling) (L267)

> Checks whether the SOD execution service returned a non-success return code. If the return code is NOT `"0"` (`RETURN_CODE_SUCCESS`), a business error log is written with error code `EKKB0010CW` containing the actual return code.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `!RETURN_CODE_SUCCESS.equals(returnCode)` // Check if return code is non-success [-> RETURN_CODE_SUCCESS="0" (L110)] |
| 2 | SET | `err_msg = new StringBuffer()` // Create error message buffer |
| 3 | EXEC | `err_msg.append("ステータスコード ：" + returnCode)` // Append status code [-> "Status code"] |
| 4 | CALL | `logPrint.printBusinessErrorLog("EKKB0010CW", new String[]{ err_msg.toString() })` // Log business error [-> Error code EKKB0010CW] |

**Block 3.2** — PROCESSING (SOD execution debug log) (L275)

> Regardless of success or error, a debug log message is printed confirming that the bandwidth limit enforcement SOD was executed for the service contract.

| # | Type | Code |
|---|------|------|
| 1 | SET | `sb = new StringBuilder()` // Create string builder |
| 2 | EXEC | `sb.append("サービス契約番号:").append(svcKeiNo).append("の帯域制御実施SODを発行しました。")` // Build debug message [-> "Executed bandwidth limit enforcement SOD for service contract:"] |
| 3 | CALL | `commonItem.getLogPrint().printDebugLog(sb.toString())` // Print debug log |

**Block 4** — PROCESSING (FTTH communication volume overflow record update) (L280)

> Updates the FTTH communication volume overflow record (`KK_T_FTTH_TSRCK_JSK`) for the service contract. This is performed unconditionally for all valid input records, regardless of send classification.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `updateFtthTsrckJsk(svcKeiNo, sendKbn)` // Update FTTH overflow record [-> updateFtthTsrckJsk()] |

**Block 5** — IF (mail sending record creation) (L288)

> Determines whether to create a mail sending record. This block is active when `sendKbn` is either `"1"` (warning notification) or `"2"` (implementation notification), as per the 2014/02/19 ANK-1876-00-00 modification that changed the notification method from mail print format to mail transmission.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `SEND_KBN_YOKOKU.equals(sendKbn) || SEND_KBN_JISHI.equals(sendKbn)` // Check send classification [-> SEND_KBN_YOKOKU="1" (L95) or SEND_KBN_JISHI="2" (L98)] |
| 2 | SET | `outputItem = new JBSbatOutputItem()` // Create output file info [-> create output file info] |
| 3 | CALL | `insertTMailSend(sysDateTime, sendKbn, mlad, keiShaNm, opeDateYear, opeDateMonth, opeDateDay, tchiTshiryo, svcKeiNo, outputItem)` // Register mail sending record [-> insertTMailSend()] |
| 4 | SET | `BndWdtOvrTchiCount++` // Increment notification count [-> Bandwidth limit overflow notification count++] |
| 5 | RETURN | `return outputItem` // Return output file information [-> Return output file info] |

**Block 6** — ELSE (no mail record created) (L300)

> When send classification is neither warning nor implementation, no mail sending record is created and null is returned.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return null` // Return null [-> Return null] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `svc_kei_no` | Field | Service Contract Number — unique identifier for a customer's service contract line in the K-Opticom system. |
| `sysid` | Field | System ID — identifies the specific system or application instance in the K-Opticom architecture. |
| `kei_shaNm` | Field | Customer Name — the name of the contracting customer (契約者氏名) being notified of bandwidth limit. |
| `mlad` | Field | Mail Address — the email address to which the bandwidth limit overflow notification is sent. |
| `tchi_tshiryo` | Field | Bandwidth Limit Notification Communication Volume (帯域制御通知通信量) — the actual usage amount that exceeded the customer's allocated bandwidth limit. |
| `send_kbn` | Field | Send Classification (送信区分) — determines the type of notification: `"1"` for warning notice (警告通知) or `"2"` for actual implementation notice (実施通知). |
| `opeDate` | Field | Operation Date (運転日) — the batch processing date in `yyyyMMdd` format, used for date-based filtering (e.g., excluding the 1st of the month for SOD execution). |
| `sod` | Acronym | Service Order Data (サービスオーダデータ) — the telecom order fulfillment entity that carries service activation, modification, and deactivation orders through the system. |
| `bandwidth limit` | Business term | Bandwidth control / bandwidth limit enforcement (帯域制御) — the process of restricting a customer's internet speed when their usage exceeds the allocated contract limit. |
| `SOD execution` | Business term | SOD issuance/execution (SOD発行) — the process of invoking the service order data workflow to enforce bandwidth limits on customer lines. |
| `KKSV0571` | Business term | Use Case ID for bandwidth limit enforcement (帯域制限実施) — the specific service use case invoked via the ESB interface to perform bandwidth limit enforcement on FTTH lines. |
| `KK_T_SVC_KEI` | DB Table | Service Contract table (サービス契約) — stores master data for service contracts. |
| `KK_T_SVC_KEI_UCWK` | DB Table | Service Contract Details table (サービス契約内訳) — stores detailed line-by-line breakdown of service contracts. |
| `KK_T_OP_SVC_KEI` | DB Table | Option Service Contract table (オプションサービス契約) — stores option service contract data. |
| `KK_T_FTTH_TSRCK_JSK` | DB Table | FTTH Communication Volume Overflow Record (FTTH通信量超過実績) — stores records of when FTTH customers exceeded their communication volume limits. |
| `CC_M_MAIL` | DB Table | Mail Master table (メールマスター) — stores mail template configuration including mail codes for different notification types. |
| `ZM_M_TCHI_MAIL_SENDS` | DB Table | Bandwidth Limit Notification Mail Sends master (帯域制御通知メール送信マスター) — tracks mail sending status for bandwidth limit notifications. |
| `MAIL_CD_YKK` | Constant | Warning Mail Code (警告用メールコード) — `"KKM1000007"`, the mail template code for warning notifications. |
| `MAIL_CD_JSHI` | Constant | Implementation Mail Code (実施用メールコード) — `"KKM1000008"`, the mail template code for actual implementation notifications. |
| `MAIL_SEND_PATTERN_CD_02` | Constant | Mail Send Pattern Code (メール送信パターンコード) — `"02"`, used to query the mail master for the appropriate mail template. |
| `SYORI_DIV_011` | Constant | Processing Division Code (処理区分) — `"011"`, identifies the bandwidth limit enforcement processing type in SOD data. |
| `CC_TITLE_JKKHAKKOSODCC` | Constant | CC Title for Service Order Issuance (CCタイトル サービスオーダ発行) — `"JKKHakkoSODCC"`, the service component title key for SOD execution. |
| `RETURN_CODE_SUCCESS` | Constant | Service IF Return Code (Service IFのリターンコード) — `"0"`, indicates successful service execution. |
| `FUNC_CODE` | Constant | Function Code (機能コード) — `"1"`, set in the data map to identify the SOD function type as issuance. |
| `USECASE_ID_KKSV0571` | Constant | User Case ID for Bandwidth Limit Enforcement — `"KKSV0571"`, the specific use case invoked via ESB. |
| `LF` | Constant | Line Feed character (改行コード) — `"LF"`, used as the line separator in output files. |
| `EKKB0010CW` | Error Code | Business Error — SOD service returned an abnormal return code. |
| `EKKB0060TE` | Error Code | Validation Error — required field is null or empty. |
| `EKKB0070TE` | Error Code | Validation Error — field digit count is out of range. |
| `EKKB0150JE` | Error Code | Mail Master Error — mail template data not found in `CC_M_MAIL` table. |
| `KK_SELECT_006` | SQL Key | SQL Definition Key for updating `KK_T_FTTH_TSRCK_JSK` record. |
| `KK_SELECT_004` | SQL Key | SQL Definition Key for querying mail master `CC_M_MAIL`. |
| `KK_SELECT_069` | SQL Key | SQL Definition Key for querying `KK_T_SVC_KEI_UCWK`. |
| `KK_SELECT_054` | SQL Key | SQL Definition Key for querying `KK_T_OP_SVC_KEI`. |
| `KK_SELECT_180` | SQL Key | SQL Definition Key for querying `KK_T_SVC_KEI`. |
| Bandwidth Limit Overflow Notification (帯域制御通信量超過通知) | Business process | The overall workflow of notifying customers when their FTTH usage exceeds allocated limits, including warning and implementation stages. |
| Mail Print Format -> Mail Transmission (メールプリントフォームから送信) | Historical change | Version 8.00 (2014/02/19, ANK-1876-00-00) changed the notification method from generating print-format mail files to actually transmitting emails via the mail sending system. |
