bugfix: 单据删除逻辑错误

This commit is contained in:
2024-11-23 17:15:36 +08:00
parent 6ed09c0818
commit 8792b4746b

View File

@@ -418,6 +418,11 @@ public class WarehouseReceiptService
public void delete(IdRequest dto) { public void delete(IdRequest dto) {
/**
* 获取所有单据
* 1。 用户选中的
* 2. 用户选中的单据的子单据
*/
List<WarehouseReceiptEntity> all = List<WarehouseReceiptEntity> all =
this.repository.findAll( this.repository.findAll(
new Specification<WarehouseReceiptEntity>() { new Specification<WarehouseReceiptEntity>() {
@@ -433,6 +438,9 @@ public class WarehouseReceiptService
} }
}); });
/**
* 获取用户选中单据中的子单据
*/
List<WarehouseReceiptEntity> ch = List<WarehouseReceiptEntity> ch =
this.repository.findAll( this.repository.findAll(
new Specification<WarehouseReceiptEntity>() { new Specification<WarehouseReceiptEntity>() {
@@ -442,7 +450,7 @@ public class WarehouseReceiptService
CriteriaQuery<?> query, CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) { CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.or( return criteriaBuilder.and(
root.get("id").in(dto.getIds()), root.get("id").in(dto.getIds()),
root.get("parent").get("id").isNotNull()); root.get("parent").get("id").isNotNull());
} }
@@ -579,10 +587,12 @@ public class WarehouseReceiptService
gs.shelf_life, gs.shelf_life,
gs.default_supplier_id, gs.default_supplier_id,
gs.model, gs.model,
gu.name as unit_name, gu.name as unit_name,
gu.code as unit_code, gu.code as unit_code,
gb.name as brand_name, gb.name as brand_name,
gb.code as brand_code, gb.code as brand_code,
w.id as warehouse_id,
w.name as warehouse_name, w.name as warehouse_name,
w.code as warehouse_code, w.code as warehouse_code,
gc.code as category_code, gc.code as category_code,
@@ -646,29 +656,30 @@ public class WarehouseReceiptService
</#if> </#if>
<#if categoryIds??> <#if categoryIds?has_content>
and gs.category_id in :categoryIds and gs.category_id in :categoryIds
</#if> </#if>
<#if brandIds??> <#if brandIds?has_content>
and gs.brand_id in :brandIds and gs.brand_id in :brandIds
</#if> </#if>
<#if unitIds??> <#if unitIds?has_content>
and gs.unit_id in :unitIds and gs.unit_id in :unitIds
</#if> </#if>
<#if shelveIds??> <#if shelveIds?has_content>
and d.shelve_id in :shelveIds and d.shelve_id in :shelveIds
</#if> </#if>
<#if warehouseIds??> <#if warehouseIds?has_content>
and d.warehouse_id in :warehouseIds and d.warehouse_id in :warehouseIds
and w.id in :warehouseIds
</#if> </#if>
<#if goodsIds??> <#if goodsIds?has_content>
and gs.id in :goodsIds and gs.id in :goodsIds
</#if> </#if>
@@ -707,10 +718,20 @@ public class WarehouseReceiptService
+ " offset " + " offset "
+ request.getPageNo() * request.getPageSize(); + request.getPageNo() * request.getPageSize();
var sumSql = """
select sum(type0_number) as type0_number,
sum(type1_number) as type1_number,
sum(type0_amount) as type0_amount,
sum(type1_amount) as type1_amount
from (
""" + sql + ") as t";
Integer count = JpaUtils.execNativeQuery(em, countSql, request, Integer.class).get(0); Integer count = JpaUtils.execNativeQuery(em, countSql, request, Integer.class).get(0);
List<Tuple> data = JpaUtils.execNativeQuery(em, selectSql, request, Tuple.class); List<Tuple> data = JpaUtils.execNativeQuery(em, selectSql, request, Tuple.class);
List<Tuple> sumData = JpaUtils.execNativeQuery(em, sumSql, request, Tuple.class);
var resultList = JpaUtils.convertTuplesToMap(data); var resultList = JpaUtils.convertTuplesToMap(data);
var ans = var ans =
@@ -737,6 +758,31 @@ public class WarehouseReceiptService
"")))) ""))))
.toList(); .toList();
var sumResultList = JpaUtils.convertTuplesToMap(sumData);
var sumAns = sumResultList.stream()
.map(
x ->
((Map) x)
.entrySet().stream()
.collect(
Collectors.toMap(
(Map.Entry e) ->
CaseFormat
.LOWER_UNDERSCORE
.to(
CaseFormat
.LOWER_CAMEL,
e.getKey()
.toString()),
e ->
ObjectUtils
.defaultIfNull(
e
.getValue(),
""))))
.toList();
List content = new ArrayList(); List content = new ArrayList();
if (request.getStartTime() != null) { if (request.getStartTime() != null) {
@@ -855,6 +901,9 @@ public class WarehouseReceiptService
currMap.put( currMap.put(
"prevPrice", "prevPrice",
NumberUtils.round2(prevNumber == 0 ? 0 : prevAmount / prevNumber)); NumberUtils.round2(prevNumber == 0 ? 0 : prevAmount / prevNumber));
currMap.put("sum", sumAns.get(0));
} }
} }