| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
- |
|
| 4 |
import java.io.InputStream;
|
- |
|
| 5 |
import java.time.LocalDate;
|
- |
|
| 6 |
import java.time.LocalDateTime;
|
- |
|
| 7 |
import java.time.format.DateTimeFormatter;
|
- |
|
| 8 |
import java.util.ArrayList;
|
- |
|
| 9 |
import java.util.Arrays;
|
- |
|
| 10 |
import java.util.Comparator;
|
- |
|
| 11 |
import java.util.HashMap;
|
- |
|
| 12 |
import java.util.HashSet;
|
- |
|
| 13 |
import java.util.List;
|
- |
|
| 14 |
import java.util.Map;
|
- |
|
| 15 |
import java.util.Map.Entry;
|
- |
|
| 16 |
import java.util.Optional;
|
- |
|
| 17 |
import java.util.Set;
|
- |
|
| 18 |
import java.util.TreeMap;
|
- |
|
| 19 |
import java.util.stream.Collectors;
|
- |
|
| 20 |
|
- |
|
| 21 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 22 |
import javax.servlet.http.HttpServletResponse;
|
- |
|
| 23 |
import javax.transaction.Transactional;
|
- |
|
| 24 |
|
- |
|
| 25 |
import org.apache.commons.csv.CSVRecord;
|
- |
|
| 26 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 27 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 28 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 29 |
import org.springframework.core.io.InputStreamResource;
|
- |
|
| 30 |
import org.springframework.http.HttpHeaders;
|
- |
|
| 31 |
import org.springframework.http.HttpStatus;
|
- |
|
| 32 |
import org.springframework.http.MediaType;
|
- |
|
| 33 |
import org.springframework.http.ResponseEntity;
|
- |
|
| 34 |
import org.springframework.stereotype.Controller;
|
- |
|
| 35 |
import org.springframework.ui.Model;
|
- |
|
| 36 |
import org.springframework.util.StringUtils;
|
- |
|
| 37 |
import org.springframework.web.bind.annotation.RequestBody;
|
- |
|
| 38 |
import org.springframework.web.bind.annotation.RequestMapping;
|
- |
|
| 39 |
import org.springframework.web.bind.annotation.RequestMethod;
|
- |
|
| 40 |
import org.springframework.web.bind.annotation.RequestParam;
|
- |
|
| 41 |
import org.springframework.web.bind.annotation.RequestPart;
|
- |
|
| 42 |
import org.springframework.web.multipart.MultipartFile;
|
- |
|
| 43 |
|
- |
|
| 44 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| 45 |
import com.mongodb.DBObject;
|
4 |
import com.mongodb.DBObject;
|
| 46 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 47 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
- |
|
| 48 |
import com.spice.profitmandi.common.model.Legend;
|
6 |
import com.spice.profitmandi.common.model.*;
|
| 49 |
import com.spice.profitmandi.common.model.OptionModel;
|
- |
|
| 50 |
import com.spice.profitmandi.common.model.PieLables;
|
- |
|
| 51 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
- |
|
| 52 |
import com.spice.profitmandi.common.util.FileUtil;
|
7 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 53 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
8 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 54 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
9 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| - |
|
10 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
| 55 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
11 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
| - |
|
12 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 56 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
13 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 57 |
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
|
- |
|
| 58 |
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
|
- |
|
| 59 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
14 |
import com.spice.profitmandi.dao.entity.user.*;
|
| 60 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
15 |
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
|
| 61 |
import com.spice.profitmandi.dao.entity.user.LeadBrand;
|
- |
|
| 62 |
import com.spice.profitmandi.dao.entity.user.LeadDetail;
|
- |
|
| 63 |
import com.spice.profitmandi.dao.entity.user.VisitRequest;
|
- |
|
| 64 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
16 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 65 |
import com.spice.profitmandi.dao.enumuration.dtr.CommunicationType;
|
17 |
import com.spice.profitmandi.dao.enumuration.dtr.CommunicationType;
|
| 66 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
|
18 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
|
| 67 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
19 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| 68 |
import com.spice.profitmandi.dao.model.ChartLeadModel;
|
- |
|
| 69 |
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
|
- |
|
| 70 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
- |
|
| 71 |
import com.spice.profitmandi.dao.model.DataLeadModel;
|
20 |
import com.spice.profitmandi.dao.model.*;
|
| 72 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
- |
|
| 73 |
import com.spice.profitmandi.dao.model.LeadBrandModel;
|
- |
|
| 74 |
import com.spice.profitmandi.dao.model.LeadDetailModel;
|
- |
|
| 75 |
import com.spice.profitmandi.dao.model.LeadStatusData;
|
- |
|
| 76 |
import com.spice.profitmandi.dao.model.PartnerCollectionPlanModel;
|
- |
|
| 77 |
import com.spice.profitmandi.dao.model.RBMPerformanceSummaryModel;
|
- |
|
| 78 |
import com.spice.profitmandi.dao.model.TeamCommitmentModel;
|
- |
|
| 79 |
import com.spice.profitmandi.dao.model.TotalTargetColectionModel;
|
- |
|
| 80 |
import com.spice.profitmandi.dao.model.UserVisitModel;
|
- |
|
| 81 |
import com.spice.profitmandi.dao.model.VisitDescriptionModel;
|
- |
|
| 82 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
21 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 83 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
|
22 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
|
| 84 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
23 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 85 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
24 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 86 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
25 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 87 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
- |
|
| 88 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeActivityRepository;
|
- |
|
| 89 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeVisitRepository;
|
- |
|
| 90 |
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
|
- |
|
| 91 |
import com.spice.profitmandi.dao.repository.dtr.LeadBrandRepository;
|
- |
|
| 92 |
import com.spice.profitmandi.dao.repository.dtr.LeadDetailRepository;
|
- |
|
| 93 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
- |
|
| 94 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
26 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 95 |
import com.spice.profitmandi.dao.repository.dtr.VisitRequestRepository;
|
- |
|
| 96 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
27 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 97 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
28 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 98 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
29 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 99 |
import com.spice.profitmandi.service.AuthService;
|
30 |
import com.spice.profitmandi.service.AuthService;
|
| 100 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
31 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
| 101 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
32 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
| 102 |
import com.spice.profitmandi.service.user.RetailerService;
|
33 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 103 |
import com.spice.profitmandi.web.model.LoginDetails;
|
34 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 104 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
35 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 105 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
36 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| - |
|
37 |
import org.apache.commons.csv.CSVRecord;
|
| - |
|
38 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
39 |
import org.apache.logging.log4j.Logger;
|
| - |
|
40 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
41 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
42 |
import org.springframework.http.HttpHeaders;
|
| - |
|
43 |
import org.springframework.http.HttpStatus;
|
| - |
|
44 |
import org.springframework.http.MediaType;
|
| - |
|
45 |
import org.springframework.http.ResponseEntity;
|
| - |
|
46 |
import org.springframework.stereotype.Controller;
|
| - |
|
47 |
import org.springframework.ui.Model;
|
| - |
|
48 |
import org.springframework.util.StringUtils;
|
| - |
|
49 |
import org.springframework.web.bind.annotation.*;
|
| - |
|
50 |
import org.springframework.web.multipart.MultipartFile;
|
| - |
|
51 |
|
| - |
|
52 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
53 |
import javax.servlet.http.HttpServletResponse;
|
| - |
|
54 |
import javax.transaction.Transactional;
|
| - |
|
55 |
import java.io.ByteArrayInputStream;
|
| - |
|
56 |
import java.io.InputStream;
|
| - |
|
57 |
import java.time.LocalDate;
|
| - |
|
58 |
import java.time.LocalDateTime;
|
| - |
|
59 |
import java.time.format.DateTimeFormatter;
|
| - |
|
60 |
import java.util.*;
|
| - |
|
61 |
import java.util.Map.Entry;
|
| - |
|
62 |
import java.util.stream.Collectors;
|
| 106 |
|
63 |
|
| 107 |
@Controller
|
64 |
@Controller
|
| 108 |
@Transactional(rollbackOn = Throwable.class)
|
65 |
@Transactional(rollbackOn = Throwable.class)
|
| 109 |
public class LeadController {
|
66 |
public class LeadController {
|
| 110 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
67 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
| Line 1287... |
Line 1244... |
| 1287 |
for (int rbmAuthId : rbmPositionsAuthIds) {
|
1244 |
for (int rbmAuthId : rbmPositionsAuthIds) {
|
| 1288 |
RBMPerformanceSummaryModel rbmPerformanceSummaryModel = new RBMPerformanceSummaryModel();
|
1245 |
RBMPerformanceSummaryModel rbmPerformanceSummaryModel = new RBMPerformanceSummaryModel();
|
| 1289 |
rbmPerformanceSummaryModel.setAuthId(rbmAuthId);
|
1246 |
rbmPerformanceSummaryModel.setAuthId(rbmAuthId);
|
| 1290 |
AuthUser authUser = authRepository.selectById(rbmAuthId);
|
1247 |
AuthUser authUser = authRepository.selectById(rbmAuthId);
|
| 1291 |
rbmPerformanceSummaryModel.setAuthName(authUser.getFullName());
|
1248 |
rbmPerformanceSummaryModel.setAuthName(authUser.getFullName());
|
| 1292 |
List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(authUser.getEmailId()));
|
1249 |
List<Integer> fofoIdList = new ArrayList<>(storeGuyMap.get(authUser.getEmailId()));
|
| - |
|
1250 |
|
| - |
|
1251 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIdList);
|
| - |
|
1252 |
|
| - |
|
1253 |
Map<Integer, PartnerCollectionRemark> partnerCollectionRemarks = new HashMap<>();
|
| - |
|
1254 |
|
| - |
|
1255 |
if (!remarkIds.isEmpty()) {
|
| - |
|
1256 |
partnerCollectionRemarks = partnerCollectionRemarkRepository.selectByIds(remarkIds).stream()
|
| - |
|
1257 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
1258 |
}
|
| - |
|
1259 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId()).stream().collect(Collectors.toList());
|
| - |
|
1260 |
boolean isRBMAndL1 = positions.stream()
|
| - |
|
1261 |
.anyMatch(position ->
|
| - |
|
1262 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId()
|
| - |
|
1263 |
&& EscalationType.L1.equals(position.getEscalationType()));
|
| - |
|
1264 |
|
| - |
|
1265 |
// this is creating for escalation filtered fofo id in case of if rbm is l1
|
| - |
|
1266 |
|
| - |
|
1267 |
List<Integer> fofoIds = fofoIdList;
|
| - |
|
1268 |
|
| - |
|
1269 |
if (isRBMAndL1) {
|
| - |
|
1270 |
fofoIds = partnerCollectionRemarks.entrySet().stream()
|
| - |
|
1271 |
// Filter for fofoIds where the escalation type is neither RBM nor Sale
|
| - |
|
1272 |
.filter(entry -> {
|
| - |
|
1273 |
PartnerCollectionRemark pcrMap = entry.getValue();
|
| - |
|
1274 |
return !(CollectionRemark.RBM_L2_ESCALATION.equals(pcrMap.getRemark())
|
| - |
|
1275 |
|| CollectionRemark.SALES_ESCALATION.equals(pcrMap.getRemark()));
|
| - |
|
1276 |
})
|
| - |
|
1277 |
.map(Map.Entry::getKey) // Map to the fofoId
|
| - |
|
1278 |
.collect(Collectors.toList()); // Collect the result as a List
|
| - |
|
1279 |
}
|
| 1293 |
|
1280 |
|
| 1294 |
if (fofoIds.size() > 0) {
|
1281 |
if (fofoIds.size() > 0) {
|
| 1295 |
fofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream().filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
|
1282 |
fofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream().filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
|
| 1296 |
|
1283 |
|
| 1297 |
/*
|
1284 |
/*
|
| 1298 |
* Map<Integer, PartnerCollectionPlanModel> foundCollectionMap =
|
1285 |
* Map<Integer, PartnerCollectionPlanModel> foundCollectionMap =
|
| 1299 |
* partnerCollectionService .getCollectionMap(fofoIds, startDate);
|
1286 |
* partnerCollectionService .getCollectionMap(fofoIds, startDate);
|
| 1300 |
*/
|
1287 |
*/
|
| 1301 |
|
1288 |
|
| 1302 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIds);
|
- |
|
| 1303 |
|
- |
|
| 1304 |
LOGGER.info("remarkIds {}", remarkIds);
|
1289 |
LOGGER.info("remarkIds {}", remarkIds);
|
| 1305 |
|
1290 |
|
| 1306 |
long todayOverallCall = 0;
|
1291 |
long todayOverallCall = 0;
|
| 1307 |
if (!remarkIds.isEmpty()) {
|
1292 |
if (!remarkIds.isEmpty()) {
|
| 1308 |
todayOverallCall = partnerCollectionRemarkRepository.selectByIds(remarkIds).stream().filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now())).collect(Collectors.counting());
|
1293 |
todayOverallCall = partnerCollectionRemarkRepository.selectByIds(remarkIds).stream().filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now())).collect(Collectors.counting());
|