package com.ruoyi.system.service.impl;

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

import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbSchoolFacilitiesMapper;
import com.ruoyi.system.domain.TbSchoolFacilities;
import com.ruoyi.system.service.ITbSchoolFacilitiesService;
import com.ruoyi.common.core.text.Convert;

/**
 * 学校设施Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-12
 */
@Service
public class TbSchoolFacilitiesServiceImpl implements ITbSchoolFacilitiesService 
{
    @Autowired
    private TbSchoolFacilitiesMapper tbSchoolFacilitiesMapper;

    @Autowired
    private CommonServiceImpl commonService;

    /**
     * 查询学校设施
     * 
     * @param id 学校设施主键
     * @return 学校设施
     */
    @Override
    public TbSchoolFacilities selectTbSchoolFacilitiesById(Long id)
    {
        TbSchoolFacilities tsf=tbSchoolFacilitiesMapper.selectTbSchoolFacilitiesById(id);
        tsf.setSchoolCnName(commonService.getSchoolCnName(tsf.getSchoolId()));
        return tsf;
    }

    /**
     * 查询学校设施列表
     * 
     * @param tbSchoolFacilities 学校设施
     * @return 学校设施
     */
    @Override
    public List<TbSchoolFacilities> selectTbSchoolFacilitiesList(TbSchoolFacilities tbSchoolFacilities)
    {
        List<TbSchoolFacilities> list=tbSchoolFacilitiesMapper.selectTbSchoolFacilitiesList(tbSchoolFacilities);
        list.stream().filter(t -> {
            t.setSchoolCnName(commonService.getSchoolCnName(t.getSchoolId()));
            t.setCreatorDesc(commonService.getUserName(t.getCreator()));
            if(ObjectUtils.isNotEmpty(t.getModifiedBy())){
                t.setModifiedByDesc(commonService.getUserName(t.getModifiedBy()));
            }
            return true;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 新增学校设施
     * 
     * @param tbSchoolFacilities 学校设施
     * @return 结果
     */
    @Override
    public int insertTbSchoolFacilities(TbSchoolFacilities tbSchoolFacilities)
    {
        return tbSchoolFacilitiesMapper.insertTbSchoolFacilities(tbSchoolFacilities);
    }

    /**
     * 修改学校设施
     * 
     * @param tbSchoolFacilities 学校设施
     * @return 结果
     */
    @Override
    public int updateTbSchoolFacilities(TbSchoolFacilities tbSchoolFacilities)
    {
        return tbSchoolFacilitiesMapper.updateTbSchoolFacilities(tbSchoolFacilities);
    }

    /**
     * 批量删除学校设施
     * 
     * @param ids 需要删除的学校设施主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolFacilitiesByIds(String ids)
    {
        return tbSchoolFacilitiesMapper.deleteTbSchoolFacilitiesByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除学校设施信息
     * 
     * @param id 学校设施主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolFacilitiesById(Long id)
    {
        return tbSchoolFacilitiesMapper.deleteTbSchoolFacilitiesById(id);
    }
}
