package beilv.carinformation.service.impl;

import beilv.carinformation.domain.CarInformation;
import beilv.carinformation.mapper.CarInformationMapper;
import beilv.carinformation.service.ICarInformationService;
import beilv.common.core.text.Convert;
import beilv.common.utils.DateUtils;
import beilv.common.utils.ShiroUtils;
import beilv.common.utils.uuid.IdUtils;
import beilv.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 卡种信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-02
 */
@Service
public class CarInformationServiceImpl implements ICarInformationService {
    @Autowired
    private CarInformationMapper carInformationMapper;
    @Autowired
    private ISysDictDataService dictDataService;

    /**
     * 查询卡种信息
     *
     * @param id 卡种信息主键
     * @return 卡种信息
     */
    @Override
    public CarInformation selectCarInformationById(Long id) {
        return carInformationMapper.selectCarInformationById(id);
    }

    /**
     * 查询卡种信息列表
     *
     * @param carInformation 卡种信息
     * @return 卡种信息
     */
    @Override
    public List<CarInformation> selectCarInformationList(CarInformation carInformation) {
        List<CarInformation> carInformations = carInformationMapper.selectCarInformationList(carInformation);
        for (CarInformation carInformation1 : carInformations) {
            carInformation1.setTypeLabel(dictDataService.selectDictLabel("site_type",carInformation1.getType()));
            carInformation1.setCardStateLabel(dictDataService.selectDictLabel("goods_state",carInformation1.getCardState()));
        }
        return carInformations;
    }

    /**
     * 新增卡种信息
     *
     * @param carInformation 卡种信息
     * @return 结果
     */
    @Override
    public int insertCarInformation(CarInformation carInformation) {
        carInformation.setCreateTime(DateUtils.getNowDate());
        carInformation.setCreateBy(ShiroUtils.getUserId().toString());
        carInformation.setCardState("2");
        return carInformationMapper.insertCarInformation(carInformation);
    }

    /**
     * 修改卡种信息
     *
     * @param carInformation 卡种信息
     * @return 结果
     */
    @Override
    public int updateCarInformation(CarInformation carInformation) {
        carInformation.setUpdateTime(DateUtils.getNowDate());
        carInformation.setUpdateBy(ShiroUtils.getUserId().toString());
        return carInformationMapper.updateCarInformation(carInformation);
    }

    /**
     * 批量删除卡种信息
     *
     * @param ids 需要删除的卡种信息主键
     * @return 结果
     */
    @Override
    public int deleteCarInformationByIds(String ids) {
        return carInformationMapper.deleteCarInformationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除卡种信息信息
     *
     * @param id 卡种信息主键
     * @return 结果
     */
    @Override
    public int deleteCarInformationById(Long id) {
        return carInformationMapper.deleteCarInformationById(id);
    }
}
