package com.ruoyi.traceability.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.traceability.mapper.BaseDeviceInfoMapper;
import com.ruoyi.traceability.domain.BaseDeviceInfo;
import com.ruoyi.traceability.service.IBaseDeviceInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 设备信息Service业务层处理
 * 
 * @author wenjy
 * @date 2022-11-23
 */
@Service
public class BaseDeviceInfoServiceImpl implements IBaseDeviceInfoService 
{
    @Autowired
    private BaseDeviceInfoMapper baseDeviceInfoMapper;

    /**
     * 查询设备信息
     * 
     * @param deviceId 设备信息主键
     * @return 设备信息
     */
    @Override
    public BaseDeviceInfo selectBaseDeviceInfoByDeviceId(Long deviceId)
    {
        return baseDeviceInfoMapper.selectBaseDeviceInfoByDeviceId(deviceId);
    }

    /**
     * 查询设备信息列表
     * 
     * @param baseDeviceInfo 设备信息
     * @return 设备信息
     */
    @Override
    public List<BaseDeviceInfo> selectBaseDeviceInfoList(BaseDeviceInfo baseDeviceInfo)
    {
        return baseDeviceInfoMapper.selectBaseDeviceInfoList(baseDeviceInfo);
    }

    /**
     * 新增设备信息
     * 
     * @param baseDeviceInfo 设备信息
     * @return 结果
     */
    @Override
    public int insertBaseDeviceInfo(BaseDeviceInfo baseDeviceInfo)
    {
        baseDeviceInfo.setCreateTime(DateUtils.getNowDate());
        return baseDeviceInfoMapper.insertBaseDeviceInfo(baseDeviceInfo);
    }

    /**
     * 修改设备信息
     * 
     * @param baseDeviceInfo 设备信息
     * @return 结果
     */
    @Override
    public int updateBaseDeviceInfo(BaseDeviceInfo baseDeviceInfo)
    {
        baseDeviceInfo.setUpdateTime(DateUtils.getNowDate());
        return baseDeviceInfoMapper.updateBaseDeviceInfo(baseDeviceInfo);
    }

    /**
     * 批量删除设备信息
     * 
     * @param deviceIds 需要删除的设备信息主键
     * @return 结果
     */
    @Override
    public int deleteBaseDeviceInfoByDeviceIds(String deviceIds)
    {
        return baseDeviceInfoMapper.deleteBaseDeviceInfoByDeviceIds(Convert.toStrArray(deviceIds));
    }

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

    /**
     * 查询设备信息树列表
     * 
     * @return 所有设备信息信息
     */
    @Override
    public List<Ztree> selectBaseDeviceInfoTree()
    {
        List<BaseDeviceInfo> baseDeviceInfoList = baseDeviceInfoMapper.selectBaseDeviceInfoList(new BaseDeviceInfo());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (BaseDeviceInfo baseDeviceInfo : baseDeviceInfoList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(baseDeviceInfo.getDeviceId());
            ztree.setpId(baseDeviceInfo.getParentId());
            ztree.setName(baseDeviceInfo.getDeviceName());
            ztree.setTitle(baseDeviceInfo.getDeviceName());
            ztree.setRemark(baseDeviceInfo.getResource());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
