package com.fs.company.mapper;

import com.fs.company.domain.CompanyTcmConsume;
import com.fs.company.vo.CompanyTcmConsumeVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 公司档期消费Mapper接口
 *
 * @author fs
 * @date 2023-09-15
 */
public interface CompanyTcmConsumeMapper
{
    /**
     * 查询公司档期消费
     *
     * @param id 公司档期消费ID
     * @return 公司档期消费
     */
    public CompanyTcmConsume selectCompanyTcmConsumeById(Long id);

    /**
     * 查询公司档期消费列表
     *
     * @param companyTcmConsume 公司档期消费
     * @return 公司档期消费集合
     */

    public List<CompanyTcmConsume> selectCompanyTcmConsumeList(CompanyTcmConsume companyTcmConsume);

    @Select({"<script> " +
            "select tc.*,c.company_name,s.name as scheduleName " +
            " from company_tcm_consume tc left join company_tcm_schedule s on tc.schedule_id=s.id left join company c on c.company_id=tc.company_id " +
            "  where 1=1 " +
            "<if test = 'maps.scheduleId != null '> " +
            " and tc.schedule_id = #{maps.scheduleId} " +
            "</if>" +
            "<if test = 'maps.companyId != null  '> " +
            " and tc.company_id = #{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.beginTime != null and maps.beginTime != \"\" '> " +
            " and date_format(tc.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(tc.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d') " +
            "</if>" +

            "${maps.params.dataScope}"+
            "order by tc.id desc " +
            "</script>"})
    public List<CompanyTcmConsumeVO> selectCompanyTcmConsumeListVO(@Param("maps") CompanyTcmConsume companyTcmConsume);

    /**
     * 新增公司档期消费
     *
     * @param companyTcmConsume 公司档期消费
     * @return 结果
     */
    public int insertCompanyTcmConsume(CompanyTcmConsume companyTcmConsume);

    /**
     * 修改公司档期消费
     *
     * @param companyTcmConsume 公司档期消费
     * @return 结果
     */
    public int updateCompanyTcmConsume(CompanyTcmConsume companyTcmConsume);

    /**
     * 删除公司档期消费
     *
     * @param id 公司档期消费ID
     * @return 结果
     */
    public int deleteCompanyTcmConsumeById(Long id);

    /**
     * 批量删除公司档期消费
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteCompanyTcmConsumeByIds(Long[] ids);

    @Select("select * from company_tcm_consume where company_id = #{companyId} and schedule_id = #{scheduleId} ")
    CompanyTcmConsume selectCompanyTcmConsumeBySchedule(@Param("companyId") Long companyId,@Param("scheduleId") Long scheduleId);
}
