package com.jojubanking.boot.module.system.dal.mysql.student;

import java.util.*;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jojubanking.boot.framework.common.pojo.PageResult;
import com.jojubanking.boot.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jojubanking.boot.framework.mybatis.core.mapper.BaseMapperX;
import com.jojubanking.boot.module.system.controller.app.xytjinfo.vo.studentJfListVO;
import com.jojubanking.boot.module.system.dal.dataobject.order.OrderDO;
import com.jojubanking.boot.module.system.dal.dataobject.student.StudentDO;
import com.jojubanking.boot.module.system.dal.dataobject.xyrw.XyrwDO;
import org.apache.ibatis.annotations.Mapper;
import com.jojubanking.boot.module.system.controller.admin.student.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 学生信息 Mapper
 *
 * @author admin
 */
@Mapper
public interface StudentMapper extends BaseMapperX<StudentDO> {

    default PageResult<StudentDO> selectPage(StudentPageReqVO reqVO, XyrwDO xyrwDO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StudentDO>()
                .eqIfPresent(StudentDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(StudentDO::getPatid, reqVO.getPatid())
                .eqIfPresent(StudentDO::getName, reqVO.getName())
                .eqIfPresent(StudentDO::getSex, reqVO.getSex())
                .eqIfPresent(StudentDO::getAge, reqVO.getAge())
                .eqIfPresent(StudentDO::getNationId, reqVO.getNationId())
                .eqIfPresent(StudentDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(StudentDO::getFeeflag, reqVO.getFeeflag())
                .eqIfPresent(StudentDO::getClassName, reqVO.getClassName())
                .eqIfPresent(StudentDO::getSchoolName, reqVO.getSchoolName())
                .likeIfPresent(StudentDO::getSqName, reqVO.getSqName())
                .likeIfPresent(StudentDO::getJdName, reqVO.getJdName())
                .eqIfPresent(StudentDO::getEmail, reqVO.getEmail())
                .eqIfPresent(StudentDO::getMobile, reqVO.getMobile())
                .eqIfPresent(StudentDO::getRemark, reqVO.getRemark())
                .eqIfPresent(StudentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(StudentDO::getBatchno, xyrwDO.getBatchno())
                .betweenIfPresent(StudentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudentDO::getId));
    }
    default PageResult<StudentDO> selectHisPage(StudentPageReqVO reqVO, XyrwDO xyrwDO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<StudentDO>()
                .eqIfPresent(StudentDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(StudentDO::getPatid, reqVO.getPatid())
                .likeIfPresent(StudentDO::getName, reqVO.getName())
                .eqIfPresent(StudentDO::getSex, reqVO.getSex())
                .eqIfPresent(StudentDO::getAge, reqVO.getAge())
                .eqIfPresent(StudentDO::getNationId, reqVO.getNationId())
                .eqIfPresent(StudentDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(StudentDO::getFeeflag, reqVO.getFeeflag())
                .likeIfPresent(StudentDO::getClassName, reqVO.getClassName())
                .likeIfPresent(StudentDO::getSchoolName, reqVO.getSchoolName())
                .likeIfPresent(StudentDO::getSqName, reqVO.getSqName())
                .likeIfPresent(StudentDO::getJdName, reqVO.getJdName())
                .eqIfPresent(StudentDO::getEmail, reqVO.getEmail())
                .eqIfPresent(StudentDO::getMobile, reqVO.getMobile())
                .eqIfPresent(StudentDO::getRemark, reqVO.getRemark())
                .eqIfPresent(StudentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(StudentDO::getBatchno, reqVO.getBatchno())
                .neIfPresent(StudentDO::getBatchno, xyrwDO.getBatchno())
                .betweenIfPresent(StudentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudentDO::getId));
    }

    default List<StudentDO> selectListSimple(StudentExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<StudentDO>()
                .eqIfPresent(StudentDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(StudentDO::getPatid, reqVO.getPatid())
                .likeIfPresent(StudentDO::getName, reqVO.getName())
                .eqIfPresent(StudentDO::getSex, reqVO.getSex())
                .eqIfPresent(StudentDO::getAge, reqVO.getAge())
                .eqIfPresent(StudentDO::getNationId, reqVO.getNationId())
                .eqIfPresent(StudentDO::getDeptId, reqVO.getDeptId())
                .likeIfPresent(StudentDO::getClassName, reqVO.getClassName())
                .likeIfPresent(StudentDO::getSchoolName, reqVO.getSchoolName())
                .likeIfPresent(StudentDO::getSqName, reqVO.getSqName())
                .likeIfPresent(StudentDO::getJdName, reqVO.getJdName())
                .eqIfPresent(StudentDO::getEmail, reqVO.getEmail())
                .eqIfPresent(StudentDO::getMobile, reqVO.getMobile())
                .eqIfPresent(StudentDO::getRemark, reqVO.getRemark())
                .eqIfPresent(StudentDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(StudentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudentDO::getId));
    }
    @Select("SELECT * FROM xytj_student where openid = #{openid} and batchno = #{batchno} and deleted = 0")
    List<studentJfListVO> selectbyopenid(@Param("openid") String openid, @Param("batchno") String batchno);
    @Select("SELECT * FROM xytj_student where nation_id = #{nationid} and deleted = 0")
    StudentDO selectByNationId(String nationid);


    @Select("SELECT * FROM xytj_student where nation_id = #{nationid} and batchno = #{batchno} and deleted = 0")
    StudentDO selectByNationidForTJ(@Param("nationid") String nationid, @Param("batchno") String batchno);

    default List<StudentDO> selectList(StudentExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<StudentDO>()
                .eqIfPresent(StudentDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(StudentDO::getPatid, reqVO.getPatid())
                .likeIfPresent(StudentDO::getName, reqVO.getName())
                .eqIfPresent(StudentDO::getSex, reqVO.getSex())
                .eqIfPresent(StudentDO::getAge, reqVO.getAge())
                .eqIfPresent(StudentDO::getNationId, reqVO.getNationId())
                .eqIfPresent(StudentDO::getDeptId, reqVO.getDeptId())
                .likeIfPresent(StudentDO::getClassName, reqVO.getClassName())
                .likeIfPresent(StudentDO::getSchoolName, reqVO.getSchoolName())
                .likeIfPresent(StudentDO::getSqName, reqVO.getSqName())
                .likeIfPresent(StudentDO::getJdName, reqVO.getJdName())
                .eqIfPresent(StudentDO::getEmail, reqVO.getEmail())
                .eqIfPresent(StudentDO::getMobile, reqVO.getMobile())
                .eqIfPresent(StudentDO::getRemark, reqVO.getRemark())
                .eqIfPresent(StudentDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(StudentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudentDO::getId));
    }

    default List<StudentDO> selectListXy(StudentExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<StudentDO>()
                .eqIfPresent(StudentDO::getOpenid, reqVO.getOpenid())
                .eqIfPresent(StudentDO::getPatid, reqVO.getPatid())
                .eqIfPresent(StudentDO::getName, reqVO.getName())
                .eqIfPresent(StudentDO::getSex, reqVO.getSex())
                .eqIfPresent(StudentDO::getAge, reqVO.getAge())
                .eqIfPresent(StudentDO::getNationId, reqVO.getNationId())
                .eqIfPresent(StudentDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(StudentDO::getClassName, reqVO.getClassName())
                .eqIfPresent(StudentDO::getSchoolName, reqVO.getSchoolName())
                .likeIfPresent(StudentDO::getSqName, reqVO.getSqName())
                .likeIfPresent(StudentDO::getJdName, reqVO.getJdName())
                .eqIfPresent(StudentDO::getEmail, reqVO.getEmail())
                .eqIfPresent(StudentDO::getMobile, reqVO.getMobile())
                .eqIfPresent(StudentDO::getRemark, reqVO.getRemark())
                .eqIfPresent(StudentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(StudentDO::getBatchno, reqVO.getBatchno())
                .eqIfPresent(StudentDO::getFeeflag, reqVO.getFeeflag())
                .betweenIfPresent(StudentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(StudentDO::getSchoolName)
                .orderByDesc(StudentDO::getClassName)
                .orderByDesc(StudentDO::getName));
    }
    default void updateOrderByNotify(StudentDO studentDO){
        update(studentDO, Wrappers.lambdaUpdate(StudentDO.class)
                .eq(StudentDO::getBatchno, studentDO.getBatchno())
                .eq(StudentDO::getOrderno, studentDO.getOrderno()));
    }
    default void updateOrderByConfirm(StudentDO studentDO){
        update(studentDO, Wrappers.lambdaUpdate(StudentDO.class)
                .eq(StudentDO::getBatchno, studentDO.getBatchno())
                .eq(StudentDO::getPatid, studentDO.getPatid()));
    }

    default void updateXyrwName(StudentDO studentDO){
        update(studentDO, Wrappers.lambdaUpdate(StudentDO.class)
                .eq(StudentDO::getBatchno, studentDO.getBatchno()));
    }


}
