...
|
...
|
@@ -4,10 +4,14 @@ import com.google.common.collect.Lists; |
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.product.PriceTrendHalfYearMapper;
|
|
|
import com.yohoufo.dal.product.model.PriceTrendModel;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* Created by li.ma on 2019/1/8.
|
...
|
...
|
@@ -17,9 +21,15 @@ public class PriceTrendHalfYearService implements PriceTrendServiceInf{ |
|
|
@Autowired
|
|
|
private PriceTrendHalfYearMapper priceTrendHalfYearMapper;
|
|
|
|
|
|
private BigDecimal zeroPrice = new BigDecimal(0);
|
|
|
|
|
|
// 180天(最小颗粒度:3天);
|
|
|
public List<PriceTrendModel> queryProductPriceTrend(Integer productId, Integer sizeId) {
|
|
|
if (null != productId) {
|
|
|
List<PriceTrendModel> priceTrendModels = priceTrendHalfYearMapper.selectByProductId(productId, sizeId, DateUtil.getTimeSecondOfDay(-180), DateUtil.getTimeSecondOfDay(0));
|
|
|
int timeSecondOfHalfYear = DateUtil.getTimeSecondOfDay(-180);
|
|
|
List<PriceTrendModel> priceTrendModels = priceTrendHalfYearMapper.selectByProductId(productId, sizeId, timeSecondOfHalfYear, DateUtil.getTimeSecondOfDay(0));
|
|
|
|
|
|
compeleteZeroPrice(priceTrendModels, timeSecondOfHalfYear, productId, sizeId);
|
|
|
|
|
|
priceTrendModels.stream().forEach(item -> {
|
|
|
item.setEndTime(null == item.getCreateTime() ? null : item.getCreateTime());
|
...
|
...
|
@@ -27,10 +37,31 @@ public class PriceTrendHalfYearService implements PriceTrendServiceInf{ |
|
|
});
|
|
|
|
|
|
return priceTrendModels;
|
|
|
}
|
|
|
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
|
|
|
//产品紧急变更需求 补全180天的数据,价格用零补充
|
|
|
private void compeleteZeroPrice(List<PriceTrendModel> priceTrendModels, int timeSecondOfHalfYear, Integer productId, Integer sizeId) {
|
|
|
if (CollectionUtils.isEmpty(priceTrendModels) || priceTrendModels.size() <= 1) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
return Lists.newArrayList();
|
|
|
Integer firstCreateTime = Optional.ofNullable(priceTrendModels.get(0)).map(PriceTrendModel::getCreateTime).orElse(null);
|
|
|
if (Objects.isNull(firstCreateTime)) { // 有脏数据 不用记日志,查询数据可以看出来
|
|
|
return;
|
|
|
}
|
|
|
List<PriceTrendModel> zeroPriceList = Lists.newArrayList();
|
|
|
for (int i = firstCreateTime - 259200; i >= timeSecondOfHalfYear; i -= 259200) {
|
|
|
zeroPriceList.add(new PriceTrendModel(productId, sizeId, zeroPrice, zeroPrice, i));
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isEmpty(zeroPriceList)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
List<PriceTrendModel> reverse = Lists.reverse(zeroPriceList);
|
|
|
reverse.addAll(priceTrendModels);
|
|
|
}
|
|
|
} |
...
|
...
|
|