package com.xinelu.familydoctor.service.impl;

import com.xinelu.familydoctor.entity.DeviceBindResident;
import com.xinelu.familydoctor.service.DeviceBindResidentService;
import com.xinelu.familydoctor.mapper.DeviceBindResidentMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author gaoyu
* @description 针对表【device_bind_resident(居民设备绑定记录表)】的数据库操作Service实现
* @createDate 2023-09-25 16:00:00
*/
@Service
public class DeviceBindResidentServiceImpl implements DeviceBindResidentService{
    @Resource
    private DeviceBindResidentMapper deviceBindResidentMapper;

    @Override
    public List<DeviceBindResident> boundDevice(String identity) {
        return deviceBindResidentMapper.boundDevice(identity);
    }

    @Override
    public boolean repeatBind(DeviceBindResident record) {
        return deviceBindResidentMapper.repeatBind(record) != null;
    }

    @Override
    public int bindDevice(DeviceBindResident entity) {
        entity.setBindTime(new Date());
        entity.setState("1");
        return deviceBindResidentMapper.insert(entity);
    }

    @Override
    public int unbindDevice(DeviceBindResident entity) {
        entity.setUnbindTime(new Date());
        entity.setState("0");
        return deviceBindResidentMapper.update(entity);
    }
}
