|
@@ -2,8 +2,8 @@ package com.sd.business.service.statement.impl;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.file.entity.FileInfoVo;
|
|
@@ -16,10 +16,12 @@ import com.sd.business.entity.statement.dto.FileUploadDto;
|
|
|
import com.sd.business.entity.statement.dto.StatementOfAccountDto;
|
|
|
import com.sd.business.entity.statement.dto.StatementOfAccountSelectDto;
|
|
|
import com.sd.business.entity.statement.po.StatementOfAccount;
|
|
|
+import com.sd.business.entity.statement.vo.DocumentByBomVo;
|
|
|
import com.sd.business.entity.statement.vo.DocumentBySkuVo;
|
|
|
import com.sd.business.entity.statement.vo.ReconciliationDetailVo;
|
|
|
import com.sd.business.entity.statement.vo.StatementOfAccountVo;
|
|
|
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.order.OrderService;
|
|
|
import com.sd.business.service.order.OrderSkuService;
|
|
@@ -29,7 +31,9 @@ import com.sd.business.util.CodeEnum;
|
|
|
import com.sd.framework.util.Assert;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -58,6 +62,9 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
@Autowired
|
|
|
private SkuSpecService skuSpecService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BomSpecService bomSpecService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<StatementOfAccountVo> getPage(StatementOfAccountSelectDto dto) {
|
|
|
|
|
@@ -79,41 +86,32 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
Map<Long, List<FileInfoVo>> receiptFileMap = ObsFileUtil.getFileMap(idList, 1);
|
|
|
Map<Long, List<FileInfoVo>> proofFileMap = ObsFileUtil.getFileMap(idList, 2);
|
|
|
|
|
|
- List<String> orderIdList = records.stream()
|
|
|
- .map(StatementOfAccount::getOrderIdJoin)
|
|
|
- .filter(StrUtil::isNotBlank)
|
|
|
- .flatMap(item -> Arrays.stream(item.split(",")))
|
|
|
- .distinct()
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- Map<Long, String> orderIdCodeMap;
|
|
|
- if (orderIdList.size() == 0) {
|
|
|
- orderIdCodeMap = orderService.mapKV(BaseIdPo::getId, OrderInfo::getCode,
|
|
|
- q -> q.select(BaseIdPo::getId, OrderInfo::getCode).in(BaseIdPo::getId, orderIdList));
|
|
|
- } else {
|
|
|
- orderIdCodeMap = new HashMap<>();
|
|
|
- }
|
|
|
+ Map<Long, Map<String, Object>> map = orderService.listMaps(Wrappers.<OrderInfo>query()
|
|
|
+ .select(
|
|
|
+ "statement_of_account_id as statementOfAccountId",
|
|
|
+ "sum(total_amount) as amount",
|
|
|
+ "count(0) as orderNum"
|
|
|
+ )
|
|
|
+ .in("statement_of_account_id", idList)
|
|
|
+ .groupBy("statement_of_account_id")
|
|
|
+ )
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> Convert.toLong(item.get("statementOfAccountId")),
|
|
|
+ Function.identity()
|
|
|
+ ));
|
|
|
|
|
|
for (StatementOfAccountVo record : records) {
|
|
|
record.setReceiptFileList(receiptFileMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
record.setProofFileList(proofFileMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
-
|
|
|
- String orderIdJoin = record.getOrderIdJoin();
|
|
|
- StringJoiner codeJoiner = new StringJoiner(",");
|
|
|
- int orderNum = 0;
|
|
|
- for (String orderId : orderIdJoin.split(",")) {
|
|
|
- if (StrUtil.isBlank(orderId)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String orderCode = orderIdCodeMap.get(Convert.toLong(orderId));
|
|
|
- if (StrUtil.isBlank(orderCode)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- codeJoiner.add(orderCode);
|
|
|
- orderNum++;
|
|
|
+ Map<String, Object> tempMap = map.get(record.getId());
|
|
|
+ if (tempMap == null) {
|
|
|
+ record.setOrderNum(0);
|
|
|
+ record.setAmount(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ record.setOrderNum(Convert.toInt(tempMap.get("orderNum"), 0));
|
|
|
+ record.setAmount(Convert.toBigDecimal(tempMap.get("amount"), BigDecimal.ZERO));
|
|
|
}
|
|
|
- record.setOrderCodeJoin(codeJoiner.toString());
|
|
|
- record.setOrderNum(orderNum);
|
|
|
}
|
|
|
|
|
|
return page;
|
|
@@ -121,29 +119,22 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
|
|
|
@Override
|
|
|
public List<ReconciliationDetailVo> detail(Long id) {
|
|
|
- StatementOfAccount StatementOfAccount = this.getById(id);
|
|
|
- String orderIdJoin = StatementOfAccount.getOrderIdJoin();
|
|
|
-
|
|
|
- List<ReconciliationDetailVo> result = Arrays.stream(orderIdJoin.split(","))
|
|
|
- .map(Convert::toLong)
|
|
|
- .filter(ObjectUtil::isNotNull)
|
|
|
- .distinct()
|
|
|
- .map(item -> ReconciliationDetailVo.builder().orderId(item).build())
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- orderService.attributeAssign(result, ReconciliationDetailVo::getOrderId, (item, order) -> {
|
|
|
- item.setDepartmentId(order.getDepartmentId());
|
|
|
- item.setOrderCode(order.getCode());
|
|
|
- item.setTotalAmount(order.getTotalAmount());
|
|
|
- item.setProductTotalAmount(order.getProductTotalAmount());
|
|
|
- item.setCustomProcessingFee(order.getCustomProcessingFee());
|
|
|
- item.setLssueFee(order.getLssueFee());
|
|
|
- item.setDeliveryMaterialsFee(order.getDeliveryMaterialsFee());
|
|
|
- item.setPackingLabor(order.getPackingLabor());
|
|
|
- item.setPackagingMaterialCost(order.getPackagingMaterialCost());
|
|
|
- });
|
|
|
|
|
|
- result = result.stream().filter(item -> ObjectUtil.isNotEmpty(item.getOrderCode())).collect(Collectors.toList());
|
|
|
+ List<OrderInfo> orderInfoList = orderService.list(q -> q.eq(OrderInfo::getStatementOfAccountId, id));
|
|
|
+
|
|
|
+ List<ReconciliationDetailVo> result = orderInfoList.stream().map(item -> ReconciliationDetailVo.builder()
|
|
|
+ .orderId(item.getId())
|
|
|
+ .departmentId(item.getDepartmentId())
|
|
|
+ .orderCode(item.getCode())
|
|
|
+ .totalAmount(item.getTotalAmount())
|
|
|
+ .productTotalAmount(item.getProductTotalAmount())
|
|
|
+ .customProcessingFee(item.getCustomProcessingFee())
|
|
|
+ .lssueFee(item.getLssueFee())
|
|
|
+ .deliveryMaterialsFee(item.getDeliveryMaterialsFee())
|
|
|
+ .packingLabor(item.getPackingLabor())
|
|
|
+ .packagingMaterialCost(item.getPackagingMaterialCost())
|
|
|
+ .build()
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
|
|
departmentService.attributeAssign(result, ReconciliationDetailVo::getDepartmentId, (item, department) -> {
|
|
|
item.setDepartmentName(department.getName());
|
|
@@ -152,36 +143,57 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(StatementOfAccountDto statementOfAccountDto) {
|
|
|
|
|
|
- String orderIdJoin = statementOfAccountDto.getOrderIdList()
|
|
|
- .stream()
|
|
|
- .map(Convert::toStr)
|
|
|
- .collect(Collectors.joining(","));
|
|
|
+ List<Long> orderIdList = statementOfAccountDto.getOrderIdList();
|
|
|
|
|
|
statementOfAccountDto.setCode(CodeEnum.STATEMENT_OF_ACCOUNT_CODE.getCode());
|
|
|
statementOfAccountDto.setType(1);
|
|
|
- statementOfAccountDto.setOrderIdJoin(orderIdJoin);
|
|
|
this.save(statementOfAccountDto);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(orderIdList)) {
|
|
|
+ orderService.update(q -> q
|
|
|
+ .in(BaseIdPo::getId, orderIdList)
|
|
|
+ .set(OrderInfo::getStatementOfAccountId, statementOfAccountDto.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void edit(StatementOfAccountDto statementOfAccountDto) {
|
|
|
+ Long statementOfAccountId = statementOfAccountDto.getId();
|
|
|
+ List<Long> orderIdList = statementOfAccountDto.getOrderIdList();
|
|
|
|
|
|
- String orderIdJoin = statementOfAccountDto.getOrderIdList()
|
|
|
- .stream()
|
|
|
- .map(Convert::toStr)
|
|
|
- .collect(Collectors.joining(","));
|
|
|
+ Assert.notNull(statementOfAccountId, "对账单id不能为空");
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(orderIdList)) {
|
|
|
+ orderService.update(q -> q
|
|
|
+ .in(BaseIdPo::getId, orderIdList)
|
|
|
+ .set(OrderInfo::getStatementOfAccountId, statementOfAccountId)
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
- statementOfAccountDto.setOrderIdJoin(orderIdJoin);
|
|
|
+ orderService.update(q -> q
|
|
|
+ .eq(OrderInfo::getStatementOfAccountId, statementOfAccountId)
|
|
|
+ .notIn(ObjectUtil.isNotEmpty(orderIdList), BaseIdPo::getId, orderIdList)
|
|
|
+ .set(OrderInfo::getStatementOfAccountId, null)
|
|
|
+ );
|
|
|
|
|
|
- this.updateById(statementOfAccountDto);
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
+
|
|
|
+ orderService.update(q -> q
|
|
|
+ .eq(OrderInfo::getStatementOfAccountId, id)
|
|
|
+ .set(OrderInfo::getStatementOfAccountId, null)
|
|
|
+ );
|
|
|
+
|
|
|
this.removeById(id);
|
|
|
ObsFileUtil.removeFile(id);
|
|
|
}
|
|
@@ -192,51 +204,49 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DocumentBySkuVo> getDocumentBySku(Long id) {
|
|
|
-
|
|
|
- Assert.notNull(id, "对账单id不能为空");
|
|
|
- StatementOfAccount statementOfAccount = getById(id);
|
|
|
- Assert.notNull(statementOfAccount, "没有找到对账单");
|
|
|
+ public List<DocumentBySkuVo> getDocumentBySku(Long statementOfAccountId) {
|
|
|
|
|
|
- List<String> ordedrIdList = Arrays.stream(statementOfAccount.getOrderIdJoin().split(","))
|
|
|
- .distinct().collect(Collectors.toList());
|
|
|
+ // 获取订单id列表
|
|
|
+ List<Long> ordedrIdList = getOrderIdList(statementOfAccountId);
|
|
|
|
|
|
if (ordedrIdList.size() == 0) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
+ // 获取订单sku
|
|
|
List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, ordedrIdList));
|
|
|
|
|
|
// 生成结果集
|
|
|
- List<DocumentBySkuVo> result = orderSkuList.stream()
|
|
|
+ List<DocumentBySkuVo> documentBySkuVoList = orderSkuList.stream()
|
|
|
.map(item -> DocumentBySkuVo.builder()
|
|
|
.skuSpecId(item.getSkuId())
|
|
|
.quantity(item.getQuantity())
|
|
|
- .unitPrice(item.getUnitPrice())
|
|
|
- .subtotal(item.getUnitPrice()
|
|
|
+ .unitPrice(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())))
|
|
|
+ .peek(item -> item.setSubtotal(item.getQuantity().multiply(item.getUnitPrice())))
|
|
|
+ .peek(item -> item.setTotal(item.getSubtotal()))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
// 赋值sku规格品名和品号
|
|
|
- skuSpecService.attributeAssign(result, DocumentBySkuVo::getSkuSpecId, (item, skuSpec) -> {
|
|
|
+ skuSpecService.attributeAssign(documentBySkuVoList, DocumentBySkuVo::getSkuSpecId, (item, skuSpec) -> {
|
|
|
item.setSkuSpecCode(skuSpec.getCode());
|
|
|
item.setSkuSpecName(skuSpec.getName());
|
|
|
});
|
|
|
|
|
|
// 合并单价、小计、sku规格id系统的对账数据
|
|
|
- Collection<DocumentBySkuVo> documentBySkuVoCollection = result.stream()
|
|
|
+ Collection<DocumentBySkuVo> documentBySkuVoCollection = documentBySkuVoList.stream()
|
|
|
.sorted(Comparator.comparing(DocumentBySkuVo::getSkuSpecCode))
|
|
|
.collect(Collectors.toMap(
|
|
|
- item -> item.getUnitPrice() + ":" + item.getSubtotal() + ":" + item.getSkuSpecId(),
|
|
|
+ item -> item.getUnitPrice() + ":" + item.getSkuSpecId(),
|
|
|
Function.identity(),
|
|
|
(v1, v2) -> {
|
|
|
v1.setQuantity(v2.getQuantity());
|
|
|
+ v1.setSubtotal(v2.getSubtotal());
|
|
|
v1.setTotal(v2.getTotal());
|
|
|
return v1;
|
|
|
}
|
|
@@ -245,5 +255,65 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
|
|
|
return new ArrayList<>(documentBySkuVoCollection);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<DocumentByBomVo> getDocumentByBom(Long statementOfAccountId) {
|
|
|
+
|
|
|
+ // 获取订单id列表
|
|
|
+ List<Long> ordedrIdList = getOrderIdList(statementOfAccountId);
|
|
|
+
|
|
|
+ if (ordedrIdList.size() == 0) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取订单sku
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, ordedrIdList));
|
|
|
+
|
|
|
+ List<DocumentByBomVo> result = orderSkuList.stream()
|
|
|
+ .map(item -> DocumentByBomVo.builder()
|
|
|
+ .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());
|
|
|
+
|
|
|
+ bomSpecService.attributeAssign(result, DocumentByBomVo::getBomSpecId, (item, bomSpec) -> {
|
|
|
+ item.setBomSpecCode(bomSpec.getCode());
|
|
|
+ item.setBomSpecName(bomSpec.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+ Collection<DocumentByBomVo> documentByBomVoCollection = result.stream()
|
|
|
+ .sorted(Comparator.comparing(DocumentByBomVo::getBomSpecCode))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ item -> item.getUnitPrice() + ":" + item.getBomSpecId(),
|
|
|
+ Function.identity(),
|
|
|
+ (v1, v2) -> {
|
|
|
+
|
|
|
+ return v1;
|
|
|
+ }
|
|
|
+ )).values();
|
|
|
+
|
|
|
+
|
|
|
+ result = new ArrayList<>(documentByBomVoCollection);
|
|
|
+
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
|
|
|
}
|