package com.cmvr.device.service.impl;

import java.util.List;

import com.cmvr.common.utils.DateUtils;
import com.cmvr.common.utils.DateUtils;
import com.cmvr.device.domain.DeDeviceProfile;
import com.cmvr.device.domain.vo.Device;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cmvr.device.mapper.DeDeviceRegistrationMapper;
import com.cmvr.device.domain.DeDeviceRegistration;
import com.cmvr.device.service.IDeDeviceRegistrationService;

/**
 * 设备注册Service业务层处理
 * 
 * @author cmvr-iot
 * @date 2025-05-08
 */
@Service
public class DeDeviceRegistrationServiceImpl implements IDeDeviceRegistrationService 
{
    @Autowired
    private DeDeviceRegistrationMapper deDeviceRegistrationMapper;

    /**
     * 查询设备注册
     * 
     * @param id 设备注册主键
     * @return 设备注册
     */
    @Override
    public DeDeviceRegistration selectDeDeviceRegistrationById(String id)
    {
        return deDeviceRegistrationMapper.selectDeDeviceRegistrationById(id);
    }


    @Override
    public int addDeviceList(List<DeDeviceRegistration> devices) {

        // 2. 获取数据库中已有设备
        List<String> deviceCodes= deDeviceRegistrationMapper.selectAllDeviceCode();

        int addedCount = 0;

        for (DeDeviceRegistration edgeDevice : devices) {
            if (!deviceCodes.contains(edgeDevice.getDeviceCode())) {

                deDeviceRegistrationMapper.insert(edgeDevice);
                addedCount++;
            }
        }

        return addedCount;

    }




    /**
     * 查询设备注册列表
     * 
     * @param deDeviceRegistration 设备注册
     * @return 设备注册
     */
    @Override
    public List<DeDeviceRegistration> selectDeDeviceRegistrationList(DeDeviceRegistration deDeviceRegistration)
    {
        return deDeviceRegistrationMapper.selectDeDeviceRegistrationList(deDeviceRegistration);
    }

    /**
     * 新增设备注册
     * 
     * @param deDeviceRegistration 设备注册
     * @return 结果
     */
    @Override
    public int insertDeDeviceRegistration(DeDeviceRegistration deDeviceRegistration)
    {
        deDeviceRegistration.setCreateTime(DateUtils.getNowDate());
        deDeviceRegistration.setStatus("1");
        return deDeviceRegistrationMapper.insert(deDeviceRegistration);
    }

    /**
     * 修改设备注册
     * 
     * @param deDeviceRegistration 设备注册
     * @return 结果
     */
    @Override
    public int updateDeDeviceRegistration(DeDeviceRegistration deDeviceRegistration)
    {
        deDeviceRegistration.setUpdateTime(DateUtils.getNowDate());
        return deDeviceRegistrationMapper.updateDeDeviceRegistration(deDeviceRegistration);
    }

    /**
     * 批量删除设备注册
     * 
     * @param ids 需要删除的设备注册主键
     * @return 结果
     */
    @Override
    public int deleteDeDeviceRegistrationByIds(String[] ids)
    {
        return deDeviceRegistrationMapper.deleteDeDeviceRegistrationByIds(ids);
    }

    /**
     * 删除设备注册信息
     * 
     * @param id 设备注册主键
     * @return 结果
     */
    @Override
    public int deleteDeDeviceRegistrationById(String id)
    {
        return deDeviceRegistrationMapper.deleteDeDeviceRegistrationById(id);
    }
}
