package com.ruoyi.wgz.mapper;

import com.ruoyi.wgz.domain.WgzQuestionSave;
import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
import com.ruoyi.common.core.mybatisplus.cache.MybatisPlusRedisCache;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * 用户试卷存储Mapper接口
 *
 * @author ruoyi
 * @date 2025-02-17
 */
// 如使需切换数据源 请勿使用缓存 会造成数据不一致现象
@CacheNamespace(implementation = MybatisPlusRedisCache.class, eviction = MybatisPlusRedisCache.class)
public interface WgzQuestionSaveMapper extends BaseMapperPlus<WgzQuestionSave> {

	@Select("SELECT SUM(score) AS sumScore, " +
		"(SELECT pass FROM bus_question_save WHERE user_id = #{userId} AND del_flag = '0' ORDER BY id ASC LIMIT 1) AS pass, " +
		"(SELECT sign FROM bus_question_save WHERE user_id = #{userId} AND del_flag = '0' ORDER BY id ASC LIMIT 1) AS sign " +
		"FROM wgz_question_save " +
		"WHERE correct = 1 AND user_id = #{userId}")
	Map<String, Object> getSumScoreAndPassAndSign(@Param("userId") Long userId);

}
