| Line 14... |
Line 14... |
| 14 |
import com.spice.profitmandi.dao.entity.logistics.ProviderDetails;
|
14 |
import com.spice.profitmandi.dao.entity.logistics.ProviderDetails;
|
| 15 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
15 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
| 16 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
16 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
| 17 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
17 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 18 |
import com.spice.profitmandi.dao.entity.user.Address;
|
18 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| - |
|
19 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 19 |
import com.spice.profitmandi.dao.model.*;
|
20 |
import com.spice.profitmandi.dao.model.*;
|
| 20 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
21 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 21 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
22 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 22 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
23 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 23 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
24 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| Line 189... |
Line 190... |
| 189 |
Map<Integer, List<Order>> existingProviderOrderMap = ordersByWaybill.stream().collect(Collectors.groupingBy(x -> x.getLogisticsProviderId()));
|
190 |
Map<Integer, List<Order>> existingProviderOrderMap = ordersByWaybill.stream().collect(Collectors.groupingBy(x -> x.getLogisticsProviderId()));
|
| 190 |
for (Entry<Integer, List<Order>> existingProviderEntrySet : existingProviderOrderMap.entrySet()) {
|
191 |
for (Entry<Integer, List<Order>> existingProviderEntrySet : existingProviderOrderMap.entrySet()) {
|
| 191 |
String providerName = providerMap.get(existingProviderEntrySet.getKey());
|
192 |
String providerName = providerMap.get(existingProviderEntrySet.getKey());
|
| 192 |
LOGGER.info("Provider Name - {}", providerName);
|
193 |
LOGGER.info("Provider Name - {}", providerName);
|
| 193 |
Set<String> wayBillNumbers = providerWayBillNumberMap.get(providerName);
|
194 |
Set<String> wayBillNumbers = providerWayBillNumberMap.get(providerName);
|
| 194 |
if(wayBillNumbers==null) continue;
|
195 |
if (wayBillNumbers == null) continue;
|
| 195 |
for (Order order : ordersByWaybill) {
|
196 |
for (Order order : ordersByWaybill) {
|
| 196 |
if (wayBillNumbers.contains(order.getAirwayBillNumber())) {
|
197 |
if (wayBillNumbers.contains(order.getAirwayBillNumber())) {
|
| 197 |
String errorMessage = "Provider " + providerName + ", wayBillNumber " + order.getAirwayBillNumber() + " already exists";
|
198 |
String errorMessage = "Provider " + providerName + ", wayBillNumber " + order.getAirwayBillNumber() + " already exists";
|
| 198 |
throw new ProfitMandiBusinessException(errorMessage, errorMessage, errorMessage);
|
199 |
throw new ProfitMandiBusinessException(errorMessage, errorMessage, errorMessage);
|
| 199 |
}
|
200 |
}
|
| Line 206... |
Line 207... |
| 206 |
|
207 |
|
| 207 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
208 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
| 208 |
List<Position> positions = positionRepository.selectAll(authUser.getId());
|
209 |
List<Position> positions = positionRepository.selectAll(authUser.getId());
|
| 209 |
|
210 |
|
| 210 |
List<Position> warehousePositions = positions.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE).collect(Collectors.toList());
|
211 |
List<Position> warehousePositions = positions.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE).collect(Collectors.toList());
|
| - |
|
212 |
List<Integer> authWarehouseIds = null;
|
| - |
|
213 |
if (warehousePositions.stream().filter(x -> EscalationType.L2.isGreaterThanEqualTo(x.getEscalationType())).count() > 0) {
|
| - |
|
214 |
authWarehouseIds = new ArrayList<>(ProfitMandiConstants.WAREHOUSE_MAP.keySet());
|
| - |
|
215 |
} else {
|
| 211 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
216 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 212 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
217 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
| 213 |
positionRetailers.addAll(customRetailers);
|
218 |
positionRetailers.addAll(customRetailers);
|
| 214 |
});
|
219 |
});
|
| - |
|
220 |
|
| - |
|
221 |
LOGGER.info("positionRetailers" + positionRetailers);
|
| - |
|
222 |
List<Integer> fofoIds = new ArrayList<>();
|
| - |
|
223 |
if (!positionRetailers.isEmpty()) {
|
| - |
|
224 |
fofoIds.addAll(positionRetailers.stream().map(x -> x.getPartnerId()).collect(Collectors.toList()));
|
| 215 |
|
225 |
|
| 216 |
LOGGER.info("positionRetailers" + positionRetailers);
|
- |
|
| 217 |
List<Integer> fofoIds = new ArrayList<>();
|
- |
|
| 218 |
List<Integer> warehouseIds = new ArrayList<>();
|
- |
|
| 219 |
if (!positionRetailers.isEmpty()) {
|
- |
|
| 220 |
fofoIds.addAll(positionRetailers.stream().map(x -> x.getPartnerId()).collect(Collectors.toList()));
|
- |
|
| 221 |
|
- |
|
| 222 |
warehouseIds = this.getWarehouses(positionRetailers).entrySet().stream().map(x -> x.getKey()).collect(Collectors.toList());
|
226 |
authWarehouseIds = this.getWarehouses(positionRetailers).entrySet().stream().map(x -> x.getKey()).collect(Collectors.toList());
|
| 223 |
|
227 |
|
| - |
|
228 |
}
|
| 224 |
}
|
229 |
}
|
| 225 |
|
230 |
|
| 226 |
LOGGER.info("fofoIds" + fofoIds);
|
- |
|
| 227 |
|
- |
|
| 228 |
LOGGER.info("warehouseIds" + warehouseIds);
|
- |
|
| 229 |
|
- |
|
| 230 |
Map<String, DispatchNotificationModel> dispatchNotication = new HashMap<>();
|
231 |
Map<String, DispatchNotificationModel> dispatchNotication = new HashMap<>();
|
| 231 |
|
232 |
|
| 232 |
if (!billedOrderListModels.isEmpty()) {
|
233 |
if (!billedOrderListModels.isEmpty()) {
|
| 233 |
List<Order> ords = orderRepository.selectByInvoiceNumbers(
|
234 |
List<Order> ords = orderRepository.selectByInvoiceNumbers(
|
| 234 |
billedOrderListModels.stream().map(x -> x.getInvoiceNumber()).collect(Collectors.toList()));
|
235 |
billedOrderListModels.stream().map(x -> x.getInvoiceNumber()).collect(Collectors.toList()));
|
| 235 |
|
236 |
|
| 236 |
List<Integer> shippingWarehouseIds = ords.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());
|
237 |
List<Integer> shippingWarehouseIds = ords.stream().map(x -> x.getWarehouseId()).collect(Collectors.toList());
|
| 237 |
|
238 |
|
| 238 |
if (!warehouseIds.containsAll(shippingWarehouseIds)) {
|
239 |
if (!authWarehouseIds.containsAll(shippingWarehouseIds)) {
|
| 239 |
throw new ProfitMandiBusinessException("Uploaded File", "", "Partners are not belong to the same warehouse");
|
240 |
throw new ProfitMandiBusinessException("Uploaded File", "", "Partners are not belong to the same warehouse");
|
| 240 |
|
241 |
|
| 241 |
}
|
242 |
}
|
| 242 |
|
243 |
|
| 243 |
Map<String, Integer> invoiceRetailerMap = ords.stream().collect(Collectors.toMap(
|
244 |
Map<String, Integer> invoiceRetailerMap = ords.stream().collect(Collectors.toMap(
|
| 244 |
x -> x.getInvoiceNumber(), x->x.getRetailerId(), (u,v)-> u ));
|
245 |
x -> x.getInvoiceNumber(), x -> x.getRetailerId(), (u, v) -> u));
|
| 245 |
|
246 |
|
| 246 |
LOGGER.info("invoicefofoIdmap" + invoiceRetailerMap);
|
247 |
LOGGER.info("invoicefofoIdmap" + invoiceRetailerMap);
|
| 247 |
|
248 |
|
| 248 |
Map<String, Set<String>> airbillInvoiceNumberMap = billedOrderListModels.stream().collect(Collectors.groupingBy(x -> x.getAirwayBillNumber(), Collectors.mapping(BilledOrderListModel::getInvoiceNumber, Collectors.toSet())));
|
249 |
Map<String, Set<String>> airbillInvoiceNumberMap = billedOrderListModels.stream().collect(Collectors.groupingBy(x -> x.getAirwayBillNumber(), Collectors.mapping(BilledOrderListModel::getInvoiceNumber, Collectors.toSet())));
|
| 249 |
|
250 |
|
| Line 316... |
Line 317... |
| 316 |
if (!dispatchNotication.isEmpty()) {
|
317 |
if (!dispatchNotication.isEmpty()) {
|
| 317 |
|
318 |
|
| 318 |
for (Entry<String, DispatchNotificationModel> dn : dispatchNotication.entrySet()) {
|
319 |
for (Entry<String, DispatchNotificationModel> dn : dispatchNotication.entrySet()) {
|
| 319 |
DispatchNotificationModel dispatchNotificationModel = dn.getValue();
|
320 |
DispatchNotificationModel dispatchNotificationModel = dn.getValue();
|
| 320 |
//Send message only if shipping date is within T+1 of upload date
|
321 |
//Send message only if shipping date is within T+1 of upload date
|
| 321 |
if(dispatchNotificationModel.getShippingDate().isAfter(LocalDate.now().minusDays(2))) {
|
322 |
if (dispatchNotificationModel.getShippingDate().isAfter(LocalDate.now().minusDays(2))) {
|
| 322 |
Provider pr = providerRepository.selectById(dispatchNotificationModel.getProviderId());
|
323 |
Provider pr = providerRepository.selectById(dispatchNotificationModel.getProviderId());
|
| 323 |
|
324 |
|
| 324 |
String title = "Order Shipped";
|
325 |
String title = "Order Shipped";
|
| 325 |
|
326 |
|
| 326 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(dn.getValue().getFofoId());
|
327 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(dn.getValue().getFofoId());
|
| Line 748... |
Line 749... |
| 748 |
order.setStatusDescription("Order Delivered");
|
749 |
order.setStatusDescription("Order Delivered");
|
| 749 |
|
750 |
|
| 750 |
}
|
751 |
}
|
| 751 |
|
752 |
|
| 752 |
//Send notification only if the case is of T + 2 days
|
753 |
//Send notification only if the case is of T + 2 days
|
| 753 |
if(orders.get(0).getDeliveryTimestamp().toLocalDate().isBefore(LocalDate.now().plusDays(2))) {
|
754 |
if (orders.get(0).getDeliveryTimestamp().toLocalDate().isBefore(LocalDate.now().plusDays(2))) {
|
| 754 |
String title = "Order Delivered";
|
755 |
String title = "Order Delivered";
|
| 755 |
|
756 |
|
| 756 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
757 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 757 |
sendNotificationModel.setCampaignName("Order Delivered");
|
758 |
sendNotificationModel.setCampaignName("Order Delivered");
|
| 758 |
sendNotificationModel.setTitle(title);
|
759 |
sendNotificationModel.setTitle(title);
|