package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.constant.Constants;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbSchoolEntranceRequirementsMapper;
import com.ruoyi.system.domain.TbSchoolEntranceRequirements;
import com.ruoyi.system.service.ITbSchoolEntranceRequirementsService;
import com.ruoyi.common.core.text.Convert;

/**
 * 入学要求Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-11
 */
@Service
public class TbSchoolEntranceRequirementsServiceImpl implements ITbSchoolEntranceRequirementsService 
{
    @Autowired
    private TbSchoolEntranceRequirementsMapper tbSchoolEntranceRequirementsMapper;

    @Autowired
    private CommonServiceImpl commonService;

    /**
     * 查询入学要求
     * 
     * @param id 入学要求主键
     * @return 入学要求
     */
    @Override
    public TbSchoolEntranceRequirements selectTbSchoolEntranceRequirementsById(Long id)
    {
        TbSchoolEntranceRequirements tser=tbSchoolEntranceRequirementsMapper.selectTbSchoolEntranceRequirementsById(id);
        tser.setSchoolCnName(commonService.getSchoolCnName(tser.getSchoolId()));
        convertUserIDToString(tser);
        tser.setCheckStatusDesc(commonService.convertDictToString(String.valueOf(tser.getCheckStatus()), Constants.BUSINESS_CHECK_STATUS));
        return tser;
    }

    /**
     * 查询入学要求列表
     * 
     * @param tbSchoolEntranceRequirements 入学要求
     * @return 入学要求
     */
    @Override
    public List<TbSchoolEntranceRequirements> selectTbSchoolEntranceRequirementsList(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        List<TbSchoolEntranceRequirements> list=tbSchoolEntranceRequirementsMapper.selectTbSchoolEntranceRequirementsList(tbSchoolEntranceRequirements);
        list.stream().filter(tser -> {
            tser.setSchoolCnName(commonService.getSchoolCnName(tser.getSchoolId()));
            convertUserIDToString(tser);
            tser.setCheckStatusDesc(commonService.convertDictToString(String.valueOf(tser.getCheckStatus()), Constants.BUSINESS_CHECK_STATUS));
            return true;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 查询没有通过审核的入学要求列表
     *
     * @param tbSchoolEntranceRequirements 入学要求
     * @return 入学要求
     */
    @Override
    public List<TbSchoolEntranceRequirements> selectTbSchoolEntranceRequirementsNotPassList(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        List<TbSchoolEntranceRequirements> list=tbSchoolEntranceRequirementsMapper.selectTbSchoolEntranceRequirementsNotPassList(tbSchoolEntranceRequirements);
        list.stream().filter(tser -> {
            tser.setSchoolCnName(commonService.getSchoolCnName(tser.getSchoolId()));
            convertUserIDToString(tser);
            tser.setCheckStatusDesc(commonService.convertDictToString(String.valueOf(tser.getCheckStatus()), Constants.BUSINESS_CHECK_STATUS));
            return true;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 新增入学要求
     * 
     * @param tbSchoolEntranceRequirements 入学要求
     * @return 结果
     */
    @Override
    public int insertTbSchoolEntranceRequirements(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        return tbSchoolEntranceRequirementsMapper.insertTbSchoolEntranceRequirements(tbSchoolEntranceRequirements);
    }

    /**
     * 修改入学要求
     * 
     * @param tbSchoolEntranceRequirements 入学要求
     * @return 结果
     */
    @Override
    public int updateTbSchoolEntranceRequirements(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        return tbSchoolEntranceRequirementsMapper.updateTbSchoolEntranceRequirements(tbSchoolEntranceRequirements);
    }

    @Override
    public int updateCheckResult(TbSchoolEntranceRequirements tbSchoolEntranceRequirements)
    {
        return tbSchoolEntranceRequirementsMapper.updateCheckResult(tbSchoolEntranceRequirements);
    }

    /**
     * 批量删除入学要求
     * 
     * @param ids 需要删除的入学要求主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolEntranceRequirementsByIds(String ids)
    {
        return tbSchoolEntranceRequirementsMapper.deleteTbSchoolEntranceRequirementsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除入学要求信息
     * 
     * @param id 入学要求主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolEntranceRequirementsById(Long id)
    {
        return tbSchoolEntranceRequirementsMapper.deleteTbSchoolEntranceRequirementsById(id);
    }

    /**
     * @Author : fanxiaolong
     * @Description :  转换userID为loginName
     * @DateTime : 2022/9/5 10:48
     * @param : tbSchoolMajor
     * @return : void
     */
    private void convertUserIDToString(TbSchoolEntranceRequirements tser){

        tser.setCreatorDesc(commonService.getUserName(tser.getCreator()));
        if(ObjectUtils.isNotEmpty(tser.getModifiedBy())){
            tser.setModifiedByDesc(commonService.getUserName(tser.getModifiedBy()));
        }
        if(ObjectUtils.isNotEmpty(tser.getChecker())){
            tser.setCheckerDesc(commonService.getUserName(tser.getChecker()));
        }
    }
}
