|
@@ -4,10 +4,14 @@ import com.google.common.collect.Lists; |
|
@@ -4,10 +4,14 @@ import com.google.common.collect.Lists; |
4
|
import com.yohoufo.common.utils.DateUtil;
|
4
|
import com.yohoufo.common.utils.DateUtil;
|
5
|
import com.yohoufo.dal.product.PriceTrendHalfYearMapper;
|
5
|
import com.yohoufo.dal.product.PriceTrendHalfYearMapper;
|
6
|
import com.yohoufo.dal.product.model.PriceTrendModel;
|
6
|
import com.yohoufo.dal.product.model.PriceTrendModel;
|
|
|
7
|
+import org.apache.commons.collections.CollectionUtils;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.stereotype.Service;
|
9
|
import org.springframework.stereotype.Service;
|
9
|
|
10
|
|
|
|
11
|
+import java.math.BigDecimal;
|
10
|
import java.util.List;
|
12
|
import java.util.List;
|
|
|
13
|
+import java.util.Objects;
|
|
|
14
|
+import java.util.Optional;
|
11
|
|
15
|
|
12
|
/**
|
16
|
/**
|
13
|
* Created by li.ma on 2019/1/8.
|
17
|
* Created by li.ma on 2019/1/8.
|
|
@@ -17,9 +21,15 @@ public class PriceTrendHalfYearService implements PriceTrendServiceInf{ |
|
@@ -17,9 +21,15 @@ public class PriceTrendHalfYearService implements PriceTrendServiceInf{ |
17
|
@Autowired
|
21
|
@Autowired
|
18
|
private PriceTrendHalfYearMapper priceTrendHalfYearMapper;
|
22
|
private PriceTrendHalfYearMapper priceTrendHalfYearMapper;
|
19
|
|
23
|
|
|
|
24
|
+ private BigDecimal zeroPrice = new BigDecimal(0);
|
|
|
25
|
+
|
|
|
26
|
+ // 180天(最小颗粒度:3天);
|
20
|
public List<PriceTrendModel> queryProductPriceTrend(Integer productId, Integer sizeId) {
|
27
|
public List<PriceTrendModel> queryProductPriceTrend(Integer productId, Integer sizeId) {
|
21
|
if (null != productId) {
|
28
|
if (null != productId) {
|
22
|
- List<PriceTrendModel> priceTrendModels = priceTrendHalfYearMapper.selectByProductId(productId, sizeId, DateUtil.getTimeSecondOfDay(-180), DateUtil.getTimeSecondOfDay(0));
|
29
|
+ int timeSecondOfHalfYear = DateUtil.getTimeSecondOfDay(-180);
|
|
|
30
|
+ List<PriceTrendModel> priceTrendModels = priceTrendHalfYearMapper.selectByProductId(productId, sizeId, timeSecondOfHalfYear, DateUtil.getTimeSecondOfDay(0));
|
|
|
31
|
+
|
|
|
32
|
+ compeleteZeroPrice(priceTrendModels, timeSecondOfHalfYear, productId, sizeId);
|
23
|
|
33
|
|
24
|
priceTrendModels.stream().forEach(item -> {
|
34
|
priceTrendModels.stream().forEach(item -> {
|
25
|
item.setEndTime(null == item.getCreateTime() ? null : item.getCreateTime());
|
35
|
item.setEndTime(null == item.getCreateTime() ? null : item.getCreateTime());
|
|
@@ -27,10 +37,31 @@ public class PriceTrendHalfYearService implements PriceTrendServiceInf{ |
|
@@ -27,10 +37,31 @@ public class PriceTrendHalfYearService implements PriceTrendServiceInf{ |
27
|
});
|
37
|
});
|
28
|
|
38
|
|
29
|
return priceTrendModels;
|
39
|
return priceTrendModels;
|
|
|
40
|
+ }
|
30
|
|
41
|
|
|
|
42
|
+ return Lists.newArrayList();
|
|
|
43
|
+ }
|
31
|
|
44
|
|
|
|
45
|
+ //产品紧急变更需求 补全180天的数据,价格用零补充
|
|
|
46
|
+ private void compeleteZeroPrice(List<PriceTrendModel> priceTrendModels, int timeSecondOfHalfYear, Integer productId, Integer sizeId) {
|
|
|
47
|
+ if (CollectionUtils.isEmpty(priceTrendModels) || priceTrendModels.size() <= 1) {
|
|
|
48
|
+ return;
|
32
|
}
|
49
|
}
|
33
|
|
50
|
|
34
|
- return Lists.newArrayList();
|
51
|
+ Integer firstCreateTime = Optional.ofNullable(priceTrendModels.get(0)).map(PriceTrendModel::getCreateTime).orElse(null);
|
|
|
52
|
+ if (Objects.isNull(firstCreateTime)) { // 有脏数据 不用记日志,查询数据可以看出来
|
|
|
53
|
+ return;
|
|
|
54
|
+ }
|
|
|
55
|
+ List<PriceTrendModel> zeroPriceList = Lists.newArrayList();
|
|
|
56
|
+ for (int i = firstCreateTime - 259200; i >= timeSecondOfHalfYear; i -= 259200) {
|
|
|
57
|
+ zeroPriceList.add(new PriceTrendModel(productId, sizeId, zeroPrice, zeroPrice, i));
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ if (CollectionUtils.isEmpty(zeroPriceList)) {
|
|
|
61
|
+ return;
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
|
64
|
+ List<PriceTrendModel> reverse = Lists.reverse(zeroPriceList);
|
|
|
65
|
+ reverse.addAll(priceTrendModels);
|
35
|
}
|
66
|
}
|
36
|
} |
67
|
} |