Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ufo
/
ufo-platform
·
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
Plain Diff
Browse Files
Authored by
Lixiaodi
5 years ago
Commit
9370d12d91f2c6ccdcfd5987f4befeba831bcc1c
2 parents
b22cc317
326dc35d
Merge branch 'test6.9.22' of
http://git.yoho.cn/ufo/ufo-platform
into test6.9.22
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
8 deletions
coupon/pom.xml
coupon/src/main/java/com/yoho/ufo/coupon/service/ProductServiceCaller.java
coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java
coupon/src/main/java/com/yoho/ufo/coupon/util/Strings.java
coupon/pom.xml
View file @
9370d12
...
...
@@ -28,6 +28,10 @@
<artifactId>
coupon-ufo-model
</artifactId>
</dependency>
<dependency>
<groupId>
com.yoho.ufo.model
</groupId>
<artifactId>
product-ufo-model
</artifactId>
</dependency>
<dependency>
<groupId>
com.yoho.core
</groupId>
<artifactId>
yoho-core-dal
</artifactId>
</dependency>
...
...
coupon/src/main/java/com/yoho/ufo/coupon/service/ProductServiceCaller.java
0 → 100644
View file @
9370d12
package
com
.
yoho
.
ufo
.
coupon
.
service
;
import
com.yoho.core.rest.client.ServiceCaller
;
import
com.yoho.error.exception.ServiceException
;
import
com.yoho.ufo.coupon.service.impl.CouponServiceImpl
;
import
com.yoho.ufo.restapi.ApiResponse
;
import
com.yohobuy.ufo.model.request.brand.BrandSeriesResponseBo
;
import
com.yohobuy.ufo.model.response.productsort.ProductSortResponseBo
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
public
class
ProductServiceCaller
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CouponServiceImpl
.
class
);
@Autowired
private
ServiceCaller
serviceCaller
;
/**
* 品类 父id - 子id
* @param subIds
* @return
*/
public
List
<
String
>
getFullCategoryIdsBySubIds
(
List
<
Integer
>
subIds
)
{
ApiResponse
response
=
serviceCaller
.
call
(
"ufoPlatform.getBaseSortsById"
,
subIds
,
ApiResponse
.
class
);
List
<
ProductSortResponseBo
>
bos
=
(
List
<
ProductSortResponseBo
>)
response
.
getData
();
List
<
String
>
fullIds
=
bos
.
stream
().
map
(
bo
->
new
StringBuilder
().
append
(
bo
.
getParentId
()).
append
(
"-"
).
append
(
bo
.
getId
()).
toString
()).
collect
(
Collectors
.
toList
());
if
(
subIds
.
size
()
!=
fullIds
.
size
())
{
logger
.
warn
(
"not find product sort by :{},response:{}"
,
subIds
,
fullIds
);
throw
new
ServiceException
(
500
,
"未查询到父品类"
);
}
return
fullIds
;
}
/**
* 系列 品牌id-系列id
* @param subIds
* @return
*/
public
List
<
String
>
getFullSeriesIdsBySubIds
(
List
<
Integer
>
subIds
)
{
BrandSeriesResponseBo
[]
bos
=
serviceCaller
.
call
(
"ufoPlatform.getBrandSeriesByIds"
,
subIds
,
BrandSeriesResponseBo
[].
class
);
List
<
String
>
fullIds
=
Arrays
.
stream
(
bos
).
map
(
bo
->
new
StringBuilder
().
append
(
bo
.
getBrandId
()).
append
(
"-"
).
append
(
bo
.
getId
()).
toString
()).
collect
(
Collectors
.
toList
());
if
(
subIds
.
size
()
!=
fullIds
.
size
())
{
logger
.
warn
(
"not find series by: {},response: {}"
,
subIds
,
fullIds
);
throw
new
ServiceException
(
500
,
"未查询到系列所属品牌"
);
}
return
fullIds
;
}
}
...
...
coupon/src/main/java/com/yoho/ufo/coupon/service/impl/CouponServiceImpl.java
View file @
9370d12
...
...
@@ -11,6 +11,7 @@ import com.yoho.ufo.coupon.model.CouponAndProductConditions;
import
com.yoho.ufo.coupon.model.ProductCondition
;
import
com.yoho.ufo.coupon.model.ProductLimitType
;
import
com.yoho.ufo.coupon.service.ICouponService
;
import
com.yoho.ufo.coupon.service.ProductServiceCaller
;
import
com.yoho.ufo.coupon.service.builder.CouponAndProductConditionsBuilder
;
import
com.yoho.ufo.coupon.util.Strings
;
import
com.yoho.ufo.dal.CouponDisplayMapper
;
...
...
@@ -85,6 +86,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
@Autowired
private
ServiceCaller
serviceCaller
;
@Autowired
private
ProductServiceCaller
productServiceCaller
;
@Override
public
Class
getDataClass
()
{
return
(
Class
)
request
.
getAttribute
(
"exportClassType"
);
...
...
@@ -371,13 +375,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
}
}
ProductLimitType
limitType
=
ProductLimitType
.
find
(
coupon
.
getProductLimitType
());
if
(
limitType
==
ProductLimitType
.
Specific_Product
)
{
coupon
.
setProductLimitValue
(
Strings
.
listToDelimitedString
(
findProductIds
(
limitType
.
getLimitType
(),
productLimitList
)));
}
else
if
(
limitType
==
ProductLimitType
.
Exclude_Product
)
{
//兼容老版本,coupon.productLimitType == Exclude_Product,设置为 ALL
coupon
.
setProductLimitType
(
ProductLimitType
.
ALL
.
getLimitType
());
}
wrapProductLimitTypeAndValueIfNeed
(
coupon
,
productLimitList
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"coupon"
,
coupon
);
...
...
@@ -388,6 +386,30 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
return
new
ApiResponse
.
ApiResponseBuilder
().
data
(
jsonObject
).
build
();
}
/**
* 品类,系列 比较特殊,便于编辑定位,需要查询父id
*
* @param coupon
* @param productLimitList
*/
private
void
wrapProductLimitTypeAndValueIfNeed
(
Coupon
coupon
,
List
<
CouponProductLimit
>
productLimitList
)
{
ProductLimitType
limitType
=
ProductLimitType
.
find
(
coupon
.
getProductLimitType
());
if
(
limitType
==
ProductLimitType
.
Specific_Product
)
{
coupon
.
setProductLimitValue
(
Strings
.
listToDelimitedString
(
findProductIds
(
limitType
.
getLimitType
(),
productLimitList
)));
}
else
if
(
limitType
==
ProductLimitType
.
Exclude_Product
)
{
//兼容老版本,coupon.productLimitType == Exclude_Product,设置为 ALL
coupon
.
setProductLimitType
(
ProductLimitType
.
ALL
.
getLimitType
());
}
else
if
(
limitType
==
ProductLimitType
.
Specific_Category
)
{
List
<
Integer
>
subCategoryIds
=
Strings
.
split
(
coupon
.
getProductLimitValue
());
//返回全路径
coupon
.
setProductLimitValue
(
Strings
.
listToDelimitedString
(
productServiceCaller
.
getFullCategoryIdsBySubIds
(
subCategoryIds
)));
}
else
if
(
limitType
==
ProductLimitType
.
Specific_Series
)
{
List
<
Integer
>
subSeriesIds
=
Strings
.
split
(
coupon
.
getProductLimitValue
());
//返回全路径
coupon
.
setProductLimitValue
(
Strings
.
listToDelimitedString
(
productServiceCaller
.
getFullSeriesIdsBySubIds
(
subSeriesIds
)));
}
}
private
List
<
Integer
>
findProductIds
(
int
limitType
,
List
<
CouponProductLimit
>
productLimitList
)
{
if
(
CollectionUtils
.
isNotEmpty
(
productLimitList
))
{
return
productLimitList
.
stream
().
filter
(
item
->
item
.
getLimitType
()
==
limitType
).
map
(
item
->
item
.
getProductId
()).
collect
(
Collectors
.
toList
());
...
...
coupon/src/main/java/com/yoho/ufo/coupon/util/Strings.java
View file @
9370d12
package
com
.
yoho
.
ufo
.
coupon
.
util
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Splitter
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
...
...
Please
register
or
login
to post a comment