package cn.ysk.cashier.service.impl.shopimpl;

import cn.ysk.cashier.pojo.TbDeviceStock;
import cn.ysk.cashier.repository.shop.TbDeviceStockRepository;
import cn.ysk.cashier.service.shop.TbDeviceStockService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author GYJ
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TbDeviceStockServiceImpl implements TbDeviceStockService {

    private final TbDeviceStockRepository deviceStockRepository;

    @Override
    public TbDeviceStock findLastRecord() {
        List<TbDeviceStock> list = deviceStockRepository.findAll(PageRequest.of(0, 1, Sort.by(Sort.Direction.DESC, "id"))).getContent();
        if (list.isEmpty()) {
            return null;
        }

        return list.get(0);
    }

    @Override
    public void saveBatch(List<TbDeviceStock> list) {
        deviceStockRepository.saveAll(list);
    }
}
