package com.supervision.web.peopleGateManage.Service.impl;

import com.supervision.web.peopleGateManage.mapper.DeviceMapper;
import com.supervision.web.peopleGateManage.Service.DeviceService;
import com.supervision.web.peopleGateManage.enity.Device;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class DeviceServiceImpl implements DeviceService {

    @Autowired
    private DeviceMapper deviceMapper;

    @Override
    public List<Device> getAll() {
        return deviceMapper.selectAll();
    }

    @Override
    public Device getById(Long id) {
        return deviceMapper.selectById(id);
    }

    @Override
    public void add(Device device) {
        device.setCreateTime(LocalDateTime.now());
        device.setUpdateTime(LocalDateTime.now());
        deviceMapper.insert(device);
    }

    @Override
    public void update(Device device) {
        device.setUpdateTime(LocalDateTime.now());
        deviceMapper.update(device);
    }

    @Override
    public void delete(Long id) {
        deviceMapper.delete(id);
    }
}
