package com.haha.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.haha.entity.ShopReplenisher;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 门店补货员关联Mapper
 */
@Mapper
public interface ShopReplenisherMapper extends BaseMapper<ShopReplenisher> {

    /**
     * 获取门店补货员列表（带管理员信息）
     */
    @Select("SELECT sr.*, a.real_name as nickname, a.phone, a.avatar " +
            "FROM t_shop_replenisher sr " +
            "LEFT JOIN t_admin a ON sr.admin_id = a.id " +
            "WHERE sr.shop_id = #{shopId} " +
            "ORDER BY sr.create_time DESC")
    List<ShopReplenisher> selectByShopId(@Param("shopId") Long shopId);

    /**
     * 检查管理员是否已是某门店的补货员
     */
    @Select("SELECT COUNT(*) FROM t_shop_replenisher WHERE shop_id = #{shopId} AND admin_id = #{adminId}")
    int countByShopIdAndAdminId(@Param("shopId") Long shopId, @Param("adminId") Long adminId);

    /**
     * 获取管理员关联的所有门店补货员记录
     */
    @Select("SELECT sr.*, s.name as shop_name FROM t_shop_replenisher sr " +
            "LEFT JOIN t_shop s ON sr.shop_id = s.id " +
            "WHERE sr.admin_id = #{adminId}")
    List<ShopReplenisher> selectByAdminId(@Param("adminId") Long adminId);
}
