pet/com.datang.pet.mapper/target/classes/mapperExtend/TalkMapperExtend.xml

379 lines
18 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.datang.pet.mapperExtend.TalkMapperExtend">
<resultMap id="TalkListResultMap" type="com.datang.pet.vo.GetTalkListResponse">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="talk_type" jdbcType="INTEGER" property="talkType"/>
<result column="talk_date" jdbcType="TIMESTAMP" property="talkDate"/>
<result column="talk_describe" jdbcType="INTEGER" property="talkDescribe"/>
<result column="like_quantity" jdbcType="INTEGER" property="likeQuantity"/>
<result column="label" jdbcType="VARCHAR" property="label"/>
<result column="nike_name" jdbcType="VARCHAR" property="nikeName"/>
<result column="head_portrait" jdbcType="VARCHAR" property="headPortrait"/>
<result column="src" jdbcType="VARCHAR" property="src"/>
<result column="width" jdbcType="DOUBLE" property="width"/>
<result column="height" jdbcType="DOUBLE" property="height"/>
</resultMap>
<resultMap id="TalkSearchResultMap" type="com.datang.pet.pojo.TalkSearchRecord">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
<result column="keyword" jdbcType="VARCHAR" property="keyword"/>
<result column="date" jdbcType="TIMESTAMP" property="date"/>
<result column="not_have" jdbcType="CHAR" property="notHave"/>
</resultMap>
<resultMap id="TalkInfoResultMap" type="com.datang.pet.vo.TalkInfoResponse">
<id column="talk_id" jdbcType="VARCHAR" property="talkId"/>
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
<result column="bgm_id" jdbcType="VARCHAR" property="bgmId"/>
<result column="talk_describe" jdbcType="VARCHAR" property="bgmAuther"/>
<result column="like_quantity" jdbcType="VARCHAR" property="bgmName"/>
<result column="label" jdbcType="VARCHAR" property="label"/>
<result column="talk_type" jdbcType="INTEGER" property="talkType"/>
<result column="resource_id" jdbcType="VARCHAR" property="resourceId"/>
<result column="talk_describe" jdbcType="VARCHAR" property="talkDescribe"/>
<result column="talk_date" jdbcType="TIMESTAMP" property="talkDate"/>
<result column="like_quantity" jdbcType="INTEGER" property="likeQuantity"/>
<result column="comment_quantity" jdbcType="INTEGER" property="commentQuantity"/>
<result column="nike_name" jdbcType="VARCHAR" property="nikeName"/>
<result column="head_portrait" jdbcType="VARCHAR" property="headPortrait"/>
<result column="like_date" jdbcType="TIMESTAMP" property="likeDate"/>
<result column="attention_date" jdbcType="TIMESTAMP" property="attentionDate"/>
<collection property="resourceList" ofType="com.datang.pet.pojo.Resource">
<result column="id" jdbcType="VARCHAR" property="id"/>
<result column="src" jdbcType="VARCHAR" property="src"/>
<result column="sequence" jdbcType="INTEGER" property="sequence"/>
<result column="width" jdbcType="DOUBLE" property="width"/>
<result column="height" jdbcType="DOUBLE" property="height"/>
<result column="size" jdbcType="DOUBLE" property="size"/>
</collection>
</resultMap>
<resultMap id="getHotCommentResponse" type="com.datang.pet.vo.GetHotCommentResponse">
<id column="one_comment_id" jdbcType="VARCHAR" property="oneCommentId"/>
<result column="one_comment_content" jdbcType="VARCHAR" property="oneCommentContent"/>
<result column="talk_id" jdbcType="VARCHAR" property="talkId"/>
<result column="one_comment_user_id" jdbcType="VARCHAR" property="oneCommentUserId"/>
<result column="one_comment_date" jdbcType="TIMESTAMP" property="oneCommentDate"/>
<result column="one_like_quantity" jdbcType="INTEGER" property="oneLikeQuantity"/>
<result column="one_comment_quantity" jdbcType="INTEGER" property="oneCommentQuantity"/>
<result column="one_nike_name" jdbcType="VARCHAR" property="oneNikeName"/>
<result column="one_head_portrait" jdbcType="VARCHAR" property="oneHeadPortrait"/>
<result column="one_like_date" jdbcType="TIMESTAMP" property="oneLikeDate"/>
<result column="one_all_quantity" jdbcType="INTEGER" property="oneAllQuantity"/>
<collection property="twoCommentResponseList" ofType="com.datang.pet.vo.GetTwoCommentResponse">
<result column="two_comment_id" jdbcType="VARCHAR" property="twoCommentId"/>
<result column="two_one_comment_id" jdbcType="VARCHAR" property="twoOneCommentId"/>
<result column="two_comment_content" jdbcType="VARCHAR" property="twoCommentContent"/>
<result column="two_comment_user_id" jdbcType="VARCHAR" property="twoCommentUserId"/>
<result column="two_comment_date" jdbcType="TIMESTAMP" property="twoCommentDate"/>
<result column="two_like_quantity" jdbcType="INTEGER" property="twoLikeQuantity"/>
<result column="two_reply_user_id" jdbcType="VARCHAR" property="twoReplyUserId"/>
<result column="two_reply_user_nike_name" jdbcType="VARCHAR" property="twoReplyUserNikeName"/>
<result column="two_user_nike_name" jdbcType="VARCHAR" property="twoUserNikeName"/>
<result column="two_user_head_portrait" jdbcType="VARCHAR" property="twoUserHeadPortrait"/>
<result column="two_like_date" jdbcType="TIMESTAMP" property="twoLikeDate"/>
<result column="two_all_qunatity" jdbcType="INTEGER" property="twoAllQunatity"/>
</collection>
</resultMap>
<resultMap id="GetTwoCommentResponse" type="com.datang.pet.vo.GetTwoCommentResponse">
<id column="two_comment_id" jdbcType="VARCHAR" property="twoCommentId"/>
<result column="two_one_comment_id" jdbcType="VARCHAR" property="twoOneCommentId"/>
<result column="two_comment_content" jdbcType="VARCHAR" property="twoCommentContent"/>
<result column="two_comment_user_id" jdbcType="VARCHAR" property="twoCommentUserId"/>
<result column="two_comment_date" jdbcType="TIMESTAMP" property="twoCommentDate"/>
<result column="two_like_quantity" jdbcType="INTEGER" property="twoLikeQuantity"/>
<result column="two_reply_user_id" jdbcType="INTEGER" property="twoReplyUserId"/>
<result column="two_reply_user_nike_name" jdbcType="VARCHAR" property="twoReplyUserNikeName"/>
<result column="two_user_nike_name" jdbcType="VARCHAR" property="twoUserNikeName"/>
<result column="two_user_head_portrait" jdbcType="VARCHAR" property="twoUserHeadPortrait"/>
<result column="two_like_date" jdbcType="TIMESTAMP" property="twoLikeDate"/>
<result column="two_all_qunatity" jdbcType="INTEGER" property="twoAllQunatity"/>
</resultMap>
<select id="getTwoCommentByOneCommentIdNotInIdOrderByDate" resultMap="GetTwoCommentResponse">
SELECT t.*,tr.like_date AS two_like_date FROM
(
SELECT t.*,u.nike_name AS two_user_nike_name,u.head_portrait AS two_user_head_portrait FROM
(
SELECT t.*,u.nike_name AS two_reply_user_nike_name FROM
(
SELECT id AS two_comment_id,talk_one_tier_comment_id AS two_one_comment_id,comment_content AS
two_comment_content,user_id AS two_comment_user_id,
comment_date AS two_comment_date,like_quantity AS two_like_quantity,reply_user_id AS two_reply_user_id
FROM talk_two_tier_comment
<where>
<if test="time != null ">
comment_date &lt; #{time}
</if>
AND talk_one_tier_comment_id = #{oneCommentId} AND id !=#{notTwoId}
</where>
)AS t
LEFT JOIN user_info AS u ON t.two_reply_user_id=u.id
)AS t
LEFT JOIN user_info AS u ON t.two_comment_user_id=u.id
)AS t
LEFT JOIN talk_two_tier_comment_like_record tr ON t.two_comment_id=tr.talk_two_tier_comment_id AND
tr.like_user_id=#{userId}
ORDER BY two_comment_date DESC LIMIT 0,10
</select>
<select id="getCommentResponseByTalkIdNotInHotListOrderByDate" resultMap="getHotCommentResponse">
SELECT t.*,tlo.like_date AS two_like_date FROM
(
SELECT t.*,u.nike_name AS two_user_nike_name,u.head_portrait AS two_user_head_portrait FROM
(
SELECT t.*,u.nike_name AS two_reply_user_nike_name FROM
(
SELECT * FROM
(
SELECT t.*,tlo.like_date AS one_like_date FROM
(
SELECT t.*,u.nike_name AS one_nike_name,u.head_portrait AS one_head_portrait FROM
(
SELECT * FROM
(
SELECT id AS one_comment_id,comment_content AS one_comment_content, talk_id,user_id AS one_comment_user_id,
comment_date AS one_comment_date,like_quantity AS one_like_quantity,comment_quantity AS one_comment_quantity
FROM talk_one_tier_comment
<where>
<if test="time != null">
comment_date &lt; #{time}
</if>
AND talk_id = #{talkId} AND id NOT IN
<foreach item="item" collection="hotIds" separator="," open="(" close=")"
index="index">
#{item}
</foreach>
</where>
)AS t
LEFT JOIN (SELECT COUNT(*)AS one_all_quantity FROM talk_one_tier_comment WHERE talk_id= #{talkId} )AS tt ON 1=1
)AS t
LEFT JOIN user_info AS u ON u.id = t.one_comment_user_id
)t
LEFT JOIN talk_one_tier_comment_like_record AS tlo ON tlo.talk_one_tier_comment_id=t.one_comment_id AND tlo.user_id=#{userId}
)AS o
LEFT JOIN
(
SELECT t3.id AS two_comment_id,t3.talk_one_tier_comment_id AS two_one_comment_id,t3.comment_content AS two_comment_content,t3.user_id AS two_comment_user_id,
t3.comment_date AS two_comment_date,t3.like_quantity AS two_like_quantity,t3.reply_user_id AS two_reply_user_id ,t2.two_all_qunatity FROM talk_one_tier_comment t1
LEFT JOIN
(SELECT talk_one_tier_comment_id AS pid,MAX(comment_date) AS t_date,COUNT(*)AS two_all_qunatity FROM talk_two_tier_comment GROUP BY pid)t2
ON t1.id = t2.pid
LEFT JOIN talk_two_tier_comment t3 ON t1.id = t3.talk_one_tier_comment_id
AND t2.t_date = t3.comment_date
)AS t ON o.one_comment_id=t.two_one_comment_id
)AS t LEFT JOIN user_info AS u ON t.two_reply_user_id=u.id
)AS t LEFT JOIN user_info AS u ON t.two_comment_user_id=u.id
)AS t LEFT JOIN talk_two_tier_comment_like_record AS tlo ON tlo.talk_two_tier_comment_id=t.two_comment_id AND tlo.like_user_id=#{userId}
ORDER BY one_like_quantity DESC ,one_comment_date DESC LIMIT 0,10
</select>
<select id="getHotCommentResponseByTalkId" resultMap="getHotCommentResponse">
SELECT t.*,tlo.like_date AS two_like_date FROM
(
SELECT t.*,u.nike_name AS two_user_nike_name,u.head_portrait AS two_user_head_portrait FROM
(
SELECT t.*,u.nike_name AS two_reply_user_nike_name FROM
(
SELECT * FROM
(
SELECT t.*,tlo.like_date AS one_like_date FROM
(
SELECT t.*,u.nike_name AS one_nike_name,u.head_portrait AS one_head_portrait FROM
(
SELECT * FROM
(
SELECT id AS one_comment_id,comment_content AS one_comment_content, talk_id,user_id AS one_comment_user_id,
comment_date AS one_comment_date,like_quantity AS one_like_quantity,comment_quantity AS one_comment_quantity
FROM talk_one_tier_comment WHERE talk_id = #{talkId}
)AS t
LEFT JOIN (SELECT COUNT(*)AS one_all_quantity FROM talk_one_tier_comment WHERE talk_id= #{talkId} )AS tt ON 1=1
)AS t
LEFT JOIN user_info AS u ON u.id = t.one_comment_user_id
)t
LEFT JOIN talk_one_tier_comment_like_record AS tlo ON tlo.talk_one_tier_comment_id=t.one_comment_id AND tlo.user_id=#{userId}
)AS o
LEFT JOIN
(
SELECT t3.id AS two_comment_id,t3.talk_one_tier_comment_id AS two_one_comment_id,t3.comment_content AS two_comment_content,t3.user_id AS two_comment_user_id,
t3.comment_date AS two_comment_date,t3.like_quantity AS two_like_quantity,t3.reply_user_id AS two_reply_user_id ,t2.two_all_qunatity FROM talk_one_tier_comment t1
LEFT JOIN
(SELECT talk_one_tier_comment_id AS pid,MAX(comment_date) AS t_date,COUNT(*)AS two_all_qunatity FROM talk_two_tier_comment GROUP BY pid)t2
ON t1.id = t2.pid
LEFT JOIN talk_two_tier_comment t3 ON t1.id = t3.talk_one_tier_comment_id
AND t2.t_date = t3.comment_date
)AS t ON o.one_comment_id=t.two_one_comment_id
)AS t LEFT JOIN user_info AS u ON t.two_reply_user_id=u.id
)AS t LEFT JOIN user_info AS u ON t.two_comment_user_id=u.id
)AS t LEFT JOIN talk_two_tier_comment_like_record AS tlo ON tlo.talk_two_tier_comment_id=t.two_comment_id AND tlo.like_user_id=#{userId}
ORDER BY one_like_quantity DESC ,one_comment_date DESC LIMIT 0,10
</select>
<select id="getTalkInfo" resultMap="TalkInfoResultMap">
SELECT t.*,r.* FROM
(
SELECT t.*,ua.attention_date FROM
(
SELECT t.*,tr.like_date FROM
(
SELECT t.*,u.nike_name,u.head_portrait FROM
(
SELECT id AS talk_id,user_id,bgm_id,bgm_author,bgm_name,label,talk_type,resource_id,talk_describe,talk_date,like_quantity,comment_quantity
FROM talk WHERE id = #{talkId} AND ban = '0'
)AS t
LEFT JOIN user_info AS u ON t.user_id = u.id
)AS t
LEFT JOIN talk_like_record AS tr ON t.talk_id = tr.`talk_id` AND tr.user_id = #{userId}
)AS t
LEFT JOIN user_attention_record AS ua ON ua.fans_id = #{userId} AND ua.user_id = t.user_id
)AS t
LEFT JOIN resource AS r ON t.resource_id = r.id ORDER BY r.sequence ASC
</select>
<select id="getTalkList" resultMap="TalkListResultMap">
SELECT t.*,r.* FROM
(
SELECT t.*,u.nike_name,u.head_portrait FROM (
SELECT id,user_id,resource_id,like_quantity,talk_describe,talk_type,talk_date,label
FROM talk
<where>
<if test="time != null">
talk_date &lt; #{time}
</if>
AND ban='0'
</where>
)AS t LEFT JOIN user_info AS u ON t.user_id = u.id
)AS t LEFT JOIN (SELECT * FROM resource WHERE sequence=1)AS r ON r.id=t.resource_id
ORDER BY talk_date DESC LIMIT 0,20
</select>
<select id="getTalkListByUserId" resultMap="TalkListResultMap">
SELECT t.*,r.* FROM
(
SELECT t.*,u.nike_name,u.head_portrait FROM (
SELECT id,user_id,resource_id,like_quantity,talk_describe,talk_type,talk_date,label
FROM talk WHERE user_id=#{userId} AND ban='0'
)AS t LEFT JOIN user_info AS u ON t.user_id = u.id
)AS t LEFT JOIN (SELECT * FROM resource WHERE sequence=1)AS r ON r.id=t.resource_id
ORDER BY talk_date desc
</select>
<select id="getTalkListByKeyword" resultMap="TalkListResultMap">
SELECT t.*,r.src,r.width,r.height FROM
(
SELECT t.*,u.nike_name,u.head_portrait FROM
(
SELECT id,user_id,resource_id,like_quantity,talk_describe,talk_type,talk_date,label FROM talk
<where>
<if test="time != null">
talk_date &lt; #{time}
</if>
AND ban='0' AND (talk_describe LIKE '%${keyword}%' OR label LIKE '%${keyword}%')
</where>
LIMIT 0,20
)AS t
LEFT JOIN user_info AS u ON t.user_id = u.id
)AS t
LEFT JOIN resource AS r ON t.resource_id = r.id WHERE r.sequence = 1
ORDER BY t.talk_date DESC
</select>
<select id="getSearchRecordList" resultMap="TalkSearchResultMap">
SELECT *,COUNT(*) AS hotvalue FROM talk_search_record WHERE not_have = '0' GROUP BY keyword ORDER BY hotvalue DESC LIMIT 0,10;
</select>
<select id="getTalkLikeLabel" resultMap="TalkListResultMap">
SELECT t.*,r.src,r.width,r.height FROM
(
SELECT t.*,u.nike_name,u.head_portrait FROM
(
SELECT id,user_id,resource_id,like_quantity,talk_describe,talk_type,talk_date,label FROM talk
where label LIKE '%${label}%' AND ban='0' AND id != #{talkId}
LIMIT 0,6
)AS t
LEFT JOIN user_info AS u ON t.user_id = u.id
)AS t
LEFT JOIN resource AS r ON t.resource_id = r.id WHERE r.sequence = 1
ORDER BY t.talk_date DESC
</select>
<update id="increaseTalk">
update talk set
<choose>
<when test="type == 1">
like_quantity = like_quantity + 1
</when>
<when test="type == 2">
comment_quantity = comment_quantity + 1
</when>
<otherwise>
complanin_quantity = complanin_quantity + 1
</otherwise>
</choose>
where id = #{talkId}
</update>
<update id="decrementTalk">
update talk set
<choose>
<when test="type == 1">
like_quantity = like_quantity - 1
</when>
<when test="type == 2">
comment_quantity = comment_quantity - 1
</when>
</choose>
where id = #{talkId}
</update>
<update id="increaseOneComment">
update talk_one_tier_comment set
<choose>
<when test="type == 1">
like_quantity = like_quantity + 1
</when>
<otherwise>
comment_quantity = comment_quantity + 1
</otherwise>
</choose>
where id = #{commentId}
</update>
<update id="decrementOneComment">
update talk_one_tier_comment set
like_quantity = like_quantity - 1
where id = #{commentId}
</update>
<update id="increaseOrDecrementTwoComment">
update talk_two_tier_comment set
<choose>
<when test="type == 1">
like_quantity = like_quantity + 1
</when>
<otherwise>
like_quantity = like_quantity - 1
</otherwise>
</choose>
where id = #{commentId}
</update>
</mapper>