Subversion Repositories SmartDukaan

Rev

Rev 26419 | Rev 26448 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26419 Rev 26422
Line 678... Line 678...
678
 
678
 
679
		Map<Integer, List<Integer>> l2andl1Map = l1andl2Map.entrySet().stream().collect(
679
		Map<Integer, List<Integer>> l2andl1Map = l1andl2Map.entrySet().stream().collect(
680
				Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList())));
680
				Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList())));
681
		return l2andl1Map;
681
		return l2andl1Map;
682
	}
682
	}
683
 
-
 
684
	@Override
-
 
685
	public Map<Integer, Object> getL2AuthUserPartnerDetail() throws Exception {
-
 
686
		List<Position> pos = positionRepository.selectPositionbyCategoryIdAndEscalationType(
-
 
687
				ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2);
-
 
688
 
-
 
689
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
-
 
690
		Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(
-
 
691
				curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
-
 
692
		Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1),
-
 
693
				curDate.with(LocalTime.MAX), 0, false);
-
 
694
 
-
 
695
		Map<Integer, List<Integer>> pp = this.getAuthUserIdPartnerIdMapping();
-
 
696
		Map<Integer, Long> ticketMap = ticketRepository.selectAllNotClosedTicketsGroupByRetailer();
-
 
697
		Map<Integer, Integer> authIdAndleadsCountMap = new HashMap<>();
-
 
698
		Map<Integer, List<Integer>> L2L1Mapping = this.getL1L2Mapping();
-
 
699
 
-
 
700
		for (Entry<Integer, List<Integer>> l2l1 : L2L1Mapping.entrySet()) {
-
 
701
			List<Integer> authIds = l2l1.getValue();
-
 
702
			authIds.add(l2l1.getKey());
-
 
703
 
-
 
704
			List<Lead> leads = leadRepository.selectByAssignAuthIdsAndStatus(authIds, LeadStatus.followUp);
-
 
705
 
-
 
706
			AuthUser auth = authRepository.selectById(l2l1.getKey());
-
 
707
			authIdAndleadsCountMap.put(auth.getId(), leads.size());
-
 
708
		}
-
 
709
 
-
 
710
		Map<Integer, Object> authIdAndallValues = new LinkedHashMap<>();
-
 
711
 
-
 
712
		for (Position po : pos) {
-
 
713
 
-
 
714
			double totallmtdAmount = 0;
-
 
715
			double totalmtdAmount = 0;
-
 
716
			int totalTicketCount = 0;
-
 
717
			float totalTodayInvestment = 0;
-
 
718
			float totalStockInInvestment = 0;
-
 
719
			double currentMonthRatingAllPartners = 0;
-
 
720
 
-
 
721
			AuthUser auth = authRepository.selectById(po.getAuthUserId());
-
 
722
 
-
 
723
			List<Integer> fofoIds = pp.get(po.getAuthUserId());
-
 
724
 
-
 
725
			for (Integer fId : fofoIds) {
-
 
726
				Map<String, Object> investmentMap = this.getInvestments(fId);
-
 
727
 
-
 
728
				double currentMonthRating = hygieneDataRepository.selectRatingAvg(fId,
-
 
729
						curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
-
 
730
 
-
 
731
				currentMonthRatingAllPartners += currentMonthRating;
-
 
732
 
-
 
733
				fofoIds.size();
-
 
734
 
-
 
735
				Double lmtdAmount = lmtdSale.get(fId);
-
 
736
				Double mtdAmount = mtdSale.get(fId);
-
 
737
				Long ticketCount = ticketMap.get(fId);
-
 
738
 
-
 
739
				if (!investmentMap.isEmpty()) {
-
 
740
					totalTodayInvestment += (float) investmentMap.get("today");
-
 
741
					totalStockInInvestment += (float) investmentMap.get("inStock");
-
 
742
 
-
 
743
				}
-
 
744
				LOGGER.info("totalTodayInvestment" + totalTodayInvestment);
-
 
745
				LOGGER.info("totalStockInInvestment" + totalStockInInvestment);
-
 
746
				if (ticketCount != null) {
-
 
747
					totalTicketCount += ticketCount;
-
 
748
				}
-
 
749
 
-
 
750
				if (lmtdAmount != null) {
-
 
751
					totallmtdAmount += lmtdAmount;
-
 
752
				}
-
 
753
 
-
 
754
				if (mtdAmount != null) {
-
 
755
					totalmtdAmount += mtdAmount;
-
 
756
				}
-
 
757
 
-
 
758
			}
-
 
759
			LOGGER.info("currentMonthRatingAllPartners" + currentMonthRatingAllPartners);
-
 
760
			LOGGER.info("size" + fofoIds.size());
-
 
761
			double totalHygieneRating = currentMonthRatingAllPartners / fofoIds.size();
-
 
762
 
-
 
763
			LOGGER.info("totalHygieneRating" + totalHygieneRating);
-
 
764
 
-
 
765
			PartnerDetailModel pm = new PartnerDetailModel();
-
 
766
			pm.setLmtd(totallmtdAmount);
-
 
767
			pm.setMtd(totalmtdAmount);
-
 
768
			if(authIdAndleadsCountMap.get(po.getAuthUserId())!=null) {
-
 
769
				pm.setLeads(authIdAndleadsCountMap.get(po.getAuthUserId()));
-
 
770
			}
-
 
771
			pm.setInvestment(totalTodayInvestment);
-
 
772
			pm.setStockInInvestment(totalStockInInvestment);
-
 
773
			pm.setTicket(totalTicketCount);
-
 
774
			pm.setHygiene((double) Math.round(totalHygieneRating));
-
 
775
			authIdAndallValues.put(auth.getId(), pm);
-
 
776
 
-
 
777
		}
-
 
778
		return authIdAndallValues;
-
 
779
	}
-
 
780
 
-
 
781
	private Map<String, Object> getInvestments(int fofoId) throws Exception {
-
 
782
		Map<String, Object> investments = new LinkedHashMap<>();
-
 
783
 
-
 
784
		PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
-
 
785
		LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
-
 
786
		LocalDate yesterDate = LocalDate.now().minusDays(1);
-
 
787
		PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
-
 
788
		if (yesterdayInvestment == null) {
-
 
789
			yesterdayInvestment = new PartnerDailyInvestment();
-
 
790
		}
-
 
791
 
-
 
792
		List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
-
 
793
				currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
-
 
794
 
-
 
795
		long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
-
 
796
				.collect(Collectors.counting());
-
 
797
		investments.put("today", investment.getTotalInvestment());
-
 
798
		investments.put("investment", investment);
-
 
799
		investments.put("inStock", investment.getInStockAmount());
-
 
800
		investments.put("minimum", investment.getMinInvestmentString());
-
 
801
		investments.put("short", investment.getShortPercentage());
-
 
802
		investments.put("activated_stock", investment.getActivatedStockAmount());
-
 
803
		investments.put("okDays", okInvestmentDays);
-
 
804
 
-
 
805
		return investments;
-
 
806
	}
683
	
807
}
684
}