package com.fs.company.mapper;

import java.math.BigDecimal;
import java.util.List;
import com.fs.company.domain.CompanyRecharge;
import com.fs.company.vo.CompanyRechargeExportVO;
import com.fs.company.vo.CompanyRechargeVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 充值Mapper接口
 *
 * @author fs
 * @date 2021-10-04
 */
public interface CompanyRechargeMapper
{
    /**
     * 查询充值
     *
     * @param rechargeId 充值ID
     * @return 充值
     */
    public CompanyRecharge selectCompanyRechargeById(Long rechargeId);

    /**
     * 查询充值列表
     *
     * @param companyRecharge 充值
     * @return 充值集合
     */
    public List<CompanyRecharge> selectCompanyRechargeList(CompanyRecharge companyRecharge);

    /**
     * 新增充值
     *
     * @param companyRecharge 充值
     * @return 结果
     */
    public int insertCompanyRecharge(CompanyRecharge companyRecharge);

    /**
     * 修改充值
     *
     * @param companyRecharge 充值
     * @return 结果
     */
    public int updateCompanyRecharge(CompanyRecharge companyRecharge);

    /**
     * 删除充值
     *
     * @param rechargeId 充值ID
     * @return 结果
     */
    public int deleteCompanyRechargeById(Long rechargeId);

    /**
     * 批量删除充值
     *
     * @param rechargeIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteCompanyRechargeByIds(Long[] rechargeIds);
    @Select({"<script> " +
            "select r.*,c.company_name,su1.nick_name as create_user_nick_name ,su2.nick_name as audit_user_nick_name " +
            "from company_recharge r left join company c on c.company_id=r.company_id " +
            " left join sys_user su1 on su1.user_id=r.create_user_id " +
            " left join sys_user su2 on su2.user_id=r.audit_user_id " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null  '> " +
            "and r.company_id = #{maps.companyId}" +
            "</if>" +
            "<if test = 'maps.rechargeNo != null and maps.rechargeNo !=\"\" '> " +
            "and r.recharge_no = #{maps.rechargeNo}" +
            "</if>" +
            "<if test = 'maps.status != null  '> " +
            "and r.status = #{maps.status}" +
            "</if>" +
            "<if test = 'maps.isAudit != null  '> " +
            "and r.is_audit = #{maps.isAudit}" +
            "</if>" +
            "<if test = 'maps.payType != null  '> " +
            "and r.pay_type = #{maps.payType}" +
            "</if>" +
            "<if test = 'maps.businessType != null  '> " +
            "and r.business_type = #{maps.businessType}" +
            "</if>" +
            "<if test= 'maps.params != null and maps.params !=\"\"'>"+
            "<if test = 'maps.params.beginTime != null and maps.params.beginTime != \"\" '> " +
            "and date_format(r.pay_time,'%y%m%d') &gt;= date_format(#{maps.params.beginTime},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.params.endTime != null and maps.params.endTime != \"\" '> " +
            "and date_format(r.pay_time,'%y%m%d') &lt;= date_format(#{maps.params.endTime},'%y%m%d') " +
            "</if>"+
            "</if>" +
            "order by r.recharge_id desc " +
            "</script>"})
    List<CompanyRechargeVO> selectCompanyRechargeVOList(@Param("maps")CompanyRecharge companyRecharge);

    @Select("select * from company_recharge where recharge_no=#{no}")
    CompanyRecharge selectCompanyRechargeByNo(String no);

    @Select("select sum(money) from company_recharge where status=1")
    BigDecimal selectCompanyRechargeMoney();


    @Select({"<script> " +
            "select r.*,c.company_name,su1.nick_name as create_user_nick_name ,su2.nick_name as audit_user_nick_name " +
            "from company_recharge r left join company c on c.company_id=r.company_id " +
            " left join sys_user su1 on su1.user_id=r.create_user_id " +
            " left join sys_user su2 on su2.user_id=r.audit_user_id " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null  '> " +
            "and r.company_id = #{maps.companyId}" +
            "</if>" +
            "<if test = 'maps.rechargeNo != null and maps.rechargeNo !=\"\" '> " +
            "and r.recharge_no = #{maps.rechargeNo}" +
            "</if>" +
            "<if test = 'maps.status != null  '> " +
            "and r.status = #{maps.status}" +
            "</if>" +
            "<if test = 'maps.payType != null  '> " +
            "and r.pay_type = #{maps.payType}" +
            "</if>" +
            "<if test = 'maps.beginTime != null and maps.beginTime != \"\" '> " +
            "and date_format(r.pay_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.endTime != null and maps.endTime != \"\" '> " +
            "and date_format(r.pay_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d') " +
            "</if>" +
            "order by r.recharge_id desc " +
            "</script>"})
    List<CompanyRechargeExportVO> selectCompanyRechargeExportList(@Param("maps") CompanyRecharge companyRecharge);

    @Select({"<script> " +
            "select r.*,c.company_name,su1.nick_name as create_user_nick_name ,su2.nick_name as audit_user_nick_name " +
            "from company_recharge r left join company c on c.company_id=r.company_id " +
            " left join sys_user su1 on su1.user_id=r.create_user_id " +
            " left join sys_user su2 on su2.user_id=r.audit_user_id " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null  '> " +
            "and r.company_id = #{maps.companyId}" +
            "</if>" +
            "<if test = 'maps.rechargeNo != null and maps.rechargeNo !=\"\" '> " +
            "and r.recharge_no = #{maps.rechargeNo}" +
            "</if>" +
            "<if test = 'maps.status != null  '> " +
            "and r.status = #{maps.status}" +
            "</if>" +
            "<if test = 'maps.isAudit != null  '> " +
            "and r.is_audit = #{maps.isAudit}" +
            "</if>" +
            "<if test = 'maps.payType != null  '> " +
            "and r.pay_type = #{maps.payType}" +
            "</if>" +
            "<if test = 'maps.businessType != null  '> " +
            "and r.business_type = #{maps.businessType}" +
            "</if>" +

            "<if test = 'maps.createTime != null  '> " +
            "and   DATE(r.create_time) = DATE(#{maps.createTime})" +
            "</if>" +
            "<if test = 'maps.companyName != null  '> " +
            "and c.company_name like concat('%', #{maps.companyName }, '%')" +
            "</if>" +
//            "<if test = 'maps.beginTime != null and maps.beginTime != \"\" '> " +
//            "and date_format(r.pay_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d') " +
//            "</if>" +
//            "<if test = 'maps.endTime != null and maps.endTime != \"\" '> " +
//            "and date_format(r.pay_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d') " +
//            "</if>" +
            "order by r.recharge_id desc " +
            "</script>"})
    List<CompanyRechargeVO> selectCompanyRechargeListVO(@Param("maps") CompanyRechargeVO companyRecharge);
}
