| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
- |
|
| 4 |
import java.io.InputStream;
|
- |
|
| 5 |
import java.time.LocalDate;
|
- |
|
| 6 |
import java.time.LocalDateTime;
|
- |
|
| 7 |
import java.time.format.DateTimeFormatter;
|
- |
|
| 8 |
import java.util.ArrayList;
|
- |
|
| 9 |
import java.util.Arrays;
|
- |
|
| 10 |
import java.util.HashMap;
|
- |
|
| 11 |
import java.util.HashSet;
|
- |
|
| 12 |
import java.util.List;
|
- |
|
| 13 |
import java.util.Map;
|
- |
|
| 14 |
import java.util.Map.Entry;
|
- |
|
| 15 |
import java.util.Set;
|
- |
|
| 16 |
import java.util.stream.Collectors;
|
- |
|
| 17 |
|
- |
|
| 18 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 19 |
import javax.servlet.http.HttpServletResponse;
|
- |
|
| 20 |
import javax.transaction.Transactional;
|
- |
|
| 21 |
|
- |
|
| 22 |
import org.apache.commons.csv.CSVRecord;
|
- |
|
| 23 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 24 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 25 |
import org.json.JSONArray;
|
- |
|
| 26 |
import org.json.JSONObject;
|
- |
|
| 27 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 28 |
import org.springframework.core.io.InputStreamResource;
|
- |
|
| 29 |
import org.springframework.http.HttpHeaders;
|
- |
|
| 30 |
import org.springframework.http.HttpStatus;
|
- |
|
| 31 |
import org.springframework.http.ResponseEntity;
|
- |
|
| 32 |
import org.springframework.stereotype.Controller;
|
- |
|
| 33 |
import org.springframework.ui.Model;
|
- |
|
| 34 |
import org.springframework.web.bind.annotation.RequestBody;
|
- |
|
| 35 |
import org.springframework.web.bind.annotation.RequestMapping;
|
- |
|
| 36 |
import org.springframework.web.bind.annotation.RequestMethod;
|
- |
|
| 37 |
import org.springframework.web.bind.annotation.RequestParam;
|
- |
|
| 38 |
import org.springframework.web.bind.annotation.RequestPart;
|
- |
|
| 39 |
import org.springframework.web.multipart.MultipartFile;
|
- |
|
| 40 |
|
- |
|
| 41 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| 42 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
4 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 43 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 44 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
6 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 45 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
7 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| Line 51... |
Line 13... |
| 51 |
import com.spice.profitmandi.dao.entity.logistics.ProviderDetails;
|
13 |
import com.spice.profitmandi.dao.entity.logistics.ProviderDetails;
|
| 52 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
14 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
| 53 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
15 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
| 54 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
16 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 55 |
import com.spice.profitmandi.dao.entity.user.Address;
|
17 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 56 |
import com.spice.profitmandi.dao.model.BilledOrderListModel;
|
- |
|
| 57 |
import com.spice.profitmandi.dao.model.DelayBillingModel;
|
- |
|
| 58 |
import com.spice.profitmandi.dao.model.DelayDayModel;
|
18 |
import com.spice.profitmandi.dao.model.*;
|
| 59 |
import com.spice.profitmandi.dao.model.DispatchNotificationModel;
|
- |
|
| 60 |
import com.spice.profitmandi.dao.model.MarkDeliveredModel;
|
- |
|
| 61 |
import com.spice.profitmandi.dao.model.ProviderDetailModel;
|
- |
|
| 62 |
import com.spice.profitmandi.dao.model.ProviderTatModel;
|
- |
|
| 63 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
19 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 64 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
20 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 65 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
21 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 66 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
22 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 67 |
import com.spice.profitmandi.dao.repository.logistics.ProviderDetailsRepository;
|
23 |
import com.spice.profitmandi.dao.repository.logistics.ProviderDetailsRepository;
|
| Line 75... |
Line 31... |
| 75 |
import com.spice.profitmandi.service.LogisticsService;
|
31 |
import com.spice.profitmandi.service.LogisticsService;
|
| 76 |
import com.spice.profitmandi.service.NotificationService;
|
32 |
import com.spice.profitmandi.service.NotificationService;
|
| 77 |
import com.spice.profitmandi.web.model.LoginDetails;
|
33 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 78 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
34 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 79 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
35 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 80 |
|
- |
|
| 81 |
import in.shop2020.logistics.DeliveryType;
|
36 |
import in.shop2020.logistics.DeliveryType;
|
| 82 |
import in.shop2020.logistics.PickUpType;
|
37 |
import in.shop2020.logistics.PickUpType;
|
| 83 |
import in.shop2020.model.v1.order.OrderStatus;
|
38 |
import in.shop2020.model.v1.order.OrderStatus;
|
| - |
|
39 |
import org.apache.commons.csv.CSVRecord;
|
| - |
|
40 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
41 |
import org.apache.logging.log4j.Logger;
|
| - |
|
42 |
import org.json.JSONArray;
|
| - |
|
43 |
import org.json.JSONObject;
|
| - |
|
44 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
45 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
46 |
import org.springframework.http.HttpHeaders;
|
| - |
|
47 |
import org.springframework.http.HttpStatus;
|
| - |
|
48 |
import org.springframework.http.ResponseEntity;
|
| - |
|
49 |
import org.springframework.stereotype.Controller;
|
| - |
|
50 |
import org.springframework.ui.Model;
|
| - |
|
51 |
import org.springframework.web.bind.annotation.*;
|
| - |
|
52 |
import org.springframework.web.multipart.MultipartFile;
|
| - |
|
53 |
|
| - |
|
54 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
55 |
import javax.servlet.http.HttpServletResponse;
|
| - |
|
56 |
import javax.transaction.Transactional;
|
| - |
|
57 |
import java.io.ByteArrayInputStream;
|
| - |
|
58 |
import java.io.InputStream;
|
| - |
|
59 |
import java.time.LocalDate;
|
| - |
|
60 |
import java.time.LocalDateTime;
|
| - |
|
61 |
import java.time.format.DateTimeFormatter;
|
| - |
|
62 |
import java.util.*;
|
| - |
|
63 |
import java.util.Map.Entry;
|
| - |
|
64 |
import java.util.stream.Collectors;
|
| 84 |
|
65 |
|
| 85 |
@Controller
|
66 |
@Controller
|
| 86 |
@Transactional(rollbackOn = Throwable.class)
|
67 |
@Transactional(rollbackOn = Throwable.class)
|
| 87 |
public class LogisticsController {
|
68 |
public class LogisticsController {
|
| 88 |
|
69 |
|
| Line 472... |
Line 453... |
| 472 |
|
453 |
|
| 473 |
LOGGER.info("fileName" + fileName);
|
454 |
LOGGER.info("fileName" + fileName);
|
| 474 |
LOGGER.info("fileNames" + fileNames);
|
455 |
LOGGER.info("fileNames" + fileNames);
|
| 475 |
List<CSVRecord> records = FileUtil.readFile(file);
|
456 |
List<CSVRecord> records = FileUtil.readFile(file);
|
| 476 |
|
457 |
|
| 477 |
List<ProviderTatModel> providerTatList = new ArrayList<ProviderTatModel>();
|
458 |
List<ProviderTatModel> providerTatList = new ArrayList<>();
|
| 478 |
for (CSVRecord record : records) {
|
459 |
for (CSVRecord record : records) {
|
| 479 |
ProviderTatModel sgr = createProviderTat(record);
|
460 |
ProviderTatModel sgr = createProviderTat(record);
|
| 480 |
providerTatList.add(sgr);
|
461 |
providerTatList.add(sgr);
|
| 481 |
|
462 |
|
| 482 |
}
|
463 |
}
|
| 483 |
if (!providerTatList.isEmpty()) {
|
464 |
if (!providerTatList.isEmpty()) {
|
| 484 |
|
465 |
|
| 485 |
for (ProviderTatModel pt : providerTatList) {
|
466 |
for (ProviderTatModel pt : providerTatList) {
|
| 486 |
|
467 |
|
| 487 |
LOGGER.info("ProviderTatModel" + pt);
|
- |
|
| 488 |
|
468 |
|
| 489 |
Provider provider = providerRepository.selectByName(pt.getProviderName());
|
469 |
Provider provider = providerRepository.selectByName(pt.getProviderName());
|
| 490 |
|
470 |
|
| 491 |
if (provider == null) {
|
471 |
if (provider == null) {
|
| 492 |
throw new ProfitMandiBusinessException("Uploaded File", "", "Provider is not Available");
|
472 |
throw new ProfitMandiBusinessException("Uploaded File", "", "Provider is not Available");
|
| Line 771... |
Line 751... |
| 771 |
if (!deliveredList.isEmpty()) {
|
751 |
if (!deliveredList.isEmpty()) {
|
| 772 |
|
752 |
|
| 773 |
List<Order> vorders = orderRepository.selectByAirwayBillNumber(
|
753 |
List<Order> vorders = orderRepository.selectByAirwayBillNumber(
|
| 774 |
deliveredList.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toList()));
|
754 |
deliveredList.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toList()));
|
| 775 |
|
755 |
|
| 776 |
List<Order> filteredorders = vorders.stream().filter(x -> (x.getStatus() != (OrderStatus.SHIPPED_FROM_WH)
|
756 |
List<Order> filteredorders = vorders.stream().filter(x -> (!x.getStatus().equals(OrderStatus.SHIPPED_FROM_WH)
|
| 777 |
&& x.getStatus() != (OrderStatus.DELIVERY_SUCCESS))).collect(Collectors.toList());
|
757 |
&& !x.getStatus().equals(OrderStatus.DELIVERY_SUCCESS))).collect(Collectors.toList());
|
| 778 |
|
758 |
|
| 779 |
LOGGER.info("filteredOrder" + filteredorders);
|
759 |
LOGGER.info("filteredOrder" + filteredorders);
|
| 780 |
|
760 |
|
| 781 |
if (!filteredorders.isEmpty()) {
|
761 |
if (!filteredorders.isEmpty()) {
|
| 782 |
throw new ProfitMandiBusinessException("Upload File",
|
762 |
throw new ProfitMandiBusinessException("Upload File",
|
| Line 790... |
Line 770... |
| 790 |
.collect(Collectors.groupingBy(Order::getAirwayBillNumber));
|
770 |
.collect(Collectors.groupingBy(Order::getAirwayBillNumber));
|
| 791 |
|
771 |
|
| 792 |
for (MarkDeliveredModel dl : deliveredList) {
|
772 |
for (MarkDeliveredModel dl : deliveredList) {
|
| 793 |
|
773 |
|
| 794 |
List<Order> orders = airwayBillOrderMap.get(dl.getAirwayBillNumber());
|
774 |
List<Order> orders = airwayBillOrderMap.get(dl.getAirwayBillNumber());
|
| 795 |
if (!orders.isEmpty()) {
|
775 |
if (orders != null) {
|
| 796 |
|
- |
|
| 797 |
for (Order order : orders) {
|
776 |
for (Order order : orders) {
|
| 798 |
order.setDeliveryTimestamp(dl.getDeliveredOn());
|
777 |
order.setDeliveryTimestamp(dl.getDeliveredOn());
|
| 799 |
order.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
778 |
order.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
| 800 |
order.setStatusDescription("Order Delivered");
|
779 |
order.setStatusDescription("Order Delivered");
|
| 801 |
|
780 |
|