package com.ruoyi.frequency.level.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.code.PublicCommon;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.frequency.level.entity.Level;
import com.ruoyi.frequency.level.mapper.LevelMapper;
import com.ruoyi.frequency.level.service.LevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 等级Service业务层处理
 *
 * @author liwenlong
 * @date 2023-10-19
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class LevelServiceImpl extends ServiceImpl<LevelMapper, Level>  implements LevelService
{
    @Autowired
    private LevelMapper levelMapper;

    /**
     * 查询等级
     *
     * @param id 等级主键
     * @return 等级
     */
    @Override
    public Level selectLevelById(Long id)
    {
        return levelMapper.selectLevelById(id);
    }

    /**
     * 查询等级列表
     *
     * @param level 等级
     * @return 等级
     */
    @Override
    public List<Level> selectLevelList(Level level)
    {
        return levelMapper.selectLevelList(level);
    }

    /**
     * 新增等级
     *
     * @param level 等级
     * @return 结果
     */
    @Override
    public int insertLevel(Level level)
    {
        return levelMapper.insert(level);
    }

    /**
     * 修改等级
     *
     * @param level 等级
     * @return 结果
     */
    @Override
    public int updateLevel(Level level)
    {
        level.setUpdateTime(DateUtils.getNowDate());
        return levelMapper.updateById(level);
    }

    /**
     * 批量删除等级
     *
     * @param ids 需要删除的等级主键
     * @return 结果
     */
    @Override
    public int deleteLevelByIds(Long[] ids)
    {
        this.lambdaUpdate().set(Level::getDelFlag,PublicCommon.删除).in(Level::getId,ids).update();
        return ids.length;
    }

    /**
     * 删除等级信息
     *
     * @param id 等级主键
     * @return 结果
     */
    @Override
    public int deleteLevelById(Long id)
    {
        this.lambdaUpdate().set(Level::getDelFlag,PublicCommon.删除).eq(Level::getId,id).update();
        return 1;
    }
}
