<?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="cn.com.ty.lift.ud.question.mapper.QuestionBankMapper">
    <resultMap id="BaseResultMap" type="cn.com.ty.lift.ud.question.mapper.entity.QuestionBankEntity">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="title" property="title" jdbcType="VARCHAR"/>
        <result column="expression" property="expression" jdbcType="VARCHAR"/>
        <result column="solution" property="solution" jdbcType="VARCHAR"/>
        <result column="imgs" property="imgs" jdbcType="VARCHAR"/>
        <result column="brand_id" property="brandId" jdbcType="INTEGER"/>
        <result column="expert" property="expert" jdbcType="INTEGER"/>
        <result column="reward" property="reward" jdbcType="DECIMAL"/>
        <result column="lock_flag" property="lockFlag" jdbcType="VARCHAR"/>
        <result column="hot_flag" property="hotFlag" jdbcType="INTEGER"/>
        <result column="statuz" property="statuz" jdbcType="INTEGER"/>
        <result column="favorite_num" property="favoriteNum" jdbcType="INTEGER"/>
        <result column="like_num" property="likeNum" jdbcType="INTEGER"/>
        <result column="browse_num" property="browseNum" jdbcType="INTEGER"/>
        <result column="tip_num" property="tipNum" jdbcType="INTEGER"/>
        <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="examine_flag" property="examineFlag" jdbcType="VARCHAR"/>
        <result column="not_examine_reason" property="notExamineReason" jdbcType="VARCHAR"/>
        <result column="valid_period" property="validPeriod" jdbcType="INTEGER"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, title, expression, solution, imgs, brand_id, expert,reward,lock_flag,hot_flag
    statuz, favorite_num,like_num,browse_num,tip_num
    create_by, create_time, update_by, update_time
    examine_flag,not_examine_reason,valid_period
  </sql>
    <!--<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >-->
    <!--select -->
    <!--<include refid="Base_Column_List" />-->
    <!--from user_withdraw-->
    <!--where id = #{id,jdbcType=INTEGER}-->
    <!--</select>-->
    <!--<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >-->
    <!--delete from user_withdraw-->
    <!--where id = #{id,jdbcType=INTEGER}-->
    <!--</delete>-->
    <!--题库管理新建功能-->
    <insert id="insertSelective" parameterType="cn.com.ty.lift.ud.question.mapper.entity.QuestionBankEntity">
        insert into question_bank
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null" >
                id,
            </if>
            <if test="title != null">
                title,
            </if>
            <if test="expression != null">
                expression,
            </if>
            <if test="solution != null">
                solution,
            </if>
            <if test="imgs != null">
                imgs,
            </if>
            <if test="brandId != null">
                brand_id,
            </if>
            <if test="expert != null">
                expert,
            </if>


            <if test="reward != null">
                reward,
            </if>
            <if test="lockFlag != null">
                lock_flag,
            </if>
            <if test="hotFlag != null">
                hot_flag,
            </if>
            <if test="statuz != null">
                statuz,
            </if>
            <if test="favoriteNum != null">
                favorite_num,
            </if>
            <if test="likeNum != null">
                like_num,
            </if>
            <if test="browseNum != null">
                browse_num,
            </if>
            <if test="tipNum != null">
                tip_num,
            </if>

            <if test="createBy != null">
                create_by,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateBy != null">
                update_by,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="examineFlag != null">
                examine_flag,
            </if>
            <if test="notExamineReason != null">
                not_examine_reason,
            </if>
            <if test="validPeriod != null">
                valid_period,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="id != null" >
                #{id,jdbcType=INTEGER},
            </if>
            <if test="title != null">
                #{title,jdbcType=VARCHAR},
            </if>
            <if test="expression != null">
                #{expression,jdbcType=VARCHAR},
            </if>
            <if test="solution != null">
                #{solution,jdbcType=VARCHAR},
            </if>
            <if test="imgs != null">
                #{imgs,jdbcType=VARCHAR},
            </if>
            <if test="brandId != null">
                #{brandId,jdbcType=INTEGER},
            </if>
            <if test="expert != null">
                #{expert,jdbcType=INTEGER},
            </if>


            <if test="reward != null">
                #{reward,jdbcType=DECIMAL},
            </if>
            <if test="lockFlag != null">
                #{lockFlag,jdbcType=VARCHAR},
            </if>
            <if test="hotFlag != null">
                #{hotFlag,jdbcType=INTEGER},
            </if>
            <if test="statuz != null">
                #{statuz,jdbcType=INTEGER},
            </if>
            <if test="favoriteNum != null">
                #{favoriteNum,jdbcType=INTEGER},
            </if>
            <if test="likeNum != null">
                #{likeNum,jdbcType=INTEGER},
            </if>
            <if test="browseNum != null">
                #{browseNum,jdbcType=INTEGER},
            </if>
            <if test="tipNum != null">
                #{tipNum,jdbcType=INTEGER},
            </if>

            <if test="createBy != null">
                #{createBy,jdbcType=INTEGER},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                #{updateBy,jdbcType=INTEGER},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="examineFlag != null">
                #{examineFlag,jdbcType=VARCHAR},
            </if>
            <if test="notExamineReason != null">
                #{notExamineReason,jdbcType=VARCHAR},
            </if>
            <if test="validPeriod != null">
                #{validPeriod,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <!--题库管理修改功能-->
    <update id="updateQuestionById" parameterType="cn.com.ty.lift.ud.question.mapper.entity.QuestionBankEntity" >
    update question_bank
    <set >
    <if test="title != null" >
        title = #{title,jdbcType=VARCHAR},
    </if>
    <if test="expert != null" >
        expert = #{expert,jdbcType=INTEGER},
    </if>
    <if test="expression != null" >
        expression = #{expression,jdbcType=VARCHAR},
    </if>
    <if test="solution != null" >
        solution = #{solution,jdbcType=VARCHAR},
    </if>
    <if test="imgs != null" >
        imgs = #{imgs,jdbcType=VARCHAR},
    </if>
    <if test="reward != null" >
        reward = #{reward,jdbcType=DECIMAL},
    </if>
    <if test="statuz != null" >
         statuz = #{statuz,jdbcType=INTEGER},
    </if>

     <if test="updateBy != null" >
            update_by = #{updateBy,jdbcType=VARCHAR},
     </if>
      <if test="updateTime != null" >
            update_time = #{updateTime,jdbcType=TIMESTAMP}
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
    </update>

    <!--后台分页查询-->
    <select id="selectByQuery" resultType="cn.com.ty.lift.ud.question.mapper.entity.QuestionBankEntity">
        select q.*,users.name as userName,brand.name as brandName ,users.avatar_url as avatarUrl
        from question_bank as q
        left join user_info as users on q.expert = users.user_id
        left join lift_brand as brand on q.brand_id = brand.id
        <where>
            ${ew.sqlSegment}
        </where>
        limit #{page.pageIndex},#{page.pageSize}
</select>

<!--查询总数量-->
    <select id="countByQuery" resultType="java.lang.Integer">
        select count(0) from question_bank as q
        left join user_info as users on q.expert = users.user_id
        left join lift_brand as brand on q.brand_id = brand.id
        <where>
            ${ew.sqlSegment}
        </where>
    </select>

    <!--根据id查详情-->
    <select id="getById" resultType="cn.com.ty.lift.ud.question.mapper.entity.QuestionBankEntity">
        select q.*,users.avatar_url as avatarUrl,users.name as userName,brand.name as brandName
        from question_bank as q
        left join user_info as users on q.expert = users.user_id
        left join lift_brand as brand on q.brand_id = brand.id
        where q.id = #{id}
    </select>

    <!--app分页查询-->
    <select id="selectAppByQuery" resultType="cn.com.ty.lift.ud.question.mapper.entity.QuestionBankEntity">
        select q.*,users.name as userName,brand.name as brandName ,users.avatar_url as avatarUrl
        from question_bank as q
        left join user_info as users on q.expert = users.user_id
        left join lift_brand as brand on q.brand_id = brand.id
        <where>
            q.statuz = 1 and q.examine_flag  = 1 and
            ${ew.sqlSegment}
        </where>
        limit #{page.pageIndex},#{page.pageSize}
    </select>

    <!--查询总数量-->
    <select id="countAppByQuery" resultType="java.lang.Integer">
        select count(0) from question_bank as q
        left join user_info as users on q.expert = users.user_id
        left join lift_brand as brand on q.brand_id = brand.id
        <where>
            q.statuz = 1 and q.examine_flag  = 1 and
            ${ew.sqlSegment}
        </where>
    </select>

</mapper>