package com.fs.his.mapper;

import com.fs.his.domain.FsUserBill;
import com.fs.his.param.FsUserBillParam;
import com.fs.his.vo.FsUserBillVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户帐单记录Mapper接口
 *
 * @author fs
 * @date 2023-06-25
 */
public interface FsUserBillMapper
{
    /**
     * 查询用户帐单记录
     *
     * @param billId 用户帐单记录主键
     * @return 用户帐单记录
     */
    public FsUserBill selectFsUserBillByBillId(Long billId);

    /**
     * 查询用户帐单记录列表
     *
     * @param fsUserBill 用户帐单记录
     * @return 用户帐单记录集合
     */
    public List<FsUserBill> selectFsUserBillList(FsUserBill fsUserBill);

    /**
     * 新增用户帐单记录
     *
     * @param fsUserBill 用户帐单记录
     * @return 结果
     */
    public int insertFsUserBill(FsUserBill fsUserBill);

    /**
     * 修改用户帐单记录
     *
     * @param fsUserBill 用户帐单记录
     * @return 结果
     */
    public int updateFsUserBill(FsUserBill fsUserBill);

    /**
     * 删除用户帐单记录
     *
     * @param billId 用户帐单记录主键
     * @return 结果
     */
    public int deleteFsUserBillByBillId(Long billId);

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

    @Select({"<script> " +
            " select ub.*,fu.nick_name name,fu.phone from fs_user_bill ub LEFT JOIN fs_user fu ON fu.user_id = ub.user_id"+
            "<where>\n" +
            "            <if test=\"billId != null \"> and ub.bill_id = #{billId}</if>\n" +
            "            <if test=\"userId != null \"> and ub.user_id = #{userId}</if>\n" +
            "            <if test=\"title != null  and title != ''\"> and ub.title = #{title}</if>\n" +
            "            <if test=\"money != null \"> and ub.money = #{money}</if>\n" +
            "            <if test=\"phone != null \"> and fu.phone = #{phone}</if>\n" +
            "            <if test=\"balance != null \"> and ub.balance = #{balance}</if>\n" +
            "            <if test=\"billType != null \"> and ub.bill_type = #{billType}</if>\n" +
            "            <if test=\"createTime != null \"> and  ub.DATE(create_time) = #{createTime}</if>\n" +
            "            <if test=\"businessId != null  and businessId != ''\"> and ub.business_id = #{businessId}</if>\n" +
            "            <if test=\"sTime != null \">  and DATE(ub.create_time) &gt;= DATE(#{sTime})</if>\n" +
            "            <if test=\"eTime != null \">  and DATE(ub.create_time) &lt;= DATE(#{eTime})</if>\n" +
            "        </where>\n" +
            "        order by bill_id desc"+
            "</script>"})
    List<FsUserBillVO> selectFsUserBillListVO(FsUserBillParam fsUserBill);
}
