package com.evobms.project.bms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evobms.common.utils.DateUtils;
import com.evobms.project.bms.domain.BmsDevice;
import com.evobms.project.bms.mapper.BmsDeviceMapper;
import com.evobms.project.bms.service.IBmsDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * BMS设备Service业务层处理
 * 
 * @author evobms
 * @date 2025-01-22
 */
@Service
public class BmsDeviceServiceImpl extends ServiceImpl<BmsDeviceMapper, BmsDevice> implements IBmsDeviceService {

    @Autowired
    private BmsDeviceMapper bmsDeviceMapper;

    /**
     * 查询BMS设备
     * 
     * @param deviceId BMS设备主键
     * @return BMS设备
     */
    @Override
    public BmsDevice selectBmsDeviceByDeviceId(Long deviceId) {
        return bmsDeviceMapper.selectById(deviceId);
    }

    /**
     * 查询BMS设备列表
     * 
     * @param bmsDevice BMS设备
     * @return BMS设备
     */
    @Override
    public List<BmsDevice> selectBmsDeviceList(BmsDevice bmsDevice) {
        return bmsDeviceMapper.selectBmsDeviceList(bmsDevice);
    }

    /**
     * 新增BMS设备
     * 
     * @param bmsDevice BMS设备
     * @return 结果
     */
    @Override
    public int insertBmsDevice(BmsDevice bmsDevice) {
        bmsDevice.setCreateTime(DateUtils.getNowDate());
        return bmsDeviceMapper.insert(bmsDevice);
    }

    /**
     * 修改BMS设备
     * 
     * @param bmsDevice BMS设备
     * @return 结果
     */
    @Override
    public int updateBmsDevice(BmsDevice bmsDevice) {
        bmsDevice.setUpdateTime(DateUtils.getNowDate());
        return bmsDeviceMapper.updateById(bmsDevice);
    }

    /**
     * 批量删除BMS设备
     * 
     * @param deviceIds 需要删除的BMS设备主键
     * @return 结果
     */
    @Override
    public int deleteBmsDeviceByDeviceIds(Long[] deviceIds) {
        return bmsDeviceMapper.deleteBatchIds(java.util.Arrays.asList(deviceIds));
    }

    /**
     * 删除BMS设备信息
     * 
     * @param deviceId BMS设备主键
     * @return 结果
     */
    @Override
    public int deleteBmsDeviceByDeviceId(Long deviceId) {
        return bmsDeviceMapper.deleteById(deviceId);
    }

    /**
     * 根据设备编号查询设备信息
     * 
     * @param deviceCode 设备编号
     * @return BMS设备
     */
    @Override
    public BmsDevice selectBmsDeviceByCode(String deviceCode) {
        return bmsDeviceMapper.selectBmsDeviceByCode(deviceCode);
    }

    /**
     * 批量更新设备状态
     * 
     * @param deviceIds 设备ID数组
     * @param status 状态
     * @return 结果
     */
    @Override
    public int updateBmsDeviceStatus(Long[] deviceIds, String status) {
        return bmsDeviceMapper.updateBmsDeviceStatus(deviceIds, status);
    }
}