Subversion Repositories SmartDukaan

Rev

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

Rev 35536 Rev 35537
Line 18... Line 18...
18
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
18
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
19
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
19
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
20
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
20
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
21
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
21
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
22
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
22
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
-
 
23
import com.spice.profitmandi.dao.model.PartnerTertiarySalesModel;
23
import com.spice.profitmandi.service.user.RetailerService;
24
import com.spice.profitmandi.service.user.RetailerService;
24
import org.apache.logging.log4j.LogManager;
25
import org.apache.logging.log4j.LogManager;
25
import org.apache.logging.log4j.Logger;
26
import org.apache.logging.log4j.Logger;
26
import org.springframework.beans.factory.annotation.Autowired;
27
import org.springframework.beans.factory.annotation.Autowired;
27
import org.springframework.stereotype.Component;
28
import org.springframework.stereotype.Component;
Line 79... Line 80...
79
    @Override
80
    @Override
80
    // @Cacheable(value = "partnerStats", cacheManager =
81
    // @Cacheable(value = "partnerStats", cacheManager =
81
    // "thirtyMinsTimeOutCacheManager")
82
    // "thirtyMinsTimeOutCacheManager")
82
    public Map<Integer, PartnerDetailModel> getAllPartnerStats() throws ProfitMandiBusinessException {
83
    public Map<Integer, PartnerDetailModel> getAllPartnerStats() throws ProfitMandiBusinessException {
83
        LocalDateTime curDate = LocalDate.now().atStartOfDay();
84
        LocalDateTime curDate = LocalDate.now().atStartOfDay();
84
        Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
-
 
85
                curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
-
 
86
 
85
 
-
 
86
        // Batch fetch all tertiary sales data in a single query (performance optimization)
-
 
87
        // Combines 5 separate queries: lmtdSale, mtdSale, lmsSale, todaytertiary, last3daystertiary
87
        Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1),
88
        Map<Integer, PartnerTertiarySalesModel> tertiarySalesMap = fofoOrderItemRepository.selectPartnerTertiarySales(
-
 
89
                curDate.withDayOfMonth(1).minusMonths(1),      // lmtdStartDate
88
                curDate.with(LocalTime.MAX), 0, false);
90
                curDate.with(LocalTime.MAX).minusMonths(1),    // lmtdEndDate
89
 
-
 
90
        Map<Integer, Double> lmsSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
91
                curDate.withDayOfMonth(1),                      // mtdStartDate
-
 
92
                curDate.with(LocalTime.MAX),                    // mtdEndDate
91
                curDate.withDayOfMonth(1).minusMonths(1), curDate.withDayOfMonth(1), 0, false);
93
                curDate.withDayOfMonth(1).minusMonths(1),      // lmsStartDate
92
 
-
 
-
 
94
                curDate.withDayOfMonth(1),                      // lmsEndDate
93
        Map<Integer, Double> todaytertiary = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate,
95
                curDate,                                        // todayStartDate
94
                curDate.with(LocalTime.MAX), 0, false);
96
                curDate.with(LocalTime.MAX),                    // todayEndDate
95
 
-
 
96
        Map<Integer, Long> last3daystertiary = fofoOrderItemRepository.selectQtyGroupByRetailer(curDate.minusDays(4),
97
                curDate.minusDays(4),                           // last3daysStartDate
97
                curDate.minusDays(1).with(LocalTime.MAX), 0, false);
98
                curDate.minusDays(1).with(LocalTime.MAX)        // last3daysEndDate
-
 
99
        );
98
 
100
 
99
        Map<Integer, Long> ticketMap = ticketRepository.selectAllOpenTicketsGroupByRetailer();
101
        Map<Integer, Long> ticketMap = ticketRepository.selectAllOpenTicketsGroupByRetailer();
100
 
102
 
101
        Map<Integer, Double> secondaryMtd = orderRepository
103
        Map<Integer, Double> secondaryMtd = orderRepository
102
                .selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
104
                .selectBillingDatesBetweenSumGroupByRetailerId(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
Line 179... Line 181...
179
 
181
 
180
            // Use batch-fetched auth user escalations instead of N+1 queries
182
            // Use batch-fetched auth user escalations instead of N+1 queries
181
            Map<EscalationType, AuthUser> authuserEsclationTypeMap = authUserEscalationMap.getOrDefault(fofoId, new HashMap<>());
183
            Map<EscalationType, AuthUser> authuserEsclationTypeMap = authUserEscalationMap.getOrDefault(fofoId, new HashMap<>());
182
            PartnerDetailModel pm = new PartnerDetailModel();
184
            PartnerDetailModel pm = new PartnerDetailModel();
183
            pm.setFofoId(fofoId);
185
            pm.setFofoId(fofoId);
-
 
186
            // Use batch-fetched tertiary sales data instead of 5 separate queries
-
 
187
            PartnerTertiarySalesModel tertiarySales = tertiarySalesMap.get(fofoId);
184
            pm.setLmtd(lmtdSale.get(fofoId) == null ? 0 : lmtdSale.get(fofoId).intValue());
188
            pm.setLmtd(tertiarySales == null ? 0 : (int) tertiarySales.getLmtdSale());
185
            pm.setMtd(mtdSale.get(fofoId) == null ? 0 : mtdSale.get(fofoId).intValue());
189
            pm.setMtd(tertiarySales == null ? 0 : (int) tertiarySales.getMtdSale());
186
            pm.setLms(lmsSale.get(fofoId) == null ? 0 : lmsSale.get(fofoId).intValue());
190
            pm.setLms(tertiarySales == null ? 0 : (int) tertiarySales.getLmsSale());
187
            pm.setSecondarymtd(secondaryMtd.get(fofoId) == null ? 0 : secondaryMtd.get(fofoId).intValue());
191
            pm.setSecondarymtd(secondaryMtd.get(fofoId) == null ? 0 : secondaryMtd.get(fofoId).intValue());
188
            pm.setSecondarylmtd(secondarylmtd.get(fofoId) == null ? 0 : secondarylmtd.get(fofoId).intValue());
192
            pm.setSecondarylmtd(secondarylmtd.get(fofoId) == null ? 0 : secondarylmtd.get(fofoId).intValue());
189
            pm.setSecondarylms(secondarylms.get(fofoId) == null ? 0 : secondarylms.get(fofoId).intValue());
193
            pm.setSecondarylms(secondarylms.get(fofoId) == null ? 0 : secondarylms.get(fofoId).intValue());
190
            pm.setTodayTertiary(todaytertiary.get(fofoId) == null ? 0 : todaytertiary.get(fofoId).intValue());
194
            pm.setTodayTertiary(tertiarySales == null ? 0 : (int) tertiarySales.getTodaySale());
191
            pm.setLastThreeDaytertiary(last3daystertiary.get(fofoId) == null ? 0 : last3daystertiary.get(fofoId));
195
            pm.setLastThreeDaytertiary(tertiarySales == null ? 0 : tertiarySales.getLast3daysQty());
192
            pm.setWalletAmount(userWallet.get(fofoId) == null ? 0 : userWallet.get(fofoId).getAmount());
196
            pm.setWalletAmount(userWallet.get(fofoId) == null ? 0 : userWallet.get(fofoId).getAmount());
193
            pm.setInvestment(investmentMap.get(fofoId));
197
            pm.setInvestment(investmentMap.get(fofoId));
194
            pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
198
            pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
195
            pm.setHygiene(hygieneCount);
199
            pm.setHygiene(hygieneCount);
196
            pm.setInvestment_ok(
200
            pm.setInvestment_ok(