Authored by mali

价格走势,180天补充零价格

package com.yohoufo.dal.product.model;
import com.alibaba.fastjson.JSONObject;
import java.math.BigDecimal;
public class PriceTrendModel {
... ... @@ -13,6 +15,17 @@ public class PriceTrendModel {
private BigDecimal skuPrice;
public PriceTrendModel() {
}
public PriceTrendModel(Integer productId, Integer sizeId, BigDecimal sknPrice, BigDecimal skuPrice, Integer createTime) {
this.productId = productId;
this.sizeId = sizeId;
this.sknPrice = sknPrice;
this.skuPrice = skuPrice;
this.createTime = createTime;
}
public Integer getEndTime() {
return endTime;
}
... ... @@ -82,4 +95,9 @@ public class PriceTrendModel {
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
}
}
\ No newline at end of file
... ...
... ... @@ -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);
}
}
... ...