Authored by chenchao

add average price 4 limit

... ... @@ -7,6 +7,7 @@ import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.request.StoragePriceBo;
import com.yohobuy.ufo.model.request.product.PriceTrendBO;
import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
import com.yohobuy.ufo.model.request.product.SecondhandInfoReqBo;
import com.yohobuy.ufo.model.response.ProductDetailResp;
... ... @@ -72,7 +73,10 @@ public class ProductProxyService extends AbsProxyService{
private static final String UFO_SECONDHAND_COPYINFO= "ufo.secondhand.copyInfo";
private static final String BATCH_UPDATE_SKUP_DEPOTNO = "ufo.product.updateSkupDepotNo"; // 根据库存的鉴定室
// 根据库存的鉴定室
private static final String BATCH_UPDATE_SKUP_DEPOTNO = "ufo.product.updateSkupDepotNo";
//sku平均价
private static final String API_AVERAGE_PRICE_OF_MONTHLY = "ufo.product.getAveragePriceOfMonthly";
public boolean subtractStorage(Integer productId, Integer skup){
... ... @@ -496,4 +500,22 @@ public class ProductProxyService extends AbsProxyService{
ApiResponse apiResponse = ufoServiceCaller.call(BATCH_UPDATE_SKUP_DEPOTNO, skupList, depotNum);
return apiResponse;
}
public BigDecimal getAveragePriceOfMonthly(int uid, int storageId){
final String api = API_AVERAGE_PRICE_OF_MONTHLY;
BigDecimal avg = null;
try {
PriceTrendBO avgPT = ufoServiceCaller.call(api, storageId);
if (avgPT != null) {
avg = new BigDecimal(avgPT.getPrice());
}
}catch (Exception ex){
logger.warn("in {} fail, uid {},storageId {}", api, uid, storageId, ex);
}finally {
return avg;
}
}
}
... ...
package com.yohoufo.order.service.proxy;
import com.yohoufo.order.BaseWebTest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
public class ProductProxyServiceTest extends BaseWebTest {
@Autowired
private ProductProxyService productProxyService;
@Test
public void testgetAveragePriceOfMonthly(){
int storageId = 10090560;
int uid =8888;
BigDecimal avg = productProxyService.getAveragePriceOfMonthly(uid, storageId);
System.out.println("in testgetAveragePriceOfMonthly avg "+ avg);
}
}
... ...
... ... @@ -136,4 +136,8 @@ ip.port.uic.server = java-yoho-uic.test3.ingress.dev.yohocorp.com
ufo.nfc.syncBlockChain.url=http://192.168.102.49:3030/api/addItem
ufo.invite.productSortLimit=16,20,40
alipay.transfer.notifyurl=http://testapi.yohops.com/payment/alipay_transfer_notify
\ No newline at end of file
alipay.transfer.notifyurl=http://testapi.yohops.com/payment/alipay_transfer_notify
# Unionpay
unionpay.env=00
unionpay.notifyurl=http://testapi.yohops.com/payment/ufo_unionpay_notify
\ No newline at end of file
... ...
... ... @@ -2,12 +2,12 @@ package com.yohoufo.product.controller;
import com.yoho.tools.docs.ApiOperation;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.response.ProductDetailResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.common.utils.DateUtil;
import com.yohobuy.ufo.model.request.product.PriceTrendBO;
import com.yohoufo.product.model.PriceTrendResp;
import com.yohoufo.product.service.impl.ProductPriceService;
import org.slf4j.Logger;
... ... @@ -52,4 +52,12 @@ public class ProductPriceController {
List<GoodsSize> resp = productPriceService.queryProductSizeById(productId);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product size data").build();
}
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.getAveragePriceOfMonthly")
public PriceTrendBO getAveragePriceOfMonthly(int storageId){
LOG.info("in ufo.product.getAveragePriceOfMonthly storageId {}", storageId);
return productPriceService.getAveragePriceOfMonthly(storageId);
}
}
... ...
package com.yohoufo.product.model;
import com.alibaba.fastjson.annotation.JSONField;
public class PriceTrendBO {
@JSONField(name = "date")
private String date;
@JSONField(name = "price")
private String price;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
package com.yohoufo.product.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.yohobuy.ufo.model.request.product.PriceTrendBO;
import java.math.BigDecimal;
import java.util.List;
... ...
... ... @@ -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;
}
}
... ...
... ... @@ -17,7 +17,6 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
... ... @@ -38,7 +37,6 @@ import com.yoho.core.common.helpers.ImagesHelper;
import com.yoho.core.config.ConfigReader;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.GoodsBO;
import com.yohobuy.ufo.model.GoodsImageBO;
import com.yohobuy.ufo.model.GoodsSize;
... ... @@ -88,7 +86,7 @@ import com.yohoufo.dal.product.model.SelfSizeUid;
import com.yohoufo.dal.product.model.Size;
import com.yohoufo.dal.product.model.Storage;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.model.PriceTrendBO;
import com.yohobuy.ufo.model.request.product.PriceTrendBO;
import com.yohoufo.product.model.ProductSeriesTemplate;
import com.yohoufo.product.model.ProductSortTemplate;
import com.yohoufo.product.model.SkupDetailForScreenInfo;
... ...