...
|
...
|
@@ -2,16 +2,18 @@ package com.yohoufo.product.service.impl; |
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yohobuy.ufo.model.GoodsSize;
|
|
|
import com.yohobuy.ufo.model.response.ProductDetailResp;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.product.PriceTrendMonthMapper;
|
|
|
import com.yohoufo.dal.product.SizeMapper;
|
|
|
import com.yohoufo.dal.product.StorageMapper;
|
|
|
import com.yohoufo.dal.product.model.PriceTrendModel;
|
|
|
import com.yohoufo.dal.product.model.Size;
|
|
|
import com.yohoufo.dal.product.model.Storage;
|
|
|
import com.yohoufo.product.helper.TrendTypeEnum;
|
|
|
import com.yohobuy.ufo.model.request.product.PriceTrendBO;
|
|
|
import com.yohoufo.product.model.PriceTrendResp;
|
|
|
import com.yohoufo.product.service.impl.pricetrend.PriceTrendServiceInf;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeansException;
|
...
|
...
|
@@ -20,10 +22,11 @@ import org.springframework.context.ApplicationContext; |
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Optional;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -41,6 +44,9 @@ public class ProductPriceService implements ApplicationContextAware{ |
|
|
@Autowired
|
|
|
private SizeMapper sizeMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private PriceTrendMonthMapper priceTrendMonthMapper;
|
|
|
|
|
|
public List<PriceTrendResp> queryProductPriceTrend(Integer productId, Integer sizeId, Integer trendType) {
|
|
|
String beanNameByCode = TrendTypeEnum.getBeanNameByCode(trendType);
|
|
|
|
...
|
...
|
@@ -90,4 +96,38 @@ public class ProductPriceService implements ApplicationContextAware{ |
|
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
beansOfType = applicationContext.getBeansOfType(PriceTrendServiceInf.class);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PriceTrendBO getAveragePriceOfMonthly(int storageId){
|
|
|
LOG.warn("in getAveragePriceOfMonthly, storageId {}", storageId);
|
|
|
Storage storage = storageMapper.selectByPrimaryKey(storageId);
|
|
|
|
|
|
if (storage == null){
|
|
|
LOG.warn("in getAveragePriceOfMonthly storage is null, storageId {}", storageId);
|
|
|
return null;
|
|
|
}
|
|
|
Integer prdId, sizeId;
|
|
|
List<PriceTrendModel> ptList = priceTrendMonthMapper.selectByProductIdAndSizeId(prdId=storage.getProductId(), sizeId=storage.getSizeId(), 30);
|
|
|
if (CollectionUtils.isEmpty(ptList)){
|
|
|
LOG.warn("in getAveragePriceOfMonthly, priceTrendMonthMapper.selectByProductIdAndSizeId empty, storageId {} prdId {} sizeId {}",
|
|
|
storageId, prdId, sizeId);
|
|
|
return null;
|
|
|
}
|
|
|
final int size = ptList.size();
|
|
|
LOG.info("in getAveragePriceOfMonthly, priceTrendMonthMapper.selectByProductIdAndSizeId storageId {} prdId {} sizeId {} total {}",
|
|
|
storageId, prdId, sizeId, size);
|
|
|
int cnt = 0;
|
|
|
BigDecimal total = BigDecimal.ZERO;
|
|
|
for(PriceTrendModel pt : ptList){
|
|
|
if (Objects.nonNull(pt.getSkuPrice())) {
|
|
|
total = total.add(pt.getSkuPrice());
|
|
|
cnt++;
|
|
|
}
|
|
|
}
|
|
|
BigDecimal average = total.divide(new BigDecimal(cnt),2, BigDecimal.ROUND_HALF_UP);
|
|
|
PriceTrendBO priceTrendBO = new PriceTrendBO();
|
|
|
priceTrendBO.setPrice(average.toPlainString());
|
|
|
return priceTrendBO;
|
|
|
}
|
|
|
} |
...
|
...
|
|