Authored by mali

价格趋势

1 package com.yohoufo.product.model; 1 package com.yohoufo.product.model;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
  4 +
3 import java.math.BigDecimal; 5 import java.math.BigDecimal;
  6 +import java.util.Objects;
  7 +import java.util.Optional;
4 8
5 /** 9 /**
6 * Created by li.ma on 2019/1/8. 10 * Created by li.ma on 2019/1/8.
@@ -93,6 +97,19 @@ public class PriceTrendResp { @@ -93,6 +97,19 @@ public class PriceTrendResp {
93 return null != this.endTime && this.endTime.equals(resp.getEndTime()); 97 return null != this.endTime && this.endTime.equals(resp.getEndTime());
94 } 98 }
95 99
  100 + @Override
  101 + public int hashCode() {
  102 + if (Objects.isNull(this.endTime)) {
  103 + return super.hashCode();
  104 + }
  105 + return this.endTime.hashCode();
  106 + }
  107 +
  108 + @Override
  109 + public String toString() {
  110 + return JSONObject.toJSONString(this);
  111 + }
  112 +
96 public static class Builder { 113 public static class Builder {
97 private Integer id; 114 private Integer id;
98 115
@@ -53,6 +53,10 @@ public class ProductPriceService implements ApplicationContextAware{ @@ -53,6 +53,10 @@ public class ProductPriceService implements ApplicationContextAware{
53 53
54 LOG.info("priceTrendModels result is {}", priceTrendModels.size()); 54 LOG.info("priceTrendModels result is {}", priceTrendModels.size());
55 55
  56 + if (priceTrendModels.size() <= 1) {
  57 + return Lists.newArrayList();
  58 + }
  59 +
56 List<PriceTrendResp> result = Lists.newArrayList(); 60 List<PriceTrendResp> result = Lists.newArrayList();
57 priceTrendModels.stream().forEach(item -> 61 priceTrendModels.stream().forEach(item ->
58 result.add(new PriceTrendResp.Builder().setProductId(item.getProductId()) 62 result.add(new PriceTrendResp.Builder().setProductId(item.getProductId())
  1 +package com.yohoufo.order;
  2 +
  3 +import com.google.common.collect.Lists;
  4 +import com.yohoufo.product.model.PriceTrendResp;
  5 +
  6 +import java.util.List;
  7 +import java.util.stream.Collectors;
  8 +
  9 +/**
  10 + * Created by li.ma on 2019/1/17.
  11 + */
  12 +public class Test11 {
  13 + public static void main(String[] args) {
  14 + List<PriceTrendResp> result = Lists.newArrayList();
  15 +
  16 + PriceTrendResp resp =new PriceTrendResp();
  17 + resp.setEndTime("2019-01-09 00:00:00");
  18 + resp.setProductId(1002512);
  19 + result.add(resp);
  20 +
  21 + PriceTrendResp resp1 =new PriceTrendResp();
  22 + resp1.setEndTime("2019-01-09 00:00:00");
  23 + resp1.setProductId(46346346);
  24 + result.add(resp1);
  25 +
  26 + List<PriceTrendResp> collect = result.stream().distinct().collect(Collectors.toList());
  27 +
  28 + System.out.println(collect);
  29 + }
  30 +}