| 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.HashMap;
|
- |
|
| 11 |
import java.util.HashSet;
|
- |
|
| 12 |
import java.util.List;
|
- |
|
| 13 |
import java.util.Map;
|
- |
|
| 14 |
import java.util.Map.Entry;
|
- |
|
| 15 |
import java.util.Set;
|
- |
|
| 16 |
import java.util.TreeMap;
|
- |
|
| 17 |
import java.util.function.Predicate;
|
- |
|
| 18 |
import java.util.stream.Collectors;
|
- |
|
| 19 |
|
- |
|
| 20 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 21 |
import javax.servlet.http.HttpServletResponse;
|
- |
|
| 22 |
import javax.transaction.Transactional;
|
- |
|
| 23 |
|
- |
|
| 24 |
import org.apache.commons.collections.map.HashedMap;
|
- |
|
| 25 |
import org.apache.commons.csv.CSVRecord;
|
- |
|
| 26 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 27 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 28 |
import org.jsoup.select.Evaluator.IsEmpty;
|
- |
|
| 29 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 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;
|
- |
|
| 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.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 46 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
- |
|
| 47 |
import com.spice.profitmandi.common.model.Legend;
|
5 |
import com.spice.profitmandi.common.model.*;
|
| 48 |
import com.spice.profitmandi.common.model.OptionModel;
|
- |
|
| 49 |
import com.spice.profitmandi.common.model.PieLables;
|
- |
|
| 50 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
- |
|
| 51 |
import com.spice.profitmandi.common.util.FileUtil;
|
6 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 52 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 53 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
- |
|
| 54 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
8 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 55 |
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
|
9 |
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
|
| 56 |
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
|
10 |
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
|
| 57 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
11 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
| 58 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
12 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
| 59 |
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
|
- |
|
| 60 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
|
13 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;
|
| 61 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
14 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| 62 |
import com.spice.profitmandi.dao.model.ChartLeadModel;
|
- |
|
| 63 |
import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;
|
- |
|
| 64 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
- |
|
| 65 |
import com.spice.profitmandi.dao.model.DataLeadModel;
|
15 |
import com.spice.profitmandi.dao.model.*;
|
| 66 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
- |
|
| 67 |
import com.spice.profitmandi.dao.model.LeadStatusData;
|
- |
|
| 68 |
import com.spice.profitmandi.dao.model.PartnerCollectionAchievementModel;
|
- |
|
| 69 |
import com.spice.profitmandi.dao.model.PartnerCollectionPlanModel;
|
- |
|
| 70 |
import com.spice.profitmandi.dao.model.TeamCommitmentModel;
|
- |
|
| 71 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
16 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 72 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
|
17 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
|
| 73 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
18 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 74 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
19 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 75 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
20 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 76 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
- |
|
| 77 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeActivityRepository;
|
- |
|
| 78 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeVisitRepository;
|
- |
|
| 79 |
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
|
- |
|
| 80 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
21 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 81 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
22 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 82 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
23 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 83 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
24 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 84 |
import com.spice.profitmandi.service.AuthService;
|
25 |
import com.spice.profitmandi.service.AuthService;
|
| 85 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
26 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
| 86 |
import com.spice.profitmandi.service.user.RetailerService;
|
27 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 87 |
import com.spice.profitmandi.web.model.LoginDetails;
|
28 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 88 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
29 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 89 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
30 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| - |
|
31 |
import org.apache.commons.csv.CSVRecord;
|
| - |
|
32 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
33 |
import org.apache.logging.log4j.Logger;
|
| - |
|
34 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
35 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
36 |
import org.springframework.http.HttpHeaders;
|
| - |
|
37 |
import org.springframework.http.HttpStatus;
|
| - |
|
38 |
import org.springframework.http.ResponseEntity;
|
| - |
|
39 |
import org.springframework.stereotype.Controller;
|
| - |
|
40 |
import org.springframework.ui.Model;
|
| - |
|
41 |
import org.springframework.util.StringUtils;
|
| - |
|
42 |
import org.springframework.web.bind.annotation.*;
|
| - |
|
43 |
import org.springframework.web.multipart.MultipartFile;
|
| - |
|
44 |
|
| - |
|
45 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
46 |
import javax.servlet.http.HttpServletResponse;
|
| - |
|
47 |
import javax.transaction.Transactional;
|
| - |
|
48 |
import java.io.ByteArrayInputStream;
|
| - |
|
49 |
import java.io.InputStream;
|
| - |
|
50 |
import java.time.LocalDate;
|
| - |
|
51 |
import java.time.LocalDateTime;
|
| - |
|
52 |
import java.time.format.DateTimeFormatter;
|
| - |
|
53 |
import java.util.*;
|
| - |
|
54 |
import java.util.Map.Entry;
|
| - |
|
55 |
import java.util.stream.Collectors;
|
| 90 |
|
56 |
|
| 91 |
@Controller
|
57 |
@Controller
|
| 92 |
@Transactional(rollbackOn = Throwable.class)
|
58 |
@Transactional(rollbackOn = Throwable.class)
|
| 93 |
public class LeadController {
|
59 |
public class LeadController {
|
| 94 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
60 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
| Line 398... |
Line 364... |
| 398 |
ChartLeadModel cm = new ChartLeadModel();
|
364 |
ChartLeadModel cm = new ChartLeadModel();
|
| 399 |
|
365 |
|
| 400 |
HashSet<LeadStatus> labels = new HashSet<LeadStatus>();
|
366 |
HashSet<LeadStatus> labels = new HashSet<LeadStatus>();
|
| 401 |
labels.addAll(leadStatusMap.keySet());
|
367 |
labels.addAll(leadStatusMap.keySet());
|
| 402 |
|
368 |
|
| 403 |
HashSet<String> hotLeads = new HashSet<String>();
|
369 |
List<String> hotLeads = new ArrayList<>();
|
| 404 |
hotLeads.addAll(leadStatusMap.keySet().stream().map(x -> x.toString()).collect(Collectors.toSet()));
|
370 |
hotLeads.addAll(leadStatusMap.keySet().stream().map(x -> x.toString()).collect(Collectors.toSet()));
|
| 405 |
hotLeads.add("HotLead");
|
371 |
hotLeads.add("HotLead");
|
| 406 |
|
372 |
|
| 407 |
HashSet<String> hotLeadKeys = new HashSet<String>();
|
373 |
List<String> hotLeadKeys = new ArrayList<>();
|
| 408 |
|
374 |
|
| 409 |
hotLeadKeys.add("HotLead");
|
375 |
hotLeadKeys.add("HotLead");
|
| 410 |
List<String> hotLeadGreen = new ArrayList<>(hotLeadKeys);
|
376 |
List<String> hotLeadGreen = new ArrayList<>(hotLeadKeys);
|
| 411 |
|
377 |
|
| 412 |
LOGGER.info("hotLeads" + hotLeads);
|
378 |
LOGGER.info("hotLeads" + hotLeads);
|
| Line 870... |
Line 836... |
| 870 |
}
|
836 |
}
|
| 871 |
|
837 |
|
| 872 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
838 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 873 |
|
839 |
|
| 874 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
840 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 875 |
Set<Integer> fofoIds = storeGuyMap.get(email);
|
841 |
List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(email));
|
| 876 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
842 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
| 877 |
if (fofoIds.size() > 0 && fofoIds != null) {
|
843 |
if (fofoIds != null && fofoIds.size() > 0) {
|
| 878 |
List<Integer> fofoIdl = new ArrayList<>(fofoIds);
|
- |
|
| 879 |
List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(fofoIdl).stream()
|
844 |
List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
| 880 |
.filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
|
845 |
.filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
|
| 881 |
|
846 |
|
| 882 |
Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = partnerCollectionService
|
847 |
Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = partnerCollectionService
|
| 883 |
.getCollectionMap(fofoIdList, startDate);
|
848 |
.getCollectionMap(fofoIdList, startDate);
|
| 884 |
|
849 |
|
| Line 1007... |
Line 972... |
| 1007 |
Map<Integer, Long> rankCount = pcpm.stream().collect(Collectors.groupingBy(x -> x.getRank(),
|
972 |
Map<Integer, Long> rankCount = pcpm.stream().collect(Collectors.groupingBy(x -> x.getRank(),
|
| 1008 |
Collectors.mapping(PartnerCollectionPlanModel::getRank, Collectors.counting())));
|
973 |
Collectors.mapping(PartnerCollectionPlanModel::getRank, Collectors.counting())));
|
| 1009 |
|
974 |
|
| 1010 |
ChartLeadModel cm = new ChartLeadModel();
|
975 |
ChartLeadModel cm = new ChartLeadModel();
|
| 1011 |
|
976 |
|
| 1012 |
HashSet<String> labels = new HashSet<String>();
|
977 |
List<String> labels = new ArrayList<>();
|
| 1013 |
labels.add("Plan for Today");
|
978 |
labels.add("Plan for Today");
|
| 1014 |
labels.add("Carry Forward");
|
979 |
labels.add("Carry Forward");
|
| 1015 |
labels.add("Untouched");
|
980 |
labels.add("Untouched");
|
| 1016 |
labels.add("Plan for Future");
|
981 |
labels.add("Plan for Future");
|
| 1017 |
labels.add("Normal");
|
982 |
labels.add("Normal");
|
| Line 1177... |
Line 1142... |
| 1177 |
|
1142 |
|
| 1178 |
return "franchie-visit-detail";
|
1143 |
return "franchie-visit-detail";
|
| 1179 |
|
1144 |
|
| 1180 |
}
|
1145 |
}
|
| 1181 |
|
1146 |
|
| - |
|
1147 |
@RequestMapping(value = "/indent/today_target", method = RequestMethod.GET)
|
| - |
|
1148 |
public String todayTarget(HttpServletRequest request, Model model) throws Exception {
|
| - |
|
1149 |
//model.addAttribute("warehouseCollectionMap", warehouseCollectionMap);
|
| - |
|
1150 |
List<RBMPerformanceSummaryModel> summaryModels = new ArrayList<>();
|
| - |
|
1151 |
List<Integer> rbmPositionsAuthIds = positionRepository
|
| - |
|
1152 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM).stream()
|
| - |
|
1153 |
.map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
| - |
|
1154 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| - |
|
1155 |
List<TeamCommitmentModel> teamCommitmentModels = partnerCollectionPlanRepository.selectTeamCommitmentByDate(LocalDate.now());
|
| - |
|
1156 |
Map<Integer, TeamCommitmentModel> rbmCommittmentMap = teamCommitmentModels.stream().filter(x -> rbmPositionsAuthIds.contains(x.getAuthId())).collect(Collectors.toMap(x -> x.getAuthId(), x -> x));
|
| - |
|
1157 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
| - |
|
1158 |
for (int rbmAuthId : rbmPositionsAuthIds) {
|
| - |
|
1159 |
RBMPerformanceSummaryModel rbmPerformanceSummaryModel = new RBMPerformanceSummaryModel();
|
| - |
|
1160 |
rbmPerformanceSummaryModel.setAuthId(rbmAuthId);
|
| - |
|
1161 |
AuthUser authUser = authRepository.selectById(rbmAuthId);
|
| - |
|
1162 |
rbmPerformanceSummaryModel.setAuthName(authUser.getFullName());
|
| - |
|
1163 |
List<Integer> fofoIds = new ArrayList<>(storeGuyMap.get(authUser.getEmailId()));
|
| - |
|
1164 |
|
| - |
|
1165 |
if (fofoIds.size() > 0) {
|
| - |
|
1166 |
fofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
| - |
|
1167 |
.filter(x -> !x.isInternal()).map(x -> x.getId()).collect(Collectors.toList());
|
| - |
|
1168 |
|
| - |
|
1169 |
/*Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = partnerCollectionService
|
| - |
|
1170 |
.getCollectionMap(fofoIds, startDate);*/
|
| - |
|
1171 |
|
| - |
|
1172 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIds);
|
| - |
|
1173 |
|
| - |
|
1174 |
LOGGER.info("remarkIds {}", remarkIds);
|
| - |
|
1175 |
|
| - |
|
1176 |
long todayOverallCall = 0;
|
| - |
|
1177 |
if (!remarkIds.isEmpty()) {
|
| - |
|
1178 |
todayOverallCall = partnerCollectionRemarkRepository.selectByIds(remarkIds).stream()
|
| - |
|
1179 |
.filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
| - |
|
1180 |
.collect(Collectors.counting());
|
| - |
|
1181 |
|
| - |
|
1182 |
}
|
| - |
|
1183 |
|
| - |
|
1184 |
Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService
|
| - |
|
1185 |
.getCollectionMap(fofoIds, startDate);
|
| - |
|
1186 |
|
| - |
|
1187 |
ChartLeadModel cm = this
|
| - |
|
1188 |
.getCollectionCount(collectionMap.values().stream().collect(Collectors.toList()));
|
| - |
|
1189 |
|
| - |
|
1190 |
long collectionTarget = collectionMap.values().stream().filter(x -> x.getTargetPlan() != null).collect(Collectors.summingLong(x -> x.getTargetPlan()));
|
| - |
|
1191 |
long collection = collectionMap.values().stream().filter(x -> x.getTargetPlan() != null && x.getTargetPlan() != 0 && x.getAchievementPlan() != null).collect(Collectors.summingLong(x -> x.getAchievementPlan()));
|
| - |
|
1192 |
rbmPerformanceSummaryModel.setChartLeadModel(cm);
|
| - |
|
1193 |
rbmPerformanceSummaryModel.setPartnersCommunicated(todayOverallCall);
|
| - |
|
1194 |
rbmPerformanceSummaryModel.setCollectionTarget(collectionTarget);
|
| - |
|
1195 |
rbmPerformanceSummaryModel.setCollection(collection);
|
| - |
|
1196 |
rbmPerformanceSummaryModel.setSecondaryTarget(rbmCommittmentMap.get(rbmAuthId) == null ? 0 : rbmCommittmentMap.get(rbmAuthId).getTotalTarget() == null ? 0 : rbmCommittmentMap.get(rbmAuthId).getTotalTarget());
|
| - |
|
1197 |
rbmPerformanceSummaryModel.setSecondary(rbmCommittmentMap.get(rbmAuthId) == null ? 0 : rbmCommittmentMap.get(rbmAuthId).getTotalAchievement() == null ? 0 : rbmCommittmentMap.get(rbmAuthId).getTotalAchievement());
|
| - |
|
1198 |
summaryModels.add(rbmPerformanceSummaryModel);
|
| - |
|
1199 |
//cm.getData().getDatasets().get(0).getData().;
|
| - |
|
1200 |
//cm.getData().getDatasets().get(0).getBackgroundColor();
|
| - |
|
1201 |
//cm.getData().getLabels()
|
| - |
|
1202 |
|
| - |
|
1203 |
}
|
| - |
|
1204 |
}
|
| - |
|
1205 |
model.addAttribute("summaryModels", summaryModels);
|
| - |
|
1206 |
return "today_target";
|
| - |
|
1207 |
}
|
| - |
|
1208 |
|
| 1182 |
}
|
1209 |
}
|