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.FeeQueryEntity;
import org.ta.pddserver.entity.UnpackNoticeEntity;
import org.ta.pddserver.model.api.request.LogOrderListRequest;
import org.ta.pddserver.model.api.request.UnpackNoticeListRequest;
import org.ta.pddserver.model.api.response.LogOrderListResponse;
import org.ta.pddserver.model.api.response.UnpackNoticeListResponse;

import java.util.List;

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

    @Select("SELECT * FROM `unpack_notice` WHERE `orderCode` = #{orderCode} ORDER BY `uid` DESC LIMIT 1;")
    UnpackNoticeEntity selectByOrderCode(String orderCode);


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

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

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