Authored by Lixiaodi

Merge branch 'test6.9.22' of http://git.yoho.cn/ufo/ufo-platform into test6.9.22

... ... @@ -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>
... ...
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;
}
}
... ...
... ... @@ -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());
... ...
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;
... ...