package com.tongran.rocketmq.service.impl;

import com.tongran.common.core.utils.DateUtils;
import com.tongran.rocketmq.domain.AllMoudleName;
import com.tongran.rocketmq.domain.InitialSwitchOpticalModule;
import com.tongran.rocketmq.mapper.AllMoudleNameMapper;
import com.tongran.rocketmq.service.IAllMoudleNameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 光模块名称存储Service业务层处理
 * 
 * @author tongran
 * @date 2026-01-04
 */
@Service
public class AllMoudleNameServiceImpl implements IAllMoudleNameService 
{
    @Autowired
    private AllMoudleNameMapper allMoudleNameMapper;

    /**
     * 查询光模块名称存储
     * 
     * @param id 光模块名称存储主键
     * @return 光模块名称存储
     */
    @Override
    public AllMoudleName selectAllMoudleNameById(Long id)
    {
        return allMoudleNameMapper.selectAllMoudleNameById(id);
    }

    /**
     * 查询光模块名称存储列表
     * 
     * @param allMoudleName 光模块名称存储
     * @return 光模块名称存储
     */
    @Override
    public List<AllMoudleName> selectAllMoudleNameList(AllMoudleName allMoudleName)
    {
        return allMoudleNameMapper.selectAllMoudleNameList(allMoudleName);
    }

    /**
     * 新增光模块名称存储
     * 
     * @param allMoudleName 光模块名称存储
     * @return 结果
     */
    @Override
    public int insertAllMoudleName(AllMoudleName allMoudleName)
    {
        allMoudleName.setCreateTime(DateUtils.getNowDate());
        return allMoudleNameMapper.insertAllMoudleName(allMoudleName);
    }

    /**
     * 修改光模块名称存储
     * 
     * @param allMoudleName 光模块名称存储
     * @return 结果
     */
    @Override
    public int updateAllMoudleName(AllMoudleName allMoudleName)
    {
        allMoudleName.setUpdateTime(DateUtils.getNowDate());
        return allMoudleNameMapper.updateAllMoudleName(allMoudleName);
    }

    /**
     * 批量删除光模块名称存储
     * 
     * @param ids 需要删除的光模块名称存储主键
     * @return 结果
     */
    @Override
    public int deleteAllMoudleNameByIds(Long[] ids)
    {
        return allMoudleNameMapper.deleteAllMoudleNameByIds(ids);
    }

    /**
     * 删除光模块名称存储信息
     * 
     * @param id 光模块名称存储主键
     * @return 结果
     */
    @Override
    public int deleteAllMoudleNameById(Long id)
    {
        return allMoudleNameMapper.deleteAllMoudleNameById(id);
    }

    @Override
    public void batchInsertMoudleName(List<InitialSwitchOpticalModule> dataList) {
        if(dataList == null){
            dataList = new ArrayList<>();
        }
        List<AllMoudleName> nameList = new ArrayList<>();
        for (InitialSwitchOpticalModule initialSwitchOpticalModule : dataList) {
            AllMoudleName allMoudleName = new AllMoudleName();
            allMoudleName.setClientId(initialSwitchOpticalModule.getClientId());
            allMoudleName.setName(initialSwitchOpticalModule.getFiberPortName());
            allMoudleName.setCreateTime(initialSwitchOpticalModule.getCreateTime());
            allMoudleName.setUpdateTime(DateUtils.getNowDate());
            nameList.add(allMoudleName);
        }
        allMoudleNameMapper.batchInsertMoudleName(nameList);
    }
}
