|
@@ -17,12 +17,12 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.framework.config.ThreadPoolConfig;
|
|
|
import com.sd.business.entity.bom.bo.BomSpecBo;
|
|
|
+import com.sd.business.entity.bom.constant.BomClassifyConstant;
|
|
|
import com.sd.business.entity.department.po.Department;
|
|
|
import com.sd.business.entity.excel.enums.ExcelTypeEnum;
|
|
|
+import com.sd.business.entity.order.bo.OrderExchangeAccountBo;
|
|
|
import com.sd.business.entity.order.enums.OrderClassifyEnum;
|
|
|
-import com.sd.business.entity.order.po.OrderInfo;
|
|
|
-import com.sd.business.entity.order.po.OrderSku;
|
|
|
-import com.sd.business.entity.order.po.OrderSkuBom;
|
|
|
+import com.sd.business.entity.order.po.*;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
import com.sd.business.entity.statement.dto.FileUploadDto;
|
|
|
import com.sd.business.entity.statement.dto.StatementOfAccountDto;
|
|
@@ -33,9 +33,7 @@ import com.sd.business.mapper.statement.StatementOfAccountMapper;
|
|
|
import com.sd.business.service.bom.BomSpecService;
|
|
|
import com.sd.business.service.department.DepartmentService;
|
|
|
import com.sd.business.service.excel.ExcelGenerateLogService;
|
|
|
-import com.sd.business.service.order.OrderService;
|
|
|
-import com.sd.business.service.order.OrderSkuBomService;
|
|
|
-import com.sd.business.service.order.OrderSkuService;
|
|
|
+import com.sd.business.service.order.*;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountExportService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountService;
|
|
@@ -99,13 +97,18 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
@Autowired
|
|
|
private ExcelGenerateLogService excelGenerateLogService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderExchangeService orderExchangeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderExchangeDetailService orderExchangeDetailService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<StatementOfAccountVo> getPage(StatementOfAccountSelectDto dto) {
|
|
|
|
|
|
IWrapper<StatementOfAccount> wrapper = getWrapper();
|
|
|
wrapper.like("soa", StatementOfAccount::getCode, dto.getCode());
|
|
|
wrapper.eq("soa", StatementOfAccount::getDepartmentId, dto.getDepartmentId());
|
|
|
- wrapper.eq("soa", StatementOfAccount::getCheckStatus, dto.getCheckStatus());
|
|
|
wrapper.ge("soa", StatementOfAccount::getTimePeriod, dto.getBeginTime());
|
|
|
wrapper.le("soa", StatementOfAccount::getTimePeriod, dto.getEndTime());
|
|
|
wrapper.orderByDesc("soa", StatementOfAccount::getCode);
|
|
@@ -136,6 +139,9 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
Function.identity()
|
|
|
));
|
|
|
|
|
|
+
|
|
|
+ Map<Long, OrderExchangeAccountBo> exchangeAccountBoMap = orderExchangeService.orderExchangeAccountStatistics(idList);
|
|
|
+
|
|
|
for (StatementOfAccountVo record : records) {
|
|
|
record.setReceiptFileList(receiptFileMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
record.setProofFileList(proofFileMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
@@ -147,6 +153,14 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
record.setOrderNum(Convert.toInt(tempMap.get("orderNum"), 0));
|
|
|
record.setAmount(Convert.toBigDecimal(tempMap.get("amount"), BigDecimal.ZERO));
|
|
|
}
|
|
|
+ OrderExchangeAccountBo orderExchangeAccountBo = exchangeAccountBoMap.get(record.getId());
|
|
|
+ if (orderExchangeAccountBo != null) {
|
|
|
+
|
|
|
+ record.setOrderNum(record.getOrderNum() + orderExchangeAccountBo.getOrderNum());
|
|
|
+ record.setAmount(record.getAmount()
|
|
|
+ .subtract(orderExchangeAccountBo.getReturnAmount())
|
|
|
+ .add(BigDecimal.valueOf(orderExchangeAccountBo.getOrderSkuNum()).multiply(BigDecimal.valueOf(2))));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return page;
|
|
@@ -255,6 +269,10 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
|
|
|
@Override
|
|
|
public List<DocumentBySkuVo> getSkuDocument(List<Long> statementOfAccountIdList, Integer orderClassify) {
|
|
|
+
|
|
|
+ if (Objects.equals(orderClassify, OrderClassifyEnum.AFTER_SALE_ORDER.getKey())) {
|
|
|
+ return getAfterSaleSkuDocument(statementOfAccountIdList);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
List<Long> orderIdList = getOrderIdList(statementOfAccountIdList, orderClassify);
|
|
@@ -329,6 +347,10 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
|
|
|
@Override
|
|
|
public List<DocumentByBomVo> getBomDocument(List<Long> statementOfAccountIdList, Integer orderClassify) {
|
|
|
+
|
|
|
+ if (Objects.equals(orderClassify, OrderClassifyEnum.AFTER_SALE_ORDER.getKey())) {
|
|
|
+ return getAfterSaleBomDocument(statementOfAccountIdList);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
List<Long> orderIdList = getOrderIdList(statementOfAccountIdList, orderClassify);
|
|
@@ -356,7 +378,7 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
.laserMitochondrialSummary((Objects.equals(item.getCustomProcessingType(), "10")
|
|
|
? item.getCustomProcessingFee().multiply(item.getQuantity()) : BigDecimal.ZERO))
|
|
|
.lssueFeeSummary(item.getLssueFee().multiply(item.getQuantity()))
|
|
|
- .deliveryMaterialsFeeSummary(item.getDeliveryMaterialsFee().multiply(item.getQuantity()))
|
|
|
+ .deliveryMaterialsFeeSummary(item.getDeliveryMaterialsFee().multiply(item.getQuantity()).setScale(2, RoundingMode.HALF_UP))
|
|
|
.packingLaborSummary(item.getPackingLabor().multiply(item.getQuantity()))
|
|
|
.managementFeeSummary(item.getManagementFee().multiply(item.getQuantity()))
|
|
|
.proofingFeeSummary(item.getProofingFee())
|
|
@@ -452,6 +474,12 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
public List<DocumentByOrderVo> getOrderDocument(List<Long> statementOfAccountId, Integer orderClassify) {
|
|
|
|
|
|
Assert.notEmpty(statementOfAccountId, "对账单id不能为空");
|
|
|
+
|
|
|
+
|
|
|
+ if (Objects.equals(orderClassify, OrderClassifyEnum.AFTER_SALE_ORDER.getKey())) {
|
|
|
+ return getAfterSaleOrderDocument(statementOfAccountId);
|
|
|
+ }
|
|
|
+
|
|
|
List<OrderInfo> orderList = orderService.list(q -> q
|
|
|
.in(OrderInfo::getStatementOfAccountId, statementOfAccountId)
|
|
|
.eq(OrderInfo::getClassify, orderClassify));
|
|
@@ -569,16 +597,21 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
@Override
|
|
|
public StatementOrderClassifyTotalCountVo getOrderClassifyTotalCount(List<Long> idList) {
|
|
|
Assert.notEmpty(idList, "对账单id不能为空");
|
|
|
- return orderService.getOrderClassifyTotalCount(idList);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getNotCheckCount() {
|
|
|
-
|
|
|
- List<Department> departmentList = departmentService.list(q -> q.like(Department::getName, "实业").or().eq(Department::getName, "佰卓").select(BaseIdPo::getId));
|
|
|
- List<Long> departmentIds = departmentList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
- return this.count(q -> q.in(StatementOfAccount::getDepartmentId, departmentIds)
|
|
|
- .eq(StatementOfAccount::getCheckStatus, StatusConstant.NO));
|
|
|
+ StatementOrderClassifyTotalCountVo vo = orderService.getOrderClassifyTotalCount(idList);
|
|
|
+ if (vo == null) {
|
|
|
+ vo = new StatementOrderClassifyTotalCountVo();
|
|
|
+ vo.setWlnOrderCount(0);
|
|
|
+ vo.setPurchaseOrderCount(0);
|
|
|
+ vo.setOutsourceOrderCount(0);
|
|
|
+ vo.setAfterSaleOrderCount(0);
|
|
|
+ vo.setNoReasonOrderCount(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ long count = orderExchangeService.count(q -> q
|
|
|
+ .eq(OrderExchange::getStatus, StatusConstant.YES)
|
|
|
+ .in(OrderExchange::getStatementOfAccountId, idList));
|
|
|
+ vo.setAfterSaleOrderCount((int) count);
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -691,4 +724,421 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
return bomSpecList;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 获取售后订单bom
|
|
|
+ */
|
|
|
+ private List<DocumentByOrderVo.BomSpec> getAfterSaleBomSpecList(List<OrderSku> orderSkuList, List<OrderSkuBom> orderSkuBomList) {
|
|
|
+
|
|
|
+ List<DocumentByOrderVo.BomSpec> bomSpecList = orderSkuList.stream()
|
|
|
+ .map(item -> {
|
|
|
+ DocumentByOrderVo.BomSpec bomSpec = new DocumentByOrderVo.BomSpec();
|
|
|
+ bomSpec.setOrderSkuId(item.getId());
|
|
|
+ bomSpec.setBomSpecId(item.getBomSpecId());
|
|
|
+ bomSpec.setQuantity(item.getQuantity());
|
|
|
+ bomSpec.setUnitPrice(item.getUnitPrice());
|
|
|
+ bomSpec.setCustomProcessingType(item.getCustomProcessingType());
|
|
|
+ bomSpec.setLaserLogoSummary((Objects.equals(item.getCustomProcessingType(), "20")
|
|
|
+ ? item.getCustomProcessingFee() : BigDecimal.ZERO));
|
|
|
+ bomSpec.setLaserMitochondrialSummary((Objects.equals(item.getCustomProcessingType(), "10")
|
|
|
+ ? item.getCustomProcessingFee() : BigDecimal.ZERO));
|
|
|
+ bomSpec.setLssueFeeSummary(item.getLssueFee());
|
|
|
+ bomSpec.setDeliveryMaterialsFeeSummary(item.getDeliveryMaterialsFee());
|
|
|
+ bomSpec.setPackingLaborSummary(item.getPackingLabor());
|
|
|
+ bomSpec.setManagementFeeSummary(item.getManagementFee());
|
|
|
+ bomSpec.setProofingFeeSummary(item.getProofingFee().divide(item.getQuantity(), 2, RoundingMode.HALF_UP));
|
|
|
+ return bomSpec;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> map = bomSpecList.stream().collect(
|
|
|
+ Collectors.toMap(DocumentByOrderVo.BomSpec::getOrderSkuId, DocumentByOrderVo.BomSpec::getQuantity));
|
|
|
+
|
|
|
+
|
|
|
+ List<DocumentByOrderVo.BomSpec> packBomSpecList = orderSkuBomList.stream()
|
|
|
+ .map(item -> {
|
|
|
+ DocumentByOrderVo.BomSpec bomSpec = new DocumentByOrderVo.BomSpec();
|
|
|
+ bomSpec.setOrderSkuId(item.getOrderSkuId());
|
|
|
+ bomSpec.setBomSpecId(item.getBomSpecId());
|
|
|
+ bomSpec.setQuantity(item.getQuantity());
|
|
|
+ bomSpec.setUnitPrice(item.getUnitPrice());
|
|
|
+ return bomSpec;
|
|
|
+ })
|
|
|
+ .peek(item -> item.setQuantity(ObjectUtil.equals(map.get(item.getOrderSkuId()), BigDecimal.ZERO) ? item.getQuantity() : map.get(item.getOrderSkuId()).multiply(item.getQuantity())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ bomSpecList.addAll(packBomSpecList);
|
|
|
+
|
|
|
+ List<Long> bomSpecIdList = bomSpecList.stream().map(DocumentByOrderVo.BomSpec::getBomSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+
|
|
|
+ for (DocumentByOrderVo.BomSpec bomSpec : bomSpecList) {
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(bomSpec.getBomSpecId());
|
|
|
+
|
|
|
+ bomSpec.setBomSpecCode(bomSpecBo.getBomSpecCode());
|
|
|
+ bomSpec.setBomSpecName(bomSpecBo.getBomSpecName());
|
|
|
+ bomSpec.setClassifyName(bomSpecBo.getClassifyName());
|
|
|
+ bomSpec.setUnit(bomSpecBo.getUnit());
|
|
|
+ }
|
|
|
+
|
|
|
+ return bomSpecList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取售后订单记录
|
|
|
+ * @param statementOfAccountId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<DocumentByOrderVo> getAfterSaleOrderDocument(List<Long> statementOfAccountId) {
|
|
|
+
|
|
|
+ List<OrderExchange> list = orderExchangeService.list(q -> q
|
|
|
+ .eq(OrderExchange::getStatus, StatusConstant.YES)
|
|
|
+ .in(OrderExchange::getStatementOfAccountId, statementOfAccountId)
|
|
|
+ .select(BaseIdPo::getId, OrderExchange::getOrderInfoId));
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<Long> orderExchangeIdList = list.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ List<Long> orderIdList = list.stream().map(OrderExchange::getOrderInfoId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<OrderExchangeDetail> exchangeDetailList = orderExchangeDetailService.list(q -> q
|
|
|
+ .in(OrderExchangeDetail::getOrderExchangeId, orderExchangeIdList));
|
|
|
+
|
|
|
+ if (exchangeDetailList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Map<Long, BigDecimal> exchangeDetailMap = exchangeDetailList.stream().collect(Collectors.toMap(
|
|
|
+ OrderExchangeDetail::getOrderSkuId,
|
|
|
+ OrderExchangeDetail::getQuantity,
|
|
|
+ BigDecimal::add));
|
|
|
+
|
|
|
+
|
|
|
+ List<OrderInfo> orderList = orderService.list(q -> q.in(BaseIdPo::getId, orderIdList));
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(BaseIdPo::getId, exchangeDetailMap.keySet()));
|
|
|
+
|
|
|
+ List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderSkuId, exchangeDetailMap.keySet()));
|
|
|
+
|
|
|
+ List<OrderSkuBom> tempOrderSkuBomList = this.getReusableOrderSkuBomList(orderSkuBomList);
|
|
|
+ Map<Long, BigDecimal> packagingMaterialCostMap = tempOrderSkuBomList.stream()
|
|
|
+ .peek(item -> item.setUnitPrice(item.getUnitPrice().negate()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ OrderSkuBom::getOrderSkuId,
|
|
|
+ v -> v.getUnitPrice().multiply(v.getQuantity()),
|
|
|
+ BigDecimal::add
|
|
|
+ ));
|
|
|
+
|
|
|
+
|
|
|
+ for (OrderSku orderSku : orderSkuList) {
|
|
|
+ orderSku.setQuantity(exchangeDetailMap.get(orderSku.getId()));
|
|
|
+ orderSku.setProofingFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setLssueFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setPackingLabor(BigDecimal.ZERO);
|
|
|
+ orderSku.setCustomProcessingFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setUnitPrice(orderSku.getUnitPrice().negate());
|
|
|
+ orderSku.setDeliveryMaterialsFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setManagementFee(BigDecimal.ZERO);
|
|
|
+ orderSku.setPackagingMaterialCost(packagingMaterialCostMap.getOrDefault(orderSku.getId(), BigDecimal.ZERO));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DocumentByOrderVo> result = orderList.stream().map(item -> {
|
|
|
+ DocumentByOrderVo documentByOrderVo = new DocumentByOrderVo();
|
|
|
+ documentByOrderVo.setOrderId(item.getId());
|
|
|
+ documentByOrderVo.setWlnCreateTime(ObjectUtil.defaultIfNull(item.getWlnCreateTime(), item.getCreateTime()));
|
|
|
+ documentByOrderVo.setCode(item.getCode());
|
|
|
+ documentByOrderVo.setWlnCode(item.getWlnCode());
|
|
|
+
|
|
|
+ documentByOrderVo.setSourcePlatform(item.getSourcePlatform());
|
|
|
+ documentByOrderVo.setShopName(item.getShopName());
|
|
|
+ documentByOrderVo.setDepartmentId(item.getDepartmentId());
|
|
|
+
|
|
|
+ return documentByOrderVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ SecurityContext context = SecurityContextHolder.getContext();
|
|
|
+
|
|
|
+ CompletableFuture<List<DocumentByOrderVo.SkuSpec>> skuSpecListCompletableFuture = CompletableFuture.supplyAsync(
|
|
|
+ () -> {
|
|
|
+ SecurityContextHolder.setContext(context);
|
|
|
+ return getSkuSpecList(orderSkuList);
|
|
|
+ }, threadPoolExecutor);
|
|
|
+
|
|
|
+ CompletableFuture<List<DocumentByOrderVo.BomSpec>> bomSpecListCompletableFuture = CompletableFuture.supplyAsync(
|
|
|
+ () -> {
|
|
|
+ SecurityContextHolder.setContext(context);
|
|
|
+ return getAfterSaleBomSpecList(orderSkuList, tempOrderSkuBomList);
|
|
|
+ }, threadPoolExecutor);
|
|
|
+
|
|
|
+
|
|
|
+ List<DocumentByOrderVo.BomSpec> bomSpecList = bomSpecListCompletableFuture.join();
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, List<DocumentByOrderVo.BomSpec>> bomSpecMap = bomSpecList.stream()
|
|
|
+ .collect(Collectors.groupingBy(DocumentByOrderVo.BomSpec::getOrderSkuId));
|
|
|
+
|
|
|
+
|
|
|
+ List<DocumentByOrderVo.SkuSpec> skuSpecList = skuSpecListCompletableFuture.join();
|
|
|
+
|
|
|
+ for (DocumentByOrderVo.SkuSpec skuSpec : skuSpecList) {
|
|
|
+ skuSpec.setBomSpecList(bomSpecMap.getOrDefault(skuSpec.getOrderSkuId(), Collections.emptyList()));
|
|
|
+
|
|
|
+ skuSpec.setCheckFee(BigDecimal.valueOf(2).multiply(skuSpec.getQuantity()));
|
|
|
+ skuSpec.setSubtotal(skuSpec.getSubtotal()
|
|
|
+ .add(skuSpec.getCheckFee()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, List<DocumentByOrderVo.SkuSpec>> skuSpecMap = skuSpecList.stream()
|
|
|
+ .collect(Collectors.groupingBy(DocumentByOrderVo.SkuSpec::getOrderId));
|
|
|
+ result.forEach(item -> {
|
|
|
+ List<DocumentByOrderVo.SkuSpec> specList = skuSpecMap.getOrDefault(item.getOrderId(), Collections.emptyList());
|
|
|
+ item.setSkuSpecList(specList);
|
|
|
+ BigDecimal total = specList.stream().map(DocumentByOrderVo.SkuSpec::getSubtotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ item.setTotal(total);
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取售后bom记录
|
|
|
+ * @param statementOfAccountIdList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<DocumentByBomVo> getAfterSaleBomDocument(List<Long> statementOfAccountIdList) {
|
|
|
+ Assert.notEmpty(statementOfAccountIdList, "对账单id不能为空");
|
|
|
+
|
|
|
+ List<Long> orderExchangeIdList = orderExchangeService.list(q -> q
|
|
|
+ .eq(OrderExchange::getStatus, StatusConstant.YES)
|
|
|
+ .in(OrderExchange::getStatementOfAccountId, statementOfAccountIdList)
|
|
|
+ .select(BaseIdPo::getId))
|
|
|
+ .stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (orderExchangeIdList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderExchangeDetail> exchangeDetailList = orderExchangeDetailService.list(q -> q
|
|
|
+ .in(OrderExchangeDetail::getOrderExchangeId, orderExchangeIdList));
|
|
|
+
|
|
|
+ if (exchangeDetailList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Map<Long, BigDecimal> exchangeDetailMap = exchangeDetailList.stream().collect(Collectors.toMap(
|
|
|
+ OrderExchangeDetail::getOrderSkuId,
|
|
|
+ OrderExchangeDetail::getQuantity,
|
|
|
+ BigDecimal::add));
|
|
|
+
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(BaseIdPo::getId, exchangeDetailMap.keySet()));
|
|
|
+
|
|
|
+
|
|
|
+ List<DocumentByBomVo> result = orderSkuList.stream()
|
|
|
+ .map(item -> DocumentByBomVo.builder()
|
|
|
+ .bomSpecId(item.getBomSpecId())
|
|
|
+ .orderId(item.getOrderId())
|
|
|
+ .quantity(exchangeDetailMap.get(item.getId()))
|
|
|
+ .unitPrice(item.getUnitPrice().negate())
|
|
|
+ .laserLogoSummary(BigDecimal.ZERO)
|
|
|
+ .laserMitochondrialSummary(BigDecimal.ZERO)
|
|
|
+ .lssueFeeSummary(BigDecimal.ZERO)
|
|
|
+ .deliveryMaterialsFeeSummary(BigDecimal.ZERO)
|
|
|
+ .packingLaborSummary(BigDecimal.ZERO)
|
|
|
+ .managementFeeSummary(BigDecimal.ZERO)
|
|
|
+ .checkFeeSummary(BigDecimal.valueOf(2).multiply(exchangeDetailMap.get(item.getId())))
|
|
|
+ .build())
|
|
|
+ .peek(item -> item.setSubtotal(
|
|
|
+ item.getUnitPrice()
|
|
|
+ .multiply(item.getQuantity())
|
|
|
+ .add(item.getLaserLogoSummary())
|
|
|
+ .add(item.getLaserMitochondrialSummary())
|
|
|
+ .add(item.getLssueFeeSummary())
|
|
|
+ .add(item.getDeliveryMaterialsFeeSummary())
|
|
|
+ .add(item.getPackingLaborSummary())
|
|
|
+ .add(item.getManagementFeeSummary())
|
|
|
+ .add(item.getCheckFeeSummary())
|
|
|
+ .setScale(2, RoundingMode.HALF_UP)
|
|
|
+ ))
|
|
|
+ .peek(item -> item.setTotal(item.getSubtotal()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ bomSpecService.attributeAssign(result, DocumentByBomVo::getBomSpecId, (item, bomSpec) -> {
|
|
|
+ item.setBomSpecCode(bomSpec.getCode());
|
|
|
+ item.setBomSpecName(bomSpec.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ Collection<DocumentByBomVo> documentByBomVoCollection = result.stream()
|
|
|
+ .sorted(comparing(DocumentByBomVo::getBomSpecCode))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.getUnitPrice() + ":" + item.getBomSpecId(),
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
|
|
|
+ v1.setLaserLogoSummary(v1.getLaserLogoSummary().add(v2.getLaserLogoSummary()));
|
|
|
+ v1.setLaserMitochondrialSummary(v1.getLaserMitochondrialSummary().add(v2.getLaserMitochondrialSummary()));
|
|
|
+ v1.setLssueFeeSummary(v1.getLssueFeeSummary().add(v2.getLssueFeeSummary()));
|
|
|
+ v1.setDeliveryMaterialsFeeSummary(v1.getDeliveryMaterialsFeeSummary().add(v2.getDeliveryMaterialsFeeSummary()));
|
|
|
+ v1.setPackingLaborSummary(v1.getPackingLaborSummary().add(v2.getPackingLaborSummary()));
|
|
|
+ v1.setManagementFeeSummary(v1.getManagementFeeSummary().add(v2.getManagementFeeSummary()));
|
|
|
+ v1.setProofingFeeSummary(v1.getProofingFeeSummary().add(v2.getProofingFeeSummary()));
|
|
|
+ v1.setSubtotal(v1.getSubtotal().add(v2.getSubtotal()));
|
|
|
+ v1.setTotal(v1.getSubtotal());
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+ )).values();
|
|
|
+
|
|
|
+
|
|
|
+ result = new ArrayList<>(documentByBomVoCollection);
|
|
|
+
|
|
|
+ result.sort(comparing(DocumentByBomVo::getBomSpecName));
|
|
|
+
|
|
|
+ Map<Long, BigDecimal> orderSkuMap = orderSkuList.stream().collect(Collectors.toMap(BaseIdPo::getId, OrderSku::getQuantity));
|
|
|
+
|
|
|
+
|
|
|
+ List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderSkuId, exchangeDetailMap.keySet()));
|
|
|
+
|
|
|
+ List<OrderSkuBom> tempOrderSkuBomList = this.getReusableOrderSkuBomList(orderSkuBomList);
|
|
|
+
|
|
|
+ List<DocumentByBomVo> bomVoList = tempOrderSkuBomList.stream()
|
|
|
+ .map(item ->
|
|
|
+ DocumentByBomVo.builder()
|
|
|
+ .bomSpecId(item.getBomSpecId())
|
|
|
+ .quantity(item.getQuantity().multiply(orderSkuMap.get(item.getOrderSkuId())))
|
|
|
+ .unitPrice(item.getUnitPrice().negate())
|
|
|
+ .subtotal(item.getUnitPrice().multiply(item.getQuantity().multiply(orderSkuMap.get(item.getOrderSkuId()))).negate())
|
|
|
+ .total(item.getUnitPrice().multiply(item.getQuantity().multiply(orderSkuMap.get(item.getOrderSkuId()))).negate())
|
|
|
+ .build()
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ bomSpecService.attributeAssign(bomVoList, DocumentByBomVo::getBomSpecId, (item, bomSpec) -> {
|
|
|
+ item.setBomSpecCode(bomSpec.getCode());
|
|
|
+ item.setBomSpecName(bomSpec.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ Collection<DocumentByBomVo> bomValues = bomVoList.stream()
|
|
|
+ .sorted(comparing(DocumentByBomVo::getBomSpecCode))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.getUnitPrice() + ":" + item.getBomSpecId(),
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
|
|
|
+ v1.setSubtotal(v1.getSubtotal().add(v2.getSubtotal()));
|
|
|
+ v1.setTotal(v1.getSubtotal());
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+ )).values();
|
|
|
+
|
|
|
+
|
|
|
+ result.addAll(bomValues);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取售后sku记录
|
|
|
+ * @param statementOfAccountIdList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<DocumentBySkuVo> getAfterSaleSkuDocument(List<Long> statementOfAccountIdList) {
|
|
|
+ Assert.notEmpty(statementOfAccountIdList, "对账单id不能为空");
|
|
|
+
|
|
|
+ List<Long> orderExchangeIdList = orderExchangeService.list(q -> q
|
|
|
+ .eq(OrderExchange::getStatus, StatusConstant.YES)
|
|
|
+ .in(OrderExchange::getStatementOfAccountId, statementOfAccountIdList)
|
|
|
+ .select(BaseIdPo::getId))
|
|
|
+ .stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (orderExchangeIdList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderExchangeDetail> exchangeDetailList = orderExchangeDetailService.list(q -> q
|
|
|
+ .in(OrderExchangeDetail::getOrderExchangeId, orderExchangeIdList));
|
|
|
+ Map<Long, BigDecimal> exchangeDetailMap = exchangeDetailList.stream().collect(Collectors.toMap(
|
|
|
+ OrderExchangeDetail::getOrderSkuId,
|
|
|
+ OrderExchangeDetail::getQuantity,
|
|
|
+ BigDecimal::add));
|
|
|
+ if (exchangeDetailList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(BaseIdPo::getId, exchangeDetailMap.keySet()));
|
|
|
+ List<Long> orderSkuIds = orderSkuList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderSkuId, orderSkuIds));
|
|
|
+ List<OrderSkuBom> tempOrderSkuBomList = this.getReusableOrderSkuBomList(orderSkuBomList);
|
|
|
+ Map<Long, BigDecimal> packagingMaterialCostMap = tempOrderSkuBomList.stream()
|
|
|
+ .collect(Collectors.toMap(OrderSkuBom::getOrderSkuId, v -> v.getUnitPrice().multiply(v.getQuantity()), BigDecimal::add));
|
|
|
+
|
|
|
+
|
|
|
+ List<DocumentBySkuVo> documentBySkuVoList = orderSkuList.stream()
|
|
|
+ .map(item -> DocumentBySkuVo.builder()
|
|
|
+ .skuSpecId(item.getSkuSpecId())
|
|
|
+ .orderId(item.getOrderId())
|
|
|
+ .quantity(exchangeDetailMap.get(item.getId()))
|
|
|
+ .unitPrice(item.getUnitPrice()
|
|
|
+ .add(packagingMaterialCostMap.getOrDefault(item.getId(), BigDecimal.ZERO))
|
|
|
+ .negate()
|
|
|
+ )
|
|
|
+ .checkFee(BigDecimal.valueOf(2).multiply(exchangeDetailMap.get(item.getId())))
|
|
|
+ .build())
|
|
|
+ .peek(item ->
|
|
|
+ item.setSubtotal(item.getQuantity()
|
|
|
+ .multiply(item.getUnitPrice())
|
|
|
+ .add(item.getCheckFee())
|
|
|
+ .setScale(2, RoundingMode.HALF_UP)))
|
|
|
+ .peek(item -> item.setTotal(item.getSubtotal()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ skuSpecService.attributeAssign(documentBySkuVoList, DocumentBySkuVo::getSkuSpecId, (item, skuSpec) -> {
|
|
|
+ item.setSkuSpecCode(skuSpec.getCode());
|
|
|
+ item.setSkuSpecName(skuSpec.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ Collection<DocumentBySkuVo> documentBySkuVoCollection = documentBySkuVoList.stream()
|
|
|
+ .sorted(comparing(DocumentBySkuVo::getSkuSpecCode))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.getUnitPrice() + ":" + item.getSkuSpecId(),
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+ v1.setQuantity(v1.getQuantity().add(v2.getQuantity()));
|
|
|
+ v1.setSubtotal(v1.getSubtotal().add(v2.getSubtotal()));
|
|
|
+ v1.setTotal(v1.getTotal().add(v2.getTotal()));
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+ )).values();
|
|
|
+
|
|
|
+ return new ArrayList<>(documentBySkuVoCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取可二次利用的包材
|
|
|
+ * @param orderSkuBomList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<OrderSkuBom> getReusableOrderSkuBomList(List<OrderSkuBom> orderSkuBomList) {
|
|
|
+ List<Long> bomSpecIdList = orderSkuBomList.stream()
|
|
|
+ .map(OrderSkuBom::getBomSpecId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Long, BomSpecBo> bomSpecBoMap = skuSpecService.getBomSpecBoByIdList(bomSpecIdList);
|
|
|
+ return orderSkuBomList.stream()
|
|
|
+ .filter(item -> {
|
|
|
+ BomSpecBo bomSpecBo = bomSpecBoMap.get(item.getBomSpecId());
|
|
|
+ if (bomSpecBo == null
|
|
|
+ || !(Objects.equals(bomSpecBo.getClassifyId(), BomClassifyConstant.MESH_BAG)
|
|
|
+ || Objects.equals(bomSpecBo.getClassifyId(), BomClassifyConstant.SUSPENDERS))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
}
|