Subversion Repositories SmartDukaan

Rev

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