package cn.newfeifan.mall.module.distri.dal.mysql.applicationforwithdrawal;


import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
import cn.newfeifan.mall.module.distri.controller.admin.applicationforwithdrawalchannel.vo.GZHXExcelResp;
import cn.newfeifan.mall.module.distri.dal.dataobject.applicationforwithdrawal.ApplicationForWithdrawalDO;
import org.apache.ibatis.annotations.Mapper;
import cn.newfeifan.mall.module.distri.controller.admin.applicationforwithdrawal.vo.*;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 提现申请记录 Mapper
 *
 * @author 非繁人
 */
@Mapper
public interface ApplicationForWithdrawalMapper extends BaseMapperX<ApplicationForWithdrawalDO> {

    default PageResult<ApplicationForWithdrawalDO> selectPage(ApplicationForWithdrawalPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ApplicationForWithdrawalDO>()
                .eqIfPresent(ApplicationForWithdrawalDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ApplicationForWithdrawalDO::getWithdrawalType, reqVO.getWithdrawalType())
                .eqIfPresent(ApplicationForWithdrawalDO::getAmount, reqVO.getAmount())
                .eqIfPresent(ApplicationForWithdrawalDO::getWithdrawalAccount, reqVO.getWithdrawalAccount())
                .eqIfPresent(ApplicationForWithdrawalDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ApplicationForWithdrawalDO::getApplicationForWithdrawalChannelId, reqVO.getApplicationForWithdrawalChannelId())
                .betweenIfPresent(ApplicationForWithdrawalDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ApplicationForWithdrawalDO::getId));
    }

    @Select("SELECT p.name,stu.question_count questionCount,stu.correct_count correctCount,stu.error_count errorCount,stu.score,CONCAT(DATE_FORMAT(stu.start_time, '%Y-%m-%d '), DATE_FORMAT(stu.start_time, '%H:%i'), ' ~ ', DATE_FORMAT(stu.end_time, '%H:%i')) AS time,CASE WHEN pass = 1 THEN '合格' ELSE '不合格' END AS pass,de.name deName,po.name postName,ma.name macName,mac.name className FROM `study_examination` stu\n" +
            "left join person p on p.personid = stu.create_pid\n" +
            "left join post po on po.postid = p.postid\n" +
            "left join department de on de.departmentid = p.departmentid\n" +
            "left join major_class mac on mac.major_classid = p.major_classid\n" +
            "left join major ma on ma.majorid= mac.majorid\n" +
            "order by stu.create_time desc")
    List<GZHXExcelResp> selectStudy();
}