| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
3 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 4 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
4 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| - |
|
5 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 5 |
import com.spice.profitmandi.dao.entity.fofo.TrialBrandPotential;
|
6 |
import com.spice.profitmandi.dao.entity.fofo.TrialBrandPotential;
|
| 6 |
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
|
7 |
import com.spice.profitmandi.dao.entity.fofo.TrialForm;
|
| - |
|
8 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| - |
|
9 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 7 |
import com.spice.profitmandi.dao.repository.fofo.TrialBrandPotentialRepository;
|
10 |
import com.spice.profitmandi.dao.repository.fofo.TrialBrandPotentialRepository;
|
| 8 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
11 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
| - |
|
12 |
import com.spice.profitmandi.dao.service.TrialService;
|
| 9 |
import org.apache.logging.log4j.LogManager;
|
13 |
import org.apache.logging.log4j.LogManager;
|
| 10 |
import org.apache.logging.log4j.Logger;
|
14 |
import org.apache.logging.log4j.Logger;
|
| 11 |
import org.springframework.beans.factory.annotation.Autowired;
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 12 |
import org.springframework.http.ResponseEntity;
|
16 |
import org.springframework.http.ResponseEntity;
|
| 13 |
import org.springframework.stereotype.Controller;
|
17 |
import org.springframework.stereotype.Controller;
|
| 14 |
import org.springframework.ui.Model;
|
18 |
import org.springframework.ui.Model;
|
| 15 |
import org.springframework.web.bind.annotation.PathVariable;
|
19 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| - |
|
22 |
import org.springframework.web.bind.annotation.ResponseBody;
|
| 18 |
|
23 |
|
| 19 |
import javax.servlet.http.HttpServletRequest;
|
24 |
import javax.servlet.http.HttpServletRequest;
|
| 20 |
import javax.transaction.Transactional;
|
25 |
import javax.transaction.Transactional;
|
| - |
|
26 |
import java.time.LocalDateTime;
|
| - |
|
27 |
import java.util.Collections;
|
| 21 |
import java.util.List;
|
28 |
import java.util.List;
|
| - |
|
29 |
import java.util.Set;
|
| - |
|
30 |
import java.util.stream.Collectors;
|
| 22 |
|
31 |
|
| 23 |
@Controller
|
32 |
@Controller
|
| 24 |
@Transactional(rollbackOn = Throwable.class)
|
33 |
@Transactional(rollbackOn = Throwable.class)
|
| 25 |
public class TrialController {
|
34 |
public class TrialController {
|
| 26 |
|
35 |
|
| - |
|
36 |
private static final Logger LOGGER = LogManager.getLogger(TrialController.class);
|
| 27 |
@Autowired
|
37 |
@Autowired
|
| 28 |
TrialBrandPotentialRepository trialBrandPotentialRepository;
|
38 |
TrialBrandPotentialRepository trialBrandPotentialRepository;
|
| 29 |
|
39 |
|
| 30 |
@Autowired
|
40 |
@Autowired
|
| 31 |
ResponseSender responseSender;
|
41 |
ResponseSender responseSender;
|
| 32 |
|
42 |
|
| - |
|
43 |
@Autowired
|
| 33 |
private static final Logger LOGGER = LogManager.getLogger(TrialController.class);
|
44 |
CsService csService;
|
| - |
|
45 |
|
| 34 |
@Autowired
|
46 |
@Autowired
|
| 35 |
TrialFormRepository trialFormRepository;
|
47 |
TrialFormRepository trialFormRepository;
|
| 36 |
|
48 |
|
| - |
|
49 |
@Autowired
|
| - |
|
50 |
TrialService trialService;
|
| - |
|
51 |
|
| 37 |
@RequestMapping(value = "/trial/pending", method = RequestMethod.GET)
|
52 |
@RequestMapping(value = "/trial/pending", method = RequestMethod.GET)
|
| 38 |
public String getTrialPending(HttpServletRequest request, Model model) throws Exception {
|
53 |
public String getTrialPending(HttpServletRequest request, Model model) throws Exception {
|
| 39 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.PENDING);
|
54 |
List<TrialForm> trialForms = trialFormRepository.selectAllByStatus(ProfitMandiConstants.Status.PENDING);
|
| 40 |
LOGGER.info("trialForms {}", trialForms.size());
|
55 |
LOGGER.info("trialForms {}", trialForms.size());
|
| - |
|
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);
|
| 41 |
model.addAttribute("trialForms", trialForms);
|
62 |
model.addAttribute("trialForms", trialForms);
|
| 42 |
return "trial-form";
|
63 |
return "trial-form";
|
| 43 |
}
|
64 |
}
|
| 44 |
|
65 |
|
| 45 |
@RequestMapping(value = "/trial/verified", method = RequestMethod.GET)
|
66 |
@RequestMapping(value = "/trial/verified", method = RequestMethod.GET)
|
| Line 48... |
Line 69... |
| 48 |
LOGGER.info("trialForms {}", trialForms.size());
|
69 |
LOGGER.info("trialForms {}", trialForms.size());
|
| 49 |
model.addAttribute("trialForms", trialForms);
|
70 |
model.addAttribute("trialForms", trialForms);
|
| 50 |
return "trial-verified";
|
71 |
return "trial-verified";
|
| 51 |
}
|
72 |
}
|
| 52 |
|
73 |
|
| - |
|
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 |
|
| 53 |
@RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
|
91 |
@RequestMapping(value = "/trial/create/{trialFormId}", method = RequestMethod.GET)
|
| 54 |
public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
92 |
public String getTrialPending(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
| 55 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
93 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
| 56 |
|
- |
|
| 57 |
return "trial-form";
|
94 |
return "trial-form";
|
| 58 |
}
|
95 |
}
|
| 59 |
|
96 |
|
| 60 |
@RequestMapping(value = "/trial/cancel/{trialFormId}", method = RequestMethod.POST)
|
97 |
@RequestMapping(value = "/trial/cancel/{trialFormId}", method = RequestMethod.POST)
|
| 61 |
public String rejectTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
98 |
public String rejectTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
| Line 63... |
Line 100... |
| 63 |
trialForm.setStatus(ProfitMandiConstants.Status.REJECTED);
|
100 |
trialForm.setStatus(ProfitMandiConstants.Status.REJECTED);
|
| 64 |
|
101 |
|
| 65 |
return "trial-form";
|
102 |
return "trial-form";
|
| 66 |
}
|
103 |
}
|
| 67 |
|
104 |
|
| - |
|
105 |
@RequestMapping(value = "/trial/approve/{trialFormId}", method = RequestMethod.POST)
|
| - |
|
106 |
public String approveTrialUser(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
| - |
|
107 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
| - |
|
108 |
trialForm.setStatus(ProfitMandiConstants.Status.APPROVED);
|
| - |
|
109 |
try {
|
| - |
|
110 |
trialService.sentMailForStoreCodeCreation(trialForm);
|
| - |
|
111 |
} catch (Exception e) {
|
| - |
|
112 |
e.printStackTrace();
|
| - |
|
113 |
}
|
| - |
|
114 |
return "trial-form";
|
| - |
|
115 |
}
|
| - |
|
116 |
|
| - |
|
117 |
@RequestMapping(value = "/trial/convertToFranchise/{trialFormId}", method = RequestMethod.POST)
|
| - |
|
118 |
public String convertedToFranchise(HttpServletRequest request, Model model, @PathVariable int trialFormId) throws Exception {
|
| - |
|
119 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
| - |
|
120 |
trialForm.setStatus(ProfitMandiConstants.Status.CONVERTED);
|
| - |
|
121 |
|
| - |
|
122 |
return "trial-form";
|
| - |
|
123 |
}
|
| - |
|
124 |
|
| - |
|
125 |
@RequestMapping(value = "/trial/userBrandPotential/{trialFormId}", method = RequestMethod.GET)
|
| - |
|
126 |
public ResponseEntity<?> userBrandPotential(HttpServletRequest request, @PathVariable int trialFormId) throws Exception {
|
| - |
|
127 |
List<TrialBrandPotential> trialBrandPotentials = trialBrandPotentialRepository.findAllByTrialFormId(trialFormId);
|
| - |
|
128 |
|
| - |
|
129 |
return responseSender.ok(trialBrandPotentials);
|
| - |
|
130 |
}
|
| - |
|
131 |
|
| 68 |
@RequestMapping(value = "/trial/brand-Potential", method = RequestMethod.POST)
|
132 |
@RequestMapping(value = "/trial/brand-Potential", method = RequestMethod.POST)
|
| 69 |
public ResponseEntity<?> brandPotential(HttpServletRequest request) throws Exception {
|
133 |
public ResponseEntity<?> brandPotential(HttpServletRequest request) throws Exception {
|
| 70 |
|
134 |
|
| 71 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
135 |
int trialFormId = Integer.parseInt(request.getParameter("trialFormId"));
|
| 72 |
int row = 1;
|
136 |
int row = 1;
|
| Line 90... |
Line 154... |
| 90 |
}
|
154 |
}
|
| 91 |
|
155 |
|
| 92 |
row++;
|
156 |
row++;
|
| 93 |
}
|
157 |
}
|
| 94 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
158 |
TrialForm trialForm = trialFormRepository.selectById(trialFormId);
|
| - |
|
159 |
trialForm.setUpdatedOn(LocalDateTime.now());
|
| 95 |
trialForm.setStatus(ProfitMandiConstants.Status.VERIFIED);
|
160 |
trialForm.setStatus(ProfitMandiConstants.Status.VERIFIED);
|
| - |
|
161 |
try {
|
| - |
|
162 |
trialService.sentMailForTrialUserToSales(trialForm);
|
| - |
|
163 |
} catch (Exception e) {
|
| - |
|
164 |
e.printStackTrace();
|
| - |
|
165 |
}
|
| 96 |
return responseSender.ok("Saved Successfully");
|
166 |
return responseSender.ok("Saved Successfully");
|
| 97 |
}
|
167 |
}
|
| 98 |
|
168 |
|
| 99 |
|
169 |
|
| 100 |
}
|
170 |
}
|