|
@@ -0,0 +1,252 @@
|
|
|
+<?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.sooka.jnb.asking.mapper.JnbQuestionMapper">
|
|
|
+
|
|
|
+ <resultMap type="JnbQuestion" id="JnbQuestionResult">
|
|
|
+ <result property="id" column="id" />
|
|
|
+ <result property="title" column="title" />
|
|
|
+ <result property="text" column="text" />
|
|
|
+ <result property="whetherShow" column="whether_show" />
|
|
|
+ <result property="typeId" column="type_id" />
|
|
|
+ <result property="type" column="type" />
|
|
|
+ <result property="score" column="score" />
|
|
|
+ <result property="status" column="status" />
|
|
|
+ <result property="browse" column="browse" />
|
|
|
+ <result property="comment" column="comment" />
|
|
|
+ <result property="comment" column="comment" />
|
|
|
+ <result property="collect" column="collect" />
|
|
|
+ <result property="createBy" column="create_by" />
|
|
|
+ <result property="createTime" column="create_time" />
|
|
|
+ <result property="updateBy" column="update_by" />
|
|
|
+ <result property="updateTime" column="update_time" />
|
|
|
+ <result property="dataStatus" column="data_status" />
|
|
|
+ <result property="path" column="path" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <sql id="selectJnbQuestionVo">
|
|
|
+ select id, title, text, whether_show, type_id,type, score, status, browse, create_by, create_time, update_by, update_time, data_status from jnb_question
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <select id="selectJnbQuestionList" parameterType="JnbQuestion" resultMap="JnbQuestionResult">
|
|
|
+ <include refid="selectJnbQuestionVo"/>
|
|
|
+ where data_status = 1
|
|
|
+ <if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if>
|
|
|
+ <if test="text != null and text != ''"> and text = #{text}</if>
|
|
|
+ <if test="whetherShow != null and whetherShow != ''"> and whether_show = #{whetherShow}</if>
|
|
|
+ <if test="typeId != null and typeId != ''"> and type_id = #{typeId}</if>
|
|
|
+ <if test="score != null and score != ''"> and score = #{score}</if>
|
|
|
+ <if test="status != null and status != ''"> and status = #{status}</if>
|
|
|
+ <if test="browse != null "> and browse = #{browse}</if>
|
|
|
+ <if test="dataStatus != null and dataStatus != ''"> and data_status = #{dataStatus}</if>
|
|
|
+ order by create_time desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectJnbQuestionById" parameterType="String" resultMap="JnbQuestionResult">
|
|
|
+ SELECT
|
|
|
+ a.id,
|
|
|
+ a.title,
|
|
|
+ a.text,
|
|
|
+ a.whether_show,
|
|
|
+ a.type_id,
|
|
|
+ a.type,
|
|
|
+ a.score,
|
|
|
+ a.STATUS,
|
|
|
+ a.browse,
|
|
|
+ a.create_by,
|
|
|
+ a.create_time,
|
|
|
+ a.update_by,
|
|
|
+ a.update_time,
|
|
|
+ a.data_status,
|
|
|
+ GROUP_CONCAT(b.path) path,
|
|
|
+ count(c.id) collect
|
|
|
+ FROM
|
|
|
+ jnb_question a
|
|
|
+ left join jnb_question_img b on a.id = b.question_id
|
|
|
+ left join jnb_question_collect c on a.id = c.question_id
|
|
|
+ where a.id = #{id}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <insert id="insertJnbQuestion" parameterType="JnbQuestion">
|
|
|
+ insert into jnb_question
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">id,</if>
|
|
|
+ <if test="title != null">title,</if>
|
|
|
+ <if test="text != null">text,</if>
|
|
|
+ <if test="whetherShow != null">whether_show,</if>
|
|
|
+ <if test="typeId != null">type_id,</if>
|
|
|
+ <if test="type != null">type,</if>
|
|
|
+ <if test="score != null">score,</if>
|
|
|
+ <if test="status != null">status,</if>
|
|
|
+ <if test="browse != null">browse,</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="dataStatus != null">data_status,</if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">#{id},</if>
|
|
|
+ <if test="title != null">#{title},</if>
|
|
|
+ <if test="text != null">#{text},</if>
|
|
|
+ <if test="whetherShow != null">#{whetherShow},</if>
|
|
|
+ <if test="typeId != null">#{typeId},</if>
|
|
|
+ <if test="type != null">#{type},</if>
|
|
|
+ <if test="score != null">#{score},</if>
|
|
|
+ <if test="status != null">#{status},</if>
|
|
|
+ <if test="browse != null">#{browse},</if>
|
|
|
+ <if test="createBy != null">#{createBy},</if>
|
|
|
+ <if test="createTime != null">#{createTime},</if>
|
|
|
+ <if test="updateBy != null">#{updateBy},</if>
|
|
|
+ <if test="updateTime != null">#{updateTime},</if>
|
|
|
+ <if test="dataStatus != null">#{dataStatus},</if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <insert id="insertJnbQuestionImg" parameterType="JnbQuestionImg">
|
|
|
+ insert into jnb_question_img
|
|
|
+ <trim prefix="(" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">id,</if>
|
|
|
+ <if test="questionId != null">question_id,</if>
|
|
|
+ <if test="path != null">path,</if>
|
|
|
+ </trim>
|
|
|
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
|
|
|
+ <if test="id != null">#{id},</if>
|
|
|
+ <if test="questionId != null">#{questionId},</if>
|
|
|
+ <if test="path != null">#{path},</if>
|
|
|
+ </trim>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <update id="updateJnbQuestion" parameterType="JnbQuestion">
|
|
|
+ update jnb_question
|
|
|
+ <trim prefix="SET" suffixOverrides=",">
|
|
|
+ <if test="title != null">title = #{title},</if>
|
|
|
+ <if test="text != null">text = #{text},</if>
|
|
|
+ <if test="whetherShow != null">whether_show = #{whetherShow},</if>
|
|
|
+ <if test="typeId != null">type_id = #{typeId},</if>
|
|
|
+ <if test="type != null">type = #{type},</if>
|
|
|
+ <if test="score != null">score = #{score},</if>
|
|
|
+ <if test="status != null">status = #{status},</if>
|
|
|
+ <if test="browse != null">browse = #{browse},</if>
|
|
|
+ <if test="createBy != null">create_by = #{createBy},</if>
|
|
|
+ <if test="createTime != null">create_time = #{createTime},</if>
|
|
|
+ <if test="updateBy != null">update_by = #{updateBy},</if>
|
|
|
+ <if test="updateTime != null">update_time = #{updateTime},</if>
|
|
|
+ <if test="dataStatus != null">data_status = #{dataStatus},</if>
|
|
|
+ </trim>
|
|
|
+ where id = #{id}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <delete id="deleteJnbQuestionById" parameterType="String">
|
|
|
+ delete from jnb_question where id = #{id}
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <delete id="deleteQuestionImg" parameterType="String">
|
|
|
+ delete from jnb_question_img where question_id = #{id}
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <update id="deleteJnbQuestionByIds" parameterType="String">
|
|
|
+ update jnb_question set data_status = 2
|
|
|
+ where id in
|
|
|
+ <foreach item="id" collection="array" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <select id="getHotQuestionList" parameterType="JnbQuestion" resultMap="JnbQuestionResult">
|
|
|
+ SELECT
|
|
|
+ a.id,
|
|
|
+ a.title,
|
|
|
+ a.type,
|
|
|
+ a.score,
|
|
|
+ a.browse,
|
|
|
+ count(b.id) comment,
|
|
|
+ count(c.id) collect
|
|
|
+ FROM
|
|
|
+ jnb_question a
|
|
|
+ LEFT JOIN jnb_answer b on a.id = b.question_id and b.data_status = 1
|
|
|
+ LEFT JOIN jnb_question_collect c on a.id = c.question_id
|
|
|
+ WHERE
|
|
|
+ a.data_status = 1
|
|
|
+ and a.status = 1
|
|
|
+ and a.whether_show = 'Y'
|
|
|
+ and a.browse >= #{browse}
|
|
|
+ GROUP BY a.id
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getQuestionByType" parameterType="JnbQuestion" resultMap="JnbQuestionResult">
|
|
|
+ SELECT
|
|
|
+ a.id,
|
|
|
+ a.title,
|
|
|
+ a.text,
|
|
|
+ a.score,
|
|
|
+ a.browse,
|
|
|
+ GROUP_CONCAT(b.path) path,
|
|
|
+ a.create_by,
|
|
|
+ count(c.id) comment,
|
|
|
+ count(d.id) collect
|
|
|
+ FROM
|
|
|
+ jnb_question a
|
|
|
+ left join jnb_question_img b on a.id = b.question_id
|
|
|
+ left join jnb_answer c on a.id = c.question_id and c.data_status = 1
|
|
|
+ left join jnb_question_collect d on a.id = d.question_id
|
|
|
+ WHERE
|
|
|
+ a.data_status = 1
|
|
|
+ and a.`status` = 1
|
|
|
+ and a.whether_show = 'Y'
|
|
|
+ and a.type_id = #{id}
|
|
|
+ GROUP BY a.id
|
|
|
+ order by a.create_time desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getExcitingAnswersList" parameterType="JnbQuestion" resultMap="JnbQuestionResult">
|
|
|
+ SELECT
|
|
|
+ a.id,
|
|
|
+ a.title,
|
|
|
+ a.text,
|
|
|
+ a.score,
|
|
|
+ a.browse,
|
|
|
+ GROUP_CONCAT(b.path) path,
|
|
|
+ a.create_by,
|
|
|
+ count(c.id) comment,
|
|
|
+ count(d.id) collect
|
|
|
+ FROM
|
|
|
+ jnb_question a
|
|
|
+ left join jnb_question_img b on a.id = b.question_id
|
|
|
+ left join jnb_answer c on a.id = c.question_id and c.data_status = 1
|
|
|
+ left join jnb_question_collect d on a.id = d.question_id
|
|
|
+ WHERE
|
|
|
+ a.data_status = 1
|
|
|
+ and a.`status` = 1
|
|
|
+ and a.whether_show = 'Y'
|
|
|
+ and a.type_id = #{id}
|
|
|
+ GROUP BY a.id
|
|
|
+ order by count(d.id) desc,comment desc,a.browse desc,a.create_time desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getMaxScoreList" parameterType="JnbQuestion" resultMap="JnbQuestionResult">
|
|
|
+ SELECT
|
|
|
+ a.id,
|
|
|
+ a.title,
|
|
|
+ a.text,
|
|
|
+ a.score,
|
|
|
+ a.browse,
|
|
|
+ GROUP_CONCAT(b.path) path,
|
|
|
+ a.create_by,
|
|
|
+ count(c.id) comment,
|
|
|
+ count(d.id) collect
|
|
|
+ FROM
|
|
|
+ jnb_question a
|
|
|
+ left join jnb_question_img b on a.id = b.question_id
|
|
|
+ left join jnb_answer c on a.id = c.question_id and c.data_status = 1
|
|
|
+ left join jnb_question_collect d on a.id = d.question_id
|
|
|
+ WHERE
|
|
|
+ a.data_status = 1
|
|
|
+ and a.`status` = 1
|
|
|
+ and a.whether_show = 'Y'
|
|
|
+ and a.type_id = #{id}
|
|
|
+ GROUP BY a.id
|
|
|
+ order by a.score desc
|
|
|
+ </select>
|
|
|
+</mapper>
|