50 lines
1.7 KiB
XML
50 lines
1.7 KiB
XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||
|
|
<mapper namespace="com.qingqiu.interview.mapper.QuestionMapper">
|
||
|
|
|
||
|
|
<select id="selectByCategory" resultType="com.qingqiu.interview.entity.Question">
|
||
|
|
SELECT *
|
||
|
|
FROM question
|
||
|
|
WHERE category = #{category} AND deleted = 0
|
||
|
|
ORDER BY created_time DESC
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="selectByCategories" resultType="com.qingqiu.interview.entity.Question">
|
||
|
|
SELECT *
|
||
|
|
FROM question
|
||
|
|
WHERE category IN
|
||
|
|
<foreach collection="categories" item="category" open="(" separator="," close=")">
|
||
|
|
#{category}
|
||
|
|
</foreach>
|
||
|
|
AND deleted = 0
|
||
|
|
ORDER BY created_time DESC
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="selectRandomByCategories" resultType="com.qingqiu.interview.entity.Question">
|
||
|
|
SELECT *
|
||
|
|
FROM question
|
||
|
|
WHERE category IN
|
||
|
|
<foreach collection="categories" item="category" open="(" separator="," close=")">
|
||
|
|
#{category}
|
||
|
|
</foreach>
|
||
|
|
AND deleted = 0
|
||
|
|
ORDER BY RAND()
|
||
|
|
LIMIT #{limit}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="selectByContent" resultType="com.qingqiu.interview.entity.Question">
|
||
|
|
SELECT *
|
||
|
|
FROM question
|
||
|
|
WHERE content = #{content} AND deleted = 0
|
||
|
|
LIMIT 1
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<select id="countByCategory" resultType="com.qingqiu.interview.dto.DashboardStatsResponse$CategoryStat">
|
||
|
|
SELECT category as name, COUNT(*) as value
|
||
|
|
FROM question
|
||
|
|
WHERE deleted = 0
|
||
|
|
GROUP BY category
|
||
|
|
ORDER BY value DESC
|
||
|
|
</select>
|
||
|
|
|
||
|
|
</mapper>
|