package com.fs.his.mapper;

import com.fs.his.domain.FsStoreBill;
import com.fs.his.param.FsStoreBillParam;
import com.fs.his.vo.FsStoreBillVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 店铺帐单记录Mapper接口
 *
 * @author fs
 * @date 2023-06-25
 */
public interface FsStoreBillMapper
{
    /**
     * 查询店铺帐单记录
     *
     * @param billId 店铺帐单记录主键
     * @return 店铺帐单记录
     */
    public FsStoreBill selectFsStoreBillByBillId(Long billId);

    /**
     * 查询店铺帐单记录列表
     *
     * @param fsStoreBill 店铺帐单记录
     * @return 店铺帐单记录集合
     */
    public List<FsStoreBill> selectFsStoreBillList(FsStoreBill fsStoreBill);

    /**
     * 新增店铺帐单记录
     *
     * @param fsStoreBill 店铺帐单记录
     * @return 结果
     */
    public int insertFsStoreBill(FsStoreBill fsStoreBill);

    /**
     * 修改店铺帐单记录
     *
     * @param fsStoreBill 店铺帐单记录
     * @return 结果
     */
    public int updateFsStoreBill(FsStoreBill fsStoreBill);

    /**
     * 删除店铺帐单记录
     *
     * @param billId 店铺帐单记录主键
     * @return 结果
     */
    public int deleteFsStoreBillByBillId(Long billId);

    /**
     * 批量删除店铺帐单记录
     *
     * @param billIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsStoreBillByBillIds(Long[] billIds);

    @Select({"<script> " +
                "select sb.*,fs.store_name name from fs_store_bill sb LEFT JOIN fs_store fs ON fs.store_id=sb.store_id "+
            "<where>  \n" +
            "            <if test=\"billId != null \"> and sb.bill_id = #{billId}</if>\n" +
            "            <if test=\"storeId != null \"> and sb.store_id = #{storeId}</if>\n" +
            "            <if test=\"title != null  and title != ''\"> and sb.title = #{title}</if>\n" +
            "            <if test=\"money != null \"> and sb.money = #{money}</if>\n" +
            "            <if test=\"storeName != null \"> and  fs.store_name like concat('%', #{storeName}, '%')</if>\n" +
            "            <if test=\"balance != null \"> and sb.balance = #{balance}</if>\n" +
            "            <if test=\"billType != null \"> and sb.bill_type = #{billType}</if>\n" +
            "            <if test=\"businessId != null  and businessId != ''\"> and sb.business_id = #{businessId}</if>\n" +
            "            <if test=\"sTime != null \">  and DATE(sb.create_time) &gt;= DATE(#{sTime})</if>\n" +
            "            <if test=\"eTime != null \">  and DATE(sb.create_time) &lt;= DATE(#{eTime})</if>\n" +
            "        </where>"+
            "order by sb.bill_id desc "+
            "</script>"})
    List<FsStoreBillVO> selectFsStoreBillListVO(FsStoreBillParam fsStoreBill);
}
