package org.ta.pddserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.ta.pdd.entity.UnpackMailDetailEntity;

import java.util.List;

@Mapper
public interface UnpackMailDetailMapper extends BaseMapper<UnpackMailDetailEntity> {

    @Select("SELECT * FROM `unpack_mail_detail` WHERE `mailNo` = #{mailNo} AND `state` > 0;")
    UnpackMailDetailEntity findByMailNo(@Param("mailNo") String mailNo);

    @Select("SELECT * FROM `unpack_mail_detail` WHERE `orderCode` = #{orderCode}  AND `state` > 0 ;")
    List<UnpackMailDetailEntity> findByOrderCode(@Param("orderCode") String orderCode);

    @Delete("DELETE FROM `unpack_mail_detail` WHERE `orderCode` = #{orderCode}; ")
    Integer deleteByOrderCode(@Param("orderCode") String orderCode);

    @Update("UPDATE `unpack_mail_detail` SET `state` = 2, `remarks` = '已经申报问题件' WHERE `mailNo` = #{mailNo};")
    Integer updateMailToProblem(@Param("mailNo") String mailNo);

    @Update("UPDATE `unpack_mail_detail` SET `state` = 3, `remarks` = '该包裹已下发退运' WHERE `mailNo` in (${mailNos});")
    Integer updateMailToReturnBack(@Param("mailNos") String mailNos);
}
