package com.dcs.hnyz.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dcs.common.exception.CustomException;
import com.dcs.hnyz.domain.vo.EquipmentFormVo;
import org.springframework.stereotype.Service;
import com.dcs.hnyz.mapper.EquipmentParamMapper;
import com.dcs.hnyz.domain.EquipmentParam;
import com.dcs.hnyz.service.IEquipmentParamService;

import javax.annotation.Resource;

/**
 * 设备参数管理Service业务层处理
 * 
 * @author hmy
 * @date 2025-04-23
 */
@Service
public class EquipmentParamServiceImpl implements IEquipmentParamService 
{
    @Resource
    private EquipmentParamMapper equipmentParamMapper;

    /**
     * 查询设备参数管理
     * 
     * @param registerId 设备参数管理主键
     * @return 设备参数管理
     */
    @Override
    public EquipmentParam selectEquipmentParamByRegisterId(Long registerId)
    {
        return equipmentParamMapper.selectById(registerId);
    }

    /**
     * 查询设备参数管理列表
     * 
     * @param equipmentParam 设备参数管理
     * @return 设备参数管理
     */
    @Override
    public List<EquipmentParam> selectEquipmentParamList(EquipmentParam equipmentParam)
    {
        return equipmentParamMapper.selectEquipmentParamList(equipmentParam);
    }

    /**
     * 新增设备参数管理
     * 
     * @param equipmentParam 设备参数管理
     * @return 结果
     */
    @Override
    public int insertEquipmentParam(EquipmentParam equipmentParam)
    {
        LambdaQueryWrapper<EquipmentParam> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(EquipmentParam::getCode,equipmentParam.getCode());
        EquipmentParam ep = equipmentParamMapper.selectOne(wrapper);
        if(ep!=null){
            throw new CustomException("该寄存器标识已存在");
        }
        return equipmentParamMapper.insert(equipmentParam);
    }

    /**
     * 修改设备参数管理
     * 
     * @param equipmentParam 设备参数管理
     * @return 结果
     */
    @Override
    public int updateEquipmentParam(EquipmentParam equipmentParam)
    {
        LambdaQueryWrapper<EquipmentParam> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(EquipmentParam::getCode,equipmentParam.getCode());
        wrapper.ne(EquipmentParam::getEquipmentId,equipmentParam.getEquipmentId());
        EquipmentParam ep=equipmentParamMapper.selectOne(wrapper);
        if(ep!=null){
            throw new CustomException("该寄存器标识已存在");
        }
        return equipmentParamMapper.updateById(equipmentParam);
    }

    /**
     * 批量删除设备参数管理
     * 
     * @param registerIds 需要删除的设备参数管理主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentParamByRegisterIds(Long[] registerIds)
    {
        return equipmentParamMapper.deleteBatchIds(Arrays.asList(registerIds));
    }

    /**
     * 删除设备参数管理信息
     * 
     * @param registerId 设备参数管理主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentParamByRegisterId(Long registerId)
    {
        return equipmentParamMapper.deleteById(registerId);
    }

    @Override
    public List<EquipmentFormVo> selectEquipmentParamForm(EquipmentParam equipmentParam) {
        return equipmentParamMapper.selectEquipmentParamForm(equipmentParam);
    }
}
