package com.common.service;

import com.common.entity.DeviceInterlockingCmd;
import com.common.mapper.DeviceInterlockingCmdMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class DeviceInterlockingCmdService {

    @Autowired
    private DeviceInterlockingCmdMapper cmdMapper;

    /**
     * 根据ID查询
     */
    public DeviceInterlockingCmd selectById(Long id) {
        return cmdMapper.selectById(id);
    }

    /**
     * 查询待执行的指令
     */
    public List<DeviceInterlockingCmd> selectPendingCommands(Long probeId) {
        return cmdMapper.selectPendingCommands(probeId);
    }

    /**
     * 根据探针ID和状态查询
     */
    public List<DeviceInterlockingCmd> selectByProbeIdAndStatus(Long probeId, String cmdStatus) {
        return cmdMapper.selectByProbeIdAndStatus(probeId, cmdStatus);
    }

    /**
     * 插入指令
     */
    public int insert(DeviceInterlockingCmd cmd) {
        return cmdMapper.insert(cmd);
    }

    /**
     * 更新指令状态
     */
    public int updateStatus(Long id, String cmdStatus) {
        return cmdMapper.updateStatus(id, cmdStatus);
    }

    /**
     * 更新指令状态为执行中
     */
    public int updateStatusToExecuting(Long id) {
        return cmdMapper.updateStatusToExecuting(id);
    }

    /**
     * 更新指令状态为执行完成
     */
    public int updateStatusToCompleted(Long id) {
        return cmdMapper.updateStatusToCompleted(id);
    }

    /**
     * 更新指令状态为执行失败
     */
    public int updateStatusToFailed(Long id) {
        return cmdMapper.updateStatusToFailed(id);
    }

    /**
     * 查询所有指令
     */
    public List<DeviceInterlockingCmd> selectAll() {
        return cmdMapper.selectAll();
    }

    /**
     * 根据多个ID查询
     */
    public List<DeviceInterlockingCmd> selectByIds(List<Long> ids) {
        return cmdMapper.selectByIds(ids);
    }
}
