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(t.uid) FROM ( SELECT `uid`  FROM  `gd_ticket`  WHERE  `source` LIKE '%${source}%'  AND `title` LIKE '%${title}%'  AND `create_type`  LIKE '%${create_type}%' AND `compensate_state`  LIKE '%${compensate_state}%' AND `type_id`  LIKE '%${type_id}%' AND `sign_state`  LIKE '%${sign_state}%' AND `urgent_type`  LIKE '%${urgent_type}%' AND `state`  LIKE '%${state}%' AND `area_name`  LIKE '%${area_name}%')  t")
    Integer countUsable(TicketListRequest param);


    @Select("SELECT `source`, `title`, `create_type`,`compensate_state`, `type_id`, `sign_state`, `urgent_type`, `state`, `area_name` , `pre_delivery_id`, `ticket_id`, `create_at` FROM `gd_ticket` WHERE  `source` LIKE '%${source}%'  AND `title` LIKE '%${title}%'  AND `create_type`  LIKE '%${create_type}%' AND `compensate_state`  LIKE '%${compensate_state}%' AND `type_id`  LIKE '%${type_id}%' AND `sign_state`  LIKE '%${sign_state}%' AND `urgent_type`  LIKE '%${urgent_type}%' AND `state`  LIKE '%${state}%' AND `area_name`  LIKE '%${area_name}%' ORDER BY `ticket_id` DESC LIMIT #{offset}, #{size}; ")
    List<TicketListResponse> getListByRequest(TicketListRequest param);
}
