|
@@ -13,26 +13,26 @@ import com.ruoyi.common.core.domain.BasePo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.PageUtils;
|
|
|
import com.sd.business.entity.excel.enums.ExcelTypeEnum;
|
|
|
+import com.sd.business.entity.inventory.po.InventoryFinishedOrderDetail;
|
|
|
import com.sd.business.entity.order.po.OrderInfo;
|
|
|
import com.sd.business.entity.order.po.OrderSku;
|
|
|
+import com.sd.business.entity.order.po.OrderSkuProductionCost;
|
|
|
+import com.sd.business.entity.sku.bo.SkuSpecBo;
|
|
|
import com.sd.business.entity.sku.po.SkuSpec;
|
|
|
-import com.sd.business.entity.statement.dto.ExportDocumentDto;
|
|
|
-import com.sd.business.entity.statement.dto.GetDocumentDto;
|
|
|
-import com.sd.business.entity.statement.dto.SalesOutWarehouseDetailsDto;
|
|
|
-import com.sd.business.entity.statement.dto.StatementOfAccountMergePageDto;
|
|
|
+import com.sd.business.entity.statement.dto.*;
|
|
|
import com.sd.business.entity.statement.po.StatementOfAccount;
|
|
|
-import com.sd.business.entity.statement.vo.DocumentByBomVo;
|
|
|
-import com.sd.business.entity.statement.vo.DocumentByOrderVo;
|
|
|
-import com.sd.business.entity.statement.vo.DocumentBySkuVo;
|
|
|
-import com.sd.business.entity.statement.vo.StatementOfAccountMergePageVo;
|
|
|
+import com.sd.business.entity.statement.vo.*;
|
|
|
import com.sd.business.service.department.DepartmentService;
|
|
|
import com.sd.business.service.excel.ExcelGenerateLogService;
|
|
|
+import com.sd.business.service.inventory.InventoryFinishedOrderDetailService;
|
|
|
import com.sd.business.service.order.OrderService;
|
|
|
+import com.sd.business.service.order.OrderSkuProductionCostService;
|
|
|
import com.sd.business.service.order.OrderSkuService;
|
|
|
import com.sd.business.service.sku.SkuSpecService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountExportService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountMergeService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountService;
|
|
|
+import com.sd.business.strategy.impl.DefaultExportStrategy;
|
|
|
import com.sd.business.strategy.impl.DocumentByOrderExcelExportStrategy;
|
|
|
import com.sd.business.strategy.impl.SalesOutWarehouseDetailsExportStrategy;
|
|
|
import com.sd.framework.util.Assert;
|
|
@@ -40,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -76,6 +77,12 @@ public class StatementOfAccountMergeServiceImpl implements StatementOfAccountMer
|
|
|
@Autowired
|
|
|
private SkuSpecService skuSpecService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderSkuProductionCostService orderSkuProductionCostService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryFinishedOrderDetailService inventoryFinishedOrderDetailService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<StatementOfAccountMergePageVo> getPage(StatementOfAccountMergePageDto dto) {
|
|
|
|
|
@@ -316,6 +323,182 @@ public class StatementOfAccountMergeServiceImpl implements StatementOfAccountMer
|
|
|
DateUtil.formatDate(new Date()) + " 销售出货明细");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Page<DocumentByRevenueCostVo> salesRevenueCostPage(SalesRevenueCostSelectDto dto) {
|
|
|
+
|
|
|
+ List<StatementOfAccount> statementOfAccountList = null;
|
|
|
+ List<Long> statementOfAccountIdList = null;
|
|
|
+
|
|
|
+ if (!ObjectUtil.isAllEmpty(dto.getBeginTime(), dto.getEndTime())) {
|
|
|
+ statementOfAccountList = statementOfAccountService.list(q -> q
|
|
|
+ .ge(ObjectUtil.isNotNull(dto.getBeginTime()), BasePo::getCreateTime, dto.getBeginTime())
|
|
|
+ .le(ObjectUtil.isNotNull(dto.getEndTime()), BasePo::getCreateTime, dto.getEndTime()));
|
|
|
+
|
|
|
+ if (statementOfAccountList.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ statementOfAccountIdList = statementOfAccountList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<Long> orderIdList = null;
|
|
|
+ if (!StrUtil.isAllBlank(dto.getSkuSpecCode(), dto.getSkuSpecName())) {
|
|
|
+ List<SkuSpec> skuSpecList = skuSpecService.list(q -> q
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSkuSpecCode()), SkuSpec::getCode, dto.getSkuSpecCode())
|
|
|
+ .like(StrUtil.isNotBlank(dto.getSkuSpecName()), SkuSpec::getName, dto.getSkuSpecName()));
|
|
|
+
|
|
|
+ if (skuSpecList.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ List<Long> skuSpecIdList = skuSpecList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getSkuSpecId, skuSpecIdList));
|
|
|
+ if (orderSkuList.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ orderIdList = orderSkuList.stream().map(OrderSku::getOrderId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<OrderInfo> page = dto.getPage();
|
|
|
+
|
|
|
+
|
|
|
+ orderService.page(page, Wrappers.lambdaQuery(OrderInfo.class)
|
|
|
+ .in(ObjectUtil.isNotEmpty(orderIdList), BaseIdPo::getId, orderIdList)
|
|
|
+ .in(ObjectUtil.isNotEmpty(statementOfAccountIdList), OrderInfo::getStatementOfAccountId, statementOfAccountIdList)
|
|
|
+ .isNotNull(ObjectUtil.isEmpty(statementOfAccountIdList), OrderInfo::getStatementOfAccountId)
|
|
|
+ .eq(ObjectUtil.isNotNull(dto.getDepartmentId()), OrderInfo::getDepartmentId, dto.getDepartmentId())
|
|
|
+ .and(StrUtil.isNotBlank(dto.getCode()), q -> q
|
|
|
+ .like(OrderInfo::getCode, dto.getCode()).or().like(OrderInfo::getWlnCode, dto.getCode()))
|
|
|
+ .orderByDesc(OrderInfo::getStatementOfAccountId)
|
|
|
+ );
|
|
|
+
|
|
|
+ List<OrderInfo> records = page.getRecords();
|
|
|
+
|
|
|
+ if (records.isEmpty()) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+ Map<Long, OrderInfo> orderInfoMap = records.stream().collect(Collectors.toMap(BaseIdPo::getId, item -> item, (v1, v2) -> v2));
|
|
|
+ List<Long> orderIds = records.stream().map(BaseIdPo::getId).collect(Collectors.toList());
|
|
|
+ List<OrderSku> orderSkuList = orderSkuService.list(q -> q.in(OrderSku::getOrderId, orderIds));
|
|
|
+
|
|
|
+ List<Long> skuSpecIds = orderSkuList.stream().map(OrderSku::getSkuSpecId).collect(Collectors.toList());
|
|
|
+ Map<Long, SkuSpecBo> skuSpecBoMap = skuSpecService.getSkuSpecBoByIdList(skuSpecIds);
|
|
|
+
|
|
|
+ Map<Long, InventoryFinishedOrderDetail> inventoryMap = inventoryFinishedOrderDetailService.mapKEntity(
|
|
|
+ InventoryFinishedOrderDetail::getOrderSkuId,
|
|
|
+ q -> q.eq(InventoryFinishedOrderDetail::getOperationType, 2)
|
|
|
+ .in(InventoryFinishedOrderDetail::getOrderInfoId, orderIds)
|
|
|
+ .in(InventoryFinishedOrderDetail::getOrderSkuId, skuSpecIds));
|
|
|
+
|
|
|
+ Map<Long, OrderSkuProductionCost> productionCostMap = orderSkuProductionCostService.mapKEntity(OrderSkuProductionCost::getOrderSkuId,
|
|
|
+ q -> q.in(OrderSkuProductionCost::getOrderId, orderIds));
|
|
|
+ Integer[] serialNumber = {1};
|
|
|
+ List<DocumentByRevenueCostVo> documentByRevenueCostVos = orderSkuList.stream()
|
|
|
+ .map(item -> {
|
|
|
+ OrderInfo orderInfo = orderInfoMap.get(item.getOrderId());
|
|
|
+ SkuSpecBo skuSpecBo = skuSpecBoMap.get(item.getSkuSpecId());
|
|
|
+ InventoryFinishedOrderDetail inventoryDetail = inventoryMap.get(item.getSkuSpecId());
|
|
|
+
|
|
|
+ String length = skuSpecBo.getLength() == null ? "0" : skuSpecBo.getLength().stripTrailingZeros().toPlainString();
|
|
|
+ String width = skuSpecBo.getWidth() == null ? "0" : skuSpecBo.getWidth().stripTrailingZeros().toPlainString();
|
|
|
+ String height = skuSpecBo.getHeight() == null ? "0" : skuSpecBo.getHeight().stripTrailingZeros().toPlainString();
|
|
|
+
|
|
|
+ OrderSkuProductionCost productionCost = productionCostMap.get(item.getId());
|
|
|
+
|
|
|
+ return DocumentByRevenueCostVo.builder()
|
|
|
+ .orderId(item.getOrderId())
|
|
|
+ .departmentId(orderInfo.getDepartmentId())
|
|
|
+ .statementOfAccountId(orderInfo.getStatementOfAccountId())
|
|
|
+ .salesDate(orderInfo.getShippingTime())
|
|
|
+ .serialNumber(serialNumber[0]++)
|
|
|
+ .code(orderInfo.getCode())
|
|
|
+ .wlnCode(orderInfo.getWlnCode())
|
|
|
+ .outStorageCode(inventoryDetail == null ? "" : inventoryDetail.getCode())
|
|
|
+ .skuSpecCode(skuSpecBo.getSkuSpecCode())
|
|
|
+ .skuSpecName(skuSpecBo.getSkuSpecName())
|
|
|
+ .spec(length + " * " + width + " * " + height)
|
|
|
+ .classifyName(skuSpecBo.getSkuClassifyName())
|
|
|
+ .measuringUnit("pcs")
|
|
|
+ .quantity(item.getQuantity())
|
|
|
+ .salesUnitPrice(item.getUnitPrice()
|
|
|
+ .add(item.getCustomProcessingFee())
|
|
|
+ .add(item.getLssueFee())
|
|
|
+ .add(item.getDeliveryMaterialsFee())
|
|
|
+ .add(item.getPackingLabor())
|
|
|
+ .add(item.getPackagingMaterialCost())
|
|
|
+ .add(item.getManagementFee()))
|
|
|
+ .issuingAmount(item.getLssueFee().multiply(item.getQuantity()))
|
|
|
+ .otherAmount(item.getDeliveryMaterialsFee().multiply(item.getQuantity()))
|
|
|
+ .materialCost(productionCost.getMaterialCost())
|
|
|
+ .auxiliaryMaterialCost(productionCost.getAuxiliaryMaterialCost())
|
|
|
+ .productPackagingMaterialCost(productionCost.getProductPackagingMaterialCost())
|
|
|
+ .logisticsPackagingMaterialCost(productionCost.getLogisticsPackagingMaterialCost())
|
|
|
+ .costSubtotal(productionCost.getTotalAmount())
|
|
|
+ .build();
|
|
|
+ })
|
|
|
+ .peek(item -> item.setSalesAmount(item.getQuantity().multiply(item.getSalesUnitPrice())))
|
|
|
+ .peek(item -> {
|
|
|
+
|
|
|
+ item.setProductAmount(item.getSalesAmount()
|
|
|
+ .subtract(item.getIssuingAmount()).subtract(item.getOtherAmount()));
|
|
|
+
|
|
|
+ BigDecimal grossProfit = item.getSalesAmount().subtract(item.getCostSubtotal());
|
|
|
+
|
|
|
+ String grossProfitRate;
|
|
|
+ if (ObjectUtil.equals(item.getSalesAmount(), BigDecimal.ZERO)) {
|
|
|
+ grossProfitRate = "0%";
|
|
|
+ } else {
|
|
|
+ grossProfitRate = grossProfit
|
|
|
+ .divide(item.getSalesAmount(), 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal(100))
|
|
|
+ .stripTrailingZeros().toPlainString() + "%";
|
|
|
+ }
|
|
|
+ item.setGrossProfit(grossProfit);
|
|
|
+ item.setGrossProfitRate(grossProfitRate);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ departmentService.attributeAssign(documentByRevenueCostVos, DocumentByRevenueCostVo::getDepartmentId, (item, department) -> {
|
|
|
+ item.setCustomerName(department.getName().startsWith("胜德实业") ? "胜德实业" : department.getName());
|
|
|
+ item.setDepartmentName(department.getName());
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ if (statementOfAccountList == null) {
|
|
|
+ statementOfAccountList = statementOfAccountService.listByIds(
|
|
|
+ records.stream().map(OrderInfo::getStatementOfAccountId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ Map<Long, StatementOfAccount> map = statementOfAccountList.stream().collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
|
|
|
+
|
|
|
+ documentByRevenueCostVos.forEach(item -> {
|
|
|
+ Long statementOfAccountId = item.getStatementOfAccountId();
|
|
|
+ StatementOfAccount statementOfAccount = map.get(statementOfAccountId);
|
|
|
+ item.setSalesDate(statementOfAccount.getCreateTime());
|
|
|
+ });
|
|
|
+
|
|
|
+ Page<DocumentByRevenueCostVo> result = new Page<>();
|
|
|
+ result.setTotal(page.getTotal());
|
|
|
+ result.setRecords(documentByRevenueCostVos);
|
|
|
+ result.setPages(page.getPages());
|
|
|
+ result.setSize(page.getSize());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportSalesRevenueCostData(SalesRevenueCostSelectDto dto) {
|
|
|
+ dto.setPageNum(1);
|
|
|
+ dto.setPageSize(999999999);
|
|
|
+ Page<DocumentByRevenueCostVo> page = this.salesRevenueCostPage(dto);
|
|
|
+ List<DocumentByRevenueCostVo> list = page.getRecords();
|
|
|
+ DefaultExportStrategy<DocumentByRevenueCostVo> defaultExportStrategy = new DefaultExportStrategy<>(
|
|
|
+ () -> list, DocumentByRevenueCostVo.class, "销售收入成本数据");
|
|
|
+
|
|
|
+ excelGenerateLogService.generateExcel(ExcelTypeEnum.DOCUMENT_BY_SALES_REVENUE_COST, defaultExportStrategy,
|
|
|
+ DateUtil.formatDate(new Date()) + " 销售收入成本表");
|
|
|
+ }
|
|
|
+
|
|
|
private List<Long> getIdList(GetDocumentDto dto) {
|
|
|
|
|
|
String idGroupConcat = dto.getIdGroupConcat();
|