SearchController.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package com.uas.search.console.controller;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import org.apache.commons.collections.CollectionUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import com.uas.search.console.dao.ComponentSimpleInfoDao;
  13. import com.uas.search.console.model.ComponentSimpleInfo;
  14. import com.uas.search.model.PageParams;
  15. import com.uas.search.service.SearchService;
  16. /**
  17. * 搜索请求
  18. *
  19. * @author suntg
  20. * @since 2016年8月1日上午9:18:05
  21. */
  22. @Controller
  23. @RequestMapping("/search")
  24. public class SearchController {
  25. @Autowired
  26. private SearchService searchService;
  27. /**
  28. * 搜索产品类目
  29. *
  30. * @param keyword
  31. * @return
  32. */
  33. @RequestMapping("/kindIds")
  34. @ResponseBody
  35. public List<Long> seachKindIds(String keyword) {
  36. return searchService.getKindIds(keyword);
  37. }
  38. /**
  39. * 搜索产品类目
  40. *
  41. * @param keyword
  42. * @return
  43. */
  44. @RequestMapping("/kinds")
  45. @ResponseBody
  46. public List<Map<String, Object>> seachKinds(String keyword) {
  47. return searchService.getKinds(keyword);
  48. }
  49. /**
  50. * 搜索产品品牌id
  51. *
  52. * @param keyword
  53. * @return
  54. */
  55. @RequestMapping("/brandIds")
  56. @ResponseBody
  57. public List<Long> searchBrandIds(String keyword) {
  58. return searchService.getBrandIds(keyword);
  59. }
  60. /**
  61. * 搜索产品品牌
  62. *
  63. * @param keyword
  64. * @return
  65. */
  66. @RequestMapping("/brands")
  67. @ResponseBody
  68. public List<Map<String, Object>> searchBrand(String keyword) {
  69. return searchService.getBrands(keyword);
  70. }
  71. /**
  72. * 搜索产品id
  73. *
  74. * @param keyword
  75. * @return
  76. */
  77. @RequestMapping("/componentIds")
  78. @ResponseBody
  79. public Map<String, Object> searchComponentIds(String keyword) {
  80. return searchService.getComponentIds(keyword, new PageParams());
  81. }
  82. /**
  83. * 搜索产品
  84. *
  85. * @param keyword
  86. * @return
  87. */
  88. @Autowired
  89. private ComponentSimpleInfoDao componentDao;
  90. @RequestMapping("/components")
  91. @ResponseBody
  92. public List<ComponentSimpleInfo> searchComponents(String keyword) {
  93. PageParams pageParams = new PageParams();
  94. Map<String, Object> filters = new HashMap<>();
  95. // filters.put("pr_329", "HRC");
  96. // filters.put("20", "Fast Blow");
  97. pageParams.setFilters(filters);
  98. @SuppressWarnings("unchecked")
  99. List<Long> ids = (List<Long>) searchService.getComponentIds(keyword, pageParams).get("componentIds");
  100. if (CollectionUtils.isEmpty(ids)) {
  101. return new ArrayList<ComponentSimpleInfo>();
  102. }
  103. Long[] idsLong = new Long[ids.size()];
  104. int i = 0;
  105. for (Long id : ids) {
  106. idsLong[i++] = id;
  107. }
  108. return componentDao.findByIdsInOrder(idsLong);
  109. }
  110. /**
  111. * 统计器件的类目id
  112. *
  113. * @param keyword
  114. * @param brandId
  115. * @return
  116. */
  117. @RequestMapping("/kindIdsByComponent")
  118. @ResponseBody
  119. public Set<Long> searchKindIdsBySearchComponent(String keyword, String brandId) {
  120. return searchService.getKindIdsBySearchComponent(keyword, brandId);
  121. }
  122. /**
  123. * 统计器件的类目
  124. *
  125. * @param keyword
  126. * @param brandId
  127. * @return
  128. */
  129. @RequestMapping("/kindsByComponent")
  130. @ResponseBody
  131. public List<Map<String, Object>> searchKindsBySearchComponent(String keyword, String brandId) {
  132. return searchService.getKindsBySearchComponent(keyword, brandId);
  133. }
  134. /**
  135. * 统计器件的品牌id
  136. *
  137. * @param keyword
  138. * @param brandId
  139. * @return
  140. */
  141. @RequestMapping("/brandIdsByComponent")
  142. @ResponseBody
  143. public Set<Long> searchBrandIdsBySearchComponent(String keyword, String kindId) {
  144. return searchService.getBrandIdsBySearchComponent(keyword, kindId);
  145. }
  146. /**
  147. * 统计器件的品牌
  148. *
  149. * @param keyword
  150. * @param brandId
  151. * @return
  152. */
  153. @RequestMapping("/brandsByComponent")
  154. @ResponseBody
  155. public List<Map<String, Object>> searchBrandsBySearchComponent(String keyword, String kindId) {
  156. return searchService.getBrandsBySearchComponent(keyword, kindId);
  157. }
  158. /**
  159. * 联想词
  160. *
  161. * @param keyword
  162. * @return
  163. */
  164. @RequestMapping("/similarKeywords")
  165. @ResponseBody
  166. public List<String> getSimilarKeywords(String keyword) {
  167. return searchService.getSimilarKeywords(keyword);
  168. }
  169. /**
  170. * 器件原厂型号联想词
  171. *
  172. * @param componentCode
  173. * @return
  174. */
  175. @RequestMapping("/similarComponents")
  176. @ResponseBody
  177. public List<Map<String, Object>> getSimilarComponents(String componentCode) {
  178. return searchService.getSimilarComponents(componentCode);
  179. }
  180. /**
  181. * 器件品牌联想词
  182. *
  183. * @param componentCode
  184. * @return
  185. */
  186. @RequestMapping("/similarBrands")
  187. @ResponseBody
  188. public List<Map<String, Object>> getSimilarBrands(String brandName) {
  189. return searchService.getSimilarBrands(brandName);
  190. }
  191. }