From bc23c0baf2422fb2be69550ffb0d0e3e617dc444 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Tue, 19 Nov 2024 22:45:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TimeStatementInspector.java | 7 +++++++ .../entity/WarehouseGoodsSummaryEntity.java | 8 ++++---- .../service/WarehouseGoodsSummaryService.java | 14 ++++++++++++++ .../service/WarehouseReceiptService.java | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/TimeStatementInspector.java b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/TimeStatementInspector.java index 12e369ff..e6caea47 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/TimeStatementInspector.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/TimeStatementInspector.java @@ -21,6 +21,7 @@ public class TimeStatementInspector implements StatementInspector { String startTime = (String) ThreadLocalUtils.get("startTime", null); String endTime = (String) ThreadLocalUtils.get("endTime", null); + String supplierId = (String) ThreadLocalUtils.get("supplierId", null); if (startTime != null) { sql = sql.replace(":startTime", startTime); @@ -30,6 +31,12 @@ public class TimeStatementInspector implements StatementInspector { sql = sql.replace(":endTime", endTime); } + + if (supplierId != null) { + sql = sql.replace(":supplier", supplierId); + } + return sql; + } } diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/entity/WarehouseGoodsSummaryEntity.java b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/entity/WarehouseGoodsSummaryEntity.java index 0f7bb6e8..ac5f8f57 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/entity/WarehouseGoodsSummaryEntity.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/entity/WarehouseGoodsSummaryEntity.java @@ -50,14 +50,14 @@ select g.shelf_life, d.warehouse_id as warehouse_id, count(d.id) over (partition by g.id) as detail_count, - round((sum(d.number) filter ( where d.receipt_type = '0' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) ) over (partition by g.id, d.warehouse_id))::numeric, + round((sum(d.number) filter ( where d.receipt_type = '0' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) :supplier ) over (partition by g.id, d.warehouse_id))::numeric, 2) as type0number, - round((sum(d.number) filter ( where d.receipt_type = '1' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) ) over (partition by g.id, d.warehouse_id))::numeric, + round((sum(d.number) filter ( where d.receipt_type = '1' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) :supplier ) over (partition by g.id, d.warehouse_id))::numeric, 2) as type1number, - round((sum(d.amount) filter ( where d.receipt_type = '0' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) ) over (partition by g.id, d.warehouse_id))::numeric, + round((sum(d.amount) filter ( where d.receipt_type = '0' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) :supplier ) over (partition by g.id, d.warehouse_id))::numeric, 2) as type0amount, - round((sum(d.amount) filter ( where d.receipt_type = '1' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) ) over (partition by g.id, d.warehouse_id))::numeric, + round((sum(d.amount) filter ( where d.receipt_type = '1' and (r.receipt_date >= :startTime and r.receipt_date <= :endTime) :supplier ) over (partition by g.id, d.warehouse_id))::numeric, 2) as type1amount from t_warehouse_goods g diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java index 1a94176a..b83f8b7f 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoodsSummary/service/WarehouseGoodsSummaryService.java @@ -113,6 +113,8 @@ public class WarehouseGoodsSummaryService ThreadLocalUtils.remove("startTime"); ThreadLocalUtils.remove("endTime"); + ThreadLocalUtils.remove("supplierId"); + ThreadLocalUtils.remove("enableTimeStatementInspector"); Page dtos = page.map(this.mapper::toDto); @@ -126,6 +128,7 @@ public class WarehouseGoodsSummaryService CommonQuery.QueryItem endTimeItem = copy.deleteItem("endTime"); + if (startTimeItem == null || conversionService.convert(startTimeItem.getValue(), LocalDateTime.class).equals(MIN_TIME)) { return dtos; } @@ -137,6 +140,8 @@ public class WarehouseGoodsSummaryService + + copy.getItems().add(new CommonQuery.QueryItem().withKey("startTime").withValue(LocalDateTimeUtil.format(startTime, "yyyy-MM-dd HH:mm:ss"))); copy.getItems().add(new CommonQuery.QueryItem().withKey("endTime").withValue(LocalDateTimeUtil.format(endTime, "yyyy-MM-dd HH:mm:ss"))); copy.getItems().add(new CommonQuery.QueryItem().withKey("id").withOpt("in").withValue(dtos.getContent().stream().map(WarehouseGoodsSummaryDto::getId).collect(Collectors.joining(",")))); @@ -167,6 +172,7 @@ public class WarehouseGoodsSummaryService CommonQuery.QueryItem startTimeItem = query.deleteItem("startTime"); CommonQuery.QueryItem endTimeItem = query.deleteItem("endTime"); + CommonQuery.QueryItem supplierIdItem = query.deleteItem("supplierId"); LocalDateTime startTime = startTimeItem == null @@ -178,6 +184,9 @@ public class WarehouseGoodsSummaryService ? MAX_TIME : conversionService.convert(endTimeItem.getValue(), LocalDateTime.class); + + String supplierId = supplierIdItem == null ? "" : "and d.supplier_id = '%s'".formatted(supplierIdItem.getValue()); + ThreadLocalUtils.set( "startTime", "'%s'::timestamp" @@ -192,6 +201,9 @@ public class WarehouseGoodsSummaryService DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") .format(endTime))); + ThreadLocalUtils.set("supplierId", supplierId); + + ThreadLocalUtils.set("enableTimeStatementInspector", true); } @@ -227,6 +239,8 @@ public class WarehouseGoodsSummaryService ThreadLocalUtils.remove("startTime"); ThreadLocalUtils.remove("endTime"); + ThreadLocalUtils.remove("supplierId"); + ThreadLocalUtils.remove("enableTimeStatementInspector"); return mapper.toDto(resultList.get(0)); diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java index 9c085966..03f15821 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java @@ -435,7 +435,7 @@ public class WarehouseReceiptService } }); - List list = ch.stream().map(x -> x.getParent().getId()).toList(); + List list = ch.stream().filter(x -> x.getParent()!=null).map(x -> x.getParent().getId()).toList(); Collection notSelected = CollectionUtils.removeAll(list, dto.getIds());