diff --git a/src/main/java/cn/lihongjie/coal/warehouseGoods/controller/WarehouseGoodsController.java b/src/main/java/cn/lihongjie/coal/warehouseGoods/controller/WarehouseGoodsController.java index 4353317c..093e04a1 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseGoods/controller/WarehouseGoodsController.java +++ b/src/main/java/cn/lihongjie/coal/warehouseGoods/controller/WarehouseGoodsController.java @@ -64,4 +64,5 @@ public class WarehouseGoodsController { } + } diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/controller/WarehouseReceiptController.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/controller/WarehouseReceiptController.java index cd64a08a..1f07616d 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/controller/WarehouseReceiptController.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/controller/WarehouseReceiptController.java @@ -71,5 +71,9 @@ public class WarehouseReceiptController { return this.service.report(request); } + @PostMapping("/supplierReport") + public Object supplierReport(@RequestBody WarehouseReportRequest request) { + return this.service.supplierReport(request); + } } 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 a664fe3b..ae9eeb24 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java @@ -100,7 +100,10 @@ public class WarehouseReceiptService if (CollectionUtils.isNotEmpty(entity.getDetail())) { entity.getDetail() - .forEach(item -> {item.setSupplier(null);}); + .forEach( + item -> { + item.setSupplier(null); + }); } } } @@ -939,4 +942,320 @@ from ( criteriaBuilder.and( root.get("detail").get("goods").get("id").in(ids))); } + + public Object supplierReport(WarehouseReportRequest request) { + + request.setOrganizationId(Ctx.currentUser().getOrganizationId()); + + String sql = + FreeMakerUtils.render( + """ + + + with tmp1 as ( + + + select s.*, + + (select count(distinct re.id) + from t_warehouse_receipt re + inner join t_warehouse_receipt_detail d + on re.id = d.receipt_id + inner join t_warehouse_goods gs on d.goods_id = gs.id + where re.organization_id = s.organization_id + and re.receipt_type = '0' + and d.supplier_id = s.id + <#if startTime??> + and re.receipt_date >= :startTime + + <#if endTime??> + and re.receipt_date <= :endTime + + <#if reason??> + and re.reason like '%' || :reason || '%' + + <#if goodsIds?has_content> + and gs.id in :goodsIds + + + <#if barCode??> + and gs.bar_code like '%' || :barCode || '%' + + <#if code??> + and gs.code like '%' || :code || '%' + + + + <#if goodsName??> + + and gs.name like '%' || :goodsName || '%' + + + <#if categoryIds?has_content> + and gs.category_id in :categoryIds + + + <#if brandIds?has_content> + and gs.brand_id in :brandIds + + + <#if unitIds?has_content> + and gs.unit_id in :unitIds + + + ) as "入库单数量", + + (select count(d.id) + from t_warehouse_receipt re + inner join t_warehouse_receipt_detail d + on re.id = d.receipt_id + inner join t_warehouse_goods gs on d.goods_id = gs.id + where re.organization_id = s.organization_id + and re.receipt_type = '0' + and d.supplier_id = s.id + + <#if startTime??> + and re.receipt_date >= :startTime + + <#if endTime??> + and re.receipt_date <= :endTime + + <#if reason??> + and re.reason like '%' || :reason || '%' + + <#if goodsIds?has_content> + and gs.id in :goodsIds + + + <#if barCode??> + and gs.bar_code like '%' || :barCode || '%' + + <#if code??> + and gs.code like '%' || :code || '%' + + + + <#if goodsName??> + + and gs.name like '%' || :goodsName || '%' + + + <#if categoryIds?has_content> + and gs.category_id in :categoryIds + + + <#if brandIds?has_content> + and gs.brand_id in :brandIds + + + <#if unitIds?has_content> + and gs.unit_id in :unitIds + + ) as "入库单明细数量", + + (select count(distinct d.goods_id) + from t_warehouse_receipt re + inner join t_warehouse_receipt_detail d + on re.id = d.receipt_id + inner join t_warehouse_goods gs on d.goods_id = gs.id + where re.organization_id = s.organization_id + and re.receipt_type = '0' + and d.supplier_id = s.id + <#if startTime??> + and re.receipt_date >= :startTime + + <#if endTime??> + and re.receipt_date <= :endTime + + <#if reason??> + and re.reason like '%' || :reason || '%' + + <#if goodsIds?has_content> + and gs.id in :goodsIds + + + <#if barCode??> + and gs.bar_code like '%' || :barCode || '%' + + <#if code??> + and gs.code like '%' || :code || '%' + + + + <#if goodsName??> + + and gs.name like '%' || :goodsName || '%' + + + <#if categoryIds?has_content> + and gs.category_id in :categoryIds + + + <#if brandIds?has_content> + and gs.brand_id in :brandIds + + + <#if unitIds?has_content> + and gs.unit_id in :unitIds + + + ) as "入库商品种数", + + (select round(sum(d.number)::::numeric, 2) + from t_warehouse_receipt re + inner join t_warehouse_receipt_detail d + on re.id = d.receipt_id + inner join t_warehouse_goods gs on d.goods_id = gs.id + where re.organization_id = s.organization_id + and re.receipt_type = '0' + and d.supplier_id = s.id + <#if startTime??> + and re.receipt_date >= :startTime + + <#if endTime??> + and re.receipt_date <= :endTime + + <#if reason??> + and re.reason like '%' || :reason || '%' + + <#if goodsIds?has_content> + and gs.id in :goodsIds + + + <#if barCode??> + and gs.bar_code like '%' || :barCode || '%' + + <#if code??> + and gs.code like '%' || :code || '%' + + + + <#if goodsName??> + + and gs.name like '%' || :goodsName || '%' + + + <#if categoryIds?has_content> + and gs.category_id in :categoryIds + + + <#if brandIds?has_content> + and gs.brand_id in :brandIds + + + <#if unitIds?has_content> + and gs.unit_id in :unitIds + + ) as "入库商品数量", + + (select round(sum(d.amount)::::numeric, 2) + from t_warehouse_receipt re + inner join t_warehouse_receipt_detail d + on re.id = d.receipt_id + inner join t_warehouse_goods gs on d.goods_id = gs.id + where re.organization_id = s.organization_id + and re.receipt_type = '0' + and d.supplier_id = s.id + + <#if startTime??> + and re.receipt_date >= :startTime + + <#if endTime??> + and re.receipt_date <= :endTime + + <#if reason??> + and re.reason like '%' || :reason || '%' + + <#if goodsIds?has_content> + and gs.id in :goodsIds + + + <#if barCode??> + and gs.bar_code like '%' || :barCode || '%' + + <#if code??> + and gs.code like '%' || :code || '%' + + + + <#if goodsName??> + + and gs.name like '%' || :goodsName || '%' + + + <#if categoryIds?has_content> + and gs.category_id in :categoryIds + + + <#if brandIds?has_content> + and gs.brand_id in :brandIds + + + <#if unitIds?has_content> + and gs.unit_id in :unitIds + + + ) as "入库商品总价" + + + from t_warehouse_supplier s + where s.organization_id = :organizationId + ) + + + select * from tmp1 + + + <#if excludeEmpty> + + where "入库单数量" > 0 + + + + + """, + request); + + var countSql = "select count(1) from (" + sql + ") as t"; + + var selectSql = + "select * from (" + + sql + + ") as t limit " + + request.getPageSize() + + " offset " + + request.getPageNo() * request.getPageSize(); + + Integer count = JpaUtils.execNativeQuery(em, countSql, request, Integer.class).get(0); + + List data = JpaUtils.execNativeQuery(em, selectSql, request, Tuple.class); + + var resultList = JpaUtils.convertTuplesToMap(data); + + var ans = + resultList.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(); + + return new PageImpl<>(ans, PageRequest.of(0, request.getPageSize()), count); + } }