package com.gxwebsoft.cms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gxwebsoft.cms.entity.CustomerLeadEntity;
import com.gxwebsoft.cms.param.CustomerLeadParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
 * 客资管理Mapper
 *
 * @author 科技小王子
 * @since 2026-04-14
 */
@Mapper
public interface CustomerLeadMapper extends BaseMapper<CustomerLeadEntity> {

    /**
     * 分页查询客资列表
     */
    List<CustomerLeadEntity> selectLeadPage(CustomerLeadParam param);

    /**
     * 查询客资详情
     */
    CustomerLeadEntity selectLeadDetail(@Param("leadId") Integer leadId);

    /**
     * 获取业务员待处理客资数量
     */
    Integer countBySalesman(@Param("salesmanId") Integer salesmanId, @Param("status") Integer status);

    /**
     * 批量更新客资状态
     */
    int batchUpdateStatus(@Param("leadIds") List<Integer> leadIds, @Param("status") Integer status);

    /**
     * 派单给业务员
     */
    int dispatchToUser(@Param("leadId") Integer leadId, @Param("userId") Integer userId, 
                       @Param("adminId") Integer adminId, @Param("remarks") String remarks);

    /**
     * 统计数据
     */
    Map<String, Object> selectStatistics(@Param("startDate") String startDate, @Param("endDate") String endDate,
                                         @Param("salesmanId") Integer salesmanId);

    /**
     * 按状态统计
     */
    List<Map<String, Object>> selectStatusStatistics(@Param("startDate") String startDate, @Param("endDate") String endDate);

    /**
     * 按来源统计
     */
    List<Map<String, Object>> selectSourceStatistics(@Param("startDate") String startDate, @Param("endDate") String endDate);

    /**
     * 按日统计趋势
     */
    List<Map<String, Object>> selectDailyTrend(@Param("startDate") String startDate, @Param("endDate") String endDate);

    /**
     * 查询未分配客资
     */
    List<CustomerLeadEntity> selectUnassignedLeads();

    /**
     * 批量派单
     */
    int batchDispatch(@Param("leadIds") List<Integer> leadIds, @Param("userId") Integer userId,
                      @Param("adminId") Integer adminId, @Param("remarks") String remarks);
}
