I'm developing a Spring Boot application with Spring Data JPA. I'm using a custom JPQL query to get the data I need.
The following is my method repository:
/**
* SELECT sku, SUM(real_allocation - logical_allocation)
* FROM stock
* WHERE warehouse_brand = '?'
* GROUP BY (warehouse_brand, sku);
*/
@Query(value = "SELECT new it.reply.retail.oms.common.api.inventory.CumulativeInventoryItem " +
"(s.pk.sku, SUM(s.realAllocation - s.logicalAllocation)) " +
"FROM Stock s WHERE s.pk.whsCode IN :warehouses GROUP BY (s.pk.sku)")
Page<CumulativeInventoryItem> getCumulativeInventory(List<String> warehouses, Pageable pageable);
and the CumulativeInventoryItem
custom object is the following one:
public class CumulativeInventoryItem {
private String sku;
private Long cumulativeQty;
}
The result set I obtain, sometimes, contains negative values for the cumulativeQty
attribute which need to be replaced with 0 instead.
Is it possible to replace these values using ad-hoc query or I need to replace them once I get the result set back from my JPA method?
question from:
https://stackoverflow.com/questions/65643773/spring-jpa-query-replace-negative-values-in-result-set 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…