|
|
<?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.chenhai.vet.mapper.VetExperienceArticleMapper">
<resultMap type="VetExperienceArticle" id="VetExperienceArticleResult"> <result property="id" column="id"/> <result property="title" column="title"/> <result property="content" column="content"/> <result property="summary" column="summary"/> <result property="coverImage" column="cover_image"/> <result property="images" column="images"/> <result property="userId" column="user_id"/> <result property="vetName" column="vet_name"/> <result property="vetAvatar" column="vet_avatar"/> <result property="vetTitle" column="vet_title"/> <result property="categoryId" column="category_id"/> <result property="categoryName" column="category_name"/> <result property="tags" column="tags"/> <result property="viewCount" column="view_count"/> <result property="likeCount" column="like_count"/> <result property="collectCount" column="collect_count"/> <result property="isTop" column="is_top"/> <result property="isFeatured" column="is_featured"/> <result property="status" column="status"/> <result property="isSensitive" column="is_sensitive"/> <result property="sensitiveWords" column="sensitive_words"/> <result property="publishTime" column="publish_time"/> <result property="createTime" column="create_time"/> <result property="updateTime" column="update_time"/> <result property="userRole" column="user_role"/> <result property="userType" column="user_type"/> </resultMap>
<!-- 修改基础查询语句,始终从用户表获取用户信息 --> <sql id="selectVetExperienceArticleVo"> select a.id, a.title, a.content, <!-- 富文本内容 --> a.summary, a.cover_image, a.images, a.user_id, <!-- 始终从用户表获取用户信息 --> COALESCE(u.nick_name, u.user_name) as vet_name, <!-- 用户姓名 --> u.avatar as vet_avatar, <!-- 用户头像 --> a.vet_title, a.category_id, a.category_name, a.tags, a.view_count, a.like_count, a.collect_count, a.is_top, a.is_featured, a.status, a.is_sensitive, a.sensitive_words, a.publish_time, a.create_time, a.update_time, a.user_role, a.user_type from vet_experience_article a left join sys_user u on a.user_id = u.user_id </sql>
<!-- 查询兽医经验文章 --> <select id="selectVetExperienceArticleById" parameterType="Long" resultMap="VetExperienceArticleResult"> <include refid="selectVetExperienceArticleVo"/> where a.id = #{id} <!-- 添加表别名 a. --> </select>
<!-- 查询兽医经验文章列表(已包含关联用户表) --> <select id="selectVetExperienceArticleList" parameterType="VetExperienceArticle" resultMap="VetExperienceArticleResult"> <include refid="selectVetExperienceArticleVo"/> <where> <if test="title != null and title != ''"> and a.title like concat('%', #{title}, '%')</if> <if test="userId != null"> and a.user_id = #{userId}</if> <if test="vetName != null and vetName != ''"> and (a.vet_name like concat('%', #{vetName}, '%') or u.nick_name like concat('%', #{vetName}, '%'))</if> <if test="categoryId != null"> and a.category_id = #{categoryId}</if> <if test="categoryName != null and categoryName != ''"> and a.category_name like concat('%', #{categoryName}, '%')</if> <if test="status != null and status != ''"> and a.status = #{status}</if> <if test="isTop != null and isTop != ''"> and a.is_top = #{isTop}</if> <if test="isFeatured != null and isFeatured != ''"> and a.is_featured = #{isFeatured}</if> <if test="isSensitive != null and isSensitive != ''"> and a.is_sensitive = #{isSensitive}</if> <if test="tags != null and tags != ''"> and ( a.tags = #{tags} or a.tags like concat(#{tags}, ',%') or a.tags like concat('%,', #{tags}, ',%') or a.tags like concat('%,', #{tags}) ) </if> <if test="searchKey != null and searchKey != ''"> <bind name="searchKeyLike" value="'%' + searchKey + '%'" /> and ( a.title like #{searchKeyLike} or a.content like #{searchKeyLike} or a.summary like #{searchKeyLike} or a.tags like #{searchKeyLike} or a.category_name like #{searchKeyLike} or a.vet_name like #{searchKeyLike} or u.nick_name like #{searchKeyLike} ) </if> <if test="viewCount != null and viewCount != ''"> and a.view_count = #{viewCount}</if> </where> order by a.publish_time desc </select> <!-- 根据条件查询文章列表(论坛专用) --> <select id="selectArticlesByCondition" parameterType="map" resultMap="VetExperienceArticleResult"> <include refid="selectVetExperienceArticleVo"/> <where> a.status = #{status} <if test="keyword != null and keyword != ''"> and ( a.title like concat('%', #{keyword}, '%') or a.content like concat('%', #{keyword}, '%') or a.summary like concat('%', #{keyword}, '%') or a.tags like concat('%', #{keyword}, '%') ) </if> <if test="userId != null"> and a.user_id = #{userId}</if> <if test="categoryId != null"> and a.category_id = #{categoryId}</if> <if test="excludeId != null"> and a.id != #{excludeId}</if> </where> <!-- ORDER BY必须在WHERE子句之后,LIMIT之前 --> <choose> <when test="orderBy != null and orderType != null"> order by a.${orderBy} ${orderType} </when> <otherwise> order by a.publish_time desc </otherwise> </choose> <!-- LIMIT必须在ORDER BY之后 --><!-- <if test="limit != null and limit > 0">--><!-- limit #{limit}--><!-- </if>--> </select>
<!-- 搜索文章 --> <select id="searchArticles" resultMap="VetExperienceArticleResult"> <include refid="selectVetExperienceArticleVo"/> where a.status = #{status} and (a.title like concat('%', #{keyword}, '%') or a.content like concat('%', #{keyword}, '%') or a.summary like concat('%', #{keyword}, '%')) order by a.publish_time desc </select>
<!-- <!– 增加浏览数 –>
<update id="incrementViewCount" parameterType="Long"> update vet_experience_article set view_count = ifnull(view_count, 0) + 1, update_time = now() where id = #{id} </update>-->
<!-- 增加点赞数 --> <update id="incrementLikeCount" parameterType="Long"> update vet_experience_article set like_count = ifnull(like_count, 0) + 1, update_time = now() where id = #{id} </update>
<!-- 增加收藏数 --> <update id="incrementCollectCount" parameterType="Long"> update vet_experience_article set collect_count = ifnull(collect_count, 0) + 1, update_time = now() where id = #{id} </update>
<!-- 新增兽医经验文章 --> <insert id="insertVetExperienceArticle" parameterType="VetExperienceArticle" useGeneratedKeys="true" keyProperty="id"> insert into vet_experience_article <trim prefix="(" suffix=")" suffixOverrides=","> <if test="title != null and title != ''">title,</if> <if test="content != null and content != ''">content,</if> <if test="summary != null">summary,</if> <if test="coverImage != null">cover_image,</if> <if test="images != null">images,</if> <if test="userId != null">user_id,</if> <if test="vetName != null and vetName != ''">vet_name,</if> <if test="vetAvatar != null">vet_avatar,</if> <if test="vetTitle != null">vet_title,</if> <if test="categoryId != null">category_id,</if> <if test="categoryName != null and categoryName != ''">category_name,</if> <if test="tags != null">tags,</if> <if test="viewCount != null">view_count,</if> <if test="likeCount != null">like_count,</if> <if test="collectCount != null">collect_count,</if> <if test="isTop != null">is_top,</if> <if test="isFeatured != null">is_featured,</if> <if test="status != null and status != ''">status,</if> <if test="isSensitive != null">is_sensitive,</if> <if test="sensitiveWords != null">sensitive_words,</if> <if test="publishTime != null">publish_time,</if> <if test="userRole != null and userRole != ''">user_role,</if> <if test="userType != null and userType != ''">user_type,</if> create_time, <!-- 固定字段放在最后 --> <if test="updateTime != null">update_time,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="title != null and title != ''">#{title},</if> <if test="content != null and content != ''">#{content},</if> <if test="summary != null">#{summary},</if> <if test="coverImage != null">#{coverImage},</if> <if test="images != null">#{images},</if> <if test="userId != null">#{userId},</if> <if test="vetName != null and vetName != ''">#{vetName},</if> <if test="vetAvatar != null">#{vetAvatar},</if> <if test="vetTitle != null">#{vetTitle},</if> <if test="categoryId != null">#{categoryId},</if> <if test="categoryName != null and categoryName != ''">#{categoryName},</if> <if test="tags != null">#{tags},</if> <if test="viewCount != null">#{viewCount},</if> <if test="likeCount != null">#{likeCount},</if> <if test="collectCount != null">#{collectCount},</if> <if test="isTop != null">#{isTop},</if> <if test="isFeatured != null">#{isFeatured},</if> <if test="status != null and status != ''">#{status},</if> <if test="isSensitive != null">#{isSensitive},</if> <if test="sensitiveWords != null">#{sensitiveWords},</if> <if test="publishTime != null">#{publishTime},</if> <if test="userRole != null and userRole != ''">#{userRole},</if> <if test="userType != null and userType != ''">#{userType},</if> now(), <!-- 对应create_time --> <if test="updateTime != null">#{updateTime},</if> </trim> </insert>
<!-- 修改兽医经验文章 --> <update id="updateVetExperienceArticle" parameterType="VetExperienceArticle"> update vet_experience_article <trim prefix="SET" suffixOverrides=","> <if test="title != null and title != ''">title = #{title},</if> <if test="content != null and content != ''">content = #{content},</if> <if test="summary != null">summary = #{summary},</if> <if test="coverImage != null">cover_image = #{coverImage},</if> <if test="images != null">images = #{images},</if> <if test="userId != null">user_id = #{userId},</if> <if test="vetName != null and vetName != ''">vet_name = #{vetName},</if> <if test="vetAvatar != null">vet_avatar = #{vetAvatar},</if> <if test="vetTitle != null">vet_title = #{vetTitle},</if> <if test="categoryId != null">category_id = #{categoryId},</if> <if test="categoryName != null and categoryName != ''">category_name = #{categoryName},</if> <if test="tags != null">tags = #{tags},</if> <if test="viewCount != null">view_count = #{viewCount},</if> <if test="likeCount != null">like_count = #{likeCount},</if> <if test="collectCount != null">collect_count = #{collectCount},</if> <if test="isTop != null">is_top = #{isTop},</if> <if test="isFeatured != null">is_featured = #{isFeatured},</if> <if test="status != null and status != ''">status = #{status},</if> <if test="isSensitive != null">is_sensitive = #{isSensitive},</if> <if test="sensitiveWords != null">sensitive_words = #{sensitiveWords},</if> <if test="publishTime != null">publish_time = #{publishTime},</if> <if test="userRole != null and userRole != ''">user_role = #{userRole},</if> <if test="userType != null and userType != ''">user_type = #{userType},</if> update_time = now(), </trim> where id = #{id} </update> <!-- 删除兽医经验文章 --> <delete id="deleteVetExperienceArticleById" parameterType="Long"> delete from vet_experience_article where id = #{id} </delete>
<!-- 批量删除兽医经验文章 --> <delete id="deleteVetExperienceArticleByIds" parameterType="Long"> delete from vet_experience_article where id in <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach> </delete></mapper>
|