Browse Source

搜索关键词与菜单

chao 4 years ago
parent
commit
a75310c983

+ 22 - 0
pom.xml

@@ -70,6 +70,28 @@
             <artifactId>reactor-test</artifactId>
             <artifactId>reactor-test</artifactId>
             <scope>test</scope>
             <scope>test</scope>
         </dependency>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <!--引入商品模块-->
+        <dependency>
+            <groupId>com.caimei.module</groupId>
+            <artifactId>product</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
+
+
+
+
+
+
+
+
+
+
     </dependencies>
     </dependencies>
 
 
 
 

+ 8 - 0
src/main/java/com/caimei/www/WwwApplication.java

@@ -2,6 +2,11 @@ package com.caimei.www;
 
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.Ordered;
+import org.thymeleaf.spring5.view.ThymeleafViewResolver;
 
 
 /**
 /**
  * @author Charles
  * @author Charles
@@ -13,4 +18,7 @@ public class WwwApplication {
         SpringApplication.run(WwwApplication.class, args);
         SpringApplication.run(WwwApplication.class, args);
     }
     }
 
 
+
+
+
 }
 }

+ 42 - 0
src/main/java/com/caimei/www/api/BaseApi.java

@@ -0,0 +1,42 @@
+package com.caimei.www.api;
+
+import com.caimei.module.base.entity.bo.JsonModel;
+import com.caimei.www.service.BaseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2020/6/16
+ */
+@RestController
+public class BaseApi {
+
+    private BaseService baseService;
+    @Autowired
+    public void setBaseService(BaseService baseService) {
+        this.baseService = baseService;
+    }
+
+    /**
+     * 获取搜索热门关键字
+     */
+    @GetMapping("/search/hot/word")
+    public JsonModel hotWord() {
+        return baseService.getSearchHotWord();
+    }
+
+    /**
+     * 获取头部菜单
+     */
+    @GetMapping("/nav/menu")
+    public JsonModel navMenu() {
+        return baseService.getNavMenu();
+    }
+
+
+
+}

+ 0 - 4
src/main/java/com/caimei/www/controller/ProductController.java

@@ -3,11 +3,7 @@ package com.caimei.www.controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.thymeleaf.spring5.context.webflux.IReactiveDataDriverContextVariable;
-import org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable;
 
 
 /**
 /**
  *cription
  *cription

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

@@ -0,0 +1,30 @@
+package com.caimei.www.mapper;
+
+import com.caimei.www.pojo.SubMenuVo;
+import com.caimei.www.pojo.TopMenuVo;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2020/6/16
+ */
+@Mapper
+public interface BaseDao {
+    /**
+     * 获取搜索热门关键字
+     */
+    public List<String> getSearchKeyword();
+    /**
+     * 获取头部菜单
+     */
+    List<TopMenuVo> getTopMenus();
+    /**
+     * 获取二级菜单
+     */
+    List<SubMenuVo> getSubMenus(@Param("topId") Integer topId);
+}

+ 24 - 0
src/main/java/com/caimei/www/pojo/SubMenuVo.java

@@ -0,0 +1,24 @@
+package com.caimei.www.pojo;
+
+import lombok.Data;
+
+/**
+ * 二级导航栏
+ *
+ * @author : Charles
+ * @date : 2020/6/18
+ */
+@Data
+public class SubMenuVo {
+	private Integer id;
+	/** 一级导航栏ID */
+	private Integer topId;
+    /** 一级导航栏名称 */
+	private String name;
+	/** 二级导航栏图片 */
+	private String image;
+	/** 一级导航链接 */
+	private String link;
+	/** 排序 */
+	private String sort;
+}

+ 26 - 0
src/main/java/com/caimei/www/pojo/TopMenuVo.java

@@ -0,0 +1,26 @@
+package com.caimei.www.pojo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 一级导航栏
+ *
+ * @author : Charles
+ * @date : 2020/6/18
+ */
+@Data
+public class TopMenuVo {
+	private Integer id;
+    /** 一级导航栏名称 */
+	private String name;
+	/** 一级导航栏类型 0启用二级导航跳转 1启用链接跳转 */
+	private String type;
+	/** 一级导航链接 */
+	private String link;
+	/** 排序 */
+	private String sort;
+	/** 二级导航列表 */
+	private List<SubMenuVo> subMenus;
+}

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

@@ -0,0 +1,22 @@
+package com.caimei.www.service;
+
+import com.caimei.module.base.entity.bo.JsonModel;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2020/6/16
+ */
+public interface BaseService {
+
+    /**
+     * 获取搜索热门关键字
+     */
+    JsonModel getSearchHotWord();
+
+    /**
+     * 获取头部菜单
+     */
+    JsonModel getNavMenu();
+}

+ 54 - 0
src/main/java/com/caimei/www/service/impl/BaseServiceImpl.java

@@ -0,0 +1,54 @@
+package com.caimei.www.service.impl;
+
+import com.caimei.module.base.entity.bo.JsonModel;
+import com.caimei.www.mapper.BaseDao;
+import com.caimei.www.pojo.SubMenuVo;
+import com.caimei.www.pojo.TopMenuVo;
+import com.caimei.www.service.BaseService;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2020/6/16
+ */
+@Service
+public class BaseServiceImpl implements BaseService {
+    @Resource
+    private BaseDao baseDao;
+    /**
+     * 获取搜索热门关键字
+     */
+    @Override
+    public JsonModel getSearchHotWord() {
+        List<String> hotSearch = baseDao.getSearchKeyword();
+        if (!CollectionUtils.isEmpty(hotSearch) && hotSearch.size() > 8) {
+            List<String> newList = hotSearch.stream()
+                .filter(str -> !StringUtils.isEmpty(str)).limit(8)
+                .collect(Collectors.toList());
+            return JsonModel.newInstance().success(newList);
+        } else {
+            return JsonModel.newInstance().success(hotSearch);
+        }
+    }
+
+    /**
+     * 获取头部菜单
+     */
+    @Override
+    public JsonModel getNavMenu() {
+        List<TopMenuVo> menuList = baseDao.getTopMenus();
+        menuList.forEach(item -> {
+            List<SubMenuVo> subList = baseDao.getSubMenus(item.getId());
+            item.setSubMenus(subList);
+        });
+        return JsonModel.newInstance().success(menuList);
+    }
+}

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

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei.www.mapper.BaseDao">
+    <select id="getSearchKeyword" resultType="java.lang.String">
+        select name from keyword
+        where validFlag=1
+        order by sortIndex desc
+    </select>
+    <select id="getTopMenus" resultType="com.caimei.www.pojo.TopMenuVo">
+		select
+            id,
+            navigationName as name,
+            type,
+            link,
+            sort
+		from new_page_first_navigation
+		where wwwEnabledStatus='1' and delFlag = 0
+		order by sort desc,createDate desc
+		limit 7
+    </select>
+    <select id="getSubMenus" resultType="com.caimei.www.pojo.SubMenuVo">
+		select
+            id,
+            firstNavigationId as topId,
+            navigationName as name,
+            navigationImage as image,
+            link,
+            sort
+		from new_page_secondary_navigation
+		where wwwEnabledStatus='1' and delFlag = 0
+		and firstNavigationId = #{topId}
+		order by sort desc,createDate desc
+    </select>
+</mapper>

+ 4 - 0
src/main/resources/static/css/base.css

@@ -0,0 +1,4 @@
+@charset "utf-8";
+html,body{width:100%;height:100%;}
+.clear{clear:both;}
+.clear:after{content:"";display:table;clear:both;}

BIN
src/main/resources/static/img/home/qr_code_caimei365.jpg


BIN
src/main/resources/static/img/home/qr_code_hehe.jpg


BIN
src/main/resources/static/img/logo.png


+ 21 - 0
src/main/resources/static/js/base.js

@@ -0,0 +1,21 @@
+window.onload=function(){
+    if ($('#hotWord').length >0 ){
+        var hotWords = [];
+        $.get("/search/hot/word").done(function(r){
+            if (r.code === 0 && r.data) {
+                hotWords = r.data;
+                var html = '';
+                for (var i=0; i<hotWords.length; i++){
+                    if (i>0) {
+                        html += '/';
+                    }
+                    html += '<a href="/product/search.shtml?keyword='+ hotWords[i] +'" target="_blank">'+ hotWords[i] +'</a>';
+                }
+                $('#hotWord').html(html);
+            }
+        });
+    }
+};
+
+
+

+ 79 - 1
src/main/resources/templates/components/header.html

@@ -1 +1,79 @@
-<header>header</header>
+<header xmlns:th="http://www.w3.org/1999/xhtml">
+    <ul>
+        <li><a href="javascript:void(0);">登录</a></li>
+        <li><a href="javascript:void(0);">注册</a></li>
+        <li>
+            <a href="javascript:void(0);">用户名</a>
+            <div>
+                <a href="javascript:void(0);">我的采美</a>
+                <a href="javascript:void(0);">机构资料</a>
+                <a href="javascript:void(0);">我的机构</a>
+                <a href="javascript:void(0);">店铺管理</a>
+                <a href="javascript:void(0);">退出登录</a>
+            </div>
+        </li>
+        <li><a href="javascript:void(0);">我的订单</a></li>
+        <li class="qr-code">
+            <a href="javascript:void(0);">采美365公众号</a>
+            <div class="hover">
+                <img src="/img/home/qr_code_caimei365.jpg" alt="采美365网"/>
+                <p>扫描关注<br/>获取更多优惠信息</p>
+            </div>
+        </li>
+        <li class="qr-code">
+            <a href="javascript:void(0);">呵呵商城</a>
+            <div class="hover">
+                <img src="/img/home/qr_code_hehe.jpg" alt="呵呵商城"/>
+                <p>扫描关注<br/>获取更多优惠信息</p>
+            </div>
+        </li>
+    </ul>
+
+    <nav>
+        <a href="/" class="logo">
+            <img src="/img/logo.png" alt="采美"/>
+            <span>生美/医美采购服务平台</span>
+        </a>
+        <div class="search">
+            <div>
+                <span class="current" data-id="0">产品</span>
+                <span data-id="1">供应商</span>
+                <span data-id="2">项目仪器</span>
+            </div>
+            <label>
+                <input type="text" placeholder="请输入关键字" th:value="${path}" />
+                <a href="javascript:void(0);">搜索</a>
+            </label>
+            <!-- 热门搜索关键词 -->
+            <div id="hotWord"></div>
+        </div>
+    </nav>
+<style>
+    ul{
+        width:1200px;
+        margin:0 auto;
+        display:-webkit-box;
+        display:-webkit-flex;
+        display:-ms-flexbox;
+        display:flex;
+        -webkit-box-pack:end;
+        -webkit-justify-content:flex-end;
+        justify-content:end;
+    }
+    li {
+        position: relative;
+        display: inline-block;
+        /*height: 40px;*/
+        line-height: 40px;
+        cursor: pointer;
+        font-size: 12px;
+        padding: 0 10px;
+        vertical-align: top;
+        font-weight: bold;
+        color: #333;
+    }
+   .qr-code .hover {
+
+   }
+</style>
+</header>

+ 2 - 0
src/main/resources/templates/index.html

@@ -6,6 +6,8 @@
           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
     <meta http-equiv="X-UA-Compatible" content="ie=edge">
     <meta http-equiv="X-UA-Compatible" content="ie=edge">
     <title>Document</title>
     <title>Document</title>
+    <script type="text/javascript" src="/lib/jquery-3.5.1.js"></script>
+    <script type="text/javascript" src="/js/base.js"></script>
 </head>
 </head>
 <body>
 <body>
     <!-- 引用头部 -->
     <!-- 引用头部 -->

+ 0 - 1
src/main/resources/templates/product/list.html

@@ -15,7 +15,6 @@
         <p th:text="${msg}"></p>
         <p th:text="${msg}"></p>
     </div>
     </div>
     <!-- 引入底部 -->
     <!-- 引入底部 -->
-    <!-- 引入底部 -->
     <div th:replace="components/footer"></div>
     <div th:replace="components/footer"></div>
 </body>
 </body>
 </html>
 </html>

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

@@ -1,7 +1,17 @@
 package com.caimei.www;
 package com.caimei.www;
 
 
+import lombok.Data;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest;
+import reactor.core.publisher.Flux;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
 
 
 @SpringBootTest
 @SpringBootTest
 class WwwApplicationTests {
 class WwwApplicationTests {
@@ -10,4 +20,82 @@ class WwwApplicationTests {
     void contextLoads() {
     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);
+    }
+
 }
 }