From 0dac827b160dd95909bf4d20afc8ec97359f4ad4 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sat, 23 Nov 2024 21:45:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/WarehouseReportRequest.java | 12 +- .../service/WarehouseReceiptService.java | 309 +++++++++--------- 2 files changed, 171 insertions(+), 150 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReportRequest.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReportRequest.java index cf07fdb5..7e16de69 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReportRequest.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/dto/WarehouseReportRequest.java @@ -41,8 +41,16 @@ public class WarehouseReportRequest { private String organizationId; + + /** + * 是否按照货架汇总 + */ + private Boolean shelveSummary = false; + private Boolean excludeEmpty = false; - - + /** + * 是否包含合计 + */ + private Boolean includeSum = true; } 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 f00c92bf..7c4e1fe5 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java @@ -39,6 +39,7 @@ import jakarta.persistence.criteria.Root; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -188,8 +189,7 @@ public class WarehouseReceiptService request.setRuleCode(RuleCodeConstant.KF_RKD); request.setTime(receipt0.getReceiptDate()); receipt0.setReceiptNo( - orderNoRuleService.genOrderNo( - request, Ctx.currentUser().getOrganizationId())); + orderNoRuleService.genOrderNo(request, Ctx.currentUser().getOrganizationId())); entity.setReceipt0(receipt0); this.warehouseReceiptDetailRepository.saveAll(receipt0.getDetail()); @@ -213,8 +213,7 @@ public class WarehouseReceiptService request.setRuleCode(RuleCodeConstant.KF_CKD); request.setTime(receipt1.getReceiptDate()); receipt1.setReceiptNo( - orderNoRuleService.genOrderNo( - request, Ctx.currentUser().getOrganizationId())); + orderNoRuleService.genOrderNo(request, Ctx.currentUser().getOrganizationId())); entity.setReceipt1(receipt1); this.save(receipt1); @@ -424,11 +423,7 @@ public class WarehouseReceiptService public void delete(IdRequest dto) { - /** - * 获取所有单据 - * 1。 用户选中的 - * 2. 用户选中的单据的子单据 - */ + /** 获取所有单据 1。 用户选中的 2. 用户选中的单据的子单据 */ List all = this.repository.findAll( new Specification() { @@ -444,9 +439,7 @@ public class WarehouseReceiptService } }); - /** - * 获取用户选中单据中的子单据 - */ + /** 获取用户选中单据中的子单据 */ List ch = this.repository.findAll( new Specification() { @@ -559,159 +552,173 @@ public class WarehouseReceiptService """ - with bq as (select distinct on ( gs.id, w.id) gs.id, - gs.create_time, - gs.create_user_id, - gs.file_ids, - gs.update_time, - gs.update_user_id, - gs.code, - gs.name, - gs.remarks, - gs.sort_key, - gs.status, - gs.organization_id, - gs.bar_code, - gs.price1, - gs.price2, - gs.price3, - gs.price4, - gs.price5, - gs.size, - gs.volume, - gs.weight, - gs.brand_id, - gs.category_id, - gs.unit_id, - gs.parent_id, - gs.spec, - gs.default_shelve_id, - gs.default_warehouse_id, - gs.enable_attribute, - gs.attributes, - gs.enable_shelf_life, - gs.shelf_life, - gs.default_supplier_id, - gs.model, - - gu.name as unit_name, - gu.code as unit_code, - gb.name as brand_name, - gb.code as brand_code, - w.id as warehouse_id, - w.name as warehouse_name, - w.code as warehouse_code, - gc.code as category_code, - gc.name as category_name, - - round((sum(d.number) - filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric, - 2) as type0_number, - round((sum(d.number) - filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric, - 2) as type1_number, - round((sum(d.amount) - filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric, - 2) as type0_amount, - round((sum(d.amount) - filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric, - 2) as type1_amount, - round((sum(d.amount) - filter (where d.receipt_type = '0') over (partition by w.id, gs.id) / - sum(d.number) - filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric, - 2) as type0_price, - - round((sum(d.amount) - filter (where d.receipt_type = '1') over (partition by w.id, gs.id) / - sum(d.number) - filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric, - 2) as type1_price - from t_warehouse_goods gs - inner join t_warehouse w on 1 = 1 - <#if excludeEmpty> - inner - - <#else> - - left - - - - join t_warehouse_receipt_detail d on d.goods_id = gs.id - left join t_warehouse_receipt re on d.receipt_id = re.id - left join t_warehouse_goods_unit gu on gs.unit_id = gu.id - left join t_warehouse_goods_brand gb on gs.brand_id = gb.id - left join t_warehouse_goods_category gc on gs.category_id = gc.id - - - where 1=1 - <#if startTime??> - and re.receipt_date >= :startTime - - <#if endTime??> - and re.receipt_date <= :endTime + with bq as (select distinct on ( gs.id, w.id + + <#if shelveSummary> + , d.shelve_id + ) gs.id, + gs.create_time, + gs.create_user_id, + gs.file_ids, + gs.update_time, + gs.update_user_id, + gs.code, + gs.name, + gs.remarks, + gs.sort_key, + gs.status, + gs.organization_id, + gs.bar_code, + gs.price1, + gs.price2, + gs.price3, + gs.price4, + gs.price5, + gs.size, + gs.volume, + gs.weight, + gs.brand_id, + gs.category_id, + gs.unit_id, + gs.parent_id, + gs.spec, + gs.default_shelve_id, + gs.default_warehouse_id, + gs.enable_attribute, + gs.attributes, + gs.enable_shelf_life, + gs.shelf_life, + gs.default_supplier_id, + gs.model, - <#if supplierIds??> - and d.supplier_id in :supplierIds - + gu.name as unit_name, + gu.code as unit_code, + gb.name as brand_name, + gb.code as brand_code, + w.id as warehouse_id, + w.name as warehouse_name, + w.code as warehouse_code, + gc.code as category_code, + gc.name as category_name, + + <#if shelveSummary> + ws.id as shelve_id, + ws.name as shelve_name, + ws.code as shelve_code, + - <#if organizationId??> - and gs.organization_id = :organizationId + round((sum(d.number) + filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric, + 2) as type0_number, + round((sum(d.number) + filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric, + 2) as type1_number, + round((sum(d.amount) + filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric, + 2) as type0_amount, + round((sum(d.amount) + filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric, + 2) as type1_amount, + round((sum(d.amount) + filter (where d.receipt_type = '0') over (partition by w.id, gs.id) / + sum(d.number) + filter (where d.receipt_type = '0') over (partition by w.id, gs.id))::::numeric, + 2) as type0_price, - + round((sum(d.amount) + filter (where d.receipt_type = '1') over (partition by w.id, gs.id) / + sum(d.number) + filter (where d.receipt_type = '1') over (partition by w.id, gs.id))::::numeric, + 2) as type1_price + from t_warehouse_goods gs + inner join t_warehouse w on 1 = 1 + <#if excludeEmpty> + inner - <#if categoryIds?has_content> - and gs.category_id in :categoryIds - + <#else> - <#if brandIds?has_content> - and gs.brand_id in :brandIds - + left - <#if unitIds?has_content> - and gs.unit_id in :unitIds - + - <#if shelveIds?has_content> - and d.shelve_id in :shelveIds - + join t_warehouse_receipt_detail d on d.goods_id = gs.id + left join t_warehouse_receipt re on d.receipt_id = re.id + left join t_warehouse_goods_unit gu on gs.unit_id = gu.id + left join t_warehouse_goods_brand gb on gs.brand_id = gb.id + left join t_warehouse_goods_category gc on gs.category_id = gc.id + + <#if shelveSummary> + left join t_warehouse_shelve ws on d.shelve_id = ws.id + - <#if warehouseIds?has_content> + where 1=1 + <#if startTime??> + and re.receipt_date >= :startTime + + <#if endTime??> + and re.receipt_date <= :endTime + - and d.warehouse_id in :warehouseIds - and w.id in :warehouseIds + <#if supplierIds??> + and d.supplier_id in :supplierIds + - + <#if organizationId??> + and gs.organization_id = :organizationId - <#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 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 + + + <#if shelveIds?has_content> + and d.shelve_id in :shelveIds + + + <#if warehouseIds?has_content> + + and d.warehouse_id in :warehouseIds + and w.id in :warehouseIds + + + + <#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??> + <#if goodsName??> - and gs.name like '%' || :goodsName || '%' + and gs.name like '%' || :goodsName || '%' - + - ) + ) - select * from bq + select * from bq - """, + """, request); var countSql = "select count(1) from (" + sql + ") as t"; @@ -724,19 +731,25 @@ public class WarehouseReceiptService + " offset " + request.getPageNo() * request.getPageSize(); - var sumSql = """ + 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"; +""" + + sql + + ") as t"; Integer count = JpaUtils.execNativeQuery(em, countSql, request, Integer.class).get(0); List data = JpaUtils.execNativeQuery(em, selectSql, request, Tuple.class); - List sumData = JpaUtils.execNativeQuery(em, sumSql, request, Tuple.class); + List sumData = + BooleanUtils.isTrue(request.getIncludeSum()) + ? JpaUtils.execNativeQuery(em, sumSql, request, Tuple.class) + : new ArrayList<>(); var resultList = JpaUtils.convertTuplesToMap(data); @@ -766,7 +779,8 @@ from ( var sumResultList = JpaUtils.convertTuplesToMap(sumData); - var sumAns = sumResultList.stream() + var sumAns = + sumResultList.stream() .map( x -> ((Map) x) @@ -814,7 +828,7 @@ from ( newRequest.setEndTime(request.getStartTime().minusSeconds(1)); content = ((PageImpl) report(newRequest)).getContent(); - }else { + } else { content = ans.stream() .map( @@ -908,8 +922,7 @@ from ( "prevPrice", NumberUtils.round2(prevNumber == 0 ? 0 : prevAmount / prevNumber)); - - currMap.put("sum", sumAns.get(0)); + currMap.put("sum", sumAns.isEmpty() ? null : sumAns.get(0)); } }