Subversion Repositories SmartDukaan

Rev

Rev 37642 | Rev 37735 | 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
 
32048 tejbeer 274
    // No longer needed
275
    // @Scheduled(cron = "0 */10 * * * *")
276
    public void attachToffeeInvoices() throws Throwable {
29757 tejbeer 277
 
32048 tejbeer 278
        scheduledTasks.attachToffeeInvoices();
29757 tejbeer 279
 
32048 tejbeer 280
    }
24841 govind 281
 
35568 amit 282
    // REMOVED: ticketClosed() scheduler - now handled by TicketRelatedScheduledTask.autoCloseResolvedTickets()
283
    // which uses 8 working days instead of 7 calendar days and runs as part of processAllTicketTasks()
26283 tejbeer 284
 
32048 tejbeer 285
    @Scheduled(cron = "0 0 8 * * *")
286
    public void checkfocusedModelInPartnerStock() throws Throwable {
287
        log.info("startTime" + LocalDateTime.now());
29757 tejbeer 288
 
32048 tejbeer 289
        scheduledTasks.checkfocusedModelInPartnerStock();
25721 tejbeer 290
 
32048 tejbeer 291
        log.info("endTime" + LocalDateTime.now());
292
    }
28205 tejbeer 293
 
32048 tejbeer 294
    @Scheduled(cron = "0 0 8,10,12,14,16,18,20 * * *")
295
    public void notifyLead() throws Throwable {
29757 tejbeer 296
 
32048 tejbeer 297
        scheduledTasks.notifyLead();
29757 tejbeer 298
 
32048 tejbeer 299
        // scheduledTasks.notifyVisits();
300
    }
25721 tejbeer 301
 
32411 amit.gupta 302
    @Scheduled(cron = "0 0 7 * * *")
303
    //Send all lead owners the report for scheduled followups missed
304
    public void sendUnscheduledFollowUpMail() throws Exception {
305
        scheduledTasks.sendUnscheduledFollowUpMail();
306
    }
307
 
32048 tejbeer 308
    @Scheduled(cron = "0 0 1 * * *")
309
    public void checkValidateReferral() throws Throwable {
310
        log.info("startTime" + LocalDateTime.now());
29673 manish 311
 
32048 tejbeer 312
        scheduledTasks.checkValidateReferral();
29757 tejbeer 313
 
32048 tejbeer 314
        log.info("endTime" + LocalDateTime.now());
315
    }
26790 tejbeer 316
 
32048 tejbeer 317
    // @Scheduled(cron = "0 0 8 * * *")
318
    public void partnerProblemAlert() throws Throwable {
319
        log.info("startTime" + LocalDateTime.now());
29673 manish 320
 
32048 tejbeer 321
        scheduledTasks.partnerProblemAlert();
29673 manish 322
 
32048 tejbeer 323
        log.info("endTime" + LocalDateTime.now());
324
    }
28921 tejbeer 325
 
35109 ranu 326
    @Scheduled(cron = "0 0 10 * * *")
32048 tejbeer 327
    public void onboardingEventDelays() throws Throwable {
328
        log.info("startTime" + LocalDateTime.now());
29757 tejbeer 329
 
32048 tejbeer 330
        onBoardingRelatedSchelduleTask.onboardingEventDelays();
29757 tejbeer 331
 
32048 tejbeer 332
        log.info("endTime" + LocalDateTime.now());
333
    }
28921 tejbeer 334
 
36065 aman 335
    @Scheduled(cron = "0 30 10 * * *")
336
    public void sendStockDeliveredTrainingNotification() {
337
        log.info("sendStockDeliveredTrainingNotification startTime " + LocalDateTime.now());
338
        onBoardingRelatedSchelduleTask.sendStockDeliveredTrainingNotification();
339
        log.info("sendStockDeliveredTrainingNotification endTime " + LocalDateTime.now());
340
    }
341
 
36003 aman 342
    @Scheduled(cron = "0 0 9 * * ?")
343
    public void sendDelayAlertEmail() {
344
        log.info("sendDelayAlertEmail startTime " + LocalDateTime.now());
345
        onBoardingRelatedSchelduleTask.sendDelayAlertEmail();
346
        log.info("sendDelayAlertEmail endTime " + LocalDateTime.now());
347
    }
348
 
32048 tejbeer 349
    @Scheduled(cron = "0 0 8 * * *")
350
    public void brandingAlert() throws Throwable {
351
        log.info("startTime" + LocalDateTime.now());
29673 manish 352
 
32048 tejbeer 353
        onBoardingRelatedSchelduleTask.brandingAlert();
29673 manish 354
 
32048 tejbeer 355
        log.info("endTime" + LocalDateTime.now());
356
    }
28921 tejbeer 357
 
32048 tejbeer 358
    @Scheduled(cron = "0 0 8 * * *")
359
    public void fullPaymentPendingAlert() throws Throwable {
360
        log.info("startTime" + LocalDateTime.now());
29757 tejbeer 361
 
32048 tejbeer 362
        onBoardingRelatedSchelduleTask.fullPaymentPendingAlert();
29757 tejbeer 363
 
32048 tejbeer 364
        log.info("endTime" + LocalDateTime.now());
365
    }
28921 tejbeer 366
 
32048 tejbeer 367
    @Scheduled(cron = "0 */5 * * * *")
368
    public void onBoardingCompleteEventEmail() throws Throwable {
369
        log.info("startTime" + LocalDateTime.now());
29673 manish 370
 
32048 tejbeer 371
        onBoardingRelatedSchelduleTask.onBoardingCompleteEventEmail();
29673 manish 372
 
32048 tejbeer 373
        log.info("endTime" + LocalDateTime.now());
374
    }
29040 tejbeer 375
 
32048 tejbeer 376
    @Scheduled(cron = "0 */5 * * * *")
377
    public void updateSaholicCISTable() throws Throwable {
378
        log.info("updateSaholicCISTable startTime" + LocalDateTime.now());
379
        runOnceTasks.updateSaholicCISTable();
380
        log.info("updateSaholicCISTable endTime" + LocalDateTime.now());
381
    }
30667 amit.gupta 382
 
34241 tejus.loha 383
    @Autowired
384
    PurSaleService purSaleService;
385
 
35133 ranu 386
    @Scheduled(cron = "0 0 6,22 * * ?")
34241 tejus.loha 387
    public void send10DaysEgedStockReport() throws Throwable {
34275 tejus.loha 388
        log.info("moreThen10DaysEgedStockReport startTime" + LocalDateTime.now());
389
        scheduledTasks.send10OrMoreOlderStockReport();
390
        log.info("moreThen10DaysEgedStockReport endTime" + LocalDateTime.now());
34241 tejus.loha 391
    }
392
 
35616 amit 393
    @Scheduled(fixedDelay = 5 * 60 * 1000)
32048 tejbeer 394
    public void fetchPartnerStat() throws Throwable {
395
        scheduledTasks.fetchParnterStats();
396
    }
30390 amit.gupta 397
 
37472 amit 398
    @Scheduled(cron = "0 0 23 * * *")
32214 jai.hind 399
    public void checkItelImeiActivationNew() throws Throwable {
400
        log.info("startTime" + LocalDate.now());
401
 
402
        log.info("startTimecheckItelImeiActivation" + LocalDate.now());
403
        scheduledTasks.checkItelImeiActivationNew(LocalDate.now(), 90);
404
        long secs = (new Date().getTime()) / 1000;
405
        log.info("endTimecheckItelImeiActivation" + LocalDate.now());
406
 
407
    }
408
 
37472 amit 409
    /**
410
     * Vivo: one full pass a day, then nothing until tomorrow.
411
     *
412
     * Was two parallel jobs every 5 minutes capped at 50 and 10 imeis, which never
413
     * finished a pass over a 9,510-row pool and retried a failed lookup five minutes
414
     * later instead of the next day. Vivo stays on its own schedule and its own thread:
415
     * it is direct HTTP plus the captcha solver, no ChromeDriver, so it does not
416
     * contend for the resource the oppo/realme pass is rationing.
417
     *
418
     * ~9,510 imeis at roughly 2.5s each is about 6.6 hours.
419
     */
37565 amit 420
    // One chunk of 250 every 20 seconds until the day's pool is empty, then idle ticks
421
    // until midnight. Was a single 00:15 pass; the method name is kept so the
422
    // cron_job_* series and anything keyed on it stay continuous.
423
    //
424
    // The 20s cadence is not a throttle -- vivo is 0.24s an imei and does not rate-limit
425
    // us. It is what makes progress durable: the old pass held one thread for its whole
426
    // run and kept its position nowhere else, so a restart mid-pass forfeited the rest.
427
    @Scheduled(fixedDelay = 20 * 1000)
32048 tejbeer 428
    public void vivoImeiActivation() throws Throwable {
429
        scheduledTasks.checkImeiActivation();
430
    }
29255 tejbeer 431
 
37482 amit 432
    /**
433
     * Itel activation from Carlcare, Transsion's own after-sales endpoint. 50 imeis every 5
434
     * minutes, which spreads the work over the whole day rather than bursting: 14,400 lookups a
435
     * day against a pending pool of ~10,400.
436
     *
437
     * The 5-minute cadence is safe here in a way it was not for vivo, whose comment below records
438
     * why that pattern ran away: there, a failed lookup wrote no row, so createTimestamp was not
439
     * bumped and the same imei was eligible again five minutes later. This service stamps the row
440
     * on EVERY outcome, failures included, so each tick advances past the imeis it asked about
441
     * and a failure costs one retry tomorrow rather than one every five minutes.
442
     *
443
     * It is one plain signed GET per imei -- no captcha solver, no ChromeDriver -- so it does not
444
     * contend with the oppo/realme pass. Both this and the 23:00 DCR pull write Itel rows and
445
     * need no coordination: the pool query returns only imeis whose activationTimestamp is still
446
     * null, so whatever one has filled has already left the other's pool.
447
     */
448
    @Scheduled(fixedDelay = 5 * 60 * 1000)
449
    public void carlcareImeiActivation() throws Throwable {
450
        scheduledTasks.checkCarlcareImeiActivation();
451
    }
452
 
32048 tejbeer 453
    @Scheduled(cron = "0 0 8 * * *")
454
    public void reviewUncontactablePartner() throws Throwable {
455
        log.info("startTime" + LocalDateTime.now());
30421 tejbeer 456
 
32048 tejbeer 457
        scheduledTasks.reviewUncontactablePartner();
30421 tejbeer 458
 
32048 tejbeer 459
    }
30421 tejbeer 460
 
33928 ranu 461
    @Scheduled(cron = "0 0 7 * * *")
462
    public void setMovementWiseRbmTodayTargets() throws Throwable {
34669 amit.gupta 463
        log.info("today targets startTime {}", LocalDateTime.now());
33928 ranu 464
 
465
        scheduledTasks.persistRbmTodayTargets();
466
 
467
    }
468
 
33986 ranu 469
    @Scheduled(cron = "0 0 21 * * *")
470
    public void setMovementWiseRbmTodayAchievements() throws Throwable {
34669 amit.gupta 471
        log.info("today achievement startTime {}", LocalDateTime.now());
33986 ranu 472
 
473
        scheduledTasks.persistRbmTodayAchievements();
474
 
475
    }
476
 
37499 ranu 477
    // Sales-hierarchy target snapshot — runs 10 minutes after RBM targets so
478
    // today's rbm_targets rows are guaranteed present for the roll-up.
479
    @Scheduled(cron = "0 10 7 * * *")
480
    public void setSalesTodayTargets() throws Throwable {
481
        log.info("sales today targets startTime {}", LocalDateTime.now());
482
 
483
        scheduledTasks.persistSalesTodayTargets();
484
 
485
    }
486
 
487
    // Sales-hierarchy achievement snapshot — independent of the target chain;
488
    // rolls up live order ACH so it can run any time after orders settle.
489
    // Kept aligned with RBM achievement time (21:00).
490
    @Scheduled(cron = "0 10 21 * * *")
491
    public void setSalesTodayAchievements() throws Throwable {
492
        log.info("sales today achievement startTime {}", LocalDateTime.now());
493
 
494
        scheduledTasks.persistSalesTodayAchievements();
495
 
496
    }
497
 
33078 ranu 498
    @Scheduled(cron = "0 0 8 * * *")
499
    public void reviewNonSdBuyingBrand() throws Throwable {
500
        log.info("startTime" + LocalDateTime.now());
501
 
502
        scheduledTasks.reviewNonSdBuyingBrand();
503
 
504
    }
505
 
32048 tejbeer 506
    @Autowired
507
    private StandAlone standAlone;
30352 amit.gupta 508
 
32832 amit.gupta 509
    @Autowired
510
    OrderTrackingService orderTrackingService;
511
 
37472 amit 512
    // ONE thread, ONE full pass a day, for oppo and realme together.
513
    //
514
    // This replaces four @Scheduled jobs (oppo and realme x secondary and tertiary,
515
    // every 5 minutes), and it supersedes the r37447 / r37448 / r37449 argument about
516
    // how many ChromeDrivers to run. That argument was about the wrong variable.
517
    //
518
    // The revert in r37449 was sized on lookups ATTEMPTED per day, and the re-merge that
519
    // followed blamed the resulting collapse on CPU contention pushing the captcha
520
    // render past the element waits. The logs do not support contention:
521
    //
522
    //   29 Aug        imeis   canvas timeouts   captcha ok   distinct imeis   asks each
523
    //   oppo          4,350                 0       ~100%            4,238        1.03
524
    //   realme        4,524             3,390         19%            1,004        4.50
525
    //
526
    // Same box, same six cores, same driver count, same captcha vendor, load average
527
    // 0.9 -- and oppo took ZERO timeouts in all 24 hours, including the 15:00-23:00
528
    // window in which realme solved nothing at all. Realme's own canvas wait is 15s
529
    // against oppo's 8s, so the LONGER wait is the one expiring.
530
    //
531
    // What realme's timeout rate actually tracks is its own daily request volume, and
532
    // it resets at midnight: 920/day -> 0.3%, 3,467/day -> 28%, 4,524/day -> 75%. That
533
    // is realme.com declining to serve the widget, not a busy box.
534
    //
535
    // The 4.5 asks per imei is why it ran away. A failed lookup never reaches
536
    // dateMap.put, so no row is written, so createTimestamp is not bumped, so the same
537
    // imei was eligible again five minutes later -- more requests hardened the block,
538
    // which caused more failures, which caused more requests. A snapshotted daily pass
539
    // bounds that by construction: a failure costs one retry tomorrow, never one in
540
    // five minutes, however the far end behaves.
541
    //
542
    // Judge this change on dates written, not on timeout count.
37565 amit 543
    // One chunk of 25 for one brand every 20 seconds, oppo and realme by turns, until
544
    // both pools are empty for the day. Was a single 00:30 pass that held this thread for
545
    // 20+ hours; the method name is kept so the cron_job_* series stays continuous.
546
    //
547
    // fixedDelay, not fixedRate: the gap is measured from the END of a tick, so a chunk
548
    // that takes six minutes is not immediately followed by a queued one. The lane
549
    // self-throttles to whatever the far ends are actually giving us.
550
    //
551
    // The start/end log lines are gone deliberately -- at 4,320 ticks a day they were
552
    // pure volume on a log that is already 1.8GB. StandAlone logs the day boundary and
553
    // the chunks; idle ticks say nothing at all.
554
    @Scheduled(fixedDelay = 20 * 1000)
37472 amit 555
    public void oppoRealmeImeiActivation() throws Throwable {
556
        standAlone.checkBrowserImeiActivation();
34421 amit.gupta 557
    }
558
 
32801 amit.gupta 559
    @Scheduled(cron = "0 0 * * * *")
32048 tejbeer 560
    public void markBlueDartOrderDelivered() throws Throwable {
561
        log.info("startTime" + LocalDateTime.now());
32832 amit.gupta 562
        orderTrackingService.markBlueDartOrderDelivered();
32048 tejbeer 563
        log.info("endTime" + LocalDateTime.now());
564
    }
31117 tejbeer 565
 
32881 amit.gupta 566
    @Scheduled(cron = "0 15 * * * *")
32048 tejbeer 567
    public void markDelhiveryOrderDelivered() throws Throwable {
29673 manish 568
 
32048 tejbeer 569
        log.info("startTime" + LocalDateTime.now());
32832 amit.gupta 570
        orderTrackingService.markDelhiveryOrderDelivered();
29673 manish 571
 
32048 tejbeer 572
        log.info("endTime" + LocalDateTime.now());
573
    }
29308 tejbeer 574
 
32048 tejbeer 575
    @Scheduled(cron = "0 0 4 * * *")
576
    public void processPriceDrop() throws Throwable {
577
        scheduledTasks.processPriceDrop();
578
    }
30637 amit.gupta 579
 
32048 tejbeer 580
    @Scheduled(cron = "0 0 0 * * *")
581
    public void calculateInterestAccured() throws Throwable {
34710 amit.gupta 582
        scheduledTasks.loanSettlement();
32048 tejbeer 583
        scheduledTasks.calculateInterestAccured();
584
    }
30859 tejbeer 585
 
32117 tejbeer 586
    //  @Scheduled(cron = "0 */5 2-22 * * *")
33181 amit.gupta 587
    @Scheduled(fixedDelay = 1 * 60 * 1000)
32531 amit.gupta 588
    //@Scheduled(cron = "0 0 23 * * *")
32048 tejbeer 589
    public void loanSettlement() throws Throwable {
34756 amit.gupta 590
        LocalTime now = LocalTime.now();
34767 amit.gupta 591
        LocalTime start = LocalTime.of(9, 0);
34757 amit.gupta 592
        LocalTime end = LocalTime.of(23, 0);
34756 amit.gupta 593
 
594
        if (now.isBefore(start) || now.isAfter(end)) {
34762 amit.gupta 595
            System.out.println("Task skipped during restricted hours: " + now);
596
        } else {
34756 amit.gupta 597
            scheduledTasks.loanSettlement();
598
            System.out.println("Task executed at " + now);
599
        }
32048 tejbeer 600
    }
30859 tejbeer 601
 
32048 tejbeer 602
    @Scheduled(cron = "0 */15 * * * *")
603
    public void ccAvenueSettlement() throws Throwable {
604
        scheduledTasks.settleCCAvePayments();
605
    }
31332 amit.gupta 606
 
32048 tejbeer 607
    @Scheduled(cron = "0 0 6 * * *")
608
    public void dailyLoanAlert() throws Throwable {
609
        scheduledTasks.dailyLoanAlert();
610
    }
30896 amit.gupta 611
 
35106 ranu 612
    @Scheduled(cron = "0 0 11 * * *")
34162 ranu 613
    public void groupHidCatalogsByWeeks() throws Throwable {
614
        scheduledTasks.groupHidCatalogsByWeeks();
615
    }
616
 
36113 ranu 617
    @Scheduled(cron = "0 0 9 * * MON")  // Every Monday at 9:00 AM
34321 ranu 618
    public void sendFeebackSalesAndRbm() throws Throwable {
619
        scheduledTasksTest.sendRbmFeedbackSummaryEmail();
620
        scheduledTasksTest.sendSalesFeedbackSummaryEmail();
621
    }
622
 
32165 amit.gupta 623
    //Look out for imeis that have activation pending based of sale and mark create new SIO out of them
32048 tejbeer 624
    @Scheduled(cron = "0 0 1 * * *")
625
    public void processActivatedImeisForSchemes() throws Throwable {
626
        scheduledTasks.processActivatedImeisForSchemes();
627
    }
34241 tejus.loha 628
 
33357 amit.gupta 629
    //On every fifth update deductions
33435 amit.gupta 630
    @Scheduled(cron = "0 30 6 5 * ?")
33357 amit.gupta 631
    public void processSidbiDeductions() throws Throwable {
632
        scheduledTasks.processSidbiDeductions();
633
    }
34669 amit.gupta 634
 
34374 amit.gupta 635
    //Dont reset it for now as proposed by TV
636
    //@Scheduled(cron = "0 30 6 4 * ?")
33904 amit.gupta 637
    public void resetHardLimit() throws Throwable {
638
        scheduledTasks.resetHardLimit();
639
    }
640
 
37589 amit 641
    /**
642
     * Investment snapshot for every active partner, then the credit limit for the partners whose
37595 amit 643
     * base moved. This is the path that keeps limits current: it replaces the 20-minute full rescan,
644
     * so a limit follows a payment within ~2 minutes instead of up to 20 — which matters because a
645
     * quarter of advance payments are followed by an order within five minutes.
646
     *
647
     * <p>Measured on production: ~3 partners per 2-minute window show a changed base (peak 18), so
648
     * the limit work behind this is a handful of rows rather than a 980-partner scan.
37589 amit 649
     */
650
    @Scheduled(cron = "0 0/2 * * * *")
651
    public void sweepPartnerInvestment() throws Throwable {
652
        batchScheduledTasks.sweepPartnerInvestment();
653
    }
654
 
655
    /**
37595 amit 656
     * Daily: refresh the time-driven haircuts, then run a full limit pass.
657
     *
658
     * <p>The 2-minute sweep already recalculates the limit for every partner whose base moved, which
659
     * covers investment and utilisation. The full pass exists only for inputs the base cannot see —
660
     * credit risk, the SIDBI floor and hard_limit — and those move on a far slower clock: risk
661
     * decays on a 90-day threshold, and the SIDBI sanction table has had no new row since Oct 2024
662
     * and no recorded settlement. Running a 980-partner rescan every 20 minutes to catch that was 72
663
     * wasted passes a day.
664
     *
665
     * <p>Order matters: the haircut refresh changes base for the partners whose Apple or demo stock
666
     * crossed its threshold overnight, so the limit pass runs after it and sees the new values.
37589 amit 667
     */
668
    @Scheduled(cron = "0 20 0 * * *")
669
    public void refreshAgedStockDaily() throws Throwable {
670
        batchScheduledTasks.refreshAgedStockDaily();
37595 amit 671
        batchScheduledTasks.updatePartnerLimitWithBatch();
37589 amit 672
    }
673
 
37642 amit 674
    /**
675
     * Hourly at :40 — close out batches left RUNNING by a run that died mid-loop, so they
676
     * raise their alert and stop blocking the job from running again. No-ops when clean.
677
     */
678
    @Scheduled(cron = "0 40 * * * *")
679
    public void reapStaleCronBatches() {
680
        try {
681
            batchScheduledTasks.reapStaleBatches();
682
        } catch (Exception e) {
683
            log.error("reapStaleBatches failed: {}", e.getMessage(), e);
684
        }
685
    }
686
 
34253 ranu 687
    @Scheduled(cron = "0 0 9,14,18 * * *")
33874 ranu 688
    public void createOpeningStockPartyWise() throws Throwable {
689
        scheduledTasks.createOpeningStockPartyWise();
690
    }
30936 tejbeer 691
 
32842 amit.gupta 692
    //Loans due/overdue/default notifications sent to parnters
693
    @Scheduled(cron = "0 0 11 * * *")
32822 ranu 694
    public void sendMailWhatsAppAfterLoanDueDate() throws Throwable {
695
        scheduledTasks.sendMailWhatsAppAfterLoanDueDate();
696
    }
34241 tejus.loha 697
 
32842 amit.gupta 698
    @Scheduled(cron = "0 0 8 * * *")
699
    public void alertForDueDate() throws Throwable {
700
        scheduledTasks.alertForDueDate();
701
    }
32822 ranu 702
 
35133 ranu 703
    @Scheduled(cron = "0 0 4,21 * * *")
32048 tejbeer 704
    public void notifyLoanDueDateCross() throws Throwable {
705
        scheduledTasks.notifyLoanDueDateCross();
706
    }
30936 tejbeer 707
 
35133 ranu 708
    @Scheduled(cron = "0 0 4,21 * * *")
32048 tejbeer 709
    public void notifyDefaultLoans() throws Throwable {
710
        scheduledTasks.notifyDefaultLoans();
711
    }
30936 tejbeer 712
 
34910 ranu 713
   // @Scheduled(cron = "0 0 23 * * *")
32048 tejbeer 714
    public void hygineAlertForInternalTeam() throws Throwable {
715
        scheduledTasks.hygineAlertForInternalTeam();
31206 tejbeer 716
 
32048 tejbeer 717
    }
31206 tejbeer 718
 
32048 tejbeer 719
    @Scheduled(cron = "0 0 23 * * *")
720
    public void hygineAlertForPartner() throws Throwable {
721
        scheduledTasks.hygineAlertForPartner();
31206 tejbeer 722
 
32048 tejbeer 723
    }
31206 tejbeer 724
 
32048 tejbeer 725
    @Scheduled(cron = "0 0 0 * * MON")
726
    public void monthlyTargetForPartner() throws Throwable {
727
        scheduledTasks.monthlyTargetForPartner();
31249 tejbeer 728
 
32048 tejbeer 729
    }
31249 tejbeer 730
 
32048 tejbeer 731
    @Scheduled(cron = "0 0 0 * * MON")
732
    public void monthlyTargetForInternalTeam() throws Throwable {
733
        scheduledTasks.monthlyTargetForInternalTeam();
31249 tejbeer 734
 
32048 tejbeer 735
    }
31612 tejbeer 736
 
32048 tejbeer 737
    @Scheduled(cron = "0 0 6 * * *")
738
    public void sendSamsungRebilling() throws Throwable {
739
        scheduledTasks.sendMailForSamsungRebilling();
740
    }
31931 amit.gupta 741
 
32048 tejbeer 742
    @Scheduled(cron = "0 10 8 * * *")
743
    public void sendMailForAgeingAlert() throws Throwable {
744
        scheduledTasks.sendMailForAgeingAlert();
745
    }
746
 
747
    @Scheduled(cron = "0 0 8 * * *")
748
    public void sendFilteredRetailerPerformance() throws Throwable {
749
        scheduledTasks.sendFilteredRetailerPerformance();
750
    }
32690 amit.gupta 751
 
33444 ranu 752
    @Scheduled(cron = "0 0 0 * * MON")
753
    public void findAllLiveDemoBrandItemsByBillingDate() throws Throwable {
754
        scheduledTasks.findAllLiveDemoBrandItemsByBillingDate();
755
    }
34241 tejus.loha 756
 
33464 ranu 757
    @Scheduled(cron = "0 10 6 * * *")
758
    public void findTodayPocoBillingItems() throws Throwable {
759
        scheduledTasks.findTodayPocoBillingItems();
760
    }
32690 amit.gupta 761
 
762
    @Scheduled(cron = "0 0 12 * * *")
763
    public void rejectPriceDropsOfApprovedImeis() throws Throwable {
37083 amit 764
        batchScheduledTasks.reprocessPriceDropsWithBatch();
32690 amit.gupta 765
    }
32907 amit.gupta 766
 
767
    @Autowired
768
    POScheduler poScheduler;
34241 tejus.loha 769
 
32907 amit.gupta 770
    @Scheduled(cron = "0 0 1 * * *")
33643 amit.gupta 771
    public void autoClosePO() {
32907 amit.gupta 772
        poScheduler.autoClosePurchaseOrders();
773
    }
32048 tejbeer 774
    /*
775
     * @Scheduled(cron = "0 0 9 * * *") public void onBoardingDocumentsPending()
776
     * throws Throwable { log.info("startTime" + LocalDateTime.now());
777
     * onBoardingRelatedSchelduleTask.onBoardingDocumentsPending();
778
     * log.info("endTime" + LocalDateTime.now()); }
779
     */
34443 vikas.jang 780
 
34547 vikas.jang 781
    @Scheduled(cron = "0 50 23 * * *")
34443 vikas.jang 782
    public void bidConfirmation() throws Throwable {
34547 vikas.jang 783
        log.info("running bid cron at 23:50PM");
34443 vikas.jang 784
        runOnceTasks.processBids(ProfitMandiConstants.BID_CRON_ENUM.YESTERDAY);
785
    }
786
 
34547 vikas.jang 787
    @Scheduled(cron = "0 0 19 * * *")
34443 vikas.jang 788
    public void processLiquidationBids() throws Throwable {
34547 vikas.jang 789
        log.info("running bid cron at 07:00PM");
34443 vikas.jang 790
        runOnceTasks.processBids(ProfitMandiConstants.BID_CRON_ENUM.TODAY);
791
    }
792
 
34547 vikas.jang 793
    @Scheduled(cron = "0 30 21 * * *")
34443 vikas.jang 794
    public void bidPurchaseOrder() throws Throwable {
34547 vikas.jang 795
        log.info("running bid cron at 09:30PM");
34443 vikas.jang 796
        runOnceTasks.processBids(ProfitMandiConstants.BID_CRON_ENUM.TODAY);
797
    }
34547 vikas.jang 798
 
34669 amit.gupta 799
    /*@Scheduled(cron = "0 0 12 * * *")
800
    public void processCashDiscount() throws Throwable {
801
        scheduledTasks.processCashDiscount();
802
    }*/
803
 
34563 vikas.jang 804
    @Scheduled(cron = "0 0 9,17 * * *")
34547 vikas.jang 805
    public void bidConsolidatedMessage() throws Throwable {
806
        log.info("Running bid cron at 09:00 AM or 05:00 PM");
807
        runOnceTasks.consolidatedBiddingMessage();
34563 vikas.jang 808
    }
34770 vikas.jang 809
 
810
    @Scheduled(cron = "0 0 8 * * *")
34836 vikas 811
    public void yesterdayTrackingReport() throws Throwable {
812
        log.info("Running yesterday employee tracking cron at 08:00 AM");
813
        runOnceTasks.yesterdayTrackingReport();
34770 vikas.jang 814
    }
34836 vikas 815
 
35178 amit 816
    @Scheduled(cron = "0 10 8 * * *")
35177 amit 817
    public void partnerCreditExposureReport() throws Throwable {
818
        log.info("Running yesterday employee tracking cron at 08:00 AM");
819
        runOnceTasks.sendCreditExposureReport();
820
    }
821
 
36552 ranu 822
    @Scheduled(cron = "0 0 22,16 * * *")
34836 vikas 823
    public void dailyTrackingReport() throws Throwable {
36552 ranu 824
        log.info("Running daily employee tracking cron at 10:00 PM and 04:00 PM");
34836 vikas 825
        runOnceTasks.dailyTrackingReport();
826
    }
35105 vikas 827
 
34792 amit.gupta 828
    @Scheduled(cron = "0 0 0 1 1,4,7,10 *")
829
    public void sendUpdateMobileBrandMarketShareQuaterlyMail() throws Throwable {
34791 aman.kumar 830
        log.info("Running Marketshare update remined quaterly");
831
        scheduledTasks.sendUpdateMobileBrandMarketShareQuaterlyMail();
832
    }
35105 vikas 833
 
834
    @Scheduled(cron = "0 0 * * * *")
835
    public void checkRewardsEligibility() throws Throwable {
836
        log.info("Running Rewards Disburse daily");
837
        runOnceTasks.checkRewardsEligibility();
838
    }
35326 amit 839
 
840
    @Scheduled(cron="0 0 20 * * *")
841
    public void sendTrialExpiry() {
842
        scheduledTasks.sendTrialExpiry();
843
    }
35666 vikas 844
 
845
    @Scheduled(cron = "0 0 0 * * *")
846
    public void fetchOffersByItem() {
847
        scheduledTasks.cachePinelabsOffers();
848
    }
35788 vikas 849
 
850
    @Scheduled(cron = "0 0 0 * * *")
851
    public void syncProductsToShopify() throws Exception {
36058 ranu 852
        scheduledTasks.syncProductsToShopifyByWarehouseId(ProfitMandiConstants.WAREHOUSE_NAME_MAP.get("UP-WEST/NOIDA"));
35788 vikas 853
    }
36511 amit 854
 
37162 vikas 855
    @Scheduled(cron = "0 0 6,18 * * *")
856
    public void syncInventoryToShopify() throws Exception {
857
        scheduledTasks.syncInventoryToShopifyByWarehouseId(ProfitMandiConstants.WAREHOUSE_NAME_MAP.get("UP-WEST/NOIDA"));
858
    }
859
 
36511 amit 860
    @Autowired
861
    private WarehouseStockReconciliation warehouseStockReconciliation;
862
 
863
    @Scheduled(cron = "0 30 5 * * *")
864
    public void reconcileInventorySnapshot() throws Exception {
865
        log.info("reconcileInventorySnapshot");
866
        warehouseStockReconciliation.reconcile();
867
    }
37159 amit 868
 
869
    @Autowired
870
    private PartnerIdentityIntegrityMonitor partnerIdentityIntegrityMonitor;
871
 
872
    @Scheduled(cron = "0 0 7 * * *")
873
    public void partnerIdentityIntegrityMonitor() throws Exception {
874
        log.info("partnerIdentityIntegrityMonitor");
875
        partnerIdentityIntegrityMonitor.monitor();
876
    }
23756 amit.gupta 877
}