| 29222 |
tejbeer |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
|
|
3 |
import java.time.DayOfWeek;
|
|
|
4 |
import java.time.LocalDate;
|
|
|
5 |
import java.util.ArrayList;
|
|
|
6 |
import java.util.HashMap;
|
|
|
7 |
import java.util.List;
|
|
|
8 |
import java.util.Map;
|
|
|
9 |
import java.util.stream.Collectors;
|
|
|
10 |
|
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.stereotype.Component;
|
|
|
13 |
|
|
|
14 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
|
|
15 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
|
|
16 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
|
|
17 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
|
|
18 |
import com.spice.profitmandi.dao.model.DispatchNotificationModel;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.logistics.ProviderTatRepository;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.logistics.PublicHolidaysRepository;
|
|
|
21 |
|
|
|
22 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
23 |
|
|
|
24 |
@Component
|
|
|
25 |
public class LogisticsServiceImpl implements LogisticsService {
|
|
|
26 |
|
|
|
27 |
@Autowired
|
|
|
28 |
private PublicHolidaysRepository publicHolidaysRepository;
|
|
|
29 |
|
|
|
30 |
@Autowired
|
|
|
31 |
private ProviderTatRepository providerTatRepository;
|
|
|
32 |
|
|
|
33 |
@Override
|
|
|
34 |
public LocalDate calculateDeliveryTimeline(ProviderTat providerTat) {
|
|
|
35 |
int businessDays = 0;
|
|
|
36 |
LocalDate deliveryDate = null;
|
|
|
37 |
int deliveryTat = 2;
|
|
|
38 |
if (providerTat != null) {
|
|
|
39 |
deliveryTat = providerTat.getDeliveryTime();
|
|
|
40 |
}
|
|
|
41 |
LocalDate currDate = LocalDate.now().plusDays(1);
|
|
|
42 |
List<LocalDate> ph = publicHolidaysRepository.selectAllByDate(currDate).stream().map(x -> x.getDate())
|
|
|
43 |
.collect(Collectors.toList());
|
|
|
44 |
while (businessDays < deliveryTat) {
|
|
|
45 |
if (ph.contains(currDate) || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {
|
|
|
46 |
} else {
|
|
|
47 |
businessDays++;
|
|
|
48 |
}
|
|
|
49 |
currDate = currDate.plusDays(1);
|
|
|
50 |
}
|
|
|
51 |
return currDate;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
@Override
|
|
|
55 |
public Map<String, DispatchNotificationModel> markedOrderShippedDetail(List<Order> orders, Provider provider,
|
|
|
56 |
String airwaybillNo) {
|
|
|
57 |
Map<String, DispatchNotificationModel> dispatchNotication = new HashMap<>();
|
|
|
58 |
|
|
|
59 |
for (Order order : orders) {
|
|
|
60 |
if (order.getStatus().equals(OrderStatus.BILLED)) {
|
|
|
61 |
order.setLogisticsProviderId(provider.getId());
|
|
|
62 |
order.setAirwayBillNumber(airwaybillNo);
|
|
|
63 |
order.setStatus(OrderStatus.SHIPPED_FROM_WH);
|
|
|
64 |
|
|
|
65 |
ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),
|
|
|
66 |
order.getWarehouseId(), order.getRetailerPinCode());
|
|
|
67 |
|
|
|
68 |
LocalDate deliveryDate = this.calculateDeliveryTimeline(pt);
|
|
|
69 |
|
|
|
70 |
order.setExpectedDeliveryTime(deliveryDate.atStartOfDay());
|
|
|
71 |
|
|
|
72 |
if (dispatchNotication.get(airwaybillNo) != null) {
|
|
|
73 |
DispatchNotificationModel dnm = dispatchNotication.get(airwaybillNo);
|
|
|
74 |
List<String> invoiceNumbers = dnm.getInvoiceNumber();
|
|
|
75 |
invoiceNumbers.add(order.getInvoiceNumber());
|
|
|
76 |
dnm.setInvoiceNumber(invoiceNumbers);
|
|
|
77 |
Float totalAmount = dnm.getTotalAmount();
|
|
|
78 |
dnm.setTotalAmount(totalAmount + order.getTotalAmount());
|
|
|
79 |
|
|
|
80 |
int totalQty = dnm.getTotalQty();
|
|
|
81 |
dnm.setTotalQty(totalQty + order.getLineItem().getQuantity());
|
|
|
82 |
|
|
|
83 |
dispatchNotication.put(airwaybillNo, dnm);
|
|
|
84 |
|
|
|
85 |
} else {
|
|
|
86 |
DispatchNotificationModel dnm = new DispatchNotificationModel();
|
|
|
87 |
List<String> invoiceNumber = new ArrayList<>();
|
|
|
88 |
invoiceNumber.add(order.getInvoiceNumber());
|
|
|
89 |
dnm.setInvoiceNumber(invoiceNumber);
|
|
|
90 |
dnm.setTotalAmount(order.getTotalAmount());
|
|
|
91 |
dnm.setTotalQty(order.getLineItem().getQuantity());
|
|
|
92 |
dnm.setFofoId(order.getRetailerId());
|
|
|
93 |
dnm.setProviderId(order.getLogisticsProviderId());
|
|
|
94 |
dnm.setDate(deliveryDate);
|
|
|
95 |
|
|
|
96 |
dispatchNotication.put(airwaybillNo, dnm);
|
|
|
97 |
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
return dispatchNotication;
|
|
|
104 |
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
}
|