package com.fs.store.mapper;

import java.math.BigDecimal;
import java.util.List;
import com.fs.store.domain.FsUserBill;
import com.fs.store.param.FsUserBillParam;
import com.fs.store.param.FsUserBillQueryParam;
import com.fs.store.vo.FsUserBillVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 用户账单Mapper接口
 * 
 * @author fs
 * @date 2022-04-03
 */
public interface FsUserBillMapper 
{
    /**
     * 查询用户账单
     * 
     * @param id 用户账单ID
     * @return 用户账单
     */
    public FsUserBill selectFsUserBillById(Long id);

    /**
     * 查询用户账单列表
     * 
     * @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 id 用户账单ID
     * @return 结果
     */
    public int deleteFsUserBillById(Long id);

    /**
     * 批量删除用户账单
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsUserBillByIds(Long[] ids);

    @Select({"<script> " +
            "select * from fs_user_bill " +
            "where 1=1 " +
            "<if test = 'maps.billType != null and maps.billType != -1    '> " +
            "and bill_type =#{maps.billType} " +
            "</if>" +
            "<if test = 'maps.userId != null  '> " +
            "and user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.category != null and maps.category  != \"\"  '> " +
            "and category =#{maps.category} " +
            "</if>" +
            " order by id desc "+
            "</script>"})
    List<FsUserBill> selectFsUserBillListQuery(@Param("maps") FsUserBillQueryParam param);
    @Select({"<script> " +
            "select b.*,u.nickname,u.phone from fs_user_bill b left join fs_user u on u.user_id=b.user_id " +
            "where 1=1 " +
            "<if test = 'maps.nickname != null and maps.nickname != \"\"   '> " +
            "and u.nickname like concat('%',#{maps.nickname,jdbcType=VARCHAR},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and maps.phone != \"\"   '> " +
            "and u.phone like concat('%',#{maps.phone,jdbcType=VARCHAR},'%') " +
            "</if>" +
            "<if test = 'maps.beginTime != null and maps.beginTime != \"\"   '> " +
            "and date_format(b.create_time,'%y%m%d') &gt;=  date_format(#{maps.beginTime},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.endTime != null and maps.endTime != \"\"   '> " +
            "and date_format(b.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d') " +
            "</if>" +
            " order by b.id desc "+
            "</script>"})
    List<FsUserBillVO> selectFsUserBillListVO(@Param("maps")FsUserBillParam fsUserBill);
    @Select({"<script> " +
            "select ifnull(sum(number),0) from fs_user_bill " +
            "where user_id=#{userId} " +
            "<if test = 'cate != null  and cate != \"\"  '> " +
            "and category=#{cate} " +
            "</if>" +
            "and DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT( DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%Y-%m-%d') " +
            "</script>"})
    BigDecimal selectFsUserBillTotalByUserId(@Param("userId")String userId,@Param("cate") String cate);
}
