24282 1 vuosi sitten
vanhempi
commit
89de463349

+ 38 - 0
sd-business/src/main/java/com/sd/business/entity/statement/vo/DocumentBySkuVo.java

@@ -1,11 +1,49 @@
 package com.sd.business.entity.statement.vo;
 
+import lombok.Builder;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 @Getter
 @Setter
+@Builder
 public class DocumentBySkuVo {
 
+    /**
+     * sku规格id
+     */
+    private Long skuSpecId;
+
+    /**
+     * sku品号
+     */
+    private String skuSpecCode;
+
+    /**
+     * sku品名
+     */
+    private String skuSpecName;
+
+    /**
+     * 数量
+     */
+    private BigDecimal quantity;
+
+    /**
+     * sku单价
+     */
+    private BigDecimal unitPrice;
+
+    /**
+     * 小计
+     */
+    private BigDecimal subtotal;
+
+    /**
+     * 合计
+     */
+    private BigDecimal total;
 
 }

+ 57 - 2
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountServiceImpl.java

@@ -11,6 +11,7 @@ import com.fjhx.file.utils.ObsFileUtil;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.sd.business.entity.order.po.OrderInfo;
+import com.sd.business.entity.order.po.OrderSku;
 import com.sd.business.entity.statement.dto.FileUploadDto;
 import com.sd.business.entity.statement.dto.StatementOfAccountDto;
 import com.sd.business.entity.statement.dto.StatementOfAccountSelectDto;
@@ -21,6 +22,8 @@ import com.sd.business.entity.statement.vo.StatementOfAccountVo;
 import com.sd.business.mapper.statement.StatementOfAccountMapper;
 import com.sd.business.service.department.DepartmentService;
 import com.sd.business.service.order.OrderService;
+import com.sd.business.service.order.OrderSkuService;
+import com.sd.business.service.sku.SkuSpecService;
 import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.business.util.CodeEnum;
 import com.sd.framework.util.Assert;
@@ -28,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 
@@ -46,14 +50,20 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     private OrderService orderService;
 
     @Autowired
+    private OrderSkuService orderSkuService;
+
+    @Autowired
     private DepartmentService departmentService;
 
+    @Autowired
+    private SkuSpecService skuSpecService;
+
     @Override
     public Page<StatementOfAccountVo> getPage(StatementOfAccountSelectDto dto) {
 
         IWrapper<StatementOfAccount> wrapper = getWrapper();
-        wrapper.eq("soa", StatementOfAccount::getDepartmentId, dto.getDepartmentId());
         wrapper.like("soa", StatementOfAccount::getCode, dto.getCode());
+        wrapper.eq("soa", StatementOfAccount::getDepartmentId, dto.getDepartmentId());
         wrapper.ge("soa", StatementOfAccount::getCreateTime, dto.getBeginTime());
         wrapper.le("soa", StatementOfAccount::getCreateTime, dto.getEndTime());
         wrapper.orderByDesc("soa", StatementOfAccount::getId);
@@ -183,12 +193,57 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
 
     @Override
     public List<DocumentBySkuVo> getDocumentBySku(Long id) {
+
         Assert.notNull(id, "对账单id不能为空");
         StatementOfAccount statementOfAccount = getById(id);
         Assert.notNull(statementOfAccount, "没有找到对账单");
 
+        List<String> ordedrIdList = Arrays.stream(statementOfAccount.getOrderIdJoin().split(","))
+                .distinct().collect(Collectors.toList());
 
-        return null;
+        if (ordedrIdList.size() == 0) {
+            return Collections.emptyList();
+        }
+
+        List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, ordedrIdList));
+
+        // 生成结果集
+        List<DocumentBySkuVo> result = orderSkuList.stream()
+                .map(item -> DocumentBySkuVo.builder()
+                        .skuSpecId(item.getSkuId())
+                        .quantity(item.getQuantity())
+                        .unitPrice(item.getUnitPrice())
+                        .subtotal(item.getUnitPrice()
+                                .add(item.getCustomProcessingFee())
+                                .add(item.getLssueFee())
+                                .add(item.getDeliveryMaterialsFee())
+                                .add(item.getPackingLabor())
+                                .add(item.getPackagingMaterialCost()))
+                        .build())
+                .peek(item -> item.setTotal(item.getQuantity().multiply(item.getSubtotal())))
+                .collect(Collectors.toList());
+
+        // 赋值sku规格品名和品号
+        skuSpecService.attributeAssign(result, DocumentBySkuVo::getSkuSpecId, (item, skuSpec) -> {
+            item.setSkuSpecCode(skuSpec.getCode());
+            item.setSkuSpecName(skuSpec.getName());
+        });
+
+        // 合并单价、小计、sku规格id系统的对账数据
+        Collection<DocumentBySkuVo> documentBySkuVoCollection = result.stream()
+                .sorted(Comparator.comparing(DocumentBySkuVo::getSkuSpecCode))
+                .collect(Collectors.toMap(
+                        item -> item.getUnitPrice() + ":" + item.getSubtotal() + ":" + item.getSkuSpecId(),
+                        Function.identity(),
+                        (v1, v2) -> {
+                            v1.setQuantity(v2.getQuantity());
+                            v1.setTotal(v2.getTotal());
+                            return v1;
+                        }
+                )).values();
+
+        return new ArrayList<>(documentBySkuVoCollection);
     }
 
+
 }