| 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;
|
4 |
import java.io.ByteArrayOutputStream;
|
| - |
|
5 |
import java.io.IOException;
|
| 5 |
import java.io.InputStream;
|
6 |
import java.io.InputStream;
|
| 6 |
import java.time.LocalDateTime;
|
7 |
import java.time.LocalDateTime;
|
| - |
|
8 |
import java.time.ZoneOffset;
|
| 7 |
import java.util.ArrayList;
|
9 |
import java.util.ArrayList;
|
| 8 |
import java.util.Arrays;
|
10 |
import java.util.HashMap;
|
| 9 |
import java.util.HashSet;
|
11 |
import java.util.HashSet;
|
| - |
|
12 |
import java.util.Iterator;
|
| 10 |
import java.util.List;
|
13 |
import java.util.List;
|
| 11 |
import java.util.Map;
|
14 |
import java.util.Map;
|
| - |
|
15 |
import java.util.Optional;
|
| 12 |
import java.util.Set;
|
16 |
import java.util.Set;
|
| 13 |
import java.util.stream.Collectors;
|
17 |
import java.util.stream.Collectors;
|
| 14 |
import java.util.stream.Stream;
|
- |
|
| 15 |
|
18 |
|
| - |
|
19 |
import javax.mail.MessagingException;
|
| - |
|
20 |
import javax.mail.internet.InternetAddress;
|
| - |
|
21 |
import javax.mail.internet.MimeMessage;
|
| 16 |
import javax.servlet.http.HttpServletRequest;
|
22 |
import javax.servlet.http.HttpServletRequest;
|
| 17 |
import javax.servlet.http.HttpServletResponse;
|
23 |
import javax.servlet.http.HttpServletResponse;
|
| 18 |
|
24 |
|
| 19 |
import org.apache.logging.log4j.LogManager;
|
25 |
import org.apache.logging.log4j.LogManager;
|
| 20 |
import org.apache.logging.log4j.Logger;
|
26 |
import org.apache.logging.log4j.Logger;
|
| Line 25... |
Line 31... |
| 25 |
import org.springframework.beans.factory.annotation.Value;
|
31 |
import org.springframework.beans.factory.annotation.Value;
|
| 26 |
import org.springframework.core.io.InputStreamResource;
|
32 |
import org.springframework.core.io.InputStreamResource;
|
| 27 |
import org.springframework.http.HttpHeaders;
|
33 |
import org.springframework.http.HttpHeaders;
|
| 28 |
import org.springframework.http.HttpStatus;
|
34 |
import org.springframework.http.HttpStatus;
|
| 29 |
import org.springframework.http.ResponseEntity;
|
35 |
import org.springframework.http.ResponseEntity;
|
| - |
|
36 |
import org.springframework.mail.javamail.JavaMailSender;
|
| - |
|
37 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 30 |
import org.springframework.stereotype.Controller;
|
38 |
import org.springframework.stereotype.Controller;
|
| 31 |
import org.springframework.transaction.annotation.Transactional;
|
39 |
import org.springframework.transaction.annotation.Transactional;
|
| 32 |
import org.springframework.ui.Model;
|
40 |
import org.springframework.ui.Model;
|
| 33 |
import org.springframework.web.bind.annotation.RequestBody;
|
41 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 34 |
import org.springframework.web.bind.annotation.RequestMapping;
|
42 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| Line 39... |
Line 47... |
| 39 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
47 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 40 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
48 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 41 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
49 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 42 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
50 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 43 |
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
|
51 |
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
|
| - |
|
52 |
import com.spice.profitmandi.common.model.NotifyItemIdModel;
|
| - |
|
53 |
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
|
| - |
|
54 |
import com.spice.profitmandi.common.model.NotifyOrderModel;
|
| 44 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
55 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 45 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
56 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 46 |
import com.spice.profitmandi.common.util.Utils;
|
57 |
import com.spice.profitmandi.common.util.Utils;
|
| 47 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
58 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 48 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
59 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| - |
|
60 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
| - |
|
61 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 49 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
62 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 50 |
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
|
63 |
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
|
| - |
|
64 |
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
|
| - |
|
65 |
import com.spice.profitmandi.dao.entity.transaction.NotifyItem;
|
| - |
|
66 |
import com.spice.profitmandi.dao.entity.transaction.NotifyOrder;
|
| 51 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
67 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 52 |
import com.spice.profitmandi.dao.entity.user.User;
|
68 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 53 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
69 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
70 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
71 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| - |
|
72 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| - |
|
73 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 56 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
74 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 57 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
75 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 58 |
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
|
76 |
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
|
| - |
|
77 |
import com.spice.profitmandi.dao.repository.inventory.NotifyStatus;
|
| - |
|
78 |
import com.spice.profitmandi.dao.repository.transaction.NotifyColorChangeRepository;
|
| - |
|
79 |
import com.spice.profitmandi.dao.repository.transaction.NotifyItemRepository;
|
| - |
|
80 |
import com.spice.profitmandi.dao.repository.transaction.NotifyOrderRespository;
|
| 59 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
81 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 60 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
82 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 61 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
83 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 62 |
import com.spice.profitmandi.service.user.RetailerService;
|
84 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 63 |
import com.spice.profitmandi.web.model.LoginDetails;
|
85 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| Line 94... |
Line 116... |
| 94 |
|
116 |
|
| 95 |
@Autowired
|
117 |
@Autowired
|
| 96 |
private ItemRepository itemRepository;
|
118 |
private ItemRepository itemRepository;
|
| 97 |
|
119 |
|
| 98 |
@Autowired
|
120 |
@Autowired
|
| - |
|
121 |
private NotifyItemRepository notifyItemRespository;
|
| - |
|
122 |
|
| - |
|
123 |
@Autowired
|
| 99 |
private RetailerService retailerService;
|
124 |
private RetailerService retailerService;
|
| 100 |
|
125 |
|
| 101 |
@Autowired
|
126 |
@Autowired
|
| 102 |
private MVCResponseSender mvcResponseSender;
|
127 |
private MVCResponseSender mvcResponseSender;
|
| 103 |
|
128 |
|
| Line 107... |
Line 132... |
| 107 |
@Autowired
|
132 |
@Autowired
|
| 108 |
private OrderRepository orderRepository;
|
133 |
private OrderRepository orderRepository;
|
| 109 |
|
134 |
|
| 110 |
@Autowired
|
135 |
@Autowired
|
| 111 |
private UserRepository userRepository;
|
136 |
private UserRepository userRepository;
|
| - |
|
137 |
@Autowired
|
| - |
|
138 |
private NotifyItemRepository notifyItemRepository;
|
| - |
|
139 |
|
| - |
|
140 |
@Autowired
|
| - |
|
141 |
private NotifyColorChangeRepository notifyColorChangeRepository;
|
| - |
|
142 |
|
| - |
|
143 |
@Autowired
|
| - |
|
144 |
private NotifyOrderRespository notifyOrderRespository;
|
| - |
|
145 |
|
| - |
|
146 |
@Autowired
|
| - |
|
147 |
private UserAccountRepository userAccountRepository;
|
| 112 |
|
148 |
|
| 113 |
@Value("${saholic.api.host}")
|
149 |
@Value("${saholic.api.host}")
|
| 114 |
private String host;
|
150 |
private String host;
|
| 115 |
|
151 |
|
| 116 |
@Value("${saholic.api.port}")
|
152 |
@Value("${saholic.api.port}")
|
| 117 |
private int port;
|
153 |
private int port;
|
| 118 |
|
154 |
|
| 119 |
@Value("${saholic.api.webapp}")
|
155 |
@Value("${saholic.api.webapp}")
|
| 120 |
private String webapp;
|
156 |
private String webapp;
|
| 121 |
|
157 |
|
| - |
|
158 |
@Autowired
|
| - |
|
159 |
JavaMailSender mailSender;
|
| - |
|
160 |
|
| - |
|
161 |
@Autowired
|
| - |
|
162 |
private Mongo mongoClient;
|
| - |
|
163 |
|
| 122 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
164 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
| 123 |
public String getCurrentAvailability(HttpServletRequest request,
|
165 |
public String getCurrentAvailability(HttpServletRequest request,
|
| 124 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
166 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 125 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
167 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 126 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
168 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| Line 366... |
Line 408... |
| 366 |
return "feature";
|
408 |
return "feature";
|
| 367 |
|
409 |
|
| 368 |
}
|
410 |
}
|
| 369 |
|
411 |
|
| 370 |
/*
|
412 |
/*
|
| 371 |
* @RequestMapping(value = "/getPaginatedfeature", method =
|
413 |
* @RequestMapping(value = "/getPaginatedfeature", method = RequestMethod.GET)
|
| 372 |
* RequestMethod.GET) public String
|
- |
|
| 373 |
* getPaginatedFeaturePanel(HttpServletRequest request,
|
414 |
* public String getPaginatedFeaturePanel(HttpServletRequest request,
|
| 374 |
*
|
415 |
*
|
| 375 |
* @RequestParam(name = "offset", defaultValue = "0") int offset,
|
416 |
* @RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 376 |
*
|
417 |
*
|
| 377 |
* @RequestParam(name = "limit", defaultValue = "10") int limit, Model
|
418 |
* @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
| 378 |
* model) throws ProfitMandiBusinessException {
|
419 |
* throws ProfitMandiBusinessException {
|
| 379 |
* LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
420 |
* LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 380 |
* List<TagRanking> tagRanking = null;
|
421 |
* List<TagRanking> tagRanking = null;
|
| 381 |
*
|
422 |
*
|
| 382 |
*
|
423 |
*
|
| 383 |
* long size = 0; tagRanking =
|
- |
|
| 384 |
* tagRankingRepository.selectAllTagRanking(offset, limit); if
|
424 |
* long size = 0; tagRanking = tagRankingRepository.selectAllTagRanking(offset,
|
| 385 |
* (!tagRanking.isEmpty()) {
|
425 |
* limit); if (!tagRanking.isEmpty()) {
|
| 386 |
*
|
426 |
*
|
| 387 |
* model.addAttribute("tagRanking", tagRanking); model.addAttribute("start",
|
427 |
* model.addAttribute("tagRanking", tagRanking); model.addAttribute("start",
|
| 388 |
* offset + 1); model.addAttribute("size", size); model.addAttribute("url",
|
428 |
* offset + 1); model.addAttribute("size", size); model.addAttribute("url",
|
| 389 |
* "/getPaginatedfeature");
|
429 |
* "/getPaginatedfeature");
|
| 390 |
*
|
430 |
*
|
| Line 407... |
Line 447... |
| 407 |
}
|
447 |
}
|
| 408 |
|
448 |
|
| 409 |
@RequestMapping(value = "/removeFeature", method = RequestMethod.DELETE)
|
449 |
@RequestMapping(value = "/removeFeature", method = RequestMethod.DELETE)
|
| 410 |
public String removeTagRankingEnteries(HttpServletRequest request,
|
450 |
public String removeTagRankingEnteries(HttpServletRequest request,
|
| 411 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
451 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
| 412 |
|
452 |
|
| 413 |
tagRankingRepository.deleteById(id);
|
453 |
tagRankingRepository.deleteById(id);
|
| 414 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
454 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 415 |
return "response";
|
455 |
return "response";
|
| 416 |
}
|
456 |
}
|
| 417 |
|
457 |
|
| Line 477... |
Line 517... |
| 477 |
@RequestMapping(value = "/getInProcessOrder", method = RequestMethod.GET)
|
517 |
@RequestMapping(value = "/getInProcessOrder", method = RequestMethod.GET)
|
| 478 |
public String getInProcessOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
518 |
public String getInProcessOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 479 |
|
519 |
|
| 480 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
520 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
| 481 |
.selectAllOrderBeforeTwoDaysByStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
521 |
.selectAllOrderBeforeTwoDaysByStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 482 |
List<com.spice.profitmandi.dao.entity.transaction.Order> pendingPaymentorder = orderRepository
|
522 |
List<Integer> retailerIds = new ArrayList<>();
|
| 483 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
523 |
List<Integer> orderIds = new ArrayList<>();
|
| 484 |
OrderStatus.PAYMENT_PENDING);
|
524 |
if (!inProcessorder.isEmpty()) {
|
| 485 |
List<com.spice.profitmandi.dao.entity.transaction.Order> failedPaymentorder = orderRepository
|
525 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
| 486 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
- |
|
| 487 |
OrderStatus.PAYMENT_FAILED);
|
526 |
retailerIds.add(order.getRetailerId());
|
| 488 |
pendingPaymentorder.addAll(failedPaymentorder);
|
527 |
orderIds.add(order.getId());
|
| 489 |
|
528 |
|
| 490 |
model.addAttribute("inProcessorder", inProcessorder);
|
- |
|
| 491 |
model.addAttribute("pendingPaymentorder", pendingPaymentorder);
|
- |
|
| - |
|
529 |
}
|
| 492 |
|
530 |
|
| - |
|
531 |
List<NotifyOrder> notify = notifyOrderRespository.selectByorderIds(orderIds);
|
| - |
|
532 |
for (NotifyOrder notifyOrder : notify) {
|
| - |
|
533 |
List<NotifyItem> notifyItems = notifyItemRepository.selectByNotifyId(notifyOrder.getNotifyId());
|
| - |
|
534 |
Iterator<NotifyItem> notifyItemsIterator = notifyItems.iterator();
|
| - |
|
535 |
|
| - |
|
536 |
while(notifyItemsIterator.hasNext()) {
|
| - |
|
537 |
NotifyItem notifyItem = notifyItemsIterator.next();
|
| - |
|
538 |
if (LocalDateTime.now().isAfter(notifyItem.getResponseTime())) {
|
| - |
|
539 |
notifyItemsIterator.remove();
|
| - |
|
540 |
}
|
| - |
|
541 |
}
|
| - |
|
542 |
if(notifyItems.size() == 0) {
|
| - |
|
543 |
if(NotifyStatus.pending== notifyOrder.getStatus() ) {
|
| - |
|
544 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
| - |
|
545 |
}
|
| - |
|
546 |
}
|
| - |
|
547 |
|
| - |
|
548 |
}
|
| - |
|
549 |
|
| - |
|
550 |
Map<Integer, Optional<NotifyOrder>> notifyOrders = notifyOrderRespository.selectByorderIds(orderIds)
|
| - |
|
551 |
.stream().collect(Collectors.groupingBy(NotifyOrder::getOrderId,
|
| - |
|
552 |
Collectors.maxBy((x1, x2) -> x1.getId() - x2.getId())));
|
| - |
|
553 |
|
| - |
|
554 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
| - |
|
555 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
| - |
|
556 |
List<com.spice.profitmandi.dao.entity.transaction.Order> pendingPaymentorder = orderRepository
|
| - |
|
557 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
| - |
|
558 |
OrderStatus.PAYMENT_PENDING);
|
| - |
|
559 |
List<com.spice.profitmandi.dao.entity.transaction.Order> failedPaymentorder = orderRepository
|
| - |
|
560 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
| - |
|
561 |
OrderStatus.PAYMENT_FAILED);
|
| - |
|
562 |
pendingPaymentorder.addAll(failedPaymentorder);
|
| - |
|
563 |
|
| - |
|
564 |
model.addAttribute("inProcessorder", inProcessorder);
|
| - |
|
565 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
| - |
|
566 |
model.addAttribute("pendingPaymentorder", pendingPaymentorder);
|
| - |
|
567 |
model.addAttribute("latestNotifyOrders", notifyOrders);
|
| - |
|
568 |
} else {
|
| - |
|
569 |
model.addAttribute("inProcessorder", inProcessorder);
|
| - |
|
570 |
}
|
| 493 |
return "review_order";
|
571 |
return "review_order";
|
| 494 |
}
|
572 |
}
|
| 495 |
|
573 |
|
| 496 |
@RequestMapping(value = "/getKeepInTabOrder", method = RequestMethod.GET)
|
574 |
@RequestMapping(value = "/getKeepInTabOrder", method = RequestMethod.GET)
|
| 497 |
public String getKeepInTabOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
575 |
public String getKeepInTabOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| Line 536... |
Line 614... |
| 536 |
|
614 |
|
| 537 |
}
|
615 |
}
|
| 538 |
return "response";
|
616 |
return "response";
|
| 539 |
}
|
617 |
}
|
| 540 |
|
618 |
|
| - |
|
619 |
@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
|
| - |
|
620 |
public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
|
| - |
|
621 |
@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
|
| - |
|
622 |
|
| - |
|
623 |
List<Item> availableColorItem = itemRepository.selectAllByCatalogItemId(catalogItemId);
|
| - |
|
624 |
|
| - |
|
625 |
List<Order> inProcessselectedOrder = orderRepository.selectByItemIdOrderStatus(itemId,
|
| - |
|
626 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| - |
|
627 |
List<Integer> retailerIds = new ArrayList<>();
|
| - |
|
628 |
|
| - |
|
629 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessselectedOrder) {
|
| - |
|
630 |
retailerIds.add(order.getRetailerId());
|
| - |
|
631 |
|
| - |
|
632 |
}
|
| - |
|
633 |
|
| - |
|
634 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
| - |
|
635 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
| - |
|
636 |
LOGGER.info("item" + availableColorItem);
|
| - |
|
637 |
LOGGER.info("inProcessselectedOrder" + inProcessselectedOrder);
|
| - |
|
638 |
model.addAttribute("item", availableColorItem);
|
| - |
|
639 |
model.addAttribute("inProcessselectedOrder", inProcessselectedOrder);
|
| - |
|
640 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
| - |
|
641 |
|
| - |
|
642 |
return "notify-order-modal";
|
| - |
|
643 |
}
|
| - |
|
644 |
|
| - |
|
645 |
@RequestMapping(value = "/notifyOrder", method = RequestMethod.POST)
|
| - |
|
646 |
public String NotifyOrder(HttpServletRequest request, @RequestBody NotifyOrderModel notifyOrderModel, Model model)
|
| - |
|
647 |
throws Exception {
|
| - |
|
648 |
|
| - |
|
649 |
com.spice.profitmandi.dao.entity.transaction.NotifyItem notifyItem = null;
|
| - |
|
650 |
List<Integer> orderIds = new ArrayList<>();
|
| - |
|
651 |
|
| - |
|
652 |
NotifyColorChange notifytimestamp = new NotifyColorChange();
|
| - |
|
653 |
notifytimestamp.setCreated(LocalDateTime.now());
|
| - |
|
654 |
notifyColorChangeRepository.persist(notifytimestamp);
|
| - |
|
655 |
for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
|
| - |
|
656 |
|
| - |
|
657 |
notifyItem = new com.spice.profitmandi.dao.entity.transaction.NotifyItem();
|
| - |
|
658 |
notifyItem.setItemId(itemid.getItemId());
|
| - |
|
659 |
notifyItem.setResponseTime(itemid.getResponseTime());
|
| - |
|
660 |
notifyItem.setProcuredDate(itemid.getProcuredTime());
|
| - |
|
661 |
notifyItem.setNotifyColorchangeId(notifytimestamp.getId());
|
| - |
|
662 |
notifyItemRepository.persist(notifyItem);
|
| - |
|
663 |
LOGGER.info("notifyItem" + notifyItem);
|
| - |
|
664 |
}
|
| - |
|
665 |
for (NotifyOrderIdModel st : notifyOrderModel.getOrderIds()) {
|
| - |
|
666 |
List<NotifyOrder> existingOrder = notifyOrderRespository.selectByOrder(st.getOrderId());
|
| - |
|
667 |
if(!existingOrder.isEmpty()) {
|
| - |
|
668 |
LOGGER.info("existingOrder" + existingOrder);
|
| - |
|
669 |
for(NotifyOrder notifyOrder: existingOrder) {
|
| - |
|
670 |
if(NotifyStatus.pending == notifyOrder.getStatus()) {
|
| - |
|
671 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
| - |
|
672 |
}
|
| - |
|
673 |
}
|
| - |
|
674 |
}
|
| - |
|
675 |
NotifyOrder orderStatus = new NotifyOrder();
|
| - |
|
676 |
orderStatus.setOrderId(st.getOrderId());
|
| - |
|
677 |
orderStatus.setNotifyId(notifytimestamp.getId());
|
| - |
|
678 |
orderStatus.setItemId(st.getOlditemId());
|
| - |
|
679 |
Order id = orderRepository.selectById(st.getOrderId());
|
| - |
|
680 |
orderStatus.setFofoId(id.getRetailerId());
|
| - |
|
681 |
orderStatus.setStatus(NotifyStatus.pending);
|
| - |
|
682 |
notifyOrderRespository.persist(orderStatus);
|
| - |
|
683 |
|
| - |
|
684 |
LOGGER.info("itemStatus" + orderStatus);
|
| - |
|
685 |
orderIds.add(st.getOrderId());
|
| - |
|
686 |
}
|
| - |
|
687 |
|
| - |
|
688 |
LOGGER.info("orderIds" + orderIds);
|
| - |
|
689 |
List<Order> orders = orderRepository.selectByOrderIds(orderIds);
|
| - |
|
690 |
for (Order order : orders) {
|
| - |
|
691 |
LOGGER.info("order" + order.getId());
|
| - |
|
692 |
Item item = itemRepository.selectById(order.getLineItem().getItemId());
|
| - |
|
693 |
List<String> color = new ArrayList<>();
|
| - |
|
694 |
for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
|
| - |
|
695 |
Item newItem = itemRepository.selectById(itemid.getItemId());
|
| - |
|
696 |
color.add(newItem.getColor());
|
| - |
|
697 |
}
|
| - |
|
698 |
|
| - |
|
699 |
LOGGER.info("message" + item.getItemDescriptionNoColor() + "/" + item.getColor()
|
| - |
|
700 |
+ "is currently not in stock with Brand/ND. The current availability is in" + color);
|
| - |
|
701 |
|
| - |
|
702 |
NotificationCampaigns notification = new NotificationCampaigns();
|
| - |
|
703 |
notification.setName("Notify Partner");
|
| - |
|
704 |
|
| - |
|
705 |
notification.setTitle("Notify Partner");
|
| - |
|
706 |
|
| - |
|
707 |
notification.setMessage(item.getItemDescriptionNoColor() +"/"+
|
| - |
|
708 |
item.getColor() +
|
| - |
|
709 |
"is currently not in stock with Brand/ND. The current availability is in" +
|
| - |
|
710 |
color); notification.setType("Url");
|
| - |
|
711 |
notification.setUrl("http://app.profitmandi.com/pages/home/notifyOrder");
|
| - |
|
712 |
|
| - |
|
713 |
notification.
|
| - |
|
714 |
setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on" +
|
| - |
|
715 |
"(d1.imeinumber = d2.imeinumber and d1.created < d2.created) " +
|
| - |
|
716 |
" where d2.id is null and d1.user_id = " +
|
| - |
|
717 |
userAccountRepository.selectUserIdByRetailerId(order. getRetailerId()));
|
| - |
|
718 |
notification.setExpiresat(LocalDateTime.now().plusDays(2).
|
| - |
|
719 |
toEpochSecond(ZoneOffset.UTC) * 1000);
|
| - |
|
720 |
notification.setStatus("active");
|
| - |
|
721 |
notification.setSmsprocessed(0); notification.setNotification_processed(0);
|
| - |
|
722 |
notification.setNotification_type("GENERAL_NOTIFICATION");
|
| - |
|
723 |
mongoClient.persistNotificationCmpInfo(notification);
|
| - |
|
724 |
|
| - |
|
725 |
}
|
| - |
|
726 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| - |
|
727 |
return "response";
|
| - |
|
728 |
}
|
| - |
|
729 |
|
| - |
|
730 |
private void sendMailOfHtmlFomat(String email, String messageText, String subject)
|
| - |
|
731 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
| - |
|
732 |
MimeMessage message = mailSender.createMimeMessage();
|
| - |
|
733 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
| - |
|
734 |
helper.setSubject(subject);
|
| - |
|
735 |
helper.setText(messageText, true);
|
| - |
|
736 |
helper.setTo(email);
|
| - |
|
737 |
|
| - |
|
738 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
| - |
|
739 |
helper.setFrom(senderAddress);
|
| - |
|
740 |
mailSender.send(message);
|
| - |
|
741 |
}
|
| - |
|
742 |
|
| - |
|
743 |
/*
|
| - |
|
744 |
* private String getMessage(List<NotifyOrderModel> notifyOrderModels, Order
|
| - |
|
745 |
* order) throws ProfitMandiBusinessException {
|
| - |
|
746 |
*
|
| - |
|
747 |
* StringBuilder sb = new StringBuilder(); sb.
|
| - |
|
748 |
* append("<html><body><p>Notify Partner</p><p>Which have order out stock following model:-</p>"
|
| - |
|
749 |
* + "<div>" + order.getLineItem().getItem().getItemDescription() +
|
| - |
|
750 |
* "</div> <div>choose the model from following:- </div><br/><table style='border:1px solid black ;padding: 5px';>"
|
| - |
|
751 |
* ); sb.append("<tbody>\n" + " <tr>\n" +
|
| - |
|
752 |
* " <th style='border:1px solid black;padding: 5px'>Color</th>\n"
|
| - |
|
753 |
* +
|
| - |
|
754 |
* " <th style='border:1px solid black;padding: 5px'>Procured Time</th>\n"
|
| - |
|
755 |
* +
|
| - |
|
756 |
* " <th style='border:1px solid black;padding: 5px'>Response Time</th>\n"
|
| - |
|
757 |
* + " </tr>"); for (NotifyOrderModel notifyOrderModel :
|
| - |
|
758 |
* notifyOrderModels) { Item item =
|
| - |
|
759 |
* itemRepository.selectById(notifyOrderModel.getItemId()); sb.append("<tr>");
|
| - |
|
760 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
| - |
|
761 |
* item.getColor() + "</td>");
|
| - |
|
762 |
*
|
| - |
|
763 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
| - |
|
764 |
* notifyOrderModel.getFormattedProcuredTime() + "</td>");
|
| - |
|
765 |
*
|
| - |
|
766 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
| - |
|
767 |
* notifyOrderModel.getFormattedResponseTime() + "</td>");
|
| - |
|
768 |
*
|
| - |
|
769 |
* sb.append("</tr>"); }
|
| - |
|
770 |
*
|
| - |
|
771 |
* sb.append("</tbody></table></body></html>"); return sb.toString(); }
|
| - |
|
772 |
*/
|
| - |
|
773 |
|
| - |
|
774 |
@RequestMapping(value = "/getAllNotifyOrder", method = RequestMethod.GET)
|
| - |
|
775 |
public String getAllNotifyOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| - |
|
776 |
List<NotifyOrder> notifyOrders= null;
|
| - |
|
777 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
| - |
|
778 |
.selectAllOrderBeforeTwoDaysByStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| - |
|
779 |
|
| - |
|
780 |
List<Integer> orderIds = new ArrayList<>();
|
| - |
|
781 |
if(!inProcessorder.isEmpty()) {
|
| - |
|
782 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
| - |
|
783 |
|
| - |
|
784 |
orderIds.add(order.getId());
|
| - |
|
785 |
|
| - |
|
786 |
}
|
| - |
|
787 |
notifyOrders = notifyOrderRespository.selectByorderIds(orderIds);
|
| - |
|
788 |
Set<Integer> oldItemIds = new HashSet<>();
|
| - |
|
789 |
List<Integer> fofoIds = new ArrayList<>();
|
| - |
|
790 |
List<Integer> notifyIds = new ArrayList<>();
|
| - |
|
791 |
if (!notifyOrders.isEmpty()) {
|
| - |
|
792 |
for (NotifyOrder notifyOrder : notifyOrders) {
|
| - |
|
793 |
List<NotifyItem> notifyItems = notifyItemRepository.selectByNotifyId(notifyOrder.getNotifyId());
|
| - |
|
794 |
Iterator<NotifyItem> notifyItemsIterator = notifyItems.iterator();
|
| - |
|
795 |
|
| - |
|
796 |
while(notifyItemsIterator.hasNext()) {
|
| - |
|
797 |
NotifyItem notifyItem = notifyItemsIterator.next();
|
| - |
|
798 |
if (LocalDateTime.now().isAfter(notifyItem.getResponseTime())) {
|
| - |
|
799 |
notifyItemsIterator.remove();
|
| - |
|
800 |
}
|
| - |
|
801 |
}
|
| - |
|
802 |
if(notifyItems.size() == 0) {
|
| - |
|
803 |
if(NotifyStatus.pending == notifyOrder.getStatus()) {
|
| - |
|
804 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
| - |
|
805 |
LOGGER.info("existingOrder" + notifyOrder);
|
| - |
|
806 |
}
|
| - |
|
807 |
}
|
| - |
|
808 |
oldItemIds.add(notifyOrder.getItemId());
|
| - |
|
809 |
fofoIds.add(notifyOrder.getFofoId());
|
| - |
|
810 |
notifyIds.add(notifyOrder.getNotifyId());
|
| - |
|
811 |
}
|
| - |
|
812 |
|
| - |
|
813 |
List<NotifyColorChange> notifyColorChanges = notifyColorChangeRepository.selectByNotifyId(notifyIds);
|
| - |
|
814 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = this.notifyOrdersToNotifyId(notifyColorChanges);
|
| - |
|
815 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
|
| - |
|
816 |
Map<Integer, String> itemdescription = inventoryService.getItemIdDescriptionMap(oldItemIds);
|
| - |
|
817 |
|
| - |
|
818 |
model.addAttribute("notifyOrders", notifyOrders);
|
| - |
|
819 |
model.addAttribute("notifyIdNotifyColorMap", notifyIdNotifyColorMap);
|
| - |
|
820 |
model.addAttribute("itemdescription", itemdescription);
|
| - |
|
821 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
| - |
|
822 |
|
| - |
|
823 |
} else {
|
| - |
|
824 |
model.addAttribute("notifyOrders", notifyOrders);
|
| - |
|
825 |
}}
|
| - |
|
826 |
else {
|
| - |
|
827 |
model.addAttribute("notifyOrders", notifyOrders);
|
| - |
|
828 |
}
|
| - |
|
829 |
return "notify_order";
|
| - |
|
830 |
}
|
| - |
|
831 |
|
| - |
|
832 |
private Map<Integer, NotifyColorChange> notifyOrdersToNotifyId(List<NotifyColorChange> notifyColorChanges) {
|
| - |
|
833 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = new HashMap<>();
|
| - |
|
834 |
for (NotifyColorChange notifyColorChange : notifyColorChanges) {
|
| - |
|
835 |
notifyIdNotifyColorMap.put(notifyColorChange.getId(), notifyColorChange);
|
| - |
|
836 |
}
|
| - |
|
837 |
return notifyIdNotifyColorMap;
|
| - |
|
838 |
}
|
| - |
|
839 |
|
| 541 |
}
|
840 |
}
|
| 542 |
|
841 |
|