| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.time.LocalDate;
|
| 3 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| - |
|
5 |
import java.time.format.DateTimeFormatter;
|
| 4 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 5 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| 6 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| - |
|
9 |
import java.util.HashSet;
|
| 7 |
import java.util.List;
|
10 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 9 |
import java.util.stream.Collectors;
|
12 |
import java.util.stream.Collectors;
|
| 10 |
|
13 |
|
| 11 |
import javax.servlet.http.HttpServletRequest;
|
14 |
import javax.servlet.http.HttpServletRequest;
|
| Line 19... |
Line 22... |
| 19 |
import org.springframework.web.bind.annotation.RequestBody;
|
22 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
23 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
24 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 22 |
import org.springframework.web.bind.annotation.RequestParam;
|
25 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 23 |
|
26 |
|
| - |
|
27 |
import com.google.gson.Gson;
|
| 24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
29 |
import com.spice.profitmandi.common.model.ChartInvestmentModel;
|
| - |
|
30 |
import com.spice.profitmandi.common.model.Data;
|
| - |
|
31 |
import com.spice.profitmandi.common.model.DataInvestmentModel;
|
| - |
|
32 |
import com.spice.profitmandi.common.model.Legend;
|
| - |
|
33 |
import com.spice.profitmandi.common.model.OptionModel;
|
| - |
|
34 |
import com.spice.profitmandi.common.model.PieLables;
|
| 25 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
35 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| - |
|
36 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| - |
|
37 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 26 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
38 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
| 27 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
39 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
| 28 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
40 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| - |
|
41 |
import com.spice.profitmandi.dao.model.ChartLeadModel;
|
| 29 |
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
|
42 |
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
|
| 30 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
43 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
| - |
|
44 |
import com.spice.profitmandi.dao.model.DataLeadModel;
|
| - |
|
45 |
import com.spice.profitmandi.dao.model.LeadStatusData;
|
| 31 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
46 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| - |
|
47 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
|
48 |
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
49 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
| 34 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
50 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| - |
|
51 |
import com.spice.profitmandi.service.AuthService;
|
| 35 |
import com.spice.profitmandi.web.model.LoginDetails;
|
52 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 36 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
53 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 37 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
54 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 38 |
|
55 |
|
| 39 |
@Controller
|
56 |
@Controller
|
| Line 49... |
Line 66... |
| 49 |
|
66 |
|
| 50 |
@Autowired
|
67 |
@Autowired
|
| 51 |
private StateRepository stateRepository;
|
68 |
private StateRepository stateRepository;
|
| 52 |
|
69 |
|
| 53 |
@Autowired
|
70 |
@Autowired
|
| - |
|
71 |
private AuthService authService;
|
| - |
|
72 |
|
| - |
|
73 |
@Autowired
|
| 54 |
private AuthRepository authRepository;
|
74 |
private AuthRepository authRepository;
|
| 55 |
|
75 |
|
| 56 |
@Autowired
|
76 |
@Autowired
|
| - |
|
77 |
private Gson gson;
|
| - |
|
78 |
|
| - |
|
79 |
@Autowired
|
| 57 |
private CookiesProcessor cookiesProcessor;
|
80 |
private CookiesProcessor cookiesProcessor;
|
| 58 |
|
81 |
|
| 59 |
@Autowired
|
82 |
@Autowired
|
| 60 |
private MVCResponseSender mvcResponseSender;
|
83 |
private MVCResponseSender mvcResponseSender;
|
| 61 |
|
84 |
|
| Line 65... |
Line 88... |
| 65 |
public String getOpenLead(HttpServletRequest request,
|
88 |
public String getOpenLead(HttpServletRequest request,
|
| 66 |
@RequestParam(name = "leadStatus", required = false, defaultValue = "followUp") List<LeadStatus> leadStatus,
|
89 |
@RequestParam(name = "leadStatus", required = false, defaultValue = "followUp") List<LeadStatus> leadStatus,
|
| 67 |
@RequestParam(name = "color", required = false, defaultValue = "") List<String> color, Model model)
|
90 |
@RequestParam(name = "color", required = false, defaultValue = "") List<String> color, Model model)
|
| 68 |
throws Exception {
|
91 |
throws Exception {
|
| 69 |
|
92 |
|
| - |
|
93 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
94 |
String emailId = loginDetails.getEmailId();
|
| - |
|
95 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailId);
|
| - |
|
96 |
|
| - |
|
97 |
List<Integer> authUserIds = authService.getDirectReportee(authUser.getId());
|
| - |
|
98 |
LOGGER.info("authIds" + authUserIds);
|
| - |
|
99 |
|
| 70 |
if (leadStatus.contains(LeadStatus.All)) {
|
100 |
if (leadStatus.contains(LeadStatus.All)) {
|
| 71 |
|
101 |
|
| 72 |
leadStatus.addAll(Arrays.asList(LeadStatus.values()));
|
102 |
leadStatus.addAll(Arrays.asList(LeadStatus.values()));
|
| 73 |
}
|
103 |
}
|
| 74 |
|
104 |
|
| 75 |
List<Lead> leads = null;
|
105 |
List<Lead> leads = null;
|
| 76 |
Map<Integer, LeadActivity> leadActivityMap = new HashMap<>();
|
106 |
Map<Integer, LeadActivity> leadActivityMap = new HashMap<>();
|
| 77 |
|
- |
|
| 78 |
if (!color.isEmpty()) {
|
107 |
if (!color.isEmpty()) {
|
| 79 |
if (color.contains("All")) {
|
108 |
if (color.contains("All")) {
|
| 80 |
color.add("yellow");
|
109 |
color.add("yellow");
|
| 81 |
color.add("green");
|
110 |
color.add("green");
|
| 82 |
}
|
111 |
}
|
| 83 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color,
|
112 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, authUserIds, color,
|
| 84 |
LocalDateTime.now().withDayOfMonth(1).minusMonths(3));
|
113 |
LocalDateTime.now().withDayOfMonth(1).minusMonths(3));
|
| 85 |
|
- |
|
| 86 |
} else {
|
114 |
} else {
|
| 87 |
|
115 |
|
| 88 |
leads = leadRepository.selectAllByStatusAndUpdatedTimestamp(leadStatus,
|
116 |
leads = leadRepository.selectAllByStatusAndUpdatedTimestamp(leadStatus,
|
| 89 |
LocalDateTime.now().withDayOfMonth(1).minusMonths(3));
|
117 |
LocalDateTime.now().withDayOfMonth(1).minusMonths(3), authUserIds);
|
| 90 |
|
- |
|
| 91 |
// List<Lead> leads = leadRepository.selectAllBylistStatus(leadStatus);
|
118 |
// List<Lead> leads = leadRepository.selectAllBylistStatus(leadStatus);
|
| 92 |
if (!leads.isEmpty()) {
|
119 |
if (!leads.isEmpty()) {
|
| 93 |
leads.addAll(leadRepository.selectAllByStatus(LeadStatus.pending));
|
120 |
leads.addAll(leadRepository.selectAllByStatus(LeadStatus.pending));
|
| 94 |
}
|
121 |
}
|
| 95 |
}
|
122 |
}
|
| - |
|
123 |
List<Lead> weekLast = new ArrayList<>();
|
| - |
|
124 |
List<Lead> weekThird = new ArrayList<>();
|
| - |
|
125 |
List<Lead> weekSecond = new ArrayList<>();
|
| - |
|
126 |
List<Lead> weekFirst = new ArrayList<>();
|
| - |
|
127 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| - |
|
128 |
List<LeadWeakWiseModel> lwDays = new ArrayList<>();
|
| - |
|
129 |
|
| - |
|
130 |
|
| - |
|
131 |
for (int i = 7; i >= 1; i--) {
|
| - |
|
132 |
LocalDateTime startOfDay = curDate.minusDays(i);
|
| - |
|
133 |
|
| - |
|
134 |
LeadWeakWiseModel lm = new LeadWeakWiseModel();
|
| - |
|
135 |
lm.setMonth(startOfDay.toLocalDate());
|
| - |
|
136 |
lwDays.add(lm);
|
| - |
|
137 |
}
|
| - |
|
138 |
if(!leads.isEmpty())
|
| - |
|
139 |
{
|
| - |
|
140 |
for (Lead lead : leads) {
|
| - |
|
141 |
|
| - |
|
142 |
if (lead.getCreatedTimestamp().isAfter(curDate.minusDays(28))
|
| - |
|
143 |
&& lead.getCreatedTimestamp().isBefore(curDate.minusDays(22))) {
|
| - |
|
144 |
weekLast.add(lead);
|
| - |
|
145 |
|
| - |
|
146 |
}
|
| - |
|
147 |
|
| - |
|
148 |
if (lead.getCreatedTimestamp().isAfter(curDate.minusDays(21))
|
| - |
|
149 |
&& lead.getCreatedTimestamp().isBefore(curDate.minusDays(15))) {
|
| - |
|
150 |
weekThird.add(lead);
|
| - |
|
151 |
}
|
| - |
|
152 |
if (lead.getCreatedTimestamp().isAfter(curDate.minusDays(14))
|
| - |
|
153 |
&& lead.getCreatedTimestamp().isBefore(curDate.minusDays(8))) {
|
| - |
|
154 |
|
| - |
|
155 |
weekSecond.add(lead);
|
| - |
|
156 |
}
|
| - |
|
157 |
if (lead.getCreatedTimestamp().isAfter(curDate.minusDays(7))) {
|
| - |
|
158 |
weekFirst.add(lead);
|
| - |
|
159 |
}
|
| - |
|
160 |
|
| - |
|
161 |
}
|
| - |
|
162 |
}
|
| - |
|
163 |
|
| - |
|
164 |
|
| - |
|
165 |
LOGGER.info("weekLast" + weekLast);
|
| - |
|
166 |
LOGGER.info("weekThird" + weekThird);
|
| - |
|
167 |
LOGGER.info("weekSecond" + weekSecond);
|
| - |
|
168 |
Map<String, Long> leadLasts = weekLast.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
| - |
|
169 |
Collectors.mapping(Lead::getCreatedBy, Collectors.counting())));
|
| - |
|
170 |
Map<String, Long> leadThirds = weekThird.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
| - |
|
171 |
Collectors.mapping(Lead::getCreatedBy, Collectors.counting())));
|
| - |
|
172 |
Map<String, Long> leadSeconds = weekSecond.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
| - |
|
173 |
Collectors.mapping(Lead::getCreatedBy, Collectors.counting())));
|
| - |
|
174 |
|
| - |
|
175 |
Map<String, Map<LocalDate, Long>> leadFirsts = weekFirst.stream()
|
| - |
|
176 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
| - |
|
177 |
Collectors.groupingBy(x -> x.getCreatedTimestamp().toLocalDate(), Collectors.counting())));
|
| - |
|
178 |
|
| - |
|
179 |
LOGGER.info("leadFirsts" + leadFirsts);
|
| 96 |
|
180 |
|
| 97 |
List<Integer> authIds = new ArrayList<>();
|
181 |
List<Integer> authIds = new ArrayList<>();
|
| 98 |
if (!leads.isEmpty()) {
|
182 |
if (!leads.isEmpty()) {
|
| 99 |
|
183 |
|
| 100 |
authIds.addAll(leads.stream().map(x -> x.getAssignTo()).collect(Collectors.toList()));
|
184 |
authIds.addAll(leads.stream().map(x -> x.getAssignTo()).collect(Collectors.toList()));
|
| Line 113... |
Line 197... |
| 113 |
|
197 |
|
| 114 |
} else {
|
198 |
} else {
|
| 115 |
model.addAttribute("lead", leads);
|
199 |
model.addAttribute("lead", leads);
|
| 116 |
}
|
200 |
}
|
| 117 |
|
201 |
|
| - |
|
202 |
ChartLeadModel cm = this.getLeadChart(leads);
|
| - |
|
203 |
model.addAttribute("chartLead", gson.toJson(cm));
|
| - |
|
204 |
|
| - |
|
205 |
LOGGER.info("ChartLeadModel" + gson.toJson(cm));
|
| - |
|
206 |
LOGGER.info("lwDays" + lwDays);
|
| - |
|
207 |
|
| 118 |
LOGGER.info("leads" + leads);
|
208 |
LOGGER.info("leads" + leads);
|
| 119 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
209 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
| 120 |
.collect(Collectors.toList());
|
210 |
.collect(Collectors.toList());
|
| 121 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
211 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| - |
|
212 |
LocalDate lastDate = curDate.minusDays(1).toLocalDate();
|
| - |
|
213 |
|
| - |
|
214 |
List<LocalDate> weekDates = new ArrayList<>();
|
| - |
|
215 |
|
| - |
|
216 |
weekDates.add(curDate.minusDays(28).toLocalDate());
|
| - |
|
217 |
weekDates.add(curDate.minusDays(22).toLocalDate());
|
| - |
|
218 |
weekDates.add(curDate.minusDays(21).toLocalDate());
|
| - |
|
219 |
weekDates.add(curDate.minusDays(15).toLocalDate());
|
| - |
|
220 |
weekDates.add(curDate.minusDays(14).toLocalDate());
|
| - |
|
221 |
weekDates.add(curDate.minusDays(8).toLocalDate());
|
| - |
|
222 |
weekDates.add(curDate.minusDays(7).toLocalDate());
|
| - |
|
223 |
LOGGER.info("lastDate" + lastDate);
|
| - |
|
224 |
|
| - |
|
225 |
|
| - |
|
226 |
model.addAttribute("weekDates", weekDates);
|
| - |
|
227 |
|
| - |
|
228 |
model.addAttribute("lastDate", lastDate);
|
| 122 |
model.addAttribute("stateNames", stateNames);
|
229 |
model.addAttribute("stateNames", stateNames);
|
| 123 |
model.addAttribute("authUsers", authUsers);
|
230 |
model.addAttribute("authUsers", authUsers);
|
| 124 |
model.addAttribute("lead", leads);
|
231 |
model.addAttribute("lead", leads);
|
| 125 |
model.addAttribute("leadStatus", LeadStatus.values());
|
232 |
model.addAttribute("leadStatus", LeadStatus.values());
|
| - |
|
233 |
model.addAttribute("leadLasts", leadLasts);
|
| - |
|
234 |
model.addAttribute("leadThirds", leadThirds);
|
| - |
|
235 |
model.addAttribute("leadSeconds", leadSeconds);
|
| - |
|
236 |
model.addAttribute("leadFirsts", leadFirsts);
|
| - |
|
237 |
model.addAttribute("lwDays", lwDays);
|
| 126 |
|
238 |
|
| 127 |
model.addAttribute("selectedLeadStatus", leadStatus.get(0));
|
239 |
model.addAttribute("selectedLeadStatus", leadStatus.get(0));
|
| 128 |
return "lead";
|
240 |
return "lead";
|
| 129 |
|
241 |
|
| 130 |
}
|
242 |
}
|
| 131 |
|
243 |
|
| - |
|
244 |
public ChartLeadModel getLeadChart(List<Lead> leads) throws ProfitMandiBusinessException {
|
| - |
|
245 |
|
| - |
|
246 |
Map<LeadStatus, Long> leadStatusMap = leads.stream().collect(
|
| - |
|
247 |
Collectors.groupingBy(x -> x.getStatus(), Collectors.mapping(Lead::getStatus, Collectors.counting())));
|
| - |
|
248 |
|
| - |
|
249 |
ChartLeadModel cm = new ChartLeadModel();
|
| - |
|
250 |
|
| - |
|
251 |
HashSet<LeadStatus> labels = new HashSet<LeadStatus>();
|
| - |
|
252 |
labels.addAll(leadStatusMap.keySet());
|
| - |
|
253 |
|
| - |
|
254 |
List<LeadStatus> labelList = new ArrayList<>(labels);
|
| - |
|
255 |
List<String> backgroundColor = new ArrayList<>();
|
| - |
|
256 |
|
| - |
|
257 |
List<Long> values = new ArrayList<>();
|
| - |
|
258 |
|
| - |
|
259 |
for (LeadStatus label : labelList) {
|
| - |
|
260 |
values.add(leadStatusMap.get(label));
|
| - |
|
261 |
|
| - |
|
262 |
if (label.equals(LeadStatus.pending)) {
|
| - |
|
263 |
backgroundColor.add("pink");
|
| - |
|
264 |
}
|
| - |
|
265 |
if (label.equals(LeadStatus.notInterested)) {
|
| - |
|
266 |
backgroundColor.add("red");
|
| - |
|
267 |
}
|
| - |
|
268 |
if (label.equals(LeadStatus.followUp)) {
|
| - |
|
269 |
backgroundColor.add("#9ACD32");
|
| - |
|
270 |
}
|
| - |
|
271 |
if (label.equals(LeadStatus.finalized)) {
|
| - |
|
272 |
backgroundColor.add("blue");
|
| - |
|
273 |
}
|
| - |
|
274 |
}
|
| - |
|
275 |
LOGGER.info("labelList" + labelList);
|
| - |
|
276 |
|
| - |
|
277 |
LOGGER.info("backgroundColor" + backgroundColor);
|
| - |
|
278 |
LOGGER.info("labelsChartLead" + labels);
|
| - |
|
279 |
LeadStatusData data = new LeadStatusData();
|
| - |
|
280 |
data.setData(values);
|
| - |
|
281 |
data.setBackgroundColor(backgroundColor);
|
| - |
|
282 |
data.setLabel("DataSet 1");
|
| - |
|
283 |
|
| - |
|
284 |
PieLables label = new PieLables();
|
| - |
|
285 |
label.setFontColor("black");
|
| - |
|
286 |
label.setFontSize(15);
|
| - |
|
287 |
|
| - |
|
288 |
Legend legend = new Legend();
|
| - |
|
289 |
legend.setLabels(label);
|
| - |
|
290 |
legend.setPosition("left");
|
| - |
|
291 |
|
| - |
|
292 |
List<LeadStatusData> dataList = new ArrayList<>();
|
| - |
|
293 |
dataList.add(data);
|
| - |
|
294 |
|
| - |
|
295 |
DataLeadModel datasets = new DataLeadModel();
|
| - |
|
296 |
datasets.setDatasets(dataList);
|
| - |
|
297 |
datasets.setLabels(labels);
|
| - |
|
298 |
|
| - |
|
299 |
OptionModel om = new OptionModel();
|
| - |
|
300 |
om.setLegend(legend);
|
| - |
|
301 |
|
| - |
|
302 |
cm.setType("pie");
|
| - |
|
303 |
cm.setData(datasets);
|
| - |
|
304 |
cm.setOptions(om);
|
| - |
|
305 |
|
| - |
|
306 |
return cm;
|
| - |
|
307 |
}
|
| - |
|
308 |
|
| 132 |
@RequestMapping(value = "/getClosedLead", method = RequestMethod.GET)
|
309 |
@RequestMapping(value = "/getClosedLead", method = RequestMethod.GET)
|
| 133 |
public String getClosedLead(HttpServletRequest request,
|
310 |
public String getClosedLead(HttpServletRequest request,
|
| 134 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
311 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 135 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
312 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 136 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
313 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|