package com.ruoyi.bst.bindRecord.service.impl;

import java.util.List;

import com.ruoyi.bst.bindRecord.domain.enums.BindRecordType;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bst.bindRecord.mapper.BindRecordMapper;
import com.ruoyi.bst.bindRecord.domain.BindRecord;
import com.ruoyi.bst.bindRecord.domain.BindRecordVO;
import com.ruoyi.bst.bindRecord.domain.BindRecordQuery;
import com.ruoyi.bst.bindRecord.service.BindRecordService;

/**
 * 设备绑定记录Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-24
 */
@Service
public class BindRecordServiceImpl implements BindRecordService
{
    @Autowired
    private BindRecordMapper bindRecordMapper;

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

    /**
     * 查询设备绑定记录列表
     *
     * @param bindRecord 设备绑定记录
     * @return 设备绑定记录
     */
    @Override
    public List<BindRecordVO> selectBindRecordList(BindRecordQuery bindRecord)
    {
        return bindRecordMapper.selectBindRecordList(bindRecord);
    }

    /**
     * 新增设备绑定记录
     *
     * @param bindRecord 设备绑定记录
     * @return 结果
     */
    @Override
    public int insertBindRecord(BindRecord bindRecord)
    {
        bindRecord.setCreateTime(DateUtils.getNowDate());
        return bindRecordMapper.insertBindRecord(bindRecord);
    }

    /**
     * 修改设备绑定记录
     *
     * @param bindRecord 设备绑定记录
     * @return 结果
     */
    @Override
    public int updateBindRecord(BindRecord bindRecord)
    {
        return bindRecordMapper.updateBindRecord(bindRecord);
    }

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

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

    @Override
    public int record(Long userId, Long deviceId, BindRecordType recordType) {
        BindRecord record = new BindRecord();
        record.setUserId(userId);
        record.setDeviceId(deviceId);
        record.setType(recordType.getType());
        return this.insertBindRecord(record);
    }

}
