package org.ta.pddserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.ta.pddserver.entity.PackageNoticeEntity;
import org.ta.pddserver.entity.PackageQueryEntity;
import org.ta.pddserver.model.api.request.LogOrderListRequest;
import org.ta.pddserver.model.api.request.PackageNoticeRequest;
import org.ta.pddserver.model.api.response.LogOrderListResponse;
import org.ta.pddserver.model.api.response.PackageNoticeResponse;

import java.util.List;

@Mapper
public interface PackageNoticeMapper extends BaseMapper<PackageNoticeEntity> {
    // 根据用户名查找用户
    @Select("SELECT * FROM `package_notice` WHERE `username` = #{username};")
    List<PackageNoticeEntity> selectByUsername(String username);

    @Select("SELECT count(a.`uid`) FROM `package_notice` a, `log_order_mail_detail` b WHERE a.`orderCode` = b.`logisticsOrderCode` AND a.`orderCode` LIKE '%${orderCode}%' ; ")
    Integer countUsable(PackageNoticeRequest param);

    @Select("SELECT a.`orderCode`, b.`expressCode`, b.`mailNo`, a.`status` FROM `package_notice` a, `log_order_mail_detail` b  WHERE a.`orderCode` = b.`logisticsOrderCode` AND a.`orderCode` LIKE '%${orderCode}%' ORDER BY a.`updated` DESC LIMIT #{offset}, #{size}; ")
    List<PackageNoticeResponse> getListByRequest(PackageNoticeRequest param);

    @Select("SELECT * FROM `package_notice` WHERE  `orderCode` = #{orderCode}")
    PackageNoticeEntity getByOrderCode(@Param("orderCode") String orderCode);
}
