package com.fzm.mall.server.front.asset.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzm.mall.server.front.asset.model.Tran;
import com.fzm.mall.server.front.asset.model.vo.GoodsTransVO;
import com.fzm.mall.server.front.asset.model.vo.UserAssetTransferVO;
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 java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author fzm
 * @since 2021-09-07
 */
@Mapper
public interface TranMapper extends BaseMapper<Tran> {

    IPage<GoodsTransVO> list(Page<GoodsTransVO> page,
                             @Param("keyword") String keyword,@Param("status") Integer status);
    @Select("select * from tran where id = #{id} for update")
    Tran getByTranIdForUpdate(@Param("id") Integer id);

    @Update("update tran set stock = stock - #{number} where id = #{id} and stock >= #{number}")
    int delStock(@Param("id") Integer id, @Param("number") Integer number);

    List<UserAssetTransferVO> listByUid(@Param("uid") String uid,
                                        @Param("keyword") String keyword,
                                        @Param("status") Integer status);

    UserAssetTransferVO read(@Param("tranId") String tranId);

    IPage<GoodsTransVO> pageSerach(Page<GoodsTransVO> page,
                             @Param("keyword") String keyword,@Param("status") Integer status,@Param("goodsIds") String goodsIds,@Param("price") String price,@Param("sale") String sale);

}
