495 lines
23 KiB
XML
495 lines
23 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.kexue.skills.mapper.CmsContentMapper">
|
|
|
|
<resultMap type="com.kexue.skills.entity.CmsContent" id="CmsContentMap">
|
|
<result property="contentId" column="content_id" jdbcType="BIGINT"/>
|
|
<result property="title" column="title" jdbcType="VARCHAR"/>
|
|
<result property="subtitle" column="subtitle" jdbcType="VARCHAR"/>
|
|
<result property="contentType" column="content_type" jdbcType="INTEGER"/>
|
|
<result property="summary" column="summary" jdbcType="VARCHAR"/>
|
|
<result property="description" column="description" jdbcType="LONGVARCHAR"/>
|
|
<result property="requirement" column="requirement" jdbcType="LONGVARCHAR"/>
|
|
<result property="introduce" column="introduce" jdbcType="LONGVARCHAR"/>
|
|
<result property="content" column="content" jdbcType="LONGVARCHAR"/>
|
|
<result property="coverImage" column="cover_image" jdbcType="VARCHAR"/>
|
|
<result property="authorId" column="author_id" jdbcType="BIGINT"/>
|
|
<result property="authorName" column="author_name" jdbcType="VARCHAR"/>
|
|
<result property="reviewerId" column="reviewer_id" jdbcType="BIGINT"/>
|
|
<result property="reviewerName" column="reviewer_name" jdbcType="VARCHAR"/>
|
|
<result property="auditStatus" column="audit_status" jdbcType="INTEGER"/>
|
|
<result property="auditComment" column="audit_comment" jdbcType="VARCHAR"/>
|
|
<result property="publishStatus" column="publish_status" jdbcType="INTEGER"/>
|
|
<result property="publishTime" column="publish_time" jdbcType="TIMESTAMP"/>
|
|
<result property="viewCount" column="view_count" jdbcType="INTEGER"/>
|
|
<result property="likeCount" column="like_count" jdbcType="INTEGER"/>
|
|
<result property="commentCount" column="comment_count" jdbcType="INTEGER"/>
|
|
<result property="sort" column="sort" jdbcType="INTEGER"/>
|
|
<result property="isPaid" column="is_paid" jdbcType="BIT"/>
|
|
<result property="price" column="price" jdbcType="DECIMAL"/>
|
|
<result property="requiredPoints" column="required_points" jdbcType="INTEGER"/>
|
|
<result property="supportPointsPay" column="support_points_pay" jdbcType="BIT"/>
|
|
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
|
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
|
|
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
|
|
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
|
|
<result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
|
|
<result property="isOfficial" column="is_official" jdbcType="BIT"/>
|
|
<result property="shareCount" column="share_count" jdbcType="INTEGER"/>
|
|
<result property="fileUrl" column="file_url" jdbcType="VARCHAR"/>
|
|
<result property="icon" column="icon" jdbcType="VARCHAR"/>
|
|
<result property="background" column="background" jdbcType="VARCHAR"/>
|
|
<result property="origin" column="origin" jdbcType="VARCHAR"/>
|
|
<result property="tags" column="tags" jdbcType="VARCHAR"/>
|
|
</resultMap>
|
|
|
|
<!--查询单个-->
|
|
<select id="queryById" resultMap="CmsContentMap">
|
|
select
|
|
content_id, title, subtitle, content_type, summary, description, requirement, introduce, content, cover_image, author_id, author_name,
|
|
reviewer_id, reviewer_name, audit_status, audit_comment, publish_status, publish_time,
|
|
view_count, like_count, comment_count, sort, is_paid, price, required_points, support_points_pay, is_official, share_count, file_url, icon, background, origin, tags, create_time, update_time, create_by, update_by, delete_flag
|
|
from cms_content
|
|
where content_id = #{contentId}
|
|
</select>
|
|
|
|
<!--查询分页列表-->
|
|
<select id="getPageList" resultMap="CmsContentMap">
|
|
select
|
|
content_id, title, subtitle, content_type, summary, description, requirement, introduce, content, cover_image, author_id, author_name,
|
|
reviewer_id, reviewer_name, audit_status, audit_comment, publish_status, publish_time,
|
|
view_count, like_count, comment_count, sort, is_paid, price, required_points, support_points_pay, is_official, share_count, file_url, icon, background, origin, tags, create_time, update_time, create_by, update_by, delete_flag
|
|
from cms_content
|
|
<where>
|
|
<if test="contentId != null">
|
|
and content_id = #{contentId}
|
|
</if>
|
|
<if test="title != null and title != ''">
|
|
and (title like concat('%', #{title}, '%') or summary like concat('%', #{title}, '%'))
|
|
</if>
|
|
<if test="contentType != null">
|
|
and content_type = #{contentType}
|
|
</if>
|
|
<if test="authorId != null">
|
|
and author_id = #{authorId}
|
|
</if>
|
|
<if test="authorName != null and authorName != ''">
|
|
and author_name like concat('%', #{authorName}, '%')
|
|
</if>
|
|
<if test="auditStatus != null">
|
|
and audit_status = #{auditStatus}
|
|
</if>
|
|
<if test="publishStatus != null">
|
|
and publish_status = #{publishStatus}
|
|
</if>
|
|
<if test="createBy != null and createBy != ''">
|
|
and create_by like concat('%', #{createBy}, '%')
|
|
</if>
|
|
<if test="deleteFlag != null">
|
|
and delete_flag = #{deleteFlag}
|
|
</if>
|
|
<if test="isOfficial != null">
|
|
and is_official = #{isOfficial}
|
|
</if>
|
|
<if test="tagId != null">
|
|
and find_in_set(#{tagId}, tags)
|
|
</if>
|
|
</where>
|
|
<if test="sortBy != null and sortBy != ''">
|
|
order by ${sortBy} ${sortDesc ? 'desc' : 'asc'}
|
|
</if>
|
|
<if test="sortBy == null or sortBy == ''">
|
|
order by sort asc, create_time desc
|
|
</if>
|
|
</select>
|
|
|
|
<!--带分页的查询-->
|
|
<select id="getPageListWithPagination" resultMap="CmsContentMap">
|
|
select
|
|
content_id, title, subtitle, content_type, summary, description, requirement, introduce, content, cover_image, author_id, author_name,
|
|
reviewer_id, reviewer_name, audit_status, audit_comment, publish_status, publish_time,
|
|
view_count, like_count, comment_count, sort, is_paid, price, required_points, support_points_pay, is_official, share_count, file_url, icon, background, origin, tags, create_time, update_time, create_by, update_by, delete_flag
|
|
from cms_content
|
|
<where>
|
|
<if test="queryDto.contentId != null">
|
|
and content_id = #{queryDto.contentId}
|
|
</if>
|
|
<if test="queryDto.title != null and queryDto.title != ''">
|
|
and (title like concat('%', #{queryDto.title}, '%') or summary like concat('%', #{queryDto.title}, '%'))
|
|
</if>
|
|
<if test="queryDto.contentType != null">
|
|
and content_type = #{queryDto.contentType}
|
|
</if>
|
|
<if test="queryDto.authorId != null">
|
|
and author_id = #{queryDto.authorId}
|
|
</if>
|
|
<if test="queryDto.authorName != null and queryDto.authorName != ''">
|
|
and author_name like concat('%', #{queryDto.authorName}, '%')
|
|
</if>
|
|
<if test="queryDto.auditStatus != null">
|
|
and audit_status = #{queryDto.auditStatus}
|
|
</if>
|
|
<if test="queryDto.publishStatus != null">
|
|
and publish_status = #{queryDto.publishStatus}
|
|
</if>
|
|
<if test="queryDto.createBy != null and queryDto.createBy != ''">
|
|
and create_by like concat('%', #{queryDto.createBy}, '%')
|
|
</if>
|
|
<if test="queryDto.deleteFlag != null">
|
|
and delete_flag = #{queryDto.deleteFlag}
|
|
</if>
|
|
<if test="queryDto.isOfficial != null">
|
|
and is_official = #{queryDto.isOfficial}
|
|
</if>
|
|
<if test="queryDto.tagId != null">
|
|
and find_in_set(#{queryDto.tagId}, tags)
|
|
</if>
|
|
</where>
|
|
<if test="queryDto.sortBy != null and queryDto.sortBy != ''">
|
|
order by ${queryDto.sortBy} ${queryDto.sortDesc ? 'desc' : 'asc'}
|
|
</if>
|
|
<if test="queryDto.sortBy == null or queryDto.sortBy == ''">
|
|
order by sort asc, create_time desc
|
|
</if>
|
|
limit #{offset}, #{limit}
|
|
</select>
|
|
|
|
<!--查询总记录数-->
|
|
<select id="getPageListCount" resultType="int">
|
|
select count(*)
|
|
from cms_content
|
|
<where>
|
|
<if test="contentId != null">
|
|
and content_id = #{contentId}
|
|
</if>
|
|
<if test="title != null and title != ''">
|
|
and (title like concat('%', #{title}, '%') or summary like concat('%', #{title}, '%'))
|
|
</if>
|
|
<if test="contentType != null">
|
|
and content_type = #{contentType}
|
|
</if>
|
|
<if test="authorId != null">
|
|
and author_id = #{authorId}
|
|
</if>
|
|
<if test="authorName != null and authorName != ''">
|
|
and author_name like concat('%', #{authorName}, '%')
|
|
</if>
|
|
<if test="auditStatus != null">
|
|
and audit_status = #{auditStatus}
|
|
</if>
|
|
<if test="publishStatus != null">
|
|
and publish_status = #{publishStatus}
|
|
</if>
|
|
<if test="createBy != null and createBy != ''">
|
|
and create_by like concat('%', #{createBy}, '%')
|
|
</if>
|
|
<if test="deleteFlag != null">
|
|
and delete_flag = #{deleteFlag}
|
|
</if>
|
|
<if test="isOfficial != null">
|
|
and is_official = #{isOfficial}
|
|
</if>
|
|
<if test="tagId != null">
|
|
and find_in_set(#{tagId}, tags)
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<!--查询列表-->
|
|
<select id="getList" resultMap="CmsContentMap">
|
|
select
|
|
content_id, title, subtitle, content_type, summary, description, requirement, introduce, content, cover_image, author_id, author_name,
|
|
reviewer_id, reviewer_name, audit_status, audit_comment, publish_status, publish_time,
|
|
view_count, like_count, comment_count, sort, is_paid, price, required_points, support_points_pay, is_official, share_count, file_url, icon, background, origin, tags, create_time, update_time, create_by, update_by, delete_flag
|
|
from cms_content
|
|
<where>
|
|
<if test="contentId != null">
|
|
and content_id = #{contentId}
|
|
</if>
|
|
<if test="title != null and title != ''">
|
|
and (title like concat('%', #{title}, '%') or summary like concat('%', #{title}, '%'))
|
|
</if>
|
|
<if test="contentType != null">
|
|
and content_type = #{contentType}
|
|
</if>
|
|
<if test="authorId != null">
|
|
and author_id = #{authorId}
|
|
</if>
|
|
<if test="auditStatus != null">
|
|
and audit_status = #{auditStatus}
|
|
</if>
|
|
<if test="publishStatus != null">
|
|
and publish_status = #{publishStatus}
|
|
</if>
|
|
<if test="deleteFlag != null">
|
|
and delete_flag = #{deleteFlag}
|
|
</if>
|
|
<if test="isOfficial != null">
|
|
and is_official = #{isOfficial}
|
|
</if>
|
|
<if test="tagId != null">
|
|
and find_in_set(#{tagId}, tags)
|
|
</if>
|
|
</where>
|
|
order by sort asc, create_time desc
|
|
</select>
|
|
|
|
<!--新增所有列-->
|
|
<insert id="insert" keyProperty="contentId" useGeneratedKeys="true">
|
|
insert into cms_content(title, subtitle, content_type, summary, description, requirement, introduce, content, cover_image, author_id, author_name,
|
|
reviewer_id, reviewer_name, audit_status, audit_comment, publish_status, publish_time,
|
|
view_count, like_count, comment_count, sort, is_paid, price, required_points, support_points_pay, is_official, share_count, file_url, icon, background, origin, tags, create_time, update_time, create_by, update_by, delete_flag)
|
|
values (#{title}, #{subtitle}, #{contentType}, #{summary}, #{description}, #{requirement}, #{introduce}, #{content}, #{coverImage}, #{authorId}, #{authorName},
|
|
#{reviewerId}, #{reviewerName}, #{auditStatus}, #{auditComment}, #{publishStatus}, #{publishTime},
|
|
#{viewCount}, #{likeCount}, #{commentCount}, #{sort}, #{isPaid}, #{price}, #{requiredPoints}, #{supportPointsPay}, #{isOfficial}, #{shareCount}, #{fileUrl}, #{icon}, #{background}, #{origin}, #{tags}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy}, #{deleteFlag})
|
|
</insert>
|
|
|
|
<!--通过主键修改数据-->
|
|
<update id="update">
|
|
update cms_content
|
|
<set>
|
|
<if test="title != null and title != ''">
|
|
title = #{title},
|
|
</if>
|
|
<if test="subtitle != null">
|
|
subtitle = #{subtitle},
|
|
</if>
|
|
<if test="contentType != null">
|
|
content_type = #{contentType},
|
|
</if>
|
|
<if test="summary != null">
|
|
summary = #{summary},
|
|
</if>
|
|
<if test="description != null">
|
|
description = #{description},
|
|
</if>
|
|
<if test="requirement != null">
|
|
requirement = #{requirement},
|
|
</if>
|
|
<if test="introduce != null">
|
|
introduce = #{introduce},
|
|
</if>
|
|
<if test="content != null">
|
|
content = #{content},
|
|
</if>
|
|
<if test="coverImage != null">
|
|
cover_image = #{coverImage},
|
|
</if>
|
|
<if test="authorId != null">
|
|
author_id = #{authorId},
|
|
</if>
|
|
<if test="authorName != null and authorName != ''">
|
|
author_name = #{authorName},
|
|
</if>
|
|
<if test="reviewerId != null">
|
|
reviewer_id = #{reviewerId},
|
|
</if>
|
|
<if test="reviewerName != null and reviewerName != ''">
|
|
reviewer_name = #{reviewerName},
|
|
</if>
|
|
<if test="auditStatus != null">
|
|
audit_status = #{auditStatus},
|
|
</if>
|
|
<if test="auditComment != null">
|
|
audit_comment = #{auditComment},
|
|
</if>
|
|
<if test="publishStatus != null">
|
|
publish_status = #{publishStatus},
|
|
</if>
|
|
<if test="publishTime != null">
|
|
publish_time = #{publishTime},
|
|
</if>
|
|
<if test="viewCount != null">
|
|
view_count = #{viewCount},
|
|
</if>
|
|
<if test="likeCount != null">
|
|
like_count = #{likeCount},
|
|
</if>
|
|
<if test="commentCount != null">
|
|
comment_count = #{commentCount},
|
|
</if>
|
|
<if test="sort != null">
|
|
sort = #{sort},
|
|
</if>
|
|
<if test="isPaid != null">
|
|
is_paid = #{isPaid},
|
|
</if>
|
|
<if test="price != null">
|
|
price = #{price},
|
|
</if>
|
|
<if test="requiredPoints != null">
|
|
required_points = #{requiredPoints},
|
|
</if>
|
|
<if test="supportPointsPay != null">
|
|
support_points_pay = #{supportPointsPay},
|
|
</if>
|
|
<if test="isOfficial != null">
|
|
is_official = #{isOfficial},
|
|
</if>
|
|
<if test="shareCount != null">
|
|
share_count = #{shareCount},
|
|
</if>
|
|
<if test="fileUrl != null">
|
|
file_url = #{fileUrl},
|
|
</if>
|
|
<if test="icon != null">
|
|
icon = #{icon},
|
|
</if>
|
|
<if test="background != null">
|
|
background = #{background},
|
|
</if>
|
|
<if test="origin != null">
|
|
origin = #{origin},
|
|
</if>
|
|
<if test="tags != null">
|
|
tags = #{tags},
|
|
</if>
|
|
<if test="updateTime != null">
|
|
update_time = #{updateTime},
|
|
</if>
|
|
<if test="updateBy != null">
|
|
update_by = #{updateBy},
|
|
</if>
|
|
</set>
|
|
where content_id = #{contentId}
|
|
</update>
|
|
|
|
<!--更新审核状态-->
|
|
<update id="updateAuditStatus">
|
|
update cms_content
|
|
set audit_status = #{auditStatus},
|
|
reviewer_id = #{reviewerId},
|
|
reviewer_name = #{reviewerName},
|
|
audit_comment = #{auditComment},
|
|
update_by = #{updateBy},
|
|
update_time = now()
|
|
where content_id = #{contentId}
|
|
</update>
|
|
|
|
<!--更新发布状态-->
|
|
<update id="updatePublishStatus">
|
|
update cms_content
|
|
set publish_status = #{publishStatus},
|
|
publish_time = #{publishTime},
|
|
update_by = #{updateBy},
|
|
update_time = now()
|
|
where content_id = #{contentId}
|
|
</update>
|
|
|
|
<!--通过主键逻辑删除-->
|
|
<update id="logicDeleteById">
|
|
update cms_content
|
|
set delete_flag = 1, update_by = #{updateBy}, update_time = now()
|
|
where content_id = #{contentId}
|
|
</update>
|
|
|
|
<!--通过主键物理删除-->
|
|
<delete id="deleteById">
|
|
delete from cms_content where content_id = #{contentId}
|
|
</delete>
|
|
|
|
<!--增加阅读量-->
|
|
<update id="increaseViewCount">
|
|
update cms_content
|
|
set view_count = view_count + 1
|
|
where content_id = #{contentId}
|
|
</update>
|
|
|
|
<!--查询用户最近创建的内容ID列表-->
|
|
<select id="queryRecentCreatedByUserId" resultType="Long">
|
|
select content_id from cms_content
|
|
where author_id = #{userId} and delete_flag = 0
|
|
order by create_time desc
|
|
limit #{limit}
|
|
</select>
|
|
|
|
<!--获取用户历史查看的内容列表-->
|
|
<select id="getPageListByUserHistory" resultMap="CmsContentMap">
|
|
select
|
|
c.content_id, c.title, c.subtitle, c.content_type, c.summary, c.description, c.requirement, c.introduce, c.content, c.cover_image, c.author_id, c.author_name,
|
|
c.reviewer_id, c.reviewer_name, c.audit_status, c.audit_comment, c.publish_status, c.publish_time,
|
|
c.view_count, c.like_count, c.comment_count, c.sort, c.is_paid, c.price, c.required_points, c.support_points_pay, c.is_official, c.share_count, c.file_url, c.icon, c.background, c.origin, c.tags, c.create_time, c.update_time, c.create_by, c.update_by, c.delete_flag
|
|
from cms_content c
|
|
inner join cms_content_view cv on c.content_id = cv.content_id
|
|
where cv.user_id = #{userId} and c.delete_flag = 0
|
|
order by cv.view_time desc
|
|
limit #{offset}, #{limit}
|
|
</select>
|
|
|
|
<!--获取用户历史查看的内容总数-->
|
|
<select id="getPageListByUserHistoryCount" resultType="int">
|
|
select count(distinct c.content_id)
|
|
from cms_content c
|
|
inner join cms_content_view cv on c.content_id = cv.content_id
|
|
where cv.user_id = #{userId} and c.delete_flag = 0
|
|
</select>
|
|
|
|
<!--获取用户收藏的内容列表-->
|
|
<select id="getPageListByUserFavorites" resultMap="CmsContentMap">
|
|
select
|
|
c.content_id, c.title, c.subtitle, c.content_type, c.summary, c.description, c.requirement, c.introduce, c.content, c.cover_image, c.author_id, c.author_name,
|
|
c.reviewer_id, c.reviewer_name, c.audit_status, c.audit_comment, c.publish_status, c.publish_time,
|
|
c.view_count, c.like_count, c.comment_count, c.sort, c.is_paid, c.price, c.required_points, c.support_points_pay, c.is_official, c.share_count, c.file_url, c.icon, c.background, c.origin, c.tags, c.create_time, c.update_time, c.create_by, c.update_by, c.delete_flag
|
|
from cms_content c
|
|
inner join cms_content_like cl on c.content_id = cl.content_id
|
|
where cl.user_id = #{userId} and c.delete_flag = 0
|
|
order by cl.like_time desc
|
|
limit #{offset}, #{limit}
|
|
</select>
|
|
|
|
<!--获取用户收藏的内容总数-->
|
|
<select id="getPageListByUserFavoritesCount" resultType="int">
|
|
select count(distinct c.content_id)
|
|
from cms_content c
|
|
inner join cms_content_like cl on c.content_id = cl.content_id
|
|
where cl.user_id = #{userId} and c.delete_flag = 0
|
|
</select>
|
|
|
|
<!--获取用户购买的内容列表-->
|
|
<select id="getPageListByUserPurchases" resultMap="CmsContentMap">
|
|
select
|
|
c.content_id, c.title, c.subtitle, c.content_type, c.summary, c.description, c.requirement, c.introduce, c.content, c.cover_image, c.author_id, c.author_name,
|
|
c.reviewer_id, c.reviewer_name, c.audit_status, c.audit_comment, c.publish_status, c.publish_time,
|
|
c.view_count, c.like_count, c.comment_count, c.sort, c.is_paid, c.price, c.required_points, c.support_points_pay, c.is_official, c.share_count, c.file_url, c.icon, c.background, c.origin, c.tags, c.create_time, c.update_time, c.create_by, c.update_by, c.delete_flag
|
|
from cms_content c
|
|
inner join content_purchase cp on c.content_id = cp.content_id
|
|
where cp.user_id = #{userId} and cp.status = 1 and c.delete_flag = 0
|
|
order by cp.purchase_time desc
|
|
limit #{offset}, #{limit}
|
|
</select>
|
|
|
|
<!--获取用户购买的内容总数-->
|
|
<select id="getPageListByUserPurchasesCount" resultType="int">
|
|
select count(distinct c.content_id)
|
|
from cms_content c
|
|
inner join content_purchase cp on c.content_id = cp.content_id
|
|
where cp.user_id = #{userId} and cp.status = 1 and c.delete_flag = 0
|
|
</select>
|
|
|
|
<!--获取用户创建的内容列表-->
|
|
<select id="getPageListByUserCreated" resultMap="CmsContentMap">
|
|
select
|
|
content_id, title, subtitle, content_type, summary, description, requirement, introduce, content, cover_image, author_id, author_name,
|
|
reviewer_id, reviewer_name, audit_status, audit_comment, publish_status, publish_time,
|
|
view_count, like_count, comment_count, sort, is_paid, price, required_points, support_points_pay, is_official, share_count, file_url, icon, background, origin, tags, create_time, update_time, create_by, update_by, delete_flag
|
|
from cms_content
|
|
where author_id = #{userId} and delete_flag = 0
|
|
<if test="publishStatus != null">
|
|
and publish_status = #{publishStatus}
|
|
</if>
|
|
order by create_time desc
|
|
limit #{offset}, #{limit}
|
|
</select>
|
|
|
|
<!--获取用户创建的内容总数-->
|
|
<select id="getPageListByUserCreatedCount" resultType="int">
|
|
select count(*)
|
|
from cms_content
|
|
where author_id = #{userId} and delete_flag = 0
|
|
<if test="publishStatus != null">
|
|
and publish_status = #{publishStatus}
|
|
</if>
|
|
</select>
|
|
|
|
</mapper>
|