| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import com.spice.profitmandi.service.warehouse.BillingWarehouseService;
|
| - |
|
4 |
|
| 3 |
import com.google.gson.Gson;
|
5 |
import com.google.gson.Gson;
|
| 4 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
6 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
7 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 6 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
8 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 7 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
9 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| Line 69... |
Line 71... |
| 69 |
@Controller
|
71 |
@Controller
|
| 70 |
@Transactional(rollbackFor = Throwable.class)
|
72 |
@Transactional(rollbackFor = Throwable.class)
|
| 71 |
public class LogisticsController {
|
73 |
public class LogisticsController {
|
| 72 |
|
74 |
|
| 73 |
@Autowired
|
75 |
@Autowired
|
| - |
|
76 |
private BillingWarehouseService billingWarehouseService;
|
| - |
|
77 |
|
| - |
|
78 |
|
| - |
|
79 |
@Autowired
|
| 74 |
private OrderRepository orderRepository;
|
80 |
private OrderRepository orderRepository;
|
| 75 |
|
81 |
|
| 76 |
@Autowired
|
82 |
@Autowired
|
| 77 |
private ProviderRepository providerRepository;
|
83 |
private ProviderRepository providerRepository;
|
| 78 |
|
84 |
|
| Line 210... |
Line 216... |
| 210 |
List<Position> positions = positionRepository.selectAllByAuthUserId(authUser.getId());
|
216 |
List<Position> positions = positionRepository.selectAllByAuthUserId(authUser.getId());
|
| 211 |
|
217 |
|
| 212 |
List<Position> warehousePositions = positions.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE).collect(Collectors.toList());
|
218 |
List<Position> warehousePositions = positions.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE).collect(Collectors.toList());
|
| 213 |
List<Integer> authWarehouseIds = null;
|
219 |
List<Integer> authWarehouseIds = null;
|
| 214 |
if (warehousePositions.stream().filter(x -> EscalationType.L2.isGreaterThanEqualTo(x.getEscalationType())).count() > 0) {
|
220 |
if (warehousePositions.stream().filter(x -> EscalationType.L2.isGreaterThanEqualTo(x.getEscalationType())).count() > 0) {
|
| 215 |
authWarehouseIds = new ArrayList<>(ProfitMandiConstants.WAREHOUSE_MAP.keySet());
|
221 |
authWarehouseIds = new ArrayList<>(billingWarehouseService.getOperationalWarehouses().keySet());
|
| 216 |
} else {
|
222 |
} else {
|
| 217 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
223 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 218 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
224 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
| 219 |
positionRetailers.addAll(customRetailers);
|
225 |
positionRetailers.addAll(customRetailers);
|
| 220 |
});
|
226 |
});
|
| Line 434... |
Line 440... |
| 434 |
}
|
440 |
}
|
| 435 |
|
441 |
|
| 436 |
@RequestMapping(value = "/getProviderTat", method = RequestMethod.GET)
|
442 |
@RequestMapping(value = "/getProviderTat", method = RequestMethod.GET)
|
| 437 |
public String getProviderTat(HttpServletRequest request, @RequestParam int providerId, Model model) throws Exception {
|
443 |
public String getProviderTat(HttpServletRequest request, @RequestParam int providerId, Model model) throws Exception {
|
| 438 |
List<ProviderTat> providerTat = providerTatRepository.selectByProviderId(providerId);
|
444 |
List<ProviderTat> providerTat = providerTatRepository.selectByProviderId(providerId);
|
| 439 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
445 |
Map<Integer, String> warehouseMap = billingWarehouseService.getOperationalWarehouses();
|
| 440 |
|
446 |
|
| 441 |
providerTat = providerTat.stream().filter(x -> warehouseMap.containsKey(x.getWarehouseLocation())).collect(Collectors.toList());
|
447 |
providerTat = providerTat.stream().filter(x -> warehouseMap.containsKey(x.getWarehouseLocation())).collect(Collectors.toList());
|
| 442 |
|
448 |
|
| 443 |
Map<Integer, Provider> providerIdMap = new HashMap<>();
|
449 |
Map<Integer, Provider> providerIdMap = new HashMap<>();
|
| 444 |
Provider provider = providerRepository.selectById(providerId);
|
450 |
Provider provider = providerRepository.selectById(providerId);
|
| Line 479... |
Line 485... |
| 479 |
|
485 |
|
| 480 |
if (provider == null) {
|
486 |
if (provider == null) {
|
| 481 |
throw new ProfitMandiBusinessException("Uploaded File", "", "Provider is not Available");
|
487 |
throw new ProfitMandiBusinessException("Uploaded File", "", "Provider is not Available");
|
| 482 |
}
|
488 |
}
|
| 483 |
|
489 |
|
| 484 |
Map<String, Integer> warehouseMap = ProfitMandiConstants.WAREHOUSE_NAME_MAP;
|
490 |
Integer warehouseLocation = billingWarehouseService.getIdByName(pt.getWarehouseName());
|
| 485 |
ProviderTat providerTat = providerTatRepository.selectByProviderId(provider.getId(), warehouseMap.get(pt.getWarehouseName()), pt.getPincode());
|
491 |
ProviderTat providerTat = providerTatRepository.selectByProviderId(provider.getId(), warehouseLocation, pt.getPincode());
|
| 486 |
|
492 |
|
| 487 |
LOGGER.info("providerTat" + providerTat);
|
493 |
LOGGER.info("providerTat" + providerTat);
|
| 488 |
if (providerTat == null) {
|
494 |
if (providerTat == null) {
|
| 489 |
LOGGER.info("providerTat" + providerTat);
|
495 |
LOGGER.info("providerTat" + providerTat);
|
| 490 |
providerTat = new ProviderTat();
|
496 |
providerTat = new ProviderTat();
|
| 491 |
providerTat.setDestinationPin(pt.getPincode());
|
497 |
providerTat.setDestinationPin(pt.getPincode());
|
| 492 |
providerTat.setProviderId(provider.getId());
|
498 |
providerTat.setProviderId(provider.getId());
|
| 493 |
providerTat.setWarehouseLocation(warehouseMap.get(pt.getWarehouseName()));
|
499 |
providerTat.setWarehouseLocation(warehouseLocation);
|
| 494 |
providerTat.setDeliveryTime(pt.getTat());
|
500 |
providerTat.setDeliveryTime(pt.getTat());
|
| 495 |
providerTatRepository.persist(providerTat);
|
501 |
providerTatRepository.persist(providerTat);
|
| 496 |
} else {
|
502 |
} else {
|
| 497 |
LOGGER.info("providerTat else" + providerTat);
|
503 |
LOGGER.info("providerTat else" + providerTat);
|
| 498 |
providerTat.setDeliveryTime(pt.getTat());
|
504 |
providerTat.setDeliveryTime(pt.getTat());
|
| Line 571... |
Line 577... |
| 571 |
|
577 |
|
| 572 |
private Map<Integer, String> getWarehouses(Set<CustomRetailer> positionRetailers) {
|
578 |
private Map<Integer, String> getWarehouses(Set<CustomRetailer> positionRetailers) {
|
| 573 |
Map<Integer, String> warehouses = new HashMap<>();
|
579 |
Map<Integer, String> warehouses = new HashMap<>();
|
| 574 |
positionRetailers.stream().forEach(x -> {
|
580 |
positionRetailers.stream().forEach(x -> {
|
| 575 |
if (x.getWarehouseId() != 0) {
|
581 |
if (x.getWarehouseId() != 0) {
|
| 576 |
warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId()));
|
582 |
warehouses.put(x.getWarehouseId(), billingWarehouseService.getName(x.getWarehouseId()));
|
| 577 |
}
|
583 |
}
|
| 578 |
});
|
584 |
});
|
| 579 |
return warehouses;
|
585 |
return warehouses;
|
| 580 |
|
586 |
|
| 581 |
}
|
587 |
}
|
| 582 |
|
588 |
|
| 583 |
@RequestMapping(value = "/downloadProviderTatTemplate", method = RequestMethod.GET)
|
589 |
@RequestMapping(value = "/downloadProviderTatTemplate", method = RequestMethod.GET)
|
| 584 |
public ResponseEntity<?> downloadProviderTatTemplate(HttpServletRequest request) throws Exception {
|
590 |
public ResponseEntity<?> downloadProviderTatTemplate(HttpServletRequest request) throws Exception {
|
| 585 |
List<List<?>> rows = new ArrayList<>();
|
591 |
List<List<?>> rows = new ArrayList<>();
|
| 586 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
592 |
Map<Integer, String> warehouseMap = billingWarehouseService.getOperationalWarehouses();
|
| 587 |
for (Entry<Integer, String> warehouse : warehouseMap.entrySet()) {
|
593 |
for (Entry<Integer, String> warehouse : warehouseMap.entrySet()) {
|
| 588 |
rows.add(Arrays.asList("Delhivery", warehouse.getValue(), "110018", "-"));
|
594 |
rows.add(Arrays.asList("Delhivery", warehouse.getValue(), "110018", "-"));
|
| 589 |
}
|
595 |
}
|
| 590 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
596 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 591 |
Arrays.asList("Provider Name", "Source Warehouse", "Destination Pincode", "TAT in days"), rows);
|
597 |
Arrays.asList("Provider Name", "Source Warehouse", "Destination Pincode", "TAT in days"), rows);
|