package com.ruoyi.ss.deviceBindRecord.service;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordType;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordUserType;
import com.ruoyi.ss.deviceBindRecord.mapper.DeviceBindRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备绑定记录Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-17
 */
@Service
public class DeviceBindRecordServiceImpl implements DeviceBindRecordService
{
    @Autowired
    private DeviceBindRecordMapper deviceBindRecordMapper;

    /**
     * 查询设备绑定记录
     *
     * @param recordId 设备绑定记录主键
     * @return 设备绑定记录
     */
    @Override
    public DeviceBindRecordVO selectSmDeviceBindRecordByRecordId(Long recordId)
    {
        return deviceBindRecordMapper.selectSmDeviceBindRecordByRecordId(recordId);
    }

    /**
     * 查询设备绑定记录列表
     *
     * @param deviceBindRecord 设备绑定记录
     * @return 设备绑定记录
     */
    @Override
    public List<DeviceBindRecordVO> selectSmDeviceBindRecordList(DeviceBindRecordQuery deviceBindRecord)
    {
        return deviceBindRecordMapper.selectSmDeviceBindRecordList(deviceBindRecord);
    }

    /**
     * 新增设备绑定记录
     *
     * @param deviceBindRecord 设备绑定记录
     * @return 结果
     */
    @Override
    public int insertSmDeviceBindRecord(DeviceBindRecord deviceBindRecord)
    {
        deviceBindRecord.setCreateTime(DateUtils.getNowDate());
        return deviceBindRecordMapper.insertSmDeviceBindRecord(deviceBindRecord);
    }

    /**
     * 修改设备绑定记录
     *
     * @param deviceBindRecord 设备绑定记录
     * @return 结果
     */
    @Override
    public int updateSmDeviceBindRecord(DeviceBindRecord deviceBindRecord)
    {
        return deviceBindRecordMapper.updateSmDeviceBindRecord(deviceBindRecord);
    }

    /**
     * 批量删除设备绑定记录
     *
     * @param recordIds 需要删除的设备绑定记录主键
     * @return 结果
     */
    @Override
    public int deleteSmDeviceBindRecordByRecordIds(Long[] recordIds)
    {
        return deviceBindRecordMapper.deleteSmDeviceBindRecordByRecordIds(recordIds);
    }

    /**
     * 删除设备绑定记录信息
     *
     * @param recordId 设备绑定记录主键
     * @return 结果
     */
    @Override
    public int deleteSmDeviceBindRecordByRecordId(Long recordId)
    {
        return deviceBindRecordMapper.deleteSmDeviceBindRecordByRecordId(recordId);
    }

    @Override
    public int record(Long userId, Long deviceId, BindRecordType recordType, BindRecordUserType userType) {
        DeviceBindRecord record = new DeviceBindRecord();
        record.setUserId(userId);
        record.setDeviceId(deviceId);
        record.setType(recordType.getType());
        record.setUserType(userType.getUserType());
        return this.insertSmDeviceBindRecord(record);
    }
}
