| 21615 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 25651 |
tejbeer |
3 |
import java.io.File;
|
|
|
4 |
import java.io.FileInputStream;
|
|
|
5 |
import java.io.FileNotFoundException;
|
| 24288 |
amit.gupta |
6 |
import java.time.LocalDate;
|
| 24276 |
amit.gupta |
7 |
import java.time.LocalDateTime;
|
| 24880 |
govind |
8 |
import java.time.LocalTime;
|
| 25649 |
tejbeer |
9 |
import java.time.ZoneOffset;
|
| 24339 |
amit.gupta |
10 |
import java.util.ArrayList;
|
| 26027 |
amit.gupta |
11 |
import java.util.Arrays;
|
| 26011 |
amit.gupta |
12 |
import java.util.HashMap;
|
| 26090 |
amit.gupta |
13 |
import java.util.HashSet;
|
| 25136 |
amit.gupta |
14 |
import java.util.LinkedHashMap;
|
| 23884 |
amit.gupta |
15 |
import java.util.List;
|
| 24880 |
govind |
16 |
import java.util.Map;
|
| 26055 |
tejbeer |
17 |
import java.util.Map.Entry;
|
| 26071 |
tejbeer |
18 |
import java.util.Optional;
|
| 26090 |
amit.gupta |
19 |
import java.util.Set;
|
| 24880 |
govind |
20 |
import java.util.stream.Collectors;
|
| 23568 |
govind |
21 |
|
| 22086 |
amit.gupta |
22 |
import javax.servlet.http.HttpServletRequest;
|
| 25221 |
amit.gupta |
23 |
import javax.transaction.Transactional;
|
| 22086 |
amit.gupta |
24 |
|
| 23786 |
amit.gupta |
25 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
26 |
import org.apache.logging.log4j.Logger;
|
| 26158 |
amit.gupta |
27 |
import org.json.JSONObject;
|
| 22481 |
ashik.ali |
28 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23379 |
ashik.ali |
29 |
import org.springframework.beans.factory.annotation.Value;
|
| 26327 |
amit.gupta |
30 |
import org.springframework.cglib.core.Local;
|
| 25651 |
tejbeer |
31 |
import org.springframework.core.io.InputStreamResource;
|
|
|
32 |
import org.springframework.http.HttpHeaders;
|
|
|
33 |
import org.springframework.http.HttpStatus;
|
| 25649 |
tejbeer |
34 |
import org.springframework.http.ResponseEntity;
|
| 21615 |
kshitij.so |
35 |
import org.springframework.stereotype.Controller;
|
| 22073 |
ashik.ali |
36 |
import org.springframework.ui.Model;
|
| 21615 |
kshitij.so |
37 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
38 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 25649 |
tejbeer |
39 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21615 |
kshitij.so |
40 |
|
| 25649 |
tejbeer |
41 |
import com.google.gson.Gson;
|
| 25677 |
amit.gupta |
42 |
import com.mongodb.DBObject;
|
| 25651 |
tejbeer |
43 |
import com.spice.profitmandi.common.enumuration.ContentType;
|
| 25683 |
tejbeer |
44 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 26065 |
amit.gupta |
45 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 22481 |
ashik.ali |
46 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 25677 |
amit.gupta |
47 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
| 26055 |
tejbeer |
48 |
import com.spice.profitmandi.common.model.ChartModel;
|
| 26005 |
amit.gupta |
49 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 26055 |
tejbeer |
50 |
import com.spice.profitmandi.common.model.DataModel;
|
|
|
51 |
import com.spice.profitmandi.common.model.DatasetModel;
|
|
|
52 |
import com.spice.profitmandi.common.model.LegendModel;
|
| 25649 |
tejbeer |
53 |
import com.spice.profitmandi.common.model.Notification;
|
| 26055 |
tejbeer |
54 |
import com.spice.profitmandi.common.model.OptionsModel;
|
| 24203 |
amit.gupta |
55 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 26055 |
tejbeer |
56 |
import com.spice.profitmandi.common.model.TitleModel;
|
| 25651 |
tejbeer |
57 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 25649 |
tejbeer |
58 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
| 26011 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
60 |
import com.spice.profitmandi.dao.entity.auth.Menu;
|
|
|
61 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 25651 |
tejbeer |
62 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 25649 |
tejbeer |
63 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
| 22654 |
ashik.ali |
64 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24288 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 25214 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 25566 |
tejbeer |
67 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 26418 |
tejbeer |
68 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
| 26024 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 26418 |
tejbeer |
70 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
|
|
71 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
| 25649 |
tejbeer |
72 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
|
|
73 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 25976 |
amit.gupta |
74 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 26011 |
amit.gupta |
75 |
import com.spice.profitmandi.dao.repository.auth.MenuCategoryRepository;
|
|
|
76 |
import com.spice.profitmandi.dao.repository.auth.MenuRepository;
|
| 26090 |
amit.gupta |
77 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 26418 |
tejbeer |
78 |
import com.spice.profitmandi.dao.repository.cs.PartnersPositionRepository;
|
| 26011 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
|
|
80 |
import com.spice.profitmandi.dao.repository.cs.TicketCategoryRepository;
|
| 26418 |
tejbeer |
81 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
| 25651 |
tejbeer |
82 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 22481 |
ashik.ali |
83 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 26418 |
tejbeer |
84 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
| 24996 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 25649 |
tejbeer |
86 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
|
|
87 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
88 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
| 24203 |
amit.gupta |
89 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24880 |
govind |
90 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 26071 |
tejbeer |
91 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 25649 |
tejbeer |
92 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
| 26234 |
amit.gupta |
93 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24288 |
amit.gupta |
94 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 25214 |
amit.gupta |
95 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 25566 |
tejbeer |
96 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 24336 |
amit.gupta |
97 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23844 |
amit.gupta |
98 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 25677 |
amit.gupta |
99 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 26005 |
amit.gupta |
100 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22481 |
ashik.ali |
101 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
102 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
103 |
|
| 21615 |
kshitij.so |
104 |
@Controller
|
| 25222 |
amit.gupta |
105 |
@Transactional(rollbackOn = Throwable.class)
|
| 21615 |
kshitij.so |
106 |
public class DashboardController {
|
| 26327 |
amit.gupta |
107 |
|
|
|
108 |
private static final double ONE_LAC = 1*1000*100;
|
|
|
109 |
private static final double TWO_LAC = 2*1000*100;
|
|
|
110 |
private static final double FOUR_LAC = 4*1000*100;
|
| 23923 |
amit.gupta |
111 |
|
| 23379 |
ashik.ali |
112 |
@Value("${web.api.host}")
|
|
|
113 |
private String webApiHost;
|
| 23923 |
amit.gupta |
114 |
|
| 24072 |
amit.gupta |
115 |
@Value("${web.api.scheme}")
|
|
|
116 |
private String webApiScheme;
|
| 24288 |
amit.gupta |
117 |
|
| 24078 |
amit.gupta |
118 |
@Value("${web.api.root}")
|
|
|
119 |
private String webApiRoot;
|
|
|
120 |
|
| 23379 |
ashik.ali |
121 |
@Value("${web.api.port}")
|
|
|
122 |
private int webApiPort;
|
| 21615 |
kshitij.so |
123 |
|
| 22481 |
ashik.ali |
124 |
@Autowired
|
| 22927 |
ashik.ali |
125 |
private CookiesProcessor cookiesProcessor;
|
| 23923 |
amit.gupta |
126 |
|
| 23568 |
govind |
127 |
@Autowired
|
| 26011 |
amit.gupta |
128 |
private MenuRepository menuRepository;
|
| 26012 |
amit.gupta |
129 |
|
| 26011 |
amit.gupta |
130 |
@Autowired
|
|
|
131 |
private MenuCategoryRepository menuCategoryRepository;
|
|
|
132 |
|
|
|
133 |
@Autowired
|
| 26090 |
amit.gupta |
134 |
private CsService csService;
|
|
|
135 |
|
|
|
136 |
@Autowired
|
| 25214 |
amit.gupta |
137 |
private PartnerTargetRepository partnerTargetRepository;
|
|
|
138 |
|
|
|
139 |
@Autowired
|
| 25653 |
amit.gupta |
140 |
private ResponseSender<?> responseSender;
|
| 26012 |
amit.gupta |
141 |
|
| 26005 |
amit.gupta |
142 |
@Autowired
|
|
|
143 |
RetailerService retailerService;
|
| 25214 |
amit.gupta |
144 |
|
|
|
145 |
@Autowired
|
| 23786 |
amit.gupta |
146 |
private RoleManager roleManager;
|
| 23923 |
amit.gupta |
147 |
|
| 23838 |
ashik.ali |
148 |
@Autowired
|
|
|
149 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
150 |
|
|
|
151 |
@Autowired
|
| 24880 |
govind |
152 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 23923 |
amit.gupta |
153 |
|
| 23884 |
amit.gupta |
154 |
@Autowired
|
| 24880 |
govind |
155 |
private PartnerInvestmentService partnerInvestmentService;
|
| 24288 |
amit.gupta |
156 |
|
| 23884 |
amit.gupta |
157 |
@Autowired
|
| 25653 |
amit.gupta |
158 |
DocumentRepository documentRepository;
|
| 26236 |
amit.gupta |
159 |
|
| 26234 |
amit.gupta |
160 |
@Autowired
|
|
|
161 |
InventoryItemRepository inventoryItemRepository;
|
| 25683 |
tejbeer |
162 |
|
| 25677 |
amit.gupta |
163 |
@Autowired
|
|
|
164 |
InventoryService inventoryService;
|
| 23923 |
amit.gupta |
165 |
|
| 23884 |
amit.gupta |
166 |
@Autowired
|
| 24203 |
amit.gupta |
167 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
168 |
|
| 24880 |
govind |
169 |
@Autowired
|
|
|
170 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 26012 |
amit.gupta |
171 |
|
| 26011 |
amit.gupta |
172 |
@Autowired
|
|
|
173 |
private TicketCategoryRepository ticketCategoryRepository;
|
| 24880 |
govind |
174 |
|
|
|
175 |
@Autowired
|
| 25566 |
tejbeer |
176 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| 25136 |
amit.gupta |
177 |
|
| 24996 |
amit.gupta |
178 |
@Autowired
|
| 25649 |
tejbeer |
179 |
private HygieneDataRepository hygieneDataRepository;
|
|
|
180 |
|
|
|
181 |
@Autowired
|
|
|
182 |
private UserCampaignRepository userCampaignRepository;
|
| 26012 |
amit.gupta |
183 |
|
| 26011 |
amit.gupta |
184 |
@Autowired
|
|
|
185 |
private PositionRepository positionRepository;
|
| 25649 |
tejbeer |
186 |
|
|
|
187 |
@Autowired
|
| 26418 |
tejbeer |
188 |
private PartnersPositionRepository partnerPositionRepository;
|
|
|
189 |
|
|
|
190 |
@Autowired
|
| 25649 |
tejbeer |
191 |
private UserAccountRepository userAccountRepository;
|
|
|
192 |
|
|
|
193 |
@Autowired
|
|
|
194 |
private NotificationCampaignRepository notificationCampaignRepository;
|
|
|
195 |
|
|
|
196 |
@Autowired
|
| 24996 |
amit.gupta |
197 |
private Mongo mongoClient;
|
| 26012 |
amit.gupta |
198 |
|
| 25976 |
amit.gupta |
199 |
@Autowired
|
|
|
200 |
private AuthRepository authRepository;
|
| 24880 |
govind |
201 |
|
| 25649 |
tejbeer |
202 |
@Autowired
|
| 26071 |
tejbeer |
203 |
private FofoOrderRepository fofoOrderRepository;
|
|
|
204 |
|
|
|
205 |
@Autowired
|
| 25649 |
tejbeer |
206 |
private Gson gson;
|
|
|
207 |
|
| 26418 |
tejbeer |
208 |
@Autowired
|
|
|
209 |
TicketRepository ticketRepository;
|
|
|
210 |
|
|
|
211 |
@Autowired
|
|
|
212 |
private LeadRepository leadRepository;
|
|
|
213 |
|
| 23568 |
govind |
214 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 23923 |
amit.gupta |
215 |
|
| 25136 |
amit.gupta |
216 |
@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
|
| 25726 |
amit.gupta |
217 |
public String dashboard1(HttpServletRequest request, Model model, @RequestParam int fofoId) throws Exception {
|
| 25740 |
amit.gupta |
218 |
boolean isAdmin = false;
|
|
|
219 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
220 |
|
|
|
221 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
222 |
model.addAttribute("webApiPort", webApiPort);
|
|
|
223 |
model.addAttribute("webApiScheme", webApiScheme);
|
|
|
224 |
model.addAttribute("webApiRoot", webApiRoot);
|
|
|
225 |
if (isAdmin) {
|
|
|
226 |
return "dashboard1";
|
| 26236 |
amit.gupta |
227 |
}
|
|
|
228 |
|
|
|
229 |
FofoStore fofoStore = null;
|
| 26234 |
amit.gupta |
230 |
try {
|
|
|
231 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
232 |
fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
233 |
if (!fofoStore.isActive()) {
|
|
|
234 |
return "redirect:/login";
|
|
|
235 |
}
|
| 25740 |
amit.gupta |
236 |
|
| 26234 |
amit.gupta |
237 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
|
|
|
238 |
model.addAttribute("partnerType", partnerType);
|
|
|
239 |
model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
|
|
|
240 |
model.addAttribute("fofoStore", customRetailer);
|
|
|
241 |
model.addAttribute("partnerType", partnerType);
|
|
|
242 |
model.addAttribute("hasGift", hasGift(fofoId));
|
|
|
243 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
| 25740 |
amit.gupta |
244 |
|
| 26234 |
amit.gupta |
245 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
|
|
|
246 |
model.addAttribute("salesMap", this.getSales(fofoId));
|
|
|
247 |
model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
|
|
|
248 |
// this.setInvestments
|
|
|
249 |
//
|
|
|
250 |
model.addAttribute("investments", this.getInvestments(fofoId));
|
|
|
251 |
model.addAttribute("isInvestmentOk",
|
|
|
252 |
partnerInvestmentService.isInvestmentOk(fofoId, 10, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
|
|
253 |
} catch (ProfitMandiBusinessException e) {
|
|
|
254 |
LOGGER.error("FofoStore Code not found of fofoId {}", fofoId);
|
| 25740 |
amit.gupta |
255 |
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
|
|
|
259 |
LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
|
| 26012 |
amit.gupta |
260 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd)
|
|
|
261 |
/ 2;
|
|
|
262 |
double lastMonthRating = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd) / 2;
|
|
|
263 |
double ratingTillDate = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd) / 2;
|
| 25740 |
amit.gupta |
264 |
model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
|
|
|
265 |
model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
|
|
|
266 |
model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
|
|
|
267 |
|
| 26012 |
amit.gupta |
268 |
long hygieneCount = hygieneDataRepository.selectHygieneCount(fofoId, true, currentMonthStart, currentMonthEnd);
|
|
|
269 |
|
|
|
270 |
long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(fofoId, false, currentMonthStart,
|
| 25740 |
amit.gupta |
271 |
currentMonthEnd);
|
|
|
272 |
if (hygieneCount == 0 && invalidHygieneCount == 0) {
|
|
|
273 |
invalidHygieneCount = 1;
|
|
|
274 |
}
|
|
|
275 |
model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
|
| 26327 |
amit.gupta |
276 |
|
| 25740 |
amit.gupta |
277 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
|
|
278 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
|
|
279 |
return "12dashboard34";
|
| 25136 |
amit.gupta |
280 |
}
|
|
|
281 |
|
|
|
282 |
private Map<String, Object> getInvestments(int fofoId) throws Exception {
|
|
|
283 |
Map<String, Object> investments = new LinkedHashMap<>();
|
| 26233 |
amit.gupta |
284 |
PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
|
| 25649 |
tejbeer |
285 |
LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
|
| 25136 |
amit.gupta |
286 |
LocalDate yesterDate = LocalDate.now().minusDays(1);
|
|
|
287 |
PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
|
|
|
288 |
if (yesterdayInvestment == null) {
|
|
|
289 |
yesterdayInvestment = new PartnerDailyInvestment();
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
|
|
|
293 |
currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
|
|
|
294 |
|
| 25140 |
amit.gupta |
295 |
long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
|
| 25136 |
amit.gupta |
296 |
.collect(Collectors.counting());
|
| 25140 |
amit.gupta |
297 |
investments.put("today", investment.getTotalInvestment());
|
|
|
298 |
investments.put("investment", investment);
|
|
|
299 |
investments.put("inStock", investment.getInStockAmount());
|
| 25182 |
amit.gupta |
300 |
investments.put("minimum", investment.getMinInvestmentString());
|
| 25140 |
amit.gupta |
301 |
investments.put("short", investment.getShortPercentage());
|
| 26267 |
amit.gupta |
302 |
investments.put("activated_stock", investment.getActivatedStockAmount());
|
| 25649 |
tejbeer |
303 |
investments.put("okDays", okInvestmentDays);
|
| 25136 |
amit.gupta |
304 |
return investments;
|
|
|
305 |
}
|
|
|
306 |
|
| 25221 |
amit.gupta |
307 |
private Map<String, Object> getSales(int fofoId) {
|
| 25653 |
amit.gupta |
308 |
|
| 25221 |
amit.gupta |
309 |
Map<String, Object> salesMap = new LinkedHashMap<>();
|
| 25140 |
amit.gupta |
310 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 25214 |
amit.gupta |
311 |
int monthLength = LocalDate.now().lengthOfMonth();
|
| 26012 |
amit.gupta |
312 |
Double todaySale = fofoOrderItemRepository
|
|
|
313 |
.selectSumAmountGroupByRetailer(curDate, curDate.with(LocalTime.MAX), fofoId, false).get(fofoId);
|
|
|
314 |
Double mtdSale = fofoOrderItemRepository
|
|
|
315 |
.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId, false)
|
|
|
316 |
.get(fofoId);
|
|
|
317 |
Double lmtdSale = fofoOrderItemRepository
|
|
|
318 |
.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1).minusMonths(1),
|
|
|
319 |
curDate.with(LocalTime.MAX).minusMonths(1), fofoId, false)
|
|
|
320 |
.get(fofoId);
|
| 26327 |
amit.gupta |
321 |
|
| 25214 |
amit.gupta |
322 |
|
|
|
323 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
324 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
| 25544 |
amit.gupta |
325 |
if (partnerTargetDetails.isEmpty()) {
|
| 25372 |
tejbeer |
326 |
partnerTargetDetails = partnerTargetRepository
|
| 25653 |
amit.gupta |
327 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now().minusMonths(3));
|
| 25372 |
tejbeer |
328 |
}
|
| 25214 |
amit.gupta |
329 |
|
| 25653 |
amit.gupta |
330 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
| 25214 |
amit.gupta |
331 |
|
| 25664 |
amit.gupta |
332 |
int currentRate = (int) (mtdSale / curDate.getDayOfMonth());
|
| 25653 |
amit.gupta |
333 |
|
|
|
334 |
salesMap.put("requiredType", partnerType.next());
|
|
|
335 |
float reqdAmount = partnerTypeChangeService.getMinimumAmount(partnerType.next());
|
|
|
336 |
int requiredRate = (int) ((reqdAmount - mtdSale) / (monthLength - curDate.getDayOfMonth()));
|
|
|
337 |
salesMap.put("requiredRate", requiredRate);
|
|
|
338 |
salesMap.put("requiredTypeImage", PartnerType.imageMap.get(partnerType.next()));
|
|
|
339 |
|
| 25858 |
amit.gupta |
340 |
salesMap.put("todaySale", todaySale == null ? 0 : todaySale);
|
|
|
341 |
salesMap.put("mtdSale", mtdSale == null ? 0 : mtdSale);
|
| 26012 |
amit.gupta |
342 |
salesMap.put("lmtdSale", lmtdSale == null ? 0 : lmtdSale);
|
| 26065 |
amit.gupta |
343 |
|
| 26400 |
amit.gupta |
344 |
PartnerType currentType = partnerTypeChangeService.getPartnerTypeByAmount(mtdSale.floatValue());
|
| 25653 |
amit.gupta |
345 |
salesMap.put("currentRate", currentRate);
|
|
|
346 |
salesMap.put("currentType", currentType);
|
|
|
347 |
salesMap.put("currentTypeImage", PartnerType.imageMap.get(currentType));
|
| 25136 |
amit.gupta |
348 |
return salesMap;
|
|
|
349 |
}
|
|
|
350 |
|
| 25677 |
amit.gupta |
351 |
private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
|
|
|
352 |
Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
|
| 25175 |
amit.gupta |
353 |
|
| 26309 |
amit.gupta |
354 |
List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
|
| 25677 |
amit.gupta |
355 |
List<BrandStockPrice> brandStockPrices = new ArrayList<>();
|
|
|
356 |
|
|
|
357 |
mobileBrands.stream().forEach(x -> {
|
|
|
358 |
String brand = (String) x.get("name");
|
|
|
359 |
if (brandStockPricesMap.containsKey(brand)) {
|
|
|
360 |
BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
|
|
|
361 |
brandStockPrice.setBrandUrl((String) x.get("url"));
|
|
|
362 |
brandStockPrice.setRank(((Double) x.get("rank")).intValue());
|
|
|
363 |
brandStockPrices.add(brandStockPrice);
|
|
|
364 |
}
|
|
|
365 |
});
|
|
|
366 |
|
|
|
367 |
return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
|
|
|
368 |
.collect(Collectors.toList());
|
|
|
369 |
}
|
|
|
370 |
|
| 21615 |
kshitij.so |
371 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 25653 |
amit.gupta |
372 |
public String dashboard(HttpServletRequest request, Model model) throws Exception {
|
| 22927 |
ashik.ali |
373 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26011 |
amit.gupta |
374 |
String email = loginDetails.getEmailId();
|
| 25180 |
amit.gupta |
375 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
376 |
model.addAttribute("isAdmin", isAdmin);
|
| 23923 |
amit.gupta |
377 |
|
| 25274 |
amit.gupta |
378 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
379 |
model.addAttribute("webApiPort", webApiPort);
|
|
|
380 |
model.addAttribute("webApiScheme", webApiScheme);
|
| 25544 |
amit.gupta |
381 |
model.addAttribute("webApiRoot", webApiRoot);
|
| 25183 |
amit.gupta |
382 |
if (isAdmin) {
|
| 26011 |
amit.gupta |
383 |
return adminPanel(loginDetails.getFofoId(), email, model);
|
| 25180 |
amit.gupta |
384 |
} else {
|
| 25740 |
amit.gupta |
385 |
FofoStore fofoStore = null;
|
| 25180 |
amit.gupta |
386 |
try {
|
|
|
387 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 25544 |
amit.gupta |
388 |
if (!fofoStore.isActive()) {
|
|
|
389 |
return "redirect:/login";
|
|
|
390 |
}
|
| 25649 |
tejbeer |
391 |
|
| 25740 |
amit.gupta |
392 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
|
| 25566 |
tejbeer |
393 |
model.addAttribute("partnerType", partnerType);
|
| 25653 |
amit.gupta |
394 |
model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
|
| 25180 |
amit.gupta |
395 |
model.addAttribute("fofoStore", fofoStore);
|
| 25566 |
tejbeer |
396 |
model.addAttribute("partnerType", partnerType);
|
| 25180 |
amit.gupta |
397 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
|
|
398 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
| 26222 |
tejbeer |
399 |
model.addAttribute("retailers", new JSONObject().append("code", fofoStore.getCode())
|
| 26162 |
amit.gupta |
400 |
.append("partnerId", fofoStore.getId()).toString());
|
| 26237 |
amit.gupta |
401 |
model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(loginDetails.getFofoId()));
|
| 26071 |
tejbeer |
402 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
403 |
Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository
|
|
|
404 |
.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
|
|
|
405 |
curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
|
|
|
406 |
LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
|
|
|
407 |
Double accesoriesStock = currentInventorySnapshotRepository
|
|
|
408 |
.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
|
|
|
409 |
Optional.of(false))
|
|
|
410 |
.get(loginDetails.getFofoId());
|
| 25180 |
amit.gupta |
411 |
|
| 26071 |
tejbeer |
412 |
model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
|
| 26065 |
amit.gupta |
413 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
| 25180 |
amit.gupta |
414 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
| 26055 |
tejbeer |
415 |
ChartModel cm = this.getBrandChart(loginDetails.getFofoId());
|
|
|
416 |
|
|
|
417 |
LOGGER.info("chartMap" + gson.toJson(cm));
|
|
|
418 |
model.addAttribute("chartMap", gson.toJson(cm));
|
| 25544 |
amit.gupta |
419 |
// this.setInvestments
|
|
|
420 |
//
|
| 25180 |
amit.gupta |
421 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
| 25544 |
amit.gupta |
422 |
model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
|
|
|
423 |
10, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
| 26327 |
amit.gupta |
424 |
|
|
|
425 |
//Hardcoded for valentine
|
| 26330 |
amit.gupta |
426 |
//Hardcoded for valentine
|
| 26414 |
amit.gupta |
427 |
if(LocalDate.now().isBefore(LocalDate.of(2020, 3, 11))) {
|
| 26413 |
amit.gupta |
428 |
double valentineSales = fofoOrderItemRepository.selectSumAmountGroupByRetailer(LocalDate.of(2020, 3, 6).atStartOfDay(),
|
|
|
429 |
LocalDate.of(2020, 3, 10).atStartOfDay(), loginDetails.getFofoId(), false).get(loginDetails.getFofoId());
|
| 26327 |
amit.gupta |
430 |
if(valentineSales < ONE_LAC) {
|
|
|
431 |
model.addAttribute("valentineSale", "ONE_LAC");
|
|
|
432 |
model.addAttribute("valentineShort", ONE_LAC - valentineSales);
|
|
|
433 |
} else if(valentineSales < TWO_LAC) {
|
|
|
434 |
model.addAttribute("valentineSale", "TWO_LAC");
|
|
|
435 |
model.addAttribute("valentineShort", TWO_LAC - valentineSales);
|
|
|
436 |
} else if (valentineSales < FOUR_LAC) {
|
|
|
437 |
model.addAttribute("valentineSale", "FOUR_LAC");
|
|
|
438 |
model.addAttribute("valentineShort", FOUR_LAC - valentineSales);
|
|
|
439 |
} else {
|
|
|
440 |
model.addAttribute("valentineSale", "CONGO");
|
|
|
441 |
}
|
|
|
442 |
}
|
| 25180 |
amit.gupta |
443 |
} catch (ProfitMandiBusinessException e) {
|
|
|
444 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
|
|
445 |
|
|
|
446 |
}
|
| 22481 |
ashik.ali |
447 |
}
|
| 25649 |
tejbeer |
448 |
|
|
|
449 |
LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
|
| 25747 |
amit.gupta |
450 |
LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
|
| 25653 |
amit.gupta |
451 |
LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
|
|
|
452 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
|
| 25677 |
amit.gupta |
453 |
currentMonthEnd) / 2;
|
| 25747 |
amit.gupta |
454 |
double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
|
|
|
455 |
currentMonthStart) / 2;
|
|
|
456 |
double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
|
| 25677 |
amit.gupta |
457 |
currentMonthEnd) / 2;
|
|
|
458 |
model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
|
|
|
459 |
model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
|
|
|
460 |
model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
|
| 25649 |
tejbeer |
461 |
|
| 25653 |
amit.gupta |
462 |
long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true, currentMonthStart,
|
|
|
463 |
currentMonthEnd);
|
| 25651 |
tejbeer |
464 |
|
| 25653 |
amit.gupta |
465 |
long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
|
|
|
466 |
currentMonthStart, currentMonthEnd);
|
|
|
467 |
if (hygieneCount == 0 && invalidHygieneCount == 0) {
|
|
|
468 |
invalidHygieneCount = 1;
|
|
|
469 |
}
|
|
|
470 |
model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
|
| 25651 |
tejbeer |
471 |
|
| 25197 |
amit.gupta |
472 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
|
|
473 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
| 25140 |
amit.gupta |
474 |
return "dashboard1";
|
| 21615 |
kshitij.so |
475 |
}
|
| 23923 |
amit.gupta |
476 |
|
| 26055 |
tejbeer |
477 |
private ChartModel getBrandChart(int fofoId) {
|
|
|
478 |
|
|
|
479 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
480 |
|
|
|
481 |
LOGGER.info("cur Date" + curDate.withDayOfMonth(1));
|
|
|
482 |
|
|
|
483 |
LOGGER.info("curDateYear" + curDate.with(LocalTime.MAX));
|
|
|
484 |
|
|
|
485 |
Map<String, Double> brandwisesale = fofoOrderItemRepository
|
|
|
486 |
.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
|
| 26244 |
tejbeer |
487 |
|
|
|
488 |
Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
|
|
|
489 |
fofoId, curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
|
|
|
490 |
|
|
|
491 |
LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
|
|
|
492 |
|
| 26055 |
tejbeer |
493 |
LOGGER.info("brandwisesale" + brandwisesale);
|
|
|
494 |
|
|
|
495 |
Map<String, Double> lmtdBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
|
|
|
496 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
|
|
|
497 |
|
| 26244 |
tejbeer |
498 |
Map<Integer, Double> accesorieslmtdsale = fofoOrderRepository.selectSumSaleGroupByFofoIdsForMobileOrAccessories(
|
|
|
499 |
fofoId, curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1),
|
|
|
500 |
Optional.of(false));
|
|
|
501 |
LOGGER.info("accesorieslmtdsale" + accesorieslmtdsale);
|
| 26055 |
tejbeer |
502 |
ChartModel cm = new ChartModel();
|
|
|
503 |
|
|
|
504 |
List<String> labels = new ArrayList<>();
|
|
|
505 |
labels.addAll(brandwisesale.keySet());
|
| 26244 |
tejbeer |
506 |
labels.add("accessories");
|
| 26055 |
tejbeer |
507 |
List<Double> values = new ArrayList<>();
|
|
|
508 |
values.addAll(brandwisesale.values());
|
| 26244 |
tejbeer |
509 |
values.addAll(accesoriesmtdsale.values());
|
| 26055 |
tejbeer |
510 |
|
|
|
511 |
List<Double> lmtdValues = new ArrayList<>();
|
|
|
512 |
lmtdValues.addAll(lmtdBrandWiseSale.values());
|
| 26244 |
tejbeer |
513 |
lmtdValues.addAll(accesorieslmtdsale.values());
|
| 26055 |
tejbeer |
514 |
|
|
|
515 |
DatasetModel dsm = new DatasetModel();
|
|
|
516 |
dsm.setLabel("mtd sales");
|
|
|
517 |
|
|
|
518 |
List<String> backgroundColor = new ArrayList<>();
|
|
|
519 |
for (Entry<String, Double> bs : brandwisesale.entrySet()) {
|
|
|
520 |
backgroundColor.add("#3e95cd");
|
|
|
521 |
}
|
| 26244 |
tejbeer |
522 |
backgroundColor.add("#3e95cd");
|
| 26055 |
tejbeer |
523 |
dsm.setBackgroundColor(backgroundColor);
|
|
|
524 |
dsm.setData(values);
|
|
|
525 |
|
|
|
526 |
DatasetModel lmtddsm = new DatasetModel();
|
|
|
527 |
lmtddsm.setLabel("lmtd sales");
|
|
|
528 |
|
|
|
529 |
List<String> background = new ArrayList<>();
|
|
|
530 |
for (Entry<String, Double> bs : lmtdBrandWiseSale.entrySet()) {
|
|
|
531 |
background.add("#8e5ea2");
|
|
|
532 |
}
|
| 26244 |
tejbeer |
533 |
background.add("#8e5ea2");
|
| 26055 |
tejbeer |
534 |
lmtddsm.setBackgroundColor(background);
|
|
|
535 |
lmtddsm.setData(lmtdValues);
|
|
|
536 |
|
|
|
537 |
List<DatasetModel> datasets = new ArrayList<>();
|
|
|
538 |
datasets.add(dsm);
|
|
|
539 |
datasets.add(lmtddsm);
|
|
|
540 |
|
|
|
541 |
DataModel dm = new DataModel();
|
|
|
542 |
dm.setDatasets(datasets);
|
|
|
543 |
dm.setLabels(labels);
|
|
|
544 |
|
|
|
545 |
LegendModel lm = new LegendModel();
|
|
|
546 |
lm.setDisplay(true);
|
|
|
547 |
|
|
|
548 |
TitleModel tm = new TitleModel();
|
|
|
549 |
tm.setText("Brand Wise Sale Graph");
|
|
|
550 |
tm.setDisplay(true);
|
|
|
551 |
|
|
|
552 |
OptionsModel om = new OptionsModel();
|
|
|
553 |
om.setLegend(lm);
|
|
|
554 |
om.setTitle(tm);
|
|
|
555 |
|
|
|
556 |
cm.setType("bar");
|
|
|
557 |
cm.setData(dm);
|
|
|
558 |
cm.setOptions(om);
|
|
|
559 |
|
|
|
560 |
return cm;
|
|
|
561 |
|
|
|
562 |
}
|
|
|
563 |
|
| 26418 |
tejbeer |
564 |
private String adminPanel(int fofoId, String email, Model model) throws Exception {
|
| 26022 |
amit.gupta |
565 |
List<Menu> menus = null;
|
| 26011 |
amit.gupta |
566 |
try {
|
|
|
567 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
|
|
568 |
List<Position> positions = positionRepository.selectAll(authUser.getId());
|
| 26418 |
tejbeer |
569 |
Map<Integer, AuthUser> authIdAndAuthUserMap = null;
|
|
|
570 |
Map<Integer, Object> authIdAndallValues = null;
|
|
|
571 |
if (positions.size() > 0) {
|
|
|
572 |
if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L3)).count() > 0) {
|
|
|
573 |
|
|
|
574 |
authIdAndAuthUserMap = authRepository.selectAllActiveUser().stream()
|
|
|
575 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
576 |
|
| 26422 |
tejbeer |
577 |
authIdAndallValues = this.getL2AuthUserPartnerDetail();
|
| 26418 |
tejbeer |
578 |
|
|
|
579 |
LOGGER.info("authIdAndallValues" + authIdAndallValues);
|
|
|
580 |
}
|
|
|
581 |
}
|
|
|
582 |
|
| 26090 |
amit.gupta |
583 |
if (Arrays.asList("amit.gupta@shop2020.in", "tejbeer.kaur@shop2020.in").contains(email)) {
|
| 26029 |
amit.gupta |
584 |
menus = menuRepository.selectAll();
|
|
|
585 |
} else if (positions.size() > 0) {
|
|
|
586 |
if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L4)).count() > 0) {
|
| 26028 |
amit.gupta |
587 |
menus = menuRepository.selectAll();
|
|
|
588 |
} else {
|
|
|
589 |
List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
|
|
|
590 |
.map(x -> x.getMenuId()).collect(Collectors.toList());
|
|
|
591 |
LOGGER.info("Menu Ids are {}", menuIds);
|
|
|
592 |
if (menuIds.size() > 0) {
|
|
|
593 |
menus = menuRepository.selectAllByIds(menuIds);
|
|
|
594 |
}
|
| 26022 |
amit.gupta |
595 |
}
|
| 26090 |
amit.gupta |
596 |
List<Position> salesPositions = positions.stream()
|
|
|
597 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES)
|
|
|
598 |
.collect(Collectors.toList());
|
|
|
599 |
if (salesPositions.size() > 0) {
|
|
|
600 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 26100 |
amit.gupta |
601 |
csService.getPositionCustomRetailerMap(salesPositions).values().forEach(customRetailers -> {
|
| 26090 |
amit.gupta |
602 |
positionRetailers.addAll(customRetailers);
|
|
|
603 |
});
|
|
|
604 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
|
|
605 |
model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
|
| 26152 |
amit.gupta |
606 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 26090 |
amit.gupta |
607 |
}
|
| 26114 |
amit.gupta |
608 |
List<Position> warehousePositions = positions.stream()
|
|
|
609 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
|
|
|
610 |
.collect(Collectors.toList());
|
|
|
611 |
if (warehousePositions.size() > 0) {
|
|
|
612 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 26123 |
amit.gupta |
613 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
| 26114 |
amit.gupta |
614 |
positionRetailers.addAll(customRetailers);
|
|
|
615 |
});
|
|
|
616 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
|
|
617 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
| 26123 |
amit.gupta |
618 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 26114 |
amit.gupta |
619 |
}
|
| 26142 |
amit.gupta |
620 |
model.addAttribute("authId", authUser.getId());
|
| 26028 |
amit.gupta |
621 |
|
| 26022 |
amit.gupta |
622 |
}
|
| 26418 |
tejbeer |
623 |
model.addAttribute("authIdAndallValues", authIdAndallValues);
|
|
|
624 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
625 |
|
|
|
626 |
LOGGER.info("authIdAndallValues1" + authIdAndallValues);
|
| 26012 |
amit.gupta |
627 |
} catch (ProfitMandiBusinessException e) {
|
| 26011 |
amit.gupta |
628 |
}
|
| 26028 |
amit.gupta |
629 |
List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
|
| 26422 |
tejbeer |
630 |
LOGGER.info("menu" + menuList);
|
| 26022 |
amit.gupta |
631 |
model.addAttribute("menu", menuList);
|
| 26012 |
amit.gupta |
632 |
return "admin";
|
|
|
633 |
}
|
|
|
634 |
|
| 26418 |
tejbeer |
635 |
@RequestMapping(value = "/getL1AuthUser", method = RequestMethod.GET)
|
|
|
636 |
public String L1AuthUsersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
|
|
|
637 |
throws Exception {
|
|
|
638 |
|
|
|
639 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
640 |
|
|
|
641 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
642 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(
|
|
|
643 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
|
|
644 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1),
|
|
|
645 |
curDate.with(LocalTime.MAX), 0, false);
|
|
|
646 |
Map<Integer, List<Integer>> L2L1Mapping = csService.getL1L2Mapping();
|
|
|
647 |
|
|
|
648 |
LOGGER.info("L2L1Mapping" + L2L1Mapping);
|
|
|
649 |
List<Integer> l1authIds = L2L1Mapping.get(authId);
|
|
|
650 |
|
|
|
651 |
Map<Integer, Object> authIdAndallValues = new LinkedHashMap<>();
|
|
|
652 |
Map<Integer, Object> authIdAndAuthUserMap = new LinkedHashMap<>();
|
|
|
653 |
|
|
|
654 |
Map<Integer, Long> ticketMap = ticketRepository.selectAllNotClosedTicketsGroupByRetailer();
|
|
|
655 |
for (Integer auth : l1authIds) {
|
|
|
656 |
|
|
|
657 |
double totallmtdAmount = 0;
|
|
|
658 |
double totalmtdAmount = 0;
|
|
|
659 |
int totalTicketCount = 0;
|
|
|
660 |
float totalTodayInvestment = 0;
|
|
|
661 |
float totalStockInInvestment = 0;
|
|
|
662 |
double currentMonthRatingAllPartners = 0;
|
|
|
663 |
Map<Integer, Long> leadCount = leadRepository.selectByAssignAuthIdAndStatus(auth, LeadStatus.followUp)
|
|
|
664 |
.stream().collect(Collectors.groupingBy(Lead::getAssignTo, Collectors.counting()));
|
|
|
665 |
|
|
|
666 |
AuthUser authUser = authRepository.selectById(auth);
|
|
|
667 |
|
|
|
668 |
authIdAndAuthUserMap.put(auth, authUser);
|
|
|
669 |
|
|
|
670 |
List<Integer> fofoIds = pp.get(auth);
|
|
|
671 |
|
|
|
672 |
for (Integer fId : fofoIds) {
|
|
|
673 |
Map<String, Object> investmentMap = this.getInvestments(fId);
|
|
|
674 |
|
|
|
675 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(fId,
|
|
|
676 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
|
|
677 |
|
|
|
678 |
currentMonthRatingAllPartners += currentMonthRating;
|
|
|
679 |
|
|
|
680 |
fofoIds.size();
|
|
|
681 |
|
|
|
682 |
Double lmtdAmount = lmtdSale.get(fId);
|
|
|
683 |
Double mtdAmount = mtdSale.get(fId);
|
|
|
684 |
Long ticketCount = ticketMap.get(fId);
|
|
|
685 |
|
|
|
686 |
if (!investmentMap.isEmpty()) {
|
|
|
687 |
totalTodayInvestment += (float) investmentMap.get("today");
|
|
|
688 |
totalStockInInvestment += (float) investmentMap.get("inStock");
|
|
|
689 |
|
|
|
690 |
}
|
|
|
691 |
LOGGER.info("totalTodayInvestment" + totalTodayInvestment);
|
|
|
692 |
LOGGER.info("totalStockInInvestment" + totalStockInInvestment);
|
|
|
693 |
if (ticketCount != null) {
|
|
|
694 |
totalTicketCount += ticketCount;
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
if (lmtdAmount != null) {
|
|
|
698 |
totallmtdAmount += lmtdAmount;
|
|
|
699 |
}
|
|
|
700 |
|
|
|
701 |
if (mtdAmount != null) {
|
|
|
702 |
totalmtdAmount += mtdAmount;
|
|
|
703 |
}
|
|
|
704 |
|
|
|
705 |
}
|
|
|
706 |
LOGGER.info("currentMonthRatingAllPartners" + currentMonthRatingAllPartners);
|
|
|
707 |
LOGGER.info("size" + fofoIds.size());
|
|
|
708 |
double totalHygieneRating = currentMonthRatingAllPartners / fofoIds.size();
|
|
|
709 |
|
|
|
710 |
LOGGER.info("totalHygieneRating" + totalHygieneRating);
|
|
|
711 |
|
|
|
712 |
PartnerDetailModel pm = new PartnerDetailModel();
|
|
|
713 |
pm.setLmtd(totallmtdAmount);
|
|
|
714 |
pm.setMtd(totalmtdAmount);
|
|
|
715 |
if (leadCount.get(auth) != null) {
|
|
|
716 |
pm.setLeads(leadCount.get(auth).intValue());
|
|
|
717 |
} else {
|
|
|
718 |
pm.setLeads(0);
|
|
|
719 |
}
|
|
|
720 |
|
|
|
721 |
pm.setInvestment(totalTodayInvestment);
|
|
|
722 |
pm.setStockInInvestment(totalStockInInvestment);
|
|
|
723 |
pm.setTicket(totalTicketCount);
|
|
|
724 |
pm.setHygiene((double) Math.round(totalHygieneRating));
|
|
|
725 |
authIdAndallValues.put(auth, pm);
|
|
|
726 |
|
|
|
727 |
}
|
|
|
728 |
model.addAttribute("authIdAndallValues", authIdAndallValues);
|
|
|
729 |
model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);
|
|
|
730 |
LOGGER.info("authIdAndallValues" + authIdAndallValues);
|
|
|
731 |
|
|
|
732 |
return "auth_user_detail";
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
@RequestMapping(value = "/getAuthUserPartners", method = RequestMethod.GET)
|
|
|
736 |
public String AuthUserPartnersDetail(HttpServletRequest request, Model model, @RequestParam int authId)
|
|
|
737 |
throws Exception {
|
|
|
738 |
|
|
|
739 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
740 |
List<Integer> fofoIds = pp.get(authId);
|
|
|
741 |
Map<Integer, Long> ticketMap = ticketRepository.selectAllNotClosedTicketsGroupByRetailer();
|
|
|
742 |
Map<Integer, Object> fofoIdAndallValues = new LinkedHashMap<>();
|
|
|
743 |
Map<Integer, Object> fofoIdAndPartnerMap = new LinkedHashMap<>();
|
|
|
744 |
for (Integer fofoId : fofoIds) {
|
|
|
745 |
|
|
|
746 |
CustomRetailer cr = retailerService.getFofoRetailer(fofoId);
|
|
|
747 |
fofoIdAndPartnerMap.put(fofoId, cr);
|
|
|
748 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
749 |
Double lmtdSale = fofoOrderItemRepository
|
|
|
750 |
.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1).minusMonths(1),
|
|
|
751 |
curDate.with(LocalTime.MAX).minusMonths(1), fofoId, false)
|
|
|
752 |
.get(fofoId);
|
|
|
753 |
Double mtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1),
|
|
|
754 |
curDate.with(LocalTime.MAX), fofoId, false).get(fofoId);
|
|
|
755 |
Map<String, Object> investmentMap = this.getInvestments(fofoId);
|
|
|
756 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(fofoId,
|
|
|
757 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
|
|
758 |
|
|
|
759 |
Long ticketCount = ticketMap.get(fofoId);
|
|
|
760 |
|
|
|
761 |
float totalTodayInvestment = (float) investmentMap.get("today");
|
|
|
762 |
float totalStockInInvestment = (float) investmentMap.get("inStock");
|
|
|
763 |
|
|
|
764 |
PartnerDetailModel pm = new PartnerDetailModel();
|
|
|
765 |
pm.setLmtd(lmtdSale);
|
|
|
766 |
pm.setMtd(mtdSale);
|
|
|
767 |
pm.setInvestment(totalTodayInvestment);
|
|
|
768 |
pm.setStockInInvestment(totalStockInInvestment);
|
|
|
769 |
if (ticketCount != null) {
|
|
|
770 |
pm.setTicket(ticketCount.intValue());
|
|
|
771 |
} else {
|
|
|
772 |
pm.setTicket(0);
|
|
|
773 |
}
|
|
|
774 |
pm.setHygiene((double) Math.round(currentMonthRating));
|
|
|
775 |
fofoIdAndallValues.put(fofoId, pm);
|
|
|
776 |
}
|
|
|
777 |
|
|
|
778 |
model.addAttribute("fofoIdAndallValues", fofoIdAndallValues);
|
|
|
779 |
model.addAttribute("fofoIdAndPartnerMap", fofoIdAndPartnerMap);
|
|
|
780 |
|
|
|
781 |
return "auth_user_partner_detail";
|
|
|
782 |
}
|
|
|
783 |
|
| 26114 |
amit.gupta |
784 |
private String getWarehouses(Set<CustomRetailer> positionRetailers) {
|
|
|
785 |
Map<Integer, String> warehouses = new HashMap<>();
|
| 26222 |
tejbeer |
786 |
positionRetailers.stream().forEach(x -> {
|
|
|
787 |
if (x.getWarehouseId() != 0) {
|
| 26171 |
amit.gupta |
788 |
warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId()));
|
|
|
789 |
}
|
|
|
790 |
});
|
| 26114 |
amit.gupta |
791 |
return gson.toJson(warehouses);
|
|
|
792 |
|
|
|
793 |
}
|
|
|
794 |
|
| 26012 |
amit.gupta |
795 |
private List<Menu> prepareMenu(List<Menu> menus) {
|
|
|
796 |
List<Menu> returnMenu = new ArrayList<>();
|
|
|
797 |
Map<Menu, List<Menu>> subMenuMap = new HashMap<Menu, List<Menu>>();
|
|
|
798 |
for (Menu menu : menus) {
|
|
|
799 |
if (menu.get_parent() == null) {
|
| 26014 |
amit.gupta |
800 |
if (!subMenuMap.containsKey(menu)) {
|
| 26012 |
amit.gupta |
801 |
subMenuMap.put(menu, new ArrayList<>());
|
| 26011 |
amit.gupta |
802 |
}
|
|
|
803 |
} else {
|
| 26012 |
amit.gupta |
804 |
Menu parentMenu = menu.get_parent();
|
|
|
805 |
if (!subMenuMap.containsKey(parentMenu)) {
|
|
|
806 |
subMenuMap.put(parentMenu, new ArrayList<>());
|
| 26011 |
amit.gupta |
807 |
}
|
| 26012 |
amit.gupta |
808 |
subMenuMap.get(parentMenu).add(menu);
|
| 26011 |
amit.gupta |
809 |
}
|
|
|
810 |
}
|
| 26012 |
amit.gupta |
811 |
subMenuMap.entrySet().stream().forEach(entry -> {
|
|
|
812 |
entry.getKey().setSubMenus(entry.getValue());
|
|
|
813 |
returnMenu.add(entry.getKey());
|
|
|
814 |
});
|
|
|
815 |
return returnMenu;
|
| 26005 |
amit.gupta |
816 |
}
|
|
|
817 |
|
| 24288 |
amit.gupta |
818 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
819 |
private boolean hasGift(int fofoId) {
|
|
|
820 |
try {
|
| 24288 |
amit.gupta |
821 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
822 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
823 |
} catch (ProfitMandiBusinessException e) {
|
|
|
824 |
return false;
|
|
|
825 |
}
|
|
|
826 |
}
|
| 24288 |
amit.gupta |
827 |
|
| 22354 |
ashik.ali |
828 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
829 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable {
|
| 22354 |
ashik.ali |
830 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
831 |
return "contact-us";
|
|
|
832 |
}
|
| 23923 |
amit.gupta |
833 |
|
| 25649 |
tejbeer |
834 |
@RequestMapping(value = "/notifications", method = RequestMethod.GET)
|
| 25683 |
tejbeer |
835 |
public String getNotificationsWithType(HttpServletRequest request,
|
|
|
836 |
@RequestParam(required = false) MessageType messageType,
|
| 25649 |
tejbeer |
837 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
838 |
@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
|
|
|
839 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26060 |
tejbeer |
840 |
int userId = 0;
|
|
|
841 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
842 |
if (isAdmin) {
|
|
|
843 |
userId = loginDetails.getFofoId();
|
|
|
844 |
} else {
|
|
|
845 |
userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
|
|
|
846 |
}
|
| 25683 |
tejbeer |
847 |
List<Notification> notifications = null;
|
|
|
848 |
|
| 26086 |
tejbeer |
849 |
List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
|
|
|
850 |
userId, offset, limit);
|
|
|
851 |
LOGGER.info("messageType" + messageType);
|
|
|
852 |
notifications = getNotifications(notificationCampaigns, messageType);
|
|
|
853 |
|
| 25683 |
tejbeer |
854 |
model.addAttribute("notifications", notifications);
|
|
|
855 |
|
|
|
856 |
LOGGER.info("notifications" + notifications);
|
|
|
857 |
return "notification-template";
|
|
|
858 |
}
|
|
|
859 |
|
|
|
860 |
public List<Notification> getNotifications(List<NotificationCampaign> nc, MessageType messageType)
|
|
|
861 |
throws ProfitMandiBusinessException {
|
|
|
862 |
List<Notification> notifications = new ArrayList<>();
|
|
|
863 |
Document document = null;
|
|
|
864 |
if (messageType != null) {
|
|
|
865 |
for (NotificationCampaign notificationCampaign : nc) {
|
|
|
866 |
if (notificationCampaign.getMessageType() == messageType) {
|
| 25649 |
tejbeer |
867 |
Notification ns = new Notification();
|
|
|
868 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
869 |
SimpleCampaignParams.class);
|
|
|
870 |
Campaign campaign = new SimpleCampaign(scp);
|
|
|
871 |
LocalDateTime expire = campaign.getExpireTimestamp();
|
|
|
872 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
|
|
873 |
ns.setType(campaign.getType());
|
|
|
874 |
ns.setMessage(campaign.getMessage());
|
|
|
875 |
ns.setTitle(campaign.getTitle());
|
| 25651 |
tejbeer |
876 |
if (notificationCampaign.getDocumentId() != null) {
|
|
|
877 |
document = documentRepository.selectById(notificationCampaign.getDocumentId());
|
|
|
878 |
ns.setDocumentName(document.getDisplayName());
|
|
|
879 |
}
|
| 25683 |
tejbeer |
880 |
ns.setUrl(campaign.getUrl());
|
| 25649 |
tejbeer |
881 |
ns.setShowImage(campaign.getShowImage());
|
|
|
882 |
ns.setImageUrl(campaign.getImageUrl());
|
| 25683 |
tejbeer |
883 |
ns.setDocumentId(notificationCampaign.getDocumentId());
|
|
|
884 |
ns.setMessageType(notificationCampaign.getMessageType());
|
| 25649 |
tejbeer |
885 |
ns.setCreated(
|
|
|
886 |
notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
|
|
|
887 |
* 1000);
|
|
|
888 |
if (LocalDateTime.now().isAfter(expire)) {
|
|
|
889 |
ns.setExpired(true);
|
|
|
890 |
} else {
|
|
|
891 |
ns.setExpired(false);
|
|
|
892 |
}
|
|
|
893 |
notifications.add(ns);
|
|
|
894 |
}
|
|
|
895 |
}
|
| 25683 |
tejbeer |
896 |
} else {
|
|
|
897 |
for (NotificationCampaign notificationCampaign : nc) {
|
|
|
898 |
|
|
|
899 |
Notification ns = new Notification();
|
|
|
900 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
901 |
SimpleCampaignParams.class);
|
|
|
902 |
Campaign campaign = new SimpleCampaign(scp);
|
|
|
903 |
LocalDateTime expire = campaign.getExpireTimestamp();
|
|
|
904 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
|
|
905 |
ns.setType(campaign.getType());
|
|
|
906 |
ns.setMessage(campaign.getMessage());
|
|
|
907 |
ns.setTitle(campaign.getTitle());
|
|
|
908 |
if (notificationCampaign.getDocumentId() != null) {
|
|
|
909 |
document = documentRepository.selectById(notificationCampaign.getDocumentId());
|
|
|
910 |
ns.setDocumentName(document.getDisplayName());
|
|
|
911 |
}
|
|
|
912 |
ns.setUrl(campaign.getUrl());
|
|
|
913 |
ns.setShowImage(campaign.getShowImage());
|
|
|
914 |
ns.setImageUrl(campaign.getImageUrl());
|
|
|
915 |
ns.setDocumentId(notificationCampaign.getDocumentId());
|
|
|
916 |
ns.setMessageType(notificationCampaign.getMessageType());
|
|
|
917 |
ns.setCreated(notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
|
|
|
918 |
* 1000);
|
|
|
919 |
if (LocalDateTime.now().isAfter(expire)) {
|
|
|
920 |
ns.setExpired(true);
|
|
|
921 |
} else {
|
|
|
922 |
ns.setExpired(false);
|
|
|
923 |
}
|
|
|
924 |
notifications.add(ns);
|
|
|
925 |
}
|
|
|
926 |
|
| 25649 |
tejbeer |
927 |
}
|
| 25683 |
tejbeer |
928 |
return notifications;
|
| 25651 |
tejbeer |
929 |
|
|
|
930 |
}
|
| 25649 |
tejbeer |
931 |
|
| 25651 |
tejbeer |
932 |
@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
|
|
|
933 |
public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
|
|
|
934 |
@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
|
|
|
935 |
throws ProfitMandiBusinessException {
|
|
|
936 |
Document document = documentRepository.selectById(documentId);
|
|
|
937 |
NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
|
|
|
938 |
if (nc.getDocumentId() == null) {
|
|
|
939 |
throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
|
|
|
940 |
}
|
|
|
941 |
if (nc.getDocumentId() != documentId) {
|
|
|
942 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
|
|
|
943 |
}
|
|
|
944 |
return responseSender.ok(document);
|
| 25649 |
tejbeer |
945 |
}
|
|
|
946 |
|
| 25651 |
tejbeer |
947 |
@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
|
|
|
948 |
public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
|
|
|
949 |
throws ProfitMandiBusinessException {
|
|
|
950 |
|
|
|
951 |
NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
|
|
|
952 |
|
|
|
953 |
if (nc.getDocumentId() == null) {
|
|
|
954 |
throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
|
|
|
955 |
}
|
|
|
956 |
|
|
|
957 |
Document document = documentRepository.selectById(nc.getDocumentId());
|
|
|
958 |
|
|
|
959 |
FileInputStream file = null;
|
|
|
960 |
try {
|
|
|
961 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
|
|
962 |
} catch (FileNotFoundException e) {
|
|
|
963 |
LOGGER.error("Retailer Document file not found : ", e);
|
|
|
964 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
|
|
965 |
}
|
|
|
966 |
// ByteArrayOutputStream byteArrayOutputStream = new
|
|
|
967 |
// ByteArrayOutputStream();
|
|
|
968 |
// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
969 |
|
|
|
970 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
971 |
String contentType = "";
|
|
|
972 |
if (document.getContentType() == ContentType.JPEG) {
|
|
|
973 |
contentType = "image/jpeg";
|
|
|
974 |
} else if (document.getContentType() == ContentType.PNG) {
|
|
|
975 |
contentType = "image/png";
|
|
|
976 |
} else if (document.getContentType() == ContentType.PDF) {
|
|
|
977 |
contentType = "application/pdf";
|
|
|
978 |
}
|
|
|
979 |
headers.set("Content-Type", contentType);
|
|
|
980 |
headers.set("Content-disposition", "inline; filename=" + document.getName());
|
|
|
981 |
headers.setContentLength(document.getSize());
|
|
|
982 |
final InputStreamResource inputStreamResource = new InputStreamResource(file);
|
|
|
983 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
984 |
}
|
| 26422 |
tejbeer |
985 |
|
|
|
986 |
|
|
|
987 |
public Map<Integer, Object> getL2AuthUserPartnerDetail() throws Exception {
|
|
|
988 |
List<Position> pos = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
|
|
989 |
ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2);
|
| 25651 |
tejbeer |
990 |
|
| 26422 |
tejbeer |
991 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
992 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(
|
|
|
993 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
|
|
994 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1),
|
|
|
995 |
curDate.with(LocalTime.MAX), 0, false);
|
|
|
996 |
|
|
|
997 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
998 |
Map<Integer, Long> ticketMap = ticketRepository.selectAllNotClosedTicketsGroupByRetailer();
|
|
|
999 |
Map<Integer, Integer> authIdAndleadsCountMap = new HashMap<>();
|
|
|
1000 |
Map<Integer, List<Integer>> L2L1Mapping = csService.getL1L2Mapping();
|
|
|
1001 |
|
|
|
1002 |
for (Entry<Integer, List<Integer>> l2l1 : L2L1Mapping.entrySet()) {
|
|
|
1003 |
List<Integer> authIds = l2l1.getValue();
|
|
|
1004 |
authIds.add(l2l1.getKey());
|
|
|
1005 |
|
|
|
1006 |
List<Lead> leads = leadRepository.selectByAssignAuthIdsAndStatus(authIds, LeadStatus.followUp);
|
|
|
1007 |
|
|
|
1008 |
AuthUser auth = authRepository.selectById(l2l1.getKey());
|
| 26431 |
tejbeer |
1009 |
if (!leads.isEmpty()) {
|
|
|
1010 |
authIdAndleadsCountMap.put(auth.getId(), leads.size());
|
|
|
1011 |
} else {
|
|
|
1012 |
authIdAndleadsCountMap.put(auth.getId(), 0);
|
|
|
1013 |
}
|
| 26422 |
tejbeer |
1014 |
}
|
|
|
1015 |
|
|
|
1016 |
Map<Integer, Object> authIdAndallValues = new LinkedHashMap<>();
|
|
|
1017 |
|
|
|
1018 |
for (Position po : pos) {
|
|
|
1019 |
|
|
|
1020 |
double totallmtdAmount = 0;
|
|
|
1021 |
double totalmtdAmount = 0;
|
|
|
1022 |
int totalTicketCount = 0;
|
|
|
1023 |
float totalTodayInvestment = 0;
|
|
|
1024 |
float totalStockInInvestment = 0;
|
|
|
1025 |
double currentMonthRatingAllPartners = 0;
|
|
|
1026 |
|
|
|
1027 |
AuthUser auth = authRepository.selectById(po.getAuthUserId());
|
|
|
1028 |
|
|
|
1029 |
List<Integer> fofoIds = pp.get(po.getAuthUserId());
|
|
|
1030 |
|
|
|
1031 |
for (Integer fId : fofoIds) {
|
|
|
1032 |
Map<String, Object> investmentMap = this.getInvestments(fId);
|
|
|
1033 |
|
|
|
1034 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(fId,
|
|
|
1035 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
|
|
1036 |
|
|
|
1037 |
currentMonthRatingAllPartners += currentMonthRating;
|
|
|
1038 |
|
|
|
1039 |
fofoIds.size();
|
|
|
1040 |
|
|
|
1041 |
Double lmtdAmount = lmtdSale.get(fId);
|
|
|
1042 |
Double mtdAmount = mtdSale.get(fId);
|
|
|
1043 |
Long ticketCount = ticketMap.get(fId);
|
|
|
1044 |
|
|
|
1045 |
if (!investmentMap.isEmpty()) {
|
|
|
1046 |
totalTodayInvestment += (float) investmentMap.get("today");
|
|
|
1047 |
totalStockInInvestment += (float) investmentMap.get("inStock");
|
|
|
1048 |
|
|
|
1049 |
}
|
|
|
1050 |
LOGGER.info("totalTodayInvestment" + totalTodayInvestment);
|
|
|
1051 |
LOGGER.info("totalStockInInvestment" + totalStockInInvestment);
|
|
|
1052 |
if (ticketCount != null) {
|
|
|
1053 |
totalTicketCount += ticketCount;
|
|
|
1054 |
}
|
|
|
1055 |
|
|
|
1056 |
if (lmtdAmount != null) {
|
|
|
1057 |
totallmtdAmount += lmtdAmount;
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
if (mtdAmount != null) {
|
|
|
1061 |
totalmtdAmount += mtdAmount;
|
|
|
1062 |
}
|
|
|
1063 |
|
|
|
1064 |
}
|
|
|
1065 |
LOGGER.info("currentMonthRatingAllPartners" + currentMonthRatingAllPartners);
|
|
|
1066 |
LOGGER.info("size" + fofoIds.size());
|
|
|
1067 |
double totalHygieneRating = currentMonthRatingAllPartners / fofoIds.size();
|
|
|
1068 |
|
| 26432 |
tejbeer |
1069 |
LOGGER.info("authIdAndleadsCountMap" + authIdAndleadsCountMap.get(po.getAuthUserId()));
|
| 26422 |
tejbeer |
1070 |
|
|
|
1071 |
PartnerDetailModel pm = new PartnerDetailModel();
|
|
|
1072 |
pm.setLmtd(totallmtdAmount);
|
|
|
1073 |
pm.setMtd(totalmtdAmount);
|
|
|
1074 |
pm.setLeads(authIdAndleadsCountMap.get(po.getAuthUserId()));
|
|
|
1075 |
pm.setInvestment(totalTodayInvestment);
|
|
|
1076 |
pm.setStockInInvestment(totalStockInInvestment);
|
|
|
1077 |
pm.setTicket(totalTicketCount);
|
|
|
1078 |
pm.setHygiene((double) Math.round(totalHygieneRating));
|
|
|
1079 |
authIdAndallValues.put(auth.getId(), pm);
|
|
|
1080 |
|
|
|
1081 |
}
|
|
|
1082 |
return authIdAndallValues;
|
|
|
1083 |
}
|
|
|
1084 |
|
| 21615 |
kshitij.so |
1085 |
}
|