| Line 36... |
Line 36... |
| 36 |
private PartnerLimitHelper partnerLimitHelper;
|
36 |
private PartnerLimitHelper partnerLimitHelper;
|
| 37 |
|
37 |
|
| 38 |
@Autowired
|
38 |
@Autowired
|
| 39 |
private PriceDropBatchService priceDropBatchService;
|
39 |
private PriceDropBatchService priceDropBatchService;
|
| 40 |
|
40 |
|
| - |
|
41 |
@Autowired
|
| - |
|
42 |
private com.spice.profitmandi.service.PartnerInvestmentSweepService partnerInvestmentSweepService;
|
| - |
|
43 |
|
| - |
|
44 |
/**
|
| - |
|
45 |
* Recomputes every active partner's investment snapshot, then recomputes the credit limit for
|
| - |
|
46 |
* the partners whose base actually moved.
|
| - |
|
47 |
*
|
| - |
|
48 |
* <p>Runs every 2 minutes. Measured on production: ~3.5s of batched reads for ~980 partners,
|
| - |
|
49 |
* with an average of 3 partners (peak 18) showing a changed base per window — so the limit work
|
| - |
|
50 |
* that follows is a handful of rows, not a full scan.
|
| - |
|
51 |
*
|
| - |
|
52 |
* <p>Investment and utilisation are read in the same pass deliberately. Reading them at
|
| - |
|
53 |
* different vintages is what let an advance payment be counted twice — once as a cached wallet
|
| - |
|
54 |
* balance and once as the loan repayment it funded — and overstate a limit by the payment x the
|
| - |
|
55 |
* partner's tier.
|
| - |
|
56 |
*/
|
| - |
|
57 |
public void sweepPartnerInvestment() throws Exception {
|
| - |
|
58 |
List<Integer> changedBases;
|
| - |
|
59 |
try {
|
| - |
|
60 |
changedBases = partnerInvestmentSweepService.sweep();
|
| - |
|
61 |
} catch (Exception e) {
|
| - |
|
62 |
LOGGER.error("Investment sweep failed: {}", e.getMessage(), e);
|
| - |
|
63 |
return;
|
| - |
|
64 |
}
|
| - |
|
65 |
if (changedBases.isEmpty()) {
|
| - |
|
66 |
return;
|
| - |
|
67 |
}
|
| - |
|
68 |
updatePartnerLimitWithBatch(changedBases);
|
| - |
|
69 |
}
|
| - |
|
70 |
|
| - |
|
71 |
/** Daily refresh of the time-driven aged-Apple and live-demo haircuts. */
|
| - |
|
72 |
public void refreshAgedStockDaily() {
|
| - |
|
73 |
try {
|
| - |
|
74 |
partnerInvestmentSweepService.refreshAgedStockDaily();
|
| - |
|
75 |
} catch (Exception e) {
|
| - |
|
76 |
LOGGER.error("Aged stock daily refresh failed: {}", e.getMessage(), e);
|
| - |
|
77 |
}
|
| - |
|
78 |
}
|
| - |
|
79 |
|
| 41 |
/**
|
80 |
/**
|
| 42 |
* CLI entrypoint for cron: delegates to shared OfferBatchService (also used by web/fofo controllers).
|
81 |
* CLI entrypoint for cron: delegates to shared OfferBatchService (also used by web/fofo controllers).
|
| 43 |
*/
|
82 |
*/
|
| 44 |
public void processOfferWithBatch(int offerId) throws Exception {
|
83 |
public void processOfferWithBatch(int offerId) throws Exception {
|
| 45 |
offerBatchService.processOfferWithBatch(offerId);
|
84 |
offerBatchService.processOfferWithBatch(offerId);
|
| Line 63... |
Line 102... |
| 63 |
* 2. Create batch with only changed partners (~50-100 typically)
|
102 |
* 2. Create batch with only changed partners (~50-100 typically)
|
| 64 |
* 3. Per-partner: update in REQUIRES_NEW transaction
|
103 |
* 3. Per-partner: update in REQUIRES_NEW transaction
|
| 65 |
* 4. Finalize: counts + failure email
|
104 |
* 4. Finalize: counts + failure email
|
| 66 |
*/
|
105 |
*/
|
| 67 |
public void updatePartnerLimitWithBatch() throws Exception {
|
106 |
public void updatePartnerLimitWithBatch() throws Exception {
|
| - |
|
107 |
updatePartnerLimitWithBatch(null);
|
| - |
|
108 |
}
|
| - |
|
109 |
|
| - |
|
110 |
/**
|
| - |
|
111 |
* @param restrictTo when non-null, only recalculate these partners. Passed by the investment
|
| - |
|
112 |
* sweep with the partners whose base moved.
|
| - |
|
113 |
*/
|
| - |
|
114 |
public void updatePartnerLimitWithBatch(java.util.Collection<Integer> restrictTo) throws Exception {
|
| 68 |
List<PartnerLimitUpdateData> changedPartners;
|
115 |
List<PartnerLimitUpdateData> changedPartners;
|
| 69 |
try {
|
116 |
try {
|
| 70 |
changedPartners = partnerLimitHelper.calculateChangedPartnerLimits();
|
117 |
changedPartners = partnerLimitHelper.calculateChangedPartnerLimits(restrictTo);
|
| 71 |
} catch (Exception e) {
|
118 |
} catch (Exception e) {
|
| 72 |
LOGGER.error("Failed to calculate partner limits: {}", e.getMessage());
|
119 |
LOGGER.error("Failed to calculate partner limits: {}", e.getMessage());
|
| 73 |
return;
|
120 |
return;
|
| 74 |
}
|
121 |
}
|
| 75 |
|
122 |
|