package com.yn.bftl.thirdparty.common.repository;

import com.yn.bftl.common.modules.inventory.entity.InventoryManagement;
import com.yn.bftl.common.modules.inventory.entity.Warehouse;
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 org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;


/**
 * InventoryManagementRepository
 *
 * @author wangwenliang
 * @create 2021年4月25日15:39:25
 **/
@Repository
public interface InventoryManagementRepository extends JpaRepository<InventoryManagement, Long>, JpaSpecificationExecutor<InventoryManagement> {

    @Modifying
    @Transactional
    @Query("update InventoryManagement i set i.availableInventory = i.availableInventory - 1 where i.availableInventory > 0 and i.defaultWarehouse = :warehouse")
    int subStock(@Param("warehouse") Warehouse warehouse);

}
