| 25979 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 29266 |
manish |
3 |
import com.google.gson.Gson;
|
| 31370 |
tejbeer |
4 |
import com.mongodb.DBObject;
|
| 25988 |
tejbeer |
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 31422 |
amit.gupta |
6 |
import com.spice.profitmandi.common.model.*;
|
| 29426 |
manish |
7 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 31370 |
tejbeer |
8 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 25979 |
tejbeer |
9 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30416 |
tejbeer |
10 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 31422 |
amit.gupta |
11 |
import com.spice.profitmandi.dao.entity.user.*;
|
| 30773 |
amit.gupta |
12 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 31249 |
tejbeer |
13 |
import com.spice.profitmandi.dao.enumuration.dtr.CommunicationType;
|
| 29598 |
tejbeer |
14 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
|
| 25979 |
tejbeer |
15 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| 31422 |
amit.gupta |
16 |
import com.spice.profitmandi.dao.model.*;
|
| 25979 |
tejbeer |
17 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 30185 |
tejbeer |
18 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
|
| 30434 |
tejbeer |
19 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 30416 |
tejbeer |
20 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 29266 |
manish |
21 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 31422 |
amit.gupta |
22 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 30416 |
tejbeer |
23 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 25979 |
tejbeer |
24 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 30445 |
tejbeer |
25 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 29266 |
manish |
26 |
import com.spice.profitmandi.service.AuthService;
|
| 30416 |
tejbeer |
27 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
|
|
28 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 25979 |
tejbeer |
29 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
30 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
31 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 31422 |
amit.gupta |
32 |
import org.apache.commons.csv.CSVRecord;
|
|
|
33 |
import org.apache.logging.log4j.LogManager;
|
|
|
34 |
import org.apache.logging.log4j.Logger;
|
|
|
35 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
36 |
import org.springframework.core.io.InputStreamResource;
|
|
|
37 |
import org.springframework.http.HttpHeaders;
|
|
|
38 |
import org.springframework.http.HttpStatus;
|
|
|
39 |
import org.springframework.http.MediaType;
|
|
|
40 |
import org.springframework.http.ResponseEntity;
|
|
|
41 |
import org.springframework.stereotype.Controller;
|
|
|
42 |
import org.springframework.ui.Model;
|
|
|
43 |
import org.springframework.util.StringUtils;
|
|
|
44 |
import org.springframework.web.bind.annotation.*;
|
|
|
45 |
import org.springframework.web.multipart.MultipartFile;
|
| 25979 |
tejbeer |
46 |
|
| 31422 |
amit.gupta |
47 |
import javax.servlet.http.HttpServletRequest;
|
|
|
48 |
import javax.servlet.http.HttpServletResponse;
|
|
|
49 |
import javax.transaction.Transactional;
|
|
|
50 |
import java.io.ByteArrayInputStream;
|
|
|
51 |
import java.io.InputStream;
|
|
|
52 |
import java.time.LocalDate;
|
|
|
53 |
import java.time.LocalDateTime;
|
|
|
54 |
import java.time.format.DateTimeFormatter;
|
|
|
55 |
import java.util.*;
|
|
|
56 |
import java.util.Map.Entry;
|
|
|
57 |
import java.util.stream.Collectors;
|
|
|
58 |
|
| 25979 |
tejbeer |
59 |
@Controller
|
|
|
60 |
@Transactional(rollbackOn = Throwable.class)
|
|
|
61 |
public class LeadController {
|
|
|
62 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
|
|
63 |
|
|
|
64 |
@Autowired
|
|
|
65 |
private LeadRepository leadRepository;
|
|
|
66 |
|
|
|
67 |
@Autowired
|
|
|
68 |
private LeadActivityRepository leadActivityRepository;
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private StateRepository stateRepository;
|
|
|
72 |
|
|
|
73 |
@Autowired
|
| 29266 |
manish |
74 |
private AuthService authService;
|
|
|
75 |
|
|
|
76 |
@Autowired
|
| 25979 |
tejbeer |
77 |
private AuthRepository authRepository;
|
|
|
78 |
|
|
|
79 |
@Autowired
|
| 29266 |
manish |
80 |
private Gson gson;
|
|
|
81 |
|
|
|
82 |
@Autowired
|
| 25979 |
tejbeer |
83 |
private CookiesProcessor cookiesProcessor;
|
| 29426 |
manish |
84 |
|
| 29278 |
manish |
85 |
@Autowired
|
|
|
86 |
PositionRepository positionRepository;
|
| 25979 |
tejbeer |
87 |
|
|
|
88 |
@Autowired
|
|
|
89 |
private MVCResponseSender mvcResponseSender;
|
|
|
90 |
|
| 30185 |
tejbeer |
91 |
@Autowired
|
|
|
92 |
private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
|
|
|
93 |
|
| 30416 |
tejbeer |
94 |
@Autowired
|
|
|
95 |
private CsService csService;
|
|
|
96 |
|
|
|
97 |
@Autowired
|
|
|
98 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
99 |
|
|
|
100 |
@Autowired
|
|
|
101 |
private PartnerCollectionService partnerCollectionService;
|
|
|
102 |
|
|
|
103 |
@Autowired
|
|
|
104 |
private RetailerService retailerService;
|
|
|
105 |
|
|
|
106 |
@Autowired
|
| 30434 |
tejbeer |
107 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
|
|
108 |
|
|
|
109 |
@Autowired
|
| 30416 |
tejbeer |
110 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 30445 |
tejbeer |
111 |
|
|
|
112 |
@Autowired
|
|
|
113 |
private UserWalletRepository userWalletRepository;
|
|
|
114 |
|
| 30522 |
tejbeer |
115 |
@Autowired
|
|
|
116 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
|
|
117 |
|
|
|
118 |
@Autowired
|
|
|
119 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
|
|
120 |
|
| 31249 |
tejbeer |
121 |
@Autowired
|
|
|
122 |
private VisitRequestRepository visitRequestRepository;
|
|
|
123 |
|
| 31370 |
tejbeer |
124 |
@Autowired
|
|
|
125 |
private LeadBrandRepository leadBrandRepository;
|
|
|
126 |
|
|
|
127 |
@Autowired
|
|
|
128 |
private LeadDetailRepository leadDetailRepository;
|
|
|
129 |
|
|
|
130 |
@Autowired
|
|
|
131 |
private Mongo mongoClient;
|
|
|
132 |
|
|
|
133 |
@Autowired
|
|
|
134 |
private ResponseSender<?> responseSender;
|
|
|
135 |
|
| 25988 |
tejbeer |
136 |
List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);
|
|
|
137 |
|
| 25979 |
tejbeer |
138 |
@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)
|
| 27609 |
tejbeer |
139 |
public String getOpenLead(HttpServletRequest request,
|
| 29426 |
manish |
140 |
@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,
|
| 29744 |
tejbeer |
141 |
@RequestParam(name = "color", required = false, defaultValue = "All") List<String> color,
|
| 29445 |
manish |
142 |
@RequestParam(name = "leadDate", required = false, defaultValue = "") LocalDate leadDate, Model model)
|
| 27642 |
tejbeer |
143 |
throws Exception {
|
| 27609 |
tejbeer |
144 |
|
| 29445 |
manish |
145 |
LocalDateTime localDateTime = null;
|
|
|
146 |
if (leadDate != null) {
|
|
|
147 |
localDateTime = leadDate.atStartOfDay();
|
|
|
148 |
}
|
|
|
149 |
LOGGER.info("localDateTime" + localDateTime);
|
|
|
150 |
|
| 29266 |
manish |
151 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
152 |
String emailId = loginDetails.getEmailId();
|
|
|
153 |
AuthUser authUser = authRepository.selectByEmailOrMobile(emailId);
|
| 29426 |
manish |
154 |
|
|
|
155 |
boolean authPositon = positionRepository.hasCategory(authUser.getId(),
|
|
|
156 |
ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
157 |
|
| 27610 |
tejbeer |
158 |
if (leadStatus.contains(LeadStatus.All)) {
|
|
|
159 |
|
| 29445 |
manish |
160 |
leadStatus.add(LeadStatus.pending);
|
|
|
161 |
leadStatus.add(LeadStatus.notInterested);
|
|
|
162 |
leadStatus.add(LeadStatus.finalized);
|
| 27610 |
tejbeer |
163 |
}
|
| 27615 |
tejbeer |
164 |
|
| 29744 |
tejbeer |
165 |
if (color.contains("All")) {
|
|
|
166 |
color.add("yellow");
|
|
|
167 |
color.add("green");
|
|
|
168 |
}
|
|
|
169 |
|
| 29852 |
tejbeer |
170 |
List<Lead> leads = new ArrayList<>();
|
| 29445 |
manish |
171 |
|
|
|
172 |
model.addAttribute("colors", color);
|
|
|
173 |
|
| 29744 |
tejbeer |
174 |
Map<Integer, List<LeadActivity>> leadActivityMap = new HashMap<>();
|
|
|
175 |
|
| 29287 |
amit.gupta |
176 |
List<Integer> authUserIds = null;
|
| 29445 |
manish |
177 |
|
| 29744 |
tejbeer |
178 |
LOGGER.info("color111" + color);
|
| 29445 |
manish |
179 |
|
| 29744 |
tejbeer |
180 |
List<Lead> leadFollowUp = new ArrayList<>();
|
| 29426 |
manish |
181 |
|
| 29744 |
tejbeer |
182 |
if (authPositon) {
|
|
|
183 |
authUserIds = authService.getAllReportees(authUser.getId());
|
|
|
184 |
authUserIds.add(authUser.getId());
|
|
|
185 |
LOGGER.info("authIds" + authUserIds);
|
| 29426 |
manish |
186 |
|
| 29753 |
tejbeer |
187 |
LOGGER.info("leadStatus" + leadStatus);
|
|
|
188 |
|
| 29744 |
tejbeer |
189 |
if (localDateTime == null) {
|
| 29445 |
manish |
190 |
|
| 29852 |
tejbeer |
191 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
192 |
|
| 29852 |
tejbeer |
193 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,
|
|
|
194 |
color, LocalDateTime.now().minusMonths(1));
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
| 30290 |
tejbeer |
198 |
leadFollowUp = leadRepository.selectByAssignAuthIdsAndStatus(authUserIds, LeadStatus.followUp);
|
| 29852 |
tejbeer |
199 |
leads.addAll(leadFollowUp);
|
|
|
200 |
}
|
|
|
201 |
|
| 29744 |
tejbeer |
202 |
} else {
|
| 29445 |
manish |
203 |
|
| 29852 |
tejbeer |
204 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
|
|
205 |
|
|
|
206 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,
|
|
|
207 |
color, localDateTime);
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
211 |
|
| 30290 |
tejbeer |
212 |
leadFollowUp = leadRepository.selectByAssignAuthIdsAndStatus(authUserIds, LeadStatus.followUp);
|
|
|
213 |
|
| 29852 |
tejbeer |
214 |
leads.addAll(leadFollowUp);
|
|
|
215 |
|
|
|
216 |
}
|
|
|
217 |
|
| 29744 |
tejbeer |
218 |
}
|
| 29445 |
manish |
219 |
|
| 29744 |
tejbeer |
220 |
} else {
|
| 29445 |
manish |
221 |
|
| 29744 |
tejbeer |
222 |
if (localDateTime == null) {
|
| 29852 |
tejbeer |
223 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
224 |
|
| 29852 |
tejbeer |
225 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color,
|
|
|
226 |
LocalDateTime.now().minusMonths(1));
|
|
|
227 |
}
|
|
|
228 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
229 |
|
| 30292 |
tejbeer |
230 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
| 30290 |
tejbeer |
231 |
|
| 29852 |
tejbeer |
232 |
leads.addAll(leadFollowUp);
|
|
|
233 |
}
|
| 29744 |
tejbeer |
234 |
LOGGER.info("leadlocalDateTime1" + leads);
|
| 29445 |
manish |
235 |
|
| 29744 |
tejbeer |
236 |
} else {
|
| 29852 |
tejbeer |
237 |
if (!leadStatus.contains(LeadStatus.followUp)) {
|
| 29445 |
manish |
238 |
|
| 29852 |
tejbeer |
239 |
leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color, localDateTime);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {
|
|
|
243 |
|
| 30292 |
tejbeer |
244 |
leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);
|
| 30290 |
tejbeer |
245 |
|
| 29852 |
tejbeer |
246 |
leads.addAll(leadFollowUp);
|
|
|
247 |
}
|
| 29744 |
tejbeer |
248 |
LOGGER.info("leadlocalDateTime2" + leads);
|
| 29445 |
manish |
249 |
|
| 29278 |
manish |
250 |
}
|
| 29426 |
manish |
251 |
|
| 29445 |
manish |
252 |
}
|
|
|
253 |
|
| 29426 |
manish |
254 |
if (authPositon && authUserIds.size() > 0) {
|
| 29287 |
amit.gupta |
255 |
List<String> leadCreators = new ArrayList<>();
|
|
|
256 |
leadCreators.add("daily-sync");
|
| 29426 |
manish |
257 |
leadCreators.addAll(authRepository.selectAllAuthUserByIds(authUserIds).stream().map(x -> x.getFullName())
|
|
|
258 |
.collect(Collectors.toList()));
|
| 29289 |
amit.gupta |
259 |
model.addAttribute("leadCreators", leadCreators);
|
| 29287 |
amit.gupta |
260 |
}
|
| 29266 |
manish |
261 |
List<Lead> weekLast = new ArrayList<>();
|
|
|
262 |
List<Lead> weekThird = new ArrayList<>();
|
|
|
263 |
List<Lead> weekSecond = new ArrayList<>();
|
|
|
264 |
List<Lead> weekFirst = new ArrayList<>();
|
|
|
265 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
266 |
List<LeadWeakWiseModel> lwDays = new ArrayList<>();
|
| 27642 |
tejbeer |
267 |
|
| 29266 |
manish |
268 |
for (int i = 7; i >= 1; i--) {
|
|
|
269 |
LocalDateTime startOfDay = curDate.minusDays(i);
|
|
|
270 |
|
|
|
271 |
LeadWeakWiseModel lm = new LeadWeakWiseModel();
|
|
|
272 |
lm.setMonth(startOfDay.toLocalDate());
|
|
|
273 |
lwDays.add(lm);
|
|
|
274 |
}
|
| 29426 |
manish |
275 |
if (!leads.isEmpty()) {
|
| 29266 |
manish |
276 |
|
| 29744 |
tejbeer |
277 |
weekLast.addAll(
|
|
|
278 |
leads.stream()
|
|
|
279 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(28))
|
|
|
280 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(21)))
|
|
|
281 |
.collect(Collectors.toList()));
|
| 29266 |
manish |
282 |
|
| 29744 |
tejbeer |
283 |
weekThird
|
|
|
284 |
.addAll(leads.stream()
|
|
|
285 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(21))
|
|
|
286 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(14)))
|
|
|
287 |
.collect(Collectors.toList()));
|
| 29266 |
manish |
288 |
|
| 29744 |
tejbeer |
289 |
weekSecond
|
|
|
290 |
.addAll(leads.stream()
|
|
|
291 |
.filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(14))
|
|
|
292 |
&& x.getCreatedTimestamp().isBefore(curDate.minusDays(7)))
|
|
|
293 |
.collect(Collectors.toList()));
|
| 29426 |
manish |
294 |
|
| 29744 |
tejbeer |
295 |
weekFirst.addAll(leads.stream().filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(7)))
|
|
|
296 |
.collect(Collectors.toList()));
|
|
|
297 |
|
| 29266 |
manish |
298 |
}
|
|
|
299 |
LOGGER.info("weekLast" + weekLast);
|
|
|
300 |
LOGGER.info("weekThird" + weekThird);
|
|
|
301 |
LOGGER.info("weekSecond" + weekSecond);
|
| 29426 |
manish |
302 |
Map<String, Long> leadLasts = weekLast.stream()
|
|
|
303 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));
|
|
|
304 |
Map<String, Long> leadThirds = weekThird.stream()
|
|
|
305 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));
|
| 29266 |
manish |
306 |
Map<String, Long> leadSeconds = weekSecond.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
|
|
307 |
Collectors.mapping(Lead::getCreatedBy, Collectors.counting())));
|
|
|
308 |
|
|
|
309 |
Map<String, Map<LocalDate, Long>> leadFirsts = weekFirst.stream()
|
|
|
310 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy(),
|
|
|
311 |
Collectors.groupingBy(x -> x.getCreatedTimestamp().toLocalDate(), Collectors.counting())));
|
|
|
312 |
|
|
|
313 |
LOGGER.info("leadFirsts" + leadFirsts);
|
|
|
314 |
|
| 27723 |
tejbeer |
315 |
List<Integer> authIds = new ArrayList<>();
|
|
|
316 |
if (!leads.isEmpty()) {
|
| 25979 |
tejbeer |
317 |
|
| 27723 |
tejbeer |
318 |
authIds.addAll(leads.stream().map(x -> x.getAssignTo()).collect(Collectors.toList()));
|
| 27610 |
tejbeer |
319 |
|
| 29744 |
tejbeer |
320 |
leadActivityMap = leadActivityRepository
|
|
|
321 |
.selectAllByleadIds(leads.stream().map(x -> x.getId()).collect(Collectors.toList())).stream()
|
|
|
322 |
.collect(Collectors.groupingBy(LeadActivity::getLeadId, Collectors.toList()));
|
|
|
323 |
|
| 27723 |
tejbeer |
324 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
325 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
326 |
model.addAttribute("leadActivityMap", leadActivityMap);
|
|
|
327 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
328 |
}
|
|
|
329 |
|
| 29266 |
manish |
330 |
ChartLeadModel cm = this.getLeadChart(leads);
|
|
|
331 |
model.addAttribute("chartLead", gson.toJson(cm));
|
|
|
332 |
|
|
|
333 |
LOGGER.info("ChartLeadModel" + gson.toJson(cm));
|
|
|
334 |
LOGGER.info("lwDays" + lwDays);
|
|
|
335 |
|
| 27610 |
tejbeer |
336 |
LOGGER.info("leads" + leads);
|
| 25979 |
tejbeer |
337 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
|
|
338 |
.collect(Collectors.toList());
|
|
|
339 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 29266 |
manish |
340 |
LocalDate lastDate = curDate.minusDays(1).toLocalDate();
|
| 29426 |
manish |
341 |
|
| 29266 |
manish |
342 |
List<LocalDate> weekDates = new ArrayList<>();
|
| 29426 |
manish |
343 |
|
| 29266 |
manish |
344 |
weekDates.add(curDate.minusDays(28).toLocalDate());
|
|
|
345 |
weekDates.add(curDate.minusDays(22).toLocalDate());
|
|
|
346 |
weekDates.add(curDate.minusDays(21).toLocalDate());
|
|
|
347 |
weekDates.add(curDate.minusDays(15).toLocalDate());
|
|
|
348 |
weekDates.add(curDate.minusDays(14).toLocalDate());
|
|
|
349 |
weekDates.add(curDate.minusDays(8).toLocalDate());
|
|
|
350 |
weekDates.add(curDate.minusDays(7).toLocalDate());
|
|
|
351 |
LOGGER.info("lastDate" + lastDate);
|
| 29426 |
manish |
352 |
|
| 29266 |
manish |
353 |
model.addAttribute("weekDates", weekDates);
|
| 29426 |
manish |
354 |
|
| 29445 |
manish |
355 |
model.addAttribute("leadDate", leadDate);
|
| 29266 |
manish |
356 |
model.addAttribute("lastDate", lastDate);
|
| 25979 |
tejbeer |
357 |
model.addAttribute("stateNames", stateNames);
|
| 31249 |
tejbeer |
358 |
|
|
|
359 |
model.addAttribute("communicationTypes", CommunicationType.values());
|
|
|
360 |
|
| 25979 |
tejbeer |
361 |
model.addAttribute("authUsers", authUsers);
|
| 27610 |
tejbeer |
362 |
model.addAttribute("lead", leads);
|
|
|
363 |
model.addAttribute("leadStatus", LeadStatus.values());
|
| 29266 |
manish |
364 |
model.addAttribute("leadLasts", leadLasts);
|
|
|
365 |
model.addAttribute("leadThirds", leadThirds);
|
|
|
366 |
model.addAttribute("leadSeconds", leadSeconds);
|
|
|
367 |
model.addAttribute("leadFirsts", leadFirsts);
|
|
|
368 |
model.addAttribute("lwDays", lwDays);
|
| 25979 |
tejbeer |
369 |
|
| 27610 |
tejbeer |
370 |
model.addAttribute("selectedLeadStatus", leadStatus.get(0));
|
| 31370 |
tejbeer |
371 |
|
|
|
372 |
List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
|
|
|
373 |
|
|
|
374 |
List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
|
|
|
375 |
|
|
|
376 |
model.addAttribute("brands", brands);
|
|
|
377 |
|
| 25979 |
tejbeer |
378 |
return "lead";
|
| 27642 |
tejbeer |
379 |
|
| 25979 |
tejbeer |
380 |
}
|
|
|
381 |
|
| 29266 |
manish |
382 |
public ChartLeadModel getLeadChart(List<Lead> leads) throws ProfitMandiBusinessException {
|
|
|
383 |
|
|
|
384 |
Map<LeadStatus, Long> leadStatusMap = leads.stream().collect(
|
|
|
385 |
Collectors.groupingBy(x -> x.getStatus(), Collectors.mapping(Lead::getStatus, Collectors.counting())));
|
|
|
386 |
|
| 29426 |
manish |
387 |
Map<String, Long> hotLeadsMap = leads.stream().collect(
|
|
|
388 |
Collectors.groupingBy(x -> x.getColor(), Collectors.mapping(Lead::getColor, Collectors.counting())));
|
|
|
389 |
|
|
|
390 |
LOGGER.info("hotLeadsMap" + hotLeadsMap);
|
| 29266 |
manish |
391 |
ChartLeadModel cm = new ChartLeadModel();
|
|
|
392 |
|
|
|
393 |
HashSet<LeadStatus> labels = new HashSet<LeadStatus>();
|
|
|
394 |
labels.addAll(leadStatusMap.keySet());
|
| 29445 |
manish |
395 |
|
| 30771 |
amit.gupta |
396 |
List<String> hotLeads = new ArrayList<>();
|
| 29426 |
manish |
397 |
hotLeads.addAll(leadStatusMap.keySet().stream().map(x -> x.toString()).collect(Collectors.toSet()));
|
|
|
398 |
hotLeads.add("HotLead");
|
| 29445 |
manish |
399 |
|
| 30771 |
amit.gupta |
400 |
List<String> hotLeadKeys = new ArrayList<>();
|
| 29445 |
manish |
401 |
|
| 29426 |
manish |
402 |
hotLeadKeys.add("HotLead");
|
|
|
403 |
List<String> hotLeadGreen = new ArrayList<>(hotLeadKeys);
|
| 29598 |
tejbeer |
404 |
|
| 29448 |
manish |
405 |
LOGGER.info("hotLeads" + hotLeads);
|
| 29445 |
manish |
406 |
|
| 29266 |
manish |
407 |
List<LeadStatus> labelList = new ArrayList<>(labels);
|
|
|
408 |
List<String> backgroundColor = new ArrayList<>();
|
| 29426 |
manish |
409 |
LOGGER.info("hotLeadKeys" + hotLeadKeys);
|
| 29266 |
manish |
410 |
List<Long> values = new ArrayList<>();
|
|
|
411 |
|
| 29448 |
manish |
412 |
for (String hotLead : hotLeads) {
|
| 29266 |
manish |
413 |
|
| 29448 |
manish |
414 |
if (hotLead.equals("pending")) {
|
| 29266 |
manish |
415 |
backgroundColor.add("pink");
|
| 29448 |
manish |
416 |
values.add(leadStatusMap.get(LeadStatus.pending));
|
| 29266 |
manish |
417 |
}
|
| 29448 |
manish |
418 |
if (hotLead.equals("notInterested")) {
|
| 29266 |
manish |
419 |
backgroundColor.add("red");
|
| 29448 |
manish |
420 |
values.add(leadStatusMap.get(LeadStatus.notInterested));
|
| 29266 |
manish |
421 |
}
|
| 29448 |
manish |
422 |
if (hotLead.equals("followUp")) {
|
| 29266 |
manish |
423 |
backgroundColor.add("#9ACD32");
|
| 29448 |
manish |
424 |
values.add(leadStatusMap.get(LeadStatus.followUp));
|
| 29266 |
manish |
425 |
}
|
| 29448 |
manish |
426 |
if (hotLead.equals("finalized")) {
|
| 29266 |
manish |
427 |
backgroundColor.add("blue");
|
| 29448 |
manish |
428 |
values.add(leadStatusMap.get(LeadStatus.finalized));
|
| 29445 |
manish |
429 |
}
|
| 29598 |
tejbeer |
430 |
|
| 29448 |
manish |
431 |
if (hotLead.equals("HotLead")) {
|
| 29426 |
manish |
432 |
backgroundColor.add("green");
|
|
|
433 |
values.add(hotLeadsMap.get("Green"));
|
| 29445 |
manish |
434 |
|
| 29266 |
manish |
435 |
}
|
| 29445 |
manish |
436 |
|
| 29266 |
manish |
437 |
}
|
|
|
438 |
LOGGER.info("labelList" + labelList);
|
|
|
439 |
|
|
|
440 |
LOGGER.info("backgroundColor" + backgroundColor);
|
|
|
441 |
LOGGER.info("labelsChartLead" + labels);
|
|
|
442 |
LeadStatusData data = new LeadStatusData();
|
|
|
443 |
data.setData(values);
|
|
|
444 |
data.setBackgroundColor(backgroundColor);
|
|
|
445 |
data.setLabel("DataSet 1");
|
|
|
446 |
|
|
|
447 |
PieLables label = new PieLables();
|
|
|
448 |
label.setFontColor("black");
|
|
|
449 |
label.setFontSize(15);
|
|
|
450 |
|
|
|
451 |
Legend legend = new Legend();
|
|
|
452 |
legend.setLabels(label);
|
|
|
453 |
legend.setPosition("left");
|
|
|
454 |
|
|
|
455 |
List<LeadStatusData> dataList = new ArrayList<>();
|
|
|
456 |
dataList.add(data);
|
|
|
457 |
|
|
|
458 |
DataLeadModel datasets = new DataLeadModel();
|
|
|
459 |
datasets.setDatasets(dataList);
|
| 29426 |
manish |
460 |
datasets.setLabels(hotLeads);
|
| 29266 |
manish |
461 |
|
|
|
462 |
OptionModel om = new OptionModel();
|
|
|
463 |
om.setLegend(legend);
|
|
|
464 |
|
|
|
465 |
cm.setType("pie");
|
|
|
466 |
cm.setData(datasets);
|
|
|
467 |
cm.setOptions(om);
|
|
|
468 |
|
|
|
469 |
return cm;
|
|
|
470 |
}
|
|
|
471 |
|
| 25988 |
tejbeer |
472 |
@RequestMapping(value = "/getClosedLead", method = RequestMethod.GET)
|
|
|
473 |
public String getClosedLead(HttpServletRequest request,
|
|
|
474 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
475 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
476 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
477 |
throws Exception {
|
|
|
478 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
479 |
List<Lead> leads = null;
|
|
|
480 |
long size = 0;
|
|
|
481 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
482 |
size = leadRepository.selectCountByStatus(status);
|
|
|
483 |
|
|
|
484 |
if (!leads.isEmpty()) {
|
|
|
485 |
List<Integer> authIds = new ArrayList<>();
|
|
|
486 |
for (Lead lead : leads) {
|
|
|
487 |
authIds.add(lead.getAssignTo());
|
|
|
488 |
}
|
|
|
489 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
490 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
491 |
|
|
|
492 |
model.addAttribute("leads", leads);
|
|
|
493 |
model.addAttribute("start", offset + 1);
|
|
|
494 |
model.addAttribute("size", size);
|
|
|
495 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
496 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
| 25990 |
tejbeer |
497 |
model.addAttribute("url", "/getPaginatedClosedLeads");
|
| 25988 |
tejbeer |
498 |
|
|
|
499 |
if (leads.size() < limit) {
|
|
|
500 |
model.addAttribute("end", offset + leads.size());
|
|
|
501 |
} else {
|
|
|
502 |
model.addAttribute("end", offset + limit);
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
} else {
|
|
|
506 |
model.addAttribute("lead", leads);
|
|
|
507 |
|
|
|
508 |
model.addAttribute("size", size);
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
model.addAttribute("authUsers", authUsers);
|
|
|
512 |
return "lead-close";
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
@RequestMapping(value = "/getPaginatedClosedLeads", method = RequestMethod.GET)
|
| 25990 |
tejbeer |
516 |
public String getPaginatedClosedLeads(HttpServletRequest request,
|
| 25988 |
tejbeer |
517 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
518 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
519 |
throws ProfitMandiBusinessException {
|
|
|
520 |
List<Lead> leads = null;
|
|
|
521 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
522 |
|
|
|
523 |
if (!leads.isEmpty()) {
|
|
|
524 |
List<Integer> authIds = new ArrayList<>();
|
|
|
525 |
for (Lead lead : leads) {
|
|
|
526 |
authIds.add(lead.getAssignTo());
|
|
|
527 |
}
|
|
|
528 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
529 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
530 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
531 |
model.addAttribute("leads", leads);
|
| 25990 |
tejbeer |
532 |
model.addAttribute("url", "/getPaginatedClosedLeads");
|
| 25988 |
tejbeer |
533 |
|
|
|
534 |
} else {
|
|
|
535 |
model.addAttribute("leads", leads);
|
|
|
536 |
|
|
|
537 |
}
|
|
|
538 |
return "lead-close-paginated";
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
@RequestMapping(value = "/searchLeads")
|
|
|
542 |
public String getClosedLeads(HttpServletRequest request,
|
|
|
543 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
544 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
545 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
546 |
throws ProfitMandiBusinessException {
|
|
|
547 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
548 |
List<Lead> leads = null;
|
|
|
549 |
long size = 0;
|
|
|
550 |
if (!(searchTerm.equals(""))) {
|
|
|
551 |
leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);
|
|
|
552 |
if (!(leads.size() == 0)) {
|
|
|
553 |
size = leadRepository.selectCountByStatus(status);
|
|
|
554 |
List<Integer> authIds = new ArrayList<>();
|
|
|
555 |
for (Lead lead : leads) {
|
|
|
556 |
authIds.add(lead.getAssignTo());
|
|
|
557 |
}
|
|
|
558 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
559 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
560 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
561 |
model.addAttribute("leads", leads);
|
|
|
562 |
model.addAttribute("start", offset + 1);
|
|
|
563 |
model.addAttribute("size", size);
|
|
|
564 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
565 |
|
|
|
566 |
if (leads.size() < limit) {
|
|
|
567 |
model.addAttribute("end", offset + leads.size());
|
|
|
568 |
} else {
|
|
|
569 |
model.addAttribute("end", offset + limit);
|
|
|
570 |
}
|
|
|
571 |
} else {
|
|
|
572 |
throw new ProfitMandiBusinessException("lead", searchTerm, "leads Not Found");
|
|
|
573 |
}
|
|
|
574 |
} else {
|
|
|
575 |
leads = leadRepository.selectAllByStatus(status, offset, limit);
|
|
|
576 |
size = leadRepository.selectCountByStatus(status);
|
|
|
577 |
|
|
|
578 |
if (!leads.isEmpty()) {
|
|
|
579 |
List<Integer> authIds = new ArrayList<>();
|
|
|
580 |
for (Lead lead : leads) {
|
|
|
581 |
authIds.add(lead.getAssignTo());
|
|
|
582 |
}
|
|
|
583 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
584 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
585 |
|
|
|
586 |
model.addAttribute("leads", leads);
|
|
|
587 |
model.addAttribute("start", offset + 1);
|
|
|
588 |
model.addAttribute("size", size);
|
|
|
589 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
590 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
591 |
|
|
|
592 |
if (leads.size() < limit) {
|
|
|
593 |
model.addAttribute("end", offset + leads.size());
|
|
|
594 |
} else {
|
|
|
595 |
model.addAttribute("end", offset + limit);
|
|
|
596 |
}
|
|
|
597 |
|
|
|
598 |
}
|
|
|
599 |
}
|
|
|
600 |
|
|
|
601 |
model.addAttribute("authUsers", authUsers);
|
|
|
602 |
return "lead-close";
|
|
|
603 |
}
|
|
|
604 |
|
|
|
605 |
@RequestMapping(value = "/searchLeadPaginated")
|
| 25990 |
tejbeer |
606 |
public String searchLeadPaginated(HttpServletRequest request,
|
| 25988 |
tejbeer |
607 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
608 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
609 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
610 |
throws ProfitMandiBusinessException {
|
|
|
611 |
LOGGER.info("In search Item....");
|
|
|
612 |
List<Lead> leads = null;
|
|
|
613 |
if (!searchTerm.equals("")) {
|
|
|
614 |
leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);
|
|
|
615 |
if (!(leads.size() == 0)) {
|
|
|
616 |
|
|
|
617 |
List<Integer> authIds = new ArrayList<>();
|
|
|
618 |
for (Lead lead : leads) {
|
|
|
619 |
authIds.add(lead.getAssignTo());
|
|
|
620 |
}
|
|
|
621 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream()
|
|
|
622 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
623 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
624 |
model.addAttribute("leads", leads);
|
|
|
625 |
}
|
|
|
626 |
}
|
|
|
627 |
|
|
|
628 |
return "lead-close-paginated";
|
|
|
629 |
|
|
|
630 |
}
|
|
|
631 |
|
| 25979 |
tejbeer |
632 |
@RequestMapping(value = "/getLeadActivity", method = RequestMethod.GET)
|
|
|
633 |
public String getLeadActivity(HttpServletRequest request, @RequestParam int leadId, Model model) throws Exception {
|
|
|
634 |
List<LeadActivity> leadActivity = leadActivityRepository.selectBYLeadId(leadId);
|
| 31249 |
tejbeer |
635 |
|
|
|
636 |
LOGGER.info("leadActivity" + leadActivity);
|
|
|
637 |
|
| 25979 |
tejbeer |
638 |
model.addAttribute("leadActivity", leadActivity);
|
| 31249 |
tejbeer |
639 |
model.addAttribute("authUserMap",
|
|
|
640 |
authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x)));
|
|
|
641 |
|
| 25979 |
tejbeer |
642 |
return "lead_activity_modal";
|
|
|
643 |
}
|
|
|
644 |
|
| 31370 |
tejbeer |
645 |
@RequestMapping(value = "/getLead", method = RequestMethod.GET)
|
|
|
646 |
public ResponseEntity<?> getLead(HttpServletRequest request, @RequestParam int leadId) throws Exception {
|
|
|
647 |
Lead lead = leadRepository.selectById(leadId);
|
|
|
648 |
|
|
|
649 |
LeadDetail leadDetail = leadDetailRepository.selectByLeadId(lead.getId());
|
|
|
650 |
if (leadDetail != null) {
|
|
|
651 |
lead.setOutLetName(leadDetail.getOutletName());
|
|
|
652 |
}
|
|
|
653 |
|
|
|
654 |
return responseSender.ok(lead);
|
|
|
655 |
|
|
|
656 |
}
|
|
|
657 |
|
| 25979 |
tejbeer |
658 |
@RequestMapping(value = "/createLead", method = RequestMethod.POST)
|
|
|
659 |
public String CreateLead(HttpServletRequest request, @RequestBody CreateRefferalRequest createRefferalRequest,
|
|
|
660 |
Model model) throws Exception {
|
|
|
661 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 31249 |
tejbeer |
662 |
|
| 25979 |
tejbeer |
663 |
LOGGER.info("createRefferalRequest" + createRefferalRequest.getSchelduleTimestamp());
|
|
|
664 |
Lead lead = new Lead();
|
|
|
665 |
lead.setFirstName(createRefferalRequest.getFirstName());
|
|
|
666 |
lead.setLastName(createRefferalRequest.getLastName());
|
|
|
667 |
lead.setLeadMobile(createRefferalRequest.getMobile());
|
|
|
668 |
lead.setState(createRefferalRequest.getState());
|
|
|
669 |
lead.setCity(createRefferalRequest.getCity());
|
|
|
670 |
lead.setAddress(createRefferalRequest.getAddress());
|
|
|
671 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
672 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
673 |
lead.setStatus(createRefferalRequest.getStatus());
|
|
|
674 |
lead.setAssignTo(createRefferalRequest.getAssignTo());
|
|
|
675 |
lead.setSource(createRefferalRequest.getSource());
|
| 26298 |
tejbeer |
676 |
lead.setColor("yellow");
|
| 25979 |
tejbeer |
677 |
// change
|
| 25989 |
tejbeer |
678 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 25979 |
tejbeer |
679 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
680 |
lead.setCreatedBy(authUserName);
|
|
|
681 |
lead.setAuthId(authUser.getId());
|
| 31422 |
amit.gupta |
682 |
LOGGER.info("lead --- {}", lead);
|
| 25979 |
tejbeer |
683 |
leadRepository.persist(lead);
|
|
|
684 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
685 |
leadActivity.setLeadId(lead.getId());
|
|
|
686 |
leadActivity.setRemark(createRefferalRequest.getRemark());
|
| 31249 |
tejbeer |
687 |
leadActivity.setAuthId(authUser.getId());
|
|
|
688 |
LOGGER.info("createRefferalRequest" + createRefferalRequest.getCommunicationType());
|
| 25979 |
tejbeer |
689 |
|
|
|
690 |
if (createRefferalRequest.getStatus() == LeadStatus.followUp) {
|
|
|
691 |
leadActivity.setSchelduleTimestamp(createRefferalRequest.getSchelduleTimestamp());
|
| 31249 |
tejbeer |
692 |
leadActivity.setCommunicationType(createRefferalRequest.getCommunicationType());
|
|
|
693 |
|
|
|
694 |
if (leadActivity.getCommunicationType().equals(CommunicationType.VISIT)) {
|
|
|
695 |
visitRequestRepository.createVisitRequest(lead.getId(), "lead", lead.getAssignTo(),
|
|
|
696 |
createRefferalRequest.getSchelduleTimestamp());
|
|
|
697 |
}
|
| 25979 |
tejbeer |
698 |
} else {
|
|
|
699 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
700 |
}
|
|
|
701 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
702 |
leadActivityRepository.persist(leadActivity);
|
| 31265 |
tejbeer |
703 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 31249 |
tejbeer |
704 |
|
| 25979 |
tejbeer |
705 |
return "response";
|
|
|
706 |
|
|
|
707 |
}
|
|
|
708 |
|
|
|
709 |
@RequestMapping(value = "/editLead", method = RequestMethod.POST)
|
| 27605 |
tejbeer |
710 |
public String EditLead(HttpServletRequest request,
|
|
|
711 |
@RequestBody CreateLeacdActivityRequest createLeadActivityRequest, Model model) throws Exception {
|
| 31249 |
tejbeer |
712 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25979 |
tejbeer |
713 |
|
| 31249 |
tejbeer |
714 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
715 |
|
| 31370 |
tejbeer |
716 |
LeadDetail leadDetail = leadDetailRepository.selectByLeadId(createLeadActivityRequest.getId());
|
|
|
717 |
|
| 31479 |
tejbeer |
718 |
if (leadDetail == null && !createLeadActivityRequest.getStatus().equals(LeadStatus.notInterested)) {
|
| 31370 |
tejbeer |
719 |
|
|
|
720 |
throw new ProfitMandiBusinessException("LeadDetail", "", "Please fill lead detail");
|
|
|
721 |
}
|
|
|
722 |
|
| 25979 |
tejbeer |
723 |
LeadActivity leadActivity = new LeadActivity();
|
| 27605 |
tejbeer |
724 |
leadActivity.setLeadId(createLeadActivityRequest.getId());
|
|
|
725 |
leadActivity.setRemark(createLeadActivityRequest.getRemark());
|
| 29598 |
tejbeer |
726 |
|
| 29476 |
manish |
727 |
LOGGER.info("createRefferalRequest" + createLeadActivityRequest);
|
| 27605 |
tejbeer |
728 |
|
|
|
729 |
if (createLeadActivityRequest.getStatus() == LeadStatus.followUp) {
|
|
|
730 |
leadActivity.setSchelduleTimestamp(createLeadActivityRequest.getScheldule());
|
| 31249 |
tejbeer |
731 |
leadActivity.setCommunicationType(createLeadActivityRequest.getCommunicationType());
|
|
|
732 |
if (leadActivity.getCommunicationType().equals(CommunicationType.VISIT)) {
|
|
|
733 |
visitRequestRepository.createVisitRequest(createLeadActivityRequest.getId(), "lead",
|
|
|
734 |
createLeadActivityRequest.getAssignTo(), createLeadActivityRequest.getScheldule());
|
|
|
735 |
}
|
| 27605 |
tejbeer |
736 |
} else {
|
|
|
737 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
738 |
}
|
| 25979 |
tejbeer |
739 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
| 31249 |
tejbeer |
740 |
leadActivity.setAuthId(authUser.getId());
|
| 25979 |
tejbeer |
741 |
leadActivityRepository.persist(leadActivity);
|
| 29598 |
tejbeer |
742 |
Lead lead = leadRepository.selectById(createLeadActivityRequest.getId());
|
| 27605 |
tejbeer |
743 |
lead.setAssignTo(createLeadActivityRequest.getAssignTo());
|
|
|
744 |
lead.setStatus(createLeadActivityRequest.getStatus());
|
| 28200 |
tejbeer |
745 |
lead.setNotinterestedReason(createLeadActivityRequest.getReason());
|
| 25979 |
tejbeer |
746 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
747 |
|
| 29473 |
manish |
748 |
lead = leadRepository.selectById(createLeadActivityRequest.getId());
|
| 29598 |
tejbeer |
749 |
|
| 29476 |
manish |
750 |
int authId = 0;
|
|
|
751 |
if (lead != null) {
|
| 25979 |
tejbeer |
752 |
|
| 29476 |
manish |
753 |
authId = lead.getAssignTo();
|
|
|
754 |
Map<Integer, LeadActivity> leadActivityMap = new HashMap<>();
|
| 29598 |
tejbeer |
755 |
|
|
|
756 |
List<LeadActivity> leadActivitys = leadActivityRepository.selectBYLeadId(lead.getId());
|
|
|
757 |
|
|
|
758 |
if (!leadActivitys.isEmpty()) {
|
|
|
759 |
leadActivityMap.put(lead.getId(), leadActivitys.get(0));
|
|
|
760 |
}
|
|
|
761 |
|
|
|
762 |
Map<Integer, AuthUser> authIdAndAuthUserMap = new HashMap<>();
|
|
|
763 |
AuthUser AuthUser = authRepository.selectById(authId);
|
|
|
764 |
|
|
|
765 |
authIdAndAuthUserMap.put(AuthUser.getId(), AuthUser);
|
|
|
766 |
|
| 29476 |
manish |
767 |
model.addAttribute("leadActivityMap", leadActivityMap);
|
|
|
768 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
769 |
}
|
|
|
770 |
|
| 29473 |
manish |
771 |
model.addAttribute("request", lead);
|
|
|
772 |
|
|
|
773 |
return "edit-lead";
|
|
|
774 |
|
| 25979 |
tejbeer |
775 |
}
|
| 29445 |
manish |
776 |
|
| 29426 |
manish |
777 |
@RequestMapping(value = "/downloadIvoryLead", method = RequestMethod.GET)
|
|
|
778 |
public ResponseEntity<?> downloadDelayDayTemplate(HttpServletRequest request) throws Exception {
|
| 29598 |
tejbeer |
779 |
List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName())
|
|
|
780 |
.collect(Collectors.toList());
|
|
|
781 |
|
| 29426 |
manish |
782 |
List<List<?>> rows = new ArrayList<>();
|
|
|
783 |
|
| 29598 |
tejbeer |
784 |
List<LeadSource> lss = LeadSource.enumValues;
|
| 29426 |
manish |
785 |
|
| 29598 |
tejbeer |
786 |
for (LeadSource ls : lss) {
|
|
|
787 |
rows.add(Arrays.asList("-", "-", "-", "-", "-", "-", "-", ls));
|
|
|
788 |
|
|
|
789 |
}
|
|
|
790 |
for (String stateName : stateNames) {
|
|
|
791 |
rows.add(Arrays.asList("-", "-", "-", "-", stateName, "-", "-", "-"));
|
|
|
792 |
|
|
|
793 |
}
|
|
|
794 |
|
|
|
795 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("First Name",
|
|
|
796 |
"Last Name", "Address", "City", "State", "Mobile", "Assign To(email)", "Source"), rows);
|
|
|
797 |
|
| 29426 |
manish |
798 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
799 |
headers.set("Content-Type", "text/csv");
|
| 29598 |
tejbeer |
800 |
headers.set("Content-disposition", "inline; filename=leads.format.csv");
|
| 29426 |
manish |
801 |
headers.setContentLength(baos.toByteArray().length);
|
|
|
802 |
|
|
|
803 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
804 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
805 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
806 |
|
|
|
807 |
}
|
| 29445 |
manish |
808 |
|
| 29426 |
manish |
809 |
@RequestMapping(value = "/csvFileAndSetLead", method = RequestMethod.POST)
|
|
|
810 |
public String readCsvFileAndSetLead(HttpServletRequest request, Model model, HttpServletResponse response,
|
|
|
811 |
@RequestPart MultipartFile file) throws Throwable {
|
|
|
812 |
|
| 29598 |
tejbeer |
813 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
814 |
String email = loginDetails.getEmailId();
|
|
|
815 |
|
|
|
816 |
AuthUser createdBy = authRepository.selectByEmailOrMobile(email);
|
|
|
817 |
|
| 29426 |
manish |
818 |
LOGGER.info("file" + file.toString());
|
|
|
819 |
|
|
|
820 |
String fileName = file.getName();
|
|
|
821 |
|
|
|
822 |
String fileNames = file.getOriginalFilename();
|
|
|
823 |
|
|
|
824 |
LOGGER.info("fileName" + fileName);
|
|
|
825 |
LOGGER.info("fileNames" + fileNames);
|
|
|
826 |
|
| 29598 |
tejbeer |
827 |
List<CSVRecord> records = FileUtil.readFile(file);
|
| 29426 |
manish |
828 |
|
| 29598 |
tejbeer |
829 |
for (CSVRecord record : records) {
|
| 29426 |
manish |
830 |
|
|
|
831 |
Lead lead = new Lead();
|
| 29598 |
tejbeer |
832 |
lead.setFirstName(record.get(0));
|
|
|
833 |
lead.setLastName(record.get(1));
|
|
|
834 |
lead.setAddress(record.get(2));
|
|
|
835 |
lead.setCity(record.get(3));
|
|
|
836 |
lead.setState(record.get(4));
|
|
|
837 |
lead.setLeadMobile(record.get(5));
|
|
|
838 |
LOGGER.info("record" + record.get(6));
|
| 29426 |
manish |
839 |
|
| 29598 |
tejbeer |
840 |
AuthUser assignTo = authRepository.selectByEmailOrMobile(record.get(6));
|
| 29426 |
manish |
841 |
|
| 29598 |
tejbeer |
842 |
if (assignTo == null) {
|
|
|
843 |
throw new ProfitMandiBusinessException("Assign To ", record.get(6), "email id not exist");
|
|
|
844 |
}
|
| 29445 |
manish |
845 |
|
| 29598 |
tejbeer |
846 |
lead.setAssignTo(assignTo.getId());
|
|
|
847 |
lead.setSource(record.get(7));
|
|
|
848 |
|
|
|
849 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
850 |
|
| 29426 |
manish |
851 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
852 |
lead.setStatus(LeadStatus.pending);
|
|
|
853 |
lead.setColor("yellow");
|
|
|
854 |
// change
|
| 29598 |
tejbeer |
855 |
lead.setCreatedBy(createdBy.getFullName());
|
|
|
856 |
lead.setAuthId(createdBy.getId());
|
| 29426 |
manish |
857 |
|
|
|
858 |
leadRepository.persist(lead);
|
|
|
859 |
|
|
|
860 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
861 |
leadActivity.setLeadId(lead.getId());
|
| 29598 |
tejbeer |
862 |
leadActivity.setRemark("New Lead");
|
| 29426 |
manish |
863 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
864 |
|
|
|
865 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
866 |
leadActivityRepository.persist(leadActivity);
|
| 31238 |
amit.gupta |
867 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 29426 |
manish |
868 |
|
|
|
869 |
}
|
|
|
870 |
|
|
|
871 |
model.addAttribute("responseSTG", mvcResponseSender.createResponseString(true));
|
|
|
872 |
|
|
|
873 |
return "response";
|
|
|
874 |
|
|
|
875 |
}
|
|
|
876 |
|
| 30185 |
tejbeer |
877 |
@RequestMapping(value = "/teamCommitment", method = RequestMethod.GET)
|
|
|
878 |
public String teamCommitments(HttpServletRequest request, Model model) throws Exception {
|
|
|
879 |
|
|
|
880 |
return "team-commitment";
|
|
|
881 |
|
|
|
882 |
}
|
|
|
883 |
|
| 31370 |
tejbeer |
884 |
@RequestMapping(value = "/leadDetail", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
885 |
public String leadDetail(HttpServletRequest request, @RequestBody LeadDetailModel leadDetailModel, Model model)
|
|
|
886 |
throws Exception {
|
|
|
887 |
|
|
|
888 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
889 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
890 |
LeadDetail leadDetail = leadDetailRepository.selectByLeadId(leadDetailModel.getLeadId());
|
|
|
891 |
if (leadDetail == null) {
|
|
|
892 |
leadDetail = new LeadDetail();
|
|
|
893 |
leadDetail.setLeadId(leadDetailModel.getLeadId());
|
|
|
894 |
leadDetail.setOutletName(leadDetailModel.getOutletName());
|
|
|
895 |
leadDetail.setCounterSize(leadDetailModel.getCounterSize());
|
|
|
896 |
leadDetail.setCreatedBy(authUser.getId());
|
|
|
897 |
|
| 31496 |
tejbeer |
898 |
LOGGER.info("dd {}", leadDetailModel.getFrontp(), leadDetailModel.getFrontWithMarket(),
|
|
|
899 |
leadDetailModel.getInternalLongShot(), leadDetailModel.getInternalLeftWall(),
|
|
|
900 |
leadDetailModel.getInternalRightWall());
|
|
|
901 |
|
| 31478 |
tejbeer |
902 |
if (leadDetailModel.getFrontp() != 0) {
|
|
|
903 |
leadDetail.setFrontp(leadDetailModel.getFrontp());
|
|
|
904 |
} else {
|
|
|
905 |
throw new ProfitMandiBusinessException("LeadDetail", "", "Front Image is Required");
|
| 31370 |
tejbeer |
906 |
|
| 31478 |
tejbeer |
907 |
}
|
|
|
908 |
|
|
|
909 |
if (leadDetailModel.getFrontWithMarket() != 0) {
|
|
|
910 |
leadDetail.setFrontWithMarket(leadDetailModel.getFrontWithMarket());
|
|
|
911 |
} else {
|
|
|
912 |
throw new ProfitMandiBusinessException("LeadDetail", "", "Front With Market Image is Required");
|
|
|
913 |
|
|
|
914 |
}
|
|
|
915 |
|
|
|
916 |
if (leadDetailModel.getInternalLongShot() != 0) {
|
|
|
917 |
|
|
|
918 |
leadDetail.setInternalLongShot(leadDetailModel.getInternalLongShot());
|
|
|
919 |
} else {
|
|
|
920 |
throw new ProfitMandiBusinessException("LeadDetail", "", "Internal Long Shot Image is Required");
|
|
|
921 |
|
|
|
922 |
}
|
|
|
923 |
|
|
|
924 |
if (leadDetailModel.getInternalLeftWall() != 0) {
|
|
|
925 |
|
|
|
926 |
leadDetail.setInternalLeftWall(leadDetailModel.getInternalLeftWall());
|
|
|
927 |
} else {
|
|
|
928 |
throw new ProfitMandiBusinessException("LeadDetail", "", "Internal Left Wall Image is Required");
|
|
|
929 |
|
|
|
930 |
}
|
|
|
931 |
if (leadDetailModel.getInternalRightWall() != 0) {
|
|
|
932 |
|
|
|
933 |
leadDetail.setInternalRightWall(leadDetailModel.getInternalRightWall());
|
|
|
934 |
} else {
|
|
|
935 |
throw new ProfitMandiBusinessException("LeadDetail", "", "Internal Right Wall Image is Required");
|
|
|
936 |
|
|
|
937 |
}
|
|
|
938 |
|
| 31370 |
tejbeer |
939 |
leadDetail.setCreatedTimestamp(LocalDateTime.now());
|
|
|
940 |
|
|
|
941 |
leadDetailRepository.persist(leadDetail);
|
|
|
942 |
for (LeadBrandModel leadBrandModel : leadDetailModel.getLeadBrands()) {
|
|
|
943 |
|
|
|
944 |
LeadBrand leadBrand = new LeadBrand();
|
|
|
945 |
leadBrand.setBrand(leadBrandModel.getBrand());
|
| 31408 |
tejbeer |
946 |
leadBrand.setValue(leadBrandModel.getValue());
|
| 31370 |
tejbeer |
947 |
leadBrand.setLeadDetailId(leadDetail.getId());
|
|
|
948 |
leadBrand.setLeadId(leadDetail.getLeadId());
|
|
|
949 |
leadBrand.setCreatedTimestamp(LocalDateTime.now());
|
|
|
950 |
leadBrandRepository.persist(leadBrand);
|
|
|
951 |
|
|
|
952 |
}
|
|
|
953 |
} else {
|
|
|
954 |
throw new ProfitMandiBusinessException("LeadDetail", "", "Lead Detail Already Created");
|
|
|
955 |
}
|
|
|
956 |
|
|
|
957 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
958 |
|
|
|
959 |
return "response";
|
|
|
960 |
|
|
|
961 |
}
|
|
|
962 |
|
|
|
963 |
@RequestMapping(value = "/getLeadDetail", method = RequestMethod.GET)
|
|
|
964 |
public String getLeadDetail(HttpServletRequest request, Model model) throws Exception {
|
| 31477 |
tejbeer |
965 |
List<Integer> followUpleadIds = leadRepository.selectAllByStatus(LeadStatus.followUp).stream()
|
|
|
966 |
.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
967 |
List<LeadDetail> leadDetails = leadDetailRepository.selectByLeadIds(followUpleadIds);
|
| 31370 |
tejbeer |
968 |
|
|
|
969 |
List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
|
|
|
970 |
|
|
|
971 |
List<String> brands = mobileBrands.stream().map(x -> (String) x.get("name")).collect(Collectors.toList());
|
|
|
972 |
|
|
|
973 |
model.addAttribute("brands", brands);
|
|
|
974 |
if (!leadDetails.isEmpty()) {
|
|
|
975 |
|
|
|
976 |
List<Integer> detailsIds = leadDetails.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
977 |
|
|
|
978 |
List<Integer> leadIds = leadDetails.stream().map(x -> x.getLeadId()).collect(Collectors.toList());
|
|
|
979 |
|
|
|
980 |
Map<Integer, Lead> leadMap = leadRepository.selectAllByIds(leadIds).stream()
|
| 31477 |
tejbeer |
981 |
.filter(x -> x.getStatus().equals(LeadStatus.followUp))
|
| 31370 |
tejbeer |
982 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
983 |
|
|
|
984 |
Map<Integer, Optional<LeadActivity>> leadActivityMap = leadActivityRepository.selectAllByleadIds(leadIds)
|
|
|
985 |
.stream().collect(Collectors.groupingBy(x -> x.getLeadId(),
|
| 31454 |
tejbeer |
986 |
Collectors.maxBy(Comparator.comparing(LeadActivity::getId))));
|
| 31370 |
tejbeer |
987 |
|
|
|
988 |
model.addAttribute("leadActivityMap", leadActivityMap);
|
|
|
989 |
|
|
|
990 |
List<LeadBrand> leadBrands = leadBrandRepository.selectByLeadDetailId(detailsIds);
|
|
|
991 |
|
|
|
992 |
LOGGER.info("leadBrands {}" + leadBrands);
|
|
|
993 |
|
|
|
994 |
Map<Integer, Map<String, Integer>> leadDetailBrandValue = new HashMap<>();
|
|
|
995 |
|
|
|
996 |
Map<Integer, List<LeadBrand>> leadDetail = leadBrands.stream()
|
|
|
997 |
.collect(Collectors.groupingBy(x -> x.getLeadDetailId(), Collectors.toList()));
|
|
|
998 |
|
|
|
999 |
for (Entry<Integer, List<LeadBrand>> leadDetailEntry : leadDetail.entrySet()) {
|
|
|
1000 |
|
|
|
1001 |
Map<String, Integer> brandValue = new HashMap<>();
|
|
|
1002 |
|
|
|
1003 |
for (LeadBrand leadBrand : leadDetailEntry.getValue()) {
|
|
|
1004 |
brandValue.put(leadBrand.getBrand(), leadBrand.getValue());
|
|
|
1005 |
|
|
|
1006 |
}
|
|
|
1007 |
leadDetailBrandValue.put(leadDetailEntry.getKey(), brandValue);
|
|
|
1008 |
}
|
|
|
1009 |
|
|
|
1010 |
LOGGER.info("leadDetailBrandValue {}" + leadDetailBrandValue);
|
|
|
1011 |
|
|
|
1012 |
model.addAttribute("leadDetailBrandValue", leadDetailBrandValue);
|
|
|
1013 |
|
|
|
1014 |
model.addAttribute("leadMap", leadMap);
|
|
|
1015 |
}
|
|
|
1016 |
|
|
|
1017 |
model.addAttribute("leadDetails", leadDetails);
|
|
|
1018 |
|
|
|
1019 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllActiveUser().stream()
|
|
|
1020 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1021 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
1022 |
|
|
|
1023 |
return "lead-detail";
|
|
|
1024 |
|
|
|
1025 |
}
|
|
|
1026 |
|
|
|
1027 |
@RequestMapping(value = "/getLeadDetailByLeadId", method = RequestMethod.GET)
|
|
|
1028 |
public ResponseEntity<?> getLeadDetailByLeadId(HttpServletRequest request, @RequestParam int leadId, Model model)
|
|
|
1029 |
throws Exception {
|
|
|
1030 |
|
|
|
1031 |
LeadDetail leadDetail = leadDetailRepository.selectByLeadId(leadId);
|
|
|
1032 |
return responseSender.ok(leadDetail);
|
|
|
1033 |
|
|
|
1034 |
}
|
|
|
1035 |
|
| 30185 |
tejbeer |
1036 |
@RequestMapping(value = "/getTeamCommitment", method = RequestMethod.GET)
|
|
|
1037 |
public String getTeamCommitments(HttpServletRequest request, @RequestParam LocalDateTime date, Model model)
|
|
|
1038 |
throws Exception {
|
|
|
1039 |
|
|
|
1040 |
List<TeamCommitmentModel> commitments = partnerCollectionPlanRepository
|
|
|
1041 |
.selectTeamCommitmentByDate(date.toLocalDate());
|
|
|
1042 |
|
|
|
1043 |
model.addAttribute("commitments", commitments);
|
|
|
1044 |
return "team-commitment-table";
|
|
|
1045 |
|
|
|
1046 |
}
|
| 30416 |
tejbeer |
1047 |
|
|
|
1048 |
@RequestMapping(value = "/partnerHealth", method = RequestMethod.GET)
|
|
|
1049 |
public String partnerHealth(HttpServletRequest request,
|
|
|
1050 |
@RequestParam(name = "email", required = false) String email, Model model) throws Exception {
|
|
|
1051 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1052 |
|
|
|
1053 |
if (StringUtils.isEmpty(email)) {
|
|
|
1054 |
email = loginDetails.getEmailId();
|
|
|
1055 |
} else {
|
|
|
1056 |
AuthUser selectedUser = authRepository.selectByEmailOrMobile(email);
|
|
|
1057 |
|
|
|
1058 |
model.addAttribute("selectedUser", selectedUser);
|
|
|
1059 |
|
|
|
1060 |
}
|
|
|
1061 |
|
|
|
1062 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1063 |
|
|
|
1064 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 30771 |
amit.gupta |
1065 |
List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(email));
|
| 30416 |
tejbeer |
1066 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
| 30771 |
amit.gupta |
1067 |
if (fofoIds != null && fofoIds.size() > 0) {
|
|
|
1068 |
List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
| 30416 |
tejbeer |
1069 |
.filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
|
|
|
1070 |
|
|
|
1071 |
Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = partnerCollectionService
|
|
|
1072 |
.getCollectionMap(fofoIdList, startDate);
|
|
|
1073 |
|
| 30434 |
tejbeer |
1074 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIdList);
|
|
|
1075 |
|
|
|
1076 |
LOGGER.info("remarkIds {}", remarkIds);
|
|
|
1077 |
|
|
|
1078 |
long todayOverallCall = 0;
|
|
|
1079 |
if (!remarkIds.isEmpty()) {
|
|
|
1080 |
|
| 30459 |
tejbeer |
1081 |
if (authUser.getEmailId().equals(email)) {
|
| 30458 |
tejbeer |
1082 |
|
|
|
1083 |
todayOverallCall = partnerCollectionRemarkRepository.selectByIds(remarkIds).stream()
|
|
|
1084 |
.filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
|
|
1085 |
.collect(Collectors.counting());
|
|
|
1086 |
} else {
|
|
|
1087 |
|
|
|
1088 |
todayOverallCall = partnerCollectionRemarkRepository
|
|
|
1089 |
.selectByAuthIdAndIds(authRepository.selectByEmailOrMobile(email).getId(), remarkIds)
|
|
|
1090 |
.stream().filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
|
|
1091 |
.collect(Collectors.counting());
|
|
|
1092 |
|
|
|
1093 |
}
|
|
|
1094 |
|
| 30434 |
tejbeer |
1095 |
}
|
| 30781 |
tejbeer |
1096 |
ChartLeadModel cm = new ChartLeadModel();
|
| 30434 |
tejbeer |
1097 |
|
| 30781 |
tejbeer |
1098 |
if (!foundCollectionMap.isEmpty()) {
|
|
|
1099 |
cm = this.getCollectionCount(foundCollectionMap.values().stream().collect(Collectors.toList()));
|
|
|
1100 |
|
|
|
1101 |
}
|
| 30416 |
tejbeer |
1102 |
model.addAttribute("chartPartnerHealth", gson.toJson(cm));
|
|
|
1103 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
|
|
|
1104 |
|
|
|
1105 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
|
|
|
1106 |
.selectAll(fofoIdList, startDate.toLocalDate().minusDays(1));
|
|
|
1107 |
if (!partnerDailyInvestments.isEmpty()) {
|
|
|
1108 |
partnerDailyInvestmentMap = partnerDailyInvestments.stream()
|
|
|
1109 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
1110 |
}
|
|
|
1111 |
|
|
|
1112 |
Map<LocalDate, Map<Integer, PartnerCollectionPlanModel>> pcpmMap = new TreeMap<>();
|
|
|
1113 |
for (int i = 0; i <= 6; i++) {
|
|
|
1114 |
|
|
|
1115 |
Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService
|
|
|
1116 |
.getCollectionMap(fofoIdList, startDate.minusDays(i));
|
|
|
1117 |
|
|
|
1118 |
pcpmMap.put(startDate.minusDays(i).toLocalDate(), collectionMap);
|
|
|
1119 |
}
|
|
|
1120 |
|
|
|
1121 |
Map<Integer, PartnerCollectionPlanModel> todayPcpmMap = pcpmMap.get(startDate.toLocalDate());
|
|
|
1122 |
model.addAttribute("todayPcpmMap", todayPcpmMap);
|
| 30445 |
tejbeer |
1123 |
|
| 30808 |
tejbeer |
1124 |
TotalTargetColectionModel totalTargetCollection = partnerCollectionService
|
|
|
1125 |
.getTotalTargetCollection(todayPcpmMap, startDate);
|
|
|
1126 |
model.addAttribute("totalPartnerTargetCollection", totalTargetCollection.getTotalTarget());
|
| 30445 |
tejbeer |
1127 |
|
| 30808 |
tejbeer |
1128 |
model.addAttribute("totalPartnerAchievement", totalTargetCollection.getTotalAchievement());
|
| 30445 |
tejbeer |
1129 |
|
| 30426 |
tejbeer |
1130 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 30582 |
tejbeer |
1131 |
Map<Integer, CustomRetailer> customRetailers = fofoIdList.stream().distinct()
|
|
|
1132 |
.map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream()
|
| 30426 |
tejbeer |
1133 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 30416 |
tejbeer |
1134 |
List<Integer> allReportees = authService.getAllReportees(authUser.getId());
|
| 30420 |
tejbeer |
1135 |
|
| 30416 |
tejbeer |
1136 |
List<Integer> salesPositionsAuthIds = positionRepository
|
|
|
1137 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES).stream()
|
|
|
1138 |
.map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
|
|
1139 |
List<Integer> rbmPositionsAuthIds = positionRepository
|
|
|
1140 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM).stream()
|
|
|
1141 |
.map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
|
|
1142 |
|
|
|
1143 |
salesPositionsAuthIds.addAll(rbmPositionsAuthIds);
|
|
|
1144 |
|
|
|
1145 |
Set<Integer> empHierarchy = allReportees.stream().filter(x -> salesPositionsAuthIds.contains(x))
|
|
|
1146 |
.collect(Collectors.toSet());
|
|
|
1147 |
|
|
|
1148 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(new ArrayList<>(empHierarchy));
|
|
|
1149 |
|
| 30441 |
tejbeer |
1150 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAll().stream()
|
|
|
1151 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1152 |
|
|
|
1153 |
LOGGER.info("todayPcpmMap {}", todayPcpmMap);
|
|
|
1154 |
|
| 30416 |
tejbeer |
1155 |
model.addAttribute("authUsers", authUsers);
|
| 30441 |
tejbeer |
1156 |
model.addAttribute("authUserMap", authUserMap);
|
| 30416 |
tejbeer |
1157 |
model.addAttribute("partnerCollectionPlanMap", pcpmMap);
|
|
|
1158 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
|
|
1159 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
1160 |
model.addAttribute("rankColorMap", ProfitMandiConstants.Rank_Color_Map);
|
| 30434 |
tejbeer |
1161 |
model.addAttribute("todayOverallCall", todayOverallCall);
|
| 30416 |
tejbeer |
1162 |
|
|
|
1163 |
}
|
|
|
1164 |
return "partner-health";
|
|
|
1165 |
|
|
|
1166 |
}
|
|
|
1167 |
|
|
|
1168 |
public ChartLeadModel getCollectionCount(List<PartnerCollectionPlanModel> pcpm)
|
|
|
1169 |
throws ProfitMandiBusinessException {
|
|
|
1170 |
|
|
|
1171 |
Map<Integer, Long> rankCount = pcpm.stream().collect(Collectors.groupingBy(x -> x.getRank(),
|
|
|
1172 |
Collectors.mapping(PartnerCollectionPlanModel::getRank, Collectors.counting())));
|
|
|
1173 |
|
|
|
1174 |
ChartLeadModel cm = new ChartLeadModel();
|
|
|
1175 |
|
| 30771 |
amit.gupta |
1176 |
List<String> labels = new ArrayList<>();
|
| 30416 |
tejbeer |
1177 |
labels.add("Plan for Today");
|
|
|
1178 |
labels.add("Carry Forward");
|
|
|
1179 |
labels.add("Untouched");
|
|
|
1180 |
labels.add("Plan for Future");
|
|
|
1181 |
labels.add("Normal");
|
|
|
1182 |
|
|
|
1183 |
List<String> backgroundColor = new ArrayList<>();
|
|
|
1184 |
List<Long> values = new ArrayList<>();
|
|
|
1185 |
|
|
|
1186 |
for (String label : labels) {
|
|
|
1187 |
|
|
|
1188 |
if (label.equals("Plan for Today")) {
|
|
|
1189 |
backgroundColor.add("#007bff");
|
|
|
1190 |
values.add(rankCount.get(1));
|
|
|
1191 |
}
|
|
|
1192 |
if (label.equals("Carry Forward")) {
|
|
|
1193 |
backgroundColor.add("#ffc107");
|
|
|
1194 |
values.add(rankCount.get(2));
|
|
|
1195 |
}
|
|
|
1196 |
if (label.equals("Untouched")) {
|
|
|
1197 |
backgroundColor.add("#dc3545");
|
|
|
1198 |
values.add(rankCount.get(3));
|
|
|
1199 |
}
|
|
|
1200 |
if (label.equals("Plan for Future")) {
|
|
|
1201 |
backgroundColor.add("#6c757d");
|
|
|
1202 |
values.add(rankCount.get(4));
|
|
|
1203 |
}
|
|
|
1204 |
if (label.equals("Normal")) {
|
|
|
1205 |
backgroundColor.add("White");
|
|
|
1206 |
values.add(rankCount.get(5));
|
|
|
1207 |
}
|
|
|
1208 |
|
|
|
1209 |
}
|
|
|
1210 |
|
|
|
1211 |
LOGGER.info("backgroundColor" + backgroundColor);
|
|
|
1212 |
LOGGER.info("labelsChartLead" + labels);
|
|
|
1213 |
LeadStatusData data = new LeadStatusData();
|
|
|
1214 |
data.setData(values);
|
|
|
1215 |
data.setBackgroundColor(backgroundColor);
|
|
|
1216 |
data.setLabel("DataSet 1");
|
|
|
1217 |
|
|
|
1218 |
PieLables label = new PieLables();
|
|
|
1219 |
label.setFontColor("black");
|
|
|
1220 |
label.setFontSize(15);
|
|
|
1221 |
|
|
|
1222 |
Legend legend = new Legend();
|
|
|
1223 |
legend.setLabels(label);
|
|
|
1224 |
legend.setPosition("left");
|
|
|
1225 |
|
|
|
1226 |
List<LeadStatusData> dataList = new ArrayList<>();
|
|
|
1227 |
dataList.add(data);
|
|
|
1228 |
|
|
|
1229 |
DataLeadModel datasets = new DataLeadModel();
|
|
|
1230 |
datasets.setDatasets(dataList);
|
|
|
1231 |
datasets.setLabels(labels);
|
|
|
1232 |
|
|
|
1233 |
OptionModel om = new OptionModel();
|
|
|
1234 |
om.setLegend(legend);
|
|
|
1235 |
|
|
|
1236 |
cm.setType("pie");
|
|
|
1237 |
cm.setData(datasets);
|
|
|
1238 |
cm.setOptions(om);
|
|
|
1239 |
|
|
|
1240 |
return cm;
|
|
|
1241 |
}
|
|
|
1242 |
|
| 30522 |
tejbeer |
1243 |
@RequestMapping(value = "/franchiseVisit", method = RequestMethod.GET)
|
|
|
1244 |
public String franchiseVisit(HttpServletRequest request,
|
|
|
1245 |
@RequestParam(name = "email", required = false) String email, Model model) throws Exception {
|
|
|
1246 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1247 |
|
|
|
1248 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1249 |
|
|
|
1250 |
List<Integer> salesPositionsAuthIds = positionRepository
|
|
|
1251 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES).stream()
|
|
|
1252 |
.map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
|
|
1253 |
List<Integer> rbmPositionsAuthIds = positionRepository
|
|
|
1254 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM).stream()
|
|
|
1255 |
.map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
|
|
1256 |
|
|
|
1257 |
salesPositionsAuthIds.addAll(rbmPositionsAuthIds);
|
|
|
1258 |
|
|
|
1259 |
List<Integer> allReportees = authService.getAllReportees(authUser.getId());
|
|
|
1260 |
|
|
|
1261 |
Set<Integer> empHierarchy = allReportees.stream().filter(x -> salesPositionsAuthIds.contains(x))
|
|
|
1262 |
.collect(Collectors.toSet());
|
|
|
1263 |
|
|
|
1264 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(new ArrayList<>(empHierarchy));
|
|
|
1265 |
|
|
|
1266 |
Map<Integer, String> monthValueMap = new HashMap<>();
|
|
|
1267 |
for (int i = 0; i <= 5; i++) {
|
|
|
1268 |
LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
|
|
|
1269 |
monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
|
|
|
1270 |
}
|
|
|
1271 |
|
|
|
1272 |
model.addAttribute("authUsers", authUsers);
|
|
|
1273 |
model.addAttribute("monthValueMap", monthValueMap);
|
|
|
1274 |
|
|
|
1275 |
return "franchise-visit";
|
|
|
1276 |
|
|
|
1277 |
}
|
|
|
1278 |
|
|
|
1279 |
@RequestMapping(value = "/getFranchiseVisit", method = RequestMethod.GET)
|
|
|
1280 |
public String getFranchiseVisit(HttpServletRequest request,
|
|
|
1281 |
@RequestParam(name = "authId", required = false) int authId, int yearMonth, Model model) throws Exception {
|
|
|
1282 |
|
| 30582 |
tejbeer |
1283 |
LocalDateTime startDate = LocalDate.now().minusMonths(8).withDayOfMonth(1).atStartOfDay();
|
| 30522 |
tejbeer |
1284 |
LocalDateTime endDate = startDate.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
|
|
|
1285 |
|
|
|
1286 |
DateRangeModel drm = DateRangeModel.of(startDate, endDate);
|
|
|
1287 |
|
|
|
1288 |
List<FranchiseeVisit> visits = franchiseeVisitRepository.selectByAuthUserAndDateRange(drm, authId);
|
|
|
1289 |
|
|
|
1290 |
if (!visits.isEmpty()) {
|
|
|
1291 |
|
|
|
1292 |
Map<Integer, List<FranchiseeVisit>> franchiseeVisitMap = visits.stream()
|
|
|
1293 |
.collect(Collectors.groupingBy(x -> x.getScheduleTimestamp().getDayOfMonth()));
|
|
|
1294 |
|
|
|
1295 |
model.addAttribute("franchiseeVisitMap", franchiseeVisitMap);
|
|
|
1296 |
|
|
|
1297 |
}
|
|
|
1298 |
|
|
|
1299 |
model.addAttribute("visits", visits);
|
|
|
1300 |
model.addAttribute("monthLength", startDate.toLocalDate().lengthOfMonth());
|
|
|
1301 |
|
|
|
1302 |
// Calender
|
|
|
1303 |
|
|
|
1304 |
int Year = startDate.getYear(); // year
|
|
|
1305 |
int startDayOfMonth = 5;
|
|
|
1306 |
int spaces = startDayOfMonth;
|
|
|
1307 |
|
|
|
1308 |
int month = startDate.getMonthValue();
|
|
|
1309 |
|
|
|
1310 |
int[] days = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
1311 |
|
|
|
1312 |
LOGGER.info("visits {} ", visits);
|
|
|
1313 |
|
|
|
1314 |
if ((((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0)) && month == 2) {
|
|
|
1315 |
days[month] = 29;
|
|
|
1316 |
}
|
|
|
1317 |
|
|
|
1318 |
spaces = (days[month - 1] + spaces) % 7;
|
|
|
1319 |
|
|
|
1320 |
model.addAttribute("month", month);
|
|
|
1321 |
model.addAttribute("spaces", spaces);
|
|
|
1322 |
model.addAttribute("days", days);
|
|
|
1323 |
|
|
|
1324 |
return "franchise-visit-container";
|
|
|
1325 |
|
|
|
1326 |
}
|
|
|
1327 |
|
|
|
1328 |
@RequestMapping(value = "/getFranchiseeActivity", method = RequestMethod.GET)
|
|
|
1329 |
public String getFranchiseeActivity(HttpServletRequest request, int visitId, Model model) throws Exception {
|
|
|
1330 |
|
|
|
1331 |
List<FranchiseeActivity> franchiseeActivities = franchiseeActivityRepository.selectByFranchiseeVisitId(visitId);
|
|
|
1332 |
|
|
|
1333 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(visitId);
|
|
|
1334 |
|
|
|
1335 |
Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAll().stream()
|
|
|
1336 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1337 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
1338 |
|
|
|
1339 |
model.addAttribute("franchiseeVisit", franchiseeVisit);
|
|
|
1340 |
model.addAttribute("franchiseeActivity", franchiseeActivities.get(0));
|
|
|
1341 |
|
|
|
1342 |
return "franchie-visit-detail";
|
|
|
1343 |
|
|
|
1344 |
}
|
|
|
1345 |
|
| 30771 |
amit.gupta |
1346 |
@RequestMapping(value = "/indent/today_target", method = RequestMethod.GET)
|
|
|
1347 |
public String todayTarget(HttpServletRequest request, Model model) throws Exception {
|
|
|
1348 |
List<RBMPerformanceSummaryModel> summaryModels = new ArrayList<>();
|
|
|
1349 |
List<Integer> rbmPositionsAuthIds = positionRepository
|
| 30781 |
tejbeer |
1350 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM).stream()
|
|
|
1351 |
.filter(x -> Arrays.asList(EscalationType.L1, EscalationType.L2).contains(x.getEscalationType()))
|
| 30771 |
amit.gupta |
1352 |
.map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
|
|
1353 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 30781 |
tejbeer |
1354 |
List<TeamCommitmentModel> teamCommitmentModels = partnerCollectionPlanRepository
|
|
|
1355 |
.selectTeamCommitmentByDate(LocalDate.now());
|
|
|
1356 |
Map<Integer, Double> rbmSecondaryTargetMap = teamCommitmentModels.stream()
|
|
|
1357 |
.filter(x -> rbmPositionsAuthIds.contains(x.getAuthId()))
|
|
|
1358 |
.collect(Collectors.groupingBy(x -> x.getAuthId(),
|
|
|
1359 |
Collectors.summingDouble(x -> x.getTotalTarget() == null ? 0 : x.getTotalTarget())));
|
|
|
1360 |
Map<Integer, Double> rbmSecondaryMap = teamCommitmentModels.stream()
|
|
|
1361 |
.filter(x -> rbmPositionsAuthIds.contains(x.getAuthId()))
|
|
|
1362 |
.collect(Collectors.groupingBy(x -> x.getAuthId(),
|
|
|
1363 |
Collectors.summingDouble(x -> x.getTotalAchievement() == null ? 0 : x.getTotalAchievement())));
|
| 30771 |
amit.gupta |
1364 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
|
|
1365 |
for (int rbmAuthId : rbmPositionsAuthIds) {
|
|
|
1366 |
RBMPerformanceSummaryModel rbmPerformanceSummaryModel = new RBMPerformanceSummaryModel();
|
|
|
1367 |
rbmPerformanceSummaryModel.setAuthId(rbmAuthId);
|
|
|
1368 |
AuthUser authUser = authRepository.selectById(rbmAuthId);
|
|
|
1369 |
rbmPerformanceSummaryModel.setAuthName(authUser.getFullName());
|
|
|
1370 |
List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(authUser.getEmailId()));
|
|
|
1371 |
|
|
|
1372 |
if (fofoIds.size() > 0) {
|
| 30781 |
tejbeer |
1373 |
fofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream().filter(x -> !x.isInternal())
|
|
|
1374 |
.map(x -> x.getId()).collect(Collectors.toList());
|
| 30771 |
amit.gupta |
1375 |
|
| 30781 |
tejbeer |
1376 |
/*
|
|
|
1377 |
* Map<Integer, PartnerCollectionPlanModel> foundCollectionMap =
|
|
|
1378 |
* partnerCollectionService .getCollectionMap(fofoIds, startDate);
|
|
|
1379 |
*/
|
| 30771 |
amit.gupta |
1380 |
|
|
|
1381 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIds);
|
|
|
1382 |
|
|
|
1383 |
LOGGER.info("remarkIds {}", remarkIds);
|
|
|
1384 |
|
|
|
1385 |
long todayOverallCall = 0;
|
|
|
1386 |
if (!remarkIds.isEmpty()) {
|
|
|
1387 |
todayOverallCall = partnerCollectionRemarkRepository.selectByIds(remarkIds).stream()
|
|
|
1388 |
.filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
|
|
1389 |
.collect(Collectors.counting());
|
|
|
1390 |
|
|
|
1391 |
}
|
|
|
1392 |
|
|
|
1393 |
Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService
|
|
|
1394 |
.getCollectionMap(fofoIds, startDate);
|
|
|
1395 |
|
|
|
1396 |
ChartLeadModel cm = this
|
|
|
1397 |
.getCollectionCount(collectionMap.values().stream().collect(Collectors.toList()));
|
|
|
1398 |
|
| 30781 |
tejbeer |
1399 |
long collectionTarget = collectionMap.values().stream().filter(x -> x.getTargetPlan() != null)
|
|
|
1400 |
.collect(Collectors.summingLong(x -> x.getTargetPlan()));
|
|
|
1401 |
long collection = collectionMap.values().stream().filter(
|
|
|
1402 |
x -> x.getTargetPlan() != null && x.getTargetPlan() != 0 && x.getAchievementPlan() != null)
|
|
|
1403 |
.collect(Collectors.summingLong(x -> x.getAchievementPlan()));
|
| 30771 |
amit.gupta |
1404 |
rbmPerformanceSummaryModel.setChartLeadModel(cm);
|
|
|
1405 |
rbmPerformanceSummaryModel.setPartnersCommunicated(todayOverallCall);
|
|
|
1406 |
rbmPerformanceSummaryModel.setCollectionTarget(collectionTarget);
|
|
|
1407 |
rbmPerformanceSummaryModel.setCollection(collection);
|
| 30781 |
tejbeer |
1408 |
rbmPerformanceSummaryModel.setSecondaryTarget(rbmSecondaryTargetMap.get(rbmAuthId) == null ? 0
|
|
|
1409 |
: rbmSecondaryTargetMap.get(rbmAuthId).floatValue());
|
|
|
1410 |
rbmPerformanceSummaryModel.setSecondary(
|
|
|
1411 |
rbmSecondaryMap.get(rbmAuthId) == null ? 0 : rbmSecondaryMap.get(rbmAuthId).floatValue());
|
| 30771 |
amit.gupta |
1412 |
summaryModels.add(rbmPerformanceSummaryModel);
|
| 30781 |
tejbeer |
1413 |
// cm.getData().getDatasets().get(0).getData().;
|
|
|
1414 |
// cm.getData().getDatasets().get(0).getBackgroundColor();
|
|
|
1415 |
// cm.getData().getLabels()
|
| 30771 |
amit.gupta |
1416 |
|
|
|
1417 |
}
|
|
|
1418 |
}
|
|
|
1419 |
model.addAttribute("summaryModels", summaryModels);
|
|
|
1420 |
return "today_target";
|
|
|
1421 |
}
|
|
|
1422 |
|
| 31249 |
tejbeer |
1423 |
@RequestMapping(value = "/visitPlan", method = RequestMethod.GET)
|
|
|
1424 |
public String visitPlan(HttpServletRequest request, Model model) throws Exception {
|
|
|
1425 |
|
|
|
1426 |
return "visit-request-plan";
|
|
|
1427 |
}
|
|
|
1428 |
|
|
|
1429 |
@RequestMapping(value = "/visit/getVisitPlan", method = RequestMethod.GET)
|
|
|
1430 |
public String getVisitPlan(HttpServletRequest request, @RequestParam LocalDate date, Model model) throws Exception {
|
|
|
1431 |
List<VisitRequest> visitRequests = visitRequestRepository.selectByAuthIdAndDate(date);
|
|
|
1432 |
|
|
|
1433 |
List<Integer> leadIds = visitRequests.stream().filter(x -> x.getVisitType().equals("lead"))
|
|
|
1434 |
.map(x -> x.getVisitId()).collect(Collectors.toList());
|
|
|
1435 |
Map<Integer, Lead> leadMap = new HashMap<>();
|
|
|
1436 |
if (!leadIds.isEmpty()) {
|
|
|
1437 |
List<Lead> leads = leadRepository.selectAllByIds(leadIds);
|
|
|
1438 |
|
|
|
1439 |
for (Lead lead : leads) {
|
|
|
1440 |
List<LeadActivity> leadActivities = leadActivityRepository.selectBYLeadId(lead.getId());
|
|
|
1441 |
lead.setScheduledTimestamp(leadActivities.get(0).getSchelduleTimestamp());
|
|
|
1442 |
lead.setLeadActivity(leadActivities.get(0));
|
|
|
1443 |
|
|
|
1444 |
leadMap.put(lead.getId(), lead);
|
|
|
1445 |
}
|
|
|
1446 |
|
|
|
1447 |
}
|
|
|
1448 |
List<Integer> franchiseeIds = visitRequests.stream().filter(x -> x.getVisitType().equals("franchiseeVisit"))
|
|
|
1449 |
.map(x -> x.getVisitId()).collect(Collectors.toList());
|
|
|
1450 |
Map<Integer, FranchiseeVisit> franchiseeVisitsMap = new HashMap<>();
|
|
|
1451 |
if (!franchiseeIds.isEmpty()) {
|
|
|
1452 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository.selectAllByIds(franchiseeIds);
|
|
|
1453 |
LOGGER.info("franchiseeVisits {}", franchiseeVisits);
|
|
|
1454 |
|
|
|
1455 |
for (FranchiseeVisit franchiseeVisit : franchiseeVisits) {
|
|
|
1456 |
List<FranchiseeActivity> franchiseeActivities = franchiseeActivityRepository
|
|
|
1457 |
.selectByFranchiseeVisitId(franchiseeVisit.getId());
|
|
|
1458 |
LOGGER.info("franchiseeActivities {}", franchiseeActivities);
|
|
|
1459 |
|
|
|
1460 |
franchiseeVisit.setScheduleTimestamp(franchiseeActivities.get(0).getSchelduleTimestamp());
|
|
|
1461 |
franchiseeVisit.setFranchiseeActivity(franchiseeActivities.get(0));
|
|
|
1462 |
|
|
|
1463 |
franchiseeVisitsMap.put(franchiseeVisit.getId(), franchiseeVisit);
|
|
|
1464 |
}
|
|
|
1465 |
|
|
|
1466 |
}
|
|
|
1467 |
|
|
|
1468 |
Map<Integer, List<VisitRequest>> visitRequestMap = visitRequests.stream()
|
|
|
1469 |
.collect(Collectors.groupingBy(x -> x.getCreatedBy()));
|
|
|
1470 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
1471 |
List<UserVisitModel> userVisits = new ArrayList<>();
|
|
|
1472 |
|
|
|
1473 |
for (AuthUser authUser : authUsers) {
|
|
|
1474 |
|
|
|
1475 |
List<VisitRequest> authVisitRequests = visitRequestMap.get(authUser.getId());
|
|
|
1476 |
|
|
|
1477 |
if (authVisitRequests != null) {
|
|
|
1478 |
UserVisitModel userVisitModel = new UserVisitModel();
|
|
|
1479 |
userVisitModel.setAuthUser(authUser.getFullName());
|
|
|
1480 |
List<VisitDescriptionModel> visitDescriptions = new ArrayList<>();
|
|
|
1481 |
|
|
|
1482 |
for (VisitRequest authVisitRequest : authVisitRequests) {
|
|
|
1483 |
VisitDescriptionModel visitDescriptionModel = new VisitDescriptionModel();
|
|
|
1484 |
visitDescriptionModel.setVisitId(authVisitRequest.getVisitId());
|
|
|
1485 |
|
|
|
1486 |
if (authVisitRequest.getVisitType().equals("lead")) {
|
|
|
1487 |
Lead lead = leadMap.get(authVisitRequest.getVisitId());
|
|
|
1488 |
|
|
|
1489 |
visitDescriptionModel.setVisitName(lead.getFirstName());
|
|
|
1490 |
visitDescriptionModel.setCity(lead.getCity());
|
|
|
1491 |
visitDescriptionModel.setState(lead.getState());
|
|
|
1492 |
visitDescriptionModel.setScheduleTime(lead.getScheduledTimestamp());
|
|
|
1493 |
visitDescriptionModel.setRemarks(lead.getLeadActivity().getRemark());
|
|
|
1494 |
|
|
|
1495 |
} else {
|
|
|
1496 |
FranchiseeVisit franchiseeVisit = franchiseeVisitsMap.get(authVisitRequest.getVisitId());
|
|
|
1497 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(franchiseeVisit.getFofoId());
|
|
|
1498 |
|
|
|
1499 |
visitDescriptionModel.setVisitName(franchiseeVisit.getPartnerName());
|
|
|
1500 |
visitDescriptionModel.setCity(customRetailer.getAddress().getCity());
|
|
|
1501 |
visitDescriptionModel.setState(customRetailer.getAddress().getState());
|
|
|
1502 |
visitDescriptionModel
|
|
|
1503 |
.setScheduleTime(franchiseeVisit.getFranchiseeActivity().getSchelduleTimestamp());
|
|
|
1504 |
visitDescriptionModel.setRemarks(franchiseeVisit.getAgenda());
|
|
|
1505 |
|
|
|
1506 |
}
|
|
|
1507 |
|
|
|
1508 |
if (authVisitRequest.getActionedBy() != 0) {
|
|
|
1509 |
AuthUser au = authRepository.selectById(authVisitRequest.getActionedBy());
|
|
|
1510 |
|
|
|
1511 |
visitDescriptionModel.setActionBy(au.getFullName());
|
|
|
1512 |
}
|
|
|
1513 |
visitDescriptionModel.setStatus(authVisitRequest.getStatus());
|
|
|
1514 |
visitDescriptionModel.setVisitType(authVisitRequest.getVisitType());
|
|
|
1515 |
visitDescriptions.add(visitDescriptionModel);
|
|
|
1516 |
}
|
|
|
1517 |
|
|
|
1518 |
userVisitModel.setVisitDescriptions(visitDescriptions);
|
|
|
1519 |
userVisits.add(userVisitModel);
|
|
|
1520 |
}
|
|
|
1521 |
|
|
|
1522 |
}
|
|
|
1523 |
|
|
|
1524 |
model.addAttribute("userVisits", userVisits);
|
|
|
1525 |
|
|
|
1526 |
return "visit-request-plan";
|
|
|
1527 |
}
|
| 25979 |
tejbeer |
1528 |
}
|