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