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.OrderCreateEntity;
import org.ta.pddserver.entity.OutboundNoticeEntity;
import org.ta.pddserver.model.api.request.OutboundNoticeListRequest;
import org.ta.pddserver.model.api.request.UnpackNoticeListRequest;
import org.ta.pddserver.model.api.response.OutboundNoticeListResponse;
import org.ta.pddserver.model.api.response.UnpackNoticeListResponse;

import java.util.List;

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

    @Select("SELECT count(`uid`) FROM `outbound_notice` WHERE `status` = 1")
    Integer countUsable(OutboundNoticeListRequest param);

    @Select("SELECT `orderCode`, `status` FROM `outbound_notice` WHERE `status` = 1 ORDER BY `uid` DESC LIMIT #{offset}, #{size}; ")
    List<OutboundNoticeListResponse> getListByRequest(OutboundNoticeListRequest param);

    @Update("UPDATE `outbound_notice` SET `status` = ${status} WHERE `orderCode` = #{orderCode} ")
    void updateStatusByOrderCode(@Param("orderCode") String orderCode, @Param("status") int status);
}
