<?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.fzm.mall.server.admin.system.mapper.SysQuestionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.fzm.mall.server.admin.system.model.SysQuestion">
        <id column="id" property="id" />
        <result column="question_id" property="questionId" />
        <result column="navigation_id" property="navigationId" />
        <result column="question" property="question" />
        <result column="answer" property="answer" />
        <result column="display_order" property="displayOrder" />
        <result column="status" property="status" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <select id="read" resultType="com.fzm.mall.server.admin.system.model.SysQuestion">
        select q.id, q.question_id, q.navigation_id, q.question, q.answer, q.display_order, q.status, q.create_time, q.update_time,
               n.navigation_name
        from sys_question q
        left join sys_navigation n on q.navigation_id = n.navigation_id
        where q.question_id = #{questionId}
    </select>

    <select id="page" resultType="com.fzm.mall.server.admin.system.entity.dto.SysQuestionDTO">
        select q.id, q.question_id, q.navigation_id, q.question, q.answer, q.display_order, q.status, q.create_time, q.update_time,
               n.navigation_name
        from sys_question q
        left join sys_navigation n on q.navigation_id = n.navigation_id
        <where>
            q.status = 0
            <if test="keyword != null and keyword != ''">
                and q.question like CONCAT('%', #{keyword},'%')
            </if>
            <if test="navigationId != null and navigationId != ''">
                and q.navigation_id = #{navigationId}
            </if>
        </where>
        order by q.display_order desc, q.update_time desc
    </select>
</mapper>
