| 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;
|
- |
|
| 6 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| 7 |
import java.time.LocalDateTime;
|
6 |
import java.time.LocalDateTime;
|
| 8 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| 9 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| 10 |
import java.util.HashSet;
|
9 |
import java.util.HashSet;
|
| Line 13... |
Line 12... |
| 13 |
import java.util.Map;
|
12 |
import java.util.Map;
|
| 14 |
import java.util.Optional;
|
13 |
import java.util.Optional;
|
| 15 |
import java.util.Set;
|
14 |
import java.util.Set;
|
| 16 |
import java.util.stream.Collectors;
|
15 |
import java.util.stream.Collectors;
|
| 17 |
|
16 |
|
| 18 |
import javax.mail.MessagingException;
|
- |
|
| 19 |
import javax.mail.internet.InternetAddress;
|
- |
|
| 20 |
import javax.mail.internet.MimeMessage;
|
- |
|
| 21 |
import javax.servlet.http.HttpServletRequest;
|
17 |
import javax.servlet.http.HttpServletRequest;
|
| 22 |
import javax.servlet.http.HttpServletResponse;
|
18 |
import javax.servlet.http.HttpServletResponse;
|
| 23 |
|
19 |
|
| 24 |
import org.apache.logging.log4j.LogManager;
|
20 |
import org.apache.logging.log4j.LogManager;
|
| 25 |
import org.apache.logging.log4j.Logger;
|
21 |
import org.apache.logging.log4j.Logger;
|
| Line 32... |
Line 28... |
| 32 |
import org.springframework.http.HttpHeaders;
|
28 |
import org.springframework.http.HttpHeaders;
|
| 33 |
import org.springframework.http.HttpStatus;
|
29 |
import org.springframework.http.HttpStatus;
|
| 34 |
import org.springframework.http.MediaType;
|
30 |
import org.springframework.http.MediaType;
|
| 35 |
import org.springframework.http.ResponseEntity;
|
31 |
import org.springframework.http.ResponseEntity;
|
| 36 |
import org.springframework.mail.javamail.JavaMailSender;
|
32 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 37 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
- |
|
| 38 |
import org.springframework.stereotype.Controller;
|
33 |
import org.springframework.stereotype.Controller;
|
| 39 |
import org.springframework.transaction.annotation.Transactional;
|
34 |
import org.springframework.transaction.annotation.Transactional;
|
| 40 |
import org.springframework.ui.Model;
|
35 |
import org.springframework.ui.Model;
|
| 41 |
import org.springframework.web.bind.annotation.RequestBody;
|
36 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 42 |
import org.springframework.web.bind.annotation.RequestMapping;
|
37 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| Line 54... |
Line 49... |
| 54 |
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
|
49 |
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
|
| 55 |
import com.spice.profitmandi.common.model.NotifyOrderModel;
|
50 |
import com.spice.profitmandi.common.model.NotifyOrderModel;
|
| 56 |
import com.spice.profitmandi.common.model.OrderCancellationModel;
|
51 |
import com.spice.profitmandi.common.model.OrderCancellationModel;
|
| 57 |
import com.spice.profitmandi.common.model.PdfModel;
|
52 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 58 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
53 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
54 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 59 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
55 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 60 |
import com.spice.profitmandi.common.util.PdfUtils;
|
56 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 61 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
57 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 62 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
58 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 63 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
59 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| Line 78... |
Line 74... |
| 78 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
74 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 79 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
75 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 80 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
76 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 81 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
77 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
| 82 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
78 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 83 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
- |
|
| 84 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
79 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
| 85 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
80 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
| 86 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
81 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 87 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
82 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
| 88 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
83 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| Line 92... |
Line 87... |
| 92 |
import com.spice.profitmandi.dao.repository.transaction.NotifyColorChangeRepository;
|
87 |
import com.spice.profitmandi.dao.repository.transaction.NotifyColorChangeRepository;
|
| 93 |
import com.spice.profitmandi.dao.repository.transaction.NotifyItemRepository;
|
88 |
import com.spice.profitmandi.dao.repository.transaction.NotifyItemRepository;
|
| 94 |
import com.spice.profitmandi.dao.repository.transaction.NotifyMessageRepository;
|
89 |
import com.spice.profitmandi.dao.repository.transaction.NotifyMessageRepository;
|
| 95 |
import com.spice.profitmandi.dao.repository.transaction.NotifyOrderRespository;
|
90 |
import com.spice.profitmandi.dao.repository.transaction.NotifyOrderRespository;
|
| 96 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
91 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 97 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
92 |
import com.spice.profitmandi.service.NotificationService;
|
| 98 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
93 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 99 |
import com.spice.profitmandi.service.user.RetailerService;
|
94 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 100 |
import com.spice.profitmandi.web.model.LoginDetails;
|
95 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 101 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
96 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 102 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
97 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| Line 155... |
Line 150... |
| 155 |
|
150 |
|
| 156 |
@Autowired
|
151 |
@Autowired
|
| 157 |
private NotifyOrderRespository notifyOrderRespository;
|
152 |
private NotifyOrderRespository notifyOrderRespository;
|
| 158 |
|
153 |
|
| 159 |
@Autowired
|
154 |
@Autowired
|
| - |
|
155 |
private NotificationService notificationService;
|
| - |
|
156 |
|
| - |
|
157 |
@Autowired
|
| 160 |
private NotifyMessageRepository notifyMessageRepository;
|
158 |
private NotifyMessageRepository notifyMessageRepository;
|
| 161 |
|
159 |
|
| 162 |
@Autowired
|
160 |
@Autowired
|
| 163 |
private UserAccountRepository userAccountRepository;
|
161 |
private UserAccountRepository userAccountRepository;
|
| 164 |
|
162 |
|
| Line 688... |
Line 686... |
| 688 |
}
|
686 |
}
|
| 689 |
|
687 |
|
| 690 |
private void sendCancellationNotificationToPartner(Order order, String reason) throws Exception {
|
688 |
private void sendCancellationNotificationToPartner(Order order, String reason) throws Exception {
|
| 691 |
Item item = itemRepository.selectById(order.getLineItem().getItemId());
|
689 |
Item item = itemRepository.selectById(order.getLineItem().getItemId());
|
| 692 |
|
690 |
|
| 693 |
SimpleCampaignParams scp = new SimpleCampaignParams();
|
691 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| - |
|
692 |
sendNotificationModel.setCampaignName("Order Cancellation");
|
| 694 |
scp.setTitle(String.format("Order %s %d(Pcs) cancelled", item.getItemDescription(),
|
693 |
sendNotificationModel.setTitle(String.format("Order %s %d(Pcs) cancelled", item.getItemDescription(),
|
| 695 |
order.getLineItem().getQuantity()));
|
694 |
order.getLineItem().getQuantity()));
|
| 696 |
scp.setMessage(reason);
|
695 |
sendNotificationModel.setType("url");
|
| 697 |
scp.setType("url");
|
696 |
sendNotificationModel.setMessage(reason);
|
| 698 |
scp.setUrl("http://app.smartdukaan.com/pages/home/orderDetails");
|
697 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/orderDetails");
|
| 699 |
scp.setExpireTimestamp(LocalDateTime.now().plusDays(2));
|
698 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
| 700 |
SimpleCampaign sc = new SimpleCampaign(scp);
|
- |
|
| 701 |
sc.setSimpleCampaignParams(scp);
|
- |
|
| 702 |
|
- |
|
| 703 |
NotificationCampaign nc = new NotificationCampaign();
|
- |
|
| 704 |
nc.setName("Order Cancellation");
|
- |
|
| 705 |
nc.setImplementationType("SimpleCampaign");
|
- |
|
| 706 |
nc.setImplementationParams(gson.toJson(scp));
|
- |
|
| 707 |
nc.setMessageType(MessageType.notification);
|
699 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 708 |
nc.setCreatedTimestamp(LocalDateTime.now());
|
- |
|
| 709 |
notificationCampaignRepository.persist(nc);
|
700 |
notificationService.sendNotification(sendNotificationModel);
|
| 710 |
|
- |
|
| 711 |
int userId = userAccountRepository.selectUserIdByRetailerId(order.getRetailerId());
|
- |
|
| 712 |
UserCampaign uc = new UserCampaign();
|
- |
|
| 713 |
uc.setCampaignId(nc.getId());
|
- |
|
| 714 |
uc.setUserId(userId);
|
- |
|
| 715 |
uc.setPushTimestamp(LocalDateTime.now());
|
- |
|
| 716 |
userCampaignRepository.persist(uc);
|
- |
|
| 717 |
List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(userId,
|
- |
|
| 718 |
LocalDateTime.now().minusMonths(3), LocalDateTime.now());
|
- |
|
| 719 |
pushNotification(nc.getId(), devices);
|
- |
|
| 720 |
|
701 |
|
| 721 |
}
|
702 |
}
|
| 722 |
|
703 |
|
| 723 |
@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
|
704 |
@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
|
| 724 |
public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
|
705 |
public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
|
| Line 813... |
Line 794... |
| 813 |
for (Order order : orders) {
|
794 |
for (Order order : orders) {
|
| 814 |
LOGGER.info("order" + order.getId());
|
795 |
LOGGER.info("order" + order.getId());
|
| 815 |
|
796 |
|
| 816 |
NotifyMessage message = notifyMessageRepository.selectByNotifyId(notifytimestamp.getId());
|
797 |
NotifyMessage message = notifyMessageRepository.selectByNotifyId(notifytimestamp.getId());
|
| 817 |
|
798 |
|
| - |
|
799 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 818 |
SimpleCampaignParams scp = new SimpleCampaignParams();
|
800 |
sendNotificationModel.setCampaignName("Notify Partner");
|
| 819 |
scp.setMessage(message.getNotifyMessages());
|
801 |
sendNotificationModel.setMessage(message.getNotifyMessages());
|
| 820 |
scp.setTitle("Alert");
|
802 |
sendNotificationModel.setType("url");
|
| 821 |
scp.setType("url");
|
803 |
sendNotificationModel.setTitle("Alert");
|
| 822 |
scp.setUrl("http://app.smartdukaan.com/pages/home/notifyOrder");
|
804 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifyOrder");
|
| 823 |
scp.setExpireTimestamp(LocalDateTime.now().plusDays(2));
|
805 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
| 824 |
SimpleCampaign sc = new SimpleCampaign(scp);
|
- |
|
| 825 |
sc.setSimpleCampaignParams(scp);
|
- |
|
| 826 |
|
- |
|
| 827 |
NotificationCampaign nc = new NotificationCampaign();
|
- |
|
| 828 |
nc.setName("Notify Partner");
|
- |
|
| 829 |
nc.setImplementationType("SimpleCampaign");
|
- |
|
| 830 |
nc.setImplementationParams(gson.toJson(scp));
|
- |
|
| 831 |
nc.setCreatedTimestamp(LocalDateTime.now());
|
- |
|
| 832 |
nc.setMessageType(MessageType.notification);
|
806 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 833 |
notificationCampaignRepository.persist(nc);
|
807 |
notificationService.sendNotification(sendNotificationModel);
|
| 834 |
|
- |
|
| 835 |
int userId = userAccountRepository.selectUserIdByRetailerId(order.getRetailerId());
|
- |
|
| 836 |
UserCampaign uc = new UserCampaign();
|
- |
|
| 837 |
uc.setCampaignId(nc.getId());
|
- |
|
| 838 |
uc.setUserId(userId);
|
- |
|
| 839 |
uc.setPushTimestamp(LocalDateTime.now());
|
- |
|
| 840 |
userCampaignRepository.persist(uc);
|
- |
|
| 841 |
List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(userId,
|
- |
|
| 842 |
LocalDateTime.now().minusMonths(3), LocalDateTime.now());
|
- |
|
| 843 |
pushNotification(nc.getId(), devices);
|
- |
|
| 844 |
|
808 |
|
| 845 |
}
|
809 |
}
|
| 846 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
810 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 847 |
return "response";
|
811 |
return "response";
|
| 848 |
}
|
812 |
}
|
| Line 856... |
Line 820... |
| 856 |
pushNotificationRepository.persist(pn);
|
820 |
pushNotificationRepository.persist(pn);
|
| 857 |
}
|
821 |
}
|
| 858 |
|
822 |
|
| 859 |
}
|
823 |
}
|
| 860 |
|
824 |
|
| 861 |
private void sendMailOfHtmlFomat(String email, String messageText, String subject)
|
- |
|
| 862 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
- |
|
| 863 |
MimeMessage message = mailSender.createMimeMessage();
|
- |
|
| 864 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
- |
|
| 865 |
helper.setSubject(subject);
|
- |
|
| 866 |
helper.setText(messageText, true);
|
- |
|
| 867 |
helper.setTo(email);
|
- |
|
| 868 |
|
- |
|
| 869 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
- |
|
| 870 |
helper.setFrom(senderAddress);
|
- |
|
| 871 |
mailSender.send(message);
|
- |
|
| 872 |
}
|
- |
|
| 873 |
|
- |
|
| 874 |
/*
|
- |
|
| 875 |
* private String getMessage(List<NotifyOrderModel> notifyOrderModels, Order
|
- |
|
| 876 |
* order) throws ProfitMandiBusinessException {
|
- |
|
| 877 |
*
|
- |
|
| 878 |
* StringBuilder sb = new StringBuilder(); sb.
|
- |
|
| 879 |
* append("<html><body><p>Notify Partner</p><p>Which have order out stock following model:-</p>"
|
- |
|
| 880 |
* + "<div>" + order.getLineItem().getItem().getItemDescription() +
|
- |
|
| 881 |
* "</div> <div>choose the model from following:- </div><br/><table style='border:1px solid black ;padding: 5px';>"
|
- |
|
| 882 |
* ); sb.append("<tbody>\n" + " <tr>\n" +
|
- |
|
| 883 |
* " <th style='border:1px solid black;padding: 5px'>Color</th>\n"
|
- |
|
| 884 |
* +
|
- |
|
| 885 |
* " <th style='border:1px solid black;padding: 5px'>Procured Time</th>\n"
|
- |
|
| 886 |
* +
|
- |
|
| 887 |
* " <th style='border:1px solid black;padding: 5px'>Response Time</th>\n"
|
- |
|
| 888 |
* + " </tr>"); for (NotifyOrderModel notifyOrderModel :
|
- |
|
| 889 |
* notifyOrderModels) { Item item =
|
- |
|
| 890 |
* itemRepository.selectById(notifyOrderModel.getItemId()); sb.append("<tr>");
|
- |
|
| 891 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
- |
|
| 892 |
* item.getColor() + "</td>");
|
- |
|
| 893 |
*
|
- |
|
| 894 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
- |
|
| 895 |
* notifyOrderModel.getFormattedProcuredTime() + "</td>");
|
- |
|
| 896 |
*
|
- |
|
| 897 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
- |
|
| 898 |
* notifyOrderModel.getFormattedResponseTime() + "</td>");
|
- |
|
| 899 |
*
|
- |
|
| 900 |
* sb.append("</tr>"); }
|
- |
|
| 901 |
*
|
- |
|
| 902 |
* sb.append("</tbody></table></body></html>"); return sb.toString(); }
|
- |
|
| 903 |
*/
|
- |
|
| 904 |
|
- |
|
| 905 |
@RequestMapping(value = "/getAllNotifyOrder", method = RequestMethod.GET)
|
825 |
@RequestMapping(value = "/getAllNotifyOrder", method = RequestMethod.GET)
|
| 906 |
public String getAllNotifyOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
826 |
public String getAllNotifyOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 907 |
List<NotifyOrder> notifyOrders = null;
|
827 |
List<NotifyOrder> notifyOrders = null;
|
| 908 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
828 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
| 909 |
.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
829 |
.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
|