package com.ruoyi.system.service.impl;

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

import com.ruoyi.common.utils.DateUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbSchoolPartnersMapper;
import com.ruoyi.system.domain.TbSchoolPartners;
import com.ruoyi.system.service.ITbSchoolPartnersService;
import com.ruoyi.common.core.text.Convert;

/**
 * 合作院校Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-13
 */
@Service
public class TbSchoolPartnersServiceImpl implements ITbSchoolPartnersService 
{
    @Autowired
    private TbSchoolPartnersMapper tbSchoolPartnersMapper;

    @Autowired
    private CommonServiceImpl commonService;

    /**
     * 查询合作院校
     * 
     * @param id 合作院校主键
     * @return 合作院校
     */
    @Override
    public TbSchoolPartners selectTbSchoolPartnersById(Long id)
    {
        TbSchoolPartners tsp=tbSchoolPartnersMapper.selectTbSchoolPartnersById(id);
        tsp.setSchoolCnName(commonService.getSchoolCnName(tsp.getSchoolId()));
        tsp.setCreatorDesc(commonService.getUserName(tsp.getCreator()));
        if(ObjectUtils.isNotEmpty(tsp.getModifiedBy())){
            tsp.setModifiedByDesc(commonService.getUserName(tsp.getModifiedBy()));
        }
        return tsp;
    }

    /**
     * 查询合作院校列表
     * 
     * @param tbSchoolPartners 合作院校
     * @return 合作院校
     */
    @Override
    public List<TbSchoolPartners> selectTbSchoolPartnersList(TbSchoolPartners tbSchoolPartners)
    {
        List<TbSchoolPartners> list =tbSchoolPartnersMapper.selectTbSchoolPartnersList(tbSchoolPartners);
        list.stream().filter(tsp -> {
            tsp.setSchoolCnName(commonService.getSchoolCnName(tsp.getSchoolId()));
            tsp.setCreatorDesc(commonService.getUserName(tsp.getCreator()));
            if(ObjectUtils.isNotEmpty(tsp.getModifiedBy())){
                tsp.setModifiedByDesc(commonService.getUserName(tsp.getModifiedBy()));
            }
            return true;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 新增合作院校
     * 
     * @param tbSchoolPartners 合作院校
     * @return 结果
     */
    @Override
    public int insertTbSchoolPartners(TbSchoolPartners tbSchoolPartners)
    {
        tbSchoolPartners.setCreateTime(DateUtils.getNowDate());
        return tbSchoolPartnersMapper.insertTbSchoolPartners(tbSchoolPartners);
    }

    /**
     * 修改合作院校
     * 
     * @param tbSchoolPartners 合作院校
     * @return 结果
     */
    @Override
    public int updateTbSchoolPartners(TbSchoolPartners tbSchoolPartners)
    {
        tbSchoolPartners.setUpdateTime(DateUtils.getNowDate());
        return tbSchoolPartnersMapper.updateTbSchoolPartners(tbSchoolPartners);
    }

    /**
     * 批量删除合作院校
     * 
     * @param ids 需要删除的合作院校主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolPartnersByIds(String ids)
    {
        return tbSchoolPartnersMapper.deleteTbSchoolPartnersByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除合作院校信息
     * 
     * @param id 合作院校主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolPartnersById(Long id)
    {
        return tbSchoolPartnersMapper.deleteTbSchoolPartnersById(id);
    }
}
