Authored by 胡古飞

SKN销售类目相关代码提交

package com.yoho.search.dal;
import java.util.List;
import com.yoho.search.dal.model.SalesCategory;
public interface SalesCategoryMapper {
int deleteByPrimaryKey(Integer categoryId);
int insert(SalesCategory record);
int insertSelective(SalesCategory record);
SalesCategory selectByPrimaryKey(Integer categoryId);
List<SalesCategory> selectAll();
int updateByPrimaryKeySelective(SalesCategory record);
int updateByPrimaryKey(SalesCategory record);
}
\ No newline at end of file
... ...
<?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.yoho.search.dal.SalesCategoryMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SalesCategory">
<id column="category_id" property="categoryId" jdbcType="INTEGER" />
<result column="category_name" property="categoryName" jdbcType="VARCHAR" />
<result column="relation_parameter" property="relationParameter" jdbcType="VARCHAR" />
<result column="relation_url" property="relationUrl" jdbcType="VARCHAR" />
<result column="parent_id" property="parentId" jdbcType="INTEGER" />
<result column="order_by" property="orderBy" jdbcType="INTEGER" />
<result column="icon" property="icon" jdbcType="VARCHAR" />
<result column="category_code" property="categoryCode" jdbcType="VARCHAR" />
<result column="state" property="state" jdbcType="INTEGER" />
<result column="level_number" property="levelNumber" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="app_type" property="appType" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List">
category_id, category_name, relation_parameter,
relation_url, parent_id, order_by,
icon, category_code, state,
level_number, create_time, app_type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap"
parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from sales_category
where category_id = #{categoryId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from
sales_category
where category_id = #{categoryId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.model.SalesCategory">
insert into sales_category
(category_id, category_name,
relation_parameter,
relation_url,
parent_id, order_by,
icon, category_code, state,
level_number,
create_time, app_type
)
values (#{categoryId,jdbcType=INTEGER},
#{categoryName,jdbcType=VARCHAR},
#{relationParameter,jdbcType=VARCHAR},
#{relationUrl,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER},
#{orderBy,jdbcType=INTEGER},
#{icon,jdbcType=VARCHAR},
#{categoryCode,jdbcType=VARCHAR}, #{state,jdbcType=INTEGER},
#{levelNumber,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER},
#{appType,jdbcType=TINYINT}
)
</insert>
<insert id="insertSelective" parameterType="com.yoho.search.model.SalesCategory">
insert into sales_category
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="categoryId != null">
category_id,
</if>
<if test="categoryName != null">
category_name,
</if>
<if test="relationParameter != null">
relation_parameter,
</if>
<if test="relationUrl != null">
relation_url,
</if>
<if test="parentId != null">
parent_id,
</if>
<if test="orderBy != null">
order_by,
</if>
<if test="icon != null">
icon,
</if>
<if test="categoryCode != null">
category_code,
</if>
<if test="state != null">
state,
</if>
<if test="levelNumber != null">
level_number,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="appType != null">
app_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="categoryId != null">
#{categoryId,jdbcType=INTEGER},
</if>
<if test="categoryName != null">
#{categoryName,jdbcType=VARCHAR},
</if>
<if test="relationParameter != null">
#{relationParameter,jdbcType=VARCHAR},
</if>
<if test="relationUrl != null">
#{relationUrl,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
#{parentId,jdbcType=INTEGER},
</if>
<if test="orderBy != null">
#{orderBy,jdbcType=INTEGER},
</if>
<if test="icon != null">
#{icon,jdbcType=VARCHAR},
</if>
<if test="categoryCode != null">
#{categoryCode,jdbcType=VARCHAR},
</if>
<if test="state != null">
#{state,jdbcType=INTEGER},
</if>
<if test="levelNumber != null">
#{levelNumber,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
<if test="appType != null">
#{appType,jdbcType=TINYINT},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.model.SalesCategory">
update sales_category
<set>
<if test="categoryName != null">
category_name = #{categoryName,jdbcType=VARCHAR},
</if>
<if test="relationParameter != null">
relation_parameter =
#{relationParameter,jdbcType=VARCHAR},
</if>
<if test="relationUrl != null">
relation_url = #{relationUrl,jdbcType=VARCHAR},
</if>
<if test="parentId != null">
parent_id = #{parentId,jdbcType=INTEGER},
</if>
<if test="orderBy != null">
order_by = #{orderBy,jdbcType=INTEGER},
</if>
<if test="icon != null">
icon = #{icon,jdbcType=VARCHAR},
</if>
<if test="categoryCode != null">
category_code = #{categoryCode,jdbcType=VARCHAR},
</if>
<if test="state != null">
state = #{state,jdbcType=INTEGER},
</if>
<if test="levelNumber != null">
level_number = #{levelNumber,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="appType != null">
app_type = #{appType,jdbcType=TINYINT},
</if>
</set>
where category_id = #{categoryId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.model.SalesCategory">
update
sales_category
set category_name = #{categoryName,jdbcType=VARCHAR},
relation_parameter = #{relationParameter,jdbcType=VARCHAR},
relation_url = #{relationUrl,jdbcType=VARCHAR},
parent_id =
#{parentId,jdbcType=INTEGER},
order_by = #{orderBy,jdbcType=INTEGER},
icon = #{icon,jdbcType=VARCHAR},
category_code =
#{categoryCode,jdbcType=VARCHAR},
state = #{state,jdbcType=INTEGER},
level_number = #{levelNumber,jdbcType=INTEGER},
create_time =
#{createTime,jdbcType=INTEGER},
app_type = #{appType,jdbcType=TINYINT}
where category_id = #{categoryId,jdbcType=INTEGER}
</update>
<select id="selectAll" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List" />
from sales_category
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.search.consumer.index.increment;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.service.logic.SalesCategoryLogicService;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.dal.model.SalesCategory;
@Component
public class SalesCategoryMqListener extends AbstractMqListener implements ChannelAwareMessageListener {
private static final Logger logger = LoggerFactory.getLogger(RobotQuestionMqListener.class);
@Autowired
private IYohoIndexService indexService;
@Autowired
private SalesCategoryLogicService salesCategoryLogicService;
@Override
public void onMessage(Message message, Channel channel) throws Exception {
try {
String messageStr = new String(message.getBody(), "UTF-8");
logger.info("[model=SalesCategoryMqListener] [message={}]", messageStr);
// 如果在重建索引等待
this.waitingRebuildingIndex();
JSONObject json = JSONObject.parseObject(messageStr);
if (ISearchConstants.ACTION_DELETE.equals(json.getString("action"))) {
deleteData(json.getString("data"));
} else if (ISearchConstants.ACTION_UPDATE.equals(json.getString("action"))) {
updateData(json.getObject("data", Map.class));
} else {
updateData(json.getObject("data", Map.class));
}
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.ROBOTQUESTION_MQLISTENER_ONMESSAGE.getEventName(), EventReportEnum.ROBOTQUESTION_MQLISTENER_ONMESSAGE
.getFunctionName(), EventReportEnum.ROBOTQUESTION_MQLISTENER_ONMESSAGE.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
Thread.sleep(1000);
throw e;
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void updateData(final Map data) throws Exception {
SalesCategory salesCategory = new SalesCategory();
salesCategory = (SalesCategory) ConvertUtils.toJavaBean(salesCategory, data);
if (salesCategory == null || salesCategory.getCategoryId() == null) {
return;
}
salesCategoryLogicService.saveOrUpdate(salesCategory);
}
public void deleteData(final String id) throws Exception {
if (StringUtils.isBlank(id)) {
return;
}
salesCategoryLogicService.deleteById(Integer.valueOf(id));
}
}
... ...
... ... @@ -871,6 +871,10 @@
"type": "integer"
}
}
},
"physicalChannels": {
"type": "string",
"analyzer":"comma_spliter"
}
}
}
... ...
... ... @@ -24,7 +24,7 @@ public class ProductIndexService {
@SuppressWarnings({ "rawtypes", "unchecked" })
public Map<String, Object> beanToMap(ProductIndexBO productIndexBO) {
//对productIndexBO做特殊处理
// 对productIndexBO做特殊处理
specialDealLogicService.specialDealProductIndex(productIndexBO);
Map map = new HashMap();
... ... @@ -187,6 +187,7 @@ public class ProductIndexService {
map.put("tblCountryId", productIndexBO.getTblCountryId());
map.put("tblCountryName", productIndexBO.getTblCountryName());
map.put("pools", productIndexBO.getPools());
map.put("physicalChannels", productIndexBO.getPhysicalChannels());
return map;
}
... ...
package com.yoho.search.consumer.service.base;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.dal.SalesCategoryMapper;
import com.yoho.search.dal.model.SalesCategory;
@Component
public class SalesCategoryService {
@Autowired
private SalesCategoryMapper salesCategoryMapper;
public SalesCategory selectById(Integer categoryId) {
return salesCategoryMapper.selectByPrimaryKey(categoryId);
}
public int deleteById(Integer categoryId) {
return salesCategoryMapper.deleteByPrimaryKey(categoryId);
}
public int saveOrUpdate(SalesCategory salesCategory) {
if (salesCategory.getCategoryId() == null || salesCategoryMapper.selectByPrimaryKey(salesCategory.getCategoryId()) == null) {
return salesCategoryMapper.insert(salesCategory);
} else {
return salesCategoryMapper.updateByPrimaryKey(salesCategory);
}
}
public List<SalesCategory> selectAll() {
return salesCategoryMapper.selectAll();
}
}
... ...
... ... @@ -84,6 +84,9 @@ public class ProductIBO implements Serializable {
// from quanqiugou
private String isGlobal = "N";
// from sales_category
private String physicalChannels;
public Integer getId() {
return id;
}
... ... @@ -604,4 +607,12 @@ public class ProductIBO implements Serializable {
this.isGlobal = isGlobal;
}
public String getPhysicalChannels() {
return physicalChannels;
}
public void setPhysicalChannels(String physicalChannels) {
this.physicalChannels = physicalChannels;
}
}
\ No newline at end of file
... ...
... ... @@ -44,7 +44,7 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
private String standardOnlyNames;
// from product_sizes
//private BigDecimal salesNum;
// private BigDecimal salesNum;
private BigDecimal storageNum;
private String isSoonSoldOut;
private String isSoldOut;
... ... @@ -52,7 +52,7 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
private String sizeIds;
private String sizeNames;
//from product_15day_salesnum
// from product_15day_salesnum
private Integer salesNum;
// from product_styles
... ... @@ -87,17 +87,16 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
private String isStudentRebate;
//form storage
// form storage
private Integer storageUpdateTime;
//from tbl_product
// from tbl_product
private Integer tblCountryId;
private String tblCountryName;
private String productFeatureFactor;
//
// from product_pool_detail
private JSONArray pools;
// get
... ... @@ -461,4 +460,5 @@ public class ProductIndexBO extends ProductIBO implements Serializable {
public void setPools(JSONArray pools) {
this.pools = pools;
}
}
\ No newline at end of file
... ...
package com.yoho.search.consumer.service.logic;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.consumer.service.base.SalesCategoryService;
import com.yoho.search.dal.model.SalesCategory;
@Component
public class SalesCategoryLogicService {
@Autowired
private SalesCategoryService salesCategoryService;
// 一级销售类目和物理小分类之间的关系
private Map<String, Set<Integer>> physicalChannelToSortIds;
public void init() {
Map<String, Set<Integer>> temps = new ConcurrentHashMap<String, Set<Integer>>();
List<SalesCategory> allSalesCategory = salesCategoryService.selectAll();
for (SalesCategory salesCategory : allSalesCategory) {
if (salesCategory.getState() == null || salesCategory.getState() == 0) {
continue;
}
// 获取一级销售类目
String categoryCode = salesCategory.getCategoryCode();
if (StringUtils.isBlank(categoryCode)) {
continue;
}
String[] categorys = categoryCode.split(",", 2);
if (categorys.length != 2) {
continue;
}
String physicalChannel = categorys[0];
// 获取全部物理分类
String relation_parameter = salesCategory.getRelationParameter();
if (StringUtils.isBlank(relation_parameter)) {
continue;
}
String[] smallSortIds = relation_parameter.split(",");
Set<Integer> results = temps.get(physicalChannel);
if (results == null) {
results = new HashSet<Integer>();
temps.put(physicalChannel, results);
}
for (String smallSortId : smallSortIds) {
results.add(Integer.valueOf(smallSortId));
}
}
physicalChannelToSortIds = temps;
}
public SalesCategory selectById(Integer categoryId) {
return salesCategoryService.selectById(categoryId);
}
public int deleteById(Integer categoryId) {
return salesCategoryService.deleteById(categoryId);
}
public int saveOrUpdate(SalesCategory salesCategory) {
return salesCategoryService.saveOrUpdate(salesCategory);
}
/**
* 根据小物理分类获取对应的一级销售类目
*
* @param smallSortId
* @return
*/
public List<String> getPhysicalChannelsBySmallSortId(Integer smallSortId) {
if (smallSortId == null) {
return new ArrayList<String>();
}
if (physicalChannelToSortIds == null || physicalChannelToSortIds.isEmpty()) {
init();
}
List<String> channels = new ArrayList<String>();
for (Map.Entry<String, Set<Integer>> entry : physicalChannelToSortIds.entrySet()) {
if (entry.getValue().contains(smallSortId)) {
channels.add(entry.getKey());
}
}
return channels;
}
}
... ...
package com.yoho.search.consumer.service.logic.tools;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -8,12 +10,15 @@ import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.bo.StorageSkuBO;
import com.yoho.search.consumer.service.logic.ForbidenSortBrandLogicService;
import com.yoho.search.consumer.service.logic.SalesCategoryLogicService;
@Service
public class SpecialDealLogicService {
@Autowired
private ForbidenSortBrandLogicService forbidenSortBrandLogicService;
@Autowired
private SalesCategoryLogicService salesCategoryLogicService;
private String specialDealAgeLevel(String ageLevel) {
if (StringUtils.isBlank(ageLevel)) {
... ... @@ -52,13 +57,15 @@ public class SpecialDealLogicService {
}
private int getIsForbiddenSortBrand(ProductIBO productIBO) {
boolean isForbidenSortBrand = forbidenSortBrandLogicService.isForbiddenSortBrand(productIBO.getMaxSortId(), productIBO.getMiddleSortId(),productIBO.getSmallSortId(), productIBO.getBrandId());
boolean isForbidenSortBrand = forbidenSortBrandLogicService.isForbiddenSortBrand(productIBO.getMaxSortId(), productIBO.getMiddleSortId(), productIBO.getSmallSortId(),
productIBO.getBrandId());
return isForbidenSortBrand ? 1 : 0;
}
/**
* 全量建索引時對PI的某些字段做特殊處
* 建索引时对Pi索引的字段做一些特殊处
*
* @param productIBO
*/
public void specialDealProductI(ProductIBO productIBO) {
// 1、处理ageLevel
... ... @@ -72,22 +79,25 @@ public class SpecialDealLogicService {
// 3、处理isForiddenSortBrand
int isForbiddenSortBrand = this.getIsForbiddenSortBrand(productIBO);
productIBO.setIsForbiddenSortBrand(isForbiddenSortBrand);
// 4、处理物理分类对应的销售分类
List<String> physicalChannels = salesCategoryLogicService.getPhysicalChannelsBySmallSortId(productIBO.getSmallSortId());
productIBO.setPhysicalChannels(StringUtils.join(physicalChannels, ","));
}
/**
* 全量建索引時對PI的某些字段做特殊處
* 建索引时对Pi索引的字段做一些特殊处
*
* @param productIndexBO
*/
public void specialDealProductIndex(ProductIndexBO productIndexBO) {
//1、处理其他信息
// 1、处理其他信息
this.specialDealProductI(productIndexBO);
//2、TODO OTHERS
// 2、TODO OTHERS
}
/**
* 全量建索引時對PI的某些字段做特殊處理
*
* 针对StorageSku索引做一些特殊处理
*/
public void specialDealStorageSku(StorageSkuBO storageSkuBO) {
storageSkuBO.setAgeLevel(specialDealAgeLevel(storageSkuBO.getAgeLevel()));
... ...
... ... @@ -81,6 +81,8 @@ public class GeneralDataBuilder {
productIndexBO.setCountryId(p.getCountryId());
// 是否分期全量要增加
productIndexBO.setIsInstalment(p.getIsInstalment());
// 一级销售分类
productIndexBO.setPhysicalChannels(p.getPhysicalChannels());
productIndexBOs.add(productIndexBO);
}
}
... ...
... ... @@ -68,6 +68,7 @@
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_helper" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_shops" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_shopsbrands" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_salescategory" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_tblbrand" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_tblsite" />
... ... @@ -129,6 +130,7 @@
<rabbit:listener queue-names="data_update_channel_producttiming" ref="productTimingMqListener" />
<rabbit:listener queue-names="data_update_channel_shops" ref="shopsMqListener" />
<rabbit:listener queue-names="data_update_channel_shopsbrands" ref="shopsBrandsMqListener" />
<rabbit:listener queue-names="data_update_channel_salescategory" ref="salescategoryMqListener" />
<rabbit:listener queue-names="data_update_channel_product" ref="productMqListener" />
<rabbit:listener queue-names="data_update_channel_product_0" ref="productMqListener0" />
... ...