Subversion Repositories SmartDukaan

Rev

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