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

import java.util.*;

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.dal.dataobject.wqda.WqdaDO;
import com.jojubanking.boot.module.system.dal.dataobject.wqda.WqdaDOx;
import org.apache.ibatis.annotations.Mapper;
import com.jojubanking.boot.module.system.controller.admin.wqda.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 问卷调查答案 Mapper
 *
 * @author admin
 */
@Mapper
public interface WqdaMapper extends BaseMapperX<WqdaDO> {

    default PageResult<WqdaDO> selectPage(WqdaPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WqdaDO>()
                .eqIfPresent(WqdaDO::getTypeId, reqVO.getTypeId())
                .eqIfPresent(WqdaDO::getQuestionId, reqVO.getQuestionId())
                .eqIfPresent(WqdaDO::getQuestionType, reqVO.getQuestionType())
                .eqIfPresent(WqdaDO::getQuestionTitle, reqVO.getQuestionTitle())
                .eqIfPresent(WqdaDO::getQuestionAnswer, reqVO.getQuestionAnswer())
                .eqIfPresent(WqdaDO::getQuestionComment, reqVO.getQuestionComment())
                .likeIfPresent(WqdaDO::getUsername, reqVO.getUsername())
                .eqIfPresent(WqdaDO::getUsertel, reqVO.getUsertel())
                .betweenIfPresent(WqdaDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(WqdaDO::getId));
    }

    default List<WqdaDO> selectList(WqdaExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<WqdaDO>()
                .eqIfPresent(WqdaDO::getTypeId, reqVO.getTypeId())
                .eqIfPresent(WqdaDO::getQuestionId, reqVO.getQuestionId())
                .eqIfPresent(WqdaDO::getQuestionType, reqVO.getQuestionType())
                .eqIfPresent(WqdaDO::getQuestionTitle, reqVO.getQuestionTitle())
                .eqIfPresent(WqdaDO::getQuestionAnswer, reqVO.getQuestionAnswer())
                .eqIfPresent(WqdaDO::getQuestionComment, reqVO.getQuestionComment())
                .likeIfPresent(WqdaDO::getUsername, reqVO.getUsername())
                .eqIfPresent(WqdaDO::getUsertel, reqVO.getUsertel())
                .betweenIfPresent(WqdaDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(WqdaDO::getId));
    }

//    @Select("SELECT *, COUNT(*) as sum FROM hnwj_wqda where question_id = #{questionId} and type_id = #{typeId} GROUP BY question_answer order by id")
//    List<WqdaDO> selectSumList(@Param("questionId")String questionId, @Param("typeId")String typeId);

}
