package com.fs.store.mapper;

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

import java.util.List;

/**
 * 剩余理赔限额日志Mapper
 */
@Mapper
public interface RemainingClaimLimitLogMapper {

    /**
     * 根据ID查询
     */
    @Select("SELECT * FROM fs_remaining_claim_limit_log WHERE id = #{id}")
    RemainingClaimLimitLog selectById(Integer id);

    /**
     * 根据订单ID查询
     */
    @Select("SELECT * FROM fs_remaining_claim_limit_log WHERE order_id = #{orderId} and user_id=#{userId} and status=0 limit 1")
    RemainingClaimLimitLog selectByOrderId(@Param("orderId") Long orderId, @Param("userId") Long userId);

    /**
     * 根据用户ID查询
     */
    @Select("SELECT * FROM fs_remaining_claim_limit_log WHERE user_id = #{userId}")
    List<RemainingClaimLimitLog> selectByUserId(Integer userId);

    /**
     * 插入记录
     */
    @Insert("INSERT INTO fs_remaining_claim_limit_log(order_id, order_money, money, user_id, status, create_time) " +
            "VALUES(#{orderId}, #{orderMoney}, #{money}, #{userId}, #{status}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(RemainingClaimLimitLog record);

    /**
     * 更新记录
     */
    @Update("UPDATE fs_remaining_claim_limit_log SET " +
            "order_id = #{orderId}, " +
            "order_money = #{orderMoney}, " +
            "money = #{money}, " +
            "user_id = #{userId}, " +
            "status = #{status}, " +
            "create_time = #{createTime} " +
            "WHERE id = #{id}")
    int update(RemainingClaimLimitLog record);
}
