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