Forráskód Böngészése

更新文章点击数aop

zhongyh 5 éve
szülő
commit
e9aeeeca17

+ 42 - 36
src/main/java/net/mingsoft/cms/action/web/ContentAction.java

@@ -1,46 +1,32 @@
 package net.mingsoft.cms.action.web;
 
-import java.util.List;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import com.alibaba.fastjson.JSON;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import net.mingsoft.base.entity.BaseEntity;
 import net.mingsoft.base.entity.ResultData;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.validation.BindingResult;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.springframework.ui.ModelMap;
+import net.mingsoft.basic.bean.EUListBean;
+import net.mingsoft.basic.util.BasicUtil;
+import net.mingsoft.basic.util.StringUtil;
+import net.mingsoft.cms.biz.IContentBiz;
+import net.mingsoft.cms.entity.ContentEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.ui.ModelMap;
+import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
-
-import net.mingsoft.cms.biz.IContentBiz;
-import net.mingsoft.cms.entity.ContentEntity;
-import net.mingsoft.base.util.JSONObject;
-import net.mingsoft.base.entity.BaseEntity;
-import net.mingsoft.basic.util.BasicUtil;
-import net.mingsoft.basic.util.StringUtil;
-import net.mingsoft.base.filter.DateValueFilter;
-import net.mingsoft.base.filter.DoubleValueFilter;
-import net.mingsoft.basic.bean.EUListBean;
-import net.mingsoft.basic.annotation.LogAnn;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
 import springfox.documentation.annotations.ApiIgnore;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 /**
  * 文章管理控制层
  * @author 铭飞开发团队
@@ -186,7 +172,7 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
 	}
 	
 	/**
-	 * @param content 文章实体
+	 * @param contents 文章实体
 	 */
 	@ApiOperation(value = "批量删除文章列表接口")
 	@PostMapping("/delete")
@@ -255,6 +241,26 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
 		return ResultData.build().success(content);
 	}
 
+	@ApiOperation(value = "查看文章点击数")
+	@ApiImplicitParam(name = "contentId", value = "文章编号", required = true,paramType="path")
+	@GetMapping(value = "/{contentId}/hit")
+	@ResponseBody
+	public void hit(@PathVariable @ApiIgnore int contentId, HttpServletRequest request, HttpServletResponse response){
+	 	if(contentId<=0){
+			this.outString(response, "document.write(0)");
+			return;
+		}
+		ContentEntity content = (ContentEntity)contentBiz.getEntity(contentId);
+	 	if(content == null){
+			this.outString(response, "document.write(0)");
+			return;
+		}
+		if(content.getAppId() == null || content.getAppId() != BasicUtil.getAppId()){
+			this.outString(response, "document.write(0)");
+			return;
+		}
+		this.outString(response, "document.write(" + content.getContentHit() + ")");
+		return;
+	}
 
-		
 }

+ 81 - 0
src/main/java/net/mingsoft/cms/aop/CotentAop.java

@@ -0,0 +1,81 @@
+package net.mingsoft.cms.aop;
+
+import net.mingsoft.basic.aop.BaseAop;
+import net.mingsoft.basic.util.BasicUtil;
+import net.mingsoft.cms.biz.IContentBiz;
+import net.mingsoft.cms.biz.IHistoryLogBiz;
+import net.mingsoft.cms.entity.ContentEntity;
+import net.mingsoft.cms.entity.HistoryLogEntity;
+import org.apache.commons.lang3.StringUtils;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author 铭飞开源团队
+ * @date 2019/12/23
+ */
+@Component
+@Aspect
+public class CotentAop extends BaseAop {
+
+    /**
+     * 注入文章业务
+     */
+    @Autowired
+    private IContentBiz contentBiz;
+
+    /**
+     * 注入浏览记录业务
+     */
+    @Autowired
+    private IHistoryLogBiz historyLogBiz;
+
+    /**
+     * 文章浏览记录,
+     * 如果该文章该ip已经记录过,则不在重复记录
+     * @param pjp
+     * @return
+     * @throws Throwable
+     */
+    @Around("execution(* net.mingsoft.cms.action.web.ContentAction.get(..))")
+    public Object get(ProceedingJoinPoint pjp) throws Throwable{
+
+//        获取方法参数
+        ContentEntity content = getType(pjp, ContentEntity.class);
+//        如果id为空则直接发行
+        if(content.getId()==null) {
+            return pjp.proceed();
+        }
+        content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
+        //如果文章不存在则直接发行
+        if(content == null){
+            return pjp.proceed();
+        }
+
+        //查询判断该ip是否已经有浏览记录了
+        HistoryLogEntity historyLog = new HistoryLogEntity();
+        historyLog.setContentId(content.getId());
+        historyLog.setHlIp(BasicUtil.getIp());
+        historyLog.setHlIsMobile(BasicUtil.isMobileDevice());
+        HistoryLogEntity _historyLog = (HistoryLogEntity)historyLogBiz.getEntity(historyLog);
+        //如果该ip该文章没有浏览记录则保存浏览记录
+        //并且更新点击数
+        if(_historyLog == null || StringUtils.isBlank(_historyLog.getId())){
+            historyLogBiz.saveEntity(historyLog);
+            //更新点击数
+            ContentEntity updateContent = new ContentEntity();
+            updateContent.setId(content.getId());
+            if(content.getContentHit() == null){
+                updateContent.setContentHit(1);
+            }else{
+                updateContent.setContentHit(content.getContentHit()+1);
+            }
+            contentBiz.updateEntity(updateContent);
+        }
+
+        return pjp.proceed();
+    }
+}

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
src/main/webapp/static/plugins/vue-ueditor-wrap/vue-ueditor-wrap.min.js


Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott