123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- package com.caimei.www.controller.unlimited;
- import com.caimei.www.controller.BaseController;
- import com.caimei.www.pojo.JsonModel;
- import com.caimei.www.pojo.page.*;
- import com.caimei.www.pojo.vo.CmBrandLandingVO;
- import com.caimei.www.service.page.ArticleService;
- import com.caimei.www.service.page.CmBrandLandingService;
- import com.caimei.www.service.page.ProductService;
- import com.caimei.www.utils.PaginationVo;
- import com.github.pagehelper.PageHelper;
- 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.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- * 文章页鉴于seo,保留旧链接
- *
- * @author : Charles
- * @date : 2020/7/31
- */
- @Slf4j
- @Controller
- public class ArticleController extends BaseController {
- /**
- * 错误页面
- */
- private static final String ERROR_PATH = "article/error";
- private static final String ARTICLE_LIST_PATH = "article/list";
- private static final String ARTICLE_DETAIL_PATH = "article/detail";
- private static final String ARTICLE_RECOMMENDATION = "article/recommendation";
- private ArticleService articleService;
- @Autowired
- private CmBrandLandingService cmBrandLandingService;
- @Autowired
- private ProductService productService;
- @Autowired
- public void setArticleService(ArticleService articleService) {
- this.articleService = articleService;
- }
- /**
- * 文章列表【旧center】
- */
- @GetMapping("/info/center-{id}-{pageNum}.html")
- public String toArticleList(@PathVariable("id") Integer id, @PathVariable("pageNum") Integer pageNum, final Model model) {
- List<BaseLink> typeList = articleService.getArticleTypes();
- List<CmBrandLanding> cmBrandLandingList = cmBrandLandingService.getCmBrandLandingList(new CmBrandLanding()
- .setType("5"));
- List<Article> infoSelected = articleService.getArticleSelected(0, 5);
- List<CmProductArchiveFile> archiveFiles = articleService.findArchiveFileAddTime(null,0, 3);
- List<ProductList> productSellNumbers = productService.getProductSellNumbers(null);
- List<BaseLink> data = articleService.getArticleLabels().getData();
- List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
- model.addAttribute("ads", Ads);
- model.addAttribute("labels", data);
- model.addAttribute("articleType", typeList);//导航栏
- model.addAttribute("articleImages", CmBrandLandingVO.setValues(cmBrandLandingList));//导航栏图片
- model.addAttribute("infoSelected", infoSelected);//精选文章
- model.addAttribute("productSellNumbers", productSellNumbers);//销量前三商品
- model.addAttribute("archiveFiles", archiveFiles);//最新美业资料top3
- model.addAttribute("typeId", id);
- model.addAttribute("labelId", 0);
- model.addAttribute("pageNum", pageNum);
- model.addAttribute("isSearch", true);
- model.addAttribute("isSelectInfo", true);
- System.out.println("articleImages" + CmBrandLandingVO.setValues(cmBrandLandingList));
- //model.addAttribute("pagePath", String.format("/info/center-%s-1.html", id));
- return ARTICLE_LIST_PATH;
- }
- /**
- * 文章列表【旧label】
- */
- @GetMapping("/info/label-{id}-{pageNum}.html")
- public String toArticleLabel(@PathVariable("id") Integer id, @PathVariable("pageNum") Integer pageNum, final Model model) {
- List<BaseLink> typeList = articleService.getArticleTypes();
- List<BaseLink> data = articleService.getArticleLabels().getData();
- List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
- List<CmProductArchiveFile> archiveFiles = articleService.findArchiveFileAddTime(null,0, 3);
- List<ProductList> productSellNumbers = productService.getProductSellNumbers(null);
- model.addAttribute("productSellNumbers", productSellNumbers);//销量前三商品
- model.addAttribute("archiveFiles", archiveFiles);//最新美业资料top3
- model.addAttribute("ads", Ads);
- model.addAttribute("labels", data);
- model.addAttribute("articleType", typeList);
- model.addAttribute("typeId", 0);
- model.addAttribute("labelId", id);
- model.addAttribute("pageNum", pageNum);
- model.addAttribute("isSearch", false);
- model.addAttribute("isSelectInfo", true);
- //model.addAttribute("pagePath", String.format("/info/label-%s-1.html", id));
- return ARTICLE_LIST_PATH;
- }
- /**
- * 精选文章和美业资料列表
- */
- @GetMapping("/info/articlerecommendation-{id}-{pageNum}.html")
- public String selectedList(@PathVariable("id") Integer id, @PathVariable("pageNum") Integer pageNum, final Model model) {
- List<BaseLink> typeList = articleService.getArticleTypes();
- if (id == 1) {//精选文章
- List<CmProductArchiveFile> archiveFiles = articleService.findArchiveFileAddTime(null,0, 3);
- List<ProductList> productSellNumbers = productService.getProductSellNumbers(null);
- model.addAttribute("productSellNumbers", productSellNumbers);//销量前三商品
- model.addAttribute("archiveFiles", archiveFiles);//最新美业资料top3
- }
- List<BaseLink> data = articleService.getArticleLabels().getData();
- List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
- model.addAttribute("ads", Ads);
- model.addAttribute("labels", data);
- model.addAttribute("articleType", typeList);//导航栏
- model.addAttribute("labelId", 0);
- model.addAttribute("pageNum", pageNum);
- model.addAttribute("isSearch", true);
- model.addAttribute("isSelectInfo", id == 1);
- return ARTICLE_RECOMMENDATION;
- }
- /**
- * 精选文章和美业资料列表数据
- */
- @ResponseBody
- @GetMapping("/info/articlerecommendation/{id}/{pageNum}")
- public JsonModel<PaginationVo> toPagination(@PathVariable("id") Integer id,@PathVariable("pageNum") Integer pageNum) {
- PageHelper.startPage(pageNum, 10);
- PaginationVo pageData = null;
- if (id == 1) {//精选文章
- List<Article> infoSelected = articleService.getArticleSelected(null, null);
- pageData = new PaginationVo<Article>(infoSelected);
- } else {//美业资料
- List<CmProductArchiveFile> archiveFiles = articleService.findArchiveFileAddTime(null,null, null);
- pageData = new PaginationVo<CmProductArchiveFile>(archiveFiles);
- }
- return JsonModel.success(pageData);
- }
- @GetMapping("/info/search-{pageNum}.html")
- public String toArticleSearch(@PathVariable("pageNum") Integer pageNum, final Model model) {
- List<BaseLink> typeList = articleService.getArticleTypes();
- List<BaseLink> data = articleService.getArticleLabels().getData();
- List<ImageLink> Ads = articleService.getLastestInfoAds().getData() ;
- List<CmProductArchiveFile> archiveFiles = articleService.findArchiveFileAddTime(null,0, 3);
- List<ProductList> productSellNumbers = productService.getProductSellNumbers(null);
- model.addAttribute("productSellNumbers", productSellNumbers);//销量前三商品
- model.addAttribute("archiveFiles", archiveFiles);//最新美业资料top3
- model.addAttribute("ads", Ads);
- model.addAttribute("labels", data);
- model.addAttribute("articleType", typeList);
- model.addAttribute("typeId", 0);
- model.addAttribute("labelId", 0);
- model.addAttribute("pageNum", pageNum);
- model.addAttribute("isSearch", false);
- model.addAttribute("isSelectInfo", true);
- //model.addAttribute("pagePath", "/info/search.html");
- return ARTICLE_LIST_PATH;
- }
- /**
- * 文章详情【旧】
- */
- @GetMapping("/info/detail-{id}-1.html")
- 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);
- }
- String subReferer = "";
- if (referer.length() > 200) {
- subReferer = referer.substring(0, 190);
- }
- source = source(referer);
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String format = dateFormat.format(new Date());
- articleService.insertRecord(ip, subReferer, source, format);
- log.info("文章详情访问来源记录完成========》" + source);
- List<BaseLink> data = articleService.getArticleLabels().getData();
- List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
- List<Article> articles = new ArrayList<>();
- if (null != article && article.getAutoStatus() == 0) {
- articles = articleService.getInfoById(id);
- } else {
- articles = articleService.getArticleRelatedId(id.toString());
- }
- String relatedLabels = articleService.relatedLabel(id);
- List<Article> infoSelected = articleService.getArticleSelected(0, 5);
- List<CmProductArchiveFile> archiveFiles = articleService.findArchiveFileAddTime(article.getRelatedLabelIds(), 0,3);
- List<ProductList> productSellNumbers = productService.getProductSellNumbers(article.getRelatedLabelIds());
- model.addAttribute("infoSelected", infoSelected);//精选文章
- model.addAttribute("productSellNumbers", productSellNumbers);//销量前三商品
- model.addAttribute("archiveFiles", archiveFiles);//最新美业资料top3
- model.addAttribute("articles", articles);//相关文章
- model.addAttribute("ads", Ads);
- model.addAttribute("labels", data);
- model.addAttribute("article", article);
- model.addAttribute("articleType", typeList);
- model.addAttribute("articleId", id);
- model.addAttribute("relatedLabels", relatedLabels);
- model.addAttribute("typeId", (article != null ? article.getTypeId() : 0));
- model.addAttribute("labelId", 0);
- model.addAttribute("isSelectInfo", true);
- model.addAttribute("isDetail", true);
- return ARTICLE_DETAIL_PATH;
- }
- /**
- * 404
- */
- @GetMapping("/info/404.html")
- public String errorPage(final Model model) {
- model.addAttribute("msg", "404页面");
- model.addAttribute("type", "article");
- List<BaseLink> typeList = articleService.getArticleTypes();
- List<BaseLink> data = articleService.getArticleLabels().getData();
- List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
- model.addAttribute("ads", Ads);
- model.addAttribute("labels", data);
- model.addAttribute("articleType", typeList);
- model.addAttribute("typeId", 0);
- model.addAttribute("labelId", 0);
- return ERROR_PATH;
- }
- /**
- * 获取文章热门标签
- */
- @GetMapping("/article/labels")
- @ResponseBody
- public JsonModel<List<BaseLink>> getArticleLabels() {
- return articleService.getArticleLabels();
- }
- /**
- * 获取文章推荐
- */
- @GetMapping("/article/recommend")
- @ResponseBody
- public JsonModel<PageInfo<ImageLink>> getArticleRecommended(Integer typeId,
- @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
- @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
- return articleService.getArticleRecommended(typeId, pageNum, pageSize);
- }
- /**
- * 获取相关文章
- */
- @GetMapping("/article/related")
- @ResponseBody
- public JsonModel<PageInfo<Article>> getArticleRelated(Integer id, String labels,
- @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
- @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
- return articleService.getArticleRelated(id, labels, pageNum, pageSize);
- }
- /**
- * 获取文章广告
- */
- @GetMapping("/article/ads")
- @ResponseBody
- public JsonModel<List<ImageLink>> getLastestInfoAds() {
- return articleService.getLastestInfoAds();
- }
- /**
- * 点击标签
- */
- @GetMapping("/article/label/click")
- @ResponseBody
- public JsonModel clickArticleLabel(Integer id) {
- return articleService.clickArticleLabel(id);
- }
- /**
- * 点击广告
- */
- @GetMapping("/article/ad/click")
- @ResponseBody
- public JsonModel clickArticleAd(Integer id) {
- return articleService.clickArticleAd(id);
- }
- /**
- * 文章点赞
- */
- @GetMapping("/article/like")
- @ResponseBody
- public JsonModel articleLike(Integer id, ServerWebExchange serverWebExchange) {
- return articleService.articleLike(id, serverWebExchange);
- }
- /**
- * 文章浏览量增加
- */
- @GetMapping("/article/pv")
- @ResponseBody
- public JsonModel articlePv(Integer id) {
- return articleService.articlePv(id);
- }
- private String source(String link) {
- if (link.contains("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;
- }
- }
|