Authored by mali

搜索词

1 package com.yohoufo.dal.product; 1 package com.yohoufo.dal.product;
2 2
3 import com.yohoufo.dal.product.model.SearchWord; 3 import com.yohoufo.dal.product.model.SearchWord;
  4 +import org.apache.ibatis.annotations.Param;
4 5
5 import java.util.List; 6 import java.util.List;
6 7
@@ -8,5 +9,5 @@ import java.util.List; @@ -8,5 +9,5 @@ import java.util.List;
8 * Created by li.ma on 2018/9/27. 9 * Created by li.ma on 2018/9/27.
9 */ 10 */
10 public interface SearchWordMapper { 11 public interface SearchWordMapper {
11 - List<SearchWord> selectAll(); 12 + List<SearchWord> selectAll(@Param("clientType")Integer clientType, @Param("wordType")Integer wordType);
12 } 13 }
@@ -10,6 +10,14 @@ @@ -10,6 +10,14 @@
10 </resultMap> 10 </resultMap>
11 11
12 <select id="selectAll" resultMap="BaseResultMap"> 12 <select id="selectAll" resultMap="BaseResultMap">
13 - select id, search_word, order_by, create_time, update_time from hot_search_word order by order_by DESC 13 + select id, search_word, order_by, create_time, update_time from hot_search_word
  14 + where 1 = 1
  15 + <if test="clientType != null">
  16 + AND (client_type = #{clientType, jdbcType=INTEGER} or client_type = 2)
  17 + </if>
  18 + <if test="wordType != null">
  19 + AND word_type = #{wordType, jdbcType=INTEGER}
  20 + </if>
  21 + order by order_by DESC LIMIT 20
14 </select> 22 </select>
15 </mapper> 23 </mapper>
@@ -11,6 +11,7 @@ import org.slf4j.Logger; @@ -11,6 +11,7 @@ import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.web.bind.annotation.RequestMapping; 13 import org.springframework.web.bind.annotation.RequestMapping;
  14 +import org.springframework.web.bind.annotation.RequestParam;
14 import org.springframework.web.bind.annotation.RestController; 15 import org.springframework.web.bind.annotation.RestController;
15 16
16 import java.util.List; 17 import java.util.List;
@@ -23,6 +24,10 @@ public class HotSearchWordController { @@ -23,6 +24,10 @@ public class HotSearchWordController {
23 24
24 private final Logger LOG = LoggerFactory.getLogger(HotSearchWordController.class); 25 private final Logger LOG = LoggerFactory.getLogger(HotSearchWordController.class);
25 26
  27 + private final Integer CLIENT_TYPE_APP = 0; // APP端
  28 +
  29 + private final Integer WORD_TYPE_HOT = 0; // 热搜词
  30 +
26 @Autowired 31 @Autowired
27 private HotSearchWordService hotSearchWordService; 32 private HotSearchWordService hotSearchWordService;
28 33
@@ -31,9 +36,19 @@ public class HotSearchWordController { @@ -31,9 +36,19 @@ public class HotSearchWordController {
31 @IgnoreSession 36 @IgnoreSession
32 @RequestMapping(params = "method=ufo.product.searchWord") 37 @RequestMapping(params = "method=ufo.product.searchWord")
33 @Cachable(expire = 180) 38 @Cachable(expire = 180)
34 - public ApiResponse querySearchWord() {  
35 - LOG.info("in method=ufo.product.searchWord");  
36 - List<SearchWordResp> resp = hotSearchWordService.querySearchWord(); 39 + public ApiResponse querySearchWord(@RequestParam(value = "client_type", required = false) Integer clientType,
  40 + @RequestParam(value = "word_type", required = false) Integer wordType) {
  41 + LOG.info("in method=ufo.product.searchWord clientType is {}, wordType is {}", clientType, wordType);
  42 +
  43 + if (null == clientType) {
  44 + clientType = CLIENT_TYPE_APP;
  45 + }
  46 +
  47 + if (null == wordType) {
  48 + wordType = WORD_TYPE_HOT;
  49 + }
  50 +
  51 + List<SearchWordResp> resp = hotSearchWordService.querySearchWord(clientType, wordType);
37 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("热搜词列表").build(); 52 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("热搜词列表").build();
38 } 53 }
39 } 54 }
@@ -17,8 +17,8 @@ public class HotSearchWordService { @@ -17,8 +17,8 @@ public class HotSearchWordService {
17 @Autowired 17 @Autowired
18 private SearchWordMapper searchWordMapper; 18 private SearchWordMapper searchWordMapper;
19 19
20 - public List<SearchWordResp> querySearchWord() {  
21 - List<SearchWord> searchWords = searchWordMapper.selectAll(); 20 + public List<SearchWordResp> querySearchWord(Integer clientType, Integer wordType) {
  21 + List<SearchWord> searchWords = searchWordMapper.selectAll(clientType, wordType);
22 22
23 List<SearchWordResp> result = new ArrayList<>(); 23 List<SearchWordResp> result = new ArrayList<>();
24 24