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.apache.ibatis.annotations.Update;
import org.ta.pddserver.entity.CollectMailDetailEntity;
import org.ta.pddserver.model.api.request.CollectMailDetailListRequest;
import org.ta.pddserver.model.api.request.LogOrderListRequest;
import org.ta.pddserver.model.api.response.CollectMailDetailListResponse;
import org.ta.pddserver.model.api.response.LogOrderListResponse;

import java.util.List;

@Mapper
public interface CollectMailDetailMapper extends BaseMapper<CollectMailDetailEntity> {
    @Select("SELECT * FROM `collect_mail_detail` WHERE `orderCode` = #{orderCode} AND `expressCode` = #{expressCode} AND `mailNo` = #{mailNo};")
    CollectMailDetailEntity selectByOrderCodeAndExpressCodeAndMailNo(String orderCode, String expressCode, String mailNo);

    @Update("UPDATE `collect_mail_detail` SET `status` = #{status} WHERE `uid` = #{uid};")
    int updateStatusByUid(int status, String uid);

    @Update("UPDATE `collect_mail_detail` SET `status` = #{status} WHERE `mailNo` = #{mailNo}")
    Boolean updateByMailNo(@Param("mailNo") String mailNo, @Param("status") int status);



    @Select("SELECT count(*) FROM `collect_mail_detail` WHERE `orderCode` LIKE '%${orderCode}%' AND `mailNo` LIKE '%${mailNo}%' AND `status` LIKE '%${status}%';")
    Integer countUsable(CollectMailDetailListRequest collectMailDetailListRequest);

    @Select("SELECT `uid`, `orderCode`, `expressCode`, `mailNo` FROM `collect_mail_detail` WHERE `orderCode` LIKE '%${orderCode}%' AND `mailNo` LIKE '%${mailNo}%' AND `status` LIKE '%${status}%' ORDER BY uid DESC LIMIT #{offset}, #{size}; ")
    List<CollectMailDetailListResponse> getListByRequest(CollectMailDetailListRequest collectMailDetailListRequest);

    @Select("SELECT * FROM `collect_mail_detail` WHERE `orderCode` = #{orderCode}")
    List<CollectMailDetailEntity> findListByOrderCode(@Param("orderCode") String orderCode);

    @Select("SELECT * FROM `collect_mail_detail` WHERE `mailNo` = #{mailNo};")
    CollectMailDetailEntity findByMailNo(String mailNo);
}
