Rev 32974 | Rev 34373 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.service;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.dao.entity.logistics.Provider;import com.spice.profitmandi.dao.entity.logistics.ProviderTat;import com.spice.profitmandi.dao.entity.logistics.WarehouseProvider;import com.spice.profitmandi.dao.entity.logistics.WarehouseRider;import com.spice.profitmandi.dao.entity.transaction.Order;import com.spice.profitmandi.dao.entity.transaction.TransactionShipmentSequence;import com.spice.profitmandi.dao.model.DispatchNotificationModel;import com.spice.profitmandi.dao.repository.logistics.*;import com.spice.profitmandi.dao.repository.transaction.TransactionShipmentSequenceRepository;import com.spice.profitmandi.service.integrations.gstpro.api.model.E_InvoiceCommon;import in.shop2020.model.v1.order.OrderStatus;import org.apache.commons.lang.StringUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import java.time.DayOfWeek;import java.time.LocalDate;import java.time.LocalDateTime;import java.util.ArrayList;import java.util.List;import java.util.Map;import java.util.stream.Collectors;@Componentpublic class LogisticsServiceImpl implements LogisticsService {@Autowiredprivate PublicHolidaysRepository publicHolidaysRepository;@Autowiredprivate ProviderTatRepository providerTatRepository;@AutowiredProviderRepository providerRepository;@Overridepublic LocalDate calculateDeliveryTimeline(LocalDate date, ProviderTat providerTat, int delayDays) {int businessDays = 0;int deliveryTat = 3;if (providerTat != null) {deliveryTat = providerTat.getDeliveryTime();}deliveryTat = deliveryTat + delayDays;LocalDate currDate = date.plusDays(1);List<LocalDate> ph = publicHolidaysRepository.selectAllByDate(currDate).stream().map(x -> x.getDate()).collect(Collectors.toList());while (businessDays < deliveryTat) {if (ph.contains(currDate) || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY)) {} else {businessDays++;}currDate = currDate.plusDays(1);}return currDate;}@Overridepublic Map<String, DispatchNotificationModel> markedOrderShippedDetail(List<Order> orders, Provider provider,Map<String, DispatchNotificationModel> dispatchNotication, String airwaybillNo, LocalDateTime shippingTimestamp)throws ProfitMandiBusinessException {for (Order order : orders) {if (order.getStatus().equals(OrderStatus.BILLED)) {if (order.getBillingTimestamp().isAfter(shippingTimestamp)) {throw new ProfitMandiBusinessException("Uploaded File", "","Invoice Number " + order.getInvoiceNumber() + " cannot be shipped before billing date");}if (StringUtils.isEmpty(airwaybillNo)) {throw new ProfitMandiBusinessException("Uploaded File", "","Invoice Number " + order.getInvoiceNumber() + " airwaybill_no is empty");}if (airwaybillNo.equals("Error")) {break;}order.setLogisticsProviderId(provider.getId());order.setAirwayBillNumber(airwaybillNo);order.setStatus(OrderStatus.SHIPPED_FROM_WH);order.setStatusDescription("Order shipped from warehouses");ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),order.getWarehouseId(), order.getRetailerPinCode());order.setShippingTimestamp(shippingTimestamp);LocalDate deliveryDate = this.calculateDeliveryTimeline(LocalDate.now(), pt, 0);order.setExpectedDeliveryTime(deliveryDate.atStartOfDay());if (dispatchNotication.get(airwaybillNo) != null) {DispatchNotificationModel dnm = dispatchNotication.get(airwaybillNo);List<String> invoiceNumbers = dnm.getInvoiceNumber();invoiceNumbers.add(order.getInvoiceNumber());dnm.setInvoiceNumber(invoiceNumbers);Float totalAmount = dnm.getTotalAmount();dnm.setTotalAmount(totalAmount + order.getTotalAmount());int totalQty = dnm.getTotalQty();dnm.setTotalQty(totalQty + order.getLineItem().getQuantity());dispatchNotication.put(airwaybillNo, dnm);} else {DispatchNotificationModel dnm = new DispatchNotificationModel();List<String> invoiceNumber = new ArrayList<>();invoiceNumber.add(order.getInvoiceNumber());dnm.setInvoiceNumber(invoiceNumber);dnm.setTotalAmount(order.getTotalAmount());dnm.setTotalQty(order.getLineItem().getQuantity());dnm.setFofoId(order.getRetailerId());dnm.setProviderId(order.getLogisticsProviderId());dnm.setDate(deliveryDate);dnm.setShippingDate(shippingTimestamp.toLocalDate());dispatchNotication.put(airwaybillNo, dnm);}}}return dispatchNotication;}@AutowiredWarehouseProviderRepository warehouseProviderRepository;@AutowiredWarehouseRiderRepository warehouseRiderRepository;@AutowiredTransactionShipmentSequenceRepository transactionShipmentSequenceRepository;@Overridepublic E_InvoiceCommon.ReqPlGenIRN.EwbDetails getEwbDetails(Order order) {E_InvoiceCommon.ReqPlGenIRN.EwbDetails ewbDetails = new E_InvoiceCommon.ReqPlGenIRN.EwbDetails();//ewbDetails.Distance = String.valueOf(200);//1 is road, 2 is rail, 3 is air, 4 is shipif (order.getLogisticsProviderId() == ProfitMandiConstants.LOGISTICS_PROVIDER_SELF_PICKUP|| order.getLogisticsProviderId() == ProfitMandiConstants.LOGISTICS_PROVIDER_RUNNER) {TransactionShipmentSequence transactionShipmentSequence = transactionShipmentSequenceRepository.selectByTransactionShipmentSequence(order.getLogisticsTransactionId());ewbDetails.VehNo = transactionShipmentSequence.getVehicleNumber();ewbDetails.VehType = "R";ewbDetails.TransMode = "1";} else {WarehouseProvider warehouseProvider = warehouseProviderRepository.selectByProviderWarehouse(order.getLogisticsProviderId(), order.getWarehouseId());Provider provider = providerRepository.selectById(order.getLogisticsProviderId());//Get logistics Provider Detail hereewbDetails.TransId = warehouseProvider.getGstin();ewbDetails.TransName = provider.getName();}ewbDetails.Distance = "0";return ewbDetails;}}