package com.xkrs.dao;

import com.xkrs.model.entity.ProductEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: XinYi Song
 * @Date: 2021/12/15 15:21
 */
public interface ProductDao extends JpaRepository<ProductEntity,Long>, JpaSpecificationExecutor<ProductEntity> {

    /**
     * 根据商品名称查询商品信息
     * @param productName
     * @return
     */
    ProductEntity findByProductName(String productName);

    /**
     * 修改审核状态
     * @param productId
     * @param reviewType
     */
    @Modifying(clearAutomatically=true)
    @Query(value = "update product set review_type = ?2 where id = ?1",nativeQuery = true)
    void updateReviewType(Integer productId,String reviewType);

    /**
     * 修改上架的状态
     * @param productId
     * @param shelfType
     * @param productTime
     */
    @Modifying(clearAutomatically=true)
    @Query(value = "update product set shelf_type = ?2,product_time = ?3 where id = ?1",nativeQuery = true)
    void updateShelfType(Integer productId,String shelfType,String productTime);

    /**
     * 根据id查询商品信息
     * @param id
     * @return
     */
    ProductEntity findById(Integer id);

    /**
     * 商品下架
     * @param productId
     * @param shelfType
     */
    @Modifying(clearAutomatically=true)
    @Query(value = "update product set shelf_type = ?2 where id = ?1",nativeQuery = true)
    void updateShelfTypeById(Integer productId,String shelfType);
}
