| 25979 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 29426 |
manish |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.InputStream;
|
| 29266 |
manish |
5 |
import java.time.LocalDate;
|
| 25979 |
tejbeer |
6 |
import java.time.LocalDateTime;
|
|
|
7 |
import java.util.ArrayList;
|
| 25988 |
tejbeer |
8 |
import java.util.Arrays;
|
| 27604 |
tejbeer |
9 |
import java.util.HashMap;
|
| 29266 |
manish |
10 |
import java.util.HashSet;
|
| 25979 |
tejbeer |
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
|
|
13 |
import java.util.stream.Collectors;
|
|
|
14 |
|
|
|
15 |
import javax.servlet.http.HttpServletRequest;
|
| 29426 |
manish |
16 |
import javax.servlet.http.HttpServletResponse;
|
| 25979 |
tejbeer |
17 |
import javax.transaction.Transactional;
|
|
|
18 |
|
| 29598 |
tejbeer |
19 |
import org.apache.commons.csv.CSVRecord;
|
| 25979 |
tejbeer |
20 |
import org.apache.logging.log4j.LogManager;
|
|
|
21 |
import org.apache.logging.log4j.Logger;
|
|
|
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 29426 |
manish |
23 |
import org.springframework.core.io.InputStreamResource;
|
|
|
24 |
import org.springframework.http.HttpHeaders;
|
|
|
25 |
import org.springframework.http.HttpStatus;
|
|
|
26 |
import org.springframework.http.ResponseEntity;
|
| 25979 |
tejbeer |
27 |
import org.springframework.stereotype.Controller;
|
|
|
28 |
import org.springframework.ui.Model;
|
|
|
29 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
30 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
31 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 29426 |
manish |
33 |
import org.springframework.web.bind.annotation.RequestPart;
|
|
|
34 |
import org.springframework.web.multipart.MultipartFile;
|
| 25979 |
tejbeer |
35 |
|
| 29266 |
manish |
36 |
import com.google.gson.Gson;
|
| 25988 |
tejbeer |
37 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 29266 |
manish |
38 |
import com.spice.profitmandi.common.model.Legend;
|
|
|
39 |
import com.spice.profitmandi.common.model.OptionModel;
|
|
|
40 |
import com.spice.profitmandi.common.model.PieLables;
|
| 29278 |
manish |
41 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 29426 |
manish |
42 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 25979 |
tejbeer |
43 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 29744 |
tejbeer |
44 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 25979 |
tejbeer |
45 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
|
|
46 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
| 29598 |
tejbeer |
47 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
|
| 25979 |
tejbeer |
48 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| 29266 |
manish |
49 |
import com.spice.profitmandi.dao.model.ChartLeadModel;
|
| 27605 |
tejbeer |
50 |
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
|
| 25979 |
tejbeer |
51 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
| 29266 |
manish |
52 |
import com.spice.profitmandi.dao.model.DataLeadModel;
|
|
|
53 |
import com.spice.profitmandi.dao.model.LeadStatusData;
|
| 25979 |
tejbeer |
54 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 29266 |
manish |
55 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 25979 |
tejbeer |
56 |
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
|
|
|
57 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
|
|
58 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 29266 |
manish |
59 |
import com.spice.profitmandi.service.AuthService;
|
| 25979 |
tejbeer |
60 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
61 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
62 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
63 |
|
|
|
64 |
@Controller
|
|
|
65 |
@Transactional(rollbackOn = Throwable.class)
|
|
|
66 |
public class LeadController {
|
|
|
67 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
|
|
68 |
|
|
|
69 |
@Autowired
|
|
|
70 |
private LeadRepository leadRepository;
|
|
|
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
private LeadActivityRepository leadActivityRepository;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private StateRepository stateRepository;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
| 29266 |
manish |
79 |
private AuthService authService;
|
|
|
80 |
|
|
|
81 |
@Autowired
|
| 25979 |
tejbeer |
82 |
private AuthRepository authRepository;
|
|
|
83 |
|
|
|
84 |
@Autowired
|
| 29266 |
manish |
85 |
private Gson gson;
|
|
|
86 |
|
|
|
87 |
@Autowired
|
| 25979 |
tejbeer |
88 |
private CookiesProcessor cookiesProcessor;
|
| 29426 |
manish |
89 |
|
| 29278 |
manish |
90 |
@Autowired
|
|
|
91 |
PositionRepository positionRepository;
|
| 25979 |
tejbeer |
92 |
|
|
|
93 |
@Autowired
|
|
|
94 |
private MVCResponseSender mvcResponseSender;
|
|
|
95 |
|
| 25988 |
tejbeer |
96 |
List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
|
|
|
97 |
|
| 25979 |
tejbeer |
98 |
@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
|
| 27609 |
tejbeer |
99 |
public String getOpenLead(HttpServletRequest request,
|
| 29426 |
manish |
100 |
@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,
|
| 29744 |
tejbeer |
101 |
@RequestParam(name = "color", required = false, defaultValue = "All") List<String> color,
|
| 29445 |
manish |
102 |
@RequestParam(name = "leadDate", required = false, defaultValue = "") LocalDate leadDate, Model model)
|
| 27642 |
tejbeer |
103 |
throws Exception {
|
| 27609 |
tejbeer |
104 |
|
| 29445 |
manish |
105 |
LocalDateTime localDateTime = null;
|
|
|
106 |
if (leadDate != null) {
|
|
|
107 |
localDateTime = leadDate.atStartOfDay();
|
|
|
108 |
}
|
|
|
109 |
LOGGER.info("localDateTime" + localDateTime);
|
|
|
110 |
|
| 29266 |
manish |
111 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
112 |
String emailId = loginDetails.getEmailId();
|
|
|
113 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailId);
|
| 29426 |
manish |
114 |
|
|
|
115 |
boolean authPositon = positionRepository.hasCategory(authUser.getId(),
|
|
|
116 |
ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
117 |
|
| 27610 |
tejbeer |
118 |
if (leadStatus.contains(LeadStatus.All)) {
|
|
|
119 |
|
| 29445 |
manish |
120 |
leadStatus.add(LeadStatus.pending);
|
|
|
121 |
leadStatus.add(LeadStatus.notInterested);
|
|
|
122 |
leadStatus.add(LeadStatus.finalized);
|
| 27610 |
tejbeer |
123 |
}
|
| 27615 |
tejbeer |
124 |
|
| 29744 |
tejbeer |
125 |
if (color.contains("All")) {
|
|
|
126 |
color.add("yellow");
|
|
|
127 |
color.add("green");
|
|
|
128 |
}
|
|
|
129 |
|
| 29852 |
tejbeer |
130 |
List<Lead> leads = new ArrayList<>();
|
| 29445 |
manish |
131 |
|
|
|
132 |
model.addAttribute("colors", color);
|
|
|
133 |
|
| 29744 |
tejbeer |
134 |
Map<Integer, List<LeadActivity>> leadActivityMap = new HashMap<>();
|
|
|
135 |
|
| 29287 |
amit.gupta |
136 |
List<Integer> authUserIds = null;
|
| 29445 |
manish |
137 |
|
| 29744 |
tejbeer |
138 |
LOGGER.info("color111" + color);
|
| 29445 |
manish |
139 |
|
| 29744 |
tejbeer |
140 |
List<Lead> leadFollowUp = new ArrayList<>();
|
| 29426 |
manish |
141 |
|
| 29744 |
tejbeer |
142 |
if (authPositon) {
|
|
|
143 |
authUserIds = authService.getAllReportees(authUser.getId());
|
|
|
144 |
authUserIds.add(authUser.getId());
|
|
|
145 |
LOGGER.info("authIds" + authUserIds);
|
| 29426 |
manish |
146 |
|
| 29753 |
tejbeer |
147 |
LOGGER.info("leadStatus" + leadStatus);
|
|
|
148 |
|
| 29744 |
tejbeer |
149 |
if (localDateTime == null) {
|
| 29445 |
manish |
150 |
|
| 29852 |
tejbeer |
151 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
152 |
|
| 29852 |
tejbeer |
153 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,
|
|
|
154 |
color, LocalDateTime.now().minusMonths(1));
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
158 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
|
|
159 |
leads.addAll(leadFollowUp);
|
|
|
160 |
}
|
|
|
161 |
|
| 29744 |
tejbeer |
162 |
} else {
|
| 29445 |
manish |
163 |
|
| 29852 |
tejbeer |
164 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
|
|
165 |
|
|
|
166 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,
|
|
|
167 |
color, localDateTime);
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
171 |
|
|
|
172 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
|
|
173 |
leads.addAll(leadFollowUp);
|
|
|
174 |
|
|
|
175 |
}
|
|
|
176 |
|
| 29744 |
tejbeer |
177 |
}
|
| 29445 |
manish |
178 |
|
| 29744 |
tejbeer |
179 |
} else {
|
| 29445 |
manish |
180 |
|
| 29744 |
tejbeer |
181 |
if (localDateTime == null) {
|
| 29852 |
tejbeer |
182 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
183 |
|
| 29852 |
tejbeer |
184 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color,
|
|
|
185 |
LocalDateTime.now().minusMonths(1));
|
|
|
186 |
}
|
|
|
187 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
188 |
|
|
|
189 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
|
|
190 |
leads.addAll(leadFollowUp);
|
|
|
191 |
}
|
| 29744 |
tejbeer |
192 |
LOGGER.info("leadlocalDateTime1" + leads);
|
| 29445 |
manish |
193 |
|
| 29744 |
tejbeer |
194 |
} else {
|
| 29852 |
tejbeer |
195 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
196 |
|
| 29852 |
tejbeer |
197 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color, localDateTime);
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
201 |
|
|
|
202 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
|
|
203 |
leads.addAll(leadFollowUp);
|
|
|
204 |
}
|
| 29744 |
tejbeer |
205 |
LOGGER.info("leadlocalDateTime2" + leads);
|
| 29445 |
manish |
206 |
|
| 29278 |
manish |
207 |
}
|
| 29426 |
manish |
208 |
|
| 29445 |
manish |
209 |
}
|
|
|
210 |
|
| 29426 |
manish |
211 |
if (authPositon && authUserIds.size() > 0) {
|
| 29287 |
amit.gupta |
212 |
List<String> leadCreators = new ArrayList<>();
|
|
|
213 |
leadCreators.add("daily-sync");
|
| 29426 |
manish |
214 |
leadCreators.addAll(authRepository.selectAllAuthUserByIds(authUserIds).stream().map(x -> x.getFullName())
|
|
|
215 |
.collect(Collectors.toList()));
|
| 29289 |
amit.gupta |
216 |
model.addAttribute("leadCreators", leadCreators);
|
| 29287 |
amit.gupta |
217 |
}
|
| 29266 |
manish |
218 |
List<Lead> weekLast = new ArrayList<>();
|
|
|
219 |
List<Lead> weekThird = new ArrayList<>();
|
|
|
220 |
List<Lead> weekSecond = new ArrayList<>();
|
|
|
221 |
List<Lead> weekFirst = new ArrayList<>();
|
|
|
222 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
223 |
List<LeadWeakWiseModel> lwDays = new ArrayList<>();
|
| 27642 |
tejbeer |
224 |
|
| 29266 |
manish |
225 |
for (int i = 7; i >= 1; i--) {
|
|
|
226 |
LocalDateTime startOfDay = curDate.minusDays(i);
|
|
|
227 |
|
|
|
228 |
LeadWeakWiseModel lm = new LeadWeakWiseModel();
|
|
|
229 |
lm.setMonth(startOfDay.toLocalDate());
|
|
|
230 |
lwDays.add(lm);
|
|
|
231 |
}
|
| 29426 |
manish |
232 |
if (!leads.isEmpty()) {
|
| 29266 |
manish |
233 |
|
| 29744 |
tejbeer |
234 |
weekLast.addAll(
|
|
|
235 |
leads.stream()
|
|
|
236 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(28))
|
|
|
237 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(21)))
|
|
|
238 |
.collect(Collectors.toList()));
|
| 29266 |
manish |
239 |
|
| 29744 |
tejbeer |
240 |
weekThird
|
|
|
241 |
.addAll(leads.stream()
|
|
|
242 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(21))
|
|
|
243 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(14)))
|
|
|
244 |
.collect(Collectors.toList()));
|
| 29266 |
manish |
245 |
|
| 29744 |
tejbeer |
246 |
weekSecond
|
|
|
247 |
.addAll(leads.stream()
|
|
|
248 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(14))
|
|
|
249 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(7)))
|
|
|
250 |
.collect(Collectors.toList()));
|
| 29426 |
manish |
251 |
|
| 29744 |
tejbeer |
252 |
weekFirst.addAll(leads.stream().filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(7)))
|
|
|
253 |
.collect(Collectors.toList()));
|
|
|
254 |
|
| 29266 |
manish |
255 |
}
|
|
|
256 |
LOGGER.info("weekLast" + weekLast);
|
|
|
257 |
LOGGER.info("weekThird" + weekThird);
|
|
|
258 |
LOGGER.info("weekSecond" + weekSecond);
|
| 29426 |
manish |
259 |
Map<String, Long> leadLasts = weekLast.stream()
|
|
|
260 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));
|
|
|
261 |
Map<String, Long> leadThirds = weekThird.stream()
|
|
|
262 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));
|
| 29266 |
manish |
263 |
Map<String, Long> leadSeconds = weekSecond.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
|
|
264 |
Collectors.mapping(Lead::getCreatedBy, Collectors.counting())));
|
|
|
265 |
|
|
|
266 |
Map<String, Map<LocalDate, Long>> leadFirsts = weekFirst.stream()
|
|
|
267 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
|
|
268 |
Collectors.groupingBy(x -> x.getCreatedTimestamp().toLocalDate(), Collectors.counting())));
|
|
|
269 |
|
|
|
270 |
LOGGER.info("leadFirsts" + leadFirsts);
|
|
|
271 |
|
| 27723 |
tejbeer |
272 |
List<Integer> authIds = new ArrayList<>();
|
|
|
273 |
if (!leads.isEmpty()) {
|
| 25979 |
tejbeer |
274 |
|
| 27723 |
tejbeer |
275 |
authIds.addAll(leads.stream().map(x -> x.getAssignTo()).collect(Collectors.toList()));
|
| 27610 |
tejbeer |
276 |
|
| 29744 |
tejbeer |
277 |
leadActivityMap = leadActivityRepository
|
|
|
278 |
.selectAllByleadIds(leads.stream().map(x -> x.getId()).collect(Collectors.toList())).stream()
|
|
|
279 |
.collect(Collectors.groupingBy(LeadActivity::getLeadId, Collectors.toList()));
|
|
|
280 |
|
| 27723 |
tejbeer |
281 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
282 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
283 |
model.addAttribute("leadActivityMap", leadActivityMap);
|
|
|
284 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
285 |
}
|
|
|
286 |
|
| 29266 |
manish |
287 |
ChartLeadModel cm = this.getLeadChart(leads);
|
|
|
288 |
model.addAttribute("chartLead", gson.toJson(cm));
|
|
|
289 |
|
|
|
290 |
LOGGER.info("ChartLeadModel" + gson.toJson(cm));
|
|
|
291 |
LOGGER.info("lwDays" + lwDays);
|
|
|
292 |
|
| 27610 |
tejbeer |
293 |
LOGGER.info("leads" + leads);
|
| 25979 |
tejbeer |
294 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
|
|
295 |
.collect(Collectors.toList());
|
|
|
296 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 29266 |
manish |
297 |
LocalDate lastDate = curDate.minusDays(1).toLocalDate();
|
| 29426 |
manish |
298 |
|
| 29266 |
manish |
299 |
List<LocalDate> weekDates = new ArrayList<>();
|
| 29426 |
manish |
300 |
|
| 29266 |
manish |
301 |
weekDates.add(curDate.minusDays(28).toLocalDate());
|
|
|
302 |
weekDates.add(curDate.minusDays(22).toLocalDate());
|
|
|
303 |
weekDates.add(curDate.minusDays(21).toLocalDate());
|
|
|
304 |
weekDates.add(curDate.minusDays(15).toLocalDate());
|
|
|
305 |
weekDates.add(curDate.minusDays(14).toLocalDate());
|
|
|
306 |
weekDates.add(curDate.minusDays(8).toLocalDate());
|
|
|
307 |
weekDates.add(curDate.minusDays(7).toLocalDate());
|
|
|
308 |
LOGGER.info("lastDate" + lastDate);
|
| 29426 |
manish |
309 |
|
| 29266 |
manish |
310 |
model.addAttribute("weekDates", weekDates);
|
| 29426 |
manish |
311 |
|
| 29445 |
manish |
312 |
model.addAttribute("leadDate", leadDate);
|
| 29266 |
manish |
313 |
model.addAttribute("lastDate", lastDate);
|
| 25979 |
tejbeer |
314 |
model.addAttribute("stateNames", stateNames);
|
|
|
315 |
model.addAttribute("authUsers", authUsers);
|
| 27610 |
tejbeer |
316 |
model.addAttribute("lead", leads);
|
|
|
317 |
model.addAttribute("leadStatus", LeadStatus.values());
|
| 29266 |
manish |
318 |
model.addAttribute("leadLasts", leadLasts);
|
|
|
319 |
model.addAttribute("leadThirds", leadThirds);
|
|
|
320 |
model.addAttribute("leadSeconds", leadSeconds);
|
|
|
321 |
model.addAttribute("leadFirsts", leadFirsts);
|
|
|
322 |
model.addAttribute("lwDays", lwDays);
|
| 25979 |
tejbeer |
323 |
|
| 27610 |
tejbeer |
324 |
model.addAttribute("selectedLeadStatus", leadStatus.get(0));
|
| 25979 |
tejbeer |
325 |
return "lead";
|
| 27642 |
tejbeer |
326 |
|
| 25979 |
tejbeer |
327 |
}
|
|
|
328 |
|
| 29266 |
manish |
329 |
public ChartLeadModel getLeadChart(List<Lead> leads) throws ProfitMandiBusinessException {
|
|
|
330 |
|
|
|
331 |
Map<LeadStatus, Long> leadStatusMap = leads.stream().collect(
|
|
|
332 |
Collectors.groupingBy(x -> x.getStatus(), Collectors.mapping(Lead::getStatus, Collectors.counting())));
|
|
|
333 |
|
| 29426 |
manish |
334 |
Map<String, Long> hotLeadsMap = leads.stream().collect(
|
|
|
335 |
Collectors.groupingBy(x -> x.getColor(), Collectors.mapping(Lead::getColor, Collectors.counting())));
|
|
|
336 |
|
|
|
337 |
LOGGER.info("hotLeadsMap" + hotLeadsMap);
|
| 29266 |
manish |
338 |
ChartLeadModel cm = new ChartLeadModel();
|
|
|
339 |
|
|
|
340 |
HashSet<LeadStatus> labels = new HashSet<LeadStatus>();
|
|
|
341 |
labels.addAll(leadStatusMap.keySet());
|
| 29445 |
manish |
342 |
|
| 29426 |
manish |
343 |
HashSet<String> hotLeads = new HashSet<String>();
|
|
|
344 |
hotLeads.addAll(leadStatusMap.keySet().stream().map(x -> x.toString()).collect(Collectors.toSet()));
|
|
|
345 |
hotLeads.add("HotLead");
|
| 29445 |
manish |
346 |
|
| 29426 |
manish |
347 |
HashSet<String> hotLeadKeys = new HashSet<String>();
|
| 29445 |
manish |
348 |
|
| 29426 |
manish |
349 |
hotLeadKeys.add("HotLead");
|
|
|
350 |
List<String> hotLeadGreen = new ArrayList<>(hotLeadKeys);
|
| 29598 |
tejbeer |
351 |
|
| 29448 |
manish |
352 |
LOGGER.info("hotLeads" + hotLeads);
|
| 29445 |
manish |
353 |
|
| 29266 |
manish |
354 |
List<LeadStatus> labelList = new ArrayList<>(labels);
|
|
|
355 |
List<String> backgroundColor = new ArrayList<>();
|
| 29426 |
manish |
356 |
LOGGER.info("hotLeadKeys" + hotLeadKeys);
|
| 29266 |
manish |
357 |
List<Long> values = new ArrayList<>();
|
|
|
358 |
|
| 29448 |
manish |
359 |
for (String hotLead : hotLeads) {
|
| 29266 |
manish |
360 |
|
| 29448 |
manish |
361 |
if (hotLead.equals("pending")) {
|
| 29266 |
manish |
362 |
backgroundColor.add("pink");
|
| 29448 |
manish |
363 |
values.add(leadStatusMap.get(LeadStatus.pending));
|
| 29266 |
manish |
364 |
}
|
| 29448 |
manish |
365 |
if (hotLead.equals("notInterested")) {
|
| 29266 |
manish |
366 |
backgroundColor.add("red");
|
| 29448 |
manish |
367 |
values.add(leadStatusMap.get(LeadStatus.notInterested));
|
| 29266 |
manish |
368 |
}
|
| 29448 |
manish |
369 |
if (hotLead.equals("followUp")) {
|
| 29266 |
manish |
370 |
backgroundColor.add("#9ACD32");
|
| 29448 |
manish |
371 |
values.add(leadStatusMap.get(LeadStatus.followUp));
|
| 29266 |
manish |
372 |
}
|
| 29448 |
manish |
373 |
if (hotLead.equals("finalized")) {
|
| 29266 |
manish |
374 |
backgroundColor.add("blue");
|
| 29448 |
manish |
375 |
values.add(leadStatusMap.get(LeadStatus.finalized));
|
| 29445 |
manish |
376 |
}
|
| 29598 |
tejbeer |
377 |
|
| 29448 |
manish |
378 |
if (hotLead.equals("HotLead")) {
|
| 29426 |
manish |
379 |
backgroundColor.add("green");
|
|
|
380 |
values.add(hotLeadsMap.get("Green"));
|
| 29445 |
manish |
381 |
|
| 29266 |
manish |
382 |
}
|
| 29445 |
manish |
383 |
|
| 29266 |
manish |
384 |
}
|
|
|
385 |
LOGGER.info("labelList" + labelList);
|
|
|
386 |
|
|
|
387 |
LOGGER.info("backgroundColor" + backgroundColor);
|
|
|
388 |
LOGGER.info("labelsChartLead" + labels);
|
|
|
389 |
LeadStatusData data = new LeadStatusData();
|
|
|
390 |
data.setData(values);
|
|
|
391 |
data.setBackgroundColor(backgroundColor);
|
|
|
392 |
data.setLabel("DataSet 1");
|
|
|
393 |
|
|
|
394 |
PieLables label = new PieLables();
|
|
|
395 |
label.setFontColor("black");
|
|
|
396 |
label.setFontSize(15);
|
|
|
397 |
|
|
|
398 |
Legend legend = new Legend();
|
|
|
399 |
legend.setLabels(label);
|
|
|
400 |
legend.setPosition("left");
|
|
|
401 |
|
|
|
402 |
List<LeadStatusData> dataList = new ArrayList<>();
|
|
|
403 |
dataList.add(data);
|
|
|
404 |
|
|
|
405 |
DataLeadModel datasets = new DataLeadModel();
|
|
|
406 |
datasets.setDatasets(dataList);
|
| 29426 |
manish |
407 |
datasets.setLabels(hotLeads);
|
| 29266 |
manish |
408 |
|
|
|
409 |
OptionModel om = new OptionModel();
|
|
|
410 |
om.setLegend(legend);
|
|
|
411 |
|
|
|
412 |
cm.setType("pie");
|
|
|
413 |
cm.setData(datasets);
|
|
|
414 |
cm.setOptions(om);
|
|
|
415 |
|
|
|
416 |
return cm;
|
|
|
417 |
}
|
|
|
418 |
|
| 25988 |
tejbeer |
419 |
@RequestMapping(value = "/getClosedLead", method = RequestMethod.GET)
|
|
|
420 |
public String getClosedLead(HttpServletRequest request,
|
|
|
421 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
422 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
423 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
424 |
throws Exception {
|
|
|
425 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
426 |
List<Lead> leads = null;
|
|
|
427 |
long size = 0;
|
|
|
428 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
429 |
size = leadRepository.selectCountByStatus(status);
|
|
|
430 |
|
|
|
431 |
if (!leads.isEmpty()) {
|
|
|
432 |
List<Integer> authIds = new ArrayList<>();
|
|
|
433 |
for (Lead lead : leads) {
|
|
|
434 |
authIds.add(lead.getAssignTo());
|
|
|
435 |
}
|
|
|
436 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
437 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
438 |
|
|
|
439 |
model.addAttribute("leads", leads);
|
|
|
440 |
model.addAttribute("start", offset + 1);
|
|
|
441 |
model.addAttribute("size", size);
|
|
|
442 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
443 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
| 25990 |
tejbeer |
444 |
model.addAttribute("url", "/getPaginatedClosedLeads");
|
| 25988 |
tejbeer |
445 |
|
|
|
446 |
if (leads.size() < limit) {
|
|
|
447 |
model.addAttribute("end", offset + leads.size());
|
|
|
448 |
} else {
|
|
|
449 |
model.addAttribute("end", offset + limit);
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
} else {
|
|
|
453 |
model.addAttribute("lead", leads);
|
|
|
454 |
|
|
|
455 |
model.addAttribute("size", size);
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
model.addAttribute("authUsers", authUsers);
|
|
|
459 |
return "lead-close";
|
|
|
460 |
}
|
|
|
461 |
|
|
|
462 |
@RequestMapping(value = "/getPaginatedClosedLeads", method = RequestMethod.GET)
|
| 25990 |
tejbeer |
463 |
public String getPaginatedClosedLeads(HttpServletRequest request,
|
| 25988 |
tejbeer |
464 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
465 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
466 |
throws ProfitMandiBusinessException {
|
|
|
467 |
List<Lead> leads = null;
|
|
|
468 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
469 |
|
|
|
470 |
if (!leads.isEmpty()) {
|
|
|
471 |
List<Integer> authIds = new ArrayList<>();
|
|
|
472 |
for (Lead lead : leads) {
|
|
|
473 |
authIds.add(lead.getAssignTo());
|
|
|
474 |
}
|
|
|
475 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
476 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
477 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
478 |
model.addAttribute("leads", leads);
|
| 25990 |
tejbeer |
479 |
model.addAttribute("url", "/getPaginatedClosedLeads");
|
| 25988 |
tejbeer |
480 |
|
|
|
481 |
} else {
|
|
|
482 |
model.addAttribute("leads", leads);
|
|
|
483 |
|
|
|
484 |
}
|
|
|
485 |
return "lead-close-paginated";
|
|
|
486 |
}
|
|
|
487 |
|
|
|
488 |
@RequestMapping(value = "/searchLeads")
|
|
|
489 |
public String getClosedLeads(HttpServletRequest request,
|
|
|
490 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
491 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
492 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
493 |
throws ProfitMandiBusinessException {
|
|
|
494 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
495 |
List<Lead> leads = null;
|
|
|
496 |
long size = 0;
|
|
|
497 |
if (!(searchTerm.equals(""))) {
|
|
|
498 |
leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);
|
|
|
499 |
if (!(leads.size() == 0)) {
|
|
|
500 |
size = leadRepository.selectCountByStatus(status);
|
|
|
501 |
List<Integer> authIds = new ArrayList<>();
|
|
|
502 |
for (Lead lead : leads) {
|
|
|
503 |
authIds.add(lead.getAssignTo());
|
|
|
504 |
}
|
|
|
505 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
506 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
507 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
508 |
model.addAttribute("leads", leads);
|
|
|
509 |
model.addAttribute("start", offset + 1);
|
|
|
510 |
model.addAttribute("size", size);
|
|
|
511 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
512 |
|
|
|
513 |
if (leads.size() < limit) {
|
|
|
514 |
model.addAttribute("end", offset + leads.size());
|
|
|
515 |
} else {
|
|
|
516 |
model.addAttribute("end", offset + limit);
|
|
|
517 |
}
|
|
|
518 |
} else {
|
|
|
519 |
throw new ProfitMandiBusinessException("lead", searchTerm, "leads Not Found");
|
|
|
520 |
}
|
|
|
521 |
} else {
|
|
|
522 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
523 |
size = leadRepository.selectCountByStatus(status);
|
|
|
524 |
|
|
|
525 |
if (!leads.isEmpty()) {
|
|
|
526 |
List<Integer> authIds = new ArrayList<>();
|
|
|
527 |
for (Lead lead : leads) {
|
|
|
528 |
authIds.add(lead.getAssignTo());
|
|
|
529 |
}
|
|
|
530 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
531 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
532 |
|
|
|
533 |
model.addAttribute("leads", leads);
|
|
|
534 |
model.addAttribute("start", offset + 1);
|
|
|
535 |
model.addAttribute("size", size);
|
|
|
536 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
537 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
538 |
|
|
|
539 |
if (leads.size() < limit) {
|
|
|
540 |
model.addAttribute("end", offset + leads.size());
|
|
|
541 |
} else {
|
|
|
542 |
model.addAttribute("end", offset + limit);
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
}
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
model.addAttribute("authUsers", authUsers);
|
|
|
549 |
return "lead-close";
|
|
|
550 |
}
|
|
|
551 |
|
|
|
552 |
@RequestMapping(value = "/searchLeadPaginated")
|
| 25990 |
tejbeer |
553 |
public String searchLeadPaginated(HttpServletRequest request,
|
| 25988 |
tejbeer |
554 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
555 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
556 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
557 |
throws ProfitMandiBusinessException {
|
|
|
558 |
LOGGER.info("In search Item....");
|
|
|
559 |
List<Lead> leads = null;
|
|
|
560 |
if (!searchTerm.equals("")) {
|
|
|
561 |
leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);
|
|
|
562 |
if (!(leads.size() == 0)) {
|
|
|
563 |
|
|
|
564 |
List<Integer> authIds = new ArrayList<>();
|
|
|
565 |
for (Lead lead : leads) {
|
|
|
566 |
authIds.add(lead.getAssignTo());
|
|
|
567 |
}
|
|
|
568 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
569 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
570 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
571 |
model.addAttribute("leads", leads);
|
|
|
572 |
}
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
return "lead-close-paginated";
|
|
|
576 |
|
|
|
577 |
}
|
|
|
578 |
|
| 25979 |
tejbeer |
579 |
@RequestMapping(value = "/getLeadActivity", method = RequestMethod.GET)
|
|
|
580 |
public String getLeadActivity(HttpServletRequest request, @RequestParam int leadId, Model model) throws Exception {
|
|
|
581 |
List<LeadActivity> leadActivity = leadActivityRepository.selectBYLeadId(leadId);
|
|
|
582 |
model.addAttribute("leadActivity", leadActivity);
|
|
|
583 |
return "lead_activity_modal";
|
|
|
584 |
}
|
|
|
585 |
|
|
|
586 |
@RequestMapping(value = "/createLead", method = RequestMethod.POST)
|
|
|
587 |
public String CreateLead(HttpServletRequest request, @RequestBody CreateRefferalRequest createRefferalRequest,
|
|
|
588 |
Model model) throws Exception {
|
|
|
589 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
590 |
LOGGER.info("createRefferalRequest" + createRefferalRequest.getSchelduleTimestamp());
|
|
|
591 |
Lead lead = new Lead();
|
|
|
592 |
lead.setFirstName(createRefferalRequest.getFirstName());
|
|
|
593 |
lead.setLastName(createRefferalRequest.getLastName());
|
|
|
594 |
lead.setLeadMobile(createRefferalRequest.getMobile());
|
|
|
595 |
lead.setState(createRefferalRequest.getState());
|
|
|
596 |
lead.setCity(createRefferalRequest.getCity());
|
|
|
597 |
lead.setAddress(createRefferalRequest.getAddress());
|
|
|
598 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
599 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
600 |
lead.setStatus(createRefferalRequest.getStatus());
|
|
|
601 |
lead.setAssignTo(createRefferalRequest.getAssignTo());
|
|
|
602 |
lead.setSource(createRefferalRequest.getSource());
|
| 26298 |
tejbeer |
603 |
lead.setColor("yellow");
|
| 25979 |
tejbeer |
604 |
// change
|
| 25989 |
tejbeer |
605 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 25979 |
tejbeer |
606 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
607 |
lead.setCreatedBy(authUserName);
|
|
|
608 |
lead.setAuthId(authUser.getId());
|
|
|
609 |
|
|
|
610 |
leadRepository.persist(lead);
|
|
|
611 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
612 |
leadActivity.setLeadId(lead.getId());
|
|
|
613 |
leadActivity.setRemark(createRefferalRequest.getRemark());
|
|
|
614 |
|
|
|
615 |
if (createRefferalRequest.getStatus() == LeadStatus.followUp) {
|
|
|
616 |
leadActivity.setSchelduleTimestamp(createRefferalRequest.getSchelduleTimestamp());
|
|
|
617 |
} else {
|
|
|
618 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
619 |
}
|
|
|
620 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
621 |
leadActivityRepository.persist(leadActivity);
|
|
|
622 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
623 |
return "response";
|
|
|
624 |
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
@RequestMapping(value = "/editLead", method = RequestMethod.POST)
|
| 27605 |
tejbeer |
628 |
public String EditLead(HttpServletRequest request,
|
|
|
629 |
@RequestBody CreateLeacdActivityRequest createLeadActivityRequest, Model model) throws Exception {
|
| 25979 |
tejbeer |
630 |
|
|
|
631 |
LeadActivity leadActivity = new LeadActivity();
|
| 27605 |
tejbeer |
632 |
leadActivity.setLeadId(createLeadActivityRequest.getId());
|
|
|
633 |
leadActivity.setRemark(createLeadActivityRequest.getRemark());
|
| 29598 |
tejbeer |
634 |
|
| 29476 |
manish |
635 |
LOGGER.info("createRefferalRequest" + createLeadActivityRequest);
|
| 27605 |
tejbeer |
636 |
|
|
|
637 |
if (createLeadActivityRequest.getStatus() == LeadStatus.followUp) {
|
|
|
638 |
leadActivity.setSchelduleTimestamp(createLeadActivityRequest.getScheldule());
|
|
|
639 |
} else {
|
|
|
640 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
641 |
}
|
| 25979 |
tejbeer |
642 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
643 |
leadActivityRepository.persist(leadActivity);
|
| 29598 |
tejbeer |
644 |
Lead lead = leadRepository.selectById(createLeadActivityRequest.getId());
|
| 27605 |
tejbeer |
645 |
lead.setAssignTo(createLeadActivityRequest.getAssignTo());
|
|
|
646 |
lead.setStatus(createLeadActivityRequest.getStatus());
|
| 28200 |
tejbeer |
647 |
lead.setNotinterestedReason(createLeadActivityRequest.getReason());
|
| 25979 |
tejbeer |
648 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
649 |
|
| 29473 |
manish |
650 |
lead = leadRepository.selectById(createLeadActivityRequest.getId());
|
| 29598 |
tejbeer |
651 |
|
| 29476 |
manish |
652 |
int authId = 0;
|
|
|
653 |
if (lead != null) {
|
| 25979 |
tejbeer |
654 |
|
| 29476 |
manish |
655 |
authId = lead.getAssignTo();
|
|
|
656 |
Map<Integer, LeadActivity> leadActivityMap = new HashMap<>();
|
| 29598 |
tejbeer |
657 |
|
|
|
658 |
List<LeadActivity> leadActivitys = leadActivityRepository.selectBYLeadId(lead.getId());
|
|
|
659 |
|
|
|
660 |
if (!leadActivitys.isEmpty()) {
|
|
|
661 |
leadActivityMap.put(lead.getId(), leadActivitys.get(0));
|
|
|
662 |
}
|
|
|
663 |
|
|
|
664 |
Map<Integer, AuthUser> authIdAndAuthUserMap = new HashMap<>();
|
|
|
665 |
AuthUser AuthUser = authRepository.selectById(authId);
|
|
|
666 |
|
|
|
667 |
authIdAndAuthUserMap.put(AuthUser.getId(), AuthUser);
|
|
|
668 |
|
| 29476 |
manish |
669 |
model.addAttribute("leadActivityMap", leadActivityMap);
|
|
|
670 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
671 |
}
|
|
|
672 |
|
| 29473 |
manish |
673 |
model.addAttribute("request", lead);
|
|
|
674 |
|
|
|
675 |
return "edit-lead";
|
|
|
676 |
|
| 25979 |
tejbeer |
677 |
}
|
| 29445 |
manish |
678 |
|
| 29426 |
manish |
679 |
@RequestMapping(value = "/downloadIvoryLead", method = RequestMethod.GET)
|
|
|
680 |
public ResponseEntity<?> downloadDelayDayTemplate(HttpServletRequest request) throws Exception {
|
| 29598 |
tejbeer |
681 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
|
|
682 |
.collect(Collectors.toList());
|
|
|
683 |
|
| 29426 |
manish |
684 |
List<List<?>> rows = new ArrayList<>();
|
|
|
685 |
|
| 29598 |
tejbeer |
686 |
List<LeadSource> lss = LeadSource.enumValues;
|
| 29426 |
manish |
687 |
|
| 29598 |
tejbeer |
688 |
for (LeadSource ls : lss) {
|
|
|
689 |
rows.add(Arrays.asList("-", "-", "-", "-", "-", "-", "-", ls));
|
|
|
690 |
|
|
|
691 |
}
|
|
|
692 |
for (String stateName : stateNames) {
|
|
|
693 |
rows.add(Arrays.asList("-", "-", "-", "-", stateName, "-", "-", "-"));
|
|
|
694 |
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("First Name",
|
|
|
698 |
"Last Name", "Address", "City", "State", "Mobile", "Assign To(email)", "Source"), rows);
|
|
|
699 |
|
| 29426 |
manish |
700 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
701 |
headers.set("Content-Type", "text/csv");
|
| 29598 |
tejbeer |
702 |
headers.set("Content-disposition", "inline; filename=leads.format.csv");
|
| 29426 |
manish |
703 |
headers.setContentLength(baos.toByteArray().length);
|
|
|
704 |
|
|
|
705 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
706 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
707 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
708 |
|
|
|
709 |
}
|
| 29445 |
manish |
710 |
|
| 29426 |
manish |
711 |
@RequestMapping(value = "/csvFileAndSetLead", method = RequestMethod.POST)
|
|
|
712 |
public String readCsvFileAndSetLead(HttpServletRequest request, Model model, HttpServletResponse response,
|
|
|
713 |
@RequestPart MultipartFile file) throws Throwable {
|
|
|
714 |
|
| 29598 |
tejbeer |
715 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
716 |
String email = loginDetails.getEmailId();
|
|
|
717 |
|
|
|
718 |
AuthUser createdBy = authRepository.selectByEmailOrMobile(email);
|
|
|
719 |
|
| 29426 |
manish |
720 |
LOGGER.info("file" + file.toString());
|
|
|
721 |
|
|
|
722 |
String fileName = file.getName();
|
|
|
723 |
|
|
|
724 |
String fileNames = file.getOriginalFilename();
|
|
|
725 |
|
|
|
726 |
LOGGER.info("fileName" + fileName);
|
|
|
727 |
LOGGER.info("fileNames" + fileNames);
|
|
|
728 |
|
| 29598 |
tejbeer |
729 |
List<CSVRecord> records = FileUtil.readFile(file);
|
| 29426 |
manish |
730 |
|
| 29598 |
tejbeer |
731 |
for (CSVRecord record : records) {
|
| 29426 |
manish |
732 |
|
|
|
733 |
Lead lead = new Lead();
|
| 29598 |
tejbeer |
734 |
lead.setFirstName(record.get(0));
|
|
|
735 |
lead.setLastName(record.get(1));
|
|
|
736 |
lead.setAddress(record.get(2));
|
|
|
737 |
lead.setCity(record.get(3));
|
|
|
738 |
lead.setState(record.get(4));
|
|
|
739 |
lead.setLeadMobile(record.get(5));
|
|
|
740 |
LOGGER.info("record" + record.get(6));
|
| 29426 |
manish |
741 |
|
| 29598 |
tejbeer |
742 |
AuthUser assignTo = authRepository.selectByEmailOrMobile(record.get(6));
|
| 29426 |
manish |
743 |
|
| 29598 |
tejbeer |
744 |
if (assignTo == null) {
|
|
|
745 |
throw new ProfitMandiBusinessException("Assign To ", record.get(6), "email id not exist");
|
|
|
746 |
}
|
| 29445 |
manish |
747 |
|
| 29598 |
tejbeer |
748 |
lead.setAssignTo(assignTo.getId());
|
|
|
749 |
lead.setSource(record.get(7));
|
|
|
750 |
|
|
|
751 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
752 |
|
| 29426 |
manish |
753 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
754 |
lead.setStatus(LeadStatus.pending);
|
|
|
755 |
lead.setColor("yellow");
|
|
|
756 |
// change
|
| 29598 |
tejbeer |
757 |
lead.setCreatedBy(createdBy.getFullName());
|
|
|
758 |
lead.setAuthId(createdBy.getId());
|
| 29426 |
manish |
759 |
|
|
|
760 |
leadRepository.persist(lead);
|
|
|
761 |
|
|
|
762 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
763 |
leadActivity.setLeadId(lead.getId());
|
| 29598 |
tejbeer |
764 |
leadActivity.setRemark("New Lead");
|
| 29426 |
manish |
765 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
766 |
|
|
|
767 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
768 |
leadActivityRepository.persist(leadActivity);
|
|
|
769 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
770 |
|
|
|
771 |
}
|
|
|
772 |
|
|
|
773 |
model.addAttribute("responseSTG", mvcResponseSender.createResponseString(true));
|
|
|
774 |
|
|
|
775 |
return "response";
|
|
|
776 |
|
|
|
777 |
}
|
|
|
778 |
|
| 25979 |
tejbeer |
779 |
}
|