package com.jsowell.pile.service.impl;

import com.google.common.collect.Lists;
import com.jsowell.common.util.DateUtils;
import com.jsowell.pile.domain.PileModelInfo;
import com.jsowell.pile.mapper.PileModelInfoMapper;
import com.jsowell.pile.service.IPileModelInfoService;
import com.jsowell.pile.vo.web.PileModelInfoVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 充电桩型号信息Service业务层处理
 *
 * @author jsowell
 * @date 2022-08-26
 */
@Service
public class PileModelInfoServiceImpl implements IPileModelInfoService {
	@Autowired
	private PileModelInfoMapper pileModelInfoMapper;

	/**
	 * 查询充电桩型号信息
	 *
	 * @param id 充电桩型号信息主键
	 * @return 充电桩型号信息
	 */
	@Override
	public PileModelInfo selectPileModelInfoById(Long id) {
		return pileModelInfoMapper.selectPileModelInfoById(id);
	}

	/**
	 * 查询充电桩型号信息列表
	 *
	 * @param pileModelInfo 充电桩型号信息
	 * @return 充电桩型号信息
	 */
	@Override
	public List<PileModelInfo> selectPileModelInfoList(PileModelInfo pileModelInfo) {
		return pileModelInfoMapper.selectPileModelInfoList(pileModelInfo);
	}

	/**
	 * 新增充电桩型号信息
	 *
	 * @param pileModelInfo 充电桩型号信息
	 * @return 结果
	 */
	@Override
	public int insertPileModelInfo(PileModelInfo pileModelInfo) {
		pileModelInfo.setCreateTime(DateUtils.getNowDate());
		return pileModelInfoMapper.insertPileModelInfo(pileModelInfo);
	}

	/**
	 * 修改充电桩型号信息
	 *
	 * @param pileModelInfo 充电桩型号信息
	 * @return 结果
	 */
	@Override
	public int updatePileModelInfo(PileModelInfo pileModelInfo) {
		pileModelInfo.setUpdateTime(DateUtils.getNowDate());
		return pileModelInfoMapper.updatePileModelInfo(pileModelInfo);
	}

	/**
	 * 批量删除充电桩型号信息
	 *
	 * @param ids 需要删除的充电桩型号信息主键
	 * @return 结果
	 */
	@Override
	public int deletePileModelInfoByIds(Long[] ids) {
		return pileModelInfoMapper.deletePileModelInfoByIds(ids);
	}

	/**
	 * 删除充电桩型号信息信息
	 *
	 * @param id 充电桩型号信息主键
	 * @return 结果
	 */
	@Override
	public int deletePileModelInfoById(Long id) {
		return pileModelInfoMapper.deletePileModelInfoById(id);
	}

	/**
	 * 通过桩编号集合获取型号表中数据
	 *
	 * @param pileSns 桩编号集合
	 * @return PileModelInfo对象
	 */
    @Override
    public List<PileModelInfoVO> getPileModelInfoByPileSnList(List<String> pileSns) {
        return pileModelInfoMapper.getPileModelInfoByPileSnList(pileSns);
    }

	@Override
	public PileModelInfoVO getPileModelInfoByPileSn(String pileSn) {
		List<PileModelInfoVO> list = getPileModelInfoByPileSnList(Lists.newArrayList(pileSn));
		if (CollectionUtils.isNotEmpty(list)) {
			return list.get(0);
		}
		return null;
	}
}
