Quellcode durchsuchen

首页静态化

chao vor 4 Jahren
Ursprung
Commit
ec066585e0
24 geänderte Dateien mit 949 neuen und 629 gelöschten Zeilen
  1. 1 1
      pom.xml
  2. 30 0
      src/main/java/com/caimei/www/controller/GenerateApi.java
  3. 8 7
      src/main/java/com/caimei/www/controller/unlimited/HomeController.java
  4. 5 0
      src/main/java/com/caimei/www/mapper/BaseDao.java
  5. 17 1
      src/main/java/com/caimei/www/pojo/page/TopMenu.java
  6. 22 0
      src/main/java/com/caimei/www/service/generate/GenerateHtml.java
  7. 140 0
      src/main/java/com/caimei/www/service/generate/impl/GenerateHtmlImpl.java
  8. 5 0
      src/main/java/com/caimei/www/service/page/BaseService.java
  9. 28 9
      src/main/java/com/caimei/www/service/page/impl/BaseServiceImpl.java
  10. 238 0
      src/main/java/com/caimei/www/utils/AppletsLinkUtil.java
  11. 116 0
      src/main/java/com/caimei/www/utils/RequestUtil.java
  12. 4 3
      src/main/resources/application.yml
  13. 1 0
      src/main/resources/config/beta/application-beta.yml
  14. 2 4
      src/main/resources/config/dev/application-dev.yml
  15. 1 0
      src/main/resources/config/prod/application-prod.yml
  16. 7 0
      src/main/resources/mapper/BaseMapper.xml
  17. 1 0
      src/main/resources/static/css/base/base.h5.css
  18. 1 0
      src/main/resources/static/css/base/base.pc.css
  19. 12 12
      src/main/resources/static/js/base.js
  20. 14 4
      src/main/resources/static/js/common/serviceapi/utils.service.js
  21. 86 74
      src/main/resources/static/js/index.js
  22. 2 2
      src/main/resources/templates/components/header.html
  23. 208 399
      src/main/resources/templates/index.html
  24. 0 113
      src/test/java/com/caimei/www/WwwApplicationTests.java

+ 1 - 1
pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
-        <version>2.3.4.RELEASE</version>
+        <version>2.4.3</version>
         <relativePath/> <!-- lookup parent from repository -->
     </parent>
     <groupId>com.caimei</groupId>

+ 30 - 0
src/main/java/com/caimei/www/controller/GenerateApi.java

@@ -0,0 +1,30 @@
+package com.caimei.www.controller;
+
+import com.caimei.www.service.generate.GenerateHtml;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+import javax.annotation.Resource;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/5/7
+ */
+@RestController
+public class GenerateApi {
+    @Resource
+    private GenerateHtml generateHtml;
+
+    /**
+     * 生成静态首页
+     */
+    @GetMapping("/generate/index")
+    public Mono<String> generateStaticHome(ServerWebExchange exchange) {
+        return generateHtml.generateStaticHome(exchange);
+    }
+
+}

+ 8 - 7
src/main/java/com/caimei/www/controller/unlimited/HomeController.java

@@ -4,14 +4,14 @@ import com.caimei.www.controller.BaseController;
 import com.caimei.www.pojo.page.ImageLink;
 import com.caimei.www.pojo.JsonModel;
 import com.caimei.www.pojo.page.PageFloor;
-import com.caimei.www.pojo.page.ProductList;
+import com.caimei.www.service.page.BaseService;
 import com.caimei.www.service.page.HomeService;
-import org.springframework.beans.factory.annotation.Autowired;
 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 javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -28,12 +28,10 @@ public class HomeController extends BaseController {
 	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;
-    @Autowired
-    public void setHomeService(HomeService homeService) {
-        this.homeService = homeService;
-    }
 
     /**
      * 首页页面路径
@@ -42,6 +40,9 @@ public class HomeController extends BaseController {
      */
     @GetMapping("/index.html")
     public String home(final Model model) {
+		// 获取banner图
+		List<ImageLink> bannerList = baseService.getHomeBanners();
+		model.addAttribute("bannerList", bannerList);
         model.addAttribute("msg", "首页");
         return HOME_PATH;
     }

+ 5 - 0
src/main/java/com/caimei/www/mapper/BaseDao.java

@@ -41,4 +41,9 @@ public interface BaseDao {
      * 获取友情链接
      */
     List<BaseLink> getFriendLinks();
+
+    /**
+     * 首页轮播
+     */
+    List<ImageLink> getHomeBanners();
 }

+ 17 - 1
src/main/java/com/caimei/www/pojo/page/TopMenu.java

@@ -4,6 +4,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 一级导航栏
@@ -20,10 +21,25 @@ public class TopMenu implements Serializable {
 	private String type;
 	/** 一级导航链接 */
 	private String link;
+    /**
+     * 图标
+     */
+    private String icon;
 	/** 排序 */
 	private String sort;
 	/** 二级导航列表 */
-	private List<SubMenu> subMenus;
+	// private List<SubMenu> subMenus;
+    /**
+     * 链接类型 -1未知类型 1二级页面 2项目仪器 3直播页面 4自由页面 5商品详情 6项目仪器详情
+     * 7供应商主页 8专题活动页 9二手市场介绍 10二手商品列表 11二手商品发布 12商品搜索 13信息详情
+     * 14品牌招商介绍页 15维修保养介绍页 16首页 17注册页 18信息中心 19供应商列表
+     */
+    private Integer linkType;
+
+    /**
+     * 链接包含的参数
+     */
+    private Map<String, Object> linkParam;
 
 	private static final long serialVersionUID = 1L;
 }

+ 22 - 0
src/main/java/com/caimei/www/service/generate/GenerateHtml.java

@@ -0,0 +1,22 @@
+package com.caimei.www.service.generate;
+
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/5/7
+ */
+public interface GenerateHtml {
+    /**
+     * 生成静态首页
+     */
+    Mono<String> generateStaticHome(ServerWebExchange exchange);
+
+    /**
+     * 删除静态首页
+     */
+    Mono<String> deleteStaticHome(String pageName);
+}

+ 140 - 0
src/main/java/com/caimei/www/service/generate/impl/GenerateHtmlImpl.java

@@ -0,0 +1,140 @@
+package com.caimei.www.service.generate.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.caimei.www.pojo.page.BaseLink;
+import com.caimei.www.pojo.page.ImageLink;
+import com.caimei.www.pojo.page.TopMenu;
+import com.caimei.www.service.generate.GenerateHtml;
+import com.caimei.www.service.page.BaseService;
+import com.caimei.www.utils.RequestUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.server.ServerWebExchange;
+import org.thymeleaf.TemplateEngine;
+import org.thymeleaf.spring5.context.webflux.SpringWebFluxContext;
+import reactor.core.publisher.Mono;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/5/7
+ */
+@Slf4j
+@Service
+public class GenerateHtmlImpl implements GenerateHtml {
+    @Value("${caimei.destPath}")
+    private String destPath;
+	@Value("${caimei.coreServer}")
+	private String coreServer;
+	@Value("${caimei.spiServer}")
+    private String spiServer;
+    /** 打包时间 */
+    @Value("${caimei.siteEnv}")
+    private String siteEnv;
+    /** 打包时间 */
+    @Value("${spring.application.build-time}")
+    private String buildTime;
+
+    @Resource
+    private TemplateEngine templateEngine;
+    @Resource
+    private BaseService baseService;
+
+    /**
+     * 生成静态首页
+     */
+    @Override
+    public Mono<String> generateStaticHome(ServerWebExchange exchange) {
+        // 上下文
+        SpringWebFluxContext context = new SpringWebFluxContext(exchange);
+        // 设置页面数据
+        context.setVariables(setStaticHomeData());
+        // 输出流
+        File dest = new File(destPath, "index.html");
+        if (dest.exists()) {
+            boolean delete = dest.delete();
+        }
+        try (PrintWriter writer = new PrintWriter(dest, "UTF-8")) {
+            // 生成html
+            templateEngine.process("index", context, writer);
+            return Mono.just("[静态页服务]:生成静态首页成功! ^_^");
+        } catch (Exception e) {
+            log.error("[静态页服务]:生成静态首页异常!", e);
+            return Mono.just("[静态页服务]:生成静态首页异常!"+e.toString());
+        }
+    }
+
+    /**
+     * 删除静态页
+     */
+    @Override
+    public Mono<String> deleteStaticHome(String pageName) {
+        // 输出流
+        File dest = new File(destPath, pageName + ".html");
+        if (dest.exists()) {
+            boolean delete = dest.delete();
+            if (delete) {
+                return Mono.just("[静态页服务]:删除静态页成功! ^_^");
+            }
+        }
+        return Mono.just("[静态页服务]:删除静态页失败!");
+    }
+
+    /**
+     * 设置静态首页数据
+     */
+    private Map<String, Object> setStaticHomeData() {
+        // 这里加载的数据是从数据库查询出来的,demo就写固定了
+        Map<String, Object> map = new HashMap<>();
+
+		// 环境变量,(2:正式环境,1:测试环境,0:开发环境)
+	    map.put("siteEnv", siteEnv);
+		map.put("agent", "");
+	    // 静态文件版本号
+	    map.put("version", buildTime);
+		// spi服务器地址
+		map.put("coreServer", coreServer);
+		map.put("spiServer", spiServer);
+		// 搜索热门关键字
+		List<String> searchHotWord = baseService.getSearchHotWord();
+		map.put("searchHotWord", searchHotWord);
+		// 头部菜单
+		List<TopMenu> menuList = baseService.getNavMenu();
+		map.put("topMenuList", menuList);
+		// 获取banner图
+		List<ImageLink> bannerList = baseService.getHomeBanners();
+		map.put("bannerList", bannerList);
+        // 获取首页楼层
+        String floor = null;
+        try {
+            String floorResult = RequestUtil.sendGet(coreServer+"/commodity/home/floor?userId=0&source=1");
+            log.debug(floorResult);
+            Map<String, Object> floorMap = JSONObject.parseObject(floorResult, Map.class);
+            floor = floorMap.get("data").toString();
+        } catch (Exception e) {
+            log.error("try-catch:",e);
+        }
+        map.put("floorJson", floor);
+		// 底部帮助页
+		List<BaseLink> helpPages = baseService.getHelpPages();
+		map.put("helpPages", helpPages);
+		// 友情链接
+		List<BaseLink> friendLinks = baseService.getFriendLinks();
+		map.put("friendLinks", friendLinks);
+
+        log.info(map.toString());
+
+        return map;
+    }
+
+
+}

+ 5 - 0
src/main/java/com/caimei/www/service/page/BaseService.java

@@ -1,6 +1,7 @@
 package com.caimei.www.service.page;
 
 import com.caimei.www.pojo.page.BaseLink;
+import com.caimei.www.pojo.page.ImageLink;
 import com.caimei.www.pojo.page.TopMenu;
 
 import java.util.List;
@@ -33,4 +34,8 @@ public interface BaseService {
      */
     List<BaseLink> getFriendLinks();
 
+    /**
+     * 首页轮播
+     */
+    List<ImageLink> getHomeBanners();
 }

+ 28 - 9
src/main/java/com/caimei/www/service/page/impl/BaseServiceImpl.java

@@ -4,13 +4,13 @@ package com.caimei.www.service.page.impl;
 import com.caimei.www.mapper.BaseDao;
 import com.caimei.www.pojo.page.*;
 import com.caimei.www.service.page.BaseService;
-import com.caimei.www.utils.ImageUtil;
+import com.caimei.www.utils.AppletsLinkUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
+import org.thymeleaf.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.util.List;
@@ -53,14 +53,25 @@ public class BaseServiceImpl implements BaseService {
     public List<TopMenu> getNavMenu() {
         List<TopMenu> menuList = baseDao.getTopMenus();
         menuList.forEach(item -> {
-            List<SubMenu> subList = baseDao.getSubMenus(item.getId());
-            if (subList.size() > 0) {
-                // 设置老图片路径
-                subList.forEach(sub -> {
-                     sub.setImage(ImageUtil.getImageURL("", sub.getImage(), 0, domain));
-                });
+            String link = item.getLink();
+            if (!StringUtils.isEmpty(link)) {
+                if (link.contains("?")) {
+                    link = link + "&name=" + item.getName();
+                } else {
+                    link = link + "?name=" + item.getName();
+                }
+                item.setLinkType(AppletsLinkUtil.getLinkType(link));
+                item.setLinkParam(AppletsLinkUtil.getLinkParam(item.getLinkType(), link));
+                item.setLink(link);
             }
-            item.setSubMenus(subList);
+//            List<SubMenu> subList = baseDao.getSubMenus(item.getId());
+//            if (subList.size() > 0) {
+//                // 设置老图片路径
+//                subList.forEach(sub -> {
+//                     sub.setImage(ImageUtil.getImageURL("", sub.getImage(), 0, domain));
+//                });
+//            }
+//            item.setSubMenus(subList);
         });
         return menuList;
     }
@@ -88,4 +99,12 @@ public class BaseServiceImpl implements BaseService {
         return baseDao.getFriendLinks();
     }
 
+    /**
+     * 首页轮播
+     */
+    @Override
+    public List<ImageLink> getHomeBanners() {
+        return baseDao.getHomeBanners();
+    }
+
 }

+ 238 - 0
src/main/java/com/caimei/www/utils/AppletsLinkUtil.java

@@ -0,0 +1,238 @@
+package com.caimei.www.utils;
+
+import lombok.extern.slf4j.Slf4j;
+import org.thymeleaf.util.StringUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * 小程序链接工具类
+ *
+ * @author : Charles
+ * @date : 2021/4/9
+ */
+@Slf4j
+public class AppletsLinkUtil {
+    /**
+     * 1二级页面
+     */
+    public static final Pattern pattern1 = Pattern.compile("/cmpage/info-1");
+    public static final Pattern pattern34 = Pattern.compile("/topic.html");
+    /**
+     * 2项目仪器详情
+     */
+    public static final Pattern pattern2 = Pattern.compile("/cmpage/info-2");
+    public static final Pattern pattern6 = Pattern.compile("equipment/detail");
+    /**
+     * 3直播页面
+     */
+    public static final Pattern pattern3 = Pattern.compile("/cmpage/info-3");
+    public static final Pattern pattern36 = Pattern.compile("wx.vzan.com");
+    /**
+     * 4自由页面
+     */
+    public static final Pattern pattern4 = Pattern.compile("/cmpage/info-4");
+    public static final Pattern pattern33 = Pattern.compile("page.html");
+    /**
+     * 5商品详情
+     */
+    public static final Pattern pattern5 = Pattern.compile("/product-");
+
+    /**
+     * 7供应商主页
+     */
+    public static final Pattern pattern7 = Pattern.compile("supplier/prolist");
+    public static final Pattern pattern8 = Pattern.compile("supplier/index.html");
+    public static final Pattern pattern9 = Pattern.compile("view/supplierHomePage.jsp");
+    public static final Pattern pattern10 = Pattern.compile("supplier/productlist-");
+    /**
+     * 8专题活动页
+     */
+    public static final Pattern pattern11 = Pattern.compile("promotions.html");
+    public static final Pattern pattern12 = Pattern.compile("cmpage/area.html");
+    /**
+     * 9二手市场介绍
+     */
+    public static final Pattern pattern13 = Pattern.compile("html/secondHand/introduction.jsp");
+    public static final Pattern pattern14 = Pattern.compile("flea-market/intro.html");
+    /**
+     * 10二手商品列表
+     */
+    public static final Pattern pattern15 = Pattern.compile("html/secondHand/secondList.jsp");
+    public static final Pattern pattern16 = Pattern.compile("flea-market/list.html");
+    /**
+     * 11二手商品发布
+     */
+    public static final Pattern pattern17 = Pattern.compile("html/maintenance/view/secondtransactions.jsp");
+    public static final Pattern pattern18 = Pattern.compile("flea-market/form.html");
+    /**
+     * 12商品搜索
+     */
+    public static final Pattern pattern19 = Pattern.compile("product/search.shtml");
+    public static final Pattern pattern20 = Pattern.compile("product/search/list");
+    public static final Pattern pattern21 = Pattern.compile("product/list.html");
+    /**
+     * 13信息详情
+     */
+    public static final Pattern pattern22 = Pattern.compile("info/detail");
+    /**
+     * 14品牌招商介绍页
+     */
+    public static final Pattern pattern23 = Pattern.compile("html/InvestmentCaiMei/investmentpage.jsp");
+    public static final Pattern pattern24 = Pattern.compile("investment.html");
+    /**
+     * 15维修保养介绍页
+     */
+    public static final Pattern pattern25 = Pattern.compile("html/maintenance/view/mt-entry-index.jsp");
+    public static final Pattern pattern26 = Pattern.compile("repair.html");
+    /**
+     * 16首页
+     */
+    public static final Pattern pattern27 = Pattern.compile("index.action");
+    public static final Pattern pattern28 = Pattern.compile("index.html");
+    /**
+     * 17注册页
+     */
+    public static final Pattern pattern29 = Pattern.compile("web/login/view/register_new_vip.jsp");
+    public static final Pattern pattern30 = Pattern.compile("register.html");
+    /**
+     * 18信息中心
+     */
+    public static final Pattern pattern31 = Pattern.compile("info/center");
+    /**
+     * 19供应商列表
+     */
+    public static final Pattern pattern32 = Pattern.compile("supplier/list.html");
+    /**
+     * 20分类详情
+     */
+    public static final Pattern pattern35 = Pattern.compile("/cmpage/info-5");
+    /**
+     * 21美博会专题页
+     */
+    public static final Pattern pattern37 = Pattern.compile("/beautytopic");
+    /**
+     * 22美体会专题页
+     */
+    public static final Pattern pattern38 = Pattern.compile("/cmpage/info-5-301");
+
+    /**
+     * 根据链接判断链接类型
+     *
+     * @param link
+     * @return
+     */
+    public static Integer getLinkType(String link) {
+        if (!StringUtils.isEmpty(link)) {
+            if (pattern1.matcher(link).find() || pattern34.matcher(link).find()) {
+                return 1;
+            } else if (pattern2.matcher(link).find() || pattern6.matcher(link).find()) {
+                return 2;
+            } else if (pattern3.matcher(link).find() || pattern36.matcher(link).find()) {
+                return 3;
+            } else if (pattern4.matcher(link).find() || pattern33.matcher(link).find()) {
+                return 4;
+            } else if (pattern5.matcher(link).find()) {
+                return 5;
+            } else if (pattern7.matcher(link).find() || pattern8.matcher(link).find() || pattern9.matcher(link).find() || pattern10.matcher(link).find()) {
+                return 7;
+            } else if (pattern11.matcher(link).find() || pattern12.matcher(link).find()) {
+                return 8;
+            } else if (pattern13.matcher(link).find() || pattern14.matcher(link).find()) {
+                return 9;
+            } else if (pattern15.matcher(link).find() || pattern16.matcher(link).find()) {
+                return 10;
+            } else if (pattern17.matcher(link).find() || pattern18.matcher(link).find()) {
+                return 11;
+            } else if (pattern19.matcher(link).find() || pattern20.matcher(link).find() || pattern21.matcher(link).find()) {
+                return 12;
+            } else if (pattern22.matcher(link).find()) {
+                return 13;
+            } else if (pattern23.matcher(link).find() || pattern24.matcher(link).find()) {
+                return 14;
+            } else if (pattern25.matcher(link).find() || pattern26.matcher(link).find()) {
+                return 15;
+            } else if (pattern27.matcher(link).find() || pattern28.matcher(link).find()) {
+                return 16;
+            } else if (pattern29.matcher(link).find() || pattern30.matcher(link).find()) {
+                return 17;
+            } else if (pattern31.matcher(link).find()) {
+                return 18;
+            } else if (pattern32.matcher(link).find()) {
+                return 19;
+            } else if (pattern35.matcher(link).find()) {
+                if (pattern38.matcher(link).find()) {
+                    return 22;
+                }
+                return 20;
+            } else if (pattern37.matcher(link).find()) {
+                return 21;
+            } else {
+                return -1;
+            }
+        } else {
+            return -1;
+        }
+    }
+
+    /**
+     * 根据链接获取链接中携带的参数
+     *
+     * @param linkType
+     * @param link
+     * @return
+     */
+    public static Map<String, Object> getLinkParam(Integer linkType, String link) {
+        HashMap<String, Object> map = new HashMap<>();
+        String[] idArr = link.split("/");
+        String[] split1 = null;
+        String[] split2 = null;
+        String[] split3 = null;
+        if (idArr.length > 0) {
+            split1 = idArr[idArr.length - 1].split("-");
+            split2 = idArr[idArr.length - 1].split("=");
+            if (split1.length > 0) {
+                split3 = split1[split1.length - 1].split("\\.");
+            }
+        }
+        if (linkType == 3 || linkType == 5 || linkType == 20 || linkType == 22) {
+            //-{id}.html
+            if (split3 != null && split3.length == 2) {
+                map.put("id", split3[0]);
+            }
+        } else if (linkType == 1 || linkType == 2 || linkType == 4 || linkType == 7) {
+            if (pattern1.matcher(link).find() || pattern2.matcher(link).find() || pattern4.matcher(link).find() || pattern7.matcher(link).find() || pattern10.matcher(link).find()) {
+                //-{id}.html
+                if (split3 != null && split3.length == 2) {
+                    map.put("id", split3[0]);
+                }
+            } else if (pattern6.matcher(link).find() || pattern33.matcher(link).find() || pattern8.matcher(link).find() || pattern9.matcher(link).find() || pattern34.matcher(link).find()) {
+                //id={id}
+                if (split2 != null && split2.length == 2) {
+                    map.put("id", split2[1]);
+                }
+            }
+        } else if (linkType == 13 || linkType == 18) {
+            //a-{id}-b
+            if (split1 != null && split1.length == 3) {
+                map.put("id", split1[1]);
+            }
+        } else if (linkType == 12 || linkType == 19) {
+            //keyword=
+            if (split2 != null && split2.length == 2) {
+                String keyword = split2[1];
+                try {
+                    keyword = URLDecoder.decode(keyword, "UTF-8");
+                } catch (UnsupportedEncodingException e) {
+                    log.error("try-catch:",e);
+                }
+                map.put("keyword", keyword);
+            }
+        }
+        return map;
+    }
+}

+ 116 - 0
src/main/java/com/caimei/www/utils/RequestUtil.java

@@ -0,0 +1,116 @@
+package com.caimei.www.utils;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 请求工具类
+ *
+ * @author : Charles
+ * @date : 2021/3/8
+ */
+public class RequestUtil {
+
+    /**
+     * 向指定URL发送GET方法的请求
+     *
+     * @param url   发送请求的URL,请求参数应该是 name1=value1&name2=value2 的形式。
+     * @return 远程资源的响应结果
+     */
+    public static String sendGet(String url) throws Exception {
+        StringBuilder result = new StringBuilder();
+        BufferedReader in = null;
+        try {
+
+            URL realUrl = new URL(url);
+            // 打开和URL之间的连接
+            URLConnection connection = realUrl.openConnection();
+            // 设置通用的请求属性
+            connection.setRequestProperty("accept", "*/*");
+            connection.setRequestProperty("connection", "Keep-Alive");
+            connection.setRequestProperty("Accept-Charset", "utf-8");
+            connection.setRequestProperty("contentType", "utf-8");
+            connection.setConnectTimeout(5000);
+            // 建立实际的连接
+            connection.connect();
+            // 获取所有响应头字段
+            Map<String, List<String>> map = connection.getHeaderFields();
+            // 定义 BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(new InputStreamReader(
+                    connection.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+        }
+        // 使用finally块来关闭输入流
+        finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+        return result.toString();
+    }
+
+    /**
+     * 向指定 URL 发送POST方法的请求
+     *
+     * @param url 发送请求的 URL
+     * @param paramMap 请求参数
+     * @return 所代表远程资源的响应结果
+     */
+    public static String sendPost(String url, Map<String, ?> paramMap) throws Exception{
+        PrintWriter out = null;
+        BufferedReader in = null;
+        StringBuilder result = new StringBuilder();
+
+        StringBuilder param = new StringBuilder();
+
+        for (String key : paramMap.keySet()) {
+            param.append(key).append("=").append(paramMap.get(key)).append("&");
+        }
+
+        try {
+            URL realUrl = new URL(url);
+            // 打开和URL之间的连接
+            URLConnection conn = realUrl.openConnection();
+            // 设置通用的请求属性
+            conn.setRequestProperty("accept", "*/*");
+            conn.setRequestProperty("connection", "Keep-Alive");
+            conn.setRequestProperty("Accept-Charset", "utf-8");
+            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(conn.getOutputStream());
+            // 发送请求参数
+            out.print(param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+        }
+        //使用finally块来关闭输出流、输入流
+        finally{
+            if(out!=null){
+                out.close();
+            }
+            if(in!=null){
+                in.close();
+            }
+        }
+        return result.toString();
+    }
+
+}

+ 4 - 3
src/main/resources/application.yml

@@ -1,5 +1,9 @@
 server:
   port: 8009
+  compression:
+    enabled: true
+    mime-types: application/json,application/xml,text/xml,text/plain,text/html,text/javascript,text/css
+
 spring:
   application:
     # 指定服务名
@@ -22,6 +26,3 @@ mybatis:
   mapper-locations:
     - classpath:mapper/*.xml
     - classpath:com-caimei-module-product/*Mapper.xml
-
-
-

+ 1 - 0
src/main/resources/config/beta/application-beta.yml

@@ -53,6 +53,7 @@ caimei:
   coreServer: https://core-b.caimei365.com
   imageDomain: https://img-b.caimei365.com
   wwwDomain: https://www-b.caimei365.com
+  destPath: /mnt/newdatadrive/data/runtime/h5-instance/static/www
 
 #DFS配置
 fdfs:

+ 2 - 4
src/main/resources/config/dev/application-dev.yml

@@ -58,11 +58,9 @@ caimei:
   coreServer: https://core-b.caimei365.com
 #  coreServer: http://192.168.2.68:18002
   imageDomain: https://img-b.caimei365.com
-  wwwDomain: https://www-b.caimei365.com
+  wwwDomain: http:localhost:8009
+  destPath: D:/_PLAN_WORKSPACE/test/static
 
-#    spiServer: https://spi.caimei365.com
-#    imageDomain: https://img.caimei365.com
-#    wwwDomain: https://www.caimei365.com
 
 #DFS配置
 fdfs:

+ 1 - 0
src/main/resources/config/prod/application-prod.yml

@@ -53,6 +53,7 @@ caimei:
   coreServer: https://core.caimei365.com
   imageDomain: https://img.caimei365.com
   wwwDomain: https://www.caimei365.com
+  destPath: /mnt/newdatadrive/data/runtime/h5-instance/static/www
 
 
 #DFS配置

+ 7 - 0
src/main/resources/mapper/BaseMapper.xml

@@ -12,6 +12,7 @@
             navigationName as name,
             type,
             link,
+            icon,
             sort
 		from new_page_first_navigation
 		where wwwEnabledStatus='1' and delFlag = 0
@@ -52,4 +53,10 @@
 		from new_page_friendship_link
 		where delFlag = 0 order by id
     </select>
+    <select id="getHomeBanners" resultType="com.caimei.www.pojo.page.ImageLink">
+		select id, title, link, image
+		from new_page_homeimage
+		where wwwEnabledStatus = 1
+		order by sort desc, createDate desc
+    </select>
 </mapper>

+ 1 - 0
src/main/resources/static/css/base/base.h5.css

@@ -217,6 +217,7 @@
 .priceTag .promotion .more{color:#f55c5c;text-decoration:underline;float:right;}
 /* loading */
 .loading{box-sizing:border-box;padding:20vw 0;text-align:center;}
+.loading.home{position:fixed;z-index:9999;width:100%;height:100%;background:#FFF;}
 .empty{box-sizing:border-box;padding:15vw 0;text-align:center;color:#4A4F58;line-height:8vw;font-size:3.4vw;}
 .empty img{width:40vw;height:40vw;}
 .empty a{color:#E15616;}

+ 1 - 0
src/main/resources/static/css/base/base.pc.css

@@ -343,6 +343,7 @@ iframe{width:320px !important;height: 280px !important}
 .priceTag .promotion .more{color:#f55c5c;text-decoration:underline;float:right;}
 /* 加载  */
 .loading{box-sizing:border-box;padding:200px 0;text-align:center;}
+.loading.home{position:fixed;z-index:9999;width:100%;height:100%;background:#FFF;}
 .empty{box-sizing:border-box;padding:100px 0;text-align:center;color:#4A4F58;line-height:30px;font-size:16px;}
 .empty img{width:180px;height:180px;}
 .empty a{color:#E15616;}

+ 12 - 12
src/main/resources/static/js/base.js

@@ -49,7 +49,7 @@ var globalHead = new Vue({
         shopId:'',
         userIdentity:'',
         articleType: '',
-        topMenuList:[],
+        // topMenuList:[],
         isFiexd:false,
         TabList:[
             {name:'产品',link:'/product/instrument.html',value:'1'},
@@ -63,16 +63,16 @@ var globalHead = new Vue({
         changeline:function(tab){
             this.currenIndex=tab.value;
         },
-        GetNavigationMenu :function(){//获取顶部导航分类
-            var _self = this;
-            PublicApi.GetNavigationMenu({source:1},function(response){
-                if(response.code == 0){
-                    _self.topMenuList = response.data.topMenuList;
-                }else{
-                    CAIMEI.Alert(response.msg, '确定');
-                }
-            });
-        },
+        // GetNavigationMenu :function(){//获取顶部导航分类
+        //     var _self = this;
+        //     PublicApi.GetNavigationMenu({source:1},function(response){
+        //         if(response.code == 0){
+        //             _self.topMenuList = response.data.topMenuList;
+        //         }else{
+        //             CAIMEI.Alert(response.msg, '确定');
+        //         }
+        //     });
+        // },
         GetProductClassify: function(index) { // 导航分类菜单
             var _self = this;
             PublicApi.GetProductClassify({typeSort:index,source :'www'},function(response){
@@ -188,7 +188,7 @@ var globalHead = new Vue({
         // 导航分类数据
         this.GetProductClassify(1);
         this.GetProductClassify(2);
-        this.GetNavigationMenu();
+        // this.GetNavigationMenu();
         // 判断登录状态
         if (globalUserData.token) {
             this.loginStatus = true;

+ 14 - 4
src/main/resources/static/js/common/serviceapi/utils.service.js

@@ -8,10 +8,20 @@ var PublicApi = {
             Http.uploadImage({ url:'/formData/MultiPictareaddData',data:params},callback)
         },
         GetHomeData:function(params,callback){ //首页数据
-            Http.AjaxService({ url:'/home/data', type:'get', data:params, json:false})
-                .then(function(res){
-                    callback(res)
-                });
+            // Http.AjaxService({ url:'/home/data', type:'get', data:params, json:false})
+            //     .then(function(res){
+            //         callback(res)
+            //     });
+            Http.AjaxService({
+                url:'/commodity/home/floor',
+                type:'get',
+                data:params,
+                json:false,
+                isHost:true
+            })
+            .then(function(res){
+                callback(res)
+            });
         },
         GetHomeBanner:function(params,callback){ //首页bnner
             Http.AjaxService({ url:'/home/banner', type:'get', data:params, json:false})

+ 86 - 74
src/main/resources/static/js/index.js

@@ -14,7 +14,7 @@ var homeData = new Vue({
         supplierImage:'',//供应商banner
         supplierWwwLink:'',//供应商banner 链接
         supplierList:[],//供应商列表
-        topMenuList:[],
+        // topMenuList:[],
         showflag:false,
     },
     filters: {
@@ -49,7 +49,6 @@ var homeData = new Vue({
         },
     },
     methods: {
-
         zhuanti:function(){
             this.showflag=false;
             window.location.href='/activity/activityTopic.html?id=306&name=美博会';
@@ -62,18 +61,18 @@ var homeData = new Vue({
               localStorage.setItem('lockTime',Date.now());
               localStorage.setItem('isActivityStatus',true);
         },
-        GetBanners: function(){
-            var _self = this;
-            PublicApi.GetHomeBanner({},function(response){
-                if(response.code == 0){
-                    _self.images = response.data;
-                    _self.listLoading =false;
-                    _self.SwiperBanner();
-                }else{
-                    CAIMEI.Alert(response.msg, '确定');
-                }
-            });
-        },
+        // GetBanners: function(){
+        //     var _self = this;
+        //     PublicApi.GetHomeBanner({},function(response){
+        //         if(response.code == 0){
+        //             _self.images = response.data;
+        //             _self.listLoading =false;
+        //             _self.SwiperBanner();
+        //         }else{
+        //             CAIMEI.Alert(response.msg, '确定');
+        //         }
+        //     });
+        // },
         SwiperBanner: function(){
             setTimeout(function(){
                 if (isPC) {
@@ -107,72 +106,85 @@ var homeData = new Vue({
                 }
             },300);
         },
-        GetNavigationMenu :function(){//获取顶部导航分类
+        // GetNavigationMenu :function(){//获取顶部导航分类
+        //     var _self = this;
+        //     PublicApi.GetNavigationMenu({source:1},function(response){
+        //         if(response.code == 0){
+        //             _self.topMenuList = response.data.topMenuList;
+        //         }else{
+        //             CAIMEI.Alert(response.msg, '确定');
+        //         }
+        //     });
+        // },
+        GetHomeFloorData: function(){
             var _self = this;
-            PublicApi.GetNavigationMenu({source:1},function(response){
-                if(response.code == 0){
-                    _self.topMenuList = response.data.topMenuList;
-                }else{
-                    CAIMEI.Alert(response.msg, '确定');
-                }
-            });
+            // 预设静态数据
+            var staticJson = $("#floorJson").val();
+            if (staticJson) {
+                var staticData = JSON.parse(staticJson);
+                _self.setFloorData(staticData);
+            }
+            // 如果没有静态数据(重新请求) 或 用户登录(重新请求获取价格)
+            if (!staticJson || GLOBAL_USER_ID>0){
+                PublicApi.GetHomeData({userId:GLOBAL_USER_ID,source:1},function(response){
+                    if(response.code == 0){
+                        var data = response.data;
+                        _self.setFloorData(data);
+                    }else{
+                        CAIMEI.Alert(response.msg, '确定');
+                    }
+                });
+            }
         },
-        GetHomeFloorData: function(){
+        setFloorData: function(data){
             var _self = this;
-            PublicApi.GetHomeData({userId:GLOBAL_USER_ID,source:1},function(response){
-                if(response.code == 0){
-                    var data = response.data;
-                    // var floorList = [];
-                    _self.pageList = data.homePageFloor;
-                    _self.liveList = data.liveList;
-                    _self.supplierList = data.supplierImage.qualitySupplierList;
-                    _self.supplierImage = data.supplierImage.wwwImage;
-                    _self.supplierWwwLink = data.supplierImage.wwwLink;
-                    _self.pageList.forEach(function(page){
-                        if(page.floorContent){
-                            if(isPC){
+            _self.pageList = data.homePageFloor;
+            _self.liveList = data.liveList;
+            _self.supplierList = data.supplierImage.qualitySupplierList;
+            _self.supplierImage = data.supplierImage.wwwImage;
+            _self.supplierWwwLink = data.supplierImage.wwwLink;
+            _self.pageList.forEach(function(page){
+                if(page.floorContent){
+                    if(isPC){
 
-                                if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
-                                    if (page.floorImageList.length>7){
-                                        page.isPageMore = true;
-                                    }
-                                }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4' || page.floorContent.templateType == '7'){
-                                    if (page.floorImageList.length>5){
-                                        page.isPageMore = true;
-                                    }
-                                }else if(page.floorContent.templateType == '5'){
-                                    if (page.floorImageList.length>10){
-                                        page.isPageMore = true;
-                                    }
-                                }
-                            }else{
-                                if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
-                                    if (page.floorImageList.length>3){
-                                        page.isPageMore = true;
-                                    }
-                                }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4'){
-                                    if (page.floorImageList.length>2){
-                                        page.isPageMore = true;
-                                    }
-                                }else if(page.floorContent.templateType == '5'){
-                                    if (page.floorImageList.length>4){
-                                        page.isPageMore = true;
-                                    }
-                                }
+                        if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
+                            if (page.floorImageList.length>7){
+                                page.isPageMore = true;
+                            }
+                        }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4' || page.floorContent.templateType == '7'){
+                            if (page.floorImageList.length>5){
+                                page.isPageMore = true;
+                            }
+                        }else if(page.floorContent.templateType == '5'){
+                            if (page.floorImageList.length>10){
+                                page.isPageMore = true;
                             }
                         }
-                    });
-                    console.log(_self.pageList)
-                    _self.GetHomeRightData();
-                    setTimeout(function() {
-                        // 设置侧边导航数据
-                        _self.SetAsideNav();
-                        _self.SwiperFloor();
-                    },500);
-                }else{
-                    CAIMEI.Alert(response.msg, '确定');
+                    }else{
+                        if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
+                            if (page.floorImageList.length>3){
+                                page.isPageMore = true;
+                            }
+                        }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4'){
+                            if (page.floorImageList.length>2){
+                                page.isPageMore = true;
+                            }
+                        }else if(page.floorContent.templateType == '5'){
+                            if (page.floorImageList.length>4){
+                                page.isPageMore = true;
+                            }
+                        }
+                    }
                 }
             });
+            _self.listLoading = false;
+            _self.GetHomeRightData();
+            setTimeout(function() {
+                // 设置侧边导航数据
+                _self.SetAsideNav();
+                _self.SwiperFloor();
+            },500);
+            console.log(_self.pageList)
         },
         GetHomeRightData: function(){
             var _self = this;
@@ -280,8 +292,8 @@ var homeData = new Vue({
         if(userInfo){
             this.userId = JSON.parse(userInfo).userId;
         }
-        this.GetBanners();
-        this.GetNavigationMenu();
+        this.SwiperBanner();
+        // this.GetNavigationMenu();
         this.GetHomeFloorData();
     },
     mounted: function() {

+ 2 - 2
src/main/resources/templates/components/header.html

@@ -114,8 +114,8 @@
                 <div class="navBox">
                     <ul class="clear">
                         <!--导航菜单-->
-                        <li v-for="(menu,index) in topMenuList">
-                            <a class="nav" :href="menu.link" v-text="menu.name" target="_blank"></a>
+                        <li th:each="menu: ${topMenuList}">
+                            <a class="nav" th:href="${menu.link}" th:text="${menu.name}" target="_blank"></a>
                         </li>
                     </ul>
                 </div>

Datei-Diff unterdrückt, da er zu groß ist
+ 208 - 399
src/main/resources/templates/index.html


+ 0 - 113
src/test/java/com/caimei/www/WwwApplicationTests.java

@@ -1,113 +0,0 @@
-package com.caimei.www;
-
-import lombok.Data;
-import com.alibaba.fastjson.JSONObject;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.web.client.RestTemplate;
-import reactor.core.publisher.Flux;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-@SpringBootTest
-class WwwApplicationTests {
-
-    @Test
-    void contextLoads() {
-    }
-
-    @Test
-    void test1() {
-
-//        Flux.just("Hello", "World").subscribe(System.out::println);
-//        Flux.fromArray(new Integer[] {1, 2, 3}).subscribe(System.out::println);
-//        Flux.empty().subscribe(System.out::println);
-//        Flux.range(1, 10).subscribe(System.out::println);
-//        Flux.interval(Duration.of(10, ChronoUnit.SECONDS)).subscribe(System.out::println);
-
-//        Flux.generate(sink -> {
-//            sink.next("Hello");
-//            sink.complete();
-//        }).subscribe(System.out::println);
-
-
-//        final Random random = new Random();
-//        Flux.generate(ArrayList::new, (list, sink) -> {
-//            int value = random.nextInt(100);
-//            list.add(value);
-//            sink.next(value);
-//            if (list.size() == 10) {
-//                sink.complete();
-//            }
-//            return list;
-//        }).subscribe(System.out::println);
-//
-//        Flux.create(sink -> {
-//            for (int i = 0; i < 10; i++) {
-//                sink.next(i);
-//            }
-//            sink.complete();
-//        }).subscribe(System.out::println);
-
-//        Flux.range(1, 100).buffer(20).subscribe(System.out::println);
-//        Flux.range(1, 10).bufferUntil(i -> i % 2 == 0).subscribe(System.out::println);
-//        Flux.range(1, 10).bufferWhile(i -> i % 2 == 0).subscribe(System.out::println);
-
-
-//        List<String> list = Arrays.asList("item1", "item2");
-//        list.forEach(System.out::println);
-
-    }
-
-    @Test
-    void test2(){
-//        List<String> strs = Arrays.asList("1","4","3","2");
-//        // strs.sort((s1,s2) -> s1.compareTo(s2));
-//        strs.sort(String::compareTo);
-//        strs.forEach(System.out::println);
-    }
-//    @Data
-//    private static class Student{
-//        private String name;
-//        private int age;
-//        public Student(String name, int age) {
-//            this.name = name;
-//            this.age = age;
-//        }
-//    }
-
-    @Test
-    void test3(){
-//        List<Student> students = new ArrayList<>(3);
-//        students.add(new Student("路飞", 22));
-//        students.add(new Student("红发", 40));
-//        students.add(new Student("白胡子", 50));
-//
-//        List<Student> list = students.stream()
-//            .filter(stu -> stu.getAge() < 50)
-//            .collect(Collectors.toList());
-//        System.out.println(list);
-//
-//
-//        List<String> names = students.stream().map(Student::getName)
-//                .collect(Collectors.toList());
-//        System.out.println(names);
-    }
-
-    @Test
-    void test4(){
-//        RestTemplate restTemplate = new RestTemplate();
-//        String uri = "https://spi.caimei365.com/search/query/product?keyword=采美";
-//        JSONObject forObject = restTemplate.getForObject(uri, JSONObject.class);
-//        if(forObject != null){
-//            String data = forObject.getString("data");
-//
-//            JSONObject parse = JSONObject.parseObject(data);
-//            Integer total = parse.getInteger("total");
-//
-//            System.out.println(total);
-//        }
-    }
-
-}

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.