package org.ta.pddserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.ta.pddserver.entity.GDTicketEntity;
import org.ta.pddserver.model.api.request.CollectOutMailDetailIoRequest;
import org.ta.pddserver.model.api.request.TicketListRequest;
import org.ta.pddserver.model.api.response.CollectOutMailDetailIoListResponse;
import org.ta.pddserver.model.api.response.TicketListResponse;

import java.util.List;

@Mapper
public interface GDTicketMapper extends BaseMapper<GDTicketEntity> {

    @Select("SELECT * FROM `gd_ticket` WHERE `ticket_id` = #{ticketId};")
    GDTicketEntity findByTicketId(Long ticketId);

    @Select("SELECT COUNT(*) FROM (SELECT `uid` FROM `gd_ticket` WHERE  ( #{source} IS NULL OR #{source} = '' OR `source` LIKE CONCAT('%', #{source}, '%')) AND ( #{title} IS NULL OR #{title} = '' OR `title` LIKE CONCAT('%', #{title}, '%') ) AND ( #{create_type} IS NULL OR #{create_type} = '' OR `create_type` LIKE CONCAT('%', #{create_type}, '%') ) AND ( #{compensate_state} IS NULL OR #{compensate_state} = '' OR `compensate_state` LIKE CONCAT('%', #{compensate_state}, '%') ) AND ( #{type_id} IS NULL OR #{type_id} = '' OR `type_id` LIKE CONCAT('%', #{type_id}, '%') ) AND ( #{sign_state} IS NULL OR #{sign_state} = '' OR `sign_state` LIKE CONCAT('%', #{sign_state}, '%') ) AND ( #{urgent_type} IS NULL OR #{urgent_type} = '' OR `urgent_type` LIKE CONCAT('%', #{urgent_type}, '%')) ) t")
    Integer countUsable(TicketListRequest param);

    @Select("SELECT * FROM `gd_ticket` WHERE  ( #{source} IS NULL OR #{source} = '' OR `source` LIKE CONCAT('%', #{source}, '%')) AND ( #{title} IS NULL OR #{title} = '' OR `title` LIKE CONCAT('%', #{title}, '%') ) AND ( #{create_type} IS NULL OR #{create_type} = '' OR `create_type` LIKE CONCAT('%', #{create_type}, '%') ) AND ( #{compensate_state} IS NULL OR #{compensate_state} = '' OR `compensate_state` LIKE CONCAT('%', #{compensate_state}, '%') ) AND ( #{type_id} IS NULL OR #{type_id} = '' OR `type_id` LIKE CONCAT('%', #{type_id}, '%') ) AND ( #{sign_state} IS NULL OR #{sign_state} = '' OR `sign_state` LIKE CONCAT('%', #{sign_state}, '%') ) AND ( #{urgent_type} IS NULL OR #{urgent_type} = '' OR `urgent_type` LIKE CONCAT('%', #{urgent_type}, '%') )")
    List<GDTicketEntity> getListByRequest(TicketListRequest param);
}
