# Business Logic — JBSbatKKKjhKapZnskIktSikyAdchg.addWribSvcKei() [160 LOC]

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

## 1. Role

### JBSbatKKKjhKapZnskIktSikyAdchg.addWribSvcKei()

This method registers a new discount service contract line (`T_WRIB_SVC_KEI`) into the database during batch processing. It is the core registration routine for creating a discount service contract — a business entity that represents a billing discount arrangement applied to a customer's service subscriptions. The method operates in a builder pattern: it constructs a strongly-typed parameter array of 64 fields (`Object[]`) representing every column of the `T_WRIB_SVC_KEI` table, then delegates the actual database INSERT to `executeKK_T_WRIB_SVC_KEI_PKINSERT()`. It is a shared utility method called by multiple service contract registration flows, including new discount service registration (`addSvcKeiNet`), network service updates (`updSvcKeiNet`), and direct batch dispatch (`addWrib`).

The method handles conditional date assignment: as of modification OM-2019-0000601, the application effective date (`APLY_YMD`), plan start date (`PLAN_STA_YMD`), plan charge start date (`PLAN_CHRG_STA_YMD`), service start date (`SVC_STA_YMD`), service charge start date (`SVC_CHRG_STA_YMD`), contract conclusion date (`KEI_TIKT_YMD`), and submission calculation date (`MSKM_SEIKYU_STA_YMD`) are sourced from an instance field `judgeYmd` rather than the operation date from `commonItem`. This reflects a domain shift where contract decisions are tied to a business judgment date rather than the batch operation date.

The method always sets the same static business values regardless of input: the contract status is fixed to "calculation" (`WRIB_SVC_KEI_STAT_KEI`), the discount service detail code is fixed to "standard construction fee balance reduction amount" (`KK2371_WRIB_SVC_DTL_CD_KOJIHI_ZNSK_GENGAKU = "W50000003"`), the application status is fixed to "linkage/interlocking" (`APLY_STAT_RENKEI = "2"`), the immediate application flag is fixed to "no" (`CD00403_APLY_JUN_0 = "0"`), the registration opportunity is fixed to "manual setting" (`CD00874_DCHSKMST_ADD_OPTY_CD_2 = "2"`), the discount charge start month designation is fixed to "current month" (`CD01575_WRIB_CHRG_STA_MON_STI_CD_1 = "1"`), and the invalid flag is set to "valid/effective" (`MK_FLG_YK = "0"`). The only dynamic inputs are the service ID from `wribAddData`, the application detail number from `wribPrgAddData`, the change category (`IDO_DIV`) from `wribPrgAddData`, and the sequence number generated by `JCCBatCommon.getFormatedNextSeq`.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["addWribSvcKei(params)"])
    START --> CREATE["Create setParam array
(64 elements)"]
    CREATE --> SEQ["Generate wribSvcKeiNo
(next sequence, 12 digits)"]
    SEQ --> FILL["Fill setParam[0..63]"]
    FILL --> DB["executeKK_T_WRIB_SVC_KEI_PKINSERT
(setParam)"]
    DB --> ENDN(["Return"])
```

### Constant Resolution

| Constant | Resolved Value | Business Meaning |
|----------|---------------|-----------------|
| `WRIB_SVC_KEI_STAT_KEI` | `"100"` (inferred) | Contract status: in calculation (Kei = settlement/calculation) |
| `KK2371_WRIB_SVC_DTL_CD_KOJIHI_ZNSK_GENGAKU` | `"W50000003"` | Discount service detail: standard construction fee balance reduction |
| `APLY_STAT_RENKEI` | `"2"` | Application status: linkage/interlocking (Renkei) |
| `CD00403_APLY_JUN_0` | `"0"` | Immediate application: No (Jun = timing) |
| `CD00874_DCHSKMST_ADD_OPTY_CD_2` | `"2"` | Registration opportunity: manual setting (Dchskm = discount management) |
| `CD01575_WRIB_CHRG_STA_MON_STI_CD_1` | `"1"` | Discount charge start month: current month (Sti = start indication) |
| `MK_FLG_YK` | `"0"` | Invalid flag: valid/effective (YK = yu/has) |
| `S_MAX_DATE` | `"20991231"` | Maximum date constant for end-of-period fields |

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `wribPrgAddData` | `JBSbatCommonDBInterface` | Progress registration data — carries the application detail number (`MSKM_DTL_NO`) and change category (`IDO_DIV`) for the discount service contract. This interface provides the mapping between the discount (Wrib) and progress registration context, such as what kind of contract change is being performed (new, add, cancel, etc.). |
| 2 | `wribAddData` | `JBSbatCommonDBInterface` | Discount registration data — carries the system ID (`SYSID`) of the service being associated with this discount contract line. This is the entity that the discount applies to. |

### Instance fields read:

| Field | Type | Business Description |
|-------|------|---------------------|
| `judgeYmd` | `String` | Judgment/business decision date — the date used for all contract-effective date fields (set via modification OM-2019-0000601). Replaced `commonItem.getOpeDate()` as the source for application effective date, plan dates, service dates, and contract conclusion dates. |
| `super.batchUserId` | `String` | The batch processing user ID — used for registration and update audit fields. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `JCCBatCommon.getFormatedNextSeq` | JCCBatCommon | - | Generates the next 12-digit discount service contract number (`wribSvcKeiNo`) using the `SEQ_WRIB_SVC_KEI_NO` sequence. |
| R | `JBSbatDateUtil.getSystemDateTimeStamp` | JBSbatDateUtil | - | Called 3 times to populate registration date/time stamp, update date/time stamp fields, and set system timestamps for audit tracking. |
| R | `wribAddData.getString` | JBSbatCommonDBInterface | - | Reads the system ID (`SYSID`) of the target service from the discount registration data. |
| R | `wribPrgAddData.getString` | JBSbatCommonDBInterface | - | Reads the application detail number (`MSKM_DTL_NO`) and change category (`IDO_DIV`) from the progress registration data. |
| C | `executeKK_T_WRIB_SVC_KEI_PKINSERT` | (Self) | `KK_T_WRIB_SVC_KEI` | Performs the database INSERT of the 64-field parameter array into the discount service contract table. |
| R | `commonItem.getOpeDate` | (Commented out) | - | Previously used as the source for all business date fields; now replaced by `judgeYmd` (OM-2019-0000601). |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `JBSbatKKKjhKapZnskIktSikyAdchg.addWrib()` | `addWrib()` -> `addWribSvcKei()` | `executeKK_T_WRIB_SVC_KEI_PKINSERT [C] KK_T_WRIB_SVC_KEI` |
| 2 | `JKKAdchgAddSvcKeiNetCC.addSvcKeiNet()` | `addSvcKeiNet()` -> `addWribSvcKei()` | `executeKK_T_WRIB_SVC_KEI_PKINSERT [C] KK_T_WRIB_SVC_KEI` |
| 3 | `JKKAddSvcKeiNetCC.addSvcKeiNet()` | `addSvcKeiNet()` -> `addWribSvcKei()` | `executeKK_T_WRIB_SVC_KEI_PKINSERT [C] KK_T_WRIB_SVC_KEI` |
| 4 | `JKKUpdSvcKeiNetCC.updSvcKeiNet()` | `updSvcKeiNet()` -> `addWribSvcKei()` | `executeKK_T_WRIB_SVC_KEI_PKINSERT [C] KK_T_WRIB_SVC_KEI` |

## 6. Per-Branch Detail Blocks

**Block 1** — SET (L1702)

> Creates the parameter array and generates the sequence number for the discount service contract.

| # | Type | Code |
|---|------|------|
| 1 | SET | `setParam = new Object[KK_T_WRIB_SVC_KEI_CNT]` // Create 64-element parameter array |
| 2 | SET | `wribSvcKeiNo = JCCBatCommon.getFormatedNextSeq(super.commonItem, SEQ_WRIB_SVC_KEI_NO, "", 12)` // Generate 12-digit sequence number [-> SEQ_WRIB_SVC_KEI_NO] |

**Block 2** — SET (L1705–L1849)

> Populates all 64 fields of the parameter array. This is the core data assembly block. The comments in the source describe each field's business meaning in Japanese. All branches within this block are sequential assignments — no conditional logic.

| # | Type | Code | Business Description |
|---|------|------|---------------------|
| 1 | SET | `setParam[0] = wribSvcKeiNo` | Discount service contract number |
| 2 | SET | `setParam[1] = JBSbatDateUtil.getSystemDateTimeStamp()` | Registration date/time stamp |
| 3 | SET | `setParam[2] = JBSbatKKConst.WRIB_SVC_KEI_STAT_KEI` | Contract status: in calculation |
| 4 | SET | `setParam[3] = wribAddData.getString(JBSbatKK_T_SVC_KEI.SYSID)` | System ID of the target service |
| 5 | SET | `setParam[4] = JBSbatKKConst.KK2371_WRIB_SVC_DTL_CD_KOJIHI_ZNSK_GENGAKU` | [-> "W50000003"] Discount service detail: standard construction fee balance reduction |
| 6 | SET | `setParam[5] = ""` | Fee cost code (empty) |
| 7 | SET | `setParam[6] = ""` | Fee plan code (empty) |
| 8 | SET | `setParam[7] = ""` | Service usage start desired date (empty) |
| 9 | SET | `setParam[8] = ""` | Contract application start desired date (empty) |
| 10 | SET | `setParam[9] = wribPrgAddData.getString(JBSbatKK_T_SVC_KEI.MSKM_DTL_NO)` | Application detail number from progress registration data |
| 11 | SET | `setParam[10] = ""` | Inspection date (empty) |
| 12 | SET | `setParam[11] = ""` | Inspection cancellation date (empty) |
| 13 | SET | `setParam[12] = judgeYmd` | [OM-2019-0000601] Application effective date (replaced commonItem.getOpeDate()) |
| 14 | SET | `setParam[13] = ""` | Contract cancellation date (empty) |
| 15 | SET | `setParam[14] = JBSbatKKConst.APLY_STAT_RENKEI` | [-> "2"] Application status: linkage/interlocking |
| 16 | SET | `setParam[15] = JBSbatKKConst.CD00403_APLY_JUN_0` | [-> "0"] Immediate application flag: No |
| 17 | SET | `setParam[16] = judgeYmd` | [OM-2019-0000601] Plan start date (replaced commonItem.getOpeDate()) |
| 18 | SET | `setParam[17] = JBSbatKKConst.S_MAX_DATE` | Plan end date: 20991231 |
| 19 | SET | `setParam[18] = judgeYmd` | [OM-2019-0000601] Plan charge start date (replaced commonItem.getOpeDate()) |
| 20 | SET | `setParam[19] = JBSbatKKConst.S_MAX_DATE` | Plan charge end date: 20991231 |
| 21 | SET | `setParam[20] = ""` | Plan end reason code (empty) |
| 22 | SET | `setParam[21] = ""` | Service cancel date (empty) |
| 23 | SET | `setParam[22] = ""` | Service cancel reason code (empty) |
| 24 | SET | `setParam[23] = judgeYmd` | [OM-2019-0000601] Service start date (replaced commonItem.getOpeDate()) |
| 25 | SET | `setParam[24] = judgeYmd` | [OM-2019-0000601] Service charge start date (replaced commonItem.getOpeDate()) |
| 26 | SET | `setParam[25] = JBSbatKKConst.S_MAX_DATE` | Service end date: 20991231 |
| 27 | SET | `setParam[26] = JBSbatKKConst.S_MAX_DATE` | Service charge end date: 20991231 |
| 28 | SET | `setParam[27] = ""` | Service cancellation date (empty) |
| 29 | SET | `setParam[28] = ""` | Service cancellation reason code (empty) |
| 30 | SET | `setParam[29] = ""` | Service cancellation reason memo (empty) |
| 31 | SET | `setParam[30] = ""` | Service cancellation completion flag (empty) |
| 32 | SET | `setParam[31] = ""` | Restoration date (empty) |
| 33 | SET | `setParam[32] = ""` | Service cancel reservation cancellation date (empty) |
| 34 | SET | `setParam[33] = ""` | Service cancellation reservation date (empty) |
| 35 | SET | `setParam[34] = ""` | Charge start date correction (empty) |
| 36 | SET | `setParam[35] = ""` | Screening result transmission code (empty) |
| 37 | SET | `setParam[36] = ""` | Penalty occurrence code (empty) |
| 38 | SET | `setParam[37] = wribPrgAddData.getString(JBSbatKK_T_SVC_KEI.IDO_DIV)` | Change category from progress registration data |
| 39 | SET | `setParam[38] = ""` | Inspection cancellation completion code (empty) |
| 40 | SET | `setParam[39] = judgeYmd` | [OM-2019-0000601] Contract conclusion date (replaced commonItem.getOpeDate()) |
| 41 | SET | `setParam[40] = ""` | Group code (empty) |
| 42 | SET | `setParam[41] = ""` | Referral code (empty) |
| 43 | SET | `setParam[42] = judgeYmd` | [OM-2019-0000601] Submission calculation start date (replaced commonItem.getOpeDate()) |
| 44 | SET | `setParam[43] = JBSbatKKConst.CD00874_DCHSKMST_ADD_OPTY_CD_2` | [-> "2"] Discount registration opportunity: manual setting |
| 45 | SET | `setParam[44] = ""` | Discount cancellation cancellation opportunity code (empty) |
| 46 | SET | `setParam[45] = ""` | Discount service contract auto-renewal identification code (empty) |
| 47 | SET | `setParam[46] = ""` | Discount amount calculation standard date (empty) |
| 48 | SET | `setParam[47] = JBSbatKKConst.CD01575_WRIB_CHRG_STA_MON_STI_CD_1` | [-> "1"] Discount charge start month designation: current month |
| 49 | SET | `setParam[48] = commonItem.getOpeDate()` | Discount registration date (from operation date) |
| 50 | SET | `setParam[49] = ""` | Discount target contract service suspension date (empty) |
| 51 | SET | `setParam[50] = ""` | Discount target contract service suspension removal date (empty) |
| 52 | SET | `setParam[51] = JBSbatDateUtil.getSystemDateTimeStamp()` | Registration date/time stamp |
| 53 | SET | `setParam[52] = super.batchUserId` | Registration operator account |
| 54 | SET | `setParam[53] = JBSbatDateUtil.getSystemDateTimeStamp()` | Update date/time stamp |
| 55 | SET | `setParam[54] = super.batchUserId` | Update operator account |
| 56 | SET | `setParam[55] = ""` | Delete date/time stamp (empty) |
| 57 | SET | `setParam[56] = ""` | Delete operator account (empty) |
| 58 | SET | `setParam[57] = JBSbatKKConst.MK_FLG_YK` | [-> "0"] Invalid flag: valid/effective (0 = yu/has validity) |
| 59 | SET | `setParam[58] = ""` | Registration operation date (empty) |
| 60 | SET | `setParam[59] = ""` | Registration processing ID (empty) |
| 61 | SET | `setParam[60] = ""` | Update operation date (empty) |
| 62 | SET | `setParam[61] = ""` | Update processing ID (empty) |
| 63 | SET | `setParam[62] = ""` | Delete operation date (empty) |
| 64 | SET | `setParam[63] = ""` | Delete processing ID (empty) |

**Block 3** — CALL (L1850)

> Executes the database INSERT with the fully assembled parameter array.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `executeKK_T_WRIB_SVC_KEI_PKINSERT(setParam)` // Register discount service contract line to T_WRIB_SVC_KEI table |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `wribSvcKeiNo` | Field | Discount service contract number — the 12-digit sequence number uniquely identifying a discount service contract line |
| `MSKM_DTL_NO` | Field | Application detail number — the detail reference number from the application/registration process |
| `IDO_DIV` | Field | Change category — classifies what type of contract change is being performed (e.g., new contract, service addition, cancel, plan change, etc.) |
| `SYSID` | Field | System ID — the identifier of the target service contract that this discount line is associated with |
| `judgeYmd` | Field | Judgment date (year/month/day) — the business decision date used as the effective date for contract-related fields (replaced `commonItem.getOpeDate()`) |
| `wribPrgAddData` | Field | Discount/progress registration data — carries the application detail number and change category |
| `wribAddData` | Field | Discount registration data — carries the system ID of the target service |
| `WRIB` | Acronym | Discount (Waribiki) — prefix for all discount-related tables and entities |
| `KEI` | Acronym | Contract (Keiyaku) — refers to the service contract entity |
| `SVC_KEI` | Acronym | Service contract — the core entity representing a customer's service subscription |
| `T_WRIB_SVC_KEI` | Entity | Discount service contract table — stores discount line items applied to customer service contracts |
| `KK_T_` | Prefix | Kontract Table — table name prefix for contract-related tables in the K-Opticom system |
| `APLY_STAT_RENKEI` | Constant | Application status: linkage/interlocking — indicates this contract was created as part of a linked/interlocked operation (e.g., address change with service continuation) |
| `CD00403_APLY_JUN_0` | Constant | Immediate application: No — the discount is not applied immediately at registration time |
| `CD00874_DCHSKMST_ADD_OPTY_CD_2` | Constant | Discount registration opportunity: manual setting — the discount was manually registered rather than auto-registered |
| `CD01575_WRIB_CHRG_STA_MON_STI_CD_1` | Constant | Discount charge start month: current month — the discount billing begins from the current month |
| `MK_FLG_YK` | Constant | Invalid flag (YK = "yu/has"): "0" means the record is valid/effective |
| `S_MAX_DATE` | Constant | Maximum date: "20991231" — used as the end-of-period sentinel value for date range fields |
| `KK2371_WRIB_SVC_DTL_CD_KOJIHI_ZNSK_GENGAKU` | Constant | Discount service detail: standard construction fee balance reduction amount — identifies this discount line as a reduction of remaining standard construction fees |
| `WRIB_SVC_KEI_STAT_KEI` | Constant | Contract status: in calculation — the contract status indicates the contract line is in the billing/settlement calculation phase |
| `getFormatedNextSeq` | Method | Sequence generator — generates the next formatted sequence number for a given sequence name with a specified length |
| `getSystemDateTimeStamp` | Method | System timestamp getter — returns the current system date and time in stamp format for audit fields |
| `getOpeDate` | Method | Operation date getter — returns the batch operation date (now superseded by `judgeYmd` for contract dates) |
| `executeKK_T_WRIB_SVC_KEI_PKINSERT` | Method | Primary key INSERT executor — performs the database INSERT into the `T_WRIB_SVC_KEI` table using the parameter array |
| OM-2019-0000601 | Change ticket | Modification ticket that changed contract-effective dates from `commonItem.getOpeDate()` to the instance field `judgeYmd` |
| Batch | Concept | Automated offline processing — this method is invoked within batch processing context, not real-time screen processing |
| `batchUserId` | Field | The batch processing user identifier — used for audit trail on registration/update operations |
| `SEQ_WRIB_SVC_KEI_NO` | Constant | Sequence name for generating discount service contract numbers |
