package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.TbSchool;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.TbSchoolMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author：fanxiaolong
 * @Date： 2022-10-11 17:18
 * @Description：
 */
@Component
public class CommonServiceImpl {

    @Autowired
    private TbSchoolMapper tbSchoolMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    public String getSchoolCnName(Long id){
        TbSchool ts=tbSchoolMapper.selectTbSchoolById(id);
        return ts.getSchoolCnName();
    }

    public String getUserName(Long userId){
        SysUser su=sysUserMapper.selectUserById(userId);
        return su.getLoginName();
    }

    public String convertDictToString(String dictValue,String dictName){
        List<SysDictData> dictDataList=sysDictDataMapper.selectDictDataByType(dictName);
        String[] dictLabel = new String[1];
        dictDataList.stream().forEach(sysDictData -> {
            if(StringUtils.compare(dictValue,sysDictData.getDictValue())==0){
                dictLabel[0] =sysDictData.getDictLabel();
            }
        });
        return dictLabel[0];
    }
}
