| 35289 |
amit |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 35340 |
aman |
4 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 35360 |
aman |
5 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 35340 |
aman |
6 |
import com.spice.profitmandi.dao.entity.fofo.TrialBrandPotential;
|
| 35289 |
amit |
7 |
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
|
| 35360 |
aman |
8 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 35499 |
aman |
9 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 35360 |
aman |
10 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 35340 |
aman |
11 |
import com.spice.profitmandi.dao.repository.fofo.TrialBrandPotentialRepository;
|
| 35289 |
amit |
12 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
| 35360 |
aman |
13 |
import com.spice.profitmandi.dao.service.TrialService;
|
| 35499 |
aman |
14 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
15 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 35289 |
amit |
16 |
import org.apache.logging.log4j.LogManager;
|
|
|
17 |
import org.apache.logging.log4j.Logger;
|
|
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 35340 |
aman |
19 |
import org.springframework.http.ResponseEntity;
|
| 35289 |
amit |
20 |
import org.springframework.stereotype.Controller;
|
| 35499 |
aman |
21 |
import org.springframework.transaction.annotation.Transactional;
|
| 35289 |
amit |
22 |
import org.springframework.ui.Model;
|
| 35499 |
aman |
23 |
import org.springframework.web.bind.annotation.*;
|
| 35289 |
amit |
24 |
|
|
|
25 |
import javax.servlet.http.HttpServletRequest;
|
| 35360 |
aman |
26 |
import java.time.LocalDateTime;
|
|
|
27 |
import java.util.Collections;
|
| 35289 |
amit |
28 |
import java.util.List;
|
| 35360 |
aman |
29 |
import java.util.Set;
|
|
|
30 |
import java.util.stream.Collectors;
|
| 35289 |
amit |
31 |
|
|
|
32 |
@Controller
|
| 35458 |
amit |
33 |
@Transactional(rollbackFor = Throwable.class)
|
| 35289 |
amit |
34 |
public class TrialController {
|
|
|
35 |
|
| 35360 |
aman |
36 |
private static final Logger LOGGER = LogManager.getLogger(TrialController.class);
|
| 35340 |
aman |
37 |
@Autowired
|
|
|
38 |
TrialBrandPotentialRepository trialBrandPotentialRepository;
|
|
|
39 |
|
|
|
40 |
@Autowired
|
|
|
41 |
ResponseSender responseSender;
|
|
|
42 |
|
| 35289 |
amit |
43 |
@Autowired
|
| 35360 |
aman |
44 |
CsService csService;
|
|
|
45 |
|
|
|
46 |
@Autowired
|
| 35289 |
amit |
47 |
TrialFormRepository trialFormRepository;
|
|
|
48 |
|
| 35360 |
aman |
49 |
@Autowired
|
|
|
50 |
TrialService trialService;
|
|
|
51 |
|
| 35499 |
aman |
52 |
@Autowired
|
|
|
53 |
CookiesProcessor cookiesProcessor;
|
|
|
54 |
|
|
|
55 |
@Autowired
|
|
|
56 |
AuthRepository authRepository;
|
|
|
57 |
|
|
|
58 |
|
| 35289 |
amit |
59 |
@RequestMapping(value = "/trial/pending", method = RequestMethod.GET)
|
|
|
60 |
public String getTrialPending(HttpServletRequest request, Model model) throws Exception {
|
|
|
61 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.PENDING);
|
|
|
62 |
LOGGER.info("trialForms {}", trialForms.size());
|
| 35360 |
aman |
63 |
Set<AuthUser> bmAuthUsers = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Collections.singletonList(EscalationType.L2)).stream().filter(x -> x.isActive()).collect(Collectors.toSet());
|
|
|
64 |
Set<AuthUser> asmAuthUsers = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Collections.singletonList(EscalationType.L1)).stream().filter(x -> x.isActive()).collect(Collectors.toSet());
|
|
|
65 |
LOGGER.info("bm {}", bmAuthUsers);
|
|
|
66 |
LOGGER.info("asm {}", asmAuthUsers);
|
| 35499 |
aman |
67 |
asmAuthUsers.addAll(bmAuthUsers);
|
| 35360 |
aman |
68 |
model.addAttribute("bm", bmAuthUsers);
|
|
|
69 |
model.addAttribute("asm", asmAuthUsers);
|
| 35289 |
amit |
70 |
model.addAttribute("trialForms", trialForms);
|
|
|
71 |
return "trial-form";
|
|
|
72 |
}
|
|
|
73 |
|
| 35499 |
aman |
74 |
@RequestMapping(value = "/trial/all-trial", method = RequestMethod.GET)
|
|
|
75 |
public String getAllTrialUser(HttpServletRequest request, Model model) throws Exception {
|
|
|
76 |
List<TrialForm> trialForms = trialFormRepository.selectAll();
|
|
|
77 |
LOGGER.info("trialForms {}", trialForms.size());
|
|
|
78 |
model.addAttribute("trialForms", trialForms);
|
|
|
79 |
return "all-trial-form";
|
|
|
80 |
}
|
|
|
81 |
|
| 35340 |
aman |
82 |
@RequestMapping(value = "/trial/verified", method = RequestMethod.GET)
|
|
|
83 |
public String verifiedTrial(HttpServletRequest request, Model model) throws Exception {
|
| 35499 |
aman |
84 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
85 |
|
|
|
86 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 35340 |
aman |
87 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.VERIFIED);
|
| 35499 |
aman |
88 |
List<TrialForm> filteredTrialForms = trialForms.stream()
|
|
|
89 |
.filter(trialForm ->
|
|
|
90 |
(trialForm.getBmId() != null && trialForm.getBmId().equals(authUser.getId())) ||
|
|
|
91 |
(trialForm.getAsmId() != null && trialForm.getAsmId().equals(authUser.getId()))
|
|
|
92 |
)
|
|
|
93 |
.collect(Collectors.toList());
|
| 35340 |
aman |
94 |
LOGGER.info("trialForms {}", trialForms.size());
|
| 35499 |
aman |
95 |
LOGGER.info("filtered trialForms {}", filteredTrialForms);
|
|
|
96 |
model.addAttribute("trialForms", filteredTrialForms);
|
| 35340 |
aman |
97 |
return "trial-verified";
|
|
|
98 |
}
|
|
|
99 |
|
| 35360 |
aman |
100 |
@RequestMapping(value = "/trial/asm-bm", method = RequestMethod.POST)
|
|
|
101 |
@ResponseBody
|
|
|
102 |
public ResponseEntity<?> asmBm(HttpServletRequest request) throws Exception {
|
|
|
103 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
|
|
104 |
int asmId = Integer.parseInt(request.getParameter("asmId"));
|
|
|
105 |
int bmId = Integer.parseInt(request.getParameter("bmId"));
|
|
|
106 |
|
|
|
107 |
if (trialFormId == 0 || asmId == 0 || bmId == 0) {
|
|
|
108 |
throw new Exception("please select both bm and asm");
|
|
|
109 |
}
|
|
|
110 |
TrialForm trialForms = trialFormRepository.selectById(trialFormId);
|
|
|
111 |
trialForms.setAsmId(asmId);
|
|
|
112 |
trialForms.setBmId(bmId);
|
|
|
113 |
trialForms.setUpdatedOn(LocalDateTime.now());
|
|
|
114 |
return responseSender.ok("Saved Successfully");
|
|
|
115 |
}
|
|
|
116 |
|
| 35289 |
amit |
117 |
@RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
|
|
|
118 |
public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
119 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
120 |
return "trial-form";
|
|
|
121 |
}
|
| 35340 |
aman |
122 |
|
| 35499 |
aman |
123 |
@RequestMapping(value = "/trial/reject", method = RequestMethod.POST)
|
|
|
124 |
public ResponseEntity<?> rejectTrialUser(HttpServletRequest request, @RequestParam int trialFormId,
|
|
|
125 |
@RequestParam String remark) throws Exception {
|
| 35340 |
aman |
126 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
127 |
trialForm.setStatus(ProfitMandiConstants.Status.REJECTED);
|
| 35499 |
aman |
128 |
trialForm.setRemark(remark);
|
| 35391 |
aman |
129 |
trialService.sentRejectionMailToTrialUser(trialForm);
|
| 35499 |
aman |
130 |
return responseSender.ok("Rejected Successfully");
|
| 35340 |
aman |
131 |
}
|
|
|
132 |
|
| 35360 |
aman |
133 |
@RequestMapping(value = "/trial/approve/{trialFormId}", method = RequestMethod.POST)
|
|
|
134 |
public String approveTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
135 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
136 |
trialForm.setStatus(ProfitMandiConstants.Status.APPROVED);
|
|
|
137 |
try {
|
|
|
138 |
trialService.sentMailForStoreCodeCreation(trialForm);
|
|
|
139 |
} catch (Exception e) {
|
|
|
140 |
e.printStackTrace();
|
|
|
141 |
}
|
|
|
142 |
return "trial-form";
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
@RequestMapping(value = "/trial/convertToFranchise/{trialFormId}", method = RequestMethod.POST)
|
|
|
146 |
public String convertedToFranchise(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
147 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
148 |
trialForm.setStatus(ProfitMandiConstants.Status.CONVERTED);
|
|
|
149 |
|
|
|
150 |
return "trial-form";
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
@RequestMapping(value = "/trial/userBrandPotential/{trialFormId}", method = RequestMethod.GET)
|
|
|
154 |
public ResponseEntity<?> userBrandPotential(HttpServletRequest request, @PathVariable int trialFormId) throws Exception {
|
|
|
155 |
List<TrialBrandPotential> trialBrandPotentials = trialBrandPotentialRepository.findAllByTrialFormId(trialFormId);
|
|
|
156 |
|
|
|
157 |
return responseSender.ok(trialBrandPotentials);
|
|
|
158 |
}
|
|
|
159 |
|
| 35340 |
aman |
160 |
@RequestMapping(value = "/trial/brand-Potential", method = RequestMethod.POST)
|
|
|
161 |
public ResponseEntity<?> brandPotential(HttpServletRequest request) throws Exception {
|
|
|
162 |
|
|
|
163 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
|
|
164 |
int row = 1;
|
|
|
165 |
while (true) {
|
|
|
166 |
String brand = request.getParameter("brand_" + row);
|
|
|
167 |
String potential = request.getParameter("potential_" + row);
|
|
|
168 |
|
|
|
169 |
if (brand == null && potential == null) {
|
|
|
170 |
break;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
if (brand != null && !brand.trim().isEmpty()
|
|
|
174 |
&& potential != null && !potential.trim().isEmpty()) {
|
|
|
175 |
|
|
|
176 |
TrialBrandPotential tbp = new TrialBrandPotential();
|
|
|
177 |
tbp.setTrialFormId(trialFormId);
|
|
|
178 |
tbp.setBrandName(brand.trim());
|
|
|
179 |
tbp.setPotential(Integer.parseInt(potential));
|
| 35370 |
aman |
180 |
tbp.setCreatedAt(LocalDateTime.now());
|
| 35340 |
aman |
181 |
|
|
|
182 |
trialBrandPotentialRepository.persist(tbp);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
row++;
|
|
|
186 |
}
|
|
|
187 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
| 35360 |
aman |
188 |
trialForm.setUpdatedOn(LocalDateTime.now());
|
| 35340 |
aman |
189 |
trialForm.setStatus(ProfitMandiConstants.Status.VERIFIED);
|
| 35360 |
aman |
190 |
try {
|
|
|
191 |
trialService.sentMailForTrialUserToSales(trialForm);
|
|
|
192 |
} catch (Exception e) {
|
|
|
193 |
e.printStackTrace();
|
|
|
194 |
}
|
| 35340 |
aman |
195 |
return responseSender.ok("Saved Successfully");
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
|
| 35289 |
amit |
199 |
}
|