package com.aucma.base.service.impl;

import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.aucma.base.mapper.BaseDeviceParamValMapper;
import com.aucma.base.domain.BaseDeviceParamVal;
import com.aucma.base.service.IBaseDeviceParamValService;

/**
 * 设备工艺参数当前值Service业务层处理
 * 
 * @author zch
 * @date 2025-10-15
 */
@Service
public class BaseDeviceParamValServiceImpl implements IBaseDeviceParamValService 
{
    private static final Logger log = LoggerFactory.getLogger(BaseDeviceParamValServiceImpl.class);

    @Autowired
    private BaseDeviceParamValMapper baseDeviceParamValMapper;

    /**
     * 查询设备工艺参数当前值
     * 
     * @param recordId 设备工艺参数当前值主键
     * @return 设备工艺参数当前值
     */
    @Override
    public BaseDeviceParamVal selectBaseDeviceParamValByRecordId(Long recordId)
    {
        return baseDeviceParamValMapper.selectBaseDeviceParamValByRecordId(recordId);
    }

    /**
     * 查询设备工艺参数当前值列表
     * 
     * @param baseDeviceParamVal 设备工艺参数当前值
     * @return 设备工艺参数当前值
     */
    @Override
    public List<BaseDeviceParamVal> selectBaseDeviceParamValList(BaseDeviceParamVal baseDeviceParamVal)
    {
        return baseDeviceParamValMapper.selectBaseDeviceParamValList(baseDeviceParamVal);
    }

    /**
     * 查询每设备每参数的最新记录列表（聚合最新值）
     *
     * @param baseDeviceParamVal 查询条件
     * @return 最新记录集合
     */
    @Override
    public List<BaseDeviceParamVal> selectLatestBaseDeviceParamValList(BaseDeviceParamVal baseDeviceParamVal)
    {
        try {
            if (baseDeviceParamVal == null) {
                baseDeviceParamVal = new BaseDeviceParamVal();
            }
            List<BaseDeviceParamVal> list = baseDeviceParamValMapper.selectLatestBaseDeviceParamValList(baseDeviceParamVal);
            return list != null ? list : Collections.emptyList();
        } catch (Exception e) {
            log.error("查询设备参数最新值失败: {}", e.getMessage());
            return Collections.emptyList();
        }
    }

    /**
     * 新增设备工艺参数当前值
     * 
     * @param baseDeviceParamVal 设备工艺参数当前值
     * @return 结果
     */
    @Override
    public int insertBaseDeviceParamVal(BaseDeviceParamVal baseDeviceParamVal)
    {
        return baseDeviceParamValMapper.insertBaseDeviceParamVal(baseDeviceParamVal);
    }

    /**
     * 修改设备工艺参数当前值
     * 
     * @param baseDeviceParamVal 设备工艺参数当前值
     * @return 结果
     */
    @Override
    public int updateBaseDeviceParamVal(BaseDeviceParamVal baseDeviceParamVal)
    {
        return baseDeviceParamValMapper.updateBaseDeviceParamVal(baseDeviceParamVal);
    }

    /**
     * 批量删除设备工艺参数当前值
     * 
     * @param recordIds 需要删除的设备工艺参数当前值主键
     * @return 结果
     */
    @Override
    public int deleteBaseDeviceParamValByRecordIds(Long[] recordIds)
    {
        return baseDeviceParamValMapper.deleteBaseDeviceParamValByRecordIds(recordIds);
    }

    /**
     * 删除设备工艺参数当前值信息
     * 
     * @param recordId 设备工艺参数当前值主键
     * @return 结果
     */
    @Override
    public int deleteBaseDeviceParamValByRecordId(Long recordId)
    {
        return baseDeviceParamValMapper.deleteBaseDeviceParamValByRecordId(recordId);
    }
}
