123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- <?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.ruoyi.generator.mapper.community.CommunityArticleMapper">
- <resultMap type="com.ruoyi.generator.vo.CommunityArticleVo" id="CommunityArticleVoResult">
- <id property="id" column="article_id"/>
- <result property="userId" column="article_user_id"/>
- <result property="title" column="article_title"/>
- <result property="content" column="article_content"/>
- <result property="createBy" column="article_create_by"/>
- <result property="createTime" column="article_create_time"/>
- <result property="updateBy" column="article_update_by"/>
- <result property="updateTime" column="article_update_time"/>
- <result property="remark" column="remark"/>
- <result property="userName" column="user_name"/>
- <result property="nickName" column="nick_name"/>
- <result property="comment" column=" is_comment"/>
- <result property="raffle" column="is_raffle"/>
- <result property="draft" column="is_draft"/>
- <result property="download" column="is_download"/>
- <result property="email" column="email"/>
- <result property="avatar" column="avatar"/>
- <result property="pageViews" column="pageViews"/>
- <result column="images" property="imageList" javaType="java.util.List" typeHandler="com.ruoyi.common.utils.bean.JSONTypeHandler"/>
- <result column="comments" property="comments" typeHandler="com.ruoyi.common.utils.bean.JSONTypeHandler"/>
- </resultMap>
- <resultMap type="CommunityArticleImages" id="CommunityArticleImagesResult">
- <id property="id" column="image_id"/>
- <result property="articleId" column="images_article_id"/>
- <result property="imageUrl" column="image_url"/>
- <result property="createBy" column="images_create_by"/>
- <result property="createTime" column="images_create_time"/>
- <result property="updateBy" column="images_update_by"/>
- <result property="updateTime" column="images_update_time"/>
- </resultMap>
- <resultMap type="SysUser" id="SysUserResult">
- <id property="userId" column="user_id"/>
- <result property="deptId" column="dept_id"/>
- <result property="phonenumber" column="phonenumber"/>
- <result property="sex" column="sex"/>
- <result property="password" column="password"/>
- <result property="userName" column="user_name"/>
- <result property="nickName" column="nick_name"/>
- <result property="email" column="email"/>
- <result property="avatar" column="avatar"/>
- <result property="status" column="status"/>
- <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="remark" column="remark"/>
- </resultMap>
- <resultMap type="com.ruoyi.generator.vo.CommunityArticleCommentVo" id="CommunityCommentsResult">
- <id property="id" column="comment_id"/>
- <result property="articleId" column="comment_article_id"/>
- <result property="userId" column="comment_user_id"/>
- <result property="content" column="comment_content"/>
- <result property="createBy" column="comment_create_by"/>
- <result property="createTime" column="comment_create_time"/>
- <result property="updateBy" column="comment_update_by"/>
- <result property="updateTime" column="comment_update_time"/>
- <result property="remark" column="comment_remark"/>
- </resultMap>
- <resultMap id="CommunityCollectResult" type="CommunityArticleCollect">
- <id property="id" column="collect_id"/>
- <result property="articleId" column="article_id"/>
- <result property="userId" column="user_id"/>
- <result property="createBy" column="create_by"/>
- <result property="createTime" column="create_time"/>
- <result property="updateBy" column="update_by"/>
- <result property="updateTime" column="update_time"/>
- </resultMap>
- <resultMap id="CommunityLikeResult" type="CommunityLike">
- <id property="id" column="like_id"/>
- <result property="articleId" column="article_id"/>
- <result property="userId" column="user_id"/>
- <result property="createBy" column="create_by"/>
- <result property="createTime" column="create_time"/>
- <result property="updateBy" column="update_by"/>
- <result property="updateTime" column="update_time"/>
- </resultMap>
- <sql id="selectCommunityArticleVo">
- select id as article_id,
- user_id,
- title,
- content,
- create_by,
- create_time,
- update_by,
- update_time,
- remark
- from community_article
- </sql>
- <select id="selectCommunityArticleList" parameterType="CommunityArticle" resultMap="CommunityArticleVoResult">
- select
- a.id as article_id,
- a.user_id as article_user_id,
- a.title as article_title,
- a.is_comment as article_is_comment,
- a.content as article_content,
- a.page_views as pageViews,
- a.create_by as article_create_by,
- a.create_time as article_create_time,
- a.update_by as article_update_by,
- a.update_time as article_update_time,
- IFNULL(a.address, '未知') as address,
- a.is_comment,
- a.is_raffle,
- a.is_download,
- a.article_type,
- COALESCE((
- SELECT
- JSON_ARRAYAGG(
- CASE
- WHEN b.id IS NOT NULL THEN
- JSON_OBJECT(
- 'id', IFNULL(b.id,''),
- 'articleId', IFNULL(b.article_id,''),
- 'imageUrl', IFNULL(b.image_url,''),
- 'compressUrl', IFNULL(b.compress_url,''),
- 'createBy', IFNULL(b.create_by,''),
- 'createTime', IFNULL(DATE_FORMAT(b.create_time,'%Y-%m-%d %H:%i:%s'),''),
- 'updateBy', IFNULL(b.update_by,''),
- 'updateTime', IFNULL(DATE_FORMAT(b.update_time,'%Y-%m-%d %H:%i:%s'),'')
- )
- ELSE NULL
- END
- )
- FROM
- community_article_images b
- WHERE
- b.article_id = a.id
- and (b.is_delete != 1 or b.is_delete is null)
- ), '[]') AS images,
- c.user_name as user_name,
- c.nick_name as nick_name,
- c.email as email,
- c.avatar as avatar
- # COALESCE((
- # SELECT
- # JSON_ARRAYAGG(
- # CASE
- # WHEN d.id IS NOT NULL THEN
- # JSON_OBJECT(
- # 'id', IFNULL(d.id,''),
- # 'articleId', IFNULL(d.article_id,''),
- # 'userId', IFNULL(d.user_id,''),
- # 'content', IFNULL(d.content,''),
- # 'createBy', IFNULL(d.create_by,''),
- # 'createTime', IFNULL(DATE_FORMAT(d.create_time,'%Y-%m-%d %H:%i:%s'),''),
- # 'updateBy', IFNULL(d.update_by,''),
- # 'updateTime', IFNULL(DATE_FORMAT(d.update_time,'%Y-%m-%d %H:%i:%s'),'')
- # )
- # ELSE NULL
- # END
- # )
- # FROM
- # community_article_comment d
- # WHERE
- # d.article_id = a.id and d.is_delete != 1 order by d.create_time desc
- # ), '[]') AS comments
- from
- community_article a
- left join sys_user c on a.user_id = c.user_id
- left join community_article_class e on e.article_id = a.id
- left join community_article_tag f on f.article_id = a.id
- <where>
- <if test="communityArticle.id != null and communityArticle.id != ''">
- AND a.id = #{communityArticle.id}
- </if>
- <if test="communityArticle.title != null and communityArticle.title != ''">
- AND a.title like concat('%', #{communityArticle.title}, '%')
- </if>
- <if test="classIds != null and classIds.size() > 0">
- and e.class_id IN
- <foreach collection="classIds" item="classId" index="index" open="(" close=")" separator=",">
- #{classId}
- </foreach>
- </if>
- <if test="communityArticle.userId != null and communityArticle.userId != ''">
- AND a.user_id = #{communityArticle.userId}
- </if>
- <if test="communityArticle.userIds != null and communityArticle.userIds.size > 0">
- AND a.user_id in
- <foreach collection="communityArticle.userIds" item="userId" index="index" open="(" close=")" separator=",">
- #{userId}
- </foreach>
- </if>
- <if test="communityArticle.tags != null and communityArticle.tags.size > 0">
- AND f.tag_id in
- <foreach collection="communityArticle.tags" item="tags" index="index" open="(" close=")" separator=",">
- ( select distinct id from community_tag where tag_name = #{tags} )
- </foreach>
- </if>
- <if test="communityArticle.articleIds != null and communityArticle.articleIds.size > 0">
- AND a.id in
- <foreach collection="communityArticle.articleIds" item="articleId" index="index" open="(" close=")" separator=",">
- #{articleId}
- </foreach>
- </if>
- <if test="communityArticle.isDraft != null and communityArticle.isDraft != '' ">
- AND IFNULL(a.is_Draft,0) = #{communityArticle.isDraft}
- </if>
- and (a.is_delete != 1 or a.is_delete is null)
- and (f.is_delete != 1 or f.is_delete is null)
- and a.user_id not in (select distinct peer_id from community_user_block where user_id = #{loginId} and is_block = 1 )
- </where>
- group by a.id,a.create_time
- <if test="searchType == 1">
- order by a.create_time desc
- </if>
- <if test="searchType == 2">
- order by a.page_views desc
- </if>
- <if test="searchType == 3">
- order by RAND()
- </if>
- limit #{offset},#{limit}
- </select>
- <select id="selectCommunityArticleCount" parameterType="CommunityArticle" resultType="int">
- SELECT COUNT(DISTINCT a.id)
- FROM community_article a
- LEFT JOIN sys_user c ON a.user_id = c.user_id
- LEFT JOIN community_article_class e ON e.article_id = a.id
- LEFT JOIN community_article_tag f ON f.article_id = a.id
- <where>
- <if test="communityArticle.id != null and communityArticle.id != ''">
- AND a.id = #{communityArticle.id}
- </if>
- <if test="communityArticle.title != null and communityArticle.title != ''">
- AND a.title LIKE CONCAT('%', #{communityArticle.title}, '%')
- </if>
- <if test="classIds != null and classIds.size() > 0">
- AND e.class_id IN
- <foreach collection="classIds" item="classId" open="(" close=")" separator=",">
- #{classId}
- </foreach>
- </if>
- <if test="communityArticle.userId != null and communityArticle.userId != ''">
- AND a.user_id = #{communityArticle.userId}
- </if>
- <if test="communityArticle.userIds != null and communityArticle.userIds.size > 0">
- AND a.user_id IN
- <foreach collection="communityArticle.userIds" item="userId" open="(" close=")" separator=",">
- #{userId}
- </foreach>
- </if>
- AND (a.is_delete != 1 OR a.is_delete IS NULL)
- AND (f.is_delete != 1 OR f.is_delete is null)
- </where>
- </select>
- <select id="selectCommunityArticleCollectById" resultMap="CommunityCollectResult">
- select collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
- community_article_collect
- <where>
- <if test="userId != null and userId != ''">
- user_id = #{userId}
- </if>
- <if test="articleId != null and articleId != ''">
- and article_id = #{articleId}
- </if>
- </where>
- </select>
- <!--点赞-->
- <select id="selectCommunityArticleLikeById" resultMap="CommunityLikeResult">
- select id as like_id, article_id, user_id, create_by, create_time, update_by, update_time from
- community_like
- <where>
- <if test="userId != null and userId != ''">
- user_id = #{userId}
- </if>
- <if test="articleId != null and articleId != ''">
- and article_id = #{articleId}
- </if>
- </where>
- </select>
- <insert id="insertCommunityLikeById" parameterType="communityLike">
- insert into community_like (article_id, user_id, create_by, create_time, update_by, update_time)
- values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
- </insert>
- <delete id="deleteCommunityLikeById" parameterType="communityLike">
- delete
- from community_like
- where user_id = #{userId}
- and article_id = #{articleId};
- </delete>
- <!--收藏-->
- <select id="selectCommunityCollectById" resultMap="CommunityCollectResult" parameterType="communityArticleCollect">
- select id as collect_id, article_id, user_id, create_by, create_time, update_by, update_time from
- community_article_collect
- <where>
- <if test="userId != null and userId != ''">
- user_id = #{userId}
- </if>
- <if test="articleId != null and articleId != ''">
- and article_id = #{articleId}
- </if>
- </where>
- </select>
- <insert id="insertCommunityCollectById" parameterType="communityArticleCollect">
- insert into community_article_collect (article_id, user_id, create_by, create_time, update_by, update_time)
- values (#{articleId}, #{userId}, #{userId}, now(), #{userId}, now());
- </insert>
- <delete id="deleteCommunityCollectById" parameterType="communityArticleCollect">
- delete
- from community_article_collect
- where user_id = #{userId}
- and article_id = #{articleId};
- </delete>
- <select id="selectTrendingTopByContent" resultType="com.ruoyi.generator.domain.Community.TrendingTop">
- SELECT
- distinct type,id,content
- FROM (
- SELECT
- 'article' as type, id,title as content
- FROM community_article
- WHERE title LIKE CONCAT( #{content}, '%') AND is_delete != '1'
- UNION ALL
- SELECT
- 'tag' as type, id,tag_name
- FROM community_tag
- WHERE tag_name LIKE CONCAT( #{content}, '%') AND is_delete != '1'
- UNION ALL
- SELECT
- 'user' as type, user_id,nick_name
- FROM sys_user
- WHERE nick_name LIKE CONCAT( #{content}, '%') AND status = '0'
- ) AS A
- </select>
- <select id="selectUserNoCoArticles" resultMap="CommunityArticleVoResult">
- SELECT
- a.id as article_id,
- a.user_id as article_user_id,
- a.title as article_title,
- a.is_comment as article_is_comment, -- 去重
- a.content as article_content,
- a.page_views as pageViews,
- a.create_by as article_create_by,
- a.create_time as article_create_time,
- a.update_by as article_update_by,
- a.update_time as article_update_time,
- a.address as address,
- a.is_raffle,
- COALESCE(
- (SELECT JSON_ARRAYAGG(JSON_OBJECT('imageUrl', IFNULL(b.image_url,'')))
- FROM community_article_images b
- WHERE b.article_id = a.id
- AND IFNULL(b.is_delete, 0) != 1),
- '[]'
- ) AS images,
- a.is_download
- FROM community_article a
- WHERE a.create_by = #{userId}
- AND NOT EXISTS (
- SELECT 1
- FROM community_collection_article c
- WHERE c.article_id = a.id
- AND IFNULL(c.is_delete, 0) != 1
- )
- AND IFNULL(a.is_delete, 0) != 1 -- 统一过滤条件
- </select>
- </mapper>
|