Toggle navigation
Toggle navigation
This project
Loading...
Sign in
yoho-search
/
yoho-search-consumer
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
wangnan
8 years ago
Commit
f5dae2987b20ef546c6e05bde5df8df9eff6eb48
1 parent
4416c81a
productpool增量更新速度优化
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
32 deletions
consumer/src/main/java/com/yoho/search/mq/ProductPoolDetailMqListener.java
consumer/src/main/java/com/yoho/search/mq/ProductPoolDetailMqListener.java
View file @
f5dae29
...
...
@@ -3,13 +3,8 @@ package com.yoho.search.mq;
import
com.alibaba.fastjson.JSONObject
;
import
com.rabbitmq.client.Channel
;
import
com.yoho.error.event.SearchEvent
;
import
com.yoho.search.dal.model.ProductPool
;
import
com.yoho.search.dal.model.ProductPoolDetail
;
import
com.yoho.search.dal.model.ProductPoolDetailSkn
;
import
com.yoho.search.dal.service.ProductIndexService
;
import
com.yoho.search.dal.service.ProductPoolDetailService
;
import
com.yoho.search.dal.service.ProductPoolService
;
import
com.yoho.search.dal.service.ProductService
;
import
com.yoho.search.dal.model.*
;
import
com.yoho.search.dal.service.*
;
import
com.yoho.search.index.service.IYohoIndexService
;
import
com.yoho.search.utils.ConvertUtils
;
import
com.yoho.search.utils.EventReportEnum
;
...
...
@@ -50,6 +45,12 @@ public class ProductPoolDetailMqListener extends AbstractMqListener implements C
@Autowired
private
ProductPoolService
productPoolService
;
@Autowired
private
ProductPriceService
productPriceService
;
@Autowired
private
ProductSizesService
productSizesService
;
@Override
public
void
onMessage
(
Message
message
,
Channel
channel
)
throws
Exception
{
...
...
@@ -141,35 +142,62 @@ public class ProductPoolDetailMqListener extends AbstractMqListener implements C
}
private
void
updateProductPoolIndex
(
ProductPoolDetail
productPoolDetail
,
long
begin
,
final
String
key
)
{
//
更新productPool
//
拼装productPool索引数据
Map
<
String
,
Object
>
indexData
=
new
HashMap
<>();
ProductPool
productPool
=
productPoolService
.
getById
(
productPoolDetail
.
getId
());
if
(
productPool
==
null
){
return
;
//1)来自ProductPoolDetail表数据
indexData
.
put
(
"id"
,
productPoolDetail
.
getId
());
indexData
.
put
(
"poolId"
,
productPoolDetail
.
getPoolId
());
indexData
.
put
(
"productSkn"
,
productPoolDetail
.
getProductSkn
());
//2)来自product表数据
Product
product
=
productService
.
getBySkn
(
productPoolDetail
.
getProductSkn
());
if
(
product
!=
null
){
indexData
.
put
(
"productId"
,
product
.
getId
());
indexData
.
put
(
"sales"
,
product
.
getIsSales
());
indexData
.
put
(
"brandId"
,
product
.
getBrandId
());
indexData
.
put
(
"status"
,
product
.
getStatus
());
indexData
.
put
(
"attribute"
,
product
.
getAttribute
());
indexData
.
put
(
"smallSortId"
,
product
.
getSmallSortId
());
indexData
.
put
(
"middleSortId"
,
product
.
getMiddleSortId
());
indexData
.
put
(
"maxSortId"
,
product
.
getMaxSortId
());
indexData
.
put
(
"gender"
,
product
.
getGender
());
// 计算is_outlets
if
(
product
.
getIsOutlets
()
!=
null
)
{
if
(
product
.
getIsOutlets
().
equals
(
"Y"
))
{
indexData
.
put
(
"isOutlets"
,
1
);
}
else
{
indexData
.
put
(
"isOutlets"
,
2
);
}
}
//3)来自product_price表
ProductPrice
productPrice
=
productPriceService
.
getById
(
product
.
getId
());
indexData
.
put
(
"marketPrice"
,
productPrice
.
getMarketPrice
());
indexData
.
put
(
"salesPrice"
,
productPrice
.
getSalesPrice
());
indexData
.
put
(
"vipDiscountType"
,
productPrice
.
getVipDiscountType
());
double
SalesPrice
=
productPrice
.
getSalesPrice
().
doubleValue
();
double
MarketPice
=
productPrice
.
getMarketPrice
().
doubleValue
();
// 计算is_discount
if
(
SalesPrice
<
MarketPice
)
{
indexData
.
put
(
"isDiscount"
,
"Y"
);
}
else
{
indexData
.
put
(
"isDiscount"
,
"N"
);
}
//4)来自product_sizes视图
ProductSizes
productSizes
=
productSizesService
.
getById
(
product
.
getId
());
indexData
.
put
(
"storageNum"
,
productSizes
.
getStorageNum
());
indexData
.
put
(
"salesNum"
,
productSizes
.
getSalesNum
());
indexData
.
put
(
"sizeIds"
,
productSizes
.
getSizeIds
());
}
indexData
.
put
(
"id"
,
productPool
.
getId
());
indexData
.
put
(
"poolId"
,
productPool
.
getPoolId
());
indexData
.
put
(
"productSkn"
,
productPool
.
getProductSkn
());
indexData
.
put
(
"productId"
,
productPool
.
getProductId
());
indexData
.
put
(
"sales"
,
productPool
.
getSales
());
indexData
.
put
(
"brandId"
,
productPool
.
getBrandId
());
indexData
.
put
(
"status"
,
productPool
.
getStatus
());
indexData
.
put
(
"attribute"
,
productPool
.
getAttribute
());
indexData
.
put
(
"smallSortId"
,
productPool
.
getSmallSortId
());
indexData
.
put
(
"middleSortId"
,
productPool
.
getMiddleSortId
());
indexData
.
put
(
"maxSortId"
,
productPool
.
getMaxSortId
());
indexData
.
put
(
"gender"
,
productPool
.
getGender
());
indexData
.
put
(
"storageNum"
,
productPool
.
getStorageNum
());
indexData
.
put
(
"salesNum"
,
productPool
.
getSalesNum
());
indexData
.
put
(
"marketPrice"
,
productPool
.
getMarketPrice
());
indexData
.
put
(
"vipDiscountType"
,
productPool
.
getVipDiscountType
());
indexData
.
put
(
"isDiscount"
,
productPool
.
getIsDiscount
());
indexData
.
put
(
"isOutlets"
,
productPool
.
getIsOutlets
());
indexData
.
put
(
"sizeIds"
,
productPool
.
getSizeIds
());
try
{
indexService
.
addIndexData
(
ISearchConstans
.
INDEX_NAME_PRODUCT_POOL
,
productPool
.
getId
().
toString
(),
indexData
);
indexService
.
addIndexData
(
ISearchConstans
.
INDEX_NAME_PRODUCT_POOL
,
productPool
Detail
.
getId
().
toString
(),
indexData
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"[func=update
Index][step=error][indexName={}][id={}][cost={}ms][error={}]"
,
ISearchConstans
.
INDEX_NAME_PRODUCT_POOL
,
productPoo
l
.
getId
().
toString
(),
logger
.
error
(
"[func=update
ProductPoolIndex][step=error][indexName={}][id={}][cost={}ms][error={}]"
,
ISearchConstans
.
INDEX_NAME_PRODUCT_POOL
,
productPoolDetai
l
.
getId
().
toString
(),
(
System
.
currentTimeMillis
()
-
begin
),
e
.
getMessage
());
}
}
...
...
Please
register
or
login
to post a comment