package com.ruoyi.sim.service.impl;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysDeptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Validator;
import java.util.ArrayList;
import java.util.List;

@Service
public class TeacherService {

    private static final Logger log = LoggerFactory.getLogger(StudentService.class);

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private SysRoleMapper roleMapper;

    @Autowired
    private SysPostMapper postMapper;

    @Autowired
    private SysUserRoleMapper userRoleMapper;

    @Autowired
    private SysUserPostMapper userPostMapper;

    @Autowired
    private ISysConfigService configService;

    @Autowired
    private ISysDeptService deptService;

    @Autowired
    protected Validator validator;

    // @DataScope(deptAlias = "d", userAlias = "u")
    public List<SysUser> selectTeacherList() {
        SysUser su = new SysUser();
        List<SysUser> list  = userMapper.selectUserList(su);
        List<SysUser> list2 = new ArrayList<SysUser>();
        // todo:
        for (SysUser sysUser : list) {
            List<SysRole> listR = roleMapper.selectRolesByUserName(sysUser.getUserName());
            for (SysRole sysRole : listR) {
                if (sysRole.getRoleId() == Consts.ROLE_ID_TEACHER) {
                    list2.add(sysUser);
                    break;
                }
            }
        }
        return list2;
    }
}
