<?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.qxgmat.data.relation.UserAskQuestionRelationMapper">
  <resultMap id="IdMap" type="com.qxgmat.data.dao.entity.UserAskQuestion">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
  </resultMap>
  <sql id="Id_Column_List">
    <!--
      WARNING - @mbg.generated
    -->
    ua.`id`
  </sql>

  <!--修改问答排序-->
  <update id="adjust">
    UPDATE `user_ask`
    <trim prefix="set" suffixOverrides=",">
      `order`#{flag}1
    </trim>
    WHERE `question_id` = #{questionId,jdbcType=VARCHAR} and `order` #{direction} #{order,jdbcType=INT}
  </update>

  <!--用户提问列表-->
  <select id="listWithUser" resultMap="IdMap">
    select
    <include refid="Id_Column_List" />
    from `user_ask` ua
    left join `user` u on u.`id` = ua.`user_id`
      <if test="userId != null">
        and ua.`user_id` = #{userId,jdbcType=VARCHAR}
      </if>
      <if test="max != null">
        and u.`total_money` &lt; ${max}
      </if>
      <if test="min != null">
        and u.`total_money` &gt; ${min}
      </if>
    left join `question` q on q.`id` = ua.`question_id`
    where
    u.`id` != null
    <if test="questionNoId != null">
      and ua.`question_no_id` = #{questionNoId,jdbcType=VARCHAR}
    </if>
    <if test="target != null">
      and ua.`target` = #{target,jdbcType=VARCHAR}
    </if>
    <if test="status != null">
      and ua.`status` = #{status,jdbcType=INT}
    </if>
    <if test="showStatus != null">
      and ua.`show_status` = #{showStatus,jdbcType=INT}
    </if>
    <if test="type != null">
      and q.`type` =#{type,jdbcType=VARCHAR}
    </if>
    order by ${order} ${direction}
  </select>
</mapper>