|
@@ -7,12 +7,19 @@ import com.caimei.www.pojo.page.BaseLink;
|
|
|
import com.caimei.www.pojo.page.ImageLink;
|
|
|
import com.caimei.www.service.page.ArticleService;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
+import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
+import org.thymeleaf.util.StringUtils;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -21,6 +28,7 @@ import java.util.List;
|
|
|
* @author : Charles
|
|
|
* @date : 2020/7/31
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Controller
|
|
|
public class ArticleController extends BaseController {
|
|
|
|
|
@@ -93,13 +101,35 @@ public class ArticleController extends BaseController {
|
|
|
* 文章详情【旧】
|
|
|
*/
|
|
|
@GetMapping("/info/detail-{id}-1.html")
|
|
|
- public String toArticleDetail(@PathVariable("id") Integer id, final Model model) {
|
|
|
+ public String toArticleDetail(@PathVariable("id") Integer id, final Model model, ServerWebExchange serverWebExchange, ServerHttpResponse response) {
|
|
|
List<BaseLink> typeList = articleService.getArticleTypes();
|
|
|
Article article = articleService.getArticleInfo(id);
|
|
|
if(article == null){
|
|
|
// return super.errorPath();
|
|
|
return "redirect:/info/404.html";
|
|
|
}
|
|
|
+ // 获取referer 判断访问来源
|
|
|
+ ServerHttpRequest request = serverWebExchange.getRequest();
|
|
|
+ String ip = "";
|
|
|
+ String referer = "";
|
|
|
+ String source = "";
|
|
|
+ HttpHeaders headers = request.getHeaders();
|
|
|
+ ip = String.valueOf(headers.get("x-forwarded-for"));
|
|
|
+ if (StringUtils.isEmpty(ip)) {
|
|
|
+ ip = String.valueOf(headers.get("X-Real-IP"));
|
|
|
+ }
|
|
|
+ if (null != ip && "" != ip) {
|
|
|
+ ip = ip.replaceAll("[^\\d.]", "");
|
|
|
+ }
|
|
|
+ List<String> referer1 = headers.get("Referer");
|
|
|
+ if (referer1 != null) {
|
|
|
+ referer = referer1.get(0);
|
|
|
+ }
|
|
|
+ source = source(referer);
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String format = dateFormat.format(new Date());
|
|
|
+ articleService.insertRecord(ip,referer,source,format);
|
|
|
+ log.info("文章详情访问来源记录完成========》"+source);
|
|
|
List<BaseLink> data = articleService.getArticleLabels().getData();
|
|
|
List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
|
|
|
List<Article> articles=articleService.getInfoById(id);
|
|
@@ -201,4 +231,34 @@ public class ArticleController extends BaseController {
|
|
|
return articleService.articlePv(id);
|
|
|
}
|
|
|
|
|
|
+ private String source(String link) {
|
|
|
+ if (link.contains("www.baidu.com")) {
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+ if (link.contains("www.so.com")) {
|
|
|
+ return "2";
|
|
|
+ }
|
|
|
+ if (link.contains("www.google.cn")) {
|
|
|
+ return "3";
|
|
|
+ }
|
|
|
+ if (link.contains("m.sm.cn")) {
|
|
|
+ return "4";
|
|
|
+ }
|
|
|
+ if (link.contains("toutiao.com")) {
|
|
|
+ return "5";
|
|
|
+ }
|
|
|
+ if (link.contains("www.sogou.com")) {
|
|
|
+ return "6";
|
|
|
+ }
|
|
|
+ if (link.contains("servicewechat.com")) {
|
|
|
+ return "7";
|
|
|
+ }
|
|
|
+ if (link.contains("www.caimei365.com")) {
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ if (link.contains("zzjtest.gz.aeert.com")) {
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|