From 6d8e9ef3653639275d262a975ad477fa0bf5e366 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 30 三月 2026 10:51:53 +0800
Subject: [PATCH] fix: 加工编号缺失,发货修改为整个订单发货
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java | 1152 +++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 1,028 insertions(+), 124 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index b6c43ed..dd15ac8 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -4,30 +4,53 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+
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.ruoyi.account.service.AccountIncomeService;
import com.ruoyi.basic.mapper.CustomerMapper;
+import com.ruoyi.basic.mapper.ProductMapper;
+import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.basic.pojo.CustomerRegions;
+import com.ruoyi.basic.pojo.ProductModel;
+import com.ruoyi.basic.service.ICustomerRegionsService;
import com.ruoyi.common.enums.FileNameType;
+import com.ruoyi.common.enums.SaleEnum;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.EnumUtil;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.framework.security.LoginUser;
+import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.other.mapper.TempFileMapper;
import com.ruoyi.other.pojo.TempFile;
-import com.ruoyi.production.mapper.SalesLedgerSchedulingMapper;
-import com.ruoyi.production.pojo.SalesLedgerScheduling;
-import com.ruoyi.project.system.domain.SysDept;
+import com.ruoyi.production.mapper.*;
+import com.ruoyi.production.pojo.ProcessRoute;
+import com.ruoyi.production.pojo.ProcessRouteItem;
+import com.ruoyi.production.service.ProductionProductMainService;
+
+import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysDeptMapper;
-import com.ruoyi.sales.dto.MonthlyAmountDto;
-import com.ruoyi.sales.dto.SalesLedgerDto;
+import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.purchase.dto.SimpleReturnOrderGroupDto;
+import com.ruoyi.purchase.mapper.PurchaseReturnOrderProductsMapper;
+import com.ruoyi.quality.mapper.QualityInspectMapper;
+import com.ruoyi.sales.dto.*;
import com.ruoyi.sales.mapper.*;
import com.ruoyi.sales.pojo.*;
+import com.ruoyi.sales.service.ISalesLedgerProcessRouteService;
+import com.ruoyi.sales.service.ISalesLedgerProductProcessBindService;
+import com.ruoyi.sales.service.ISalesLedgerProductProcessService;
import com.ruoyi.sales.service.ISalesLedgerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
+import org.jetbrains.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -35,10 +58,13 @@
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Field;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -62,38 +88,101 @@
@RequiredArgsConstructor
@Slf4j
public class SalesLedgerServiceImpl extends ServiceImpl<SalesLedgerMapper, SalesLedger> implements ISalesLedgerService {
-
- private final SalesLedgerMapper salesLedgerMapper;
-
- private final CustomerMapper customerMapper;
-
- private final SalesLedgerProductMapper salesLedgerProductMapper;
-
- private final CommonFileMapper commonFileMapper;
-
- private final TempFileMapper tempFileMapper;
-
- private final ReceiptPaymentMapper receiptPaymentMapper;
-
- private final InvoiceLedgerMapper invoiceLedgerMapper;
-
- private final SalesLedgerSchedulingMapper salesLedgerSchedulingMapper;
-
- @Autowired
- private SysDeptMapper sysDeptMapper;
-
- @Value("${file.upload-dir}")
- private String uploadDir;
-
private static final String LOCK_PREFIX = "contract_no_lock:";
private static final long LOCK_WAIT_TIMEOUT = 10; // 閿佺瓑寰呰秴鏃舵椂闂达紙绉掞級
private static final long LOCK_EXPIRE_TIME = 30; // 閿佽嚜鍔ㄨ繃鏈熸椂闂达紙绉掞級
-
+ private final AccountIncomeService accountIncomeService;
+ private final SalesLedgerMapper salesLedgerMapper;
+ private final CustomerMapper customerMapper;
+ private final SalesLedgerProductMapper salesLedgerProductMapper;
+ private final SalesLedgerProductServiceImpl salesLedgerProductServiceImpl;
+ private final CommonFileMapper commonFileMapper;
+ private final TempFileMapper tempFileMapper;
+ private final ReceiptPaymentMapper receiptPaymentMapper;
+ private final ShippingInfoServiceImpl shippingInfoServiceImpl;
+ private final CommonFileServiceImpl commonFileService;
+ private final ShippingInfoMapper shippingInfoMapper;
+ private final InvoiceLedgerMapper invoiceLedgerMapper;
+ private final SalesLedgerSchedulingMapper salesLedgerSchedulingMapper;
+ private final SalesLedgerWorkMapper salesLedgerWorkMapper;
+ private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
+ private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+ private final InvoiceRegistrationMapper invoiceRegistrationMapper;
+ private final ProductOrderMapper productOrderMapper;
+ private final ProcessRouteMapper processRouteMapper;
+ private final ProductProcessRouteMapper productProcessRouteMapper;
+ private final ProcessRouteItemMapper processRouteItemMapper;
+ private final ProductProcessRouteItemMapper productProcessRouteItemMapper;
+ private final ProductWorkOrderMapper productWorkOrderMapper;
+ private final ProductionProductMainMapper productionProductMainMapper;
+ private final ProductionProductOutputMapper productionProductOutputMapper;
+ private final ProductionProductInputMapper productionProductInputMapper;
+ private final QualityInspectMapper qualityInspectMapper;
private final RedisTemplate<String, String> redisTemplate;
+
+ private final ISalesLedgerProductProcessService salesLedgerProductProcessService;
+
+ private final ISalesLedgerProductProcessBindService salesLedgerProductProcessBindService;
+
+ private final ISalesLedgerProcessRouteService salesLedgerProcessRouteService;
+
+ @Autowired
+ private SysDeptMapper sysDeptMapper;
+ @Value("${file.upload-dir}")
+ private String uploadDir;
+ @Autowired
+ private ProductModelMapper productModelMapper;
+
+ @Autowired
+ private ProductMapper productMapper;
+ @Autowired
+ private ProductStructureMapper productStructureMapper;
+ @Autowired
+ private ProductionProductMainService productionProductMainService;
+ @Autowired
+ private PurchaseReturnOrderProductsMapper purchaseReturnOrderProductsMapper;
+ ;
+ @Autowired
+ private SysUserMapper sysUserMapper;
+
+ private final ICustomerRegionsService customerRegionsService;
@Override
public List<SalesLedger> selectSalesLedgerList(SalesLedgerDto salesLedgerDto) {
return salesLedgerMapper.selectSalesLedgerList(salesLedgerDto);
+ }
+
+ public List<SalesLedgerProduct> getSalesLedgerProductListByRelateId(Long relateId, SaleEnum type) {
+ LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
+ productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, relateId);
+ productWrapper.eq(SalesLedgerProduct::getType, type.getCode());
+ return salesLedgerProductMapper.selectList(productWrapper);
+ }
+
+ @Override
+ public List<SalesLedgerProduct> getSalesLedgerProductListByIds(@Nullable List<Long> relateIds, SaleEnum type) {
+ if (CollectionUtils.isEmpty(relateIds)) {
+ return Collections.emptyList();
+ }
+ LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
+ productWrapper.in(SalesLedgerProduct::getId, relateIds);
+ productWrapper.eq(SalesLedgerProduct::getType, type.getCode());
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(productWrapper);
+ if (type.equals(SaleEnum.PURCHASE)) {
+ // 鏌ヨ閫�璐т俊鎭�
+ List<Long> productIds = salesLedgerProducts.stream().map(SalesLedgerProduct::getId).collect(Collectors.toList());
+ List<SimpleReturnOrderGroupDto> groupListByProductIds = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(productIds)) {
+ groupListByProductIds = purchaseReturnOrderProductsMapper.getReturnOrderGroupListByProductIds(productIds);
+ }
+ Map<Long, BigDecimal> returnOrderGroupDtoMap = groupListByProductIds.stream().collect(Collectors.toMap(SimpleReturnOrderGroupDto::getSalesLedgerProductId, SimpleReturnOrderGroupDto::getSumReturnQuantity));
+ salesLedgerProducts.forEach(item -> {
+ BigDecimal returnQuality = returnOrderGroupDtoMap.getOrDefault(item.getId(), BigDecimal.ZERO);
+ item.setReturnQuality(returnQuality);
+ item.setAvailableQuality(item.getQuantity().subtract(returnQuality));
+ });
+ }
+ return salesLedgerProducts;
}
@Override
@@ -109,6 +198,20 @@
productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId());
productWrapper.eq(SalesLedgerProduct::getType, 1);
List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper);
+ Map<Long, ProductModel> productModelMap = Collections.emptyMap();
+ if (CollectionUtils.isNotEmpty(products)) {
+ List<Long> productModelIds = products.stream()
+ .map(SalesLedgerProduct::getProductModelId)
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(productModelIds)) {
+ List<ProductModel> productModels = productModelMapper.selectBatchIds(productModelIds);
+ if (CollectionUtils.isNotEmpty(productModels)) {
+ productModelMap = productModels.stream().collect(Collectors.toMap(ProductModel::getId, Function.identity()));
+ }
+ }
+ }
for (SalesLedgerProduct product : products) {
product.setOriginalNoInvoiceNum(product.getNoInvoiceNum());
// 鎻愪緵涓存椂鏈紑绁ㄦ暟锛屾湭寮�绁ㄩ噾棰濅緵鍓嶆璁$畻
@@ -116,11 +219,51 @@
product.setTempNoInvoiceNum(product.getNoInvoiceNum());
product.setRegister(SecurityUtils.getLoginUser().getUser().getNickName());
product.setRegisterDate(LocalDateTime.now());
+ // 鍙戣揣淇℃伅
+ ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
+ .eq(ShippingInfo::getSalesLedgerProductId, product.getId())
+ .orderByDesc(ShippingInfo::getCreateTime)
+ .last("limit 1"));
+ if (shippingInfo != null) {
+ product.setShippingStatus(shippingInfo.getStatus());
+ }
+ // 鍔犲伐鏄庣粏锛屽厛鏌ind琛ㄨ幏鍙栬浜у搧鍏宠仈鐨勫伐搴忓強鏁伴噺
+ List<SalesLedgerProductProcessBind> bindList = salesLedgerProductProcessBindService.list(
+ new LambdaQueryWrapper<SalesLedgerProductProcessBind>()
+ .eq(SalesLedgerProductProcessBind::getSalesLedgerProductId, product.getId()));
+ if (!bindList.isEmpty()) {
+ List<Integer> processIds = bindList.stream()
+ .map(SalesLedgerProductProcessBind::getSalesLedgerProductProcessId)
+ .collect(Collectors.toList());
+ Map<Integer, Integer> processQuantityMap = bindList.stream()
+ .collect(Collectors.toMap(
+ SalesLedgerProductProcessBind::getSalesLedgerProductProcessId,
+ SalesLedgerProductProcessBind::getQuantity,
+ (a, b) -> a));
+ List<SalesLedgerProductProcess> processList = salesLedgerProductProcessService.listByIds(processIds);
+ processList.forEach(p -> p.setQuantity(processQuantityMap.get(p.getId())));
+ product.setSalesProductProcessList(processList);
+ }
+ ProductModel productModel = productModelMap.get(product.getProductModelId());
+ if (productModel != null) {
+ product.setThickness(productModel.getThickness());
+ }
+ if (product.getWidth() != null && product.getHeight() != null) {
+ BigDecimal pieceArea = product.getWidth().multiply(product.getHeight()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP);
+ if (product.getActualPieceArea() == null) {
+ product.setActualPieceArea(pieceArea);
+ }
+ BigDecimal quantity = product.getQuantity() == null ? BigDecimal.ZERO : product.getQuantity();
+ if (product.getActualTotalArea() == null) {
+ product.setActualTotalArea(pieceArea.multiply(quantity).setScale(2, RoundingMode.HALF_UP));
+ }
+ }
}
// 3.鏌ヨ涓婁紶鏂囦欢
LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
- salesLedgerFileWrapper.eq(CommonFile::getCommonId, salesLedger.getId());
+ salesLedgerFileWrapper.eq(CommonFile::getCommonId, salesLedger.getId())
+ .eq(CommonFile::getType, FileNameType.SALE.getValue());
List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
// 4. 杞崲 DTO
@@ -204,53 +347,53 @@
}
@Override
- public List<MonthlyAmountDto> getAmountHalfYear() {
+ public List<MonthlyAmountDto> getAmountHalfYear(Integer type) {
+
LocalDate now = LocalDate.now();
- YearMonth currentMonth = YearMonth.from(now);
+ List<MonthlyAmountDto> result = new ArrayList<>();
- List<MonthlyAmountDto> monthlyAmounts = new ArrayList<>();
+ for (int i = 5; i >= 0; i--) {
+ YearMonth yearMonth = YearMonth.from(now.minusMonths(i));
+ LocalDateTime startTime = yearMonth.atDay(1).atStartOfDay();
+ LocalDateTime endTime = yearMonth.atEndOfMonth().atTime(23, 59, 59);
- for (int i = 0; i < 6; i++) {
- YearMonth targetMonth = currentMonth.minusMonths(i);
- LocalDate firstDayOfMonth = targetMonth.atDay(1);
- LocalDate firstDayOfNextMonth = targetMonth.plusMonths(1).atDay(1);
+ // 鍥炴閲戦
+ LambdaQueryWrapper<ReceiptPayment> receiptPaymentQuery = new LambdaQueryWrapper<>();
+ receiptPaymentQuery
+ .ge(ReceiptPayment::getCreateTime, startTime)
+ .le(ReceiptPayment::getCreateTime, endTime);
- LocalDateTime startOfMonth = firstDayOfMonth.atStartOfDay();
- LocalDateTime startOfNextMonth = firstDayOfNextMonth.atStartOfDay();
+ List<ReceiptPayment> receiptPayments =
+ receiptPaymentMapper.selectList(receiptPaymentQuery);
- LambdaQueryWrapper<ReceiptPayment> receiptPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();
- receiptPaymentLambdaQueryWrapper.ge(ReceiptPayment::getCreateTime, startOfMonth)
- .lt(ReceiptPayment::getCreateTime, startOfNextMonth);
-
- LambdaQueryWrapper<InvoiceLedger> invoiceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
- invoiceLedgerLambdaQueryWrapper.ge(InvoiceLedger::getCreateTime, startOfMonth)
- .lt(InvoiceLedger::getCreateTime, startOfNextMonth);
-
- // 鑾峰彇鍥炴閲戦
- List<ReceiptPayment> receiptPaymentList = receiptPaymentMapper.selectList(receiptPaymentLambdaQueryWrapper);
- //寮�绁ㄩ噾棰�
- List<InvoiceLedger> invoiceLedgerList = invoiceLedgerMapper.selectList(invoiceLedgerLambdaQueryWrapper);
-
- // 浣跨敤 Stream 姹傚拰
- BigDecimal invoiceAmount = invoiceLedgerList.stream()
- .map(InvoiceLedger::getInvoiceTotal)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
-
- BigDecimal receiptAmount = receiptPaymentList.stream()
+ BigDecimal receiptAmount = receiptPayments.stream()
.map(ReceiptPayment::getReceiptPaymentAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- MonthlyAmountDto monthlyAmount = new MonthlyAmountDto();
- monthlyAmount.setMonth(targetMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")));
- monthlyAmount.setInvoiceAmount(invoiceAmount);
- monthlyAmount.setReceiptAmount(receiptAmount);
+ // 寮�绁ㄩ噾棰�
+ LambdaQueryWrapper<InvoiceLedger> invoiceLedgerQuery = new LambdaQueryWrapper<>();
+ invoiceLedgerQuery
+ .ge(InvoiceLedger::getCreateTime, startTime)
+ .le(InvoiceLedger::getCreateTime, endTime);
- monthlyAmounts.add(monthlyAmount);
+ List<InvoiceLedger> invoiceLedgers =
+ invoiceLedgerMapper.selectList(invoiceLedgerQuery);
+
+ BigDecimal invoiceAmount = invoiceLedgers.stream()
+ .map(InvoiceLedger::getInvoiceTotal)
+ .filter(Objects::nonNull)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ MonthlyAmountDto dto = new MonthlyAmountDto();
+ dto.setMonth(yearMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")));
+ dto.setReceiptAmount(receiptAmount);
+ dto.setInvoiceAmount(invoiceAmount);
+
+ result.add(dto);
}
- Collections.reverse(monthlyAmounts);
- return monthlyAmounts;
+
+ return result;
}
@Override
@@ -258,34 +401,221 @@
return salesLedgerMapper.selectSalesLedgerListPage(page, salesLedgerDto);
}
- // 鍐呴儴绫荤敤浜庡瓨鍌ㄨ仛鍚堢粨鏋�
- private static class GroupedCustomer {
- private final Long customerId;
- private final String customerName;
- private BigDecimal totalAmount = BigDecimal.ZERO;
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public AjaxResult importData(MultipartFile file) {
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ try {
+ InputStream inputStream = file.getInputStream();
+ ExcelUtil<SalesLedgerImportDto> salesLedgerImportDtoExcelUtil = new ExcelUtil<>(SalesLedgerImportDto.class);
+ Map<String, List<SalesLedgerImportDto>> stringListMap = salesLedgerImportDtoExcelUtil.importExcelMultiSheet(Arrays.asList("閿�鍞彴璐︽暟鎹�", "閿�鍞骇鍝佹暟鎹�"), inputStream, 0);
+ if (CollectionUtils.isEmpty(stringListMap)) return AjaxResult.error("閿�鍞〃鏍间负绌猴紒");
+ // 涓氬姟灞傚悎骞�
+ List<SalesLedgerImportDto> salesLedgerImportDtoList = stringListMap.get("閿�鍞彴璐︽暟鎹�");
+ if (CollectionUtils.isEmpty(salesLedgerImportDtoList)) return AjaxResult.error("閿�鍞彴璐︽暟鎹负绌猴紒");
+ List<SalesLedgerImportDto> salesLedgerProductImportDtoList = stringListMap.get("閿�鍞骇鍝佹暟鎹�");
+ if (CollectionUtils.isEmpty(salesLedgerProductImportDtoList)) return AjaxResult.error("閿�鍞骇鍝佹暟鎹负绌猴紒");
+ // 瀹㈡埛鏁版嵁
+ List<Customer> customers = customerMapper.selectList(new LambdaQueryWrapper<Customer>().in(Customer::getCustomerName,
+ salesLedgerImportDtoList.stream().map(SalesLedgerImportDto::getCustomerName).collect(Collectors.toList())));
+ List<Map<String, Object>> list = productModelMapper.getProductAndModelList();
+ // 褰曞叆浜烘暟鎹�
+ List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>().in(SysUser::getNickName,
+ salesLedgerImportDtoList.stream().map(SalesLedgerImportDto::getEntryPerson).collect(Collectors.toList())));
+ for (SalesLedgerImportDto salesLedgerImportDto : salesLedgerImportDtoList) {
+ SalesLedger salesLedger1 = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>()
+ .eq(SalesLedger::getSalesContractNo, salesLedgerImportDto.getSalesContractNo())
+ .last("LIMIT 1"));
+ if (salesLedger1 != null) {
+ throw new ServiceException("瀵煎叆澶辫触锛氬悎鍚屽彿 [" + salesLedgerImportDto.getSalesContractNo() + "] 宸插瓨鍦紝璇锋鏌ュ悗閲嶆柊瀵煎叆");
+ }
+ SalesLedger salesLedger = new SalesLedger();
+ BeanUtils.copyProperties(salesLedgerImportDto, salesLedger);
+ salesLedger.setExecutionDate(DateUtils.toLocalDate(salesLedgerImportDto.getExecutionDate()));
+ // 閫氳繃瀹㈡埛鍚嶇О鏌ヨ瀹㈡埛ID锛屽鎴峰悎鍚屽彿
+ salesLedger.setCustomerId(customers.stream()
+ .filter(customer -> customer.getCustomerName().equals(salesLedger.getCustomerName()))
+ .findFirst()
+ .map(Customer::getId)
+ .orElse(null));
+ salesLedger.setCustomerContractNo(customers.stream()
+ .filter(customer -> customer.getCustomerName().equals(salesLedger.getCustomerName()))
+ .findFirst()
+ .map(Customer::getTaxpayerIdentificationNumber)
+ .orElse(null));
+ Long aLong = sysUsers.stream()
+ .filter(sysUser -> sysUser.getNickName().equals(salesLedger.getEntryPerson()))
+ .findFirst()
+ .map(SysUser::getUserId)
+ .orElse(null);
+ if (aLong == null)
+ throw new ServiceException("褰曞叆浜�:" + salesLedger.getEntryPerson() + ",鏃犲搴旂敤鎴凤紒");
+ salesLedger.setEntryPerson(aLong.toString());
+ // 閿�鍞骇鍝佹暟鎹粦瀹氾紝閫氳繃閿�鍞崟鍙疯幏鍙栧搴旈攢鍞骇鍝佹暟鎹�
+ List<SalesLedgerProductImportDto> salesLedgerProductImportDtos = salesLedgerProductImportDtoList.stream()
+ .filter(salesLedgerProductImportDto -> salesLedgerProductImportDto.getSalesContractNo().equals(salesLedger.getSalesContractNo()))
+ .collect(Collectors.toList());
+ if (CollectionUtils.isEmpty(salesLedgerProductImportDtos))
+ throw new RuntimeException("閿�鍞崟鍙�:" + salesLedgerImportDto.getSalesContractNo() + ",鏃犲搴斾骇鍝佹暟鎹紒");
+ salesLedger.setContractAmount(salesLedgerProductImportDtos.stream()
+ .map(SalesLedgerProductImportDto::getTaxInclusiveTotalPrice)
+ .reduce(BigDecimal.ZERO, BigDecimal::add));
+ // 鍙戣揣鐘舵��
+ salesLedger.setDeliveryStatus(0);
+ salesLedgerMapper.insert(salesLedger);
- public GroupedCustomer(Long customerId, String customerName) {
- this.customerId = customerId;
- this.customerName = customerName;
+ for (SalesLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) {
+ SalesLedgerProduct salesLedgerProduct = new SalesLedgerProduct();
+ BeanUtils.copyProperties(salesLedgerProductImportDto, salesLedgerProduct);
+ salesLedgerProduct.setFloorCode(salesLedgerProductImportDto.getFloorNo());
+ salesLedgerProduct.setProcessRequirement(salesLedgerProductImportDto.getProcessingRequirements());
+ salesLedgerProduct.setRemark(salesLedgerProductImportDto.getRemarks());
+ salesLedgerProduct.setSalesLedgerId(salesLedger.getId());
+ salesLedgerProduct.setType(1);
+ // 璁$畻涓嶅惈绋庢�讳环
+ salesLedgerProduct.setTaxExclusiveTotalPrice(salesLedgerProduct.getTaxInclusiveTotalPrice().divide(new BigDecimal(1).add(salesLedgerProduct.getTaxRate().divide(new BigDecimal(100))), 2, RoundingMode.HALF_UP));
+ salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
+ salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxExclusiveTotalPrice());
+ list.stream()
+ .filter(map -> map.get("productName").equals(salesLedgerProduct.getProductCategory()) && map.get("model").equals(salesLedgerProduct.getSpecificationModel()))
+ .findFirst()
+ .ifPresent(map -> {
+ salesLedgerProduct.setProductModelId(Long.parseLong(map.get("modelId").toString()));
+ salesLedgerProduct.setProductId(Long.parseLong(map.get("id").toString()));
+ });
+ salesLedgerProduct.setRegister(loginUser.getNickName());
+ salesLedgerProduct.setRegisterDate(LocalDateTime.now());
+ salesLedgerProduct.setApproveStatus(0);
+ salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProductImportDto.getTaxInclusiveTotalPrice());
+ salesLedgerProductMapper.insert(salesLedgerProduct);
+
+ // 澶勭悊棰濆鍔犲伐淇℃伅
+ String extraProcessing = salesLedgerProductImportDto.getExtraProcessing();
+ if (StringUtils.hasText(extraProcessing)) {
+ List<SalesLedgerProductProcess> processList = new ArrayList<>();
+ // 涓嫳鏂囧垎鍙�
+ String[] items = extraProcessing.split("[;锛沒");
+ for (String item : items) {
+ if (StringUtils.hasText(item)) {
+ String[] parts = item.split("[-鈥攡锝瀅");
+ if (parts.length >= 2) {
+ String processName = parts[0].trim();
+ String qtyStr = parts[1].trim();
+ try {
+ BigDecimal quantity = new BigDecimal(qtyStr);
+ SalesLedgerProductProcess process = salesLedgerProductProcessService.getOne(
+ new LambdaQueryWrapper<SalesLedgerProductProcess>()
+ .eq(SalesLedgerProductProcess::getProcessName, processName)
+ .last("LIMIT 1")
+ );
+ if (process != null) {
+ SalesLedgerProductProcess p = new SalesLedgerProductProcess();
+ p.setId(process.getId());
+ p.setQuantity(quantity.intValue());
+ processList.add(p);
+ }
+ } catch (Exception e) {
+ log.error("瑙f瀽棰濆鍔犲伐鏁伴噺澶辫触: {}", qtyStr);
+ }
+ }
+ }
+ }
+ if (!processList.isEmpty()) {
+ salesLedgerProductProcessBindService.updateProductProcessBind(processList, salesLedgerProduct.getId());
+ }
+ }
+
+ // 娣诲姞鐢熶骇鏁版嵁
+ salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
+ }
+ }
+
+ return AjaxResult.success("瀵煎叆鎴愬姛");
+ } catch (Exception e) {
+ e.printStackTrace();
}
+ return AjaxResult.success("瀵煎叆澶辫触");
+ }
- public void addAmount(BigDecimal amount) {
- if (amount != null) {
- this.totalAmount = this.totalAmount.add(amount);
+ @Override
+ public List<LossProductModelDto> getSalesLedgerWithProductsLoss(Long salesLedgerId) {
+
+
+ List<LossProductModelDto> lossProductModelDtos = salesLedgerProductMapper.selectProductBomStructure(salesLedgerId);
+
+
+ return lossProductModelDtos;
+ }
+
+ @Override
+ public IPage<SalesLedgerDto> listSalesLedger(SalesLedgerDto salesLedgerDto, Page page) {
+ IPage<SalesLedgerDto> salesLedgerDtoIPage = salesLedgerMapper.listSalesLedgerAndShipped(page, salesLedgerDto);
+ for (SalesLedgerDto salesLedger : salesLedgerDtoIPage.getRecords()) {
+ LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
+ productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId());
+ productWrapper.eq(SalesLedgerProduct::getType, 1);
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper);
+ for (SalesLedgerProduct product : products) {
+ product.setOriginalNoInvoiceNum(product.getNoInvoiceNum());
+ // 鎻愪緵涓存椂鏈紑绁ㄦ暟锛屾湭寮�绁ㄩ噾棰濅緵鍓嶆璁$畻
+ product.setTempnoInvoiceAmount(product.getNoInvoiceAmount());
+ product.setTempNoInvoiceNum(product.getNoInvoiceNum());
+ product.setRegister(SecurityUtils.getLoginUser().getUser().getNickName());
+ product.setRegisterDate(LocalDateTime.now());
+ // 鍙戣揣淇℃伅
+ ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
+ .eq(ShippingInfo::getSalesLedgerProductId, product.getId())
+ .orderByDesc(ShippingInfo::getCreateTime)
+ .last("limit 1"));
+ product.setShippingCarNumber(shippingInfo.getShippingCarNumber());
+ product.setShippingDate(shippingInfo.getShippingDate());
+ if (shippingInfo != null) {
+ product.setShippingStatus(shippingInfo.getStatus());
+ }
+ }
+ // 杩囨护鍙繚鐣欏彂璐ц褰�
+ products = products.stream().filter(product -> "宸插彂璐�".equals(product.getShippingStatus())).collect(Collectors.toList());
+ if (!products.isEmpty()) {
+ salesLedger.setHasChildren(true);
+ salesLedger.setProductData(products);
}
}
- public Long getCustomerId() {
- return customerId;
+
+ return salesLedgerDtoIPage;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void saleProcessBind(SalesLedgerProcessRoute salesLedgerProcessRoute) {
+ if (salesLedgerProcessRoute == null) {
+ throw new ServiceException("缁戝畾澶辫触,鏁版嵁涓嶈兘涓虹┖");
}
- public String getCustomerName() {
- return customerName;
+ SalesLedger salesLedger = baseMapper.selectById(salesLedgerProcessRoute.getSalesLedgerId());
+ if (salesLedger == null) {
+ throw new ServiceException("缁戝畾澶辫触,閿�鍞鍗曚笉瀛樺湪");
}
+ ProcessRoute processRoute = processRouteMapper.selectById(salesLedgerProcessRoute.getProcessRouteId());
+ if (processRoute == null) {
+ throw new ServiceException("缁戝畾澶辫触,宸ヨ壓璺嚎涓嶅瓨鍦�");
+ }
+ // 娓呴櫎宸茬粦瀹氱殑鏁版嵁
+ salesLedgerProcessRouteService.remove(new LambdaQueryWrapper<SalesLedgerProcessRoute>().eq(SalesLedgerProcessRoute::getSalesLedgerId, salesLedger.getId()));
- public BigDecimal getTotalAmount() {
- return totalAmount;
+ // 灏嗘暟鎹縼绉诲埌sales_ledger_process_route
+ List<ProcessRouteItem> routeItems = processRouteItemMapper.selectList(new LambdaQueryWrapper<ProcessRouteItem>().eq(ProcessRouteItem::getRouteId, processRoute.getId()));
+ SalesLedgerProcessRoute ledgerProcessRoute;
+ List<SalesLedgerProcessRoute> salesLedgerProcessRouteList = new ArrayList<>();
+ for (ProcessRouteItem routeItem : routeItems) {
+ ledgerProcessRoute = new SalesLedgerProcessRoute();
+ ledgerProcessRoute.setProcessRouteId(processRoute.getId());
+ ledgerProcessRoute.setSalesLedgerId(salesLedger.getId());
+ ledgerProcessRoute.setProcessRouteItemId(routeItem.getId());
+ ledgerProcessRoute.setDragSort(routeItem.getDragSort());
+ salesLedgerProcessRouteList.add(ledgerProcessRoute);
}
+ salesLedgerProcessRouteService.saveBatch(salesLedgerProcessRouteList);
}
/**
@@ -319,20 +649,66 @@
if (CollectionUtils.isEmpty(idList)) {
return 0;
}
- // 鐢熶骇璁㈠崟鏈夊緟鎺掍骇鏁版嵁锛屽彴璐︿笉鍙垹闄�
- LambdaQueryWrapper<SalesLedgerScheduling> salesLedgerSchedulingLambdaQueryWrapper = new LambdaQueryWrapper<SalesLedgerScheduling>()
- .in(SalesLedgerScheduling::getSalesLedgerId, idList);
- if (salesLedgerSchedulingMapper.selectCount(salesLedgerSchedulingLambdaQueryWrapper) > 0) {
- throw new BaseException("鏈夋帓浜ф暟鎹紝涓嶅彲鍒犻櫎");
+ // 鍒犻櫎閿�鍞鐞嗘暟鎹�
+ LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList)
+ .select(SalesLedgerProduct::getId);
+
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(queryWrapper);
+ List<Long> productIds = products.stream()
+ .map(SalesLedgerProduct::getId)
+ .collect(Collectors.toList());
+ //鍒犻櫎鐢熶骇鏁版嵁
+ salesLedgerProductServiceImpl.deleteProductionData(productIds);
+
+ // 鎵归噺鍒犻櫎浜у搧瀛愯〃
+ if (!productIds.isEmpty()) {
+ salesLedgerProductMapper.deleteBatchIds(productIds);
}
- // 1. 鍏堝垹闄ゅ瓙琛ㄦ暟鎹�
- LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
- productWrapper.in(SalesLedgerProduct::getSalesLedgerId, idList);
- salesLedgerProductMapper.delete(productWrapper);
- // 鍒犻櫎鐢熶骇璁㈠崟鏁版嵁
- LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>()
- .in(SalesLedgerScheduling::getSalesLedgerId, idList);
- salesLedgerSchedulingMapper.delete(in);
+
+ // 娓呴櫎浜у搧鐨勫姞宸�
+ salesLedgerProductProcessBindService.remove(new LambdaQueryWrapper<SalesLedgerProductProcessBind>().in(SalesLedgerProductProcessBind::getSalesLedgerProductId, productIds));
+
+ LambdaQueryWrapper<InvoiceRegistrationProduct> wrapper = new LambdaQueryWrapper<>();
+ wrapper.in(InvoiceRegistrationProduct::getSalesLedgerId, idList);
+ List<InvoiceRegistrationProduct> invoiceRegistrationProducts = invoiceRegistrationProductMapper.selectList(wrapper);
+ List<Integer> invoiceLedgerIds = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(invoiceRegistrationProducts)) {
+ LambdaQueryWrapper<InvoiceLedger> wrapperOne = new LambdaQueryWrapper<>();
+ wrapperOne.in(InvoiceLedger::getInvoiceRegistrationProductId, invoiceRegistrationProducts.stream().map(InvoiceRegistrationProduct::getId).collect(Collectors.toList()));
+ List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(wrapperOne);
+ if (CollectionUtils.isNotEmpty(invoiceLedgers)) {
+ invoiceLedgerIds = invoiceLedgers.stream().map(InvoiceLedger::getId).collect(Collectors.toList());
+ }
+ invoiceLedgerMapper.delete(wrapperOne);
+ }
+ invoiceRegistrationProductMapper.delete(wrapper);
+ LambdaQueryWrapper<InvoiceRegistration> wrapperTwo = new LambdaQueryWrapper<>();
+ wrapperTwo.in(InvoiceRegistration::getSalesLedgerId, idList);
+ invoiceRegistrationMapper.delete(wrapperTwo);
+
+ if (CollectionUtils.isNotEmpty(invoiceLedgerIds)) {
+ LambdaQueryWrapper<ReceiptPayment> wrapperTree = new LambdaQueryWrapper<>();
+ wrapperTree.in(ReceiptPayment::getInvoiceLedgerId, invoiceLedgerIds);
+ receiptPaymentMapper.delete(wrapperTree);
+ }
+ // 鍒犻櫎鍙戣揣鍙拌处璁板綍
+ List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
+ .in(ShippingInfo::getSalesLedgerId, idList));
+ if (CollectionUtils.isNotEmpty(shippingInfos)) {
+ shippingInfoServiceImpl.delete(shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList()));
+ }
+ // 鍒犻櫎闄勪欢琛�
+ commonFileService.deleteByBusinessIds(idList, FileNameType.SALE.getValue());
+
+ // 鍒犻櫎鐢熶骇绠℃帶鏁版嵁
+ //鏌ヨ鐢熶骇鎶ュ伐id
+ ArrayList<Long> mainIdList = productionProductMainService.listMain(idList);
+ if (CollectionUtils.isNotEmpty(mainIdList)) {
+ mainIdList.stream().forEach(mainId -> {
+ productionProductMainService.removeProductMain(mainId);
+ });
+ }
// 2. 鍐嶅垹闄や富琛ㄦ暟鎹�
return salesLedgerMapper.deleteBatchIds(idList);
}
@@ -351,20 +727,23 @@
SalesLedger salesLedger = convertToEntity(salesLedgerDto);
salesLedger.setCustomerName(customer.getCustomerName());
salesLedger.setTenantId(customer.getTenantId());
-
// 3. 鏂板鎴栨洿鏂颁富琛�
if (salesLedger.getId() == null) {
String contractNo = generateSalesContractNo();
salesLedger.setSalesContractNo(contractNo);
+ salesLedger.setDeliveryStatus(0);
salesLedgerMapper.insert(salesLedger);
} else {
+ if (salesLedger.getDeliveryStatus() == 1) {
+ throw new ServiceException("璁㈠崟宸插彂璐�,绂佹缂栬緫");
+ }
salesLedgerMapper.updateById(salesLedger);
}
// 4. 澶勭悊瀛愯〃鏁版嵁
List<SalesLedgerProduct> productList = salesLedgerDto.getProductData();
if (productList != null && !productList.isEmpty()) {
- handleSalesLedgerProducts(salesLedger.getId(), productList, salesLedgerDto.getType());
+ handleSalesLedgerProducts(salesLedger.getId(), productList, EnumUtil.fromCode(SaleEnum.class, salesLedgerDto.getType()));
updateMainContractAmount(
salesLedger.getId(),
productList,
@@ -383,8 +762,6 @@
throw new BaseException("鏂囦欢杩佺Щ澶辫触: " + e.getMessage());
}
}
-
- // 鏂囦欢杩佺Щ鏂规硶
/**
* 灏嗕复鏃舵枃浠惰縼绉诲埌姝e紡鐩綍
@@ -428,12 +805,15 @@
try {
// 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
- Files.move(
- Paths.get(tempFile.getTempPath()),
- formalFilePath,
- StandardCopyOption.REPLACE_EXISTING,
- StandardCopyOption.ATOMIC_MOVE
- );
+// Files.move(
+// Paths.get(tempFile.getTempPath()),
+// formalFilePath,
+// StandardCopyOption.REPLACE_EXISTING,
+// StandardCopyOption.ATOMIC_MOVE
+// );
+ // 鍘熷瓙绉诲姩澶辫触锛屼娇鐢ㄥ鍒�+鍒犻櫎
+ Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
+ Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
// 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛�
@@ -458,8 +838,10 @@
}
}
+ // 鏂囦欢杩佺Щ鏂规硶
- private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) {
+ @Override
+ public void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, SaleEnum type) {
// 鎸塈D鍒嗙粍锛屽尯鍒嗘柊澧炲拰鏇存柊鐨勮褰�
Map<Boolean, List<SalesLedgerProduct>> partitionedProducts = products.stream()
.peek(p -> p.setSalesLedgerId(salesLedgerId))
@@ -471,17 +853,25 @@
// 鎵ц鏇存柊鎿嶄綔
if (!updateList.isEmpty()) {
for (SalesLedgerProduct product : updateList) {
- product.setType(type);
+ product.setType(type.getCode());
salesLedgerProductMapper.updateById(product);
+ // 娓呯┖閿�鍞骇鍝佺粦瀹氱殑鍔犲伐
+ salesLedgerProductProcessBindService.updateProductProcessBind(product.getSalesProductProcessList(), product.getId());
}
}
// 鎵ц鎻掑叆鎿嶄綔
if (!insertList.isEmpty()) {
for (SalesLedgerProduct salesLedgerProduct : insertList) {
- salesLedgerProduct.setType(type);
+ salesLedgerProduct.setType(type.getCode());
salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
+ salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice());
salesLedgerProductMapper.insert(salesLedgerProduct);
+ // 缁戝畾浜у搧棰濆鍔犲伐
+ // 娓呯┖閿�鍞骇鍝佺粦瀹氱殑鍔犲伐
+ salesLedgerProductProcessBindService.updateProductProcessBind(salesLedgerProduct.getSalesProductProcessList(), salesLedgerProduct.getId());
+ // 娣诲姞鐢熶骇鏁版嵁
+// salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
}
}
}
@@ -517,39 +907,524 @@
}
}
- if (!redisTemplate.hasKey(lockKey)) {
+ if (Boolean.FALSE.equals(redisTemplate.hasKey(lockKey))) {
throw new RuntimeException("鑾峰彇鍚堝悓缂栧彿鐢熸垚閿佸け璐ワ細瓒呮椂");
}
// 2. 鏌ヨ褰撳ぉ/鍏徃宸插瓨鍦ㄧ殑搴忓垪鍙凤紙涓庡師閫昏緫涓�鑷达級
- Long tenantId = SecurityUtils.getLoginUser().getTenantId();
- if (null != tenantId) {
- //鑾峰彇鍏徃缂栧彿
- SysDept sysDept = sysDeptMapper.selectDeptById(tenantId.longValue());
- if (!ObjectUtils.isEmpty(sysDept)) {
- datePart = (StringUtils.isEmpty(sysDept.getDeptNick()) ? "" : sysDept.getDeptNick()) + datePart;
- }
- }
+// Long tenantId = SecurityUtils.getLoginUser().getTenantId();
+// if (null != tenantId) {
+// //鑾峰彇鍏徃缂栧彿
+// SysDept sysDept = sysDeptMapper.selectDeptById(tenantId);
+// if (!ObjectUtils.isEmpty(sysDept)) {
+// datePart = (StringUtils.isEmpty(sysDept.getDeptNick()) ? "" : sysDept.getDeptNick()) + datePart;
+// }
+// }
+ datePart = "D" + datePart;
List<Integer> existingSequences = salesLedgerMapper.selectSequencesByDate(datePart);
int nextSequence = findFirstMissingSequence(existingSequences);
return datePart + String.format("%03d", nextSequence);
} finally {
- // 3. 閲婃斁閿侊紙浣跨敤Lua鑴氭湰淇濊瘉鍘熷瓙鎬э紝閬垮厤璇垹鍏朵粬绾跨▼鐨勯攣锛�
+ // 3. 閲婃斁閿�
String luaScript = "if redis.call('GET', KEYS[1]) == ARGV[1] then return redis.call('DEL', KEYS[1]) else return 0 end";
redisTemplate.execute(
new DefaultRedisScript<>(luaScript, Long.class),
Collections.singletonList(lockKey),
- lockValue // 鍙湁鎸佹湁鐩稿悓鍊肩殑绾跨▼鎵嶈兘鍒犻櫎閿�
+ lockValue
);
}
+ }
+
+ @Override
+ public SalesLedgerProcessRouteDto salesProcess(Long salesLedgerId) {
+ SalesLedgerProcessRouteDto dto = new SalesLedgerProcessRouteDto();
+ List<SalesLedgerProcessRoute> list = baseMapper.selectSalesProcess(salesLedgerId);
+ if (CollectionUtils.isNotEmpty(list)) {
+ Long processRouteId = list.get(0).getProcessRouteId();
+ ProcessRoute processRoute = processRouteMapper.selectById(processRouteId);
+ if (processRoute != null) {
+ dto.setRouteId(processRoute.getId());
+ dto.setRouteName(processRoute.getProcessRouteName());
+ }
+ } else {
+ // 瑕佹槸list鏌ヨ涓虹┖鐨勮瘽锛屽氨鏌ヨ榛樿鐨勫伐鑹鸿矾绾胯繑鍥�
+ ProcessRoute defaultRoute = processRouteMapper.selectOne(new LambdaQueryWrapper<ProcessRoute>().eq(ProcessRoute::getIsDefault, 1).last("limit 1"));
+ if (defaultRoute != null) {
+ dto.setRouteId(defaultRoute.getId());
+ dto.setRouteName(defaultRoute.getProcessRouteName());
+ List<ProcessRouteItem> routeItems = processRouteItemMapper.selectList(new LambdaQueryWrapper<ProcessRouteItem>().eq(ProcessRouteItem::getRouteId, defaultRoute.getId()).orderByAsc(ProcessRouteItem::getDragSort));
+ list = routeItems.stream().map(item -> {
+ SalesLedgerProcessRoute salesLedgerProcessRoute = new SalesLedgerProcessRoute();
+ salesLedgerProcessRoute.setProcessRouteId(defaultRoute.getId());
+ salesLedgerProcessRoute.setSalesLedgerId(salesLedgerId);
+ salesLedgerProcessRoute.setProcessRouteItemId(item.getId());
+ salesLedgerProcessRoute.setProcessName(item.getProcessName());
+ salesLedgerProcessRoute.setDragSort(item.getDragSort());
+ return salesLedgerProcessRoute;
+ }).collect(Collectors.toList());
+ }
+ }
+ dto.setList(list);
+ return dto;
+ }
+
+ @Override
+ public SalesProcessCardDto processCard(Long salesLedgerId) {
+ if (salesLedgerId == null) {
+ throw new ServiceException("娴佺▼鍗℃墦鍗板け璐�,鎵撳嵃閿�鍞鍗曚笉鑳戒负绌�");
+ }
+ // 鏌ヨ閿�鍞鍗�
+ SalesLedger salesLedger = baseMapper.selectById(salesLedgerId);
+ if (salesLedger == null) {
+ throw new ServiceException("娴佺▼鍗℃墦鍗板け璐�,閿�鍞鍗曚笉瀛樺湪");
+ }
+
+ SalesProcessCardDto dto = new SalesProcessCardDto();
+ dto.setSalesContractNo(salesLedger.getSalesContractNo());
+ dto.setCustomerName(salesLedger.getCustomerName());
+ dto.setDeliveryDate(salesLedger.getDeliveryDate());
+ dto.setRegister(SecurityUtils.getLoginUser().getUser().getNickName());
+ dto.setRegisterDate(LocalDateTime.now());
+ dto.setOrderProcessRequirement(salesLedger.getRemarks());
+
+ // 鏌ヨ浜у搧鍒楄〃
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(
+ new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId));
+
+ BigDecimal totalQuantity = BigDecimal.ZERO;
+ BigDecimal totalArea = BigDecimal.ZERO;
+ List<SalesProcessCardDto.ProcessCardItemDto> itemDtos = new ArrayList<>();
+
+ for (SalesLedgerProduct p : products) {
+ SalesProcessCardDto.ProcessCardItemDto itemDto = new SalesProcessCardDto.ProcessCardItemDto();
+ itemDto.setFloorCode(p.getFloorCode());
+ // 缁勮浜у搧鎻忚堪锛氬ぇ绫� + (瑙勬牸)
+ String desc = (p.getProductCategory() != null ? p.getProductCategory() : "") +
+ (StringUtils.isNotBlank(p.getSpecificationModel()) ? " " + p.getSpecificationModel() : "");
+ itemDto.setProductDescription(desc.trim());
+ itemDto.setWidth(p.getWidth());
+ itemDto.setHeight(p.getHeight());
+ itemDto.setQuantity(p.getQuantity());
+
+ // 闈㈢Н璁$畻(骞崇背)
+ BigDecimal area = p.getActualPieceArea() != null ? p.getActualPieceArea() : p.getSettlePieceArea();
+ if (area == null && p.getWidth() != null && p.getHeight() != null) {
+ area = p.getWidth().multiply(p.getHeight()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP);
+ }
+ itemDto.setArea(area);
+ itemDto.setProcessRequirement(p.getProcessRequirement());
+
+ BigDecimal qty = p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO;
+ totalQuantity = totalQuantity.add(qty);
+ if (area != null) {
+ totalArea = totalArea.add(area.multiply(qty));
+ }
+
+ itemDtos.add(itemDto);
+ }
+ dto.setItems(itemDtos);
+ dto.setTotalQuantity(totalQuantity);
+ dto.setTotalArea(totalArea.setScale(2, RoundingMode.HALF_UP));
+
+ // 宸ヨ壓璺嚎
+ List<SalesLedgerProcessRoute> salesLedgerProcessRoutes = salesLedgerProcessRouteService.list(
+ new LambdaQueryWrapper<SalesLedgerProcessRoute>()
+ .eq(SalesLedgerProcessRoute::getSalesLedgerId, salesLedgerId)
+ .orderByAsc(SalesLedgerProcessRoute::getDragSort));
+
+ List<SalesProcessCardDto.ProcessNodeDto> nodeDtos = new ArrayList<>();
+
+ if (CollectionUtils.isEmpty(salesLedgerProcessRoutes)) {
+ // 鏃犺嚜瀹氫箟璺嚎锛屽彇榛樿璺嚎
+ ProcessRoute defaultRoute = processRouteMapper.selectOne(
+ new LambdaQueryWrapper<ProcessRoute>().eq(ProcessRoute::getIsDefault, 1).last("LIMIT 1"));
+ if (defaultRoute != null) {
+ List<ProcessRouteItem> routeItems = processRouteItemMapper.selectList(
+ new LambdaQueryWrapper<ProcessRouteItem>()
+ .eq(ProcessRouteItem::getRouteId, defaultRoute.getId())
+ .orderByAsc(ProcessRouteItem::getDragSort));
+ for (ProcessRouteItem i : routeItems) {
+ SalesProcessCardDto.ProcessNodeDto node = new SalesProcessCardDto.ProcessNodeDto();
+ node.setProcessRouteItemId(i.getId());
+ node.setProcessRouteItemName(i.getProcessName());
+ node.setDragSort(i.getDragSort());
+ nodeDtos.add(node);
+ }
+ }
+ } else {
+ // 浣跨敤鑷畾涔夎矾绾跨粦瀹氱殑鑺傜偣
+ List<Long> itemIds = salesLedgerProcessRoutes.stream()
+ .map(SalesLedgerProcessRoute::getProcessRouteItemId)
+ .collect(Collectors.toList());
+ List<ProcessRouteItem> rawItems = processRouteItemMapper.selectBatchIds(itemIds);
+ Map<Long, ProcessRouteItem> itemMap = rawItems.stream()
+ .collect(Collectors.toMap(ProcessRouteItem::getId, i -> i, (a, b) -> a));
+
+ for (SalesLedgerProcessRoute r : salesLedgerProcessRoutes) {
+ ProcessRouteItem pi = itemMap.get(r.getProcessRouteItemId());
+ if (pi != null) {
+ SalesProcessCardDto.ProcessNodeDto node = new SalesProcessCardDto.ProcessNodeDto();
+ node.setProcessRouteItemId(pi.getId());
+ node.setProcessRouteItemName(pi.getProcessName());
+ node.setDragSort(r.getDragSort() != null ? r.getDragSort() : pi.getDragSort());
+ node.setRemark(r.getRemark());
+ nodeDtos.add(node);
+ }
+ }
+ }
+
+ if (!nodeDtos.isEmpty()) {
+ // dragSort 杩涜鍗囧簭鎺掑簭
+ nodeDtos.sort(Comparator.comparing(
+ SalesProcessCardDto.ProcessNodeDto::getDragSort,
+ Comparator.nullsLast(Comparator.naturalOrder())
+ ));
+ // 閲嶆柊鐢熸垚鎺掑簭鍚庣殑璺緞鍚嶇О鍒楄〃
+ List<String> sortedPathNames = nodeDtos.stream()
+ .map(SalesProcessCardDto.ProcessNodeDto::getProcessRouteItemName)
+ .collect(Collectors.toList());
+ // 鎷兼帴瀛楃涓�
+ dto.setProcessPathDisplay(String.join(" -> ", sortedPathNames));
+ // 璁剧疆椤跺眰鑺傜偣鐨勫伐鑹鸿矾绾�
+ dto.setRouteNodes(nodeDtos);
+ }
+
+ return dto;
+ }
+
+ @Override
+ public SalesOrdersDto salesOrders(Long salesLedgerId) {
+ if (salesLedgerId == null) {
+ throw new ServiceException("鎵撳嵃閿�鍞鍗曞け璐�,閿�鍞鍗旾D涓嶈兘涓虹┖");
+ }
+ SalesLedger salesLedger = baseMapper.selectById(salesLedgerId);
+ if (salesLedger == null) {
+ throw new ServiceException("鎵撳嵃閿�鍞鍗曞け璐�,閿�鍞鍗曚笉瀛樺湪");
+ }
+
+ SalesOrdersDto dto = new SalesOrdersDto();
+ dto.setSalesContractNo(salesLedger.getSalesContractNo());
+ dto.setCustomerName(salesLedger.getCustomerName());
+ dto.setProjectName(salesLedger.getProjectName());
+ dto.setSalesman(salesLedger.getSalesman());
+ dto.setExecutionDate(salesLedger.getExecutionDate() != null ? salesLedger.getExecutionDate().atStartOfDay() : null);
+ dto.setDeliveryDate(salesLedger.getDeliveryDate());
+ dto.setRemakes(salesLedger.getRemarks());
+ dto.setCompanyName("楣ゅ澶╂矏閽㈠寲鐜荤拑鍘�");
+
+ // 閫佽揣鍦板潃
+ if (salesLedger.getCustomerId() != null) {
+ Customer customer = customerMapper.selectById(salesLedger.getCustomerId());
+ if (customer != null) {
+ StringBuilder address = new StringBuilder();
+ if (customer.getRegionsId() != null) {
+ CustomerRegions regions = customerRegionsService.getById(customer.getRegionsId());
+ if (regions != null) {
+ address.append(regions.getRegionsName());
+ }
+ }
+ if (StringUtils.isNotEmpty(customer.getCompanyAddress())) {
+ address.append(customer.getCompanyAddress());
+ }
+ dto.setCompanyAddress(address.toString());
+ }
+ }
+
+ // 鍒跺崟鍛�
+ if (StringUtils.isNotEmpty(salesLedger.getEntryPerson())) {
+ try {
+ SysUser user = sysUserMapper.selectUserById(Long.parseLong(salesLedger.getEntryPerson()));
+ if (user != null) {
+ dto.setOrderMaker(user.getNickName());
+ }
+ } catch (Exception e) {
+ log.error("鑾峰彇鍒跺崟鍛樹俊鎭け璐�: {}", e.getMessage());
+ }
+ }
+ // 鍒跺崟鏃ユ湡 (搴曢儴)
+ dto.setOrderMakerDate(salesLedger.getExecutionDate() != null ? salesLedger.getExecutionDate().atStartOfDay() : null);
+
+ // 鎵撳嵃淇℃伅
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if (loginUser != null && loginUser.getUser() != null) {
+ dto.setPrintPeople(loginUser.getUser().getNickName());
+ }
+ dto.setPrintTime(LocalDateTime.now());
+
+ // 鏌ヨ浜у搧鍒楄〃
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(
+ new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId));
+
+ if (CollectionUtils.isNotEmpty(products)) {
+ SalesLedgerProduct firstProduct = products.get(0);
+ dto.setProductName(firstProduct.getProductCategory() != null ? firstProduct.getProductCategory() : "");
+ }
+
+ List<SalesOrdersDto.SalesOrderItemDto> itemDtos = new ArrayList<>();
+ BigDecimal subtotalQuantity = BigDecimal.ZERO;
+ BigDecimal subtotalArea = BigDecimal.ZERO;
+ BigDecimal subtotalAmount = BigDecimal.ZERO;
+
+ for (SalesLedgerProduct p : products) {
+ SalesOrdersDto.SalesOrderItemDto itemDto = new SalesOrdersDto.SalesOrderItemDto();
+ itemDto.setFloorCode(p.getFloorCode());
+ String desc = (p.getProductCategory() != null ? p.getProductCategory() : "") +
+ (StringUtils.isNotBlank(p.getSpecificationModel()) ? " " + p.getSpecificationModel() : "");
+ itemDto.setProductDescription(desc.trim());
+ itemDto.setWidth(p.getWidth());
+ itemDto.setHeight(p.getHeight());
+ itemDto.setQuantity(p.getQuantity());
+
+ // 闈㈢Н璁$畻
+ BigDecimal area = p.getSettleTotalArea() != null ? p.getSettleTotalArea() : p.getActualTotalArea();
+ if (area == null && p.getWidth() != null && p.getHeight() != null && p.getQuantity() != null) {
+ area = p.getWidth().multiply(p.getHeight()).multiply(p.getQuantity()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP);
+ }
+ itemDto.setArea(area);
+ itemDto.setUnitPrice(p.getTaxInclusiveUnitPrice());
+ itemDto.setAmount(p.getTaxInclusiveTotalPrice());
+ itemDto.setRemark(p.getRemark());
+ itemDto.setProcessRequirement(p.getProcessRequirement());
+
+ subtotalQuantity = subtotalQuantity.add(p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO);
+ subtotalArea = subtotalArea.add(area != null ? area : BigDecimal.ZERO);
+ subtotalAmount = subtotalAmount.add(p.getTaxInclusiveTotalPrice() != null ? p.getTaxInclusiveTotalPrice() : BigDecimal.ZERO);
+
+ itemDtos.add(itemDto);
+ }
+ dto.setItems(itemDtos);
+ dto.setSubtotalQuantity(subtotalQuantity);
+ dto.setSubtotalArea(subtotalArea.setScale(2, RoundingMode.HALF_UP));
+ dto.setSubtotalAmount(subtotalAmount);
+
+ // 澶勭悊鍏朵粬璐圭敤
+ List<Long> productIds = products.stream().map(SalesLedgerProduct::getId).collect(Collectors.toList());
+ BigDecimal otherFeesTotal = BigDecimal.ZERO;
+ if (CollectionUtils.isNotEmpty(productIds)) {
+ List<SalesLedgerProductProcessBind> binds = salesLedgerProductProcessBindService.list(
+ new LambdaQueryWrapper<SalesLedgerProductProcessBind>().in(SalesLedgerProductProcessBind::getSalesLedgerProductId, productIds));
+
+ if (CollectionUtils.isNotEmpty(binds)) {
+ Map<Integer, Integer> processQuantityMap = binds.stream()
+ .collect(Collectors.groupingBy(SalesLedgerProductProcessBind::getSalesLedgerProductProcessId,
+ Collectors.summingInt(b -> b.getQuantity() != null ? b.getQuantity() : 0)));
+
+ List<Integer> processIds = new ArrayList<>(processQuantityMap.keySet());
+ List<SalesLedgerProductProcess> processes = salesLedgerProductProcessService.listByIds(processIds);
+
+ List<SalesOrdersDto.OtherFeeDto> otherFeeDtos = new ArrayList<>();
+
+ for (SalesLedgerProductProcess proc : processes) {
+ SalesOrdersDto.OtherFeeDto feeDto = new SalesOrdersDto.OtherFeeDto();
+ feeDto.setFeeName(proc.getProcessName());
+ feeDto.setUnitPrice(proc.getUnitPrice());
+ Integer qty = processQuantityMap.get(proc.getId());
+ feeDto.setQuantity(new BigDecimal(qty != null ? qty : 0));
+ BigDecimal amount = proc.getUnitPrice() != null ? proc.getUnitPrice().multiply(feeDto.getQuantity()) : BigDecimal.ZERO;
+ feeDto.setAmount(amount);
+ otherFeeDtos.add(feeDto);
+ otherFeesTotal = otherFeesTotal.add(amount);
+ }
+ dto.setOtherFees(otherFeeDtos);
+ }
+ }
+
+ dto.setTotalQuantity(subtotalQuantity);
+ dto.setTotalArea(dto.getSubtotalArea());
+ dto.setTotalAmount(subtotalAmount.add(otherFeesTotal));
+ dto.setTotalAmountDisplay(dto.getTotalAmount().setScale(2, RoundingMode.HALF_UP).toString() + "鍏�");
+
+ return dto;
+ }
+
+ @Override
+ public SalesInvoicesDto salesInvoices(List<Long> salesLedgerIds) {
+ if (CollectionUtils.isEmpty(salesLedgerIds)) {
+ throw new ServiceException("閿�鍞彂璐у崟鎵撳嵃澶辫触,閿�鍞鍗曚笉鑳戒负绌�");
+ }
+
+ List<SalesLedger> ledgers = salesLedgerMapper.selectBatchIds(salesLedgerIds);
+ if (CollectionUtils.isEmpty(ledgers)) {
+ throw new ServiceException("閿�鍞彂璐у崟鎵撳嵃澶辫触,鏈壘鍒板搴斿彴璐﹁褰�");
+ }
+
+ Long customerId = ledgers.get(0).getCustomerId();
+ for (SalesLedger ledger : ledgers) {
+ if (!Objects.equals(customerId, ledger.getCustomerId())) {
+ throw new ServiceException("閿�鍞彂璐у崟鍚堝苟鎵撳嵃鍙兘鏄悓涓�涓鎴�");
+ }
+ }
+
+ SalesInvoicesDto dto = new SalesInvoicesDto();
+
+ Customer customer = customerMapper.selectById(customerId);
+ if (customer != null) {
+ dto.setCustomerName(customer.getCustomerName());
+ dto.setContactPerson(customer.getContactPerson());
+ dto.setContactPhone(customer.getContactPhone());
+
+ StringBuilder address = new StringBuilder();
+ if (customer.getRegionsId() != null) {
+ CustomerRegions regions = customerRegionsService.getById(customer.getRegionsId());
+ if (regions != null) {
+ address.append(regions.getRegionsName());
+ }
+ }
+ if (StringUtils.isNotEmpty(customer.getCompanyAddress())) {
+ address.append(customer.getCompanyAddress());
+ }
+ dto.setCompanyAddress(address.toString());
+ }
+
+ // 鍙戣揣鍗曞彿 (XF + 鏃ユ湡 + 搴忓垪)
+ String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMMdd"));
+ String redisKey = "sales:delivery:seq:" + dateStr;
+ Long seq = redisTemplate.opsForValue().increment(redisKey);
+ if (seq != null && seq == 1) {
+ redisTemplate.expire(redisKey, 48, TimeUnit.HOURS);
+ }
+ dto.setDeliveryNo("XF" + dateStr + String.format("%03d", seq != null ? seq : 1));
+
+ // 瀵规柟鍗曞彿
+// dto.setExternalOrderNo(ledgers.get(0).getCustomerContractNo());
+
+ // 鏌ヨ鎵�鏈変骇鍝�
+ List<SalesLedgerProduct> allProducts = salesLedgerProductMapper.selectList(
+ new LambdaQueryWrapper<SalesLedgerProduct>().in(SalesLedgerProduct::getSalesLedgerId, salesLedgerIds));
+
+ if (CollectionUtils.isNotEmpty(allProducts)) {
+ Map<Long, SalesLedger> ledgerMap = ledgers.stream()
+ .collect(Collectors.toMap(SalesLedger::getId, Function.identity()));
+
+ Map<Long, List<SalesLedgerProduct>> groupedData = new LinkedHashMap<>();
+ for (SalesLedgerProduct p : allProducts) {
+ groupedData.computeIfAbsent(p.getSalesLedgerId(), k -> new ArrayList<>()).add(p);
+ }
+
+ List<SalesInvoicesDto.InvoiceOrderGroupDto> groups = new ArrayList<>();
+ BigDecimal totalQty = BigDecimal.ZERO;
+ BigDecimal totalArea = BigDecimal.ZERO;
+
+ for (Map.Entry<Long, List<SalesLedgerProduct>> ledgerEntry : groupedData.entrySet()) {
+ SalesLedger ledger = ledgerMap.get(ledgerEntry.getKey());
+ String orderNo = ledger != null ? ledger.getSalesContractNo() : "";
+ List<SalesLedgerProduct> products = ledgerEntry.getValue();
+
+ SalesInvoicesDto.InvoiceOrderGroupDto group = new SalesInvoicesDto.InvoiceOrderGroupDto();
+ group.setSalesContractNo(orderNo);
+ if (CollectionUtils.isNotEmpty(products)) {
+ group.setProductName(products.get(0).getProductCategory());
+ }
+
+ List<SalesInvoicesDto.InvoiceItemDto> itemDtos = new ArrayList<>();
+ BigDecimal groupQty = BigDecimal.ZERO;
+ BigDecimal groupArea = BigDecimal.ZERO;
+
+ for (SalesLedgerProduct p : products) {
+ SalesInvoicesDto.InvoiceItemDto item = new SalesInvoicesDto.InvoiceItemDto();
+ item.setFloorCode(p.getFloorCode());
+ item.setWidthHeight((p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") +
+ " * " + (p.getHeight() != null ? p.getHeight().stripTrailingZeros().toPlainString() : "0"));
+ item.setQuantity(p.getQuantity());
+
+ // 闈㈢Н
+ BigDecimal area = p.getSettleTotalArea() != null ? p.getSettleTotalArea() : p.getActualTotalArea();
+ if (area == null && p.getWidth() != null && p.getHeight() != null && p.getQuantity() != null) {
+ area = p.getWidth().multiply(p.getHeight()).multiply(p.getQuantity()).divide(new BigDecimal(1000000), 2, RoundingMode.HALF_UP);
+ }
+ item.setArea(area);
+ item.setRemark(p.getRemark());
+ item.setProcessRequirement(p.getProcessRequirement());
+
+ itemDtos.add(item);
+ groupQty = groupQty.add(p.getQuantity() != null ? p.getQuantity() : BigDecimal.ZERO);
+ groupArea = groupArea.add(area != null ? area : BigDecimal.ZERO);
+ }
+
+ group.setItems(itemDtos);
+ group.setGroupTotalQuantity(groupQty);
+ group.setGroupTotalArea(groupArea.setScale(2, RoundingMode.HALF_UP));
+ groups.add(group);
+
+ totalQty = totalQty.add(groupQty);
+ totalArea = totalArea.add(groupArea);
+ }
+ dto.setGroups(groups);
+ dto.setTotalQuantity(totalQty);
+ dto.setTotalArea(totalArea.setScale(2, RoundingMode.HALF_UP));
+ }
+
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ if (loginUser != null && loginUser.getUser() != null) {
+ dto.setOrderMaker(loginUser.getUser().getNickName());
+ }
+ dto.setExecutionDate(LocalDateTime.now());
+
+ return dto;
+ }
+
+ @Override
+ public List<SalesLabelDto> salesLabel(Long salesLedgerId) {
+ if (salesLedgerId == null) {
+ throw new ServiceException("鎵撳嵃鏍囩澶辫触,鏁版嵁涓嶈兘涓虹┖");
+ }
+ SalesLedger salesLedger = baseMapper.selectById(salesLedgerId);
+ if (salesLedger == null) {
+ throw new ServiceException("鎵撳嵃澶辫触,閿�鍞鍗曚笉瀛樺湪");
+ }
+
+ // 鏌ヨ浜у搧鍒楄〃
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(
+ new LambdaQueryWrapper<SalesLedgerProduct>().eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId));
+
+ // 鏌ヨ瀹㈡埛鍦板潃
+ String fullAddress = "";
+ if (salesLedger.getCustomerId() != null) {
+ Customer customer = customerMapper.selectById(salesLedger.getCustomerId());
+ if (customer != null) {
+ StringBuilder addressSb = new StringBuilder();
+ if (customer.getRegionsId() != null) {
+ CustomerRegions regions = customerRegionsService.getById(customer.getRegionsId());
+ if (regions != null) {
+ addressSb.append(regions.getRegionsName());
+ }
+ }
+ if (StringUtils.isNotEmpty(customer.getCompanyAddress())) {
+ addressSb.append(customer.getCompanyAddress());
+ }
+ fullAddress = addressSb.toString();
+ }
+ }
+
+ List<SalesLabelDto> list = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(products)) {
+ for (SalesLedgerProduct p : products) {
+ SalesLabelDto dto = new SalesLabelDto();
+ dto.setCustomerName(salesLedger.getCustomerName());
+ dto.setSalesContractNo(salesLedger.getSalesContractNo());
+ dto.setProductName(p.getProductCategory());
+
+ // 瀹�*楂�=鏁伴噺
+ String specification = (p.getWidth() != null ? p.getWidth().stripTrailingZeros().toPlainString() : "0") + "*" +
+ (p.getHeight() != null ? p.getHeight().stripTrailingZeros().toPlainString() : "0") + "=" +
+ (p.getQuantity() != null ? p.getQuantity().stripTrailingZeros().toPlainString() : "0");
+ dto.setSpecification(specification);
+
+ // 瀹㈡埛鍦板潃 + 妤煎眰缂栧彿
+ dto.setFloorCode(fullAddress + (StringUtils.isNotEmpty(p.getFloorCode()) ? " " + p.getFloorCode() : ""));
+ list.add(dto);
+ }
+ }
+
+ return list;
}
private int findFirstMissingSequence(List<Integer> sequences) {
if (sequences.isEmpty()) {
return 1;
}
- // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁帮紙涓庡師閫昏緫涓�鑷达級
+ // 鎺掑簭鍚庢煡鎵剧涓�涓己澶辩殑姝f暣鏁�
sequences.sort(Integer::compareTo);
int next = 1;
for (int seq : sequences) {
@@ -579,14 +1454,13 @@
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- // 鏋勯�犱富琛ㄦ洿鏂板璞★紙鏀寔浠绘剰涓昏〃绫诲瀷锛�
+ // 鏋勯�犱富琛ㄦ洿鏂板璞�
try {
S entity = mainEntityClass.getDeclaredConstructor().newInstance();
Field idField = mainEntityClass.getDeclaredField("id");
idField.setAccessible(true);
idField.set(entity, mainId);
- // 璁剧疆 contractAmount 瀛楁锛屾敞鎰忚繖閲屽亣璁惧瓧娈靛悕涓� "contractAmount"
Field amountField = mainEntityClass.getDeclaredField("contractAmount");
amountField.setAccessible(true);
amountField.set(entity, totalAmount);
@@ -596,4 +1470,34 @@
throw new RuntimeException("鍔ㄦ�佹洿鏂颁富琛ㄩ噾棰濆け璐�", e);
}
}
+
+ // 鍐呴儴绫荤敤浜庡瓨鍌ㄨ仛鍚堢粨鏋�
+ private static class GroupedCustomer {
+ private final Long customerId;
+ private final String customerName;
+ private BigDecimal totalAmount = BigDecimal.ZERO;
+
+ public GroupedCustomer(Long customerId, String customerName) {
+ this.customerId = customerId;
+ this.customerName = customerName;
+ }
+
+ public void addAmount(BigDecimal amount) {
+ if (amount != null) {
+ this.totalAmount = this.totalAmount.add(amount);
+ }
+ }
+
+ public Long getCustomerId() {
+ return customerId;
+ }
+
+ public String getCustomerName() {
+ return customerName;
+ }
+
+ public BigDecimal getTotalAmount() {
+ return totalAmount;
+ }
+ }
}
--
Gitblit v1.9.3