【发布时间】:2021-10-10 04:27:07
【问题描述】:
以下是我的实体:
产品
@Entity
@Table(name = "Product")
public class Product extends ReusableFields
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
Long productId;
@NonNull
@Column(name = "product_name")
String productName;
String measurementUnit;
//more fields and getters setters
}
与产品相关的Inward Outward List:
@Entity
@Table(name = "inward_outward_entries")
public class InwardOutwardList extends ReusableFields
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long entryid;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "productId", nullable = false)
@JsonIgnoreProperties(
{ "hibernateLazyInitializer", "handler" })
Product product;
@JsonSerialize(using = DoubleTwoDigitDecimalSerializer.class)
Double quantity;
//more fields
}
具有一组内向外向清单的内向库存:
@Entity
@Table(name = "inward_inventory")
public class InwardInventory extends ReusableFields implements Cloneable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "inwardid")
Long inwardid;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "inwardinventory_entry", joinColumns =
{ @JoinColumn(name = "inwardid", referencedColumnName = "inwardid") }, inverseJoinColumns =
{ @JoinColumn(name = "entryId", referencedColumnName = "entryId") })
Set<InwardOutwardList> inwardOutwardList = new HashSet<>();
//more fields
}
我有一个内向库存清单,我想根据产品对其进行分组。所以,我想做的是
SUM(InwardInventory.InwardOutwardList.quantity) 同时基于 InwardInventory.InwardOutwardList.Product.productName 和 InwardInventory.InwardOutwardList.Product.measurementUnit 进行分组
我是流的新手,我知道可以做到但无法获得确切的解决方案。有人可以提供指导或帮助吗?
【问题讨论】:
标签: java java-8 java-stream