package com.ruoyi.hezhi.service.impl;

import com.ruoyi.common.enums.ServiceResponseEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.hezhi.domain.TbEvaluateAgency;
import com.ruoyi.hezhi.domain.vo.EvaluateAgencyVO;
import com.ruoyi.hezhi.mapper.TbEvaluateAgencyMapper;
import com.ruoyi.hezhi.service.ITbEvaluateAgencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 评价机构Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-23
 */
@Service
public class TbEvaluateAgencyServiceImpl implements ITbEvaluateAgencyService
{
    @Autowired
    private TbEvaluateAgencyMapper tbEvaluateAgencyMapper;

    /**
     * 查询评价机构
     *
     * @param evaluateAgencyId 评价机构主键
     * @return 评价机构
     */
    @Override
    public TbEvaluateAgency selectTbEvaluateAgencyByEvaluateAgencyId(Long evaluateAgencyId)
    {
        return tbEvaluateAgencyMapper.selectTbEvaluateAgencyByEvaluateAgencyId(evaluateAgencyId);
    }

    /**
     * 查询评价机构列表
     *
     * @param tbEvaluateAgency 评价机构
     * @return 评价机构
     */
    @Override
    public List<TbEvaluateAgency> selectTbEvaluateAgencyList(TbEvaluateAgency tbEvaluateAgency)
    {
        // 机构ID
        if (SecurityUtils.hasRole("evaluateAgency") && !SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            tbEvaluateAgency.setEvaluateAgencyId(SecurityUtils.getEvaluateAgencyId());
        }
        return tbEvaluateAgencyMapper.selectTbEvaluateAgencyList(tbEvaluateAgency);
    }

    /**
     * 新增评价机构
     *
     * @param tbEvaluateAgency 评价机构
     * @return 结果
     */
    @Override
    public int insertTbEvaluateAgency(TbEvaluateAgency tbEvaluateAgency)
    {
        tbEvaluateAgency.setEvaluateAgencyNumber(IdUtils.fastSimpleUUID());
        tbEvaluateAgency.setCreateTime(DateUtils.getNowDate());
        return tbEvaluateAgencyMapper.insertTbEvaluateAgency(tbEvaluateAgency);
    }

    /**
     * 修改评价机构
     *
     * @param tbEvaluateAgency 评价机构
     * @return 结果
     */
    @Override
    public int updateTbEvaluateAgency(TbEvaluateAgency tbEvaluateAgency)
    {
        tbEvaluateAgency.setUpdateTime(DateUtils.getNowDate());
        return tbEvaluateAgencyMapper.updateTbEvaluateAgency(tbEvaluateAgency);
    }

    /**
     * 批量删除评价机构
     *
     * @param evaluateAgencyIds 需要删除的评价机构主键
     * @return 结果
     */
    @Override
    public int deleteTbEvaluateAgencyByEvaluateAgencyIds(Long[] evaluateAgencyIds)
    {
        return tbEvaluateAgencyMapper.deleteTbEvaluateAgencyByEvaluateAgencyIds(evaluateAgencyIds);
    }

    /**
     * 删除评价机构信息
     *
     * @param evaluateAgencyId 评价机构主键
     * @return 结果
     */
    @Override
    public int deleteTbEvaluateAgencyByEvaluateAgencyId(Long evaluateAgencyId)
    {
        return tbEvaluateAgencyMapper.deleteTbEvaluateAgencyByEvaluateAgencyId(evaluateAgencyId);
    }

    /**
     * 获取筛选列表
     * @return 结果
     */
    @Override
    public List<EvaluateAgencyVO> getSelectList(){
        return tbEvaluateAgencyMapper.getSelectList();
    }

    /**
     * 评价机构列表
     *
     * @param params 参数
     * @return 评价机构列表
     */
    @Override
    public List<Map<String, Object>> getEvaluateAgencyList(Map<String, Object> params) {
        return tbEvaluateAgencyMapper.getEvaluateAgencyList(params);
    }

    /**
     * 获取有推荐课程的评价机构列表
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> getEvaluateAgencyListHasCourse(Map<String, Object> params){
        return tbEvaluateAgencyMapper.getEvaluateAgencyListHasCourse(params);
    }

    /**
     * 评价机构详情
     *
     * @param params 参数
     * @return 评价机构详情
     */
    @Override
    public Map<String, Object> getEvaluateAgencyInfo(Map<String, Object> params) {
        return tbEvaluateAgencyMapper.getEvaluateAgencyInfo(params);
    }

    /**
     * 根据课程类型获取机构列表
     * @param classType 1-职业考试，2-职业技能
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> getEvaluateAgencyListByClassType(Integer classType){
        return tbEvaluateAgencyMapper.getEvaluateAgencyListByClassType(classType);
    }
}
