| 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;
|
3 |
import java.io.ByteArrayInputStream;
|
| 4 |
import java.io.ByteArrayOutputStream;
|
- |
|
| 5 |
import java.io.IOException;
|
4 |
import java.io.IOException;
|
| 6 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| 7 |
import java.io.InputStreamReader;
|
6 |
import java.io.InputStreamReader;
|
| 8 |
import java.time.LocalDate;
|
7 |
import java.time.LocalDate;
|
| 9 |
import java.time.LocalDateTime;
|
8 |
import java.time.LocalDateTime;
|
| Line 26... |
Line 25... |
| 26 |
import org.apache.commons.csv.CSVFormat;
|
25 |
import org.apache.commons.csv.CSVFormat;
|
| 27 |
import org.apache.commons.csv.CSVParser;
|
26 |
import org.apache.commons.csv.CSVParser;
|
| 28 |
import org.apache.commons.csv.CSVRecord;
|
27 |
import org.apache.commons.csv.CSVRecord;
|
| 29 |
import org.apache.logging.log4j.LogManager;
|
28 |
import org.apache.logging.log4j.LogManager;
|
| 30 |
import org.apache.logging.log4j.Logger;
|
29 |
import org.apache.logging.log4j.Logger;
|
| 31 |
import org.apache.poi.ss.usermodel.CellStyle;
|
- |
|
| 32 |
import org.apache.poi.ss.usermodel.CreationHelper;
|
- |
|
| 33 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
- |
|
| 34 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
- |
|
| 35 |
import org.json.JSONArray;
|
30 |
import org.json.JSONArray;
|
| 36 |
import org.json.JSONObject;
|
31 |
import org.json.JSONObject;
|
| 37 |
import org.springframework.beans.factory.annotation.Autowired;
|
32 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 38 |
import org.springframework.core.io.InputStreamResource;
|
33 |
import org.springframework.core.io.InputStreamResource;
|
| 39 |
import org.springframework.http.HttpHeaders;
|
34 |
import org.springframework.http.HttpHeaders;
|
| Line 53... |
Line 48... |
| 53 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
48 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 54 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
49 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 55 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
50 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 56 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
51 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 57 |
import com.spice.profitmandi.common.util.FileUtil;
|
52 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 58 |
import com.spice.profitmandi.common.util.StringUtils;
|
- |
|
| 59 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
53 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 60 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
54 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 61 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
55 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
| 62 |
import com.spice.profitmandi.dao.entity.logistics.ProviderDetails;
|
56 |
import com.spice.profitmandi.dao.entity.logistics.ProviderDetails;
|
| 63 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
57 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
| 64 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
58 |
import com.spice.profitmandi.dao.entity.logistics.PublicHolidays;
|
| 65 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
59 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 66 |
import com.spice.profitmandi.dao.model.BilledOrderListModel;
|
60 |
import com.spice.profitmandi.dao.model.BilledOrderListModel;
|
| - |
|
61 |
import com.spice.profitmandi.dao.model.DelayDayModel;
|
| 67 |
import com.spice.profitmandi.dao.model.DispatchNotificationModel;
|
62 |
import com.spice.profitmandi.dao.model.DispatchNotificationModel;
|
| - |
|
63 |
import com.spice.profitmandi.dao.model.MarkDeliveredModel;
|
| 68 |
import com.spice.profitmandi.dao.model.ProviderDetailModel;
|
64 |
import com.spice.profitmandi.dao.model.ProviderDetailModel;
|
| 69 |
import com.spice.profitmandi.dao.model.ProviderTatModel;
|
65 |
import com.spice.profitmandi.dao.model.ProviderTatModel;
|
| 70 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
66 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 71 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
67 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 72 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
68 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| Line 135... |
Line 131... |
| 135 |
|
131 |
|
| 136 |
@RequestMapping(value = "/logistics", method = RequestMethod.GET)
|
132 |
@RequestMapping(value = "/logistics", method = RequestMethod.GET)
|
| 137 |
public String logistics(HttpServletRequest request, Model model) throws Exception {
|
133 |
public String logistics(HttpServletRequest request, Model model) throws Exception {
|
| 138 |
ProviderTat pt = providerTatRepository.selectByProviderId(1, 7678, "110018");
|
134 |
ProviderTat pt = providerTatRepository.selectByProviderId(1, 7678, "110018");
|
| 139 |
|
135 |
|
| 140 |
LocalDate date = logisticsService.calculateDeliveryTimeline(pt);
|
- |
|
| 141 |
|
- |
|
| 142 |
LOGGER.info("date" + date);
|
- |
|
| 143 |
return "logistics";
|
136 |
return "logistics";
|
| 144 |
|
137 |
|
| 145 |
}
|
138 |
}
|
| 146 |
|
139 |
|
| 147 |
@RequestMapping(value = "/authorisedWarehouses")
|
140 |
@RequestMapping(value = "/authorisedWarehouses")
|
| Line 186... |
Line 179... |
| 186 |
String fileNames = file.getOriginalFilename();
|
179 |
String fileNames = file.getOriginalFilename();
|
| 187 |
|
180 |
|
| 188 |
LOGGER.info("fileName" + fileName);
|
181 |
LOGGER.info("fileName" + fileName);
|
| 189 |
LOGGER.info("fileNames" + fileNames);
|
182 |
LOGGER.info("fileNames" + fileNames);
|
| 190 |
|
183 |
|
| - |
|
184 |
List<CSVRecord> records = this.readFile(file);
|
| - |
|
185 |
|
| 191 |
List<BilledOrderListModel> billedOrderList = this.readFile(file);
|
186 |
List<BilledOrderListModel> billedOrderList = new ArrayList<BilledOrderListModel>();
|
| - |
|
187 |
for (CSVRecord record : records) {
|
| - |
|
188 |
BilledOrderListModel blm = createBilleOrder(record);
|
| - |
|
189 |
billedOrderList.add(blm);
|
| - |
|
190 |
LOGGER.info("records" + record.get(1));
|
| - |
|
191 |
}
|
| 192 |
|
192 |
|
| 193 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
193 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 194 |
String email = loginDetails.getEmailId();
|
194 |
String email = loginDetails.getEmailId();
|
| 195 |
|
195 |
|
| 196 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
196 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
| Line 280... |
Line 280... |
| 280 |
Set<String> invoiceNumber = new HashSet<>();
|
280 |
Set<String> invoiceNumber = new HashSet<>();
|
| 281 |
invoiceNumber.addAll(dn.getValue().getInvoiceNumber());
|
281 |
invoiceNumber.addAll(dn.getValue().getInvoiceNumber());
|
| 282 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
282 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 283 |
sendNotificationModel.setCampaignName("Order Shipped");
|
283 |
sendNotificationModel.setCampaignName("Order Shipped");
|
| 284 |
sendNotificationModel.setTitle("Order Shipped");
|
284 |
sendNotificationModel.setTitle("Order Shipped");
|
| 285 |
sendNotificationModel.setMessage(String.format("Dear customer, your items with Invoice Number "
|
285 |
sendNotificationModel.setMessage(String.format("Dear partner, your items with Invoice Number "
|
| 286 |
+ String.join(",", invoiceNumber) + " worth Rs." + dn.getValue().getTotalAmount()
|
286 |
+ String.join(",", invoiceNumber) + " worth Rs." + dn.getValue().getTotalAmount()
|
| 287 |
+ " and qty " + dn.getValue().getTotalQty() + " has been shipped through "
|
287 |
+ " and qty " + dn.getValue().getTotalQty() + " has been shipped through "
|
| 288 |
+ pr.getName() + " via your track id " + dn.getKey() + " and will be delivered by "
|
288 |
+ pr.getName() + " via your track id " + dn.getKey() + " and will be delivered by "
|
| 289 |
+ dn.getValue().getDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))));
|
289 |
+ dn.getValue().getDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))));
|
| 290 |
sendNotificationModel.setType("url");
|
290 |
sendNotificationModel.setType("url");
|
| 291 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/dashboard");
|
291 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 292 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
292 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| 293 |
sendNotificationModel.setMessageType(MessageType.notification);
|
293 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 294 |
int userId = userAccountRepository.selectUserIdByRetailerId(dn.getValue().getFofoId());
|
294 |
int userId = userAccountRepository.selectUserIdByRetailerId(dn.getValue().getFofoId());
|
| 295 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
295 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 296 |
notificationService.sendNotification(sendNotificationModel);
|
296 |
notificationService.sendNotification(sendNotificationModel);
|
| Line 307... |
Line 307... |
| 307 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
307 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 308 |
return "response";
|
308 |
return "response";
|
| 309 |
|
309 |
|
| 310 |
}
|
310 |
}
|
| 311 |
|
311 |
|
| 312 |
private List<BilledOrderListModel> readFile(MultipartFile file) throws Exception {
|
- |
|
| 313 |
CSVParser parser = new CSVParser(new InputStreamReader(file.getInputStream()), CSVFormat.DEFAULT);
|
- |
|
| 314 |
List<CSVRecord> records = parser.getRecords();
|
- |
|
| 315 |
LOGGER.info("records" + records);
|
- |
|
| 316 |
LOGGER.info("parser" + parser);
|
- |
|
| 317 |
if (records.size() < 2) {
|
- |
|
| 318 |
parser.close();
|
- |
|
| 319 |
throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
|
- |
|
| 320 |
}
|
- |
|
| 321 |
// Remove header
|
- |
|
| 322 |
records.remove(0);
|
- |
|
| 323 |
List<BilledOrderListModel> returnList = new ArrayList<BilledOrderListModel>();
|
- |
|
| 324 |
for (CSVRecord record : records) {
|
- |
|
| 325 |
BilledOrderListModel cp = null;
|
- |
|
| 326 |
BilledOrderListModel sgr = createBilleOrder(record);
|
- |
|
| 327 |
returnList.add(sgr);
|
- |
|
| 328 |
|
- |
|
| 329 |
LOGGER.info("records" + record.get(1));
|
- |
|
| 330 |
}
|
- |
|
| 331 |
parser.close();
|
- |
|
| 332 |
return returnList;
|
- |
|
| 333 |
}
|
- |
|
| 334 |
|
- |
|
| 335 |
private BilledOrderListModel createBilleOrder(CSVRecord record) {
|
312 |
private BilledOrderListModel createBilleOrder(CSVRecord record) {
|
| 336 |
BilledOrderListModel bol = new BilledOrderListModel();
|
313 |
BilledOrderListModel bol = new BilledOrderListModel();
|
| 337 |
bol.setInvoiceNumber(record.get(0));
|
314 |
bol.setInvoiceNumber(record.get(0));
|
| 338 |
bol.setLogisticsProviderName(record.get(1));
|
315 |
bol.setLogisticsProviderName(record.get(1));
|
| 339 |
bol.setAirwayBillNumber(record.get(2));
|
316 |
bol.setAirwayBillNumber(record.get(2));
|
| Line 425... |
Line 402... |
| 425 |
|
402 |
|
| 426 |
String fileNames = file.getOriginalFilename();
|
403 |
String fileNames = file.getOriginalFilename();
|
| 427 |
|
404 |
|
| 428 |
LOGGER.info("fileName" + fileName);
|
405 |
LOGGER.info("fileName" + fileName);
|
| 429 |
LOGGER.info("fileNames" + fileNames);
|
406 |
LOGGER.info("fileNames" + fileNames);
|
| - |
|
407 |
List<CSVRecord> records = this.readFile(file);
|
| - |
|
408 |
|
| 430 |
List<ProviderTatModel> providerTatList = this.readTatFile(file);
|
409 |
List<ProviderTatModel> providerTatList = new ArrayList<ProviderTatModel>();
|
| - |
|
410 |
for (CSVRecord record : records) {
|
| - |
|
411 |
ProviderTatModel sgr = createProviderTat(record);
|
| - |
|
412 |
providerTatList.add(sgr);
|
| - |
|
413 |
|
| - |
|
414 |
}
|
| 431 |
if (!providerTatList.isEmpty()) {
|
415 |
if (!providerTatList.isEmpty()) {
|
| 432 |
|
416 |
|
| 433 |
for (ProviderTatModel pt : providerTatList) {
|
417 |
for (ProviderTatModel pt : providerTatList) {
|
| 434 |
|
418 |
|
| 435 |
LOGGER.info("ProviderTatModel" + pt);
|
419 |
LOGGER.info("ProviderTatModel" + pt);
|
| Line 463... |
Line 447... |
| 463 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
447 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 464 |
return "response";
|
448 |
return "response";
|
| 465 |
|
449 |
|
| 466 |
}
|
450 |
}
|
| 467 |
|
451 |
|
| 468 |
private List<ProviderTatModel> readTatFile(MultipartFile file) throws Exception {
|
- |
|
| 469 |
|
- |
|
| 470 |
CSVParser parser = new CSVParser(new InputStreamReader(file.getInputStream()), CSVFormat.DEFAULT);
|
- |
|
| 471 |
List<CSVRecord> records = parser.getRecords();
|
- |
|
| 472 |
LOGGER.info("records" + records);
|
- |
|
| 473 |
LOGGER.info("parser" + parser);
|
- |
|
| 474 |
if (records.size() < 2) {
|
- |
|
| 475 |
parser.close();
|
- |
|
| 476 |
throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
|
- |
|
| 477 |
}
|
- |
|
| 478 |
// Remove header
|
- |
|
| 479 |
records.remove(0);
|
- |
|
| 480 |
List<ProviderTatModel> returnList = new ArrayList<ProviderTatModel>();
|
- |
|
| 481 |
for (CSVRecord record : records) {
|
- |
|
| 482 |
ProviderTatModel sgr = createProviderTat(record);
|
- |
|
| 483 |
returnList.add(sgr);
|
- |
|
| 484 |
|
- |
|
| 485 |
LOGGER.info("records" + record.get(1));
|
- |
|
| 486 |
}
|
- |
|
| 487 |
parser.close();
|
- |
|
| 488 |
return returnList;
|
- |
|
| 489 |
}
|
- |
|
| 490 |
|
- |
|
| 491 |
private ProviderTatModel createProviderTat(CSVRecord record) {
|
452 |
private ProviderTatModel createProviderTat(CSVRecord record) {
|
| 492 |
ProviderTatModel ptm = new ProviderTatModel();
|
453 |
ProviderTatModel ptm = new ProviderTatModel();
|
| 493 |
ptm.setProviderName(record.get(0));
|
454 |
ptm.setProviderName(record.get(0));
|
| 494 |
ptm.setWarehouseName(record.get(1));
|
455 |
ptm.setWarehouseName(record.get(1));
|
| 495 |
ptm.setPincode(record.get(2));
|
456 |
ptm.setPincode(record.get(2));
|
| Line 586... |
Line 547... |
| 586 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
547 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| 587 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
548 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 588 |
|
549 |
|
| 589 |
}
|
550 |
}
|
| 590 |
|
551 |
|
| - |
|
552 |
@RequestMapping(value = "/downloadDelayDayTemplate", method = RequestMethod.GET)
|
| - |
|
553 |
public ResponseEntity<?> downloadDelayDayTemplate(HttpServletRequest request) throws Exception {
|
| - |
|
554 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
555 |
|
| - |
|
556 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
| - |
|
557 |
.getCSVByteStream(Arrays.asList("AirwayBillNumber", "Delay Day", "Reason"), rows);
|
| - |
|
558 |
|
| - |
|
559 |
final HttpHeaders headers = new HttpHeaders();
|
| - |
|
560 |
headers.set("Content-Type", "text/csv");
|
| - |
|
561 |
headers.set("Content-disposition", "inline; filename=delay-day-template.csv");
|
| - |
|
562 |
headers.setContentLength(baos.toByteArray().length);
|
| - |
|
563 |
|
| - |
|
564 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
| - |
|
565 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| - |
|
566 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| - |
|
567 |
|
| - |
|
568 |
}
|
| - |
|
569 |
|
| - |
|
570 |
@RequestMapping(value = "/delayDayFileUpload", method = RequestMethod.POST)
|
| - |
|
571 |
public String delayDayFileUpload(HttpServletRequest request, Model model, HttpServletResponse response,
|
| - |
|
572 |
@RequestPart MultipartFile file) throws Throwable {
|
| - |
|
573 |
|
| - |
|
574 |
List<CSVRecord> records = this.readFile(file);
|
| - |
|
575 |
|
| - |
|
576 |
List<DelayDayModel> delayDayList = new ArrayList<>();
|
| - |
|
577 |
for (CSVRecord record : records) {
|
| - |
|
578 |
DelayDayModel ddm = createDelayDay(record);
|
| - |
|
579 |
delayDayList.add(ddm);
|
| - |
|
580 |
|
| - |
|
581 |
}
|
| - |
|
582 |
|
| - |
|
583 |
if (!delayDayList.isEmpty()) {
|
| - |
|
584 |
|
| - |
|
585 |
List<Order> vorders = orderRepository.selectByAirwayBillNumber(
|
| - |
|
586 |
delayDayList.stream().map(x -> x.getAirwayBIllNumber()).collect(Collectors.toList()));
|
| - |
|
587 |
|
| - |
|
588 |
List<Order> filteredorders = vorders.stream()
|
| - |
|
589 |
.filter(x -> !x.getStatus().equals(OrderStatus.SHIPPED_FROM_WH)).collect(Collectors.toList());
|
| - |
|
590 |
|
| - |
|
591 |
if (!filteredorders.isEmpty()) {
|
| - |
|
592 |
throw new ProfitMandiBusinessException("Upload File", "",
|
| - |
|
593 |
"Order status should be shipped from warehouse");
|
| - |
|
594 |
|
| - |
|
595 |
}
|
| - |
|
596 |
|
| - |
|
597 |
Map<String, List<Order>> airwayBillOrderMap = vorders.stream()
|
| - |
|
598 |
.collect(Collectors.groupingBy(Order::getAirwayBillNumber));
|
| - |
|
599 |
|
| - |
|
600 |
for (DelayDayModel ddm : delayDayList) {
|
| - |
|
601 |
List<Order> orders = airwayBillOrderMap.get(ddm.getAirwayBIllNumber());
|
| - |
|
602 |
|
| - |
|
603 |
if (!orders.isEmpty()) {
|
| - |
|
604 |
|
| - |
|
605 |
Double totalAmount = orders.stream().mapToDouble(x -> x.getTotalAmount()).sum();
|
| - |
|
606 |
|
| - |
|
607 |
List<String> invoiceNumbers = orders.stream().map(x -> x.getInvoiceNumber())
|
| - |
|
608 |
.collect(Collectors.toList());
|
| - |
|
609 |
|
| - |
|
610 |
int totalQty = orders.stream().mapToInt(x -> x.getLineItem().getQuantity()).sum();
|
| - |
|
611 |
|
| - |
|
612 |
Order order = orders.get(0);
|
| - |
|
613 |
ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),
|
| - |
|
614 |
order.getWarehouseId(), order.getRetailerPinCode());
|
| - |
|
615 |
|
| - |
|
616 |
LocalDate deliveryDate = logisticsService.calculateDeliveryTimeline(
|
| - |
|
617 |
order.getShippingTimestamp().toLocalDate(), pt, ddm.getDelayDay());
|
| - |
|
618 |
|
| - |
|
619 |
orders.forEach(x -> x.setExpectedDeliveryTime(deliveryDate.atStartOfDay()));
|
| - |
|
620 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| - |
|
621 |
sendNotificationModel.setCampaignName("Order Update");
|
| - |
|
622 |
sendNotificationModel.setTitle("Order Update");
|
| - |
|
623 |
sendNotificationModel.setMessage(String
|
| - |
|
624 |
.format("Dear partner, your items with Invoice Number " + String.join(",", invoiceNumbers)
|
| - |
|
625 |
+ " worth Rs." + totalAmount + " and qty " + totalQty + " has been shipped through "
|
| - |
|
626 |
+ providerRepository.selectById(order.getLogisticsProviderId()).getName()
|
| - |
|
627 |
+ " via your track id " + ddm.getAirwayBIllNumber() + " has been delayed for "
|
| - |
|
628 |
+ ddm.getReason() + " and will be delivered by "
|
| - |
|
629 |
+ deliveryDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"))));
|
| - |
|
630 |
sendNotificationModel.setType("url");
|
| - |
|
631 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| - |
|
632 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| - |
|
633 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| - |
|
634 |
int userId = userAccountRepository.selectUserIdByRetailerId(order.getRetailerId());
|
| - |
|
635 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| - |
|
636 |
notificationService.sendNotification(sendNotificationModel);
|
| - |
|
637 |
} else {
|
| - |
|
638 |
throw new ProfitMandiBusinessException("Upload File", "",
|
| - |
|
639 |
"No order available for " + ddm.getAirwayBIllNumber() + " airwaybill Number");
|
| - |
|
640 |
|
| - |
|
641 |
}
|
| - |
|
642 |
}
|
| - |
|
643 |
}
|
| - |
|
644 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| - |
|
645 |
return "response";
|
| - |
|
646 |
|
| - |
|
647 |
}
|
| - |
|
648 |
|
| - |
|
649 |
private DelayDayModel createDelayDay(CSVRecord record) {
|
| - |
|
650 |
DelayDayModel ddm = new DelayDayModel();
|
| - |
|
651 |
ddm.setAirwayBIllNumber(record.get(0));
|
| - |
|
652 |
ddm.setDelayDay(Integer.parseInt(record.get(1)));
|
| - |
|
653 |
ddm.setReason(record.get(2));
|
| - |
|
654 |
return ddm;
|
| - |
|
655 |
}
|
| - |
|
656 |
|
| - |
|
657 |
@RequestMapping(value = "/downloadMarkDeliveredTemplate", method = RequestMethod.GET)
|
| - |
|
658 |
public ResponseEntity<?> downloadMarkDeliveredTemplate(HttpServletRequest request) throws Exception {
|
| - |
|
659 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
660 |
|
| - |
|
661 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
| - |
|
662 |
.getCSVByteStream(Arrays.asList("AirwayBillNumber", "Delivered On", "Delivered By"), rows);
|
| - |
|
663 |
|
| - |
|
664 |
final HttpHeaders headers = new HttpHeaders();
|
| - |
|
665 |
headers.set("Content-Type", "text/csv");
|
| - |
|
666 |
headers.set("Content-disposition", "inline; filename=mark-delivered-template.csv");
|
| - |
|
667 |
headers.setContentLength(baos.toByteArray().length);
|
| - |
|
668 |
|
| - |
|
669 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
| - |
|
670 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| - |
|
671 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| - |
|
672 |
|
| - |
|
673 |
}
|
| - |
|
674 |
|
| - |
|
675 |
@RequestMapping(value = "/markDeliveredFileUpload", method = RequestMethod.POST)
|
| - |
|
676 |
public String markDeliveredFileUpload(HttpServletRequest request, Model model, HttpServletResponse response,
|
| - |
|
677 |
@RequestPart MultipartFile file) throws Throwable {
|
| - |
|
678 |
|
| - |
|
679 |
List<CSVRecord> records = this.readFile(file);
|
| - |
|
680 |
|
| - |
|
681 |
List<MarkDeliveredModel> deliveredList = new ArrayList<>();
|
| - |
|
682 |
for (CSVRecord record : records) {
|
| - |
|
683 |
MarkDeliveredModel ddm = createMarkDeliveredModel(record);
|
| - |
|
684 |
deliveredList.add(ddm);
|
| - |
|
685 |
|
| - |
|
686 |
}
|
| - |
|
687 |
|
| - |
|
688 |
if (!deliveredList.isEmpty()) {
|
| - |
|
689 |
|
| - |
|
690 |
List<Order> vorders = orderRepository.selectByAirwayBillNumber(
|
| - |
|
691 |
deliveredList.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toList()));
|
| - |
|
692 |
|
| - |
|
693 |
List<Order> filteredorders = vorders.stream()
|
| - |
|
694 |
.filter(x -> !x.getStatus().equals(OrderStatus.SHIPPED_FROM_WH)).collect(Collectors.toList());
|
| - |
|
695 |
|
| - |
|
696 |
if (!filteredorders.isEmpty()) {
|
| - |
|
697 |
throw new ProfitMandiBusinessException("Upload File", "",
|
| - |
|
698 |
"Order status should be shipped from warehouse");
|
| - |
|
699 |
|
| - |
|
700 |
}
|
| - |
|
701 |
|
| - |
|
702 |
Map<String, List<Order>> airwayBillOrderMap = vorders.stream()
|
| - |
|
703 |
.collect(Collectors.groupingBy(Order::getAirwayBillNumber));
|
| - |
|
704 |
|
| - |
|
705 |
for (MarkDeliveredModel dl : deliveredList) {
|
| - |
|
706 |
|
| - |
|
707 |
List<Order> orders = airwayBillOrderMap.get(dl.getAirwayBillNumber());
|
| - |
|
708 |
if (!orders.isEmpty()) {
|
| - |
|
709 |
|
| - |
|
710 |
for (Order order : orders) {
|
| - |
|
711 |
order.setDeliveryTimestamp(dl.getDeliveredOn());
|
| - |
|
712 |
order.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
| - |
|
713 |
}
|
| - |
|
714 |
|
| - |
|
715 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| - |
|
716 |
sendNotificationModel.setCampaignName("Order Delivered");
|
| - |
|
717 |
sendNotificationModel.setTitle("Order Delivered");
|
| - |
|
718 |
sendNotificationModel.setMessage(String.format("Dear partner, your SmartDukaan ORDER "
|
| - |
|
719 |
+ dl.getAirwayBillNumber() + "has been delivered to you in a safe, sealed bag by "
|
| - |
|
720 |
+ dl.getDeliveredBy() + "."));
|
| - |
|
721 |
sendNotificationModel.setType("url");
|
| - |
|
722 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| - |
|
723 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| - |
|
724 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| - |
|
725 |
int userId = userAccountRepository.selectUserIdByRetailerId(orders.get(0).getRetailerId());
|
| - |
|
726 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| - |
|
727 |
notificationService.sendNotification(sendNotificationModel);
|
| - |
|
728 |
} else {
|
| - |
|
729 |
throw new ProfitMandiBusinessException("Upload File", "",
|
| - |
|
730 |
"No order available for " + dl.getAirwayBillNumber() + " airwaybill Number");
|
| - |
|
731 |
|
| - |
|
732 |
}
|
| - |
|
733 |
}
|
| - |
|
734 |
}
|
| - |
|
735 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| - |
|
736 |
return "response";
|
| - |
|
737 |
|
| - |
|
738 |
}
|
| - |
|
739 |
|
| - |
|
740 |
private MarkDeliveredModel createMarkDeliveredModel(CSVRecord record) {
|
| - |
|
741 |
MarkDeliveredModel mdm = new MarkDeliveredModel();
|
| - |
|
742 |
mdm.setAirwayBillNumber(record.get(0));
|
| - |
|
743 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
| - |
|
744 |
LocalDateTime dateTime = LocalDateTime.parse(record.get(1), formatter);
|
| - |
|
745 |
mdm.setDeliveredOn(dateTime);
|
| - |
|
746 |
mdm.setDeliveredBy(record.get(2));
|
| - |
|
747 |
return mdm;
|
| - |
|
748 |
}
|
| - |
|
749 |
|
| - |
|
750 |
private List<CSVRecord> readFile(MultipartFile file) throws IOException, ProfitMandiBusinessException {
|
| - |
|
751 |
|
| - |
|
752 |
CSVParser parser = new CSVParser(new InputStreamReader(file.getInputStream()), CSVFormat.DEFAULT);
|
| - |
|
753 |
List<CSVRecord> records = parser.getRecords();
|
| - |
|
754 |
LOGGER.info("records" + records);
|
| - |
|
755 |
LOGGER.info("parser" + parser);
|
| - |
|
756 |
if (records.size() < 2) {
|
| - |
|
757 |
parser.close();
|
| - |
|
758 |
throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
|
| - |
|
759 |
}
|
| - |
|
760 |
// Remove header
|
| - |
|
761 |
records.remove(0);
|
| - |
|
762 |
parser.close();
|
| - |
|
763 |
return records;
|
| - |
|
764 |
|
| - |
|
765 |
}
|
| - |
|
766 |
|
| 591 |
}
|
767 |
}
|