Subversion Repositories SmartDukaan

Rev

Rev 36984 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.repository.dtr;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.dao.entity.auth.AuthUser;
import com.spice.profitmandi.dao.entity.user.Lead;
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
import com.spice.profitmandi.dao.model.LeadDetailModel;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface LeadRepository {

    public void persist(Lead lead);

    public List<Lead> selectByAssignAuthIdAndStatus(int authId, LeadStatus status, int offset, int limit);

    public Lead selectById(int id);

    List<Lead> selectAllByColorStatusAndBetweenDate(List<LeadStatus> status, List<String> color, LocalDateTime createdTimestamp, LocalDateTime endDateTimeStamp);

    public List<Lead> selectAllByIds(List<Integer> ids);

    public List<Lead> selectByAssignAuthIdAndStatus(int authId, LeadStatus status);

    public List<Lead> selectByAssignAuthIdsAndStatus(List<Integer> authId, LeadStatus status);

    public List<Lead> selectAll(int offset, int limit);

    public List<Lead> selectAllBylistStatus(List<LeadStatus> status) throws ProfitMandiBusinessException;

    public List<Lead> selectAllByStatus(LeadStatus status);

    public List<Lead> selectAllByStatusAndUpdatedTimestamp(List<LeadStatus> status, LocalDateTime updatedTimestamp);

    public List<Lead> selectAllByStatus(List<LeadStatus> status, int offset, int limit);

    List<Lead> selectLeadsScheduledBetweenDate(List<Integer> fofoIds, LocalDateTime startDate, LocalDateTime endDate);

    public long selectCountByStatus(List<LeadStatus> status);

    public long getLeadCount(LeadStatus status, String searchTerm);

    public List<Lead> selectBySearchTerm(List<LeadStatus> status, String searchTerm, int offset, int limit);

    // Global lead search: matches name / mobile / outlet / city across ALL leads (any status, any date).
    public List<Lead> selectByGlobalSearch(String searchTerm, int limit);

    public List<Lead> selectAllByColorStatusAndUpdatedTimestamp(List<LeadStatus> status, List<String> color, LocalDateTime updatedTimestamp);

    public List<Lead> selectAllByColorStatusAndCreatedTimestamp(List<LeadStatus> status, List<String> color, LocalDateTime createdTimestamp);

    List<Lead> selectAllByStatusAndUpdatedTimestampAndAuthId(List<LeadStatus> status, LocalDateTime updatedTimestamp, List<Integer> authIds);

    List<Lead> selectAllByColorStatusAndUpdatedTimestampAndAuthIds(List<LeadStatus> status, List<Integer> authIds, List<String> color, LocalDateTime updatedTimestamp);

    List<Lead> selectAllByColorStatusAndBetweenCreatedDate(List<LeadStatus> status, List<String> color, LocalDateTime startDate, LocalDateTime endDate);

    List<Lead> selectAllByColorStatusAndBetweenCreatedDateAndAuthIds(List<LeadStatus> status, List<Integer> authIds, List<String> color, LocalDateTime startDate, LocalDateTime endDate);

    public void persistLeadDetail(LeadDetailModel leadDetailModel, AuthUser authUser) throws ProfitMandiBusinessException;

    Lead selectByMobileNumber(String mobileNumber);

    Lead selectByMobileNumberAndSource(String mobileNumber, String source);

    // ---- LMS dashboard aggregation (SOP §18) -------------------------------------------------
    // All aggregates bucket EVERY lead: rows with a real `stage` use it; legacy rows (stage NULL)
    // derive a stage from `status` in SQL, mirroring LeadStage.fromLegacy. Read-only, no schema change.

    /** (derivedStage, count) for the optional region + created-date window. */
    java.util.List<Object[]> countByDerivedStage(Integer regionId, LocalDateTime from, LocalDateTime to);

    /** (derivedStage, SUM(potential)) for the optional region + window — for the onboarded-value KPI. */
    java.util.List<Object[]> sumPotentialByDerivedStage(Integer regionId, LocalDateTime from, LocalDateTime to);

    /** (regionCode, derivedStage, count) across all regions in the window — feeds the state funnel. */
    java.util.List<Object[]> countByRegionAndDerivedStage(LocalDateTime from, LocalDateTime to);

    /** (regionCode, totalWithDue, onTime) — first-contact SLA compliance per region. */
    java.util.List<Object[]> slaComplianceByRegion(LocalDateTime from, LocalDateTime to);

    /** (ownerBmId, isoYearWeek, totalWithDue, onTime) — SLA compliance per BM per week, for the heat-map. */
    java.util.List<Object[]> slaComplianceByBmAndWeek(LocalDateTime from, LocalDateTime to);

    /** (derivedStage, count) of OPEN leads not touched since {@code olderThan} — the ageing widget. */
    java.util.List<Object[]> ageingByDerivedStage(LocalDateTime olderThan);

    /** Single row of conditional-sum attention counts (see impl) for the optional region. */
    Object[] attentionCounts(Integer regionId, LocalDateTime now, LocalDateTime nowPlus1h);

    /** Lead ids for a drill-down bucket (STAGE / ATTENTION / REGION), newest first, capped at {@code limit}. */
    java.util.List<Integer> selectLeadIdsForBucket(String bucketType, String bucketKey, Integer regionId,
                                                   LocalDateTime now, LocalDateTime nowPlus1h,
                                                   LocalDateTime from, LocalDateTime to, int limit);
}