package cn.reghao.autodop.dmaster.machine.db.crud;

import cn.reghao.autodop.dmaster.machine.db.repository.MachineHostRepository;
import cn.reghao.autodop.dmaster.machine.model.po.MachineHost;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author reghao
 * @date 2021-09-15 16:24:56
 */
@Service
public class MachineHostCrudImpl implements MachineHostCrud {
    private final MachineHostRepository hostRepository;

    public MachineHostCrudImpl(MachineHostRepository hostRepository) {
        this.hostRepository = hostRepository;
    }

    @Override
    public MachineHost save(MachineHost machineHost) {
        hostRepository.save(machineHost);
        return machineHost;
    }

    @Override
    public void saveAll(List<MachineHost> machineInfos) {
        hostRepository.saveAll(machineInfos);
    }

    @Override
    public void update(MachineHost machineHost) {
        // 利用 AOP 统一设置更新时间
        machineHost.setUpdateTime(LocalDateTime.now());
        hostRepository.save(machineHost);
    }

    @Override
    public void delete(MachineHost machineHost) {
        hostRepository.delete(machineHost);
    }
}
