Browse Source

对账单

24282 1 year ago
parent
commit
cb2e11600b

+ 5 - 0
sd-business/src/main/java/com/sd/business/entity/order/dto/OrderSelectDto.java

@@ -15,6 +15,11 @@ import lombok.Setter;
 public class OrderSelectDto extends BaseSelectDto {
 
     /**
+     * 事业部id
+     */
+    private Long departmentId;
+
+    /**
      * 事业部名称
      */
     private String departmentName;

+ 20 - 5
sd-business/src/main/java/com/sd/business/entity/statement/vo/DocumentByOrderVo.java

@@ -44,6 +44,16 @@ public class DocumentByOrderVo {
     public static class SkuSpec {
 
         /**
+         * 订单id
+         */
+        private Long orderId;
+
+        /**
+         * 订单sku id
+         */
+        private Long orderSkuId;
+
+        /**
          * sku规格id
          */
         private Long skuSpecId;
@@ -91,6 +101,11 @@ public class DocumentByOrderVo {
     public static class BomSpec {
 
         /**
+         * 订单sku id
+         */
+        private Long orderSkuId;
+
+        /**
          * bom规格id
          */
         private Long bomSpecId;
@@ -116,27 +131,27 @@ public class DocumentByOrderVo {
         private BigDecimal unitPrice;
 
         /**
-         * 激光logo汇总
+         * 激光logo
          */
         private BigDecimal laserLogoSummary;
 
         /**
-         * 激光线粒体汇总
+         * 激光线粒体
          */
         private BigDecimal laserMitochondrialSummary;
 
         /**
-         * 代发费汇总
+         * 代发费
          */
         private BigDecimal lssueFeeSummary;
 
         /**
-         * 快递包材费汇总
+         * 快递包材费
          */
         private BigDecimal deliveryMaterialsFeeSummary;
 
         /**
-         * 包装人工费汇总
+         * 包装人工费
          */
         private BigDecimal packingLaborSummary;
 

+ 1 - 0
sd-business/src/main/java/com/sd/business/service/order/impl/OrderServiceImpl.java

@@ -78,6 +78,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
     public Page<OrderInfoVo> getPage(OrderSelectDto dto) {
         IWrapper<OrderInfo> wrapper = getWrapper();
         wrapper.orderByDesc("o", OrderInfo::getId);
+        wrapper.eq("d", Department::getId, dto.getDepartmentId());
         wrapper.like("d", Department::getName, dto.getDepartmentName());
         wrapper.like("o", OrderInfo::getCode, dto.getCode());
         wrapper.like("o", OrderInfo::getWlnCode, dto.getWlnCode());

+ 94 - 11
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountServiceImpl.java

@@ -361,8 +361,12 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
 
     @Override
     public List<DocumentByOrderVo> getDocumentByOrder(Long statementOfAccountId) {
+
         Assert.notNull(statementOfAccountId, "对账单id不能为空");
         List<OrderInfo> orderList = orderService.list(q -> q.eq(OrderInfo::getStatementOfAccountId, statementOfAccountId));
+        if (orderList.size() == 0) {
+            return Collections.emptyList();
+        }
 
         List<DocumentByOrderVo> result = orderList.stream().map(item ->
                 DocumentByOrderVo.builder()
@@ -374,11 +378,50 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
         ).collect(Collectors.toList());
 
         List<Long> orderIdList = orderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
+        List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdList));
 
         // 获取订单sku
-        List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIdList));
-        List<DocumentByOrderVo.SkuSpec.SkuSpecBuilder> collect = orderSkuList.stream()
+        List<DocumentByOrderVo.SkuSpec> skuSpecList = getSkuSpecList(orderSkuList);
+
+        // 获取订单bom
+        List<DocumentByOrderVo.BomSpec> bomSpecList = getBomSpecList(orderIdList, orderSkuList);
+
+        // sku赋值bom
+        Map<Long, List<DocumentByOrderVo.BomSpec>> bomSpecMap = bomSpecList.stream()
+                .collect(Collectors.groupingBy(DocumentByOrderVo.BomSpec::getOrderSkuId));
+        for (DocumentByOrderVo.SkuSpec skuSpec : skuSpecList) {
+            skuSpec.setBomSpecList(bomSpecMap.getOrDefault(skuSpec.getOrderSkuId(), Collections.emptyList()));
+        }
+
+        // 订单赋值sku
+        Map<Long, List<DocumentByOrderVo.SkuSpec>> skuSpecMap = skuSpecList.stream()
+                .collect(Collectors.groupingBy(DocumentByOrderVo.SkuSpec::getOrderId));
+        for (DocumentByOrderVo documentByOrderVo : result) {
+            documentByOrderVo.setSkuSpecList(skuSpecMap.getOrDefault(documentByOrderVo.getOrderId(), Collections.emptyList()));
+        }
+
+        return result;
+    }
+
+
+    /**
+     * 根据对账单id获取对账订单id列表
+     */
+    private List<Long> getOrderIdList(Long statementOfAccountId) {
+        Assert.notNull(statementOfAccountId, "对账单id不能为空");
+        List<OrderInfo> orderList = orderService.list(q -> q.eq(OrderInfo::getStatementOfAccountId, statementOfAccountId));
+        return orderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
+    }
+
+    /**
+     * 获取订单sku
+     */
+    private List<DocumentByOrderVo.SkuSpec> getSkuSpecList(List<OrderSku> orderSkuList) {
+
+        List<DocumentByOrderVo.SkuSpec> skuSpecList = orderSkuList.stream()
                 .map(item -> DocumentByOrderVo.SkuSpec.builder()
+                        .orderId(item.getOrderId())
+                        .orderSkuId(item.getId())
                         .skuSpecId(item.getSkuSpecId())
                         .quantity(item.getQuantity())
                         .unitPrice(item.getUnitPrice()
@@ -386,21 +429,61 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
                                 .add(item.getLssueFee())
                                 .add(item.getDeliveryMaterialsFee())
                                 .add(item.getPackingLabor())
-                                .add(item.getPackagingMaterialCost())
-                        )
-                ).collect(Collectors.toList());
+                                .add(item.getPackagingMaterialCost()))
+                        .build()
+                )
+                .peek(item -> item.setSubtotal(item.getQuantity().multiply(item.getUnitPrice())))
+                .peek(item -> item.setTotal(item.getSubtotal()))
+                .collect(Collectors.toList());
 
+        skuSpecService.attributeAssign(skuSpecList, DocumentByOrderVo.SkuSpec::getSkuSpecId, (item, skuSpec) -> {
+            item.setSkuSpecCode(skuSpec.getCode());
+            item.setSkuSpecName(skuSpec.getName());
+        });
 
-        return result;
+        return skuSpecList;
     }
 
     /**
-     * 根据对账单id获取对账订单id列表
+     * 获取订单bom
      */
-    private List<Long> getOrderIdList(Long statementOfAccountId) {
-        Assert.notNull(statementOfAccountId, "对账单id不能为空");
-        List<OrderInfo> orderList = orderService.list(q -> q.eq(OrderInfo::getStatementOfAccountId, statementOfAccountId));
-        return orderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
+    private List<DocumentByOrderVo.BomSpec> getBomSpecList(List<Long> orderIdList, List<OrderSku> orderSkuList) {
+
+        List<DocumentByOrderVo.BomSpec> bomSpecList = orderSkuList.stream()
+                .map(item -> DocumentByOrderVo.BomSpec.builder()
+                        .orderSkuId(item.getId())
+                        .bomSpecId(item.getBomSpecId())
+                        .quantity(item.getQuantity())
+                        .unitPrice(item.getUnitPrice())
+                        .laserLogoSummary((Objects.equals(item.getCustomProcessingType(), "20")
+                                ? item.getCustomProcessingFee() : BigDecimal.ZERO).multiply(item.getQuantity()))
+                        .laserMitochondrialSummary((Objects.equals(item.getCustomProcessingType(), "10")
+                                ? item.getCustomProcessingFee() : BigDecimal.ZERO).multiply(item.getQuantity()))
+                        .lssueFeeSummary(item.getLssueFee().multiply(item.getQuantity()))
+                        .deliveryMaterialsFeeSummary(item.getDeliveryMaterialsFee().multiply(item.getQuantity()))
+                        .packingLaborSummary(item.getPackingLabor().multiply(item.getQuantity()))
+                        .build()
+                ).collect(Collectors.toList());
+
+        List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderId, orderIdList));
+
+        List<DocumentByOrderVo.BomSpec> packBomSpecList = orderSkuBomList.stream()
+                .map(item -> DocumentByOrderVo.BomSpec.builder()
+                        .orderSkuId(item.getOrderSkuId())
+                        .bomSpecId(item.getBomSpecId())
+                        .quantity(item.getQuantity())
+                        .unitPrice(item.getUnitPrice())
+                        .build()
+                ).collect(Collectors.toList());
+
+        bomSpecList.addAll(packBomSpecList);
+
+        bomSpecService.attributeAssign(bomSpecList, DocumentByOrderVo.BomSpec::getBomSpecId, (item, bomSpec) -> {
+            item.setBomSpecCode(bomSpec.getCode());
+            item.setBomSpecName(bomSpec.getName());
+        });
+
+        return bomSpecList;
     }
 
 }

+ 1 - 1
sd-wln/src/main/java/com/sd/wln/service/impl/WlnOrderServiceImpl.java

@@ -447,7 +447,7 @@ public class WlnOrderServiceImpl implements WlnOrderService {
                 .stream()
                 .filter(ObjectUtil::isNotNull)
                 .filter(item -> ObjectUtil.isNotNull(item.getPriceBillingStandardId()))
-                .collect(Collectors.toMap(BaseIdPo::getId, Department::getPriceBillingStandardId));
+                .collect(Collectors.toMap(BaseIdPo::getId, Department::getPriceBillingStandardId, (t1, t2) -> t1));
 
         // 加工计费标准id 报价规则列表 map
         Map<Long, List<PriceBillingStandardDetail>> priceBillingStandardMap = priceBillingStandardDetailService.list()