Authored by 胡古飞

添加ufo库存索引

... ... @@ -6,6 +6,11 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UfoStorageMapper {
int selectCount();
List<Storage> selectPageList(@Param(value = "offset") int offset, @Param(value = "pageSize") int pageSize);
int deleteByPrimaryKey(Integer id);
int insertSelective(Storage record);
... ... @@ -20,4 +25,5 @@ public interface UfoStorageMapper {
List<Storage> selectListByStorageIdList(@Param("storageIdList") List<Integer> storageIdList);
}
\ No newline at end of file
... ...
package com.yoho.search.dal;
import com.yoho.search.base.bo.UfoStorageMinPrice;
import com.yoho.search.dal.model.ufo_product.StoragePrice;
import org.apache.ibatis.annotations.Param;
... ... @@ -27,4 +28,6 @@ public interface UfoStoragePriceMapper {
List<StoragePrice> selectByProductIdList(List<Integer> idList);
// 尺码的当前最低现货价
List<UfoStorageMinPrice> selectStorageMinPriceList(@Param(value = "storageIds") List<Integer> storageIds);
}
\ No newline at end of file
... ...
... ... @@ -17,6 +17,18 @@
suggest_high_price
</sql>
<select id="selectCount" resultType="java.lang.Integer" timeout="20000">
select count(*) from storage
</select>
<select id="selectPageList" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List"/>
from storage
order by id
limit #{offset},#{pageSize}
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
... ...
... ... @@ -19,6 +19,11 @@
<result column="region" property="region" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="UfoStorageMinPriceMap" type="com.yoho.search.base.bo.UfoStorageMinPrice">
<id column="storage_id" property="storageId" jdbcType="INTEGER"/>
<result column="availableNowPrice" property="availableNowPrice" jdbcType="DECIMAL"/>
</resultMap>
<sql id="Base_Column_List">
id,skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status, update_time,
create_time,is_hide,pre_sale_flag,region
... ... @@ -229,4 +234,20 @@
#{item}
</foreach>
</select>
<select id="selectStorageMinPriceList" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List"/>
from storage_price
where
storage_id in
<foreach item="item" index="storageIds" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
and pre_sale_flag not in(5,6)
and status = 1
and is_hide = 0
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.search.consumer.index.fullbuild.ufo;
import com.yoho.search.base.bo.UfoStorageMinPrice;
import com.yoho.search.consumer.index.fullbuild.IIndexBuilder;
import com.yoho.search.consumer.service.bo.ufo.UfoStorageIndexBO;
import com.yoho.search.consumer.service.bo.ufo.UfoStoragePriceIndexBO;
import com.yoho.search.dal.UfoStorageMapper;
import com.yoho.search.dal.UfoStoragePriceMapper;
import com.yoho.search.dal.model.ufo_product.*;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class UfoStorageIndexBuilder extends IIndexBuilder {
@Autowired
private UfoStorageMapper ufoStorageMapper;
@Autowired
private UfoStoragePriceMapper ufoStoragePriceMapper;
@Override
public int getTotalCount() throws Exception {
return ufoStorageMapper.selectCount();
}
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
List<Storage> storages = ufoStorageMapper.selectPageList(offset, limit);
return this.buildUfoStorageIndexBOList(storages);
}
@Override
public String getId(Object object) {
return ((UfoStoragePriceIndexBO) object).getId().toString();
}
public List<UfoStorageIndexBO> buildUfoStorageIndexBOListByIds(List<Integer> storagesIds) {
if (storagesIds == null || storagesIds.isEmpty()) {
return new ArrayList<>();
}
List<Storage> storages = ufoStorageMapper.selectListByStorageIdList(storagesIds);
return this.buildUfoStorageIndexBOList(storages);
}
public List<UfoStorageIndexBO> buildUfoStorageIndexBOList(List<Storage> storages) {
if (CollectionUtils.isEmpty(storages)) {
return new ArrayList<>();
}
List<Integer> storageIds = storages.stream().map(a -> a.getId()).collect(Collectors.toList());
Map<Integer, BigDecimal> availableNowPriceMap = this.buildAvailableNowPriceMap(storageIds);
// 构建结果
List<UfoStorageIndexBO> results = new ArrayList<>();
for (Storage storage : storages) {
UfoStorageIndexBO ufoStorageIndexBO = new UfoStorageIndexBO();
BeanUtils.copyProperties(storage, ufoStorageIndexBO);
ufoStorageIndexBO.setAvailableNowPrice(availableNowPriceMap.get(storage.getId()));
results.add(ufoStorageIndexBO);
}
return results;
}
private Map<Integer, BigDecimal> buildAvailableNowPriceMap(List<Integer> storageIds) {
List<UfoStorageMinPrice> storageMinPriceList = ufoStoragePriceMapper.selectStorageMinPriceList(storageIds);
return storageMinPriceList.stream().collect(Collectors.toMap(UfoStorageMinPrice::getStorageId,UfoStorageMinPrice::getAvailableNowPrice));
}
}
... ...
... ... @@ -34,7 +34,6 @@ public class UfoStorageMqListener extends AbstractMqListener {
ufoIndexUpdateHelper.updateUfoIndexByUfoProductId(storage.getProductId());
ufo2YohoIndexUpdateHelper.updateYohoIndex(storage.getProductId());
}
}
@Override
... ...
... ... @@ -122,6 +122,7 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SORT);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_COLOR);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_SIZE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_STORAGE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_STORAGE_PRICE);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX);
logger.info("executeUfoIndex end----[end={}][cost={}]", System.currentTimeMillis(), (System.currentTimeMillis() - begin));
... ...
{
"ufostorageindex": {
"_all":{
"enabled":false
},
"_source":{
"enabled":true
},
"properties": {
"id": {
"type": "integer"
},
"productId": {
"type": "integer"
},
"goodsId": {
"type": "integer"
},
"sizeId": {
"type": "integer"
},
"storageNum": {
"type": "integer"
},
"suggestLowPrice": {
"type": "double"
},
"suggestHighPrice": {
"type": "double"
},
"availableNowPrice": {
"type": "double"
}
}
}
}
\ No newline at end of file
... ...
package com.yoho.search.consumer.service.bo.ufo;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class UfoStorageIndexBO {
private Integer id;
private Integer productId;
private Integer goodsId;
private Short sizeId;
private Integer storageNum;
private BigDecimal suggestLowPrice;
private BigDecimal suggestHighPrice;
// 现货最低价
private BigDecimal availableNowPrice;
}
... ...
... ... @@ -823,6 +823,20 @@
</index>
<index>
<name>ufostorageindex</name>
<properties>
<property key="number_of_shards" value="1"/>
<property key="number_of_replicas" value="auto"/>
<property key="refresh_interval" value="10s"/>
<property key="translog.flush_threshold_size" value="100mb"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.ufo.UfoStorageIndexBuilder</builderClass>
<mappingFile>esmapping/ufostorageindex.json</mappingFile>
<analysisFile>analysis/default.yml</analysisFile>
<rebuildPageSize>2500</rebuildPageSize>
</index>
<index>
<name>ufostoragepriceindex</name>
<properties>
<property key="number_of_shards" value="1"/>
... ...
... ... @@ -828,6 +828,20 @@
</index>
<index>
<name>ufostorageindex</name>
<properties>
<property key="number_of_shards" value="1"/>
<property key="number_of_replicas" value="auto"/>
<property key="refresh_interval" value="${search.index.refresh_interval}"/>
<property key="translog.flush_threshold_size" value="${search.index.translog.flush_threshold_size}"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.ufo.UfoStorageIndexBuilder</builderClass>
<mappingFile>esmapping/ufostorageindex.json</mappingFile>
<analysisFile>analysis/default.yml</analysisFile>
<rebuildPageSize>${search.index.batch.limit}</rebuildPageSize>
</index>
<index>
<name>ufostoragepriceindex</name>
<properties>
<property key="number_of_shards" value="1"/>
... ...