| 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;
|
| 30416 |
tejbeer |
13 |
import java.util.Set;
|
|
|
14 |
import java.util.TreeMap;
|
| 25979 |
tejbeer |
15 |
import java.util.stream.Collectors;
|
|
|
16 |
|
|
|
17 |
import javax.servlet.http.HttpServletRequest;
|
| 29426 |
manish |
18 |
import javax.servlet.http.HttpServletResponse;
|
| 25979 |
tejbeer |
19 |
import javax.transaction.Transactional;
|
|
|
20 |
|
| 30434 |
tejbeer |
21 |
import org.apache.commons.collections.map.HashedMap;
|
| 29598 |
tejbeer |
22 |
import org.apache.commons.csv.CSVRecord;
|
| 25979 |
tejbeer |
23 |
import org.apache.logging.log4j.LogManager;
|
|
|
24 |
import org.apache.logging.log4j.Logger;
|
|
|
25 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 29426 |
manish |
26 |
import org.springframework.core.io.InputStreamResource;
|
|
|
27 |
import org.springframework.http.HttpHeaders;
|
|
|
28 |
import org.springframework.http.HttpStatus;
|
|
|
29 |
import org.springframework.http.ResponseEntity;
|
| 25979 |
tejbeer |
30 |
import org.springframework.stereotype.Controller;
|
|
|
31 |
import org.springframework.ui.Model;
|
| 30416 |
tejbeer |
32 |
import org.springframework.util.StringUtils;
|
| 25979 |
tejbeer |
33 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
34 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
35 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
36 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 29426 |
manish |
37 |
import org.springframework.web.bind.annotation.RequestPart;
|
|
|
38 |
import org.springframework.web.multipart.MultipartFile;
|
| 25979 |
tejbeer |
39 |
|
| 29266 |
manish |
40 |
import com.google.gson.Gson;
|
| 25988 |
tejbeer |
41 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30416 |
tejbeer |
42 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 29266 |
manish |
43 |
import com.spice.profitmandi.common.model.Legend;
|
|
|
44 |
import com.spice.profitmandi.common.model.OptionModel;
|
|
|
45 |
import com.spice.profitmandi.common.model.PieLables;
|
| 29278 |
manish |
46 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 29426 |
manish |
47 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 25979 |
tejbeer |
48 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30416 |
tejbeer |
49 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
|
|
50 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 25979 |
tejbeer |
51 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
|
|
52 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
| 30434 |
tejbeer |
53 |
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
|
| 29598 |
tejbeer |
54 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
|
| 25979 |
tejbeer |
55 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| 29266 |
manish |
56 |
import com.spice.profitmandi.dao.model.ChartLeadModel;
|
| 27605 |
tejbeer |
57 |
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
|
| 25979 |
tejbeer |
58 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
| 29266 |
manish |
59 |
import com.spice.profitmandi.dao.model.DataLeadModel;
|
|
|
60 |
import com.spice.profitmandi.dao.model.LeadStatusData;
|
| 30416 |
tejbeer |
61 |
import com.spice.profitmandi.dao.model.PartnerCollectionPlanModel;
|
| 30185 |
tejbeer |
62 |
import com.spice.profitmandi.dao.model.TeamCommitmentModel;
|
| 25979 |
tejbeer |
63 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 30185 |
tejbeer |
64 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
|
| 30434 |
tejbeer |
65 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 30416 |
tejbeer |
66 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 29266 |
manish |
67 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 30416 |
tejbeer |
68 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 25979 |
tejbeer |
69 |
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
|
|
|
70 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
| 30416 |
tejbeer |
71 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 25979 |
tejbeer |
72 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 29266 |
manish |
73 |
import com.spice.profitmandi.service.AuthService;
|
| 30416 |
tejbeer |
74 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
|
|
75 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 25979 |
tejbeer |
76 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
77 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
78 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
79 |
|
|
|
80 |
@Controller
|
|
|
81 |
@Transactional(rollbackOn = Throwable.class)
|
|
|
82 |
public class LeadController {
|
|
|
83 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
|
|
84 |
|
|
|
85 |
@Autowired
|
|
|
86 |
private LeadRepository leadRepository;
|
|
|
87 |
|
|
|
88 |
@Autowired
|
|
|
89 |
private LeadActivityRepository leadActivityRepository;
|
|
|
90 |
|
|
|
91 |
@Autowired
|
|
|
92 |
private StateRepository stateRepository;
|
|
|
93 |
|
|
|
94 |
@Autowired
|
| 29266 |
manish |
95 |
private AuthService authService;
|
|
|
96 |
|
|
|
97 |
@Autowired
|
| 25979 |
tejbeer |
98 |
private AuthRepository authRepository;
|
|
|
99 |
|
|
|
100 |
@Autowired
|
| 29266 |
manish |
101 |
private Gson gson;
|
|
|
102 |
|
|
|
103 |
@Autowired
|
| 25979 |
tejbeer |
104 |
private CookiesProcessor cookiesProcessor;
|
| 29426 |
manish |
105 |
|
| 29278 |
manish |
106 |
@Autowired
|
|
|
107 |
PositionRepository positionRepository;
|
| 25979 |
tejbeer |
108 |
|
|
|
109 |
@Autowired
|
|
|
110 |
private MVCResponseSender mvcResponseSender;
|
|
|
111 |
|
| 30185 |
tejbeer |
112 |
@Autowired
|
|
|
113 |
private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
|
|
|
114 |
|
| 30416 |
tejbeer |
115 |
@Autowired
|
|
|
116 |
private CsService csService;
|
|
|
117 |
|
|
|
118 |
@Autowired
|
|
|
119 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
120 |
|
|
|
121 |
@Autowired
|
|
|
122 |
private PartnerCollectionService partnerCollectionService;
|
|
|
123 |
|
|
|
124 |
@Autowired
|
|
|
125 |
private RetailerService retailerService;
|
|
|
126 |
|
|
|
127 |
@Autowired
|
| 30434 |
tejbeer |
128 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
|
|
129 |
|
|
|
130 |
@Autowired
|
| 30416 |
tejbeer |
131 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 25988 |
tejbeer |
132 |
List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
|
|
|
133 |
|
| 25979 |
tejbeer |
134 |
@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
|
| 27609 |
tejbeer |
135 |
public String getOpenLead(HttpServletRequest request,
|
| 29426 |
manish |
136 |
@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,
|
| 29744 |
tejbeer |
137 |
@RequestParam(name = "color", required = false, defaultValue = "All") List<String> color,
|
| 29445 |
manish |
138 |
@RequestParam(name = "leadDate", required = false, defaultValue = "") LocalDate leadDate, Model model)
|
| 27642 |
tejbeer |
139 |
throws Exception {
|
| 27609 |
tejbeer |
140 |
|
| 29445 |
manish |
141 |
LocalDateTime localDateTime = null;
|
|
|
142 |
if (leadDate != null) {
|
|
|
143 |
localDateTime = leadDate.atStartOfDay();
|
|
|
144 |
}
|
|
|
145 |
LOGGER.info("localDateTime" + localDateTime);
|
|
|
146 |
|
| 29266 |
manish |
147 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
148 |
String emailId = loginDetails.getEmailId();
|
|
|
149 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailId);
|
| 29426 |
manish |
150 |
|
|
|
151 |
boolean authPositon = positionRepository.hasCategory(authUser.getId(),
|
|
|
152 |
ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
153 |
|
| 27610 |
tejbeer |
154 |
if (leadStatus.contains(LeadStatus.All)) {
|
|
|
155 |
|
| 29445 |
manish |
156 |
leadStatus.add(LeadStatus.pending);
|
|
|
157 |
leadStatus.add(LeadStatus.notInterested);
|
|
|
158 |
leadStatus.add(LeadStatus.finalized);
|
| 27610 |
tejbeer |
159 |
}
|
| 27615 |
tejbeer |
160 |
|
| 29744 |
tejbeer |
161 |
if (color.contains("All")) {
|
|
|
162 |
color.add("yellow");
|
|
|
163 |
color.add("green");
|
|
|
164 |
}
|
|
|
165 |
|
| 29852 |
tejbeer |
166 |
List<Lead> leads = new ArrayList<>();
|
| 29445 |
manish |
167 |
|
|
|
168 |
model.addAttribute("colors", color);
|
|
|
169 |
|
| 29744 |
tejbeer |
170 |
Map<Integer, List<LeadActivity>> leadActivityMap = new HashMap<>();
|
|
|
171 |
|
| 29287 |
amit.gupta |
172 |
List<Integer> authUserIds = null;
|
| 29445 |
manish |
173 |
|
| 29744 |
tejbeer |
174 |
LOGGER.info("color111" + color);
|
| 29445 |
manish |
175 |
|
| 29744 |
tejbeer |
176 |
List<Lead> leadFollowUp = new ArrayList<>();
|
| 29426 |
manish |
177 |
|
| 29744 |
tejbeer |
178 |
if (authPositon) {
|
|
|
179 |
authUserIds = authService.getAllReportees(authUser.getId());
|
|
|
180 |
authUserIds.add(authUser.getId());
|
|
|
181 |
LOGGER.info("authIds" + authUserIds);
|
| 29426 |
manish |
182 |
|
| 29753 |
tejbeer |
183 |
LOGGER.info("leadStatus" + leadStatus);
|
|
|
184 |
|
| 29744 |
tejbeer |
185 |
if (localDateTime == null) {
|
| 29445 |
manish |
186 |
|
| 29852 |
tejbeer |
187 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
188 |
|
| 29852 |
tejbeer |
189 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,
|
|
|
190 |
color, LocalDateTime.now().minusMonths(1));
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
| 30290 |
tejbeer |
194 |
leadFollowUp = leadRepository.selectByAssignAuthIdsAndStatus(authUserIds, LeadStatus.followUp);
|
| 29852 |
tejbeer |
195 |
leads.addAll(leadFollowUp);
|
|
|
196 |
}
|
|
|
197 |
|
| 29744 |
tejbeer |
198 |
} else {
|
| 29445 |
manish |
199 |
|
| 29852 |
tejbeer |
200 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
|
|
201 |
|
|
|
202 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,
|
|
|
203 |
color, localDateTime);
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
207 |
|
| 30290 |
tejbeer |
208 |
leadFollowUp = leadRepository.selectByAssignAuthIdsAndStatus(authUserIds, LeadStatus.followUp);
|
|
|
209 |
|
| 29852 |
tejbeer |
210 |
leads.addAll(leadFollowUp);
|
|
|
211 |
|
|
|
212 |
}
|
|
|
213 |
|
| 29744 |
tejbeer |
214 |
}
|
| 29445 |
manish |
215 |
|
| 29744 |
tejbeer |
216 |
} else {
|
| 29445 |
manish |
217 |
|
| 29744 |
tejbeer |
218 |
if (localDateTime == null) {
|
| 29852 |
tejbeer |
219 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
220 |
|
| 29852 |
tejbeer |
221 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color,
|
|
|
222 |
LocalDateTime.now().minusMonths(1));
|
|
|
223 |
}
|
|
|
224 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
225 |
|
| 30292 |
tejbeer |
226 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
| 30290 |
tejbeer |
227 |
|
| 29852 |
tejbeer |
228 |
leads.addAll(leadFollowUp);
|
|
|
229 |
}
|
| 29744 |
tejbeer |
230 |
LOGGER.info("leadlocalDateTime1" + leads);
|
| 29445 |
manish |
231 |
|
| 29744 |
tejbeer |
232 |
} else {
|
| 29852 |
tejbeer |
233 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
234 |
|
| 29852 |
tejbeer |
235 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color, localDateTime);
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
239 |
|
| 30292 |
tejbeer |
240 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
| 30290 |
tejbeer |
241 |
|
| 29852 |
tejbeer |
242 |
leads.addAll(leadFollowUp);
|
|
|
243 |
}
|
| 29744 |
tejbeer |
244 |
LOGGER.info("leadlocalDateTime2" + leads);
|
| 29445 |
manish |
245 |
|
| 29278 |
manish |
246 |
}
|
| 29426 |
manish |
247 |
|
| 29445 |
manish |
248 |
}
|
|
|
249 |
|
| 29426 |
manish |
250 |
if (authPositon && authUserIds.size() > 0) {
|
| 29287 |
amit.gupta |
251 |
List<String> leadCreators = new ArrayList<>();
|
|
|
252 |
leadCreators.add("daily-sync");
|
| 29426 |
manish |
253 |
leadCreators.addAll(authRepository.selectAllAuthUserByIds(authUserIds).stream().map(x -> x.getFullName())
|
|
|
254 |
.collect(Collectors.toList()));
|
| 29289 |
amit.gupta |
255 |
model.addAttribute("leadCreators", leadCreators);
|
| 29287 |
amit.gupta |
256 |
}
|
| 29266 |
manish |
257 |
List<Lead> weekLast = new ArrayList<>();
|
|
|
258 |
List<Lead> weekThird = new ArrayList<>();
|
|
|
259 |
List<Lead> weekSecond = new ArrayList<>();
|
|
|
260 |
List<Lead> weekFirst = new ArrayList<>();
|
|
|
261 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
262 |
List<LeadWeakWiseModel> lwDays = new ArrayList<>();
|
| 27642 |
tejbeer |
263 |
|
| 29266 |
manish |
264 |
for (int i = 7; i >= 1; i--) {
|
|
|
265 |
LocalDateTime startOfDay = curDate.minusDays(i);
|
|
|
266 |
|
|
|
267 |
LeadWeakWiseModel lm = new LeadWeakWiseModel();
|
|
|
268 |
lm.setMonth(startOfDay.toLocalDate());
|
|
|
269 |
lwDays.add(lm);
|
|
|
270 |
}
|
| 29426 |
manish |
271 |
if (!leads.isEmpty()) {
|
| 29266 |
manish |
272 |
|
| 29744 |
tejbeer |
273 |
weekLast.addAll(
|
|
|
274 |
leads.stream()
|
|
|
275 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(28))
|
|
|
276 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(21)))
|
|
|
277 |
.collect(Collectors.toList()));
|
| 29266 |
manish |
278 |
|
| 29744 |
tejbeer |
279 |
weekThird
|
|
|
280 |
.addAll(leads.stream()
|
|
|
281 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(21))
|
|
|
282 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(14)))
|
|
|
283 |
.collect(Collectors.toList()));
|
| 29266 |
manish |
284 |
|
| 29744 |
tejbeer |
285 |
weekSecond
|
|
|
286 |
.addAll(leads.stream()
|
|
|
287 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(14))
|
|
|
288 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(7)))
|
|
|
289 |
.collect(Collectors.toList()));
|
| 29426 |
manish |
290 |
|
| 29744 |
tejbeer |
291 |
weekFirst.addAll(leads.stream().filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(7)))
|
|
|
292 |
.collect(Collectors.toList()));
|
|
|
293 |
|
| 29266 |
manish |
294 |
}
|
|
|
295 |
LOGGER.info("weekLast" + weekLast);
|
|
|
296 |
LOGGER.info("weekThird" + weekThird);
|
|
|
297 |
LOGGER.info("weekSecond" + weekSecond);
|
| 29426 |
manish |
298 |
Map<String, Long> leadLasts = weekLast.stream()
|
|
|
299 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));
|
|
|
300 |
Map<String, Long> leadThirds = weekThird.stream()
|
|
|
301 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));
|
| 29266 |
manish |
302 |
Map<String, Long> leadSeconds = weekSecond.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
|
|
303 |
Collectors.mapping(Lead::getCreatedBy, Collectors.counting())));
|
|
|
304 |
|
|
|
305 |
Map<String, Map<LocalDate, Long>> leadFirsts = weekFirst.stream()
|
|
|
306 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
|
|
307 |
Collectors.groupingBy(x -> x.getCreatedTimestamp().toLocalDate(), Collectors.counting())));
|
|
|
308 |
|
|
|
309 |
LOGGER.info("leadFirsts" + leadFirsts);
|
|
|
310 |
|
| 27723 |
tejbeer |
311 |
List<Integer> authIds = new ArrayList<>();
|
|
|
312 |
if (!leads.isEmpty()) {
|
| 25979 |
tejbeer |
313 |
|
| 27723 |
tejbeer |
314 |
authIds.addAll(leads.stream().map(x -> x.getAssignTo()).collect(Collectors.toList()));
|
| 27610 |
tejbeer |
315 |
|
| 29744 |
tejbeer |
316 |
leadActivityMap = leadActivityRepository
|
|
|
317 |
.selectAllByleadIds(leads.stream().map(x -> x.getId()).collect(Collectors.toList())).stream()
|
|
|
318 |
.collect(Collectors.groupingBy(LeadActivity::getLeadId, Collectors.toList()));
|
|
|
319 |
|
| 27723 |
tejbeer |
320 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
321 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
322 |
model.addAttribute("leadActivityMap", leadActivityMap);
|
|
|
323 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
324 |
}
|
|
|
325 |
|
| 29266 |
manish |
326 |
ChartLeadModel cm = this.getLeadChart(leads);
|
|
|
327 |
model.addAttribute("chartLead", gson.toJson(cm));
|
|
|
328 |
|
|
|
329 |
LOGGER.info("ChartLeadModel" + gson.toJson(cm));
|
|
|
330 |
LOGGER.info("lwDays" + lwDays);
|
|
|
331 |
|
| 27610 |
tejbeer |
332 |
LOGGER.info("leads" + leads);
|
| 25979 |
tejbeer |
333 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
|
|
334 |
.collect(Collectors.toList());
|
|
|
335 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 29266 |
manish |
336 |
LocalDate lastDate = curDate.minusDays(1).toLocalDate();
|
| 29426 |
manish |
337 |
|
| 29266 |
manish |
338 |
List<LocalDate> weekDates = new ArrayList<>();
|
| 29426 |
manish |
339 |
|
| 29266 |
manish |
340 |
weekDates.add(curDate.minusDays(28).toLocalDate());
|
|
|
341 |
weekDates.add(curDate.minusDays(22).toLocalDate());
|
|
|
342 |
weekDates.add(curDate.minusDays(21).toLocalDate());
|
|
|
343 |
weekDates.add(curDate.minusDays(15).toLocalDate());
|
|
|
344 |
weekDates.add(curDate.minusDays(14).toLocalDate());
|
|
|
345 |
weekDates.add(curDate.minusDays(8).toLocalDate());
|
|
|
346 |
weekDates.add(curDate.minusDays(7).toLocalDate());
|
|
|
347 |
LOGGER.info("lastDate" + lastDate);
|
| 29426 |
manish |
348 |
|
| 29266 |
manish |
349 |
model.addAttribute("weekDates", weekDates);
|
| 29426 |
manish |
350 |
|
| 29445 |
manish |
351 |
model.addAttribute("leadDate", leadDate);
|
| 29266 |
manish |
352 |
model.addAttribute("lastDate", lastDate);
|
| 25979 |
tejbeer |
353 |
model.addAttribute("stateNames", stateNames);
|
|
|
354 |
model.addAttribute("authUsers", authUsers);
|
| 27610 |
tejbeer |
355 |
model.addAttribute("lead", leads);
|
|
|
356 |
model.addAttribute("leadStatus", LeadStatus.values());
|
| 29266 |
manish |
357 |
model.addAttribute("leadLasts", leadLasts);
|
|
|
358 |
model.addAttribute("leadThirds", leadThirds);
|
|
|
359 |
model.addAttribute("leadSeconds", leadSeconds);
|
|
|
360 |
model.addAttribute("leadFirsts", leadFirsts);
|
|
|
361 |
model.addAttribute("lwDays", lwDays);
|
| 25979 |
tejbeer |
362 |
|
| 27610 |
tejbeer |
363 |
model.addAttribute("selectedLeadStatus", leadStatus.get(0));
|
| 25979 |
tejbeer |
364 |
return "lead";
|
| 27642 |
tejbeer |
365 |
|
| 25979 |
tejbeer |
366 |
}
|
|
|
367 |
|
| 29266 |
manish |
368 |
public ChartLeadModel getLeadChart(List<Lead> leads) throws ProfitMandiBusinessException {
|
|
|
369 |
|
|
|
370 |
Map<LeadStatus, Long> leadStatusMap = leads.stream().collect(
|
|
|
371 |
Collectors.groupingBy(x -> x.getStatus(), Collectors.mapping(Lead::getStatus, Collectors.counting())));
|
|
|
372 |
|
| 29426 |
manish |
373 |
Map<String, Long> hotLeadsMap = leads.stream().collect(
|
|
|
374 |
Collectors.groupingBy(x -> x.getColor(), Collectors.mapping(Lead::getColor, Collectors.counting())));
|
|
|
375 |
|
|
|
376 |
LOGGER.info("hotLeadsMap" + hotLeadsMap);
|
| 29266 |
manish |
377 |
ChartLeadModel cm = new ChartLeadModel();
|
|
|
378 |
|
|
|
379 |
HashSet<LeadStatus> labels = new HashSet<LeadStatus>();
|
|
|
380 |
labels.addAll(leadStatusMap.keySet());
|
| 29445 |
manish |
381 |
|
| 29426 |
manish |
382 |
HashSet<String> hotLeads = new HashSet<String>();
|
|
|
383 |
hotLeads.addAll(leadStatusMap.keySet().stream().map(x -> x.toString()).collect(Collectors.toSet()));
|
|
|
384 |
hotLeads.add("HotLead");
|
| 29445 |
manish |
385 |
|
| 29426 |
manish |
386 |
HashSet<String> hotLeadKeys = new HashSet<String>();
|
| 29445 |
manish |
387 |
|
| 29426 |
manish |
388 |
hotLeadKeys.add("HotLead");
|
|
|
389 |
List<String> hotLeadGreen = new ArrayList<>(hotLeadKeys);
|
| 29598 |
tejbeer |
390 |
|
| 29448 |
manish |
391 |
LOGGER.info("hotLeads" + hotLeads);
|
| 29445 |
manish |
392 |
|
| 29266 |
manish |
393 |
List<LeadStatus> labelList = new ArrayList<>(labels);
|
|
|
394 |
List<String> backgroundColor = new ArrayList<>();
|
| 29426 |
manish |
395 |
LOGGER.info("hotLeadKeys" + hotLeadKeys);
|
| 29266 |
manish |
396 |
List<Long> values = new ArrayList<>();
|
|
|
397 |
|
| 29448 |
manish |
398 |
for (String hotLead : hotLeads) {
|
| 29266 |
manish |
399 |
|
| 29448 |
manish |
400 |
if (hotLead.equals("pending")) {
|
| 29266 |
manish |
401 |
backgroundColor.add("pink");
|
| 29448 |
manish |
402 |
values.add(leadStatusMap.get(LeadStatus.pending));
|
| 29266 |
manish |
403 |
}
|
| 29448 |
manish |
404 |
if (hotLead.equals("notInterested")) {
|
| 29266 |
manish |
405 |
backgroundColor.add("red");
|
| 29448 |
manish |
406 |
values.add(leadStatusMap.get(LeadStatus.notInterested));
|
| 29266 |
manish |
407 |
}
|
| 29448 |
manish |
408 |
if (hotLead.equals("followUp")) {
|
| 29266 |
manish |
409 |
backgroundColor.add("#9ACD32");
|
| 29448 |
manish |
410 |
values.add(leadStatusMap.get(LeadStatus.followUp));
|
| 29266 |
manish |
411 |
}
|
| 29448 |
manish |
412 |
if (hotLead.equals("finalized")) {
|
| 29266 |
manish |
413 |
backgroundColor.add("blue");
|
| 29448 |
manish |
414 |
values.add(leadStatusMap.get(LeadStatus.finalized));
|
| 29445 |
manish |
415 |
}
|
| 29598 |
tejbeer |
416 |
|
| 29448 |
manish |
417 |
if (hotLead.equals("HotLead")) {
|
| 29426 |
manish |
418 |
backgroundColor.add("green");
|
|
|
419 |
values.add(hotLeadsMap.get("Green"));
|
| 29445 |
manish |
420 |
|
| 29266 |
manish |
421 |
}
|
| 29445 |
manish |
422 |
|
| 29266 |
manish |
423 |
}
|
|
|
424 |
LOGGER.info("labelList" + labelList);
|
|
|
425 |
|
|
|
426 |
LOGGER.info("backgroundColor" + backgroundColor);
|
|
|
427 |
LOGGER.info("labelsChartLead" + labels);
|
|
|
428 |
LeadStatusData data = new LeadStatusData();
|
|
|
429 |
data.setData(values);
|
|
|
430 |
data.setBackgroundColor(backgroundColor);
|
|
|
431 |
data.setLabel("DataSet 1");
|
|
|
432 |
|
|
|
433 |
PieLables label = new PieLables();
|
|
|
434 |
label.setFontColor("black");
|
|
|
435 |
label.setFontSize(15);
|
|
|
436 |
|
|
|
437 |
Legend legend = new Legend();
|
|
|
438 |
legend.setLabels(label);
|
|
|
439 |
legend.setPosition("left");
|
|
|
440 |
|
|
|
441 |
List<LeadStatusData> dataList = new ArrayList<>();
|
|
|
442 |
dataList.add(data);
|
|
|
443 |
|
|
|
444 |
DataLeadModel datasets = new DataLeadModel();
|
|
|
445 |
datasets.setDatasets(dataList);
|
| 29426 |
manish |
446 |
datasets.setLabels(hotLeads);
|
| 29266 |
manish |
447 |
|
|
|
448 |
OptionModel om = new OptionModel();
|
|
|
449 |
om.setLegend(legend);
|
|
|
450 |
|
|
|
451 |
cm.setType("pie");
|
|
|
452 |
cm.setData(datasets);
|
|
|
453 |
cm.setOptions(om);
|
|
|
454 |
|
|
|
455 |
return cm;
|
|
|
456 |
}
|
|
|
457 |
|
| 25988 |
tejbeer |
458 |
@RequestMapping(value = "/getClosedLead", method = RequestMethod.GET)
|
|
|
459 |
public String getClosedLead(HttpServletRequest request,
|
|
|
460 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
461 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
462 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
463 |
throws Exception {
|
|
|
464 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
465 |
List<Lead> leads = null;
|
|
|
466 |
long size = 0;
|
|
|
467 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
468 |
size = leadRepository.selectCountByStatus(status);
|
|
|
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 |
|
|
|
478 |
model.addAttribute("leads", leads);
|
|
|
479 |
model.addAttribute("start", offset + 1);
|
|
|
480 |
model.addAttribute("size", size);
|
|
|
481 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
482 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
| 25990 |
tejbeer |
483 |
model.addAttribute("url", "/getPaginatedClosedLeads");
|
| 25988 |
tejbeer |
484 |
|
|
|
485 |
if (leads.size() < limit) {
|
|
|
486 |
model.addAttribute("end", offset + leads.size());
|
|
|
487 |
} else {
|
|
|
488 |
model.addAttribute("end", offset + limit);
|
|
|
489 |
}
|
|
|
490 |
|
|
|
491 |
} else {
|
|
|
492 |
model.addAttribute("lead", leads);
|
|
|
493 |
|
|
|
494 |
model.addAttribute("size", size);
|
|
|
495 |
}
|
|
|
496 |
|
|
|
497 |
model.addAttribute("authUsers", authUsers);
|
|
|
498 |
return "lead-close";
|
|
|
499 |
}
|
|
|
500 |
|
|
|
501 |
@RequestMapping(value = "/getPaginatedClosedLeads", method = RequestMethod.GET)
|
| 25990 |
tejbeer |
502 |
public String getPaginatedClosedLeads(HttpServletRequest request,
|
| 25988 |
tejbeer |
503 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
504 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
505 |
throws ProfitMandiBusinessException {
|
|
|
506 |
List<Lead> leads = null;
|
|
|
507 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
508 |
|
|
|
509 |
if (!leads.isEmpty()) {
|
|
|
510 |
List<Integer> authIds = new ArrayList<>();
|
|
|
511 |
for (Lead lead : leads) {
|
|
|
512 |
authIds.add(lead.getAssignTo());
|
|
|
513 |
}
|
|
|
514 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
515 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
516 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
517 |
model.addAttribute("leads", leads);
|
| 25990 |
tejbeer |
518 |
model.addAttribute("url", "/getPaginatedClosedLeads");
|
| 25988 |
tejbeer |
519 |
|
|
|
520 |
} else {
|
|
|
521 |
model.addAttribute("leads", leads);
|
|
|
522 |
|
|
|
523 |
}
|
|
|
524 |
return "lead-close-paginated";
|
|
|
525 |
}
|
|
|
526 |
|
|
|
527 |
@RequestMapping(value = "/searchLeads")
|
|
|
528 |
public String getClosedLeads(HttpServletRequest request,
|
|
|
529 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
530 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
531 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
532 |
throws ProfitMandiBusinessException {
|
|
|
533 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
534 |
List<Lead> leads = null;
|
|
|
535 |
long size = 0;
|
|
|
536 |
if (!(searchTerm.equals(""))) {
|
|
|
537 |
leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);
|
|
|
538 |
if (!(leads.size() == 0)) {
|
|
|
539 |
size = leadRepository.selectCountByStatus(status);
|
|
|
540 |
List<Integer> authIds = new ArrayList<>();
|
|
|
541 |
for (Lead lead : leads) {
|
|
|
542 |
authIds.add(lead.getAssignTo());
|
|
|
543 |
}
|
|
|
544 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
545 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
546 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
547 |
model.addAttribute("leads", leads);
|
|
|
548 |
model.addAttribute("start", offset + 1);
|
|
|
549 |
model.addAttribute("size", size);
|
|
|
550 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
551 |
|
|
|
552 |
if (leads.size() < limit) {
|
|
|
553 |
model.addAttribute("end", offset + leads.size());
|
|
|
554 |
} else {
|
|
|
555 |
model.addAttribute("end", offset + limit);
|
|
|
556 |
}
|
|
|
557 |
} else {
|
|
|
558 |
throw new ProfitMandiBusinessException("lead", searchTerm, "leads Not Found");
|
|
|
559 |
}
|
|
|
560 |
} else {
|
|
|
561 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
562 |
size = leadRepository.selectCountByStatus(status);
|
|
|
563 |
|
|
|
564 |
if (!leads.isEmpty()) {
|
|
|
565 |
List<Integer> authIds = new ArrayList<>();
|
|
|
566 |
for (Lead lead : leads) {
|
|
|
567 |
authIds.add(lead.getAssignTo());
|
|
|
568 |
}
|
|
|
569 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
570 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
571 |
|
|
|
572 |
model.addAttribute("leads", leads);
|
|
|
573 |
model.addAttribute("start", offset + 1);
|
|
|
574 |
model.addAttribute("size", size);
|
|
|
575 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
576 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
577 |
|
|
|
578 |
if (leads.size() < limit) {
|
|
|
579 |
model.addAttribute("end", offset + leads.size());
|
|
|
580 |
} else {
|
|
|
581 |
model.addAttribute("end", offset + limit);
|
|
|
582 |
}
|
|
|
583 |
|
|
|
584 |
}
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
model.addAttribute("authUsers", authUsers);
|
|
|
588 |
return "lead-close";
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
@RequestMapping(value = "/searchLeadPaginated")
|
| 25990 |
tejbeer |
592 |
public String searchLeadPaginated(HttpServletRequest request,
|
| 25988 |
tejbeer |
593 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
594 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
595 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
596 |
throws ProfitMandiBusinessException {
|
|
|
597 |
LOGGER.info("In search Item....");
|
|
|
598 |
List<Lead> leads = null;
|
|
|
599 |
if (!searchTerm.equals("")) {
|
|
|
600 |
leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);
|
|
|
601 |
if (!(leads.size() == 0)) {
|
|
|
602 |
|
|
|
603 |
List<Integer> authIds = new ArrayList<>();
|
|
|
604 |
for (Lead lead : leads) {
|
|
|
605 |
authIds.add(lead.getAssignTo());
|
|
|
606 |
}
|
|
|
607 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
608 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
609 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
610 |
model.addAttribute("leads", leads);
|
|
|
611 |
}
|
|
|
612 |
}
|
|
|
613 |
|
|
|
614 |
return "lead-close-paginated";
|
|
|
615 |
|
|
|
616 |
}
|
|
|
617 |
|
| 25979 |
tejbeer |
618 |
@RequestMapping(value = "/getLeadActivity", method = RequestMethod.GET)
|
|
|
619 |
public String getLeadActivity(HttpServletRequest request, @RequestParam int leadId, Model model) throws Exception {
|
|
|
620 |
List<LeadActivity> leadActivity = leadActivityRepository.selectBYLeadId(leadId);
|
|
|
621 |
model.addAttribute("leadActivity", leadActivity);
|
|
|
622 |
return "lead_activity_modal";
|
|
|
623 |
}
|
|
|
624 |
|
|
|
625 |
@RequestMapping(value = "/createLead", method = RequestMethod.POST)
|
|
|
626 |
public String CreateLead(HttpServletRequest request, @RequestBody CreateRefferalRequest createRefferalRequest,
|
|
|
627 |
Model model) throws Exception {
|
|
|
628 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
629 |
LOGGER.info("createRefferalRequest" + createRefferalRequest.getSchelduleTimestamp());
|
|
|
630 |
Lead lead = new Lead();
|
|
|
631 |
lead.setFirstName(createRefferalRequest.getFirstName());
|
|
|
632 |
lead.setLastName(createRefferalRequest.getLastName());
|
|
|
633 |
lead.setLeadMobile(createRefferalRequest.getMobile());
|
|
|
634 |
lead.setState(createRefferalRequest.getState());
|
|
|
635 |
lead.setCity(createRefferalRequest.getCity());
|
|
|
636 |
lead.setAddress(createRefferalRequest.getAddress());
|
|
|
637 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
638 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
639 |
lead.setStatus(createRefferalRequest.getStatus());
|
|
|
640 |
lead.setAssignTo(createRefferalRequest.getAssignTo());
|
|
|
641 |
lead.setSource(createRefferalRequest.getSource());
|
| 26298 |
tejbeer |
642 |
lead.setColor("yellow");
|
| 25979 |
tejbeer |
643 |
// change
|
| 25989 |
tejbeer |
644 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 25979 |
tejbeer |
645 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
646 |
lead.setCreatedBy(authUserName);
|
|
|
647 |
lead.setAuthId(authUser.getId());
|
|
|
648 |
|
|
|
649 |
leadRepository.persist(lead);
|
|
|
650 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
651 |
leadActivity.setLeadId(lead.getId());
|
|
|
652 |
leadActivity.setRemark(createRefferalRequest.getRemark());
|
|
|
653 |
|
|
|
654 |
if (createRefferalRequest.getStatus() == LeadStatus.followUp) {
|
|
|
655 |
leadActivity.setSchelduleTimestamp(createRefferalRequest.getSchelduleTimestamp());
|
|
|
656 |
} else {
|
|
|
657 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
658 |
}
|
|
|
659 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
660 |
leadActivityRepository.persist(leadActivity);
|
|
|
661 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
662 |
return "response";
|
|
|
663 |
|
|
|
664 |
}
|
|
|
665 |
|
|
|
666 |
@RequestMapping(value = "/editLead", method = RequestMethod.POST)
|
| 27605 |
tejbeer |
667 |
public String EditLead(HttpServletRequest request,
|
|
|
668 |
@RequestBody CreateLeacdActivityRequest createLeadActivityRequest, Model model) throws Exception {
|
| 25979 |
tejbeer |
669 |
|
|
|
670 |
LeadActivity leadActivity = new LeadActivity();
|
| 27605 |
tejbeer |
671 |
leadActivity.setLeadId(createLeadActivityRequest.getId());
|
|
|
672 |
leadActivity.setRemark(createLeadActivityRequest.getRemark());
|
| 29598 |
tejbeer |
673 |
|
| 29476 |
manish |
674 |
LOGGER.info("createRefferalRequest" + createLeadActivityRequest);
|
| 27605 |
tejbeer |
675 |
|
|
|
676 |
if (createLeadActivityRequest.getStatus() == LeadStatus.followUp) {
|
|
|
677 |
leadActivity.setSchelduleTimestamp(createLeadActivityRequest.getScheldule());
|
|
|
678 |
} else {
|
|
|
679 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
680 |
}
|
| 25979 |
tejbeer |
681 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
682 |
leadActivityRepository.persist(leadActivity);
|
| 29598 |
tejbeer |
683 |
Lead lead = leadRepository.selectById(createLeadActivityRequest.getId());
|
| 27605 |
tejbeer |
684 |
lead.setAssignTo(createLeadActivityRequest.getAssignTo());
|
|
|
685 |
lead.setStatus(createLeadActivityRequest.getStatus());
|
| 28200 |
tejbeer |
686 |
lead.setNotinterestedReason(createLeadActivityRequest.getReason());
|
| 25979 |
tejbeer |
687 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
688 |
|
| 29473 |
manish |
689 |
lead = leadRepository.selectById(createLeadActivityRequest.getId());
|
| 29598 |
tejbeer |
690 |
|
| 29476 |
manish |
691 |
int authId = 0;
|
|
|
692 |
if (lead != null) {
|
| 25979 |
tejbeer |
693 |
|
| 29476 |
manish |
694 |
authId = lead.getAssignTo();
|
|
|
695 |
Map<Integer, LeadActivity> leadActivityMap = new HashMap<>();
|
| 29598 |
tejbeer |
696 |
|
|
|
697 |
List<LeadActivity> leadActivitys = leadActivityRepository.selectBYLeadId(lead.getId());
|
|
|
698 |
|
|
|
699 |
if (!leadActivitys.isEmpty()) {
|
|
|
700 |
leadActivityMap.put(lead.getId(), leadActivitys.get(0));
|
|
|
701 |
}
|
|
|
702 |
|
|
|
703 |
Map<Integer, AuthUser> authIdAndAuthUserMap = new HashMap<>();
|
|
|
704 |
AuthUser AuthUser = authRepository.selectById(authId);
|
|
|
705 |
|
|
|
706 |
authIdAndAuthUserMap.put(AuthUser.getId(), AuthUser);
|
|
|
707 |
|
| 29476 |
manish |
708 |
model.addAttribute("leadActivityMap", leadActivityMap);
|
|
|
709 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
710 |
}
|
|
|
711 |
|
| 29473 |
manish |
712 |
model.addAttribute("request", lead);
|
|
|
713 |
|
|
|
714 |
return "edit-lead";
|
|
|
715 |
|
| 25979 |
tejbeer |
716 |
}
|
| 29445 |
manish |
717 |
|
| 29426 |
manish |
718 |
@RequestMapping(value = "/downloadIvoryLead", method = RequestMethod.GET)
|
|
|
719 |
public ResponseEntity<?> downloadDelayDayTemplate(HttpServletRequest request) throws Exception {
|
| 29598 |
tejbeer |
720 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
|
|
721 |
.collect(Collectors.toList());
|
|
|
722 |
|
| 29426 |
manish |
723 |
List<List<?>> rows = new ArrayList<>();
|
|
|
724 |
|
| 29598 |
tejbeer |
725 |
List<LeadSource> lss = LeadSource.enumValues;
|
| 29426 |
manish |
726 |
|
| 29598 |
tejbeer |
727 |
for (LeadSource ls : lss) {
|
|
|
728 |
rows.add(Arrays.asList("-", "-", "-", "-", "-", "-", "-", ls));
|
|
|
729 |
|
|
|
730 |
}
|
|
|
731 |
for (String stateName : stateNames) {
|
|
|
732 |
rows.add(Arrays.asList("-", "-", "-", "-", stateName, "-", "-", "-"));
|
|
|
733 |
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("First Name",
|
|
|
737 |
"Last Name", "Address", "City", "State", "Mobile", "Assign To(email)", "Source"), rows);
|
|
|
738 |
|
| 29426 |
manish |
739 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
740 |
headers.set("Content-Type", "text/csv");
|
| 29598 |
tejbeer |
741 |
headers.set("Content-disposition", "inline; filename=leads.format.csv");
|
| 29426 |
manish |
742 |
headers.setContentLength(baos.toByteArray().length);
|
|
|
743 |
|
|
|
744 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
745 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
746 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
747 |
|
|
|
748 |
}
|
| 29445 |
manish |
749 |
|
| 29426 |
manish |
750 |
@RequestMapping(value = "/csvFileAndSetLead", method = RequestMethod.POST)
|
|
|
751 |
public String readCsvFileAndSetLead(HttpServletRequest request, Model model, HttpServletResponse response,
|
|
|
752 |
@RequestPart MultipartFile file) throws Throwable {
|
|
|
753 |
|
| 29598 |
tejbeer |
754 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
755 |
String email = loginDetails.getEmailId();
|
|
|
756 |
|
|
|
757 |
AuthUser createdBy = authRepository.selectByEmailOrMobile(email);
|
|
|
758 |
|
| 29426 |
manish |
759 |
LOGGER.info("file" + file.toString());
|
|
|
760 |
|
|
|
761 |
String fileName = file.getName();
|
|
|
762 |
|
|
|
763 |
String fileNames = file.getOriginalFilename();
|
|
|
764 |
|
|
|
765 |
LOGGER.info("fileName" + fileName);
|
|
|
766 |
LOGGER.info("fileNames" + fileNames);
|
|
|
767 |
|
| 29598 |
tejbeer |
768 |
List<CSVRecord> records = FileUtil.readFile(file);
|
| 29426 |
manish |
769 |
|
| 29598 |
tejbeer |
770 |
for (CSVRecord record : records) {
|
| 29426 |
manish |
771 |
|
|
|
772 |
Lead lead = new Lead();
|
| 29598 |
tejbeer |
773 |
lead.setFirstName(record.get(0));
|
|
|
774 |
lead.setLastName(record.get(1));
|
|
|
775 |
lead.setAddress(record.get(2));
|
|
|
776 |
lead.setCity(record.get(3));
|
|
|
777 |
lead.setState(record.get(4));
|
|
|
778 |
lead.setLeadMobile(record.get(5));
|
|
|
779 |
LOGGER.info("record" + record.get(6));
|
| 29426 |
manish |
780 |
|
| 29598 |
tejbeer |
781 |
AuthUser assignTo = authRepository.selectByEmailOrMobile(record.get(6));
|
| 29426 |
manish |
782 |
|
| 29598 |
tejbeer |
783 |
if (assignTo == null) {
|
|
|
784 |
throw new ProfitMandiBusinessException("Assign To ", record.get(6), "email id not exist");
|
|
|
785 |
}
|
| 29445 |
manish |
786 |
|
| 29598 |
tejbeer |
787 |
lead.setAssignTo(assignTo.getId());
|
|
|
788 |
lead.setSource(record.get(7));
|
|
|
789 |
|
|
|
790 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
791 |
|
| 29426 |
manish |
792 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
793 |
lead.setStatus(LeadStatus.pending);
|
|
|
794 |
lead.setColor("yellow");
|
|
|
795 |
// change
|
| 29598 |
tejbeer |
796 |
lead.setCreatedBy(createdBy.getFullName());
|
|
|
797 |
lead.setAuthId(createdBy.getId());
|
| 29426 |
manish |
798 |
|
|
|
799 |
leadRepository.persist(lead);
|
|
|
800 |
|
|
|
801 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
802 |
leadActivity.setLeadId(lead.getId());
|
| 29598 |
tejbeer |
803 |
leadActivity.setRemark("New Lead");
|
| 29426 |
manish |
804 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
805 |
|
|
|
806 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
807 |
leadActivityRepository.persist(leadActivity);
|
|
|
808 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
809 |
|
|
|
810 |
}
|
|
|
811 |
|
|
|
812 |
model.addAttribute("responseSTG", mvcResponseSender.createResponseString(true));
|
|
|
813 |
|
|
|
814 |
return "response";
|
|
|
815 |
|
|
|
816 |
}
|
|
|
817 |
|
| 30185 |
tejbeer |
818 |
@RequestMapping(value = "/teamCommitment", method = RequestMethod.GET)
|
|
|
819 |
public String teamCommitments(HttpServletRequest request, Model model) throws Exception {
|
|
|
820 |
|
|
|
821 |
return "team-commitment";
|
|
|
822 |
|
|
|
823 |
}
|
|
|
824 |
|
|
|
825 |
@RequestMapping(value = "/getTeamCommitment", method = RequestMethod.GET)
|
|
|
826 |
public String getTeamCommitments(HttpServletRequest request, @RequestParam LocalDateTime date, Model model)
|
|
|
827 |
throws Exception {
|
|
|
828 |
|
|
|
829 |
List<TeamCommitmentModel> commitments = partnerCollectionPlanRepository
|
|
|
830 |
.selectTeamCommitmentByDate(date.toLocalDate());
|
|
|
831 |
|
|
|
832 |
model.addAttribute("commitments", commitments);
|
|
|
833 |
return "team-commitment-table";
|
|
|
834 |
|
|
|
835 |
}
|
| 30416 |
tejbeer |
836 |
|
|
|
837 |
@RequestMapping(value = "/partnerHealth", method = RequestMethod.GET)
|
|
|
838 |
public String partnerHealth(HttpServletRequest request,
|
|
|
839 |
@RequestParam(name = "email", required = false) String email, Model model) throws Exception {
|
|
|
840 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
841 |
|
|
|
842 |
if (StringUtils.isEmpty(email)) {
|
|
|
843 |
email = loginDetails.getEmailId();
|
|
|
844 |
} else {
|
|
|
845 |
AuthUser selectedUser = authRepository.selectByEmailOrMobile(email);
|
|
|
846 |
|
|
|
847 |
model.addAttribute("selectedUser", selectedUser);
|
|
|
848 |
|
|
|
849 |
}
|
|
|
850 |
|
|
|
851 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
852 |
|
|
|
853 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
|
|
854 |
Set<Integer> fofoIds = storeGuyMap.get(email);
|
|
|
855 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
|
|
856 |
if (fofoIds.size() > 0 && fofoIds != null) {
|
|
|
857 |
List<Integer> fofoIdl = new ArrayList<>(fofoIds);
|
|
|
858 |
List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(fofoIdl).stream()
|
|
|
859 |
.filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
|
|
|
860 |
|
|
|
861 |
Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = partnerCollectionService
|
|
|
862 |
.getCollectionMap(fofoIdList, startDate);
|
|
|
863 |
|
| 30434 |
tejbeer |
864 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIdList);
|
|
|
865 |
|
|
|
866 |
LOGGER.info("remarkIds {}", remarkIds);
|
|
|
867 |
|
|
|
868 |
long todayOverallCall = 0;
|
|
|
869 |
if (!remarkIds.isEmpty()) {
|
|
|
870 |
todayOverallCall = partnerCollectionRemarkRepository.selectByIds(remarkIds).stream()
|
| 30438 |
tejbeer |
871 |
.filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
| 30434 |
tejbeer |
872 |
.collect(Collectors.counting());
|
|
|
873 |
|
|
|
874 |
}
|
|
|
875 |
|
| 30416 |
tejbeer |
876 |
ChartLeadModel cm = this
|
|
|
877 |
.getCollectionCount(foundCollectionMap.values().stream().collect(Collectors.toList()));
|
|
|
878 |
model.addAttribute("chartPartnerHealth", gson.toJson(cm));
|
|
|
879 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
|
|
|
880 |
|
|
|
881 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
|
|
|
882 |
.selectAll(fofoIdList, startDate.toLocalDate().minusDays(1));
|
|
|
883 |
if (!partnerDailyInvestments.isEmpty()) {
|
|
|
884 |
partnerDailyInvestmentMap = partnerDailyInvestments.stream()
|
|
|
885 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
886 |
}
|
|
|
887 |
|
|
|
888 |
Map<LocalDate, Map<Integer, PartnerCollectionPlanModel>> pcpmMap = new TreeMap<>();
|
|
|
889 |
for (int i = 0; i <= 6; i++) {
|
|
|
890 |
|
|
|
891 |
Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService
|
|
|
892 |
.getCollectionMap(fofoIdList, startDate.minusDays(i));
|
|
|
893 |
|
| 30420 |
tejbeer |
894 |
LOGGER.info("dddd {} {}", startDate.minusDays(i), collectionMap.get(175138989));
|
|
|
895 |
|
| 30416 |
tejbeer |
896 |
pcpmMap.put(startDate.minusDays(i).toLocalDate(), collectionMap);
|
|
|
897 |
}
|
|
|
898 |
|
|
|
899 |
Map<Integer, PartnerCollectionPlanModel> todayPcpmMap = pcpmMap.get(startDate.toLocalDate());
|
|
|
900 |
model.addAttribute("todayPcpmMap", todayPcpmMap);
|
| 30426 |
tejbeer |
901 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
902 |
Map<Integer, CustomRetailer> customRetailers = fofoIdList.stream().map(x -> customRetailerMap.get(x))
|
|
|
903 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
904 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 30416 |
tejbeer |
905 |
List<Integer> allReportees = authService.getAllReportees(authUser.getId());
|
| 30420 |
tejbeer |
906 |
|
| 30416 |
tejbeer |
907 |
List<Integer> salesPositionsAuthIds = positionRepository
|
|
|
908 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES).stream()
|
|
|
909 |
.map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
|
|
910 |
List<Integer> rbmPositionsAuthIds = positionRepository
|
|
|
911 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM).stream()
|
|
|
912 |
.map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
|
|
913 |
|
|
|
914 |
salesPositionsAuthIds.addAll(rbmPositionsAuthIds);
|
|
|
915 |
|
|
|
916 |
Set<Integer> empHierarchy = allReportees.stream().filter(x -> salesPositionsAuthIds.contains(x))
|
|
|
917 |
.collect(Collectors.toSet());
|
|
|
918 |
|
|
|
919 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(new ArrayList<>(empHierarchy));
|
|
|
920 |
|
| 30441 |
tejbeer |
921 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAll().stream()
|
|
|
922 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
923 |
|
|
|
924 |
LOGGER.info("todayPcpmMap {}", todayPcpmMap);
|
|
|
925 |
|
| 30416 |
tejbeer |
926 |
model.addAttribute("authUsers", authUsers);
|
| 30441 |
tejbeer |
927 |
model.addAttribute("authUserMap", authUserMap);
|
| 30416 |
tejbeer |
928 |
model.addAttribute("partnerCollectionPlanMap", pcpmMap);
|
|
|
929 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
|
|
930 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
931 |
model.addAttribute("rankColorMap", ProfitMandiConstants.Rank_Color_Map);
|
| 30434 |
tejbeer |
932 |
model.addAttribute("todayOverallCall", todayOverallCall);
|
| 30416 |
tejbeer |
933 |
|
|
|
934 |
}
|
|
|
935 |
return "partner-health";
|
|
|
936 |
|
|
|
937 |
}
|
|
|
938 |
|
|
|
939 |
public ChartLeadModel getCollectionCount(List<PartnerCollectionPlanModel> pcpm)
|
|
|
940 |
throws ProfitMandiBusinessException {
|
|
|
941 |
|
|
|
942 |
Map<Integer, Long> rankCount = pcpm.stream().collect(Collectors.groupingBy(x -> x.getRank(),
|
|
|
943 |
Collectors.mapping(PartnerCollectionPlanModel::getRank, Collectors.counting())));
|
|
|
944 |
|
|
|
945 |
ChartLeadModel cm = new ChartLeadModel();
|
|
|
946 |
|
|
|
947 |
HashSet<String> labels = new HashSet<String>();
|
|
|
948 |
labels.add("Plan for Today");
|
|
|
949 |
labels.add("Carry Forward");
|
|
|
950 |
labels.add("Untouched");
|
|
|
951 |
labels.add("Plan for Future");
|
|
|
952 |
labels.add("Normal");
|
|
|
953 |
|
|
|
954 |
List<String> backgroundColor = new ArrayList<>();
|
|
|
955 |
List<Long> values = new ArrayList<>();
|
|
|
956 |
|
|
|
957 |
for (String label : labels) {
|
|
|
958 |
|
|
|
959 |
if (label.equals("Plan for Today")) {
|
|
|
960 |
backgroundColor.add("#007bff");
|
|
|
961 |
values.add(rankCount.get(1));
|
|
|
962 |
}
|
|
|
963 |
if (label.equals("Carry Forward")) {
|
|
|
964 |
backgroundColor.add("#ffc107");
|
|
|
965 |
values.add(rankCount.get(2));
|
|
|
966 |
}
|
|
|
967 |
if (label.equals("Untouched")) {
|
|
|
968 |
backgroundColor.add("#dc3545");
|
|
|
969 |
values.add(rankCount.get(3));
|
|
|
970 |
}
|
|
|
971 |
if (label.equals("Plan for Future")) {
|
|
|
972 |
backgroundColor.add("#6c757d");
|
|
|
973 |
values.add(rankCount.get(4));
|
|
|
974 |
}
|
|
|
975 |
if (label.equals("Normal")) {
|
|
|
976 |
backgroundColor.add("White");
|
|
|
977 |
values.add(rankCount.get(5));
|
|
|
978 |
}
|
|
|
979 |
|
|
|
980 |
}
|
|
|
981 |
|
|
|
982 |
LOGGER.info("backgroundColor" + backgroundColor);
|
|
|
983 |
LOGGER.info("labelsChartLead" + labels);
|
|
|
984 |
LeadStatusData data = new LeadStatusData();
|
|
|
985 |
data.setData(values);
|
|
|
986 |
data.setBackgroundColor(backgroundColor);
|
|
|
987 |
data.setLabel("DataSet 1");
|
|
|
988 |
|
|
|
989 |
PieLables label = new PieLables();
|
|
|
990 |
label.setFontColor("black");
|
|
|
991 |
label.setFontSize(15);
|
|
|
992 |
|
|
|
993 |
Legend legend = new Legend();
|
|
|
994 |
legend.setLabels(label);
|
|
|
995 |
legend.setPosition("left");
|
|
|
996 |
|
|
|
997 |
List<LeadStatusData> dataList = new ArrayList<>();
|
|
|
998 |
dataList.add(data);
|
|
|
999 |
|
|
|
1000 |
DataLeadModel datasets = new DataLeadModel();
|
|
|
1001 |
datasets.setDatasets(dataList);
|
|
|
1002 |
datasets.setLabels(labels);
|
|
|
1003 |
|
|
|
1004 |
OptionModel om = new OptionModel();
|
|
|
1005 |
om.setLegend(legend);
|
|
|
1006 |
|
|
|
1007 |
cm.setType("pie");
|
|
|
1008 |
cm.setData(datasets);
|
|
|
1009 |
cm.setOptions(om);
|
|
|
1010 |
|
|
|
1011 |
return cm;
|
|
|
1012 |
}
|
|
|
1013 |
|
| 25979 |
tejbeer |
1014 |
}
|