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