/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ifish.mapper;

import com.ifish.bean.CommodityInfoBean;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

/**
 *
 * @author Administrator
 */
public interface Tbl_Commodity_Info_Mapper {

    /**
     * 创建商品详情
     *
     * @param commodityInfoBean
     * @return
     */
    @InsertProvider(type = Tbl_Commodity_Info_MapperSql.class, method = "createCommodityInfo")
    @SelectKey(statement = "select @@IDENTITY as commodity_id", keyProperty = "commodity.commodityId", keyColumn = "commodity_id", before = false, resultType = int.class)
    Integer createCommodityInfo(@Param("commodity") CommodityInfoBean commodityInfoBean);

    /**
     * 修改商品详情
     *
     * @param commodityInfoBean
     * @return
     */
    @UpdateProvider(type = Tbl_Commodity_Info_MapperSql.class, method = "updateCommodityInfo")
    Integer updateCommodityInfo(@Param("commodity") CommodityInfoBean commodityInfoBean);

    /**
     * 根据商品ID查询单个商品信息
     *
     * @param id
     * @return
     */
    @Select("SELECT commodity_id,shop_id,user_id,commodity_name,commodity_detail,commodity_img,commodity_video,commodity_status,create_time,click,backstage_status FROM tbl_commodity_info WHERE commodity_id = #{id}")
    CommodityInfoBean getCommodityInfoByID(@Param("id") Integer id);

    /**
     * 分页获取店铺所属商品列表
     *
     * @param shopId
     * @param firstResult
     * @param pageSize
     * @return
     */
    @Select("SELECT commodity_id,shop_id,user_id,commodity_name,commodity_detail,commodity_img,commodity_video,commodity_status,create_time,click,backstage_status FROM tbl_commodity_info "
            + "WHERE shop_id = #{id} and backstage_status = 0 and commodity_status = #{status} order by ${orderBy} desc LIMIT ${firsltResult},${pageSize}")
    List<CommodityInfoBean> getCommodityInfoByPage(@Param("id") Integer shopId, @Param("firsltResult") Integer firstResult, @Param("pageSize") Integer pageSize, @Param("status") Integer commodityState, @Param("orderBy") String orderBy);

    /**
     * 分页获取店铺所属商品列表总数
     *
     * @param shopId
     * @param firstResult
     * @param pageSize
     * @return
     */
    @Select("SELECT count(1) FROM tbl_commodity_info WHERE shop_id = #{id} and backstage_status = 0 and commodity_status = #{status}")
    int getCommodityInfoCountByPage(@Param("id") Integer shopId, @Param("status") Integer commodityState);

    /**
     * 根据ID删除商品
     *
     * @param commodityId
     * @return
     */
    @Delete("DELETE FROM tbl_commodity_info WHERE commodity_id = #{id}")
    int deleteCommodityInfoById(@Param("id") Integer commodityId);
}
