123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package com.caimei.www.controller.unlimited;
- import com.caimei.www.controller.BaseController;
- import com.caimei.www.pojo.page.ImageLink;
- import com.caimei.www.pojo.JsonModel;
- import com.caimei.www.service.page.BaseService;
- import com.caimei.www.service.page.HomeService;
- import lombok.extern.slf4j.Slf4j;
- 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.GetMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.server.ServerWebExchange;
- import org.thymeleaf.util.StringUtils;
- import javax.annotation.Resource;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- /**
- * Description(接口已搬至spi)
- *
- * @author : Charles
- * @date : 2020/6/15
- */
- @Slf4j
- @Controller
- public class HomeController extends BaseController {
- private static final String HOME_PATH = "index";
- /** 错误页面 */
- private static final String ERROR_PATH = "error/404";
- private static final String SEARCH_CHILDREN = "error/search_children";
- @Resource
- private BaseService baseService;
- @Resource
- private HomeService homeService;
- /**
- * 首页页面路径
- * @param model
- * @return
- */
- @GetMapping("/index.html")
- public String home(final Model model, ServerWebExchange serverWebExchange, ServerHttpResponse response) {
- 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());
- homeService.insertRecord(ip,subReferer,source,format);
- log.info("首页访问来源记录完成========》"+source);
- // 获取banner图
- List<ImageLink> bannerList = homeService.getHomeBanners();
- // 首页楼层
- Map<String, Object> floorMap = homeService.getHomeFloors();
- // 右侧侧边栏数据
- Map<String, Object> sideMap = homeService.getHomeSideJson();
- model.addAttribute("bannerList", bannerList);
- model.addAttribute("floorJson", floorMap);
- model.addAttribute("sideJson", sideMap);
- model.addAttribute("msg", "首页");
- return HOME_PATH;
- }
- /**
- * 404
- */
- @GetMapping("/404.html")
- public String errorPage(final Model model) {
- model.addAttribute("msg", "404页面");
- return ERROR_PATH;
- }
- /**
- * 腾讯公益
- */
- @GetMapping("/search_children.html")
- public String searchChildren(final Model model) {
- model.addAttribute("msg", "腾讯公益");
- return SEARCH_CHILDREN;
- }
- /**
- * 首页左侧广告图
- * @return
- */
- @GetMapping("/home/advertising")
- @ResponseBody
- public JsonModel<List<ImageLink>> getAdvertising() {
- return homeService.getAdvertising();
- }
- 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;
- }
- }
|