Authored by chenchao

add average price 4 limit

@@ -7,6 +7,7 @@ import com.yohobuy.ufo.model.order.bo.PrdPrice; @@ -7,6 +7,7 @@ import com.yohobuy.ufo.model.order.bo.PrdPrice;
7 import com.yohobuy.ufo.model.order.common.SkupStatus; 7 import com.yohobuy.ufo.model.order.common.SkupStatus;
8 import com.yohobuy.ufo.model.order.constants.SkupType; 8 import com.yohobuy.ufo.model.order.constants.SkupType;
9 import com.yohobuy.ufo.model.request.StoragePriceBo; 9 import com.yohobuy.ufo.model.request.StoragePriceBo;
  10 +import com.yohobuy.ufo.model.request.product.PriceTrendBO;
10 import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo; 11 import com.yohobuy.ufo.model.request.product.ProductImportTranItemBo;
11 import com.yohobuy.ufo.model.request.product.SecondhandInfoReqBo; 12 import com.yohobuy.ufo.model.request.product.SecondhandInfoReqBo;
12 import com.yohobuy.ufo.model.response.ProductDetailResp; 13 import com.yohobuy.ufo.model.response.ProductDetailResp;
@@ -72,7 +73,10 @@ public class ProductProxyService extends AbsProxyService{ @@ -72,7 +73,10 @@ public class ProductProxyService extends AbsProxyService{
72 73
73 private static final String UFO_SECONDHAND_COPYINFO= "ufo.secondhand.copyInfo"; 74 private static final String UFO_SECONDHAND_COPYINFO= "ufo.secondhand.copyInfo";
74 75
75 - private static final String BATCH_UPDATE_SKUP_DEPOTNO = "ufo.product.updateSkupDepotNo"; // 根据库存的鉴定室 76 + // 根据库存的鉴定室
  77 + private static final String BATCH_UPDATE_SKUP_DEPOTNO = "ufo.product.updateSkupDepotNo";
  78 + //sku平均价
  79 + private static final String API_AVERAGE_PRICE_OF_MONTHLY = "ufo.product.getAveragePriceOfMonthly";
76 80
77 public boolean subtractStorage(Integer productId, Integer skup){ 81 public boolean subtractStorage(Integer productId, Integer skup){
78 82
@@ -496,4 +500,22 @@ public class ProductProxyService extends AbsProxyService{ @@ -496,4 +500,22 @@ public class ProductProxyService extends AbsProxyService{
496 ApiResponse apiResponse = ufoServiceCaller.call(BATCH_UPDATE_SKUP_DEPOTNO, skupList, depotNum); 500 ApiResponse apiResponse = ufoServiceCaller.call(BATCH_UPDATE_SKUP_DEPOTNO, skupList, depotNum);
497 return apiResponse; 501 return apiResponse;
498 } 502 }
  503 +
  504 +
  505 + public BigDecimal getAveragePriceOfMonthly(int uid, int storageId){
  506 + final String api = API_AVERAGE_PRICE_OF_MONTHLY;
  507 + BigDecimal avg = null;
  508 + try {
  509 + PriceTrendBO avgPT = ufoServiceCaller.call(api, storageId);
  510 +
  511 + if (avgPT != null) {
  512 + avg = new BigDecimal(avgPT.getPrice());
  513 + }
  514 + }catch (Exception ex){
  515 + logger.warn("in {} fail, uid {},storageId {}", api, uid, storageId, ex);
  516 + }finally {
  517 + return avg;
  518 + }
  519 +
  520 + }
499 } 521 }
  1 +package com.yohoufo.order.service.proxy;
  2 +
  3 +import com.yohoufo.order.BaseWebTest;
  4 +import org.junit.Test;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +
  7 +import java.math.BigDecimal;
  8 +
  9 +public class ProductProxyServiceTest extends BaseWebTest {
  10 + @Autowired
  11 + private ProductProxyService productProxyService;
  12 +
  13 + @Test
  14 + public void testgetAveragePriceOfMonthly(){
  15 + int storageId = 10090560;
  16 + int uid =8888;
  17 + BigDecimal avg = productProxyService.getAveragePriceOfMonthly(uid, storageId);
  18 +
  19 + System.out.println("in testgetAveragePriceOfMonthly avg "+ avg);
  20 + }
  21 +}
@@ -137,3 +137,7 @@ ufo.nfc.syncBlockChain.url=http://192.168.102.49:3030/api/addItem @@ -137,3 +137,7 @@ ufo.nfc.syncBlockChain.url=http://192.168.102.49:3030/api/addItem
137 137
138 ufo.invite.productSortLimit=16,20,40 138 ufo.invite.productSortLimit=16,20,40
139 alipay.transfer.notifyurl=http://testapi.yohops.com/payment/alipay_transfer_notify 139 alipay.transfer.notifyurl=http://testapi.yohops.com/payment/alipay_transfer_notify
  140 +
  141 +# Unionpay
  142 +unionpay.env=00
  143 +unionpay.notifyurl=http://testapi.yohops.com/payment/ufo_unionpay_notify
@@ -2,12 +2,12 @@ package com.yohoufo.product.controller; @@ -2,12 +2,12 @@ package com.yohoufo.product.controller;
2 2
3 import com.yoho.tools.docs.ApiOperation; 3 import com.yoho.tools.docs.ApiOperation;
4 import com.yohobuy.ufo.model.GoodsSize; 4 import com.yohobuy.ufo.model.GoodsSize;
5 -import com.yohobuy.ufo.model.response.ProductDetailResp;  
6 import com.yohoufo.common.ApiResponse; 5 import com.yohoufo.common.ApiResponse;
7 import com.yohoufo.common.annotation.IgnoreSession; 6 import com.yohoufo.common.annotation.IgnoreSession;
8 import com.yohoufo.common.annotation.IgnoreSignature; 7 import com.yohoufo.common.annotation.IgnoreSignature;
9 import com.yohoufo.common.cache.Cachable; 8 import com.yohoufo.common.cache.Cachable;
10 import com.yohoufo.common.utils.DateUtil; 9 import com.yohoufo.common.utils.DateUtil;
  10 +import com.yohobuy.ufo.model.request.product.PriceTrendBO;
11 import com.yohoufo.product.model.PriceTrendResp; 11 import com.yohoufo.product.model.PriceTrendResp;
12 import com.yohoufo.product.service.impl.ProductPriceService; 12 import com.yohoufo.product.service.impl.ProductPriceService;
13 import org.slf4j.Logger; 13 import org.slf4j.Logger;
@@ -52,4 +52,12 @@ public class ProductPriceController { @@ -52,4 +52,12 @@ public class ProductPriceController {
52 List<GoodsSize> resp = productPriceService.queryProductSizeById(productId); 52 List<GoodsSize> resp = productPriceService.queryProductSizeById(productId);
53 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product size data").build(); 53 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product size data").build();
54 } 54 }
  55 +
  56 + @IgnoreSignature
  57 + @IgnoreSession
  58 + @RequestMapping(params = "method=ufo.product.getAveragePriceOfMonthly")
  59 + public PriceTrendBO getAveragePriceOfMonthly(int storageId){
  60 + LOG.info("in ufo.product.getAveragePriceOfMonthly storageId {}", storageId);
  61 + return productPriceService.getAveragePriceOfMonthly(storageId);
  62 + }
55 } 63 }
1 -package com.yohoufo.product.model;  
2 -  
3 -import com.alibaba.fastjson.annotation.JSONField;  
4 -  
5 -public class PriceTrendBO {  
6 -  
7 - @JSONField(name = "date")  
8 - private String date;  
9 -  
10 - @JSONField(name = "price")  
11 - private String price;  
12 -  
13 - public String getDate() {  
14 - return date;  
15 - }  
16 -  
17 - public void setDate(String date) {  
18 - this.date = date;  
19 - }  
20 -  
21 - public String getPrice() {  
22 - return price;  
23 - }  
24 -  
25 - public void setPrice(String price) {  
26 - this.price = price;  
27 - }  
28 -}  
1 package com.yohoufo.product.model; 1 package com.yohoufo.product.model;
2 2
3 import com.alibaba.fastjson.annotation.JSONField; 3 import com.alibaba.fastjson.annotation.JSONField;
  4 +import com.yohobuy.ufo.model.request.product.PriceTrendBO;
4 5
5 import java.math.BigDecimal; 6 import java.math.BigDecimal;
6 import java.util.List; 7 import java.util.List;
@@ -2,16 +2,18 @@ package com.yohoufo.product.service.impl; @@ -2,16 +2,18 @@ package com.yohoufo.product.service.impl;
2 2
3 import com.google.common.collect.Lists; 3 import com.google.common.collect.Lists;
4 import com.yohobuy.ufo.model.GoodsSize; 4 import com.yohobuy.ufo.model.GoodsSize;
5 -import com.yohobuy.ufo.model.response.ProductDetailResp;  
6 import com.yohoufo.common.utils.DateUtil; 5 import com.yohoufo.common.utils.DateUtil;
  6 +import com.yohoufo.dal.product.PriceTrendMonthMapper;
7 import com.yohoufo.dal.product.SizeMapper; 7 import com.yohoufo.dal.product.SizeMapper;
8 import com.yohoufo.dal.product.StorageMapper; 8 import com.yohoufo.dal.product.StorageMapper;
9 import com.yohoufo.dal.product.model.PriceTrendModel; 9 import com.yohoufo.dal.product.model.PriceTrendModel;
10 import com.yohoufo.dal.product.model.Size; 10 import com.yohoufo.dal.product.model.Size;
11 import com.yohoufo.dal.product.model.Storage; 11 import com.yohoufo.dal.product.model.Storage;
12 import com.yohoufo.product.helper.TrendTypeEnum; 12 import com.yohoufo.product.helper.TrendTypeEnum;
  13 +import com.yohobuy.ufo.model.request.product.PriceTrendBO;
13 import com.yohoufo.product.model.PriceTrendResp; 14 import com.yohoufo.product.model.PriceTrendResp;
14 import com.yohoufo.product.service.impl.pricetrend.PriceTrendServiceInf; 15 import com.yohoufo.product.service.impl.pricetrend.PriceTrendServiceInf;
  16 +import org.apache.commons.collections.CollectionUtils;
15 import org.slf4j.Logger; 17 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory; 18 import org.slf4j.LoggerFactory;
17 import org.springframework.beans.BeansException; 19 import org.springframework.beans.BeansException;
@@ -20,10 +22,11 @@ import org.springframework.context.ApplicationContext; @@ -20,10 +22,11 @@ import org.springframework.context.ApplicationContext;
20 import org.springframework.context.ApplicationContextAware; 22 import org.springframework.context.ApplicationContextAware;
21 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
22 24
  25 +import java.math.BigDecimal;
23 import java.util.ArrayList; 26 import java.util.ArrayList;
24 import java.util.List; 27 import java.util.List;
25 import java.util.Map; 28 import java.util.Map;
26 -import java.util.Optional; 29 +import java.util.Objects;
27 import java.util.stream.Collectors; 30 import java.util.stream.Collectors;
28 31
29 /** 32 /**
@@ -41,6 +44,9 @@ public class ProductPriceService implements ApplicationContextAware{ @@ -41,6 +44,9 @@ public class ProductPriceService implements ApplicationContextAware{
41 @Autowired 44 @Autowired
42 private SizeMapper sizeMapper; 45 private SizeMapper sizeMapper;
43 46
  47 + @Autowired
  48 + private PriceTrendMonthMapper priceTrendMonthMapper;
  49 +
44 public List<PriceTrendResp> queryProductPriceTrend(Integer productId, Integer sizeId, Integer trendType) { 50 public List<PriceTrendResp> queryProductPriceTrend(Integer productId, Integer sizeId, Integer trendType) {
45 String beanNameByCode = TrendTypeEnum.getBeanNameByCode(trendType); 51 String beanNameByCode = TrendTypeEnum.getBeanNameByCode(trendType);
46 52
@@ -90,4 +96,38 @@ public class ProductPriceService implements ApplicationContextAware{ @@ -90,4 +96,38 @@ public class ProductPriceService implements ApplicationContextAware{
90 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 96 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
91 beansOfType = applicationContext.getBeansOfType(PriceTrendServiceInf.class); 97 beansOfType = applicationContext.getBeansOfType(PriceTrendServiceInf.class);
92 } 98 }
  99 +
  100 +
  101 +
  102 + public PriceTrendBO getAveragePriceOfMonthly(int storageId){
  103 + LOG.warn("in getAveragePriceOfMonthly, storageId {}", storageId);
  104 + Storage storage = storageMapper.selectByPrimaryKey(storageId);
  105 +
  106 + if (storage == null){
  107 + LOG.warn("in getAveragePriceOfMonthly storage is null, storageId {}", storageId);
  108 + return null;
  109 + }
  110 + Integer prdId, sizeId;
  111 + List<PriceTrendModel> ptList = priceTrendMonthMapper.selectByProductIdAndSizeId(prdId=storage.getProductId(), sizeId=storage.getSizeId(), 30);
  112 + if (CollectionUtils.isEmpty(ptList)){
  113 + LOG.warn("in getAveragePriceOfMonthly, priceTrendMonthMapper.selectByProductIdAndSizeId empty, storageId {} prdId {} sizeId {}",
  114 + storageId, prdId, sizeId);
  115 + return null;
  116 + }
  117 + final int size = ptList.size();
  118 + LOG.info("in getAveragePriceOfMonthly, priceTrendMonthMapper.selectByProductIdAndSizeId storageId {} prdId {} sizeId {} total {}",
  119 + storageId, prdId, sizeId, size);
  120 + int cnt = 0;
  121 + BigDecimal total = BigDecimal.ZERO;
  122 + for(PriceTrendModel pt : ptList){
  123 + if (Objects.nonNull(pt.getSkuPrice())) {
  124 + total = total.add(pt.getSkuPrice());
  125 + cnt++;
  126 + }
  127 + }
  128 + BigDecimal average = total.divide(new BigDecimal(cnt),2, BigDecimal.ROUND_HALF_UP);
  129 + PriceTrendBO priceTrendBO = new PriceTrendBO();
  130 + priceTrendBO.setPrice(average.toPlainString());
  131 + return priceTrendBO;
  132 + }
93 } 133 }
@@ -17,7 +17,6 @@ import java.util.function.Function; @@ -17,7 +17,6 @@ import java.util.function.Function;
17 import java.util.stream.Collectors; 17 import java.util.stream.Collectors;
18 18
19 import org.apache.commons.collections.MapUtils; 19 import org.apache.commons.collections.MapUtils;
20 -import org.apache.commons.collections.map.HashedMap;  
21 import org.apache.commons.lang.ArrayUtils; 20 import org.apache.commons.lang.ArrayUtils;
22 import org.apache.commons.lang3.StringUtils; 21 import org.apache.commons.lang3.StringUtils;
23 import org.apache.commons.lang3.tuple.Pair; 22 import org.apache.commons.lang3.tuple.Pair;
@@ -38,7 +37,6 @@ import com.yoho.core.common.helpers.ImagesHelper; @@ -38,7 +37,6 @@ import com.yoho.core.common.helpers.ImagesHelper;
38 import com.yoho.core.config.ConfigReader; 37 import com.yoho.core.config.ConfigReader;
39 import com.yoho.core.dal.datasource.annotation.Database; 38 import com.yoho.core.dal.datasource.annotation.Database;
40 import com.yoho.error.exception.ServiceException; 39 import com.yoho.error.exception.ServiceException;
41 -import com.yoho.tools.common.beans.ApiResponse;  
42 import com.yohobuy.ufo.model.GoodsBO; 40 import com.yohobuy.ufo.model.GoodsBO;
43 import com.yohobuy.ufo.model.GoodsImageBO; 41 import com.yohobuy.ufo.model.GoodsImageBO;
44 import com.yohobuy.ufo.model.GoodsSize; 42 import com.yohobuy.ufo.model.GoodsSize;
@@ -88,7 +86,7 @@ import com.yohoufo.dal.product.model.SelfSizeUid; @@ -88,7 +86,7 @@ import com.yohoufo.dal.product.model.SelfSizeUid;
88 import com.yohoufo.dal.product.model.Size; 86 import com.yohoufo.dal.product.model.Size;
89 import com.yohoufo.dal.product.model.Storage; 87 import com.yohoufo.dal.product.model.Storage;
90 import com.yohoufo.dal.product.model.StoragePrice; 88 import com.yohoufo.dal.product.model.StoragePrice;
91 -import com.yohoufo.product.model.PriceTrendBO; 89 +import com.yohobuy.ufo.model.request.product.PriceTrendBO;
92 import com.yohoufo.product.model.ProductSeriesTemplate; 90 import com.yohoufo.product.model.ProductSeriesTemplate;
93 import com.yohoufo.product.model.ProductSortTemplate; 91 import com.yohoufo.product.model.ProductSortTemplate;
94 import com.yohoufo.product.model.SkupDetailForScreenInfo; 92 import com.yohoufo.product.model.SkupDetailForScreenInfo;