Subversion Repositories SmartDukaan

Rev

Rev 27476 | Rev 27529 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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