package com.ruoyi.mall.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mall.domain.MallMajorClass;
import com.ruoyi.mall.mapper.MallMajorClassMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallCareerMapper;
import com.ruoyi.mall.domain.MallCareer;
import com.ruoyi.mall.service.IMallCareerService;

import javax.annotation.Resource;

/**
 * 职业Service业务层处理
 *
 * @author LCL
 * @date 2023-10-19
 */
@Service
public class MallCareerServiceImpl implements IMallCareerService
{
    @Resource
    private MallCareerMapper mallCareerMapper;

    @Resource
    private MallMajorClassMapper mallMajorClassMapper;

    /**
     * 查询职业
     *
     * @param careerId 职业主键
     * @return 职业
     */
    @Override
    public MallCareer selectMallCareerByCareerId(Long careerId)
    {
        return mallCareerMapper.selectMallCareerByCareerId(careerId);
    }

    /**
     * 查询职业列表
     *
     * @param mallCareer 职业
     * @return 职业
     */
    @Override
    public List<MallCareer> selectMallCareerList(MallCareer mallCareer)
    {
        return mallCareerMapper.selectMallCareerList(mallCareer);
    }

    /**
     * 新增职业
     *
     * @param mallCareer 职业
     * @return 结果
     */
    @Override
    public int insertMallCareer(MallCareer mallCareer)
    {
        mallCareer.setCreateAt(DateUtils.getTime());
        return mallCareerMapper.insertMallCareer(mallCareer);
    }

    /**
     * 修改职业
     *
     * @param mallCareer 职业
     * @return 结果
     */
    @Override
    public int updateMallCareer(MallCareer mallCareer)
    {
        mallCareer.setUpdateAt(DateUtils.getTime());
        return mallCareerMapper.updateMallCareer(mallCareer);
    }

    /**
     * 批量删除职业
     *
     * @param careerIds 需要删除的职业主键
     * @return 结果
     */
    @Override
    public int deleteMallCareerByCareerIds(Long[] careerIds)
    {
        return mallCareerMapper.deleteMallCareerByCareerIds(careerIds);
    }

    /**
     * 删除职业信息
     *
     * @param careerId 职业主键
     * @return 结果
     */
    @Override
    public int deleteMallCareerByCareerId(Long careerId)
    {
        return mallCareerMapper.deleteMallCareerByCareerId(careerId);
    }

    /**
     * 根据排序查询职业列表
     *
     * @param sortType 排序类型：0-默认，1-从高到低，2-从低到高
     * @param majorId  专业分类ID
     * @return 专业分类集合
     */
    @Override
    public List<Map<String, Object>> selectCareerListByParams(Integer sortType, Long majorId) {
        String majorName = "无";
        if (majorId == null) {
            majorName = null;
        } else {
            // 查询分类名称
            MallMajorClass majorClass = mallMajorClassMapper.selectMallMajorClassByMajorId(majorId);

            if (majorClass != null) {
                majorName = majorClass.getMajorName();
            }
        }

        List<Map<String, Object>> mapList = mallCareerMapper.selectCareerListByParams(sortType,majorName);
        if (mapList.size() > 0) {
            for (Map<String, Object> map : mapList) {
                List<Map<String, Object>> majorMapList = mallMajorClassMapper.selectRelatedMajorListByCareerId(Long.valueOf(map.get("careerId").toString()));
                map.put("majorMapList", majorMapList);
            }
        }
        return mapList;
    }

    /**
     * 查询职业列表-下拉框
     *
     * @return 职业集合
     */
    @Override
    public List<MallCareer> getCareerDropDownList() {
        return mallCareerMapper.getCareerDropDownList();
    }
}
