| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.StringWriter;
|
- |
|
| 4 |
import java.time.LocalDateTime;
|
3 |
import java.time.LocalDateTime;
|
| 5 |
import java.time.LocalTime;
|
4 |
import java.time.LocalTime;
|
| 6 |
import java.time.format.DateTimeFormatter;
|
5 |
import java.time.format.DateTimeFormatter;
|
| 7 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 8 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| Line 12... |
Line 11... |
| 12 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 13 |
import java.util.Optional;
|
12 |
import java.util.Optional;
|
| 14 |
import java.util.Set;
|
13 |
import java.util.Set;
|
| 15 |
import java.util.stream.Collectors;
|
14 |
import java.util.stream.Collectors;
|
| 16 |
|
15 |
|
| 17 |
import javax.mail.internet.InternetAddress;
|
- |
|
| 18 |
import javax.mail.internet.MimeMessage;
|
- |
|
| 19 |
import javax.servlet.http.HttpServletRequest;
|
16 |
import javax.servlet.http.HttpServletRequest;
|
| 20 |
|
17 |
|
| 21 |
import org.apache.commons.lang3.StringUtils;
|
18 |
import org.apache.commons.lang3.StringUtils;
|
| 22 |
import org.apache.http.conn.HttpHostConnectException;
|
19 |
import org.apache.http.conn.HttpHostConnectException;
|
| 23 |
import org.apache.logging.log4j.LogManager;
|
20 |
import org.apache.logging.log4j.LogManager;
|
| 24 |
import org.apache.logging.log4j.Logger;
|
21 |
import org.apache.logging.log4j.Logger;
|
| 25 |
import org.apache.velocity.Template;
|
- |
|
| 26 |
import org.apache.velocity.VelocityContext;
|
- |
|
| 27 |
import org.apache.velocity.app.VelocityEngine;
|
- |
|
| 28 |
import org.json.JSONArray;
|
22 |
import org.json.JSONArray;
|
| 29 |
import org.json.JSONObject;
|
23 |
import org.json.JSONObject;
|
| 30 |
import org.springframework.beans.factory.annotation.Autowired;
|
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 31 |
import org.springframework.beans.factory.annotation.Value;
|
25 |
import org.springframework.beans.factory.annotation.Value;
|
| 32 |
import org.springframework.cache.annotation.Cacheable;
|
26 |
import org.springframework.cache.annotation.Cacheable;
|
| 33 |
import org.springframework.http.MediaType;
|
27 |
import org.springframework.http.MediaType;
|
| 34 |
import org.springframework.http.ResponseEntity;
|
28 |
import org.springframework.http.ResponseEntity;
|
| 35 |
import org.springframework.mail.javamail.JavaMailSender;
|
- |
|
| 36 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
- |
|
| 37 |
import org.springframework.stereotype.Controller;
|
29 |
import org.springframework.stereotype.Controller;
|
| 38 |
import org.springframework.transaction.annotation.Transactional;
|
30 |
import org.springframework.transaction.annotation.Transactional;
|
| 39 |
import org.springframework.web.bind.annotation.GetMapping;
|
31 |
import org.springframework.web.bind.annotation.GetMapping;
|
| 40 |
import org.springframework.web.bind.annotation.PathVariable;
|
32 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 41 |
import org.springframework.web.bind.annotation.RequestBody;
|
33 |
import org.springframework.web.bind.annotation.RequestBody;
|
| Line 53... |
Line 45... |
| 53 |
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
|
45 |
import com.spice.profitmandi.common.model.CreatePendingOrderRequest;
|
| 54 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
46 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 55 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
47 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 56 |
import com.spice.profitmandi.common.model.UserInfo;
|
48 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 57 |
import com.spice.profitmandi.common.solr.SolrService;
|
49 |
import com.spice.profitmandi.common.solr.SolrService;
|
| - |
|
50 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 58 |
import com.spice.profitmandi.common.web.client.RestClient;
|
51 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 59 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
52 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 60 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
53 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 61 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
54 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 62 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
55 |
import com.spice.profitmandi.dao.entity.dtr.WebListing;
|
| Line 100... |
Line 93... |
| 100 |
import com.spice.profitmandi.web.processor.OtpProcessor;
|
93 |
import com.spice.profitmandi.web.processor.OtpProcessor;
|
| 101 |
import com.spice.profitmandi.web.res.DealBrands;
|
94 |
import com.spice.profitmandi.web.res.DealBrands;
|
| 102 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
95 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
| 103 |
import com.spice.profitmandi.web.res.DealsResponse;
|
96 |
import com.spice.profitmandi.web.res.DealsResponse;
|
| 104 |
import com.spice.profitmandi.web.res.ValidateCartResponse;
|
97 |
import com.spice.profitmandi.web.res.ValidateCartResponse;
|
| - |
|
98 |
import com.spice.profitmandi.web.services.EmailService;
|
| 105 |
|
99 |
|
| 106 |
import io.swagger.annotations.ApiImplicitParam;
|
100 |
import io.swagger.annotations.ApiImplicitParam;
|
| 107 |
import io.swagger.annotations.ApiImplicitParams;
|
101 |
import io.swagger.annotations.ApiImplicitParams;
|
| 108 |
import io.swagger.annotations.ApiOperation;
|
102 |
import io.swagger.annotations.ApiOperation;
|
| 109 |
|
103 |
|
| Line 199... |
Line 193... |
| 199 |
private WebProductListingRepository webProductListingRepository;
|
193 |
private WebProductListingRepository webProductListingRepository;
|
| 200 |
|
194 |
|
| 201 |
@Autowired
|
195 |
@Autowired
|
| 202 |
private RoleManager roleManagerService;
|
196 |
private RoleManager roleManagerService;
|
| 203 |
|
197 |
|
| - |
|
198 |
|
| 204 |
@Autowired
|
199 |
@Autowired
|
| 205 |
private VelocityEngine velocityEngine;
|
200 |
EmailService emailService;
|
| 206 |
|
201 |
|
| 207 |
@Autowired
|
- |
|
| 208 |
JavaMailSender mailSender;
|
- |
|
| 209 |
|
202 |
|
| 210 |
@Autowired
|
203 |
@Autowired
|
| 211 |
CsService csService;
|
204 |
CsService csService;
|
| 212 |
List<String> filterableParams = Arrays.asList("brand");
|
205 |
List<String> filterableParams = Arrays.asList("brand");
|
| 213 |
|
206 |
|
| Line 739... |
Line 732... |
| 739 |
}
|
732 |
}
|
| 740 |
pendingOrder.setPendingOrderItems(pendingOrderItems);
|
733 |
pendingOrder.setPendingOrderItems(pendingOrderItems);
|
| 741 |
|
734 |
|
| 742 |
CustomerAddress customerAddress = customerAddressRepository.selectById(pendingOrder.getCustomerAddressId());
|
735 |
CustomerAddress customerAddress = customerAddressRepository.selectById(pendingOrder.getCustomerAddressId());
|
| 743 |
|
736 |
|
| 744 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy H:m");
|
737 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy h:mm a");
|
| 745 |
Template t = velocityEngine.getTemplate("sms.vm");
|
- |
|
| 746 |
VelocityContext context = new VelocityContext();
|
- |
|
| 747 |
|
738 |
|
| - |
|
739 |
Map<String, Object> emailModel = new HashMap<>();
|
| 748 |
context.put("customer", customerAddress);
|
740 |
emailModel.put("customer", customerAddress);
|
| 749 |
context.put("pendingOrder", pendingOrder);
|
741 |
emailModel.put("pendingOrder", pendingOrder);
|
| 750 |
context.put("date", dateTimeFormatter);
|
742 |
emailModel.put("date", dateTimeFormatter);
|
| 751 |
StringWriter writer = new StringWriter();
|
- |
|
| 752 |
t.merge(context, writer);
|
- |
|
| 753 |
|
743 |
|
| 754 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(pendingOrder.getFofoId());
|
744 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(pendingOrder.getFofoId());
|
| 755 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
745 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
| 756 |
|
- |
|
| - |
|
746 |
String[] customerEmail = null;
|
| 757 |
if (!customer.getEmailId().equals(null)) {
|
747 |
if (customer.getEmailId()!= null) {
|
| 758 |
String[] customerEmail = { customer.getEmailId() };
|
748 |
customerEmail = new String[]{ customer.getEmailId() };
|
| 759 |
|
- |
|
| 760 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(), customerEmail);
|
- |
|
| 761 |
|
- |
|
| 762 |
}
|
749 |
}
|
| 763 |
|
- |
|
| 764 |
String[] retailerEmail = { customRetailer.getEmail() };
|
- |
|
| 765 |
|
- |
|
| 766 |
List<String> sendTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
750 |
List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 767 |
"hemant.kaura@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
|
751 |
"hemant.kaura@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com",
|
| 768 |
"tejbeer.kaur@shop2020.in");
|
752 |
"tejbeer.kaur@shop2020.in", customRetailer.getEmail());
|
| 769 |
|
- |
|
| 770 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
753 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
| 771 |
logger.info("authUserEmails" + authUserEmails);
|
754 |
bccTo.addAll(authUserEmails);
|
| 772 |
|
755 |
|
| 773 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(), retailerEmail);
|
756 |
emailService.sendMailWithAttachments("Order Created with SmartDukaan", "order-confirm.vm",
|
| 774 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(),
|
757 |
emailModel, customerEmail, null,
|
| 775 |
sendTo.toArray(new String[sendTo.size()]));
|
758 |
bccTo.toArray(new String[0]));
|
| 776 |
|
- |
|
| 777 |
if (!authUserEmails.isEmpty()) {
|
- |
|
| 778 |
this.sendMailWithAttachments("Order Confirmation", writer.toString(),
|
- |
|
| 779 |
authUserEmails.toArray(new String[authUserEmails.size()]));
|
- |
|
| 780 |
}
|
- |
|
| 781 |
return responseSender.ok(pendingOrder);
|
759 |
return responseSender.ok(pendingOrder);
|
| 782 |
}
|
760 |
}
|
| 783 |
|
761 |
|
| 784 |
private void sendMailWithAttachments(String subject, String messageText, String[] email) throws Exception {
|
- |
|
| 785 |
MimeMessage message = mailSender.createMimeMessage();
|
- |
|
| 786 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
- |
|
| 787 |
helper.setTo(email);
|
- |
|
| 788 |
helper.setSubject(subject);
|
- |
|
| 789 |
helper.setText(messageText, true);
|
- |
|
| 790 |
|
- |
|
| 791 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
- |
|
| 792 |
helper.setFrom(senderAddress);
|
- |
|
| 793 |
mailSender.send(message);
|
- |
|
| 794 |
|
- |
|
| 795 |
}
|
- |
|
| 796 |
|
- |
|
| 797 |
@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
|
762 |
@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
|
| 798 |
public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
|
763 |
public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
|
| 799 |
return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
|
764 |
return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
|
| 800 |
}
|
765 |
}
|
| 801 |
|
766 |
|
| Line 827... |
Line 792... |
| 827 |
public ResponseEntity<?> cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id,
|
792 |
public ResponseEntity<?> cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id,
|
| 828 |
|
793 |
|
| 829 |
@RequestParam String statusDescription) throws Exception {
|
794 |
@RequestParam String statusDescription) throws Exception {
|
| 830 |
|
795 |
|
| 831 |
PendingOrderItem pendingOrderItem = pendingOrderItemRepository.selectById(id);
|
796 |
PendingOrderItem pendingOrderItem = pendingOrderItemRepository.selectById(id);
|
| 832 |
|
- |
|
| 833 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderItem.getOrderId());
|
797 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderItem.getOrderId());
|
| - |
|
798 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
| 834 |
if (pendingOrderItem.getBilledTimestamp() == null) {
|
799 |
if (pendingOrderItem.getBilledTimestamp() == null) {
|
| 835 |
pendingOrderItem.setStatus(OrderStatus.CANCELLED);
|
800 |
pendingOrderItem.setStatus(OrderStatus.CANCELLED);
|
| 836 |
pendingOrderItem.setStatusDescription(statusDescription);
|
801 |
pendingOrderItem.setStatusDescription(statusDescription);
|
| - |
|
802 |
pendingOrderItem.setCancelledTimestamp(LocalDateTime.now());
|
| 837 |
List<OrderStatus> status = pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId())
|
803 |
List<OrderStatus> status = pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId())
|
| 838 |
.stream().map(x -> x.getStatus()).collect(Collectors.toList());
|
804 |
.stream().map(x -> x.getStatus()).collect(Collectors.toList());
|
| 839 |
|
805 |
|
| 840 |
if (!status.contains(OrderStatus.PENDING)) {
|
806 |
if (!status.contains(OrderStatus.PENDING)) {
|
| 841 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
807 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
| 842 |
}
|
808 |
}
|
| 843 |
|
809 |
|
| 844 |
pendingOrderItemRepository.persist(pendingOrderItem);
|
810 |
pendingOrderItemRepository.persist(pendingOrderItem);
|
| - |
|
811 |
String itemDescription = itemRepository.selectById(pendingOrderItem.getItemId()).getItemDescription();
|
| - |
|
812 |
otpProcessor.sendSms(OtpProcessor.SELF_CANCELLED_TEMPLATE_ID,
|
| - |
|
813 |
String.format(OtpProcessor.SELF_CANCELLED_TEMPLATE, pendingOrder.getId(),
|
| - |
|
814 |
StringUtils.abbreviate(itemDescription, 30),
|
| - |
|
815 |
FormattingUtils.format(pendingOrderItem.getCancelledTimestamp())),
|
| - |
|
816 |
customer.getMobileNumber());
|
| 845 |
}
|
817 |
}
|
| 846 |
|
818 |
|
| 847 |
return responseSender.ok(true);
|
819 |
return responseSender.ok(true);
|
| 848 |
|
820 |
|
| 849 |
}
|
821 |
}
|