u
This commit is contained in:
1 parent
5221d1cc91
commit
a8a2657753
30 files changed
+552
-255
No files matched your search
@@ -4,8 +4,8 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.link56.post.mapper.PostMapper">
|
||||
|
||||
<resultMap id="QueryPostVOMap"
|
||||
type="cn.link56.post.model.vo.QueryPostVO">
|
||||
<resultMap id="QueryEditorPostVOMap"
|
||||
type="cn.link56.post.model.vo.QueryEditorPostVO">
|
||||
<id property="id" column="id"/>
|
||||
<result property="title" column="title"/>
|
||||
|
||||
@@ -25,7 +25,27 @@
|
||||
<result property="commentCount" column="commentCount"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectPostPage" resultMap="QueryPostVOMap">
|
||||
<resultMap id="QueryPublicPostVOMap"
|
||||
type="cn.link56.post.model.vo.QueryPublicPostVO">
|
||||
<id property="id" column="id"/>
|
||||
<result property="title" column="title"/>
|
||||
|
||||
<!-- tags 字符串 → List<String> -->
|
||||
<result
|
||||
property="tags"
|
||||
column="tagsString"
|
||||
typeHandler="cn.link56.common.mybatis.StringListTypeHandler"/>
|
||||
|
||||
<result property="companyId" column="companyId"/>
|
||||
<result property="companyName" column="companyName"/>
|
||||
|
||||
<result property="viewCount" column="viewCount"/>
|
||||
<result property="commentCount" column="commentCount"/>
|
||||
|
||||
<result property="activeTime" column="activeTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectEditorPostPage" resultMap="QueryEditorPostVOMap">
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
@@ -68,7 +88,7 @@
|
||||
WHERE t.rn BETWEEN #{offset} AND #{limit}
|
||||
</select>
|
||||
|
||||
<select id="selectPostTotal" resultType="java.lang.Long">
|
||||
<select id="selectEditorPostTotal" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM b_post p
|
||||
<where>
|
||||
@@ -94,7 +114,7 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardOverview" resultType="cn.link56.post.model.vo.DashboardVO$Count">
|
||||
<select id="selectDashboardOverview" resultType="cn.link56.post.model.vo.EditorDashboardVO$Count">
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM b_post WHERE b_create_by = #{userId}) AS postCount,
|
||||
(SELECT COUNT(*) FROM b_post_view WHERE b_post_id IN (SELECT b_id FROM b_post WHERE b_create_by = #{userId})) AS viewCount,
|
||||
@@ -102,7 +122,7 @@
|
||||
(SELECT COUNT(*) FROM b_post_favorite WHERE b_post_id IN (SELECT b_id FROM b_post WHERE b_create_by = #{userId})) AS favoriteCount
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardViewStats" resultType="cn.link56.post.model.vo.DashboardVO$Chart">
|
||||
<select id="selectDashboardViewStats" resultType="cn.link56.post.model.vo.EditorDashboardVO$Chart">
|
||||
SELECT
|
||||
CONVERT(VARCHAR(10), v.b_create_time, 120) AS label,
|
||||
COUNT(*) AS value
|
||||
@@ -115,7 +135,7 @@
|
||||
ORDER BY label
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardNumberStats" resultType="cn.link56.post.model.vo.DashboardVO$Chart">
|
||||
<select id="selectDashboardNumberStats" resultType="cn.link56.post.model.vo.EditorDashboardVO$Chart">
|
||||
SELECT
|
||||
CONVERT(VARCHAR(10), p.b_create_time, 120) AS label,
|
||||
COUNT(*) AS value
|
||||
@@ -127,4 +147,61 @@
|
||||
ORDER BY label
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectPublicPostPage" resultMap="QueryPublicPostVOMap">
|
||||
SELECT
|
||||
t.id,
|
||||
t.title,
|
||||
t.tagsString,
|
||||
t.companyId,
|
||||
t.companyName,
|
||||
t.viewCount,
|
||||
t.commentCount,
|
||||
t.activeTime
|
||||
FROM (
|
||||
SELECT
|
||||
p.b_id AS id,
|
||||
p.b_title AS title,
|
||||
p.b_tag AS tagsString,
|
||||
p.company_id AS companyId,
|
||||
bc.b_name AS companyName,
|
||||
|
||||
ISNULL(pv.viewCount, 0) AS viewCount,
|
||||
ISNULL(pc.commentCount, 0) AS commentCount,
|
||||
|
||||
-- 活跃时间:最后评论时间优先
|
||||
ISNULL(pc.lastCommentTime, p.b_update_time) AS activeTime,
|
||||
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY ISNULL(pc.lastCommentTime, p.b_update_time) DESC
|
||||
) AS rn
|
||||
FROM b_post p
|
||||
LEFT JOIN b_company bc ON bc.b_id = p.company_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
b_post_id,
|
||||
COUNT(1) AS viewCount
|
||||
FROM b_post_view
|
||||
GROUP BY b_post_id
|
||||
) pv ON pv.b_post_id = p.b_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
b_post_id,
|
||||
COUNT(1) AS commentCount,
|
||||
MAX(b_create_time) AS lastCommentTime
|
||||
FROM b_post_comment
|
||||
GROUP BY b_post_id
|
||||
) pc ON pc.b_post_id = p.b_id
|
||||
<where>
|
||||
<if test="title != null and title != ''">
|
||||
AND p.b_title LIKE '%' + #{title} + '%'
|
||||
</if>
|
||||
<if test="tag != null and tag != -1">
|
||||
AND p.b_tag LIKE '%' + #{tag} + '%'
|
||||
</if>
|
||||
</where>
|
||||
) t
|
||||
WHERE t.rn BETWEEN #{offset} AND #{limit}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user