package com.czg.service.account.mapper;

import com.czg.account.dto.shopinfo.ShopInfoSubVO;
import com.czg.account.entity.ShopInfo;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.cache.annotation.Cacheable;

import java.math.BigDecimal;
import java.util.List;

/**
 * 店铺信息 映射层。
 *
 * @author Administrator
 * @since 2025-02-10
 */
public interface ShopInfoMapper extends BaseMapper<ShopInfo> {

    List<ShopInfoSubVO> getSubList(@Param("lng") String lng, @Param("lat") String lat, @Param("distance") float distance);

    @Update("update tb_shop_info set amount = amount + #{amount} where id = #{id} and amount + #{amount} >= 0")
    boolean updateAmount(@Param("id") Long id, @Param("amount") BigDecimal amount);

    /**
     * 获取所有未删除的 过期时间>三天前  店铺id列表
     *
     * @return 店铺id列表
     */
    @Select("SELECT id " +
            "FROM tb_shop_info " +
            "WHERE id > 1 " +
            "  AND expire_time > DATE_SUB(NOW(), INTERVAL 3 DAY) " +
            "  AND is_deleted = 0;")
    List<Long> getShopIdList();
}
