package com.ruoyi.school.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.page.RespPage;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.school.member.domain.ScStudent;
import com.ruoyi.school.member.domain.req.ReqStudentSelect;
import com.ruoyi.school.member.domain.resp.RespSearchStudent;
import com.ruoyi.school.member.mapper.ScStudentMapper;
import com.ruoyi.school.student.service.IScStudentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 会员基本信息 服务实现类
 * </p>
 *
 * @author zhangby
 * @since 2020-04-27 07:13:40
 */
@Service
public class ScStudentServiceImpl extends ServiceImpl<ScStudentMapper, ScStudent> implements IScStudentService {

    @Override
    public List<RespSearchStudent> selectStudentSelect(ReqStudentSelect studentSelect, Page page) {
        studentSelect.setTenantId(SecurityUtils.getLoginUser().getNowTenantId());
        return baseMapper.selectForSelect(studentSelect, page);
    }

    @Override
    public Long selectIdByName(String studentName) {
        QueryWrapper<ScStudent> qw = new QueryWrapper<>();
        qw.select("student_id");
        qw.eq("student_name", studentName);
        List<ScStudent> studentList = this.list(qw);
        if (null != studentList && studentList.size() > 0) {
            return studentList.get(0).getStudentId();
        }
        return null;
    }

    @Override
    public RespPage<ScStudent> selectStudentList(Integer max) {
        QueryWrapper<ScStudent> qw = new QueryWrapper<>();
        qw.select("student_id","student_name");
        qw.orderByDesc("create_time");
        RespPage<ScStudent> respPage = new RespPage<ScStudent>(1,max);
        return this.page(respPage,qw);
    }
}
