| 35275 |
aman |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
3 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 35293 |
amit |
4 |
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
|
|
|
5 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
| 35500 |
aman |
6 |
import com.spice.profitmandi.dao.repository.user.PrivateDealUserRepository;
|
| 35392 |
aman |
7 |
import com.spice.profitmandi.dao.service.TrialService;
|
| 35275 |
aman |
8 |
import com.spice.profitmandi.service.integrations.gstpro.GstProService;
|
|
|
9 |
import com.spice.profitmandi.service.integrations.gstpro.entity.GstDetails;
|
|
|
10 |
import org.apache.logging.log4j.LogManager;
|
|
|
11 |
import org.apache.logging.log4j.Logger;
|
|
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13 |
import org.springframework.http.ResponseEntity;
|
|
|
14 |
import org.springframework.stereotype.Controller;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
19 |
|
|
|
20 |
import javax.servlet.http.HttpServletRequest;
|
| 35458 |
amit |
21 |
import org.springframework.transaction.annotation.Transactional;
|
| 35275 |
aman |
22 |
import java.time.LocalDateTime;
|
|
|
23 |
import java.util.Collections;
|
|
|
24 |
import java.util.List;
|
| 35392 |
aman |
25 |
import java.util.Map;
|
| 35275 |
aman |
26 |
|
|
|
27 |
|
|
|
28 |
@Controller
|
| 35458 |
amit |
29 |
@Transactional(rollbackFor = Throwable.class)
|
| 35275 |
aman |
30 |
public class TrialUserController {
|
| 35293 |
amit |
31 |
private static final Logger logger = LogManager.getLogger(TrialUserController.class);
|
| 35275 |
aman |
32 |
@Autowired
|
|
|
33 |
GstProService gstProService;
|
|
|
34 |
|
|
|
35 |
@Autowired
|
| 35293 |
amit |
36 |
TrialFormRepository trialOnboardingRepository;
|
| 35275 |
aman |
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
ResponseSender responseSender;
|
|
|
40 |
|
| 35392 |
aman |
41 |
|
|
|
42 |
@Autowired
|
|
|
43 |
TrialService trialService;
|
|
|
44 |
|
| 35500 |
aman |
45 |
@Autowired
|
|
|
46 |
PrivateDealUserRepository privateDealUserRepository;
|
|
|
47 |
|
| 35275 |
aman |
48 |
private static final Logger LOGGER = LogManager.getLogger(DealsController.class);
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
@RequestMapping(value = "/gstValidate", method = RequestMethod.GET)
|
|
|
52 |
public ResponseEntity<?> gstValidate(HttpServletRequest request, @RequestParam String gstNo) throws Exception {
|
|
|
53 |
LOGGER.info("gstNo -" + gstNo);
|
|
|
54 |
GstDetails gstDetails = gstProService.getGstDetails(gstNo);
|
|
|
55 |
LOGGER.info("gstDetails -" + gstDetails);
|
|
|
56 |
if (gstDetails != null) {
|
|
|
57 |
List<GstDetails.Pradr> adadr = gstDetails.getAdadr();
|
|
|
58 |
adadr.add(gstDetails.getPradr());
|
|
|
59 |
Collections.reverse(adadr);
|
|
|
60 |
LOGGER.info("list_of_adadr-" + adadr);
|
|
|
61 |
}
|
|
|
62 |
return ResponseEntity.ok(gstDetails);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
@RequestMapping(value = "/trial-registration", method = RequestMethod.POST)
|
| 35353 |
amit |
67 |
public ResponseEntity<?> createTrialUser(@RequestBody TrialForm trialForm) {
|
| 35293 |
amit |
68 |
if (trialForm.getMobile() == null || trialForm.getMobile().isEmpty()) {
|
| 35275 |
aman |
69 |
return responseSender.badRequest("Mobile number is required");
|
|
|
70 |
}
|
|
|
71 |
try {
|
| 35293 |
amit |
72 |
TrialForm existingUser = trialOnboardingRepository.findByMobile(trialForm.getMobile());
|
| 35275 |
aman |
73 |
if (existingUser != null) {
|
| 35419 |
aman |
74 |
return responseSender.badRequest("User already exists, PLease check your mobile number");
|
| 35275 |
aman |
75 |
}
|
| 35500 |
aman |
76 |
|
|
|
77 |
boolean existingGst= privateDealUserRepository.isActiveByGst(trialForm.getGstNumber());
|
|
|
78 |
if(existingGst){
|
|
|
79 |
return responseSender.badRequest("User Gst already exists, PLease check your gst number");
|
|
|
80 |
}
|
|
|
81 |
|
| 35293 |
amit |
82 |
trialForm.setStatus(ProfitMandiConstants.Status.PENDING);
|
|
|
83 |
trialForm.setCreatedOn(LocalDateTime.now());
|
|
|
84 |
trialOnboardingRepository.persist(trialForm);
|
| 35392 |
aman |
85 |
trialService.sentMailToTrialUser(trialForm);
|
|
|
86 |
trialService.sentMailForTrialUser(trialForm);
|
| 35293 |
amit |
87 |
return responseSender.ok(trialForm);
|
| 35275 |
aman |
88 |
|
|
|
89 |
} catch (Exception e) {
|
|
|
90 |
e.printStackTrace();
|
|
|
91 |
return responseSender.internalServerError("Registration failed: " + e.getMessage());
|
|
|
92 |
}
|
|
|
93 |
}
|
| 35392 |
aman |
94 |
@RequestMapping(value = "/trial-consent", method = RequestMethod.POST)
|
|
|
95 |
public ResponseEntity<?> consent(@RequestBody Map<String, String> request) throws Exception {
|
|
|
96 |
String email = request.get("email");
|
|
|
97 |
TrialForm trialForm= trialOnboardingRepository.selectByEmailOrMobile(email);
|
|
|
98 |
trialService.sendInternalFranchiseUpgradeMail(trialForm);
|
|
|
99 |
trialService.sendUpgradeRequestMail(trialForm);
|
|
|
100 |
return responseSender.ok("We have sent upgrade mail successfully");
|
|
|
101 |
}
|
| 35275 |
aman |
102 |
|
|
|
103 |
}
|