| 37588 |
amit |
1 |
-- Partner investment snapshot.
|
|
|
2 |
--
|
|
|
3 |
-- One row per active franchise partner, refreshed by the 2-minute sweep
|
|
|
4 |
-- (PartnerInvestmentSweepService). Replaces the 3-hour Redis cache that used to sit in
|
|
|
5 |
-- front of PartnerInvestmentServiceImpl.getInvestment().
|
|
|
6 |
--
|
|
|
7 |
-- Every column in a row is computed in ONE pass, so coupled terms (wallet vs utilised,
|
|
|
8 |
-- in-stock vs aged-Apple) can never be read at different vintages. That skew is what
|
|
|
9 |
-- caused a partner's credit limit to be overstated by the full value of an advance
|
|
|
10 |
-- payment for an hour on 2026-09-10.
|
|
|
11 |
--
|
|
|
12 |
-- Money is DECIMAL, not FLOAT: float money columns lose paise above ~1.67 lakh, and
|
|
|
13 |
-- base_value is compared on every sweep to decide whether the limit must be recomputed.
|
|
|
14 |
--
|
|
|
15 |
-- Safe to re-run.
|
|
|
16 |
|
|
|
17 |
CREATE TABLE IF NOT EXISTS fofo.partner_investment (
|
|
|
18 |
fofo_id INT NOT NULL,
|
|
|
19 |
|
|
|
20 |
-- refreshed every 2 minutes
|
|
|
21 |
wallet_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
22 |
in_stock_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
23 |
unbilled_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
24 |
grn_pending_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
25 |
activated_stock_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
26 |
activated_grn_pending_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
27 |
return_in_transit_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
28 |
utilized_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
29 |
|
|
|
30 |
-- refreshed daily (time-driven), plus on the sweep when the partner's stock moved
|
|
|
31 |
aged_apple_stock_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
32 |
demo_excluded_amount DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
33 |
aged_refreshed_on DATE NULL,
|
|
|
34 |
|
|
|
35 |
-- derived
|
|
|
36 |
total_investment DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
37 |
base_value DECIMAL(14,2) NOT NULL DEFAULT 0,
|
|
|
38 |
|
|
|
39 |
snapshot_timestamp DATETIME NOT NULL,
|
|
|
40 |
|
|
|
41 |
PRIMARY KEY (fofo_id),
|
|
|
42 |
KEY ix_partner_investment_snapshot (snapshot_timestamp)
|
|
|
43 |
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|