package org.jeecg.modules.hotelleaselog.mapper;

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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.hotelleaselog.entity.HotelLeaseLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: hotel_lease_log
 * @Author: jeecg-boot
 * @Date:   2024-09-21
 * @Version: V1.0
 */
public interface HotelLeaseLogMapper extends BaseMapper<HotelLeaseLog> {

    /**
     * 我的租赁
     * @param page
     * @param userId
     * @return
     */
    IPage<HotelLeaseLog> myLeaseLogPage(Page<HotelLeaseLog> page,@Param("userId") String userId,@Param("leaseFlag") Integer leaseFlag,@Param("status") Integer status);

    /**
     * 获取所有水洗租金
     * @param userId
     * @return
     */
    @Select("SELECT SUM(IFNULL((SELECT `value` FROM hotel_conf WHERE `name` = 'depositPrice')*a.num*IFNULL(DATEDIFF(NOW(),a.start_time),0),0)) price\n" +
            "FROM hotel_lease_log a LEFT JOIN hotel_goods_sku b\n" +
            "    ON a.sku_id = b.id WHERE a.del_flag = 0 AND a.user_id = #{userId} AND a.lease_flag = 1\n" +
            "AND a.status = 0 AND a.start_time IS NOT NULL;")
    BigDecimal getAllDepositPrice(@Param("userId") String userId);

    /**
     * 统计桌布库存
     * @param userId
     * @return
     */
    @Select("SELECT SUM(num) FROM hotel_lease_log WHERE del_flag = 0 AND user_id = #{userId}")
    Integer sumLeaseNum(@Param("userId") String userId);

}
