Quellcode durchsuchen

添加点击量

luobo vor 3 Jahren
Ursprung
Commit
181df2dac2

+ 13 - 0
smart-system/src/main/java/com/huijy/management/domain/Content.java

@@ -88,6 +88,10 @@ public class Content extends BaseEntity
     @Excel(name = "终核信息")
     private String endAuditMsg;
 
+    /** 点击量 */
+    @Excel(name = "点击量")
+    private Integer browseNum;
+
     public void setContentId(Long contentId)
     {
         this.contentId = contentId;
@@ -251,6 +255,14 @@ public class Content extends BaseEntity
         return endAuditMsg;
     }
 
+    public Integer getBrowseNum() {
+        return browseNum;
+    }
+
+    public void setBrowseNum(Integer browseNum) {
+        this.browseNum = browseNum;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -273,6 +285,7 @@ public class Content extends BaseEntity
             .append("endAuditAt", getEndAuditAt())
             .append("endAuditTime", getEndAuditTime())
             .append("endAuditMsg", getEndAuditMsg())
+            .append("browseNum", getBrowseNum())
             .toString();
     }
 }

+ 15 - 8
smart-system/src/main/java/com/huijy/management/mapper/ContentMapper.java

@@ -5,15 +5,15 @@ import com.huijy.management.domain.Content;
 
 /**
  * 内容管理Mapper接口
- * 
+ *
  * @author luobo
  * @date 2021-09-12
  */
-public interface ContentMapper 
+public interface ContentMapper
 {
     /**
      * 查询内容管理
-     * 
+     *
      * @param contentId 内容管理主键
      * @return 内容管理
      */
@@ -21,7 +21,7 @@ public interface ContentMapper
 
     /**
      * 查询内容管理列表
-     * 
+     *
      * @param content 内容管理
      * @return 内容管理集合
      */
@@ -29,7 +29,7 @@ public interface ContentMapper
 
     /**
      * 新增内容管理
-     * 
+     *
      * @param content 内容管理
      * @return 结果
      */
@@ -37,7 +37,7 @@ public interface ContentMapper
 
     /**
      * 修改内容管理
-     * 
+     *
      * @param content 内容管理
      * @return 结果
      */
@@ -45,7 +45,7 @@ public interface ContentMapper
 
     /**
      * 删除内容管理
-     * 
+     *
      * @param contentId 内容管理主键
      * @return 结果
      */
@@ -53,9 +53,16 @@ public interface ContentMapper
 
     /**
      * 批量删除内容管理
-     * 
+     *
      * @param contentIds 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteContentByContentIds(Long[] contentIds);
+
+    /**
+     * 更新点击量
+     * @param contentId
+     * @return
+     */
+    public Integer updateBrowseNumById(Long contentId);
 }

+ 7 - 1
smart-system/src/main/java/com/huijy/management/service/impl/ContentServiceImpl.java

@@ -32,7 +32,12 @@ public class ContentServiceImpl implements IContentService
     @Override
     public Content selectContentByContentId(Long contentId)
     {
-        return contentMapper.selectContentByContentId(contentId);
+        Content content = contentMapper.selectContentByContentId(contentId);
+        /**
+         * 最调用一次,就加一
+         */
+        contentMapper.updateBrowseNumById(contentId);
+        return content;
     }
 
     /**
@@ -59,6 +64,7 @@ public class ContentServiceImpl implements IContentService
         content.setCreateTime(DateUtils.getNowDate());
         content.setAuditFlag("0");
         content.setReleaseFlag("0");
+        content.setBrowseNum(0);
         return contentMapper.insertContent(content);
     }
 

+ 10 - 2
smart-system/src/main/resources/mapper/management/ContentMapper.xml

@@ -24,14 +24,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="endAuditAt"    column="end_audit_at"    />
         <result property="endAuditTime"    column="end_audit_time"    />
         <result property="endAuditMsg"    column="end_audit_msg"    />
+        <result property="browseNum"    column="browse_num"    />
     </resultMap>
 
     <sql id="selectContentVo">
-        select content_id, service_info, title, author, show_pictures, brief_content, content, create_time, create_at, audit_flag, audit_at, audit_time, audit_msg, release_flag, release_time, release_at, end_audit_at, end_audit_time, end_audit_msg from t_content
+        select content_id, service_info, title, author, show_pictures, brief_content, content, create_time, create_at, audit_flag, audit_at, audit_time, audit_msg, release_flag, release_time, release_at, end_audit_at, end_audit_time, end_audit_msg,browse_num from t_content
     </sql>
 
     <sql id="selectListContentVo">
-        select content_id, service_info, title, author, show_pictures, brief_content,create_time, create_at, audit_flag, audit_at, audit_time, audit_msg, release_flag, release_time, release_at, end_audit_at, end_audit_time, end_audit_msg from t_content
+        select content_id, service_info, title, author, show_pictures, brief_content,create_time, create_at, audit_flag, audit_at, audit_time, audit_msg, release_flag, release_time, release_at, end_audit_at, end_audit_time, end_audit_msg,browse_num from t_content
     </sql>
 
     <select id="selectContentList" parameterType="Content" resultMap="ContentResult">
@@ -69,6 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="endAuditAt != null">end_audit_at,</if>
             <if test="endAuditTime != null">end_audit_time,</if>
             <if test="endAuditMsg != null">end_audit_msg,</if>
+            <if test="browseNum != null">browse_num,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="serviceInfo != null">#{serviceInfo},</if>
@@ -89,6 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="endAuditAt != null">#{endAuditAt},</if>
             <if test="endAuditTime != null">#{endAuditTime},</if>
             <if test="endAuditMsg != null">#{endAuditMsg},</if>
+            <if test="browseNum != null">#{browseNum},</if>
          </trim>
     </insert>
 
@@ -113,6 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="endAuditAt != null">end_audit_at = #{endAuditAt},</if>
             <if test="endAuditTime != null">end_audit_time = #{endAuditTime},</if>
             <if test="endAuditMsg != null">end_audit_msg = #{endAuditMsg},</if>
+            <if test="browseNum != null">browse_num = #{browseNum},</if>
         </trim>
         where content_id = #{contentId}
     </update>
@@ -127,4 +131,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{contentId}
         </foreach>
     </delete>
+
+    <update id="updateBrowseNumById" parameterType="Long">
+        update t_content t set t.browse_num = t.browse_num+1 where t.content_id = #{contentId}
+    </update>
 </mapper>

+ 9 - 0
smart-ui/src/views/management/content/index.vue

@@ -180,6 +180,12 @@
         prop="releaseFlag"
         :formatter="releaseFlagFormat"
       />
+      <el-table-column
+        label="点击量"
+        align="center"
+        prop="browseNum"
+        width="100"
+      />
       <!-- <el-table-column label="发布人" align="center" prop="releaseAt" /> -->
       <!-- <el-table-column label="发布人" align="center" prop="releaseAt" /> -->
       <!-- <el-table-column label="终核信息" align="center" prop="endAuditMsg" /> -->
@@ -295,6 +301,9 @@
         <el-form-item label="作者" prop="author">
           <el-input v-model="form.author" placeholder="请输入作者" />
         </el-form-item>
+        <el-form-item label="点击量" prop="browseNum">
+          <el-input-number v-model="form.browseNum" :min="0" :step="10" placeholder="请输入点击量" />
+        </el-form-item>
         <el-form-item label="展示图片">
           <imageUpload v-model="form.showPictures" />
         </el-form-item>