package com.education.business.service.education;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.auth.AuthUtil;
import com.education.auth.session.UserSession;
import com.education.business.mapper.education.StuGoalInfoMapper;
import com.education.business.service.BaseService;
import com.education.common.enums.LoginEnum;
import com.education.common.model.PageInfo;
import com.education.model.dto.StuGoalInfoDto;
import com.education.model.dto.StuGoalInfoRespDto;
import com.education.model.entity.GoalInfo;
import com.education.model.entity.StuGoalInfo;
import com.education.model.request.PageParam;
import org.springframework.stereotype.Service;

/**
 * @author zhangj
 * @version 1.0
 * @create_at
 */
@Service
public class StuGoalInfoService extends BaseService<StuGoalInfoMapper, StuGoalInfo> {

    public PageInfo<StuGoalInfoDto> selectPageList(PageParam pageParam, StuGoalInfo stuGoalInfo) {
        Page<StuGoalInfoDto> page = new Page<>(pageParam.getPageNumber(), pageParam.getPageSize());
        return selectPage(baseMapper.selectPageList(page, stuGoalInfo));
    }

    @Override
    public boolean saveOrUpdate(StuGoalInfo stuGoalInfo) {
        return super.saveOrUpdate(stuGoalInfo);
    }

    public PageInfo<StuGoalInfoRespDto> selectPageByCourseId(PageParam pageParam, Integer courseId) {
        UserSession userSession = AuthUtil.getSession(LoginEnum.STUDENT.getValue());
        int studentId = userSession.getId().intValue();

        Page<StuGoalInfoRespDto> page = new Page<>(pageParam.getPageNumber(), pageParam.getPageSize());

        return selectPage(baseMapper.selectPageByCourseId(page, courseId, studentId));
    }

}