package com.ruoyi.mall.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mall.domain.MallConfigLevel;
import com.ruoyi.mall.domain.MallSchoolLevel;
import com.ruoyi.mall.mapper.MallConfigLevelMapper;
import com.ruoyi.mall.mapper.MallSchoolLevelMapper;
import com.ruoyi.mall.service.IMallSchoolLevelService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学校办学层次Service业务层处理
 *
 * @author Lsm
 * @date 2023-10-18
 */
@Service
public class MallSchoolLevelServiceImpl implements IMallSchoolLevelService
{
    @Resource
    private MallSchoolLevelMapper mallSchoolLevelMapper;

    @Resource
    private MallConfigLevelMapper mallConfigLevelMapper;

    /**
     * 查询学校办学层次
     *
     * @param schoolLevelId 学校办学层次主键
     * @return 学校办学层次
     */
    @Override
    public MallSchoolLevel selectMallSchoolLevelBySchoolLevelId(Long schoolLevelId)
    {
        return mallSchoolLevelMapper.selectMallSchoolLevelBySchoolLevelId(schoolLevelId);
    }

    /**
     * 查询学校办学层次列表
     *
     * @param mallSchoolLevel 学校办学层次
     * @return 学校办学层次
     */
    @Override
    public List<MallSchoolLevel> selectMallSchoolLevelList(MallSchoolLevel mallSchoolLevel)
    {
        return mallSchoolLevelMapper.selectMallSchoolLevelList(mallSchoolLevel);
    }

    /**
     * 新增学校办学层次
     *
     * @param mallSchoolLevel 学校办学层次
     * @return 结果
     */
    @Override
    public int insertMallSchoolLevel(MallSchoolLevel mallSchoolLevel)
    {
        // 层次名
        if (ObjectUtils.isNotEmpty(mallSchoolLevel.getConfigLevelId())){
            MallConfigLevel mallConfigLevel = mallConfigLevelMapper.selectMallConfigLevelByConfigLevelId(mallSchoolLevel.getConfigLevelId());
            mallSchoolLevel.setConfigLevelName(mallConfigLevel.getConfigLevelName());
        }
        mallSchoolLevel.setCreateAt(DateUtils.getTime());
        mallSchoolLevel.setDelFlag("0");
        return mallSchoolLevelMapper.insertMallSchoolLevel(mallSchoolLevel);
    }

    /**
     * 修改学校办学层次
     *
     * @param mallSchoolLevel 学校办学层次
     * @return 结果
     */
    @Override
    public int updateMallSchoolLevel(MallSchoolLevel mallSchoolLevel)
    {
        // 层次名
        if (ObjectUtils.isNotEmpty(mallSchoolLevel.getConfigLevelId())){
            MallConfigLevel mallConfigLevel = mallConfigLevelMapper.selectMallConfigLevelByConfigLevelId(mallSchoolLevel.getConfigLevelId());
            mallSchoolLevel.setConfigLevelName(mallConfigLevel.getConfigLevelName());
        }
        return mallSchoolLevelMapper.updateMallSchoolLevel(mallSchoolLevel);
    }

    /**
     * 批量删除学校办学层次
     *
     * @param schoolLevelIds 需要删除的学校办学层次主键
     * @return 结果
     */
    @Override
    public int deleteMallSchoolLevelBySchoolLevelIds(Long[] schoolLevelIds)
    {
        return mallSchoolLevelMapper.deleteMallSchoolLevelBySchoolLevelIds(schoolLevelIds);
    }

    /**
     * 删除学校办学层次信息
     *
     * @param schoolLevelId 学校办学层次主键
     * @return 结果
     */
    @Override
    public int deleteMallSchoolLevelBySchoolLevelId(Long schoolLevelId)
    {
        return mallSchoolLevelMapper.deleteMallSchoolLevelBySchoolLevelId(schoolLevelId);
    }
}
