# FUW00943SFLogic

## Purpose

`FUW00943SFLogic` is the central view-layer business logic class for the **Account (Retail / Visiting Sales) Screen** in the K-Opticom eo Customer Base System. It serves as the orchestration hub for processing new subscription and service-add forms submitted through the web interface — handling initial page data retrieval, comprehensive service registration through dozens of backend service calls, and email message generation for confirmation. This class is the primary entry point for the entire subscription workflow for retail store, visiting sales, and au sales channel channels.

## Design

The class follows the **Facade** pattern combined with the **Web Business Logic** pattern common to this codebase's X31 framework. It sits between the presentation layer (`WEBGAMEN_FUW009430PJP`) and the service layer, acting as a single point of control that:

1. Initializes screen data by fetching account lists and account data from backend services
2. Orchestrates a massive sequence of service calls (30+ mapper invocations) for contract registration, phone number portability, payment method handling, optional services, and promotional campaign enrollment
3. Generates display-ready email confirmation messages from the submitted service selections
4. Handles error translation from low-level `JCCWebServiceException` into business-level `JCCBusinessException` with specific error codes

All service interactions are performed through mapper objects (`FUSV0160_FUSV0160OPDBMapper`, `FUSV0180_FUSV0180OPDBMapper`, etc.) which populate `inputMap` / `outputMap` `HashMap`s, which are then passed to the inherited `invokeService()` method from `JCCWebBusinessLogic` to execute the actual remote calls.

## Key Methods

### `init()` — Initial Page Display Processing

```java
public boolean init() throws Exception
```

This method handles the initial screen load. It performs:

- **Service form bean generation**: Calls `FUSV0180_FUSV0180OPDBMapper.setFUSV018001SC()` and `setEKK00311B501()` to set up input parameters for the account list lookup service, then invokes it and maps results back to the service form bean.
- **Image file path setup**: Calls `setImgpass()` to append the configured image file prefix to all survey answer image file names.
- **mineo integration data**: If the user has the mineo external linkage flag set (`MINEO_MSKM_FLG_57`), it extracts account information, subscriber info, and other data — encrypting sensitive fields (private/business email addresses, passwords) using AES encryption with keys loaded from application constants via `JFUCommonUtil.decryptKey()`.
- **Operation date setting**: Sets the `OPE_DATE` field using `JCCWebCommon.getOpeDate()`.

Returns `true` (indicating a fixed/standard navigation target).

### `finMskm()` — Form Submission Processing

```java
public boolean finMskm() throws Exception
```

**This is the most important method in the class** — a single method that orchestrates over 40 backend service calls to process a complete subscription form submission. It is the system's heavy-lifting method for registering a customer's contract. The processing flow is:

1. **Data extraction and preparation**: Extracts contract service info, eo net info, redirect info, phone info, contract info, and subscriber info from the common form bean. Sets `MSKM_KBN2` (application section type) to "main application" (`MSKM_KBN_HON`).

2. **Person verification**: For transfers (phone number portability) and eo phone submissions, if `isNeedVerifyPerson()` returns true, it performs a person confirmation document lookup and updates the contract subscriber bean accordingly.

3. **Device model code resolution**: For wireless LAN relay devices (PLC) or mesh Wi-Fi subscriptions, calls `callSvcFUSV0376()` to look up the appropriate home device model code based on the subscription service type (Home `HF`, Mezono `MZ`, or Mansion `MF`).

4. **Massive service orchestration**: Builds an `inputMap` and calls `invokeService()` with the following mapper invocations, each registering a piece of the customer's subscription:

   | Mapper Call | Purpose |
   |---|---|
   | `setMskmDmenXmlMap` | Subscription form system information |
   | `setFUSV016006CC` | Usage location address splitting |
   | `setFUSV016007CC` | Contract subscriber address splitting |
   | `setFUSV016008CC` / `setFUSV016008TypeNCC` | Phone number portability validation (NTT separation variant) |
   | `setFUSV016010CC` | Mobile device delivery address splitting |
   | `setEKK0011C050` | Pseudo-application flag |
   | `setEKK0341D010` | Device provider service contract registration |
   | `setEKK2811B503` | Device optional service contract list lookup |
   | `setEKK0341B002` | Device provider service contract list |
   | `setEKK0341C330` | Device provider service contract cancellation |
   | `setEKK0091A010` | Service agreement - eo light net consent |
   | `setEKK0341D010Tkn` | Device provider service contract registration (token) |
   | `setEKK2811D010Net02` | Device optional service contract registration |
   | `setEKK2811D010Tel02` | Device optional service contract registration (phone) |
   | `setEKK0391D010` | Optional service contract - support registration |
   | `setFUSV016040SC` | Service agreement - eo light net SC |
   | `setJKKSecurityPackOperateCC` | Security pack operation |
   | `setJFUFamipaRouterCC` | Family pack router auto-registration |
   | `setJFUVaKikiCancelCC` | Device operation registration cancellation |
   | `setJFUWribSvcKeiAutoAddCC` | Discount service contract auto-registration |
   | `setFUSV016033CC` | Discount registration (auto, except family pack) |
   | `setFUSV016034CC` | Data extraction item registration (except auto) |
   | `setFUSV016021CC` | Latest device provider service contract year/month update |
   | `setEKK0061A010` | Dealer consent (for small tablet/GH devices) |
   | `setJFUSmartLinAdd2CC` | eo smart link registration |
   | `setEKK0361D010` | Optional service contract - ISP |
   | `setEKK0341D010Sml` | Device provider service contract registration (small) |
   | `setEKK2541D010` | Discount contract registration |
   | `setJKKNttorsNetTelInfOperateCC` | NTT cancellation network phone operation |
   | `setJFUBmpTelNoAddChkCC` | Phone number portability number registration check |
   | `setTransferCC` | Data transfer |
   | `setJKKChkDobanitenPsbAreaCC` | Same number transfer possible area check |
   | `setJFUMstTelNoUpdCC` | Phone number mass update |
   | `setEZM0121D010` | Phone number registration |
   | `setEZM0111D010` | E-signing registration |
   | `setEKK0191C012` | Service contract details - eo light phone update |
   | `setEKK0371D010` | Optional service contract - phone |
   | `setEKK0381D010` | Optional service contract - TV |
   | `setEKK0341C230` | Device provider service contract info update |
   | `setJFUAddAgntCC` | Dealer registration |
   | `setEKK0431D010` | Sub-option registration |
   | `setEKK1091D010` | Progress registration map |
   | `setEKK2201A010` / `setEKK2201C010` | Screen entry support consent / update |
   | `setFUSV016025SC` - `setFUSV016029SC` | Response history linkage (list, user, consent, record, detail, hot boost, clear) |
   | `setEKK0451D01001` / `setEKK0451D01002` | Discount service - eo light phone pack (1st / 2nd number) |
   | `setJKKWrisvcAutoAplyCC` / `setJKKWrisvcAutoAplyCC2` | Discount service auto-apply |
   | `setJFUBackyardMappingCC` | WiFi set registration |
   | `setEKK1391C040` | Data extraction item setting completion |
   | `setEKK0011C100` | Application content consent request (not for additions) |
   | `setECR0511D010` | Case file creation work registration (if electricity guide requested) |
   | `setEKK0491C240` / `setEKK0491C060` | Billing payment method change / billing contract content change |
   | `setEKK0081C012` | Service contract payment method continuation change |
   | `setEKK0491C220` / `setEKK0321D010` | Billing contract reservation cancellation / advance registration |
   | `setEKKA0010003` / `setEKK0521D020` / `setEKK0521D010` / `setEKK1031D010` | Credit card processing (pre-authorization, registration, billing, actualization) |
   | `setFUSV016047SC` | Credit company list lookup |
   | `setEKK0011A010` | Application consent |
   | `setEKK0011C020` | Application content change |
   | `setJKKTmcpOperateCC` | Terminal compensation CC (for PC plan / PC Wide plan / TV plan) |
   | `setFUSV016044SC` / `setFUSV016043SC` | Introduction consent / update (referral code matching pattern) |
   | `setJFUMskmDtlUpdCC` | Application details update |
   | `setWorkStrConstMap` | Fixed text correlation map |
   | `setFUSV016046SC` | SMS send confirmation |
   | `setJFUEoidInputInfoAddCC` | eoID input info addition (new applications only) |

5. **Post-processing**: Removes invalid data from the Hanyo code list via `removeInvalidDataFromHanyoCdList()`, sets auto-campaign addition flags, and calls `JFUWebCommon.setMskmDmenXmlMapWebNew()` to preserve application form data.

6. **Error handling**: Catches `JCCWebServiceException` and inspects the `templateId`, `itemId`, `status`, and `itemCheckErr` fields to translate low-level service errors into specific business exceptions (`ERROR_CODE_0102`, `ERROR_CODE_0103`). This maps specific error conditions like "already contracted" phone numbers, e-signing conflicts, number portability errors, and same-number transfer errors.

### `mineoMskm()` — Mineo Form Submission

```java
public boolean mineoMskm() throws Exception
```

A simple delegation method that calls `finMskm()`. This exists to provide a semantically named entry point for the mineo service subscription flow (added in v29.00.00 with the visiting channel tab support). The mineo subscription uses the same registration logic as the standard subscription.

### `back()` — Back Button Processing

```java
public boolean back()
```

Handles the back button navigation. It recreates the `WEB_NEW_INFO` bean on the common form, resets the screen mode to default, and sets the next screen target to `FUW009430PJP` (screen ID `FUW00928`). Always returns `true`.

### `setServiceForm(X31SDataBeanAccess bean)` — Brand Code Construction

```java
private void setServiceForm(X31SDataBeanAccess bean)
```

This method constructs a composite brand code for the account display judgment by evaluating the selected services:

- **Network brand** (`brandCdNet`): Set based on the selected network service (eo light net) and the subscription service type (Home, Mezono, Mansion).
- **Phone brand** (`brandCdTel`): Set if eo light phone is selected.
- **TV brand** (`brandCdTv`): Set if eo light TV is selected.
- **Mobile brand** (`brandCdMob`): Set if eo mobile course is WiFi, 3G, or WiMAX.
- **Electric brand** (`brandCdElec`): Set if eo electricity simultaneous application is indicated.

These are concatenated into a single `brandCd` string. The method also determines the `MSKM_CHANNEL_CD` (submission channel code) based on the sales type: `4` for au sales store, `2` for retail, `3` for visiting sales.

### `selectSvcNm()` — Service Name Email Message Builder

```java
private StringBuilder selectSvcNm(X31SDataBeanAccess webNewInfoBean)
```

Generates a user-facing email message summarizing the selected services. This is one of the longest methods in the class (807 lines, ~lines 2156-2962), building a `StringBuilder` by:

- Checking contract type modifications (contract info change reservation)
- Evaluating each service category: network, phone, TV, mobile
- For network services, resolving display names based on service type (Home `HF`, Mezono `MZ`, Mansion `MF`)
- Incorporating course details, speed codes, discounts, automatic continuation flags, Famipa router flags, remote support, smart link, NH terminal, stick STB, mesh WiFi, wireless LAN relay
- Appending brand-specific service names and course display text using `JFUWebCommon.getDispText()`
- Building the full service name string for email delivery

### `selectHfMzKjMngn()` — Home/Mezono Warning Message Builder

```java
private StringBuilder selectHfMzKjMngn(X31SDataBeanAccess webNewInfoBean)
```

Generates warning/instruction messages specific to Home and Mezono subscription types. Includes:

- Construction period guidance for Internet/Gig Internet subscriptions
- Mezono-specific general caution messages and indoor work (opening work) notices
- Separator lines between message sections

### `selectOpSvcMngn()` — Optional Service Warning Message Builder

```java
private StringBuilder selectOpSvcMngn(X31SDataBeanAccess webNewInfoBean)
```

Generates warning messages for optional services including:

- Netflix package notices (for 1G/5G/10G courses with Netflix)
- Security pack notices
- Internet gateway notices
- Non-stop family premium notices
- Device compensation service notices (PC plan, PC Wide plan, TV plan)
- Famipa router notices
- Phone add-on adapter notices (for additional applications)
- Phone number portability notices
- TV-specific notices

### `selectMansionMngn()` — Mansion Type Message Builder

```java
private StringBuilder selectMansionMngn(X31SDataBeanAccess webNewInfoBean)
```

Generates comprehensive messages for mansion-type subscriptions, including:

- Service category separator line
- eo Mypage guidance (varies by building type: Internet/Gig Internet, fiber concentration/no construction, VDSL/fiber direct/fiber wiring)
- Router return requirements
- Construction period warnings (varies by wiring type)
- Phone number portability notices (varies by wiring type)
- Optional service warnings (security pack, internet gateway, non-stop family premium, device compensation)

### `removeInvalidDataFromHanyoCdList(X31SDataBeanAccess bnWebNewInfo)` — Hanyo Code Cleanup

```java
private void removeInvalidDataFromHanyoCdList(X31SDataBeanAccess bnWebNewInfo)
```

Removes incompatible campaign codes from the Hanyo code list before final submission. Only executes for visiting sales (`HNBAI_TYPE_HOHAN`). Removes smart link campaign codes if smart link is not selected, and NH campaign codes if NH is not selected.

### `callSvcFUSV0376(String keySvcTypeSkbtCd, Map<String, String> dispDefMap)` — Device Model Code Lookup

```java
private String callSvcFUSV0376(String keySvcTypeSkbtCd, Map<String, String> dispDefMap)
```

Calls the `FUSV0376` backend service to look up the home device model code for wireless LAN relay devices and mesh Wi-Fi devices. Takes a key service type code (`HF`, `MZ`, or `MF`) and a display definition map, invokes the service via `invokeService()`, and returns the resolved model number. Throws `JCCBusinessException` on service errors.

### `nullToEmpty(String val)` — Null Safety Utility

```java
private String nullToEmpty(String val)
```

Returns an empty string if `val` is null, otherwise returns `val`. Used in error logging to avoid `NullPointerException` in log message construction.

### Private Data Accessor Methods

These methods follow a uniform pattern: retrieve a named data bean array from the input bean, ensure at least one element exists (creating one if needed), and return the first element.

| Method | Data Bean Key | Purpose |
|---|---|---|
| `getKeiyakusvcinfo()` | `KEIYAKU_SVC_INFO` | Contract service info |
| `getEonet()` | `EONET` | eo light net info |
| `getMineoSvcInfo()` | `MINEO_SVC_INFO` | Mineo service info |
| `getRedirectinfo()` | `REDIRECT_INFO` | Redirect info |
| `getElseInfo()` | `ELSE_INFO` | Other/misc info |
| `getWebNewInfo()` | `WEB_NEW_INFO` | Web new application info |
| `getKeiyakushaInfo()` | `KEIYAKUSHA_INFO` | Contract subscriber info |
| `getEotv()` | `EOTV` | eo light TV info |
| `getEotel()` | `EOTEL` | eo light phone info (returns array) |
| `getKeiyakuSvcInfo()` | `KEIYAKU_SVC_INFO` | Contract service info (duplicate) |
| `getMansioninfo()` | `MANSION_INFO` | Mansion info |
| `getPywyInfo()` | `PAYWAY_INFO` | Payment method info |

## Relationships

### Class Diagram

```
flowchart TD
    A[WEBGAMEN_FUW009430PJP] -->|invokes| B[FUW00943SFLogic]
    C[x31business_logic_FUW00943SF] -->|references| B
    B -->|extends| D[JCCWebBusinessLogic]
    B -->|uses| E[FUSV0180_FUSV0180OPDBMapper]
    B -->|uses| F[FUSV0160_FUSV0160OPDBMapper]
    B -->|uses| G[FUSV0152_FUSV0152OPDBMapper]
    B -->|uses| H[FUSV0376_FUSV0376OPDBMapper]
    B -->|uses| I[X31SDataBeanAccess]
    B -->|uses| J[JFUWebCommon]
    B -->|uses| K[JFUEncryptUtil]
    B -->|throws| L[JCCBusinessException]
```

### Inbound Dependencies (who uses this class)

- **WEBGAMEN_FUW009430PJP.xml**: The main web page definition file for the retail/visiting sales account screen. This is the primary caller that invokes `init()`, `finMskm()`, and `back()` in response to user actions.
- **x31business_logic_FUW00943SF.xml**: The business logic configuration that references this class as part of the X31 framework's service routing.

### Outbound Dependencies (what this class depends on)

- **JCCWebBusinessLogic** (parent): Provides `invokeService()`, `getCommonInfoBean()`, `getServiceFormBean()`, and base framework methods.
- **FUSV0180_FUSV0180OPDBMapper**: Account list lookup service (initial page load).
- **FUSV0160_FUSV0160OPDBMapper**: Primary service for bulk subscription registration (the bulk of `finMskm()`).
- **FUSV0152_FUSV0152OPDBMapper**: Dealer registration for addition applications.
- **FUSV0376_FUSV0376OPDBMapper**: Home device model code lookup for wireless LAN/mesh WiFi.

## Usage Example

The typical calling pattern follows the web request lifecycle:

1. **Initial page display**: The web page (`WEBGAMEN_FUW009430PJP`) receives a GET request and calls `init()`. The logic class fetches account list data, populates the service form bean with brand codes and channel codes, sets up image file paths, and handles mineo external linkage data. The initialized beans flow back to the page for rendering.

2. **Form submission**: The user fills out the subscription form and clicks submit. The web page calls `finMskm()`. The logic class extracts all form data from the common info bean, performs person verification if needed, resolves device model codes for optional wireless LAN/mesh WiFi, orchestrates the full suite of 40+ service registrations (contracts, phone numbers, billing, optional services, etc.), and handles any service-level errors.

3. **Back navigation**: The user clicks back. The web page calls `back()`. The logic class resets the screen mode and redirects to the previous screen (`FUW00928`).

A simplified illustration:

```
sequenceDiagram
    participant U as User
    participant P as WebPage
    participant L as FUW00943SFLogic
    participant S as Service
    participant D as Database

    U->>P: Submit subscription form
    P->>L: init()
    L->>S: FUSV0180 account list lookup
    S-->>L: account data
    L->>L: setServiceForm()
    L->>L: setImgpass()
    L->>L: getMineoSvcInfo()
    L-->>P: true

    U->>P: Click submit button
    P->>L: finMskm()
    L->>L: extract bean data
    L->>L: person verification check
    L->>L: resolve model code
    L->>S: FUSV0160 bulk service registration
    S->>D: register all contracts
    D-->>S: confirmation
    S-->>L: result
    alt error
        L->>L: parse service exception
        L->>P: JCCBusinessException
    else success
        L-->>P: true
    end
```

## Notes for Developers

### Screen-Specific Logic
This class is tightly coupled to screen `FUW00943` (retail/visiting sales account screen). The next-screen navigation in `back()` is hardcoded to point to screen `FUW00928`.

### Massive Single-Method Design
`finMskm()` is approximately 970 lines of sequential service orchestration. This is intentional — the method executes as a single database transaction through the shared `invokeService()` call, ensuring all registrations succeed or fail together. Adding or removing a service registration step requires care to maintain the correct ordering, as some mappers depend on data populated by earlier calls in the same method.

### Error Handling Depth
The `finMskm()` catch block contains 5 specific error code translations based on `templateId`, `itemId`, `status`, and `itemCheckErr` fields from the service exception. Each maps to a specific `JCCBusinessException` error code. New service calls added to `finMskm()` may require corresponding error handling additions if they can produce relation check errors.

### Thread Safety
The class holds no mutable instance state beyond what is inherited from `JCCWebBusinessLogic` (which stores beans per-request). Instance variables are static constants only. The class appears to be designed for per-request instantiation, consistent with the X31 framework's typical servlet-like usage pattern.

### Data Bean Assumptions
The private accessor methods (e.g., `getEonet()`, `getKeiyakusvcinfo()`) silently create new data beans if the array is empty. Callers should not assume the data is populated — only that the bean slot exists. The `getEotel()` method is unique in that it allocates exactly 2 records minimum (for primary and secondary phone lines).

### Encryption
Sensitive fields for mineo external linkage (personal/business email, passwords) are encrypted using AES via `JFUEncryptUtil.encryptAES()`. The encryption key and IV are loaded from application constants and decrypted with a master key (`TRUE_KEY`). Non-sensitive fields (SYSID, application number, dealer code, login ID, handling code) are passed unencrypted.

### Business Rule Flags
The `MSKM_KBN` (application section) and `MSKM_KBN2` (application section 2) fields control whether certain operations execute:
- `MSKM_KBN_ADD` (addition): skips `setEKK0011C110` (application content approval) and `setEKK0011C100` (consent request), since additions don't need approval.
- `MSKM_KBN_NEW` (new): triggers special content service notices and eoID input info addition.
- `MSKM_KBN_CHG` (change): standard flow.

### Version History Notes
The class has been actively maintained since 2012 (v1.00.00 through v75.00). Recent additions (v70-v75) include optional channel changes (2024), NTT cancellation support (v73), new TV course integration (v74), and eoID acquisition method changes (v72.01.00). The changelog indicates approximately one major feature release per quarter in the later versions, reflecting the evolving Japanese telecommunications service landscape.
