package com.ruoyi.system.service.impl;

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

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.TbSchool;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.TbSchoolMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbSchoolAtlasMapper;
import com.ruoyi.system.domain.TbSchoolAtlas;
import com.ruoyi.system.service.ITbSchoolAtlasService;
import com.ruoyi.common.core.text.Convert;

/**
 * 学校图册Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-08
 */
@Service
public class TbSchoolAtlasServiceImpl implements ITbSchoolAtlasService 
{
    @Autowired
    private TbSchoolAtlasMapper tbSchoolAtlasMapper;

//    @Autowired
//    private TbSchoolMapper tbSchoolMapper;
//
//    @Autowired
//    private SysUserMapper sysUserMapper;

    @Autowired
    private CommonServiceImpl commonService;

    /**
     * 查询学校图册
     * 
     * @param id 学校图册主键
     * @return 学校图册
     */
    @Override
    public TbSchoolAtlas selectTbSchoolAtlasById(Long id)
    {
        TbSchoolAtlas tsa=tbSchoolAtlasMapper.selectTbSchoolAtlasById(id);
//        TbSchool ts=tbSchoolMapper.selectTbSchoolById(tsa.getSchoolId());
        tsa.setSchoolName(commonService.getSchoolCnName(tsa.getSchoolId()));
        return tsa;
    }

    /**
     * 查询学校图册列表
     * 
     * @param tbSchoolAtlas 学校图册
     * @return 学校图册
     */
    @Override
    public List<TbSchoolAtlas> selectTbSchoolAtlasList(TbSchoolAtlas tbSchoolAtlas)
    {
        List<TbSchoolAtlas> list=tbSchoolAtlasMapper.selectTbSchoolAtlasList(tbSchoolAtlas);
        list.stream().filter(tbSchoolAtlas1 -> {
            tbSchoolAtlas1.setSchoolName(commonService.getSchoolCnName(tbSchoolAtlas1.getSchoolId()));
            convertUserIDToString(tbSchoolAtlas1);
            return true;
        }).collect(Collectors.toList());
        return list;
    }

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

        SysUser su=null;
//        su=sysUserMapper.selectUserById(tbSchoolAtlas.getCreator());
        tbSchoolAtlas.setCreatorDesc(commonService.getUserName(tbSchoolAtlas.getCreator()));
        if(ObjectUtils.isNotEmpty(tbSchoolAtlas.getModifiedBy())){
//            su=sysUserMapper.selectUserById(tbSchoolAtlas.getModifiedBy());
            tbSchoolAtlas.setModifiedByDesc(commonService.getUserName(tbSchoolAtlas.getModifiedBy()));
        }
    }

    /**
     * 新增学校图册
     * 
     * @param tbSchoolAtlas 学校图册
     * @return 结果
     */
    @Override
    public int insertTbSchoolAtlas(TbSchoolAtlas tbSchoolAtlas)
    {
        TbSchoolAtlas tsa=new TbSchoolAtlas();
        tsa.setSchoolId(tbSchoolAtlas.getSchoolId());
        tsa.setAtlasName(tbSchoolAtlas.getAtlasName());
        if(tbSchoolAtlasMapper.selectTbSchoolAtlasList(tsa).size()>0){
            return 0;
        }
        return tbSchoolAtlasMapper.insertTbSchoolAtlas(tbSchoolAtlas);
    }

    /**
     * 修改学校图册
     * 
     * @param tbSchoolAtlas 学校图册
     * @return 结果
     */
    @Override
    public int updateTbSchoolAtlas(TbSchoolAtlas tbSchoolAtlas)
    {
        return tbSchoolAtlasMapper.updateTbSchoolAtlas(tbSchoolAtlas);
    }

    /**
     * 批量删除学校图册
     * 
     * @param ids 需要删除的学校图册主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolAtlasByIds(String ids)
    {
        return tbSchoolAtlasMapper.deleteTbSchoolAtlasByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除学校图册信息
     * 
     * @param id 学校图册主键
     * @return 结果
     */
    @Override
    public int deleteTbSchoolAtlasById(Long id)
    {
        return tbSchoolAtlasMapper.deleteTbSchoolAtlasById(id);
    }
}
