package shop.alien.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.StoreImg;
import shop.alien.entity.store.vo.StoreImgTypeVo;

import java.util.List;

/**
 * 门店图片 Mapper 接口
 *
 * @author ssk
 * @since 2024-12-05
 */
@Mapper
public interface StoreImgMapper extends BaseMapper<StoreImg> {

    @Select("select IFNULL(img_type, 0) img_type, count(1) count, img_url imgUrl from store_img where store_id = #{storeId} and img_type = 0 and delete_flag= 0 " +
            "union all " +
            "select IFNULL(img_type, 3) img_type, count(1) count, img_url imgUrl from store_img where store_id = #{storeId} and img_type = 3 and delete_flag= 0 " +
            "union all " +
            "select IFNULL(img_type, 4) img_type, count(1) count, img_url imgUrl from store_img where store_id = #{storeId} and img_type = 4 and delete_flag= 0 " +
            "union all " +
            "select IFNULL(img_type, 5) img_type, count(1) count, img_url imgUrl from store_img where store_id = #{storeId} and img_type = 5 and delete_flag= 0")
    List<StoreImgTypeVo> getStoreImgTypeCount(@Param("storeId") Integer storeId);

    /**
     * 根据商品id获取图片
     *
     * @param queryWrapper 商品id
     * @return 商品图片
     */
    @Select("SELECT * " +
            "FROM store_img ${ew.customSqlSegment}")
    List<StoreImg> getImgsByGoodsIds(@Param(Constants.WRAPPER) QueryWrapper<StoreImg> queryWrapper);
}
