Browse Source

格式优化

zhijiezhao 2 years ago
parent
commit
6cfcf7f259

+ 8 - 5
src/main/java/com/caimei365/commodity/controller/SearchProductApi.java

@@ -225,30 +225,33 @@ public class SearchProductApi {
 
     /**
      * 统计关键词及次数
+     *
      * @param fromType
      * @param path
      * @param keyword
      * @return
      */
     @GetMapping("/con/keyword")
-    public ResponseJson conKeyword(Integer fromType,String path,String keyword){
-       return ResponseJson.success(searchProductService.conKeyword(fromType,path,keyword));
+    public ResponseJson conKeyword(Integer fromType, String path, String keyword) {
+        return ResponseJson.success(searchProductService.conKeyword(fromType, path, keyword));
     }
 
     /**
      * 获取已加入关键词库的关键词进行搜索联动
      * 从redis获取,获取不到则去数据库获取
+     *
      * @return
      */
     @PostMapping("/get/keyword/list")
-    public ResponseJson<List<SearchKeywordyVo>> getKeywordList(SearchFrequencyVo searchKeywordyVo){
-        if(StringUtils.isEmpty(searchKeywordyVo.getKeyword())){
+    public ResponseJson<List<SearchKeywordyVo>> getKeywordList(SearchFrequencyVo searchKeywordyVo) {
+        if (StringUtils.isEmpty(searchKeywordyVo.getKeyword())) {
             return ResponseJson.error("请输入关键词");
         }
         return ResponseJson.success(searchProductService.getKeywordList(searchKeywordyVo.getKeyword()));
     }
+
     @GetMapping("/conKeyWord")
-    public void conKeyWord(){
+    public void conKeyWord() {
         searchProductService.conKeyWord();
     }
 

+ 6 - 6
src/main/java/com/caimei365/commodity/mapper/SearchFrequencyMapper.java

@@ -10,16 +10,16 @@ import java.util.List;
 @Mapper
 public interface SearchFrequencyMapper {
 
-        List<SearchFrequencyVo>  getAll();
+    List<SearchFrequencyVo> getAll();
 
-        List<SearchFrequencyVo>  getInfoBykeyword(String keyword, Integer fromSearch);
+    List<SearchFrequencyVo> getInfoBykeyword(String keyword, Integer fromSearch);
 
-        void saveInfo(SearchFrequencyVo searchFrequencyVo);
+    void saveInfo(SearchFrequencyVo searchFrequencyVo);
 
-        void upFrequencyById(Integer id,Integer frequency);
+    void upFrequencyById(Integer id, Integer frequency);
 
-        List<SearchKeywordyVo> getKeywordList(@Param("keyword")String keyword);
+    List<SearchKeywordyVo> getKeywordList(@Param("keyword") String keyword);
 
-        List<SearchKeywordyVo> getvalueList(@Param("keyword") String keyword);
+    List<SearchKeywordyVo> getvalueList(@Param("keyword") String keyword);
 
 }

+ 19 - 11
src/main/java/com/caimei365/commodity/service/SearchProductService.java

@@ -27,13 +27,13 @@ public interface SearchProductService {
      * @param sortType  升降序0/1
      * @return JsonStr(list)
      */
-    ResponseJson<String> queryProductByKeyword(String keyword, String brandIds,Integer identity,Integer newFlag,Integer promotionFlag, int pageNum, int pageSize, String sortField, Integer sortType);
+    ResponseJson<String> queryProductByKeyword(String keyword, String brandIds, Integer identity, Integer newFlag, Integer promotionFlag, int pageNum, int pageSize, String sortField, Integer sortType);
 
     /**
      * 根据分类Id搜索商品
      *
-     * @param id     bigTypeID/smallTypeID/tinyTypeID
-     * @param idType id类型:1一级分类,2二级分类,3三级分类
+     * @param id        bigTypeID/smallTypeID/tinyTypeID
+     * @param idType    id类型:1一级分类,2二级分类,3三级分类
      * @param identity: 0个人,1协销,2会员机构,3供应商,4普通机构
      * @param pageNum   页码
      * @param pageSize  每页数量
@@ -41,7 +41,7 @@ public interface SearchProductService {
      * @param sortType  升降序0/1
      * @return JsonStr(list)
      */
-    ResponseJson<String> queryProductByType(Integer id, Integer idType, String brandIds,Integer identity,Integer newFlag,Integer promotionFlag, int pageNum, int pageSize, String sortField, Integer sortType);
+    ResponseJson<String> queryProductByType(Integer id, Integer idType, String brandIds, Integer identity, Integer newFlag, Integer promotionFlag, int pageNum, int pageSize, String sortField, Integer sortType);
 
     /**
      * 根据小程序运营分类Id搜索商品
@@ -59,8 +59,8 @@ public interface SearchProductService {
     /**
      * 根据供应商Id搜索商品(商铺内搜索)
      *
-     * @param id       供应商Id
-     * @param keyword  搜索关键字
+     * @param id        供应商Id
+     * @param keyword   搜索关键字
      * @param identity  用户身份 1:协销, 2:会员机构
      * @param pageNum   页码
      * @param pageSize  每页数量
@@ -72,42 +72,50 @@ public interface SearchProductService {
 
     /**
      * 根据用户ID查找历史记录
+     *
      * @param userId 用户Id
      */
     ResponseJson<List<SearchHistoryPo>> getSearchHistory(Integer userId);
+
     /**
      * 保存搜索历史记录
+     *
      * @param userId  用户Id
      * @param keyword 搜索关键字
      */
     ResponseJson<Void> addSearchHistory(Integer userId, String keyword);
+
     /**
      * 根据用户ID删除历史记录
+     *
      * @param userId 用户Id
      */
     ResponseJson<Void> deleteSearchHistory(Integer userId);
+
     /**
      * 产品仪器热搜词
      */
     ResponseJson<Map<String, Object>> getHotSearchTerms();
 
-    ResponseJson<Set<HashMap<String, Object>>> queryBrand(String keyword, Integer id, Integer idType, Integer newFlag , Integer promotionFlag, Integer identity);
+    ResponseJson<Set<HashMap<String, Object>>> queryBrand(String keyword, Integer id, Integer idType, Integer newFlag, Integer promotionFlag, Integer identity);
+
     /**
      * 统计关键词及次数
+     *
      * @param fromType
      * @param path
      * @param keyword
      * @return
      */
-     ResponseJson conKeyword(Integer fromType,String path,String keyword);
+    ResponseJson conKeyword(Integer fromType, String path, String keyword);
 
     /**
      * 获取已加入关键词库的关键词进行搜索联动
      * 从redis获取,获取不到则去数据库获取
+     *
      * @return
      */
-      List<SearchKeywordyVo> getKeywordList(String keyword);
-
-       void conKeyWord();
+    List<SearchKeywordyVo> getKeywordList(String keyword);
 
+    void conKeyWord();
 }

+ 29 - 29
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -61,6 +61,7 @@ public class SearchProductServiceImpl implements SearchProductService {
 
     @Autowired
     private RedisService redisService;
+
     /**
      * 根据关键词搜索商品
      *
@@ -605,26 +606,29 @@ public class SearchProductServiceImpl implements SearchProductService {
         });
         return productHotSearch;
     }
+
     /**
      * 统计关键词及次数
+     *
      * @param fromType
      * @param path
      * @param keyword
      * @return
      */
-    public ResponseJson conKeyword(Integer fromType,String path,String keyword){
-        Date date=new Date();
+    @Override
+    public ResponseJson conKeyword(Integer fromType, String path, String keyword) {
+        Date date = new Date();
         SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
         sf.format(date);
         //根据关键词和来源查询数据库是否存在(存在来源也相同时增加次数,存在但来源不同时和不存在则新增)
-        List<SearchFrequencyVo> searchFrequencyVoList = searchFrequencyMapper.getInfoBykeyword(keyword,fromType);
-        if(null!= searchFrequencyVoList && searchFrequencyVoList.size()>0){
+        List<SearchFrequencyVo> searchFrequencyVoList = searchFrequencyMapper.getInfoBykeyword(keyword, fromType);
+        if (null != searchFrequencyVoList && searchFrequencyVoList.size() > 0) {
             //存在 统计次数
-           Integer frequency= searchFrequencyVoList.get(0).getFrequency()+1;
-            searchFrequencyMapper.upFrequencyById(searchFrequencyVoList.get(0).getId(),frequency);
-        }else{
+            Integer frequency = searchFrequencyVoList.get(0).getFrequency() + 1;
+            searchFrequencyMapper.upFrequencyById(searchFrequencyVoList.get(0).getId(), frequency);
+        } else {
             //不存在 新增
-            SearchFrequencyVo sea=new SearchFrequencyVo();
+            SearchFrequencyVo sea = new SearchFrequencyVo();
             sea.setKeyword(keyword);
             sea.setFrequency(1);
             sea.setPath(path);
@@ -638,44 +642,40 @@ public class SearchProductServiceImpl implements SearchProductService {
     /**
      * 获取已加入关键词库的关键词进行搜索联动
      * 从redis获取,获取不到则去数据库获取
+     *
      * @return
      */
     @Override
-    public List<SearchKeywordyVo> getKeywordList(String keyword){
+    public List<SearchKeywordyVo> getKeywordList(String keyword) {
         //先从reids中获取keyword值,不存在时在查询数据库
-        List<SearchKeywordyVo> searchFrequencyVos=new ArrayList<>();
-        if(redisService.getExpireTime(keyword)>0){
+        List<SearchKeywordyVo> searchFrequencyVos = new ArrayList<>();
+        if (redisService.getExpireTime(keyword) > 0) {
             log.info("-------------获取redis中的数据--------------");
-            searchFrequencyVos= com.alibaba.fastjson.JSONArray.parseArray(redisService.get(keyword).toString(),SearchKeywordyVo.class);
-        }
-        else{
+            searchFrequencyVos = com.alibaba.fastjson.JSONArray.parseArray(redisService.get(keyword).toString(), SearchKeywordyVo.class);
+        } else {
             log.info("-------------获取数据库中的数据--------------");
             searchFrequencyVos = searchFrequencyMapper.getKeywordList(keyword);
         }
         return searchFrequencyVos;
     }
+
     /**
      * redis缓存关键词(把所有的关键词整合到一个字符串中)
      * 用时从redis取出转成list集合返回给前端进行联动
      */
-    public void conKeyWord(){
+    @Override
+    public void conKeyWord() {
         List<SearchKeywordyVo> keywordList = searchFrequencyMapper.getKeywordList(null);
-        for (SearchKeywordyVo searchFrequency:keywordList) {
-            String str=searchFrequency.getKeyword();
-            String key="";
-            for(int i=0;i<str.length();i++){
-                key+=str.charAt(i);
+        for (SearchKeywordyVo searchFrequency : keywordList) {
+            String str = searchFrequency.getKeyword();
+            String key = "";
+            for (int i = 0; i < str.length(); i++) {
+                key += str.charAt(i);
                 List<SearchKeywordyVo> searchFrequencyVos = searchFrequencyMapper.getvalueList(key);
-                String keyword = com.alibaba.fastjson.JSONObject.toJSONString(searchFrequencyVos);//有值的字段才转
-                redisService.set(key,keyword,60L * 60 * 24 * 30);
+                //有值的字段才转
+                String keyword = com.alibaba.fastjson.JSONObject.toJSONString(searchFrequencyVos);
+                redisService.set(key, keyword, 60L * 60 * 24 * 30);
             }
         }
-        System.out.println(redisService.getExpireTime("恩"));
-        System.out.println(redisService.get("恩"));
-        System.out.println(redisService.getExpireTime("光"));
-        System.out.println(redisService.get("光"));
-//        System.out.println(redisService.getExpireTime("keyword"));
-//        String key=redisService.get("keyword").toString();
-//        System.out.println(key);
     }
 }

+ 31 - 27
src/main/resources/mapper/SearchFrequencyMapper.xml

@@ -1,44 +1,48 @@
 <?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.caimei365.commodity.mapper.SearchFrequencyMapper">
-         <select id="getAll" resultType="com.caimei365.commodity.model.vo.SearchFrequencyVo">
-             select
-                    id,
-                    fromSearch,
-                    path,
-                    keyword,
-                    frequency,
-                    searchTime,
-                    trueStatus
-              from cm_user_search_frequency
-         </select>
+    <select id="getAll" resultType="com.caimei365.commodity.model.vo.SearchFrequencyVo">
+        select id,
+               fromSearch,
+               path,
+               keyword,
+               frequency,
+               searchTime,
+               trueStatus
+        from cm_user_search_frequency
+    </select>
+
     <select id="getInfoBykeyword" resultType="com.caimei365.commodity.model.vo.SearchFrequencyVo">
-        select
-            id,
-            fromSearch,
-            path,
-            keyword,
-            frequency,
-            searchTime,
-            trueStatus
+        select id,
+               fromSearch,
+               path,
+               keyword,
+               frequency,
+               searchTime,
+               trueStatus
         from cm_user_search_frequency
-        where keyword=#{keyword}
-        and   fromSearch=#{fromSearch}
+        where keyword = #{keyword}
+          and fromSearch = #{fromSearch}
     </select>
+
     <insert id="saveInfo" parameterType="com.caimei365.commodity.model.vo.SearchFrequencyVo">
-        insert into cm_user_search_frequency(fromSearch,path,keyword,frequency,searchTime)
-        values (#{fromSearch},#{path},#{keyword},#{frequency},#{searchTime})
+        insert into cm_user_search_frequency(fromSearch, path, keyword, frequency, searchTime)
+        values (#{fromSearch}, #{path}, #{keyword}, #{frequency}, #{searchTime})
 
     </insert>
+
     <update id="upFrequencyById">
-        update cm_user_search_frequency set frequency=#{frequency} where id=#{id}
+        update cm_user_search_frequency
+        set frequency=#{frequency}
+        where id = #{id}
     </update>
+
     <select id="getKeywordList" resultType="com.caimei365.commodity.model.vo.SearchKeywordyVo">
         select
-            keyword
+        keyword
         from cm_user_search_frequency
         where trueStatus=1
-          and   delStatus=1
+        and delStatus=1
         <if test="keyword != null and keyword != ''">
             and keyword like concat('%', #{keyword},'%')
         </if>
@@ -49,7 +53,7 @@
         keyword
         from cm_user_search_frequency
         where trueStatus=1
-        and   delStatus=1
+        and delStatus=1
         and keyword is not null
         <if test="keyword != null and keyword != ''">
             and keyword like concat(#{keyword},'%')