Authored by Gino Zhang

Merge branch 'sales_category' of git.yoho.cn:yoho-search/yoho-search-consumer into sales_category

@@ -8,6 +8,8 @@ import java.util.Set; @@ -8,6 +8,8 @@ import java.util.Set;
8 import java.util.concurrent.ConcurrentHashMap; 8 import java.util.concurrent.ConcurrentHashMap;
9 9
10 import org.apache.commons.lang.StringUtils; 10 import org.apache.commons.lang.StringUtils;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
11 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Component; 14 import org.springframework.stereotype.Component;
13 15
@@ -17,20 +19,46 @@ import com.yoho.search.dal.model.SalesCategory; @@ -17,20 +19,46 @@ import com.yoho.search.dal.model.SalesCategory;
17 @Component 19 @Component
18 public class SalesCategoryLogicService { 20 public class SalesCategoryLogicService {
19 21
  22 + private static final Logger logger = LoggerFactory.getLogger(SalesCategoryLogicService.class);
  23 +
20 @Autowired 24 @Autowired
21 private SalesCategoryService salesCategoryService; 25 private SalesCategoryService salesCategoryService;
22 26
23 // 一级销售类目和物理小分类之间的关系 27 // 一级销售类目和物理小分类之间的关系
24 - private Map<String, Set<Integer>> physicalChannelToSortIds; 28 + private Map<Integer, Set<Integer>> physicalChannelToSortIds;
25 29
26 - public void doReload() {  
27 - Map<String, Set<Integer>> temps = new ConcurrentHashMap<String, Set<Integer>>();  
28 - List<SalesCategory> allSalesCategory = salesCategoryService.selectAll();  
29 - for (SalesCategory salesCategory : allSalesCategory) { 30 + // 判断是否是有效的有货物理分类
  31 + private boolean isLegalYohoCategory(SalesCategory salesCategory) {
30 if (salesCategory.getState() == null || salesCategory.getState() == 0) { 32 if (salesCategory.getState() == null || salesCategory.getState() == 0) {
  33 + return false;
  34 + }
  35 + // BLK的忽视
  36 + if (salesCategory.getAppType() == null || salesCategory.getAppType() == 1) {
  37 + return false;
  38 + }
  39 + return true;
  40 + }
  41 +
  42 + public void doReload() {
  43 + // 1、获取所有的销售分类
  44 + List<SalesCategory> salesCategorys = salesCategoryService.selectAll();
  45 +
  46 + // 2、过滤出所有有货的一级销售分类
  47 + List<Integer> yohoFirstPhysicalChannels = new ArrayList<Integer>();
  48 + for (SalesCategory salesCategory : salesCategorys) {
  49 + if (isLegalYohoCategory(salesCategory) && new Integer(0).equals(salesCategory.getParentId())) {
  50 + yohoFirstPhysicalChannels.add(salesCategory.getCategoryId());
  51 + }
  52 + }
  53 + // 3、获取一级销售分类对应的物理分类
  54 + Map<Integer, Set<Integer>> temps = new ConcurrentHashMap<Integer, Set<Integer>>();
  55 + for (SalesCategory salesCategory : salesCategorys) {
  56 + try {
  57 + // 1、判断销售类目是否合法
  58 + if (!isLegalYohoCategory(salesCategory)) {
31 continue; 59 continue;
32 } 60 }
33 - // 获取一级销售类目 61 + // 2、获取一级销售类目
34 String categoryCode = salesCategory.getCategoryCode(); 62 String categoryCode = salesCategory.getCategoryCode();
35 if (StringUtils.isBlank(categoryCode)) { 63 if (StringUtils.isBlank(categoryCode)) {
36 continue; 64 continue;
@@ -39,7 +67,11 @@ public class SalesCategoryLogicService { @@ -39,7 +67,11 @@ public class SalesCategoryLogicService {
39 if (categorys.length != 2) { 67 if (categorys.length != 2) {
40 continue; 68 continue;
41 } 69 }
42 - String physicalChannel = categorys[0]; 70 + // 3、判断分割出来的一级销售类目是否合法
  71 + Integer physicalChannel = Integer.valueOf(categorys[0]);
  72 + if(!yohoFirstPhysicalChannels.contains(physicalChannel)){
  73 + continue;
  74 + }
43 // 获取全部物理分类 75 // 获取全部物理分类
44 String relation_parameter = salesCategory.getRelationParameter(); 76 String relation_parameter = salesCategory.getRelationParameter();
45 if (StringUtils.isBlank(relation_parameter)) { 77 if (StringUtils.isBlank(relation_parameter)) {
@@ -54,6 +86,9 @@ public class SalesCategoryLogicService { @@ -54,6 +86,9 @@ public class SalesCategoryLogicService {
54 for (String smallSortId : smallSortIds) { 86 for (String smallSortId : smallSortIds) {
55 results.add(Integer.valueOf(smallSortId)); 87 results.add(Integer.valueOf(smallSortId));
56 } 88 }
  89 + } catch (Exception e) {
  90 + logger.error(e.getMessage(),e);
  91 + }
57 } 92 }
58 physicalChannelToSortIds = temps; 93 physicalChannelToSortIds = temps;
59 } 94 }
@@ -76,15 +111,15 @@ public class SalesCategoryLogicService { @@ -76,15 +111,15 @@ public class SalesCategoryLogicService {
76 * @param smallSortId 111 * @param smallSortId
77 * @return 112 * @return
78 */ 113 */
79 - public List<String> getPhysicalChannelsBySmallSortId(Integer smallSortId) { 114 + public List<Integer> getPhysicalChannelsBySmallSortId(Integer smallSortId) {
80 if (smallSortId == null) { 115 if (smallSortId == null) {
81 - return new ArrayList<String>(); 116 + return new ArrayList<Integer>();
82 } 117 }
83 if (physicalChannelToSortIds == null || physicalChannelToSortIds.isEmpty()) { 118 if (physicalChannelToSortIds == null || physicalChannelToSortIds.isEmpty()) {
84 doReload(); 119 doReload();
85 } 120 }
86 - List<String> channels = new ArrayList<String>();  
87 - for (Map.Entry<String, Set<Integer>> entry : physicalChannelToSortIds.entrySet()) { 121 + List<Integer> channels = new ArrayList<Integer>();
  122 + for (Map.Entry<Integer, Set<Integer>> entry : physicalChannelToSortIds.entrySet()) {
88 if (entry.getValue().contains(smallSortId)) { 123 if (entry.getValue().contains(smallSortId)) {
89 channels.add(entry.getKey()); 124 channels.add(entry.getKey());
90 } 125 }
@@ -81,7 +81,7 @@ public class SpecialDealLogicService { @@ -81,7 +81,7 @@ public class SpecialDealLogicService {
81 productIBO.setIsForbiddenSortBrand(isForbiddenSortBrand); 81 productIBO.setIsForbiddenSortBrand(isForbiddenSortBrand);
82 82
83 // 4、处理物理分类对应的销售分类 83 // 4、处理物理分类对应的销售分类
84 - List<String> physicalChannels = salesCategoryLogicService.getPhysicalChannelsBySmallSortId(productIBO.getSmallSortId()); 84 + List<Integer> physicalChannels = salesCategoryLogicService.getPhysicalChannelsBySmallSortId(productIBO.getSmallSortId());
85 productIBO.setPhysicalChannels(StringUtils.join(physicalChannels, ",")); 85 productIBO.setPhysicalChannels(StringUtils.join(physicalChannels, ","));
86 } 86 }
87 87