# Business Logic — JBSbatKKKjhKapZnskIktSikyAdchg.execute() [61 LOC]

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

## 1. Role

### JBSbatKKKjhKapZnskIktSikyAdchg.execute()

This method is the main entry point for the **Work Fee Deduction Contract Balance Unified Request (Apartment Relocation) Batch** (`工事費割賦契約残債一括請求（住所変更）バッチ`). It is a batch service that reads a target CSV file line by line, validates each record against apartment status and balance data, registers work fee deduction contract information, and conditionally applies standard service fee balance reductions (CP discount) while registering progress records. The batch implements a sequential file-processing pattern: for each input record it performs apartment type judgment, balance validation, work fee registration, discount eligibility determination, and conditional discount data registration. Its role in the larger system is to process apartment relocation requests that include work fee deduction contracts, ensuring that outstanding balances are unified and eligible CP discounts are applied before recording the batch progress.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["execute()"])
    START --> CHECK_FILE["Check File Ready"]

    CHECK_FILE -->|true| READ_RECORD["Read File Record"]
    READ_RECORD --> SPLIT_RECORD["Split Record by Delimiter"]
    SPLIT_RECORD --> EXTRACT_SVC_NO["Extract First Request Service Contract Number cols[3]"]

    EXTRACT_SVC_NO --> CHECK_MANSION{"jdgMansion(cols)"}
    CHECK_MANSION -->|null - Not Apartment| CONTINUE["Continue to Next Record"]
    CHECK_MANSION -->|not null - Is Apartment| CHECK_BALANCE["jdgZnskIktSiky(cols)"]

    CONTINUE --> CHECK_FILE

    CHECK_BALANCE --> HAS_BALANCE{"znskIktSiky is null?"}
    HAS_BALANCE -->|null - No Balance Info| CONTINUE

    HAS_BALANCE -->|not null - Has Balance Info| SEARCH_KOJIHI["excSearchKojihiKapKei(cols)"]
    SEARCH_KOJIHI --> REG_KOJIHI["addKojihiKapKei(excSearchList)"]

    REG_KOJIHI --> CHECK_GENGAKU["jdgAplyStdardKjhZnskGengaku(znskIktSiky, firstSeikySvcKeiNo)"]
    CHECK_GENGAKU --> GENGAKU_RESULT{"gengakuTgFlg"}

    GENGAKU_RESULT -->|true - Discount Applicable| ADD_WRIB["addWrib(wribPrgAddData, firstSeikySvcKeiNo)"]
    GENGAKU_RESULT -->|false - Discount Not Applicable| ADD_PRG
    ADD_WRIB --> ADD_PRG["addPrg(wribPrgAddData, firstSeikySvcKeiNo, excSearchList)"]

    ADD_PRG --> CHECK_FILE
    CHECK_FILE -->|false| RETURN_END(["Return null"])
```

**Processing Summary:**

| Step | Description |
|------|-------------|
| 1 | Open and iterate over input target file (`adchgZnskIktSikyTgFileObj`) using `ready()` loop |
| 2 | Read each record and split by configured delimiter to extract columns |
| 3 | Extract `firstSeikySvcKeiNo` (First Request Service Contract Number) from `cols[3]` |
| 4 | Call `jdgMansion(cols)` — apartment type judgment; skip record if not an apartment |
| 5 | Call `jdgZnskIktSiky(cols)` — retrieve balance unified request info; skip if null |
| 6 | Call `excSearchKojihiKapKei(cols)` — search for existing work fee deduction contract |
| 7 | Call `addKojihiKapKei(excSearchList)` — register/update work fee deduction contract |
| 8 | Call `jdgAplyStdardKjhZnskGengaku(znskIktSiky, firstSeikySvcKeiNo)` — determine if standard service fee balance reduction (CP discount) is applicable |
| 9.1 | If `gengakuTgFlg == true`: call `getWribPrgData(znskIktSiky)` to retrieve discount data, then call `addWrib()` to register discount service contract data |
| 9.2 | Regardless: call `addPrg(wribPrgAddData, firstSeikySvcKeiNo, excSearchList)` — register progress record |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This is a no-argument method. Configuration and file paths are resolved from instance fields set by the batch framework. |

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

| Field | Type | Business Description |
|-------|------|---------------------|
| `adchgZnskIktSikyTgFileObj` | `JBSbatInputFileUtil` | Input file handle for the apartment relocation service target file — provides `ready()` and `readLine()` to iterate over CSV records |
| `adchgZnskIktSikyTgFileDefObj` | File definition object | Holds the delimiter configuration used to split CSV records |
| `jbsbatKKSvcKeiObj` | `JBSbatKK_T_SVC_KEI` | Entity mapper for the Service Contract table (`KK_T_SVC_KEI`) |
| `jbsbatKKZnskIktSikyObj` | `JBSbatCommonDBInterface` | Interface for accessing balance unified request data from service contract records |
| `jbsbatKKConst` | `JBSbatKKConst` | Batch constant holder with service contract codes and configuration values |
| `jccBatCommon` | `JCCBatCommon` | Common batch utility providing shared helper methods |
| `jbsbatSQLAccess` | `JBSbatSQLAccess` | SQL execution interface for database queries and updates |
| `jbsbatKKSvcKeiAddObj` | `JBSbatKK_T_SVC_KEI` | Entity mapper for inserting/updating service contract records |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JBSbatInputFileUtil.readLine` | - | - (input file) | Reads a single CSV record line from the apartment relocation target file |
| R | `JBSbatInputFileUtil.ready` | - | - (input file) | Checks if another record is available in the input file |
| - | `String.split` | - | - | Splits the CSV record string by delimiter into column array |
| C | `JBSbatKKKjhKapZnskIktSikyAdchg.jdgMansion` | JBSbatKKKjhKapZnskIktSikyAdchg | KK_T_MANSION_BUKKEN | Queries apartment building records to determine if the record's address matches an apartment property |
| R | `JBSbatKKKjhKapZnskIktSikyAdchg.jdgZnskIktSiky` | JBSbatKKKjhKapZnskIktSikyAdchg | KK_T_SVC_KEI | Retrieves outstanding balance unified request information from service contract records |
| R | `JBSbatKKKjhKapZnskIktSikyAdchg.excSearchKojihiKapKei` | JBSbatKKKjhKapZnskIktSikyAdchg | KK_T_KOJIHI_KAP_KEI, KU_T_KOJIAK, KK_T_ADCHG_DTL | Searches for existing work fee deduction contract and related project and relocation detail records |
| C | `JBSbatKKKjhKapZnskIktSikyAdchg.addKojihiKapKei` | JBSbatKKKjhKapZnskIktSikyAdchg | KK_T_KOJIHI_KAP_KEI | Registers or updates work fee deduction contract record |
| R | `JBSbatKKKjhKapZnskIktSikyAdchg.jdgAplyStdardKjhZnskGengaku` | JBSbatKKKjhKapZnskIktSikyAdchg | - (in-memory) | Evaluates whether the standard service fee balance reduction (CP discount) conditions are met based on balance data and service contract number |
| R | `JBSbatKKKjhKapZnskIktSikyAdchg.getWribPrgData` | JBSbatKKKjhKapZnskIktSikyAdchg | - (in-memory) | Transforms balance data into discount registration data structure |
| C | `JBSbatKKKjhKapZnskIktSikyAdchg.addWrib` | JBSbatKKKjhKapZnskIktSikyAdchg | KK_T_WRIB_SVC_KEI, KK_T_WRISVC_TG_KEI, KK_T_WRISVC_KEI_UCWK | Registers discount service contract data (discount target contract, contract details, and discount service info) |
| C | `JBSbatKKKjhKapZnskIktSikyAdchg.addPrg` | JBSbatKKKjhKapZnskIktSikyAdchg | - (progress records) | Registers progress/batch execution record with discount and contract search data |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Batch: JBSbatKKKjhKapZnskIktSikyAdchg | Batch framework -> execute() [this method] | jdgMansion [R] KK_T_MANSION_BUKKEN; jdgZnskIktSiky [R] KK_T_SVC_KEI; excSearchKojihiKapKei [R] KK_T_KOJIHI_KAP_KEI, KU_T_KOJIAK, KK_T_ADCHG_DTL; addKojihiKapKei [C] KK_T_KOJIHI_KAP_KEI; addWrib [C] KK_T_WRIB_SVC_KEI, KK_T_WRISVC_TG_KEI, KK_T_WRISVC_KEI_UCWK; addPrg [C] progress records |

## 6. Per-Branch Detail Blocks

**Block 1** — [WHILE LOOP] `(adchgZnskIktSikyTgFileObj.ready())` (L248)

> Read records from input file until EOF. For each record, process the apartment relocation balance request.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `dataLine = adchgZnskIktSikyTgFileObj.readLine();` // Read file record (ファイルレコード取得) |
| 2 | SET | `String[] cols = dataLine.split(adchgZnskIktSikyTgFileDefObj.getDelimiter(), -1);` // Split record by delimiter (定義ファイルに設定された区切り文字で分割) |
| 3 | SET | `String firstSeikySvcKeiNo = cols[3];` // First request service contract number (初回請求サービス契約番号) |

**Block 1.1** — [IF CONDITION] `(null == jdgMansion(cols))` (L255)

> Call `jdgMansion` to determine if the record's address corresponds to an apartment property. If `null` is returned, the record is not an apartment and should be skipped. (マンション判定処理対象外の場合、次のレコードへ処理を移す)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `jdgMansion(cols)` // Apartment type judgment — queries KK_T_MANSION_BUKKEN table |
| 2 | RETURN | `continue;` // Skip to next record (次のレコードへ処理を移す) |

**Block 2** — [IF CONDITION] `(null == znskIktSiky)` (L265)

> After confirming the record is an apartment, retrieve the balance unified request info. If null, no balance data exists and the record should be skipped. (残債一括請求情報がnullの場合、次のレコードへ処理を移す)

| # | Type | Code |
|---|------|------|
| 1 | SET | `HashMap<String, JBSbatCommonDBInterface> znskIktSiky = jdgZnskIktSiky(cols);` // Retrieve balance unified request info from KK_T_SVC_KEI (残債一括請求情報を取得) |
| 2 | RETURN | `continue;` // Skip to next record (次のレコードへ処理を移す) |

**Block 3** — [PROCESSING STEP] No condition (L270–L273)

> Search for existing work fee deduction contract records and register/update them. (工事費割賦契約登録処理)

| # | Type | Code |
|---|------|------|
| 1 | SET | `JBSbatCommonDBInterface excSearchList = excSearchKojihiKapKei(cols);` // Search for work fee deduction contract; queries KK_T_KOJIHI_KAP_KEI, KU_T_KOJIAK, KK_T_ADCHG_DTL (工事費割賦契約に排除検索をかける) |
| 2 | CALL | `addKojihiKapKei(excSearchList);` // Register/update work fee deduction contract in KK_T_KOJIHI_KAP_KEI (工事費割賦契約登録処理) |

**Block 4** — [PROCESSING STEP] No condition (L276–L279)

> Determine if the standard service fee balance reduction (CP discount) applies, and retrieve discount registration data. (標準工事費残債減額の適用判定)

| # | Type | Code |
|---|------|------|
| 1 | SET | `boolean gengakuTgFlg = jdgAplyStdardKjhZnskGengaku(znskIktSiky, firstSeikySvcKeiNo);` // Discount applicability flag — evaluates CP discount eligibility based on balance data (標準工事費残債減額の適用判定) |
| 2 | SET | `JBSbatCommonDBInterface wribPrgAddData = getWribPrgData(znskIktSiky);` // Transform balance data to discount registration data (割引サービス契約、進捗に登録するための申込明細番号、異動区分を取得する) |

**Block 4.1** — [IF CONDITION] `(gengakuTgFlg)` (L282)

> If the discount is applicable, register the discount service contract data. (割引データ登録)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `addWrib(wribPrgAddData, firstSeikySvcKeiNo);` // Register discount data in KK_T_WRIB_SVC_KEI, KK_T_WRISVC_TG_KEI, KK_T_WRISVC_KEI_UCWK (割引データ登録) |

**Block 5** — [PROCESSING STEP] No condition (L287–L288)

> Register the batch progress record. This was modified in ANK-3951-10-00 to pass `excSearchList` as an additional parameter. (進捗登録)

| # | Type | Code |
|---|------|------|
| 1 | CALL | `addPrg(wribPrgAddData, firstSeikySvcKeiNo, excSearchList);` // Register progress record (ANK-3951-10-00: passed excSearchList as 3rd arg) (進捗登録) |

**Block 6** — [LOOP END] (L294)

> Loop back to check if more records are available in the input file.

**Block 7** — [RETURN] (L296)

> Return null to indicate batch processing is complete. (業務サービス主処理)

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return null;` // Batch complete (業務サービス主処理) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `adchg` | Abbreviation | Apartment Relocation (住所変更) — customer relocation due to moving to a different address |
| `kjh` | Abbreviation | Work Fee (工事費) — construction/installation fees charged to customers for service setup |
| `kap` | Abbreviation | Deduction/Allocation (割賦) — installment-based fee allocation or deduction |
| `znsk` | Abbreviation | Balance Unified Request (残債一括請求) — unified request for outstanding contract balances |
| `iktSiky` | Abbreviation | Execution/Implementation (実行仕訳) — batch execution journal entry |
| `kojihi` | Field | Work Fee (工事費) — charges for construction/installation work |
| `kapKei` | Field | Deduction Contract (割賦契約) — installment deduction contract for work fees |
| `gengaku` | Field | Reduction/Discount (減額) — price reduction, specifically CP (Customer Discount) discount |
| `wrib` | Abbreviation | Discount (割引) — price discount applied to service contracts |
| `firstSeikySvcKeiNo` | Field | First Request Service Contract Number (初回請求サービス契約番号) — the original service contract number from which billing originated |
| `znskIktSiky` | Field | Balance Unified Request Execution Info (残債一括請求実行情報) — HashMap containing balance data for unified billing |
| `gengakuTgFlg` | Field | Discount Target Flag (減額対象フラグ) — boolean indicating whether standard service fee balance reduction applies |
| `jdgMansion` | Method | Apartment Judgment (マンション判定) — determines if a record's address corresponds to an apartment building |
| `jdgZnskIktSiky` | Method | Balance Execution Judgment (残債実行判定) — retrieves and validates outstanding balance unified request data |
| `excSearchKojihiKapKei` | Method | Work Fee Deduction Contract Search (工事費割賦契約排除検索) — searches for existing work fee deduction contract records |
| `addKojihiKapKei` | Method | Register Work Fee Deduction Contract (工事費割賦契約登録) — inserts or updates work fee deduction contract |
| `jdgAplyStdardKjhZnskGengaku` | Method | Standard Service Fee Balance Reduction Applicability Judgment (標準工事費残債減額適用判定) — evaluates CP discount eligibility |
| `addWrib` | Method | Register Discount (割引登録) — registers discount service contract data including target contract and discount details |
| `addPrg` | Method | Register Progress (進捗登録) — records batch execution progress for audit and tracking |
| `KK_T_MANSION_BUKKEN` | Table | Apartment Building Records (マンション物件) — master table of apartment buildings and their properties |
| `KK_T_KOJIHI_KAP_KEI` | Table | Work Fee Deduction Contract (工事費割賦契約) — contract records for installment-based work fee deduction |
| `KK_T_SVC_KEI` | Table | Service Contract (サービス契約) — master table of all active service contracts |
| `KK_T_WRIB_SVC_KEI` | Table | Discount Service Contract (割引サービス契約) — discount contract records |
| `KK_T_WRISVC_TG_KEI` | Table | Discount Service Target Contract (割引サービス対象契約) — contracts targeted for discount application |
| `KK_T_WRISVC_KEI_UCWK` | Table | Discount Service Contract Details (割引サービス契約内訳) — detailed breakdown of discount service contracts |
| `KK_T_ADCHG_DTL` | Table | Apartment Relocation Details (住所変更明細) — details of apartment relocation requests |
| `KU_T_KOJIAK` | Table | Project Accounts (工事案件) — project/account records related to construction work |
| CP Discount | Business term | Customer Discount — a standard service fee balance reduction applied under certain conditions to promote customer retention |
| Batch (バッチ) | Business term | Overnight batch processing job — processes accumulated data in bulk, typically during off-hours |
| `D_TBL_NAME_KK_T_MANSION_BUKKEN` | Constant | Table name for apartment building master data (マンション物件テーブル) |
| `D_TBL_NAME_KK_T_KOJIHI_KAP_KEI` | Constant | Table name for work fee deduction contract data (工事費割賦契約テーブル) |
