package com.fs.company.mapper;

import java.util.List;
import com.fs.company.domain.CompanyDeduct;
import com.fs.company.vo.CompanyDeductExportVO;
import com.fs.company.vo.CompanyDeductVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 扣款Mapper接口
 *
 * @author fs
 * @date 2023-02-27
 */
public interface CompanyDeductMapper
{
    /**
     * 查询扣款
     *
     * @param deductId 扣款ID
     * @return 扣款
     */
    public CompanyDeduct selectCompanyDeductById(Long deductId);

    /**
     * 查询扣款列表
     *
     * @param companyDeduct 扣款
     * @return 扣款集合
     */
    public List<CompanyDeduct> selectCompanyDeductList(CompanyDeduct companyDeduct);

    /**
     * 新增扣款
     *
     * @param companyDeduct 扣款
     * @return 结果
     */
    public int insertCompanyDeduct(CompanyDeduct companyDeduct);

    /**
     * 修改扣款
     *
     * @param companyDeduct 扣款
     * @return 结果
     */
    public int updateCompanyDeduct(CompanyDeduct companyDeduct);

    /**
     * 删除扣款
     *
     * @param deductId 扣款ID
     * @return 结果
     */
    public int deleteCompanyDeductById(Long deductId);

    /**
     * 批量删除扣款
     *
     * @param deductIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteCompanyDeductByIds(Long[] deductIds);
    @Select({"<script> " +
            "select d.*,c.company_name,su1.nick_name as create_user_nick_name ,su2.nick_name as audit_user_nick_name " +
            "from company_deduct d left join company c on c.company_id=d.company_id " +
            " left join sys_user su1 on su1.user_id=d.create_user_id " +
            " left join sys_user su2 on su2.user_id=d.audit_user_id " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null  '> " +
            "and d.company_id = #{maps.companyId}" +
            "</if>" +
            "<if test = 'maps.deductNo != null and maps.deductNo !=\"\" '> " +
            "and d.deduct_no = #{maps.deductNo}" +
            "</if>" +
            "<if test = 'maps.isAudit != null  '> " +
            "and d.is_audit = #{maps.isAudit}" +
            "</if>" +
            "<if test = 'maps.beginTime != null and maps.beginTime != \"\" '> " +
            "and date_format(d.audit_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.endTime != null and maps.endTime != \"\" '> " +
            "and date_format(d.audit_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d') " +
            "</if>" +
            "order by d.deduct_id desc " +
            "</script>"})
    List<CompanyDeductVO> selectCompanyDeductVOList(@Param("maps")CompanyDeduct companyDeduct);

    @Select("select d.*,c.company_name from company_deduct d LEFT JOIN company c on d.company_id=c.company_id")
    List<CompanyDeductExportVO> selectCompanyExportDeductList(CompanyDeduct companyDeduct);

    @Select({"<script> " +
            "select d.*,c.company_name,su1.nick_name as create_user_nick_name ,su2.nick_name as audit_user_nick_name " +
            "from company_deduct d left join company c on c.company_id=d.company_id " +
            " left join sys_user su1 on su1.user_id=d.create_user_id " +
            " left join sys_user su2 on su2.user_id=d.audit_user_id " +
            "where 1=1 " +
            "<if test = 'maps.companyId != null  '> " +
            "and d.company_id = #{maps.companyId}" +
            "</if>" +
            "<if test = 'maps.deductNo != null and maps.deductNo !=\"\" '> " +
            "and d.deduct_no = #{maps.deductNo}" +
            "</if>" +
            "<if test = 'maps.isAudit != null  '> " +
            "and d.is_audit = #{maps.isAudit}" +
            "</if>" +
            "<if test = 'maps.createTime != null  '> " +
            "and   DATE(d.create_time) = DATE(#{maps.createTime})" +
            "</if>" +
            "<if test = 'maps.businessType != null  '> " +
            "and   d.business_type = #{maps.businessType}" +
            "</if>" +
            "<if test = 'maps.companyName != null  '> " +
            "and c.company_name like concat('%', #{maps.companyName }, '%')" +
            "</if>" +

            "order by d.deduct_id desc " +
            "</script>"})
    List<CompanyDeductVO> selectCompanyDeductListVO(@Param("maps") CompanyDeductVO companyDeduct);
}
