| 22398 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import javax.mail.internet.InternetAddress;
|
|
|
4 |
import javax.mail.internet.MimeMessage;
|
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
| 23568 |
govind |
7 |
import org.apache.logging.log4j.Logger;
|
|
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 22398 |
amit.gupta |
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.http.MediaType;
|
|
|
11 |
import org.springframework.http.ResponseEntity;
|
|
|
12 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
13 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 22400 |
amit.gupta |
14 |
import org.springframework.stereotype.Controller;
|
|
|
15 |
import org.springframework.transaction.annotation.Transactional;
|
| 22398 |
amit.gupta |
16 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
19 |
|
|
|
20 |
import com.spice.profitmandi.common.model.UserInfo;
|
|
|
21 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23568 |
govind |
22 |
import com.spice.profitmandi.dao.config.WebDBContextConfigure;
|
| 22398 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
26 |
import com.spice.profitmandi.web.req.FeedbackRequest;
|
|
|
27 |
|
|
|
28 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
29 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
30 |
|
| 22400 |
amit.gupta |
31 |
@Controller
|
|
|
32 |
@Transactional(rollbackFor=Throwable.class)
|
| 22398 |
amit.gupta |
33 |
public class ContactUsController {
|
|
|
34 |
|
| 23568 |
govind |
35 |
|
|
|
36 |
private static final Logger LOGGER = LogManager.getLogger(ContactUsController.class);
|
| 22398 |
amit.gupta |
37 |
@Autowired
|
| 22931 |
ashik.ali |
38 |
private JavaMailSender mailSender;
|
| 22398 |
amit.gupta |
39 |
|
|
|
40 |
@Autowired
|
| 22931 |
ashik.ali |
41 |
private ResponseSender<?> responseSender;
|
| 22398 |
amit.gupta |
42 |
|
|
|
43 |
@Autowired
|
| 22931 |
ashik.ali |
44 |
private UserRepository userRepository;
|
| 22398 |
amit.gupta |
45 |
|
|
|
46 |
@RequestMapping(value = "/contact-us/feedback" , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
47 |
@ApiImplicitParams({
|
|
|
48 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
49 |
required = true, dataType = "string", paramType = "header")
|
|
|
50 |
})
|
|
|
51 |
public ResponseEntity<?> sendCrmMail(HttpServletRequest request, @RequestBody FeedbackRequest feedbackRequest) throws Throwable {
|
|
|
52 |
UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
|
|
|
53 |
User user = userRepository.selectById(userInfo.getUserId());
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
57 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
| 22404 |
amit.gupta |
58 |
helper.setSubject("New Contact Us message");
|
| 22398 |
amit.gupta |
59 |
StringBuffer messageText = new StringBuffer();
|
|
|
60 |
messageText.append("User Id : ").append(userInfo.getUserId()).append("\n\n");
|
|
|
61 |
messageText.append("Email : ").append(user.getEmailId()).append("\n\n");
|
|
|
62 |
messageText.append("Mobile : ").append(user.getMobileNumber()).append("\n\n");
|
|
|
63 |
messageText.append("Subject : ").append(feedbackRequest.getSubject()).append("\n\n");
|
|
|
64 |
messageText.append("Message : ").append(feedbackRequest.getMessage());
|
| 22404 |
amit.gupta |
65 |
helper.setText(messageText.toString());
|
| 23452 |
amit.gupta |
66 |
String[] cc = {"neeraj.arya@smartdukaan.com","rahul.kandpal@smartdukaan.com", "ritesh.chauhan@smartdukaan.com", "krishna.kumar@smartdukaan.com"};
|
| 22405 |
amit.gupta |
67 |
//String[] cc = {"amit.gupta@shop2020.in"};
|
| 22398 |
amit.gupta |
68 |
helper.setCc(cc);
|
| 23839 |
amit.gupta |
69 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
|
|
|
70 |
helper.setTo("help@smartdukaan.com");
|
| 22403 |
amit.gupta |
71 |
helper.setFrom(senderAddress);
|
| 22398 |
amit.gupta |
72 |
mailSender.send(message);
|
| 23568 |
govind |
73 |
LOGGER.info("message send Successfully.....");
|
| 22398 |
amit.gupta |
74 |
return responseSender.ok(true);
|
|
|
75 |
}
|
|
|
76 |
}
|