ftebox пре 3 година
родитељ
комит
0c45c41dc7

+ 36 - 0
src/main/java/cn/ftebox/dao/CommentDao.java

@@ -0,0 +1,36 @@
+package cn.ftebox.dao;
+
+import cn.ftebox.entity.Comment;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 评论信息
+ */
+public interface CommentDao {
+    /**
+     * 添加一条评论
+     */
+    public int add(Comment comment);
+
+    /**
+     * 更新一条评论
+     */
+    public int update(Comment comment);
+
+    /**
+     * 评论查询
+     */
+    public List<Comment> list(Map<String, Object> map);
+
+    /**
+     * 评论数量
+     */
+    public Long getTotal(Map<String, Object> map);
+
+    /**
+     * 删除评论
+     */
+    public Integer delete(Integer id);
+}

+ 74 - 0
src/main/java/cn/ftebox/entity/Comment.java

@@ -0,0 +1,74 @@
+package cn.ftebox.entity;
+
+
+import java.util.Date;
+
+public class Comment {
+
+  /** 主键 */
+  private Integer id;
+
+  /** 用户ip */
+  private String userIp;
+
+  /** 博客id */
+  private Blog blog;
+
+  /** 内容 */
+  private String content;
+
+  /** 评论时间 */
+  private Date commentDate;
+
+  /** 审核状态 */
+  private Integer state;
+
+
+  public Integer getId() {
+    return id;
+  }
+
+  public void setId(Integer id) {
+    this.id = id;
+  }
+
+  public String getUserIp() {
+    return userIp;
+  }
+
+  public void setUserIp(String userIp) {
+    this.userIp = userIp;
+  }
+
+  public String getContent() {
+    return content;
+  }
+
+  public void setContent(String content) {
+    this.content = content;
+  }
+
+  public Integer getState() {
+    return state;
+  }
+
+  public void setState(Integer state) {
+    this.state = state;
+  }
+
+  public Blog getBlog() {
+    return blog;
+  }
+
+  public void setBlog(Blog blog) {
+    this.blog = blog;
+  }
+
+  public Date getCommentDate() {
+    return commentDate;
+  }
+
+  public void setCommentDate(Date commentDate) {
+    this.commentDate = commentDate;
+  }
+}

+ 33 - 0
src/main/java/cn/ftebox/service/CommentService.java

@@ -0,0 +1,33 @@
+package cn.ftebox.service;
+
+import cn.ftebox.entity.Comment;
+
+import java.util.List;
+import java.util.Map;
+
+public interface CommentService {
+    /**
+     * 添加一条评论
+     */
+    public int add(Comment comment);
+
+    /**
+     * 更新一条评论
+     */
+    public int update(Comment comment);
+
+    /**
+     * 评论查询
+     */
+    public List<Comment> list(Map<String, Object> map);
+
+    /**
+     * 评论数量
+     */
+    public Long getTotal(Map<String, Object> map);
+
+    /**
+     * 删除评论
+     */
+    public Integer delete(Integer id);
+}

+ 34 - 0
src/main/java/cn/ftebox/service/impl/CommentServiceImpl.java

@@ -0,0 +1,34 @@
+package cn.ftebox.service.impl;
+
+import cn.ftebox.entity.Comment;
+import cn.ftebox.service.CommentService;
+
+import java.util.List;
+import java.util.Map;
+
+public class CommentServiceImpl implements CommentService {
+    @Override
+    public int add(Comment comment) {
+        return 0;
+    }
+
+    @Override
+    public int update(Comment comment) {
+        return 0;
+    }
+
+    @Override
+    public List<Comment> list(Map<String, Object> map) {
+        return null;
+    }
+
+    @Override
+    public Long getTotal(Map<String, Object> map) {
+        return null;
+    }
+
+    @Override
+    public Integer delete(Integer id) {
+        return null;
+    }
+}

+ 110 - 0
src/main/resources/cn/ftebox/mappers/CommentMapper.xml

@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.ftebox.dao.CommentDao">
+    <resultMap id="CommentResult" type="Comment">
+        <result property="id" column="id"/>
+        <result property="userIp" column="userIp"/>
+        <result property="summary" column="summary"/>
+        <result property="releaseDate" column="releaseDate"/>
+        <result property="clickHit" column="clickHit"/>
+        <result property="replyHit" column="replyHit"/>
+        <result property="content" column="content"/>
+        <result property="keyWord" column="keyWord"/>
+        <association property="blogType" column="typeId" select="cn.ftebox.dao.BlogTypeDao.findById"/>
+    </resultMap>
+
+    <select id="countList" resultMap="BlogResult">
+        select date_format(releaseDate, '%Y年%m月') as releaseDataStr, count(*) as blogCount
+        from t_blog
+        group by date_format(releaseDate, '%Y年%m月')
+        order by date_format(releaseDate, '%Y年%m月') desc
+    </select>
+
+    <select id="list" parameterType="Map" resultMap="BlogResult">
+        select * from t_blog
+        <where>
+            <if test="title!=null and title!=''">
+                and title like #{title}
+            </if>
+            <if test="typeId!=null and typeId!=''">
+                and typeId = #{typeId}
+            </if>
+            <if test="releaseDateStr!=null and releaseDateStr!=''">
+                and date_fromat(releaseDate,'%Y年%m月')=#{releaseDateStr}
+            </if>
+        </where>
+        order by releaseDate desc
+        <if test="start!=null and size!=null">
+            limit #{start},#{size}
+        </if>
+    </select>
+
+    <select id="getTotal" parameterType="Map" resultType="long">
+        select count(*)
+        from t_blog
+        <where>
+            <if test="title!=null and title!=''">
+                and title like #{title}
+            </if>
+            <if test="typeId!=null and typeId!=''">
+                and typeId = #{typeId}
+            </if>
+            <if test="releaseDateStr!=null and releaseDateStr!=''">
+                and date_fromat(releaseDate,'%Y年%m月')=#{releaseDateStr}
+            </if>
+        </where>
+    </select>
+
+    <select id="findById" parameterType="Integer" resultMap="BlogResult">
+        select *
+        from t_blog
+        where id = #{id}
+    </select>
+
+    <insert id="add" useGeneratedKeys="true" keyProperty="id" parameterType="Blog">
+        insert into t_blog
+        values (null, #{title}, #{summary}, now(), 0, 0, #{content}, #{blogType.id}, #{keyWord})
+    </insert>
+
+    <update id="update" parameterType="Blog">
+        update t_blog
+        <set>
+            <if test="title!=null and title!=''">
+                title=#{title},
+            </if>
+            <if test="summary!=null and summary!=''">
+                summary=#{summary},
+            </if>
+            <if test="content!=null and content!=''">
+                content=#{content},
+            </if>
+            <if test="blogType.id!=null">
+                typeId=#{blogType.id},
+            </if>
+            <if test="clickHit!=null">
+                clickHit=#{clickHit},
+            </if>
+            <if test="replyHit!=null">
+                replyHit=#{replyHit},
+            </if>
+            <if test="keyWord!=null and keyWord!=''">
+                keyWord=#{keyWord},
+            </if>
+        </set>
+        where id=#{id}
+    </update>
+
+    <delete id="delete" parameterType="Integer">
+        delete
+        from t_blog
+        where id = #{id}
+    </delete>
+
+    <select id="getBlogByTypeId" parameterType="Integer" resultType="Integer">
+        select count(*)
+        from t_blog
+        where typeId = #{typeId}
+    </select>
+</mapper>