| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
2 |
|
| 3 |
import java.time.DayOfWeek;
|
3 |
import java.time.DayOfWeek;
|
| 4 |
import java.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| - |
|
5 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 6 |
import java.util.HashMap;
|
7 |
import java.util.HashMap;
|
| 7 |
import java.util.List;
|
8 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
9 |
import java.util.Map;
|
| 9 |
import java.util.stream.Collectors;
|
10 |
import java.util.stream.Collectors;
|
| Line 29... |
Line 30... |
| 29 |
|
30 |
|
| 30 |
@Autowired
|
31 |
@Autowired
|
| 31 |
private ProviderTatRepository providerTatRepository;
|
32 |
private ProviderTatRepository providerTatRepository;
|
| 32 |
|
33 |
|
| 33 |
@Override
|
34 |
@Override
|
| 34 |
public LocalDate calculateDeliveryTimeline(ProviderTat providerTat) {
|
35 |
public LocalDate calculateDeliveryTimeline(LocalDate date, ProviderTat providerTat, int delayDays) {
|
| 35 |
int businessDays = 0;
|
36 |
int businessDays = 0;
|
| 36 |
LocalDate deliveryDate = null;
|
- |
|
| 37 |
int deliveryTat = 2;
|
37 |
int deliveryTat = 5;
|
| 38 |
if (providerTat != null) {
|
38 |
if (providerTat != null) {
|
| 39 |
deliveryTat = providerTat.getDeliveryTime();
|
39 |
deliveryTat = providerTat.getDeliveryTime();
|
| 40 |
}
|
40 |
}
|
| - |
|
41 |
deliveryTat = deliveryTat + delayDays;
|
| 41 |
LocalDate currDate = LocalDate.now().plusDays(1);
|
42 |
LocalDate currDate = date.plusDays(1);
|
| 42 |
List<LocalDate> ph = publicHolidaysRepository.selectAllByDate(currDate).stream().map(x -> x.getDate())
|
43 |
List<LocalDate> ph = publicHolidaysRepository.selectAllByDate(currDate).stream().map(x -> x.getDate())
|
| 43 |
.collect(Collectors.toList());
|
44 |
.collect(Collectors.toList());
|
| 44 |
while (businessDays < deliveryTat) {
|
45 |
while (businessDays < deliveryTat) {
|
| 45 |
if (ph.contains(currDate) || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
|
46 |
if (ph.contains(currDate) || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
|
| 46 |
} else {
|
47 |
} else {
|
| Line 62... |
Line 63... |
| 62 |
order.setAirwayBillNumber(airwaybillNo);
|
63 |
order.setAirwayBillNumber(airwaybillNo);
|
| 63 |
order.setStatus(OrderStatus.SHIPPED_FROM_WH);
|
64 |
order.setStatus(OrderStatus.SHIPPED_FROM_WH);
|
| 64 |
|
65 |
|
| 65 |
ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),
|
66 |
ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),
|
| 66 |
order.getWarehouseId(), order.getRetailerPinCode());
|
67 |
order.getWarehouseId(), order.getRetailerPinCode());
|
| - |
|
68 |
order.setShippingTimestamp(LocalDateTime.now());
|
| 67 |
|
69 |
|
| 68 |
LocalDate deliveryDate = this.calculateDeliveryTimeline(pt);
|
70 |
LocalDate deliveryDate = this.calculateDeliveryTimeline(LocalDate.now(), pt, 0);
|
| 69 |
|
- |
|
| 70 |
order.setExpectedDeliveryTime(deliveryDate.atStartOfDay());
|
71 |
order.setExpectedDeliveryTime(deliveryDate.atStartOfDay());
|
| 71 |
|
72 |
|
| 72 |
if (dispatchNotication.get(airwaybillNo) != null) {
|
73 |
if (dispatchNotication.get(airwaybillNo) != null) {
|
| 73 |
DispatchNotificationModel dnm = dispatchNotication.get(airwaybillNo);
|
74 |
DispatchNotificationModel dnm = dispatchNotication.get(airwaybillNo);
|
| 74 |
List<String> invoiceNumbers = dnm.getInvoiceNumber();
|
75 |
List<String> invoiceNumbers = dnm.getInvoiceNumber();
|