package com.ruoyi.record.service.impl;

import java.util.List;

import com.ruoyi.base.domain.BaseBusbarInfo;
import com.ruoyi.base.domain.BaseCabinetInfo;
import com.ruoyi.base.mapper.BaseBusbarInfoMapper;
import com.ruoyi.base.mapper.BaseCabinetInfoMapper;
import com.ruoyi.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.record.mapper.RecordBusbarTempMapper;
import com.ruoyi.record.domain.RecordBusbarTemp;
import com.ruoyi.record.service.IRecordBusbarTempService;

/**
 * 母排测温信息Service业务层处理
 * 
 * @author zangch
 * @date 2024-11-07
 */
@Service
public class RecordBusbarTempServiceImpl implements IRecordBusbarTempService 
{
    @Autowired
    private RecordBusbarTempMapper recordBusbarTempMapper;
    @Autowired
    private BaseCabinetInfoMapper baseCabinetInfoMapper;
    @Autowired
    private BaseBusbarInfoMapper baseBusbarInfoMapper;

    /**
     * 查询母排测温信息
     * 
     * @param objId 母排测温信息主键
     * @return 母排测温信息
     */
    @Override
    public RecordBusbarTemp selectRecordBusbarTempByObjId(Long objId)
    {
        return recordBusbarTempMapper.selectRecordBusbarTempByObjId(objId);
    }

    /**
     * 查询母排测温信息列表
     * 
     * @param recordBusbarTemp 母排测温信息
     * @return 母排测温信息
     */
    @Override
    public List<RecordBusbarTemp> selectRecordBusbarTempList(RecordBusbarTemp recordBusbarTemp)
    {
        return recordBusbarTempMapper.selectRecordBusbarTempList(recordBusbarTemp);
    }

    /**
     * 新增母排测温信息
     * 
     * @param recordBusbarTemp 母排测温信息
     * @return 结果
     */
    @Override
    public int insertRecordBusbarTemp(RecordBusbarTemp recordBusbarTemp)
    {
        Long cabinetCode = recordBusbarTemp.getCabinetCode();
        BaseCabinetInfo searcgBaseCabinet = new BaseCabinetInfo();
        searcgBaseCabinet.setCabinetCode(cabinetCode);
        List<BaseCabinetInfo>  baseCabinetInfoList = baseCabinetInfoMapper.selectBaseCabinetInfoList(searcgBaseCabinet);
        if (baseCabinetInfoList.isEmpty()){
            throw new ServiceException("未找到电柜信息");
        }

        Long busbarCode = recordBusbarTemp.getBusbarCode();
        BaseBusbarInfo searchBusbar = new BaseBusbarInfo();
        searchBusbar.setBusbarCode(busbarCode);
        List<BaseBusbarInfo> baseBusbarInfoList = baseBusbarInfoMapper.selectBaseBusbarInfoList(searchBusbar);
        if (baseBusbarInfoList.isEmpty()){
            throw new ServiceException("未找到母排信息");
        }

        return recordBusbarTempMapper.insertRecordBusbarTemp(recordBusbarTemp);
    }

    /**
     * 修改母排测温信息
     * 
     * @param recordBusbarTemp 母排测温信息
     * @return 结果
     */
    @Override
    public int updateRecordBusbarTemp(RecordBusbarTemp recordBusbarTemp)
    {
        Long cabinetCode = recordBusbarTemp.getCabinetCode();
        BaseCabinetInfo searcgBaseCabinet = new BaseCabinetInfo();
        searcgBaseCabinet.setCabinetCode(cabinetCode);
        List<BaseCabinetInfo>  baseCabinetInfoList = baseCabinetInfoMapper.selectBaseCabinetInfoList(searcgBaseCabinet);
        if (baseCabinetInfoList.isEmpty()){
            throw new ServiceException("未找到电柜信息");
        }

        Long busbarCode = recordBusbarTemp.getBusbarCode();
        BaseBusbarInfo searchBusbar = new BaseBusbarInfo();
        searchBusbar.setBusbarCode(busbarCode);
        List<BaseBusbarInfo> baseBusbarInfoList = baseBusbarInfoMapper.selectBaseBusbarInfoList(searchBusbar);
        if (baseBusbarInfoList.isEmpty()){
            throw new ServiceException("未找到母排信息");
        }

        return recordBusbarTempMapper.updateRecordBusbarTemp(recordBusbarTemp);
    }

    /**
     * 批量删除母排测温信息
     * 
     * @param objIds 需要删除的母排测温信息主键
     * @return 结果
     */
    @Override
    public int deleteRecordBusbarTempByObjIds(Long[] objIds)
    {
        return recordBusbarTempMapper.deleteRecordBusbarTempByObjIds(objIds);
    }

    /**
     * 删除母排测温信息信息
     * 
     * @param objId 母排测温信息主键
     * @return 结果
     */
    @Override
    public int deleteRecordBusbarTempByObjId(Long objId)
    {
        return recordBusbarTempMapper.deleteRecordBusbarTempByObjId(objId);
    }
}
