| 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);
|
| 35517 |
aman |
79 |
model.addAttribute("status", ProfitMandiConstants.Status.values());
|
| 35499 |
aman |
80 |
return "all-trial-form";
|
|
|
81 |
}
|
|
|
82 |
|
| 35517 |
aman |
83 |
@RequestMapping(value = "/trial/by-status", method = RequestMethod.GET)
|
|
|
84 |
public String getByStatus(
|
|
|
85 |
@RequestParam("status") ProfitMandiConstants.Status status,
|
|
|
86 |
Model model) {
|
|
|
87 |
|
|
|
88 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(status);
|
|
|
89 |
model.addAttribute("trialForms", trialForms);
|
|
|
90 |
model.addAttribute("status", ProfitMandiConstants.Status.values());
|
|
|
91 |
model.addAttribute("selectedStatus", status);
|
|
|
92 |
return "all-trial-form";
|
|
|
93 |
}
|
|
|
94 |
|
| 35340 |
aman |
95 |
@RequestMapping(value = "/trial/verified", method = RequestMethod.GET)
|
|
|
96 |
public String verifiedTrial(HttpServletRequest request, Model model) throws Exception {
|
| 35499 |
aman |
97 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
98 |
|
|
|
99 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 35340 |
aman |
100 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.VERIFIED);
|
| 35499 |
aman |
101 |
List<TrialForm> filteredTrialForms = trialForms.stream()
|
|
|
102 |
.filter(trialForm ->
|
|
|
103 |
(trialForm.getBmId() != null && trialForm.getBmId().equals(authUser.getId())) ||
|
|
|
104 |
(trialForm.getAsmId() != null && trialForm.getAsmId().equals(authUser.getId()))
|
|
|
105 |
)
|
|
|
106 |
.collect(Collectors.toList());
|
| 35340 |
aman |
107 |
LOGGER.info("trialForms {}", trialForms.size());
|
| 35499 |
aman |
108 |
LOGGER.info("filtered trialForms {}", filteredTrialForms);
|
|
|
109 |
model.addAttribute("trialForms", filteredTrialForms);
|
| 35340 |
aman |
110 |
return "trial-verified";
|
|
|
111 |
}
|
|
|
112 |
|
| 35360 |
aman |
113 |
@RequestMapping(value = "/trial/asm-bm", method = RequestMethod.POST)
|
|
|
114 |
@ResponseBody
|
|
|
115 |
public ResponseEntity<?> asmBm(HttpServletRequest request) throws Exception {
|
|
|
116 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
|
|
117 |
int asmId = Integer.parseInt(request.getParameter("asmId"));
|
|
|
118 |
int bmId = Integer.parseInt(request.getParameter("bmId"));
|
|
|
119 |
|
|
|
120 |
if (trialFormId == 0 || asmId == 0 || bmId == 0) {
|
|
|
121 |
throw new Exception("please select both bm and asm");
|
|
|
122 |
}
|
|
|
123 |
TrialForm trialForms = trialFormRepository.selectById(trialFormId);
|
|
|
124 |
trialForms.setAsmId(asmId);
|
|
|
125 |
trialForms.setBmId(bmId);
|
|
|
126 |
trialForms.setUpdatedOn(LocalDateTime.now());
|
|
|
127 |
return responseSender.ok("Saved Successfully");
|
|
|
128 |
}
|
|
|
129 |
|
| 35289 |
amit |
130 |
@RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
|
|
|
131 |
public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
132 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
133 |
return "trial-form";
|
|
|
134 |
}
|
| 35340 |
aman |
135 |
|
| 35499 |
aman |
136 |
@RequestMapping(value = "/trial/reject", method = RequestMethod.POST)
|
|
|
137 |
public ResponseEntity<?> rejectTrialUser(HttpServletRequest request, @RequestParam int trialFormId,
|
|
|
138 |
@RequestParam String remark) throws Exception {
|
| 35340 |
aman |
139 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
140 |
trialForm.setStatus(ProfitMandiConstants.Status.REJECTED);
|
| 35499 |
aman |
141 |
trialForm.setRemark(remark);
|
| 35391 |
aman |
142 |
trialService.sentRejectionMailToTrialUser(trialForm);
|
| 35499 |
aman |
143 |
return responseSender.ok("Rejected Successfully");
|
| 35340 |
aman |
144 |
}
|
|
|
145 |
|
| 35360 |
aman |
146 |
@RequestMapping(value = "/trial/approve/{trialFormId}", method = RequestMethod.POST)
|
|
|
147 |
public String approveTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
148 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
149 |
trialForm.setStatus(ProfitMandiConstants.Status.APPROVED);
|
|
|
150 |
try {
|
|
|
151 |
trialService.sentMailForStoreCodeCreation(trialForm);
|
|
|
152 |
} catch (Exception e) {
|
|
|
153 |
e.printStackTrace();
|
|
|
154 |
}
|
|
|
155 |
return "trial-form";
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
@RequestMapping(value = "/trial/convertToFranchise/{trialFormId}", method = RequestMethod.POST)
|
|
|
159 |
public String convertedToFranchise(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
160 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
161 |
trialForm.setStatus(ProfitMandiConstants.Status.CONVERTED);
|
|
|
162 |
|
|
|
163 |
return "trial-form";
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
@RequestMapping(value = "/trial/userBrandPotential/{trialFormId}", method = RequestMethod.GET)
|
|
|
167 |
public ResponseEntity<?> userBrandPotential(HttpServletRequest request, @PathVariable int trialFormId) throws Exception {
|
|
|
168 |
List<TrialBrandPotential> trialBrandPotentials = trialBrandPotentialRepository.findAllByTrialFormId(trialFormId);
|
|
|
169 |
|
|
|
170 |
return responseSender.ok(trialBrandPotentials);
|
|
|
171 |
}
|
|
|
172 |
|
| 35340 |
aman |
173 |
@RequestMapping(value = "/trial/brand-Potential", method = RequestMethod.POST)
|
|
|
174 |
public ResponseEntity<?> brandPotential(HttpServletRequest request) throws Exception {
|
|
|
175 |
|
|
|
176 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
|
|
177 |
int row = 1;
|
|
|
178 |
while (true) {
|
|
|
179 |
String brand = request.getParameter("brand_" + row);
|
|
|
180 |
String potential = request.getParameter("potential_" + row);
|
|
|
181 |
|
|
|
182 |
if (brand == null && potential == null) {
|
|
|
183 |
break;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
if (brand != null && !brand.trim().isEmpty()
|
|
|
187 |
&& potential != null && !potential.trim().isEmpty()) {
|
|
|
188 |
|
|
|
189 |
TrialBrandPotential tbp = new TrialBrandPotential();
|
|
|
190 |
tbp.setTrialFormId(trialFormId);
|
|
|
191 |
tbp.setBrandName(brand.trim());
|
|
|
192 |
tbp.setPotential(Integer.parseInt(potential));
|
| 35370 |
aman |
193 |
tbp.setCreatedAt(LocalDateTime.now());
|
| 35340 |
aman |
194 |
|
|
|
195 |
trialBrandPotentialRepository.persist(tbp);
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
row++;
|
|
|
199 |
}
|
|
|
200 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
| 35360 |
aman |
201 |
trialForm.setUpdatedOn(LocalDateTime.now());
|
| 35340 |
aman |
202 |
trialForm.setStatus(ProfitMandiConstants.Status.VERIFIED);
|
| 35360 |
aman |
203 |
try {
|
|
|
204 |
trialService.sentMailForTrialUserToSales(trialForm);
|
|
|
205 |
} catch (Exception e) {
|
|
|
206 |
e.printStackTrace();
|
|
|
207 |
}
|
| 35340 |
aman |
208 |
return responseSender.ok("Saved Successfully");
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
|
| 35289 |
amit |
212 |
}
|