package com.fs.store.mapper;

import com.fs.store.domain.FsOrderExpressPush;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FsOrderExpressPushMapper {

    @Select("SELECT * FROM fs_order_express_push WHERE id = #{id}")
    FsOrderExpressPush selectById(Long id);

    @Insert("INSERT INTO fs_order_express_push (order_id, task_status, retry_count, last_execute_time, create_time, update_time, params, result, error_message) " +
            "VALUES (#{orderId}, #{taskStatus}, #{retryCount}, #{lastExecuteTime}, #{createTime}, #{updateTime}, #{params}, #{result}, #{errorMessage})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(FsOrderExpressPush fsOrderExpressPush);

    @Update("UPDATE fs_order_express_push SET order_id = #{orderId}, task_status = #{taskStatus}, retry_count = #{retryCount}, " +
            "last_execute_time = #{lastExecuteTime}, create_time = #{createTime}, update_time = #{updateTime}, " +
            "params = #{params}, result = #{result}, error_message = #{errorMessage} WHERE id = #{id}")
    int update(FsOrderExpressPush fsOrderExpressPush);

    @Delete("DELETE FROM fs_order_express_push WHERE id = #{id}")
    int deleteById(Long id);

    @Select("SELECT * FROM fs_order_express_push where task_status in (0,2) and retry_count < 3")
    List<FsOrderExpressPush> queryPendingData();

}
