Subversion Repositories SmartDukaan

Rev

Rev 37675 | Rev 37751 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23756 amit.gupta 1
package com.smartdukaan.cron.scheduled;
2
 
30049 amit.gupta 3
import com.smartdukaan.cron.migrations.RunOnceTasks;
34948 ranu 4
import com.smartdukaan.cron.scheduled.ambreports.AbmReportSender;
30049 amit.gupta 5
import com.smartdukaan.cron.scheduled.leadsync.LeadSyncRunner;
32832 amit.gupta 6
import com.smartdukaan.cron.scheduled.ordertracking.OrderTrackingService;
32907 amit.gupta 7
import com.smartdukaan.cron.scheduled.purchaseorder.POScheduler;
34443 vikas.jang 8
import com.spice.profitmandi.common.model.ProfitMandiConstants;
34241 tejus.loha 9
import com.spice.profitmandi.dao.service.PurSaleService;
37499 ranu 10
import com.spice.profitmandi.service.integrations.icicilombard.IciciLombardService;
11
import com.spice.profitmandi.service.integrations.icicilombard.model.LastTransactionsResponseModel;
23756 amit.gupta 12
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.scheduling.annotation.Scheduled;
16
import org.springframework.stereotype.Component;
17
 
30049 amit.gupta 18
import java.time.LocalDate;
19
import java.time.LocalDateTime;
34756 amit.gupta 20
import java.time.LocalTime;
36993 amit 21
import java.time.YearMonth;
30049 amit.gupta 22
import java.util.Date;
37499 ranu 23
import java.util.LinkedHashMap;
23756 amit.gupta 24
 
25
@Component
30887 amit.gupta 26
//@ConditionalOnProperty(name = "scheduled", havingValue = "true", matchIfMissing = true)
23756 amit.gupta 27
public class ScheduledSkeleton {
23794 govind 28
 
32048 tejbeer 29
    private static final Logger log = LogManager.getLogger(ScheduledSkeleton.class);
23756 amit.gupta 30
 
32048 tejbeer 31
    @Autowired
32
    private ScheduledTasks scheduledTasks;
28205 tejbeer 33
 
32048 tejbeer 34
    @Autowired
36361 amit 35
    private BatchScheduledTasks batchScheduledTasks;
36
 
37
    @Autowired
34321 ranu 38
    private ScheduledTasksTest scheduledTasksTest;
39
 
40
    @Autowired
34948 ranu 41
    private AbmReportSender abmReportSender;
42
 
43
    @Autowired
32048 tejbeer 44
    private LeadSyncRunner leadSyncRunner;
24841 govind 45
 
32048 tejbeer 46
    @Autowired
47
    private Reconciliation reconciliation;
25822 amit.gupta 48
 
32048 tejbeer 49
    @Autowired
50
    private RunOnceTasks runOnceTasks;
23756 amit.gupta 51
 
32048 tejbeer 52
    @Autowired
53
    private TicketRelatedScheduledTask ticketRelatedScheduledTask;
24841 govind 54
 
32048 tejbeer 55
    @Autowired
56
    private OnBoardingRelatedSchelduleTask onBoardingRelatedSchelduleTask;
28921 tejbeer 57
 
37499 ranu 58
//    @Autowired
59
//    private IciciLombardService iciciLombardService;
60
 
61
    String nagiosCronPropertiesFile = "/var/log/services/nagios-Cron-Monitoring.properties";
62
 
32048 tejbeer 63
    @Scheduled(cron = "0 0 2 * * *")
64
    public void processDailySchemes() throws Exception {
29757 tejbeer 65
 
32048 tejbeer 66
        int maxMinusDays = 5;
67
        int currentDayOfMonth = LocalDate.now().getDayOfMonth();
68
        int minusDays = currentDayOfMonth > maxMinusDays ? maxMinusDays : currentDayOfMonth - 1;
69
        if (minusDays > 0) {
70
            scheduledTasks.processScheme(LocalDateTime.now().minusDays(minusDays), LocalDateTime.now(), false);
71
        }
29673 manish 72
 
32048 tejbeer 73
    }
24841 govind 74
 
32048 tejbeer 75
    @Scheduled(cron = "0 15 0 * * *")
76
    public void runOnceTasks() throws Exception {
29757 tejbeer 77
 
32048 tejbeer 78
        scheduledTasks.reconcileRecharge();
29757 tejbeer 79
 
32048 tejbeer 80
    }
25822 amit.gupta 81
 
32048 tejbeer 82
    /*
83
     * @Scheduled(cron = "0 0 8 * * *") public void mailDashboardScreenshots()
84
     * throws Exception { runOnceTasks.mailDashboardScreenshots(); }
85
     */
25721 tejbeer 86
 
32048 tejbeer 87
    @Scheduled(cron = "0 05 0 1,16 * ?")
88
    public void processRechargeCashback() throws Throwable {
29673 manish 89
 
32048 tejbeer 90
        scheduledTasks.processRechargeCashback();
29673 manish 91
 
32048 tejbeer 92
    }
23794 govind 93
 
32048 tejbeer 94
    @Scheduled(cron = "0 0 6 * * *")
95
    public void sendPartnerInvestmentDetails() throws Exception {
96
        scheduledTasks.sendPartnerInvestmentDetails();
97
        long secs = (new Date().getTime()) / 1000;
98
        log.info("sendPartnerInvestmentDetails" + LocalDateTime.now());
29757 tejbeer 99
 
32048 tejbeer 100
    }
28921 tejbeer 101
 
36993 amit 102
    // Monthly margins CN dry-run at 06:00 on the 1st. dryRun=true forces the harmless dev path
103
    // (no IRN, no PDF, no DB persist, no partner mail) even on prod. The real pipeline is run
104
    // manually via `--sendCreditNote --live`.
105
    @Scheduled(cron = "0 0 6 1 * ?")
106
    public void monthlyMarginsCnDryRun() throws Exception {
107
 
108
        scheduledTasks.sendCreditNote(YearMonth.now().minusMonths(1), true);
109
 
110
    }
111
 
37234 vikas 112
    @Scheduled(cron = "0 30 6 * * *")
34648 ranu 113
    public void generateBiReport() throws Exception {
114
        scheduledTasksTest.generateBiReport();
115
    }
34939 ranu 116
    @Scheduled(cron = "0 30 4 * * *")
117
    public void createFofoSmartCartSuggestion() throws Exception {
118
        scheduledTasksTest.createFofoSmartCartSuggestion();
119
    }
35980 amit 120
    /*@Scheduled(cron = "0 0 6,22 * * *")
34948 ranu 121
    public void sendAbmSmartCartReport() throws Exception {
122
        abmReportSender.sendAbmSmartCartReport();
35980 amit 123
    }*/
34648 ranu 124
 
32048 tejbeer 125
    @Scheduled(cron = "0 0 10,15,17 * * *")
126
    public void sendIndentTertiaryReport() throws Exception {
29757 tejbeer 127
 
32048 tejbeer 128
        scheduledTasks.sendIndentTertiary();
29757 tejbeer 129
 
32048 tejbeer 130
    }
28921 tejbeer 131
 
32048 tejbeer 132
    @Scheduled(cron = "0 0 6 * * *")
133
    public void checkPartnerActiveStoreByStatus() throws Exception {
29673 manish 134
 
32048 tejbeer 135
        scheduledTasks.checkPartnerActiveStore();
29673 manish 136
 
32048 tejbeer 137
    }
26790 tejbeer 138
 
37040 ranu 139
    @Scheduled(cron = "0 30 23 * * *")
140
    public void updatePartnerActivationTypeByMonthlySale() throws Exception {
141
 
142
        scheduledTasks.updatePartnerActivationTypeByMonthlySale();
143
 
144
    }
145
 
37172 amit 146
    // 23:45 — after updatePartnerActivationTypeByMonthlySale (23:30), so the
147
    // REVIVAL agenda mirror reads today's activation_type state.
148
    @Scheduled(cron = "0 45 23 * * *")
149
    public void updatePjpAgendaInstances() throws Exception {
150
 
151
        scheduledTasks.updatePjpAgendaInstances();
152
 
153
    }
154
 
32048 tejbeer 155
    // @Scheduled(cron = "0 0 8 * * *")
156
    public void sendStockAgeingReport() throws Throwable {
29757 tejbeer 157
 
32048 tejbeer 158
        scheduledTasks.sendAgeingReport();
29757 tejbeer 159
 
32048 tejbeer 160
    }
24131 govind 161
 
32048 tejbeer 162
    @Scheduled(cron = "0 0 11 * * *")
163
    public void escalateTicket() throws Exception {
164
        log.info("escalate ticket");
165
        ticketRelatedScheduledTask.escalateTicket();
29757 tejbeer 166
 
32048 tejbeer 167
    }
24841 govind 168
 
32048 tejbeer 169
    @Scheduled(cron = "0 0 11 * * *")
170
    public void alertTicketToUser() throws Exception {
171
        log.info("alert for ticket");
29673 manish 172
 
32048 tejbeer 173
        ticketRelatedScheduledTask.alertforTicket();
29673 manish 174
 
32048 tejbeer 175
    }
24841 govind 176
 
37499 ranu 177
    /**
178
     * Hits ICICI Lombard "Get Last Twenty Five Transactions" twice a day (14:00 and 22:00 IST)
179
     * to log our CDBG account's current available balance + last 25 transactions.
180
     * First iteration: log-only so we can eyeball the response format. Persisting / alerting
181
     * on balance drops can be added once we agree on the shape.
182
     */
183
   /* @Scheduled(cron = "0 0 14,22 * * *")
184
    public void fetchIciciCdBalance() throws Exception {
185
        log.info("Fetching ICICI CD balance");
186
        LinkedHashMap<String, String> propertiesDetails = new LinkedHashMap<>();
187
        propertiesDetails.put("fetchIciciCdBalance", "0");
188
        writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosCronPropertiesFile);
189
 
190
        try {
191
            LastTransactionsResponseModel response = iciciLombardService.getLastTwentyFiveTransactions(null);
192
            log.info("ICICI CD balance response: {}", response);
193
            if (response != null
194
                    && response.getTransactionsDetails() != null
195
                    && !response.getTransactionsDetails().isEmpty()) {
196
                LastTransactionsResponseModel.TransactionDetail latest = response.getTransactionsDetails().get(0);
197
                log.info("ICICI CD current available balance = {} (as of {} — status: {})",
198
                        latest.getAvailableBalance(),
199
                        latest.getEffectiveDate(),
200
                        latest.getStatus());
201
                log.info("ICICI CD last 25 transactions -> {}", response.getTransactionsDetails());
202
            } else {
203
                log.warn("ICICI returned empty transactions_details. status={}, statusMessage={}, message={}",
204
                        response == null ? null : response.getStatus(),
205
                        response == null ? null : response.getStatusMessage(),
206
                        response == null ? null : response.getMessage());
207
            }
208
        } catch (Exception e) {
209
            log.error("Failed to fetch ICICI CD balance", e);
210
        }
211
 
212
        propertiesDetails.put("fetchIciciCdBalance", "1");
213
        writeToPropertiesFile.saveParamChanges(propertiesDetails, nagiosCronPropertiesFile);
214
    }*/
215
 
34904 ranu 216
    //@Scheduled(cron = "0 0 14,18,23 ? * *")
32048 tejbeer 217
    public void dailySaleNotification() throws Exception {
218
        log.info("daily send Notification");
29673 manish 219
 
32048 tejbeer 220
        scheduledTasks.sendDailySalesNotificationToPartner(null);
29757 tejbeer 221
 
32048 tejbeer 222
    }
24841 govind 223
 
32048 tejbeer 224
    /*
225
     * @Scheduled(cron = "0 0 6 * * *") public void dailyReconciliation() throws
226
     * Exception { reconciliation.dailyReconciliation(); }
227
     */
28205 tejbeer 228
 
32048 tejbeer 229
    @Scheduled(cron = "0 0 1 * * *")
230
    public void selectFinServiceFollowUpDateByCurrDate() throws Exception {
231
        log.info("selectFinServiceFollowUpDateByCurrDate");
232
        scheduledTasks.selectFinServiceFollowUpDateByCurrDate(LocalDate.now());
30049 amit.gupta 233
 
32048 tejbeer 234
    }
30049 amit.gupta 235
 
32165 amit.gupta 236
    @Scheduled(cron = "0 0 4 * * *")
32048 tejbeer 237
    public void processActivation() throws Exception {
29757 tejbeer 238
 
32048 tejbeer 239
        scheduledTasks.processActivation();
29757 tejbeer 240
 
32048 tejbeer 241
    }
25721 tejbeer 242
 
32048 tejbeer 243
    // TODO: Change it back to first of every month
244
    // @Scheduled(cron = "0 0 1 1 * *")
245
    @Scheduled(cron = "0 0 1 2 * *")
246
    public void rollOutUpgardedMargins() throws Exception {
35522 amit 247
        scheduledTasks.rollOutUpgardedMarginsNextMonth(null);
30788 amit.gupta 248
 
32048 tejbeer 249
    }
30788 amit.gupta 250
 
34241 tejus.loha 251
    @Scheduled(fixedDelay = 60 * 1000)
32048 tejbeer 252
    public void sendNotification() throws Throwable {
29757 tejbeer 253
 
32048 tejbeer 254
        log.info("send Notification");
29673 manish 255
 
32048 tejbeer 256
        scheduledTasks.sendNotification();
257
        log.info("send Notification Done");
29673 manish 258
 
32048 tejbeer 259
    }
28205 tejbeer 260
 
34669 amit.gupta 261
    //@Scheduled(cron = "0 */15 * * * *")
32048 tejbeer 262
    public void checkRazorPayPaymentStatus() throws Throwable {
29757 tejbeer 263
 
32048 tejbeer 264
        scheduledTasks.checkRazorPayPaymentStatus();
29673 manish 265
 
32048 tejbeer 266
    }
28377 tejbeer 267
 
36292 amit 268
    @Scheduled(fixedDelay = 5 * 1000)
33426 amit.gupta 269
    //@Scheduled(cron = "0 5 23 * * *")
32048 tejbeer 270
    public void updateIrnsToInvoices() throws Throwable {
271
        runOnceTasks.updateIrnsToInvoices();
272
    }
31612 tejbeer 273
 
35568 amit 274
    // REMOVED: ticketClosed() scheduler - now handled by TicketRelatedScheduledTask.autoCloseResolvedTickets()
275
    // which uses 8 working days instead of 7 calendar days and runs as part of processAllTicketTasks()
26283 tejbeer 276
 
32048 tejbeer 277
    @Scheduled(cron = "0 0 8 * * *")
278
    public void checkfocusedModelInPartnerStock() throws Throwable {
279
        log.info("startTime" + LocalDateTime.now());
29757 tejbeer 280
 
32048 tejbeer 281
        scheduledTasks.checkfocusedModelInPartnerStock();
25721 tejbeer 282
 
32048 tejbeer 283
        log.info("endTime" + LocalDateTime.now());
284
    }
28205 tejbeer 285
 
32048 tejbeer 286
    @Scheduled(cron = "0 0 8,10,12,14,16,18,20 * * *")
287
    public void notifyLead() throws Throwable {
29757 tejbeer 288
 
32048 tejbeer 289
        scheduledTasks.notifyLead();
29757 tejbeer 290
 
32048 tejbeer 291
        // scheduledTasks.notifyVisits();
292
    }
25721 tejbeer 293
 
32411 amit.gupta 294
    @Scheduled(cron = "0 0 7 * * *")
295
    //Send all lead owners the report for scheduled followups missed
296
    public void sendUnscheduledFollowUpMail() throws Exception {
297
        scheduledTasks.sendUnscheduledFollowUpMail();
298
    }
299
 
32048 tejbeer 300
    @Scheduled(cron = "0 0 1 * * *")
301
    public void checkValidateReferral() throws Throwable {
302
        log.info("startTime" + LocalDateTime.now());
29673 manish 303
 
32048 tejbeer 304
        scheduledTasks.checkValidateReferral();
29757 tejbeer 305
 
32048 tejbeer 306
        log.info("endTime" + LocalDateTime.now());
307
    }
26790 tejbeer 308
 
32048 tejbeer 309
    // @Scheduled(cron = "0 0 8 * * *")
310
    public void partnerProblemAlert() throws Throwable {
311
        log.info("startTime" + LocalDateTime.now());
29673 manish 312
 
32048 tejbeer 313
        scheduledTasks.partnerProblemAlert();
29673 manish 314
 
32048 tejbeer 315
        log.info("endTime" + LocalDateTime.now());
316
    }
28921 tejbeer 317
 
35109 ranu 318
    @Scheduled(cron = "0 0 10 * * *")
32048 tejbeer 319
    public void onboardingEventDelays() throws Throwable {
320
        log.info("startTime" + LocalDateTime.now());
29757 tejbeer 321
 
32048 tejbeer 322
        onBoardingRelatedSchelduleTask.onboardingEventDelays();
29757 tejbeer 323
 
32048 tejbeer 324
        log.info("endTime" + LocalDateTime.now());
325
    }
28921 tejbeer 326
 
36065 aman 327
    @Scheduled(cron = "0 30 10 * * *")
328
    public void sendStockDeliveredTrainingNotification() {
329
        log.info("sendStockDeliveredTrainingNotification startTime " + LocalDateTime.now());
330
        onBoardingRelatedSchelduleTask.sendStockDeliveredTrainingNotification();
331
        log.info("sendStockDeliveredTrainingNotification endTime " + LocalDateTime.now());
332
    }
333
 
36003 aman 334
    @Scheduled(cron = "0 0 9 * * ?")
335
    public void sendDelayAlertEmail() {
336
        log.info("sendDelayAlertEmail startTime " + LocalDateTime.now());
337
        onBoardingRelatedSchelduleTask.sendDelayAlertEmail();
338
        log.info("sendDelayAlertEmail endTime " + LocalDateTime.now());
339
    }
340
 
32048 tejbeer 341
    @Scheduled(cron = "0 0 8 * * *")
342
    public void brandingAlert() throws Throwable {
343
        log.info("startTime" + LocalDateTime.now());
29673 manish 344
 
32048 tejbeer 345
        onBoardingRelatedSchelduleTask.brandingAlert();
29673 manish 346
 
32048 tejbeer 347
        log.info("endTime" + LocalDateTime.now());
348
    }
28921 tejbeer 349
 
32048 tejbeer 350
    @Scheduled(cron = "0 0 8 * * *")
351
    public void fullPaymentPendingAlert() throws Throwable {
352
        log.info("startTime" + LocalDateTime.now());
29757 tejbeer 353
 
32048 tejbeer 354
        onBoardingRelatedSchelduleTask.fullPaymentPendingAlert();
29757 tejbeer 355
 
32048 tejbeer 356
        log.info("endTime" + LocalDateTime.now());
357
    }
28921 tejbeer 358
 
32048 tejbeer 359
    @Scheduled(cron = "0 */5 * * * *")
360
    public void onBoardingCompleteEventEmail() throws Throwable {
361
        log.info("startTime" + LocalDateTime.now());
29673 manish 362
 
32048 tejbeer 363
        onBoardingRelatedSchelduleTask.onBoardingCompleteEventEmail();
29673 manish 364
 
32048 tejbeer 365
        log.info("endTime" + LocalDateTime.now());
366
    }
29040 tejbeer 367
 
32048 tejbeer 368
    @Scheduled(cron = "0 */5 * * * *")
369
    public void updateSaholicCISTable() throws Throwable {
370
        log.info("updateSaholicCISTable startTime" + LocalDateTime.now());
371
        runOnceTasks.updateSaholicCISTable();
372
        log.info("updateSaholicCISTable endTime" + LocalDateTime.now());
373
    }
30667 amit.gupta 374
 
34241 tejus.loha 375
    @Autowired
376
    PurSaleService purSaleService;
377
 
35133 ranu 378
    @Scheduled(cron = "0 0 6,22 * * ?")
34241 tejus.loha 379
    public void send10DaysEgedStockReport() throws Throwable {
34275 tejus.loha 380
        log.info("moreThen10DaysEgedStockReport startTime" + LocalDateTime.now());
381
        scheduledTasks.send10OrMoreOlderStockReport();
382
        log.info("moreThen10DaysEgedStockReport endTime" + LocalDateTime.now());
34241 tejus.loha 383
    }
384
 
35616 amit 385
    @Scheduled(fixedDelay = 5 * 60 * 1000)
32048 tejbeer 386
    public void fetchPartnerStat() throws Throwable {
387
        scheduledTasks.fetchParnterStats();
388
    }
30390 amit.gupta 389
 
37472 amit 390
    @Scheduled(cron = "0 0 23 * * *")
32214 jai.hind 391
    public void checkItelImeiActivationNew() throws Throwable {
392
        log.info("startTime" + LocalDate.now());
393
 
394
        log.info("startTimecheckItelImeiActivation" + LocalDate.now());
395
        scheduledTasks.checkItelImeiActivationNew(LocalDate.now(), 90);
396
        long secs = (new Date().getTime()) / 1000;
397
        log.info("endTimecheckItelImeiActivation" + LocalDate.now());
398
 
399
    }
400
 
37472 amit 401
    /**
402
     * Vivo: one full pass a day, then nothing until tomorrow.
403
     *
404
     * Was two parallel jobs every 5 minutes capped at 50 and 10 imeis, which never
405
     * finished a pass over a 9,510-row pool and retried a failed lookup five minutes
406
     * later instead of the next day. Vivo stays on its own schedule and its own thread:
407
     * it is direct HTTP plus the captcha solver, no ChromeDriver, so it does not
408
     * contend for the resource the oppo/realme pass is rationing.
409
     *
410
     * ~9,510 imeis at roughly 2.5s each is about 6.6 hours.
411
     */
37565 amit 412
    // One chunk of 250 every 20 seconds until the day's pool is empty, then idle ticks
413
    // until midnight. Was a single 00:15 pass; the method name is kept so the
414
    // cron_job_* series and anything keyed on it stay continuous.
415
    //
416
    // The 20s cadence is not a throttle -- vivo is 0.24s an imei and does not rate-limit
417
    // us. It is what makes progress durable: the old pass held one thread for its whole
418
    // run and kept its position nowhere else, so a restart mid-pass forfeited the rest.
419
    @Scheduled(fixedDelay = 20 * 1000)
32048 tejbeer 420
    public void vivoImeiActivation() throws Throwable {
421
        scheduledTasks.checkImeiActivation();
422
    }
29255 tejbeer 423
 
37482 amit 424
    /**
425
     * Itel activation from Carlcare, Transsion's own after-sales endpoint. 50 imeis every 5
426
     * minutes, which spreads the work over the whole day rather than bursting: 14,400 lookups a
427
     * day against a pending pool of ~10,400.
428
     *
429
     * The 5-minute cadence is safe here in a way it was not for vivo, whose comment below records
430
     * why that pattern ran away: there, a failed lookup wrote no row, so createTimestamp was not
431
     * bumped and the same imei was eligible again five minutes later. This service stamps the row
432
     * on EVERY outcome, failures included, so each tick advances past the imeis it asked about
433
     * and a failure costs one retry tomorrow rather than one every five minutes.
434
     *
435
     * It is one plain signed GET per imei -- no captcha solver, no ChromeDriver -- so it does not
436
     * contend with the oppo/realme pass. Both this and the 23:00 DCR pull write Itel rows and
437
     * need no coordination: the pool query returns only imeis whose activationTimestamp is still
438
     * null, so whatever one has filled has already left the other's pool.
439
     */
440
    @Scheduled(fixedDelay = 5 * 60 * 1000)
441
    public void carlcareImeiActivation() throws Throwable {
442
        scheduledTasks.checkCarlcareImeiActivation();
443
    }
444
 
32048 tejbeer 445
    @Scheduled(cron = "0 0 8 * * *")
446
    public void reviewUncontactablePartner() throws Throwable {
447
        log.info("startTime" + LocalDateTime.now());
30421 tejbeer 448
 
32048 tejbeer 449
        scheduledTasks.reviewUncontactablePartner();
30421 tejbeer 450
 
32048 tejbeer 451
    }
30421 tejbeer 452
 
33928 ranu 453
    @Scheduled(cron = "0 0 7 * * *")
454
    public void setMovementWiseRbmTodayTargets() throws Throwable {
34669 amit.gupta 455
        log.info("today targets startTime {}", LocalDateTime.now());
33928 ranu 456
 
457
        scheduledTasks.persistRbmTodayTargets();
458
 
459
    }
460
 
33986 ranu 461
    @Scheduled(cron = "0 0 21 * * *")
462
    public void setMovementWiseRbmTodayAchievements() throws Throwable {
34669 amit.gupta 463
        log.info("today achievement startTime {}", LocalDateTime.now());
33986 ranu 464
 
465
        scheduledTasks.persistRbmTodayAchievements();
466
 
467
    }
468
 
37499 ranu 469
    // Sales-hierarchy target snapshot — runs 10 minutes after RBM targets so
470
    // today's rbm_targets rows are guaranteed present for the roll-up.
471
    @Scheduled(cron = "0 10 7 * * *")
472
    public void setSalesTodayTargets() throws Throwable {
473
        log.info("sales today targets startTime {}", LocalDateTime.now());
474
 
475
        scheduledTasks.persistSalesTodayTargets();
476
 
477
    }
478
 
479
    // Sales-hierarchy achievement snapshot — independent of the target chain;
480
    // rolls up live order ACH so it can run any time after orders settle.
481
    // Kept aligned with RBM achievement time (21:00).
482
    @Scheduled(cron = "0 10 21 * * *")
483
    public void setSalesTodayAchievements() throws Throwable {
484
        log.info("sales today achievement startTime {}", LocalDateTime.now());
485
 
486
        scheduledTasks.persistSalesTodayAchievements();
487
 
488
    }
489
 
33078 ranu 490
    @Scheduled(cron = "0 0 8 * * *")
491
    public void reviewNonSdBuyingBrand() throws Throwable {
492
        log.info("startTime" + LocalDateTime.now());
493
 
494
        scheduledTasks.reviewNonSdBuyingBrand();
495
 
496
    }
497
 
32048 tejbeer 498
    @Autowired
499
    private StandAlone standAlone;
30352 amit.gupta 500
 
32832 amit.gupta 501
    @Autowired
502
    OrderTrackingService orderTrackingService;
503
 
37472 amit 504
    // ONE thread, ONE full pass a day, for oppo and realme together.
505
    //
506
    // This replaces four @Scheduled jobs (oppo and realme x secondary and tertiary,
507
    // every 5 minutes), and it supersedes the r37447 / r37448 / r37449 argument about
508
    // how many ChromeDrivers to run. That argument was about the wrong variable.
509
    //
510
    // The revert in r37449 was sized on lookups ATTEMPTED per day, and the re-merge that
511
    // followed blamed the resulting collapse on CPU contention pushing the captcha
512
    // render past the element waits. The logs do not support contention:
513
    //
514
    //   29 Aug        imeis   canvas timeouts   captcha ok   distinct imeis   asks each
515
    //   oppo          4,350                 0       ~100%            4,238        1.03
516
    //   realme        4,524             3,390         19%            1,004        4.50
517
    //
518
    // Same box, same six cores, same driver count, same captcha vendor, load average
519
    // 0.9 -- and oppo took ZERO timeouts in all 24 hours, including the 15:00-23:00
520
    // window in which realme solved nothing at all. Realme's own canvas wait is 15s
521
    // against oppo's 8s, so the LONGER wait is the one expiring.
522
    //
523
    // What realme's timeout rate actually tracks is its own daily request volume, and
524
    // it resets at midnight: 920/day -> 0.3%, 3,467/day -> 28%, 4,524/day -> 75%. That
525
    // is realme.com declining to serve the widget, not a busy box.
526
    //
527
    // The 4.5 asks per imei is why it ran away. A failed lookup never reaches
528
    // dateMap.put, so no row is written, so createTimestamp is not bumped, so the same
529
    // imei was eligible again five minutes later -- more requests hardened the block,
530
    // which caused more failures, which caused more requests. A snapshotted daily pass
531
    // bounds that by construction: a failure costs one retry tomorrow, never one in
532
    // five minutes, however the far end behaves.
533
    //
534
    // Judge this change on dates written, not on timeout count.
37565 amit 535
    // One chunk of 25 for one brand every 20 seconds, oppo and realme by turns, until
536
    // both pools are empty for the day. Was a single 00:30 pass that held this thread for
537
    // 20+ hours; the method name is kept so the cron_job_* series stays continuous.
538
    //
539
    // fixedDelay, not fixedRate: the gap is measured from the END of a tick, so a chunk
540
    // that takes six minutes is not immediately followed by a queued one. The lane
541
    // self-throttles to whatever the far ends are actually giving us.
542
    //
543
    // The start/end log lines are gone deliberately -- at 4,320 ticks a day they were
544
    // pure volume on a log that is already 1.8GB. StandAlone logs the day boundary and
545
    // the chunks; idle ticks say nothing at all.
546
    @Scheduled(fixedDelay = 20 * 1000)
37472 amit 547
    public void oppoRealmeImeiActivation() throws Throwable {
548
        standAlone.checkBrowserImeiActivation();
34421 amit.gupta 549
    }
550
 
32801 amit.gupta 551
    @Scheduled(cron = "0 0 * * * *")
32048 tejbeer 552
    public void markBlueDartOrderDelivered() throws Throwable {
553
        log.info("startTime" + LocalDateTime.now());
32832 amit.gupta 554
        orderTrackingService.markBlueDartOrderDelivered();
32048 tejbeer 555
        log.info("endTime" + LocalDateTime.now());
556
    }
31117 tejbeer 557
 
32881 amit.gupta 558
    @Scheduled(cron = "0 15 * * * *")
32048 tejbeer 559
    public void markDelhiveryOrderDelivered() throws Throwable {
29673 manish 560
 
32048 tejbeer 561
        log.info("startTime" + LocalDateTime.now());
32832 amit.gupta 562
        orderTrackingService.markDelhiveryOrderDelivered();
29673 manish 563
 
32048 tejbeer 564
        log.info("endTime" + LocalDateTime.now());
565
    }
29308 tejbeer 566
 
32048 tejbeer 567
    @Scheduled(cron = "0 0 4 * * *")
568
    public void processPriceDrop() throws Throwable {
569
        scheduledTasks.processPriceDrop();
570
    }
30637 amit.gupta 571
 
32048 tejbeer 572
    @Scheduled(cron = "0 0 0 * * *")
573
    public void calculateInterestAccured() throws Throwable {
34710 amit.gupta 574
        scheduledTasks.loanSettlement();
32048 tejbeer 575
        scheduledTasks.calculateInterestAccured();
576
    }
30859 tejbeer 577
 
32117 tejbeer 578
    //  @Scheduled(cron = "0 */5 2-22 * * *")
33181 amit.gupta 579
    @Scheduled(fixedDelay = 1 * 60 * 1000)
32531 amit.gupta 580
    //@Scheduled(cron = "0 0 23 * * *")
32048 tejbeer 581
    public void loanSettlement() throws Throwable {
34756 amit.gupta 582
        LocalTime now = LocalTime.now();
34767 amit.gupta 583
        LocalTime start = LocalTime.of(9, 0);
34757 amit.gupta 584
        LocalTime end = LocalTime.of(23, 0);
34756 amit.gupta 585
 
586
        if (now.isBefore(start) || now.isAfter(end)) {
34762 amit.gupta 587
            System.out.println("Task skipped during restricted hours: " + now);
588
        } else {
34756 amit.gupta 589
            scheduledTasks.loanSettlement();
590
            System.out.println("Task executed at " + now);
591
        }
32048 tejbeer 592
    }
30859 tejbeer 593
 
32048 tejbeer 594
    @Scheduled(cron = "0 */15 * * * *")
595
    public void ccAvenueSettlement() throws Throwable {
596
        scheduledTasks.settleCCAvePayments();
597
    }
31332 amit.gupta 598
 
32048 tejbeer 599
    @Scheduled(cron = "0 0 6 * * *")
600
    public void dailyLoanAlert() throws Throwable {
601
        scheduledTasks.dailyLoanAlert();
602
    }
30896 amit.gupta 603
 
35106 ranu 604
    @Scheduled(cron = "0 0 11 * * *")
34162 ranu 605
    public void groupHidCatalogsByWeeks() throws Throwable {
606
        scheduledTasks.groupHidCatalogsByWeeks();
607
    }
608
 
36113 ranu 609
    @Scheduled(cron = "0 0 9 * * MON")  // Every Monday at 9:00 AM
34321 ranu 610
    public void sendFeebackSalesAndRbm() throws Throwable {
611
        scheduledTasksTest.sendRbmFeedbackSummaryEmail();
612
        scheduledTasksTest.sendSalesFeedbackSummaryEmail();
613
    }
614
 
32165 amit.gupta 615
    //Look out for imeis that have activation pending based of sale and mark create new SIO out of them
32048 tejbeer 616
    @Scheduled(cron = "0 0 1 * * *")
617
    public void processActivatedImeisForSchemes() throws Throwable {
618
        scheduledTasks.processActivatedImeisForSchemes();
619
    }
34241 tejus.loha 620
 
33357 amit.gupta 621
    //On every fifth update deductions
33435 amit.gupta 622
    @Scheduled(cron = "0 30 6 5 * ?")
33357 amit.gupta 623
    public void processSidbiDeductions() throws Throwable {
624
        scheduledTasks.processSidbiDeductions();
625
    }
34669 amit.gupta 626
 
34374 amit.gupta 627
    //Dont reset it for now as proposed by TV
628
    //@Scheduled(cron = "0 30 6 4 * ?")
33904 amit.gupta 629
    public void resetHardLimit() throws Throwable {
630
        scheduledTasks.resetHardLimit();
631
    }
632
 
37589 amit 633
    /**
634
     * Investment snapshot for every active partner, then the credit limit for the partners whose
37595 amit 635
     * base moved. This is the path that keeps limits current: it replaces the 20-minute full rescan,
636
     * so a limit follows a payment within ~2 minutes instead of up to 20 — which matters because a
637
     * quarter of advance payments are followed by an order within five minutes.
638
     *
639
     * <p>Measured on production: ~3 partners per 2-minute window show a changed base (peak 18), so
640
     * the limit work behind this is a handful of rows rather than a 980-partner scan.
37589 amit 641
     */
642
    @Scheduled(cron = "0 0/2 * * * *")
643
    public void sweepPartnerInvestment() throws Throwable {
644
        batchScheduledTasks.sweepPartnerInvestment();
645
    }
646
 
647
    /**
37595 amit 648
     * Daily: refresh the time-driven haircuts, then run a full limit pass.
649
     *
650
     * <p>The 2-minute sweep already recalculates the limit for every partner whose base moved, which
651
     * covers investment and utilisation. The full pass exists only for inputs the base cannot see —
652
     * credit risk, the SIDBI floor and hard_limit — and those move on a far slower clock: risk
653
     * decays on a 90-day threshold, and the SIDBI sanction table has had no new row since Oct 2024
654
     * and no recorded settlement. Running a 980-partner rescan every 20 minutes to catch that was 72
655
     * wasted passes a day.
656
     *
657
     * <p>Order matters: the haircut refresh changes base for the partners whose Apple or demo stock
658
     * crossed its threshold overnight, so the limit pass runs after it and sees the new values.
37589 amit 659
     */
660
    @Scheduled(cron = "0 20 0 * * *")
661
    public void refreshAgedStockDaily() throws Throwable {
662
        batchScheduledTasks.refreshAgedStockDaily();
37595 amit 663
        batchScheduledTasks.updatePartnerLimitWithBatch();
37589 amit 664
    }
665
 
37642 amit 666
    /**
667
     * Hourly at :40 — close out batches left RUNNING by a run that died mid-loop, so they
668
     * raise their alert and stop blocking the job from running again. No-ops when clean.
669
     */
670
    @Scheduled(cron = "0 40 * * * *")
671
    public void reapStaleCronBatches() {
672
        try {
673
            batchScheduledTasks.reapStaleBatches();
674
        } catch (Exception e) {
675
            log.error("reapStaleBatches failed: {}", e.getMessage(), e);
676
        }
677
    }
678
 
34253 ranu 679
    @Scheduled(cron = "0 0 9,14,18 * * *")
33874 ranu 680
    public void createOpeningStockPartyWise() throws Throwable {
681
        scheduledTasks.createOpeningStockPartyWise();
682
    }
30936 tejbeer 683
 
32842 amit.gupta 684
    //Loans due/overdue/default notifications sent to parnters
685
    @Scheduled(cron = "0 0 11 * * *")
32822 ranu 686
    public void sendMailWhatsAppAfterLoanDueDate() throws Throwable {
687
        scheduledTasks.sendMailWhatsAppAfterLoanDueDate();
688
    }
34241 tejus.loha 689
 
32842 amit.gupta 690
    @Scheduled(cron = "0 0 8 * * *")
691
    public void alertForDueDate() throws Throwable {
692
        scheduledTasks.alertForDueDate();
693
    }
32822 ranu 694
 
35133 ranu 695
    @Scheduled(cron = "0 0 4,21 * * *")
32048 tejbeer 696
    public void notifyLoanDueDateCross() throws Throwable {
697
        scheduledTasks.notifyLoanDueDateCross();
698
    }
30936 tejbeer 699
 
35133 ranu 700
    @Scheduled(cron = "0 0 4,21 * * *")
32048 tejbeer 701
    public void notifyDefaultLoans() throws Throwable {
702
        scheduledTasks.notifyDefaultLoans();
703
    }
30936 tejbeer 704
 
34910 ranu 705
   // @Scheduled(cron = "0 0 23 * * *")
32048 tejbeer 706
    public void hygineAlertForInternalTeam() throws Throwable {
707
        scheduledTasks.hygineAlertForInternalTeam();
31206 tejbeer 708
 
32048 tejbeer 709
    }
31206 tejbeer 710
 
32048 tejbeer 711
    @Scheduled(cron = "0 0 23 * * *")
712
    public void hygineAlertForPartner() throws Throwable {
713
        scheduledTasks.hygineAlertForPartner();
31206 tejbeer 714
 
32048 tejbeer 715
    }
31206 tejbeer 716
 
32048 tejbeer 717
    @Scheduled(cron = "0 0 0 * * MON")
718
    public void monthlyTargetForPartner() throws Throwable {
719
        scheduledTasks.monthlyTargetForPartner();
31249 tejbeer 720
 
32048 tejbeer 721
    }
31249 tejbeer 722
 
32048 tejbeer 723
    @Scheduled(cron = "0 0 0 * * MON")
724
    public void monthlyTargetForInternalTeam() throws Throwable {
725
        scheduledTasks.monthlyTargetForInternalTeam();
31249 tejbeer 726
 
32048 tejbeer 727
    }
31612 tejbeer 728
 
32048 tejbeer 729
    @Scheduled(cron = "0 0 6 * * *")
730
    public void sendSamsungRebilling() throws Throwable {
731
        scheduledTasks.sendMailForSamsungRebilling();
732
    }
31931 amit.gupta 733
 
32048 tejbeer 734
    @Scheduled(cron = "0 10 8 * * *")
735
    public void sendMailForAgeingAlert() throws Throwable {
736
        scheduledTasks.sendMailForAgeingAlert();
737
    }
738
 
739
    @Scheduled(cron = "0 0 8 * * *")
740
    public void sendFilteredRetailerPerformance() throws Throwable {
741
        scheduledTasks.sendFilteredRetailerPerformance();
742
    }
32690 amit.gupta 743
 
33444 ranu 744
    @Scheduled(cron = "0 0 0 * * MON")
745
    public void findAllLiveDemoBrandItemsByBillingDate() throws Throwable {
746
        scheduledTasks.findAllLiveDemoBrandItemsByBillingDate();
747
    }
34241 tejus.loha 748
 
33464 ranu 749
    @Scheduled(cron = "0 10 6 * * *")
750
    public void findTodayPocoBillingItems() throws Throwable {
751
        scheduledTasks.findTodayPocoBillingItems();
752
    }
32690 amit.gupta 753
 
754
    @Scheduled(cron = "0 0 12 * * *")
755
    public void rejectPriceDropsOfApprovedImeis() throws Throwable {
37083 amit 756
        batchScheduledTasks.reprocessPriceDropsWithBatch();
32690 amit.gupta 757
    }
32907 amit.gupta 758
 
759
    @Autowired
760
    POScheduler poScheduler;
34241 tejus.loha 761
 
32907 amit.gupta 762
    @Scheduled(cron = "0 0 1 * * *")
33643 amit.gupta 763
    public void autoClosePO() {
32907 amit.gupta 764
        poScheduler.autoClosePurchaseOrders();
765
    }
32048 tejbeer 766
    /*
767
     * @Scheduled(cron = "0 0 9 * * *") public void onBoardingDocumentsPending()
768
     * throws Throwable { log.info("startTime" + LocalDateTime.now());
769
     * onBoardingRelatedSchelduleTask.onBoardingDocumentsPending();
770
     * log.info("endTime" + LocalDateTime.now()); }
771
     */
34443 vikas.jang 772
 
34547 vikas.jang 773
    @Scheduled(cron = "0 50 23 * * *")
34443 vikas.jang 774
    public void bidConfirmation() throws Throwable {
34547 vikas.jang 775
        log.info("running bid cron at 23:50PM");
34443 vikas.jang 776
        runOnceTasks.processBids(ProfitMandiConstants.BID_CRON_ENUM.YESTERDAY);
777
    }
778
 
34547 vikas.jang 779
    @Scheduled(cron = "0 0 19 * * *")
34443 vikas.jang 780
    public void processLiquidationBids() throws Throwable {
34547 vikas.jang 781
        log.info("running bid cron at 07:00PM");
34443 vikas.jang 782
        runOnceTasks.processBids(ProfitMandiConstants.BID_CRON_ENUM.TODAY);
783
    }
784
 
34547 vikas.jang 785
    @Scheduled(cron = "0 30 21 * * *")
34443 vikas.jang 786
    public void bidPurchaseOrder() throws Throwable {
34547 vikas.jang 787
        log.info("running bid cron at 09:30PM");
34443 vikas.jang 788
        runOnceTasks.processBids(ProfitMandiConstants.BID_CRON_ENUM.TODAY);
789
    }
34547 vikas.jang 790
 
34669 amit.gupta 791
    /*@Scheduled(cron = "0 0 12 * * *")
792
    public void processCashDiscount() throws Throwable {
793
        scheduledTasks.processCashDiscount();
794
    }*/
795
 
34563 vikas.jang 796
    @Scheduled(cron = "0 0 9,17 * * *")
34547 vikas.jang 797
    public void bidConsolidatedMessage() throws Throwable {
798
        log.info("Running bid cron at 09:00 AM or 05:00 PM");
799
        runOnceTasks.consolidatedBiddingMessage();
34563 vikas.jang 800
    }
34770 vikas.jang 801
 
802
    @Scheduled(cron = "0 0 8 * * *")
34836 vikas 803
    public void yesterdayTrackingReport() throws Throwable {
804
        log.info("Running yesterday employee tracking cron at 08:00 AM");
805
        runOnceTasks.yesterdayTrackingReport();
34770 vikas.jang 806
    }
34836 vikas 807
 
35178 amit 808
    @Scheduled(cron = "0 10 8 * * *")
35177 amit 809
    public void partnerCreditExposureReport() throws Throwable {
810
        log.info("Running yesterday employee tracking cron at 08:00 AM");
811
        runOnceTasks.sendCreditExposureReport();
812
    }
813
 
36552 ranu 814
    @Scheduled(cron = "0 0 22,16 * * *")
34836 vikas 815
    public void dailyTrackingReport() throws Throwable {
36552 ranu 816
        log.info("Running daily employee tracking cron at 10:00 PM and 04:00 PM");
34836 vikas 817
        runOnceTasks.dailyTrackingReport();
818
    }
35105 vikas 819
 
34792 amit.gupta 820
    @Scheduled(cron = "0 0 0 1 1,4,7,10 *")
821
    public void sendUpdateMobileBrandMarketShareQuaterlyMail() throws Throwable {
34791 aman.kumar 822
        log.info("Running Marketshare update remined quaterly");
823
        scheduledTasks.sendUpdateMobileBrandMarketShareQuaterlyMail();
824
    }
35105 vikas 825
 
826
    @Scheduled(cron = "0 0 * * * *")
827
    public void checkRewardsEligibility() throws Throwable {
828
        log.info("Running Rewards Disburse daily");
829
        runOnceTasks.checkRewardsEligibility();
830
    }
35326 amit 831
 
832
    @Scheduled(cron="0 0 20 * * *")
833
    public void sendTrialExpiry() {
834
        scheduledTasks.sendTrialExpiry();
835
    }
35666 vikas 836
 
837
    @Scheduled(cron = "0 0 0 * * *")
838
    public void fetchOffersByItem() {
839
        scheduledTasks.cachePinelabsOffers();
840
    }
35788 vikas 841
 
842
    @Scheduled(cron = "0 0 0 * * *")
843
    public void syncProductsToShopify() throws Exception {
36058 ranu 844
        scheduledTasks.syncProductsToShopifyByWarehouseId(ProfitMandiConstants.WAREHOUSE_NAME_MAP.get("UP-WEST/NOIDA"));
35788 vikas 845
    }
36511 amit 846
 
37162 vikas 847
    @Scheduled(cron = "0 0 6,18 * * *")
848
    public void syncInventoryToShopify() throws Exception {
849
        scheduledTasks.syncInventoryToShopifyByWarehouseId(ProfitMandiConstants.WAREHOUSE_NAME_MAP.get("UP-WEST/NOIDA"));
850
    }
851
 
36511 amit 852
    @Autowired
853
    private WarehouseStockReconciliation warehouseStockReconciliation;
854
 
855
    @Scheduled(cron = "0 30 5 * * *")
856
    public void reconcileInventorySnapshot() throws Exception {
857
        log.info("reconcileInventorySnapshot");
858
        warehouseStockReconciliation.reconcile();
859
    }
37159 amit 860
 
861
    @Autowired
862
    private PartnerIdentityIntegrityMonitor partnerIdentityIntegrityMonitor;
863
 
864
    @Scheduled(cron = "0 0 7 * * *")
865
    public void partnerIdentityIntegrityMonitor() throws Exception {
866
        log.info("partnerIdentityIntegrityMonitor");
867
        partnerIdentityIntegrityMonitor.monitor();
868
    }
23756 amit.gupta 869
}