package com.bc.exam.modules.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bc.exam.core.api.dto.PagingReqDTO;
import com.bc.exam.core.utils.StringUtils;
import com.bc.exam.modules.student.entity.Student;
import com.bc.exam.modules.student.mapper.StudentMapper;
import com.bc.exam.modules.student.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;


/**
 * @Description 描述:学生基础信息 服务实现类
 * @Author A贾宇婷034244310
 * @Date 20260615
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {


    @Override
    public IPage<Student> paging(PagingReqDTO<Student> reqDTO) {
        //创建分页对象
        Page<Student> query = new Page<>(reqDTO.getCurrent(), reqDTO.getSize());

        //查询条件
        QueryWrapper<Student> wrapper = new QueryWrapper<>();

        Student params = reqDTO.getParams();
        if(!StringUtils.isBlank(params.getId())){
            wrapper.eq("a.id", params.getId());
        }
        if(!StringUtils.isBlank(params.getUserid())){
            wrapper.eq("a.userid", params.getUserid());
        }

        wrapper.like(!StringUtils.isBlank(params.getNj()),"a.nj", params.getNj());//年级
        wrapper.like(!StringUtils.isBlank(params.getYuanxi()),"a.yuanxi", params.getYuanxi());//学院
        wrapper.like(!StringUtils.isBlank(params.getZhuanye()),"a.zhuanye", params.getZhuanye());//专业

        //获得数据
        IPage<Student> page = baseMapper.paging(query, wrapper);
        //转换结果
       // IPage<Student> pageData = JSON.parseObject(JSON.toJSONString(page), new TypeReference<Page<Student>>(){});

        return page;
    }
}
