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