| 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;
|
|
|
9 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 35340 |
aman |
10 |
import com.spice.profitmandi.dao.repository.fofo.TrialBrandPotentialRepository;
|
| 35289 |
amit |
11 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
| 35360 |
aman |
12 |
import com.spice.profitmandi.dao.service.TrialService;
|
| 35289 |
amit |
13 |
import org.apache.logging.log4j.LogManager;
|
|
|
14 |
import org.apache.logging.log4j.Logger;
|
|
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 35340 |
aman |
16 |
import org.springframework.http.ResponseEntity;
|
| 35289 |
amit |
17 |
import org.springframework.stereotype.Controller;
|
|
|
18 |
import org.springframework.ui.Model;
|
|
|
19 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 35360 |
aman |
22 |
import org.springframework.web.bind.annotation.ResponseBody;
|
| 35289 |
amit |
23 |
|
|
|
24 |
import javax.servlet.http.HttpServletRequest;
|
|
|
25 |
import javax.transaction.Transactional;
|
| 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
|
|
|
33 |
@Transactional(rollbackOn = Throwable.class)
|
|
|
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 |
|
| 35289 |
amit |
52 |
@RequestMapping(value = "/trial/pending", method = RequestMethod.GET)
|
|
|
53 |
public String getTrialPending(HttpServletRequest request, Model model) throws Exception {
|
|
|
54 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.PENDING);
|
|
|
55 |
LOGGER.info("trialForms {}", trialForms.size());
|
| 35360 |
aman |
56 |
Set<AuthUser> bmAuthUsers = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Collections.singletonList(EscalationType.L2)).stream().filter(x -> x.isActive()).collect(Collectors.toSet());
|
|
|
57 |
Set<AuthUser> asmAuthUsers = csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_SALES, Collections.singletonList(EscalationType.L1)).stream().filter(x -> x.isActive()).collect(Collectors.toSet());
|
|
|
58 |
LOGGER.info("bm {}", bmAuthUsers);
|
|
|
59 |
LOGGER.info("asm {}", asmAuthUsers);
|
|
|
60 |
model.addAttribute("bm", bmAuthUsers);
|
|
|
61 |
model.addAttribute("asm", asmAuthUsers);
|
| 35289 |
amit |
62 |
model.addAttribute("trialForms", trialForms);
|
|
|
63 |
return "trial-form";
|
|
|
64 |
}
|
|
|
65 |
|
| 35340 |
aman |
66 |
@RequestMapping(value = "/trial/verified", method = RequestMethod.GET)
|
|
|
67 |
public String verifiedTrial(HttpServletRequest request, Model model) throws Exception {
|
|
|
68 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.VERIFIED);
|
|
|
69 |
LOGGER.info("trialForms {}", trialForms.size());
|
|
|
70 |
model.addAttribute("trialForms", trialForms);
|
|
|
71 |
return "trial-verified";
|
|
|
72 |
}
|
|
|
73 |
|
| 35360 |
aman |
74 |
@RequestMapping(value = "/trial/asm-bm", method = RequestMethod.POST)
|
|
|
75 |
@ResponseBody
|
|
|
76 |
public ResponseEntity<?> asmBm(HttpServletRequest request) throws Exception {
|
|
|
77 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
|
|
78 |
int asmId = Integer.parseInt(request.getParameter("asmId"));
|
|
|
79 |
int bmId = Integer.parseInt(request.getParameter("bmId"));
|
|
|
80 |
|
|
|
81 |
if (trialFormId == 0 || asmId == 0 || bmId == 0) {
|
|
|
82 |
throw new Exception("please select both bm and asm");
|
|
|
83 |
}
|
|
|
84 |
TrialForm trialForms = trialFormRepository.selectById(trialFormId);
|
|
|
85 |
trialForms.setAsmId(asmId);
|
|
|
86 |
trialForms.setBmId(bmId);
|
|
|
87 |
trialForms.setUpdatedOn(LocalDateTime.now());
|
|
|
88 |
return responseSender.ok("Saved Successfully");
|
|
|
89 |
}
|
|
|
90 |
|
| 35289 |
amit |
91 |
@RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
|
|
|
92 |
public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
93 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
94 |
return "trial-form";
|
|
|
95 |
}
|
| 35340 |
aman |
96 |
|
| 35391 |
aman |
97 |
@RequestMapping(value = "/trial/reject/{trialFormId}", method = RequestMethod.POST)
|
| 35340 |
aman |
98 |
public String rejectTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
99 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
100 |
trialForm.setStatus(ProfitMandiConstants.Status.REJECTED);
|
| 35391 |
aman |
101 |
trialService.sentRejectionMailToTrialUser(trialForm);
|
| 35340 |
aman |
102 |
|
|
|
103 |
return "trial-form";
|
|
|
104 |
}
|
|
|
105 |
|
| 35360 |
aman |
106 |
@RequestMapping(value = "/trial/approve/{trialFormId}", method = RequestMethod.POST)
|
|
|
107 |
public String approveTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
108 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
109 |
trialForm.setStatus(ProfitMandiConstants.Status.APPROVED);
|
|
|
110 |
try {
|
|
|
111 |
trialService.sentMailForStoreCodeCreation(trialForm);
|
|
|
112 |
} catch (Exception e) {
|
|
|
113 |
e.printStackTrace();
|
|
|
114 |
}
|
|
|
115 |
return "trial-form";
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
@RequestMapping(value = "/trial/convertToFranchise/{trialFormId}", method = RequestMethod.POST)
|
|
|
119 |
public String convertedToFranchise(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
|
|
120 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
|
|
121 |
trialForm.setStatus(ProfitMandiConstants.Status.CONVERTED);
|
|
|
122 |
|
|
|
123 |
return "trial-form";
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
@RequestMapping(value = "/trial/userBrandPotential/{trialFormId}", method = RequestMethod.GET)
|
|
|
127 |
public ResponseEntity<?> userBrandPotential(HttpServletRequest request, @PathVariable int trialFormId) throws Exception {
|
|
|
128 |
List<TrialBrandPotential> trialBrandPotentials = trialBrandPotentialRepository.findAllByTrialFormId(trialFormId);
|
|
|
129 |
|
|
|
130 |
return responseSender.ok(trialBrandPotentials);
|
|
|
131 |
}
|
|
|
132 |
|
| 35340 |
aman |
133 |
@RequestMapping(value = "/trial/brand-Potential", method = RequestMethod.POST)
|
|
|
134 |
public ResponseEntity<?> brandPotential(HttpServletRequest request) throws Exception {
|
|
|
135 |
|
|
|
136 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
|
|
137 |
int row = 1;
|
|
|
138 |
while (true) {
|
|
|
139 |
String brand = request.getParameter("brand_" + row);
|
|
|
140 |
String potential = request.getParameter("potential_" + row);
|
|
|
141 |
|
|
|
142 |
if (brand == null && potential == null) {
|
|
|
143 |
break;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
if (brand != null && !brand.trim().isEmpty()
|
|
|
147 |
&& potential != null && !potential.trim().isEmpty()) {
|
|
|
148 |
|
|
|
149 |
TrialBrandPotential tbp = new TrialBrandPotential();
|
|
|
150 |
tbp.setTrialFormId(trialFormId);
|
|
|
151 |
tbp.setBrandName(brand.trim());
|
|
|
152 |
tbp.setPotential(Integer.parseInt(potential));
|
| 35370 |
aman |
153 |
tbp.setCreatedAt(LocalDateTime.now());
|
| 35340 |
aman |
154 |
|
|
|
155 |
trialBrandPotentialRepository.persist(tbp);
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
row++;
|
|
|
159 |
}
|
|
|
160 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
| 35360 |
aman |
161 |
trialForm.setUpdatedOn(LocalDateTime.now());
|
| 35340 |
aman |
162 |
trialForm.setStatus(ProfitMandiConstants.Status.VERIFIED);
|
| 35360 |
aman |
163 |
try {
|
|
|
164 |
trialService.sentMailForTrialUserToSales(trialForm);
|
|
|
165 |
} catch (Exception e) {
|
|
|
166 |
e.printStackTrace();
|
|
|
167 |
}
|
| 35340 |
aman |
168 |
return responseSender.ok("Saved Successfully");
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
|
| 35289 |
amit |
172 |
}
|