From 55d694aaae4e421b5e55cd941500e08f85cb5d4d Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 27 八月 2026 18:21:33 +0800
Subject: [PATCH] feat(sales): 添加框架合同订单功能并优化销售台账管理
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java | 78 +++++++++++++++++++++++---------------
1 files changed, 47 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
index 9f6e004..55cb1d4 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -2,7 +2,9 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.procurementrecord.utils.StockUtils;
@@ -25,17 +27,16 @@
import com.ruoyi.technology.mapper.TechnologyBomStructureMapper;
import com.ruoyi.technology.mapper.TechnologyRoutingMapper;
import com.ruoyi.technology.pojo.TechnologyRouting;
+import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
-import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
-import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
@@ -98,16 +99,29 @@
List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectSalesLedgerProductList(salesLedgerProduct);
if(!CollectionUtils.isEmpty(salesLedgerProducts)){
salesLedgerProducts.forEach(item -> {
- // 鍙戣揣淇℃伅
- ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
+ // 鍙戣揣淇℃伅锛堝彇鏈�鏂颁竴鏉★紝鍙煡璇㈠鏍搁�氳繃鎴栧凡鍙戣揣鐨勮褰曪級
+ ShippingInfo latestShippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
.eq(ShippingInfo::getSalesLedgerProductId, item.getId())
+ .in(ShippingInfo::getStatus, "瀹℃牳閫氳繃", "宸插彂璐�")
.orderByDesc(ShippingInfo::getCreateTime)
.last("limit 1"));
- if(shippingInfo != null){
- item.setShippingDate(shippingInfo.getShippingDate());
- item.setShippingCarNumber(shippingInfo.getShippingCarNumber());
- item.setExpressCompany(shippingInfo.getExpressCompany());
- item.setExpressNumber(shippingInfo.getExpressNumber());
+ if(latestShippingInfo != null){
+ item.setShippingDate(latestShippingInfo.getShippingDate());
+ item.setExpressCompany(latestShippingInfo.getExpressCompany());
+ item.setExpressNumber(latestShippingInfo.getExpressNumber());
+ }
+ // 杞︾墝鍙凤細鍙栨墍鏈夊鏍搁�氳繃鎴栧凡鍙戣揣璁板綍鐨勮溅鐗屽彿锛岄�楀彿鎷兼帴
+ List<ShippingInfo> allShippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
+ .eq(ShippingInfo::getSalesLedgerProductId, item.getId())
+ .in(ShippingInfo::getStatus, "瀹℃牳閫氳繃", "宸插彂璐�")
+ .orderByAsc(ShippingInfo::getCreateTime));
+ if(!CollectionUtils.isEmpty(allShippingInfos)){
+ String carNumbers = allShippingInfos.stream()
+ .map(ShippingInfo::getShippingCarNumber)
+ .filter(carNo -> carNo != null && !carNo.trim().isEmpty())
+ .distinct()
+ .collect(Collectors.joining(","));
+ item.setShippingCarNumber(carNumbers);
}
});
}
@@ -215,23 +229,34 @@
* 鏂板鐢熶骇鏁版嵁
*/
public void addProductionData(SalesLedgerProduct salesLedgerProduct) {
- //鍏堝垽鏂浜у搧鏄惁闇�瑕佺敓浜�
- if (!salesLedgerProduct.getIsProduction()) {
+ SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId());
+ if (salesLedger == null) {
return;
}
- SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerProduct.getSalesLedgerId());
+ boolean isFrameworkOrder = Objects.equals(salesLedger.getContractType(), 3);
+ // 妗嗘灦鍚堝悓涓嶇敓鎴愮敓浜ц鍒掞紱妗嗘灦璁㈠崟鍥哄畾鐢熸垚锛堟暟閲忕暀绌猴紝涓嬪彂鏃跺~鍐欙級
+ if (Objects.equals(salesLedger.getContractType(), 2)) {
+ return;
+ }
+ if (!isFrameworkOrder && !BooleanUtils.isTrue(salesLedgerProduct.getIsProduction())) {
+ return;
+ }
ProductionPlan productionPlan = new ProductionPlan();
productionPlan.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId());
productionPlan.setSalesLedgerProductId(salesLedgerProduct.getId());
- productionPlan.setMpsNo(generateNextPlanNo(salesLedger.getEntryDate().toInstant()
- .atZone(ZoneId.systemDefault())
- .toLocalDate().format(DateTimeFormatter.ofPattern("yyyyMMdd"))));
+ // 璁″垝鍗曞彿鏃ユ湡鍓嶇紑锛氱櫥璁版棩鏈熶负绌烘椂鍙栧綋鍓嶆棩鏈�
+ java.time.LocalDate planDate = salesLedger.getEntryDate() != null
+ ? com.ruoyi.common.utils.DateUtils.toLocalDate(salesLedger.getEntryDate())
+ : java.time.LocalDate.now();
+ productionPlan.setMpsNo(generateNextPlanNo(planDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"))));
productionPlan.setProductModelId(salesLedgerProduct.getProductModelId());
productionPlan.setQtyRequired(salesLedgerProduct.getQuantity());
productionPlan.setSource("閿�鍞�");
productionPlan.setStatus(0);
- productionPlan.setRequiredDate(salesLedger.getDeliveryDate());//闇�姹傛棩鏈�=浜よ揣鏃ユ湡
- productionPlan.setPromisedDeliveryDate(salesLedger.getDeliveryDate());//鎵胯鏃ユ湡=浜よ揣鏃ユ湡
+ // 闇�姹傛棩鏈�=浜よ揣鏃ユ湡锛屾鏋惰鍗曞彇浜у搧浜よ揣鏃ユ湡锛屽叾浣欏彇涓昏〃浜よ揣鏃ユ湡
+ LocalDate deliveryDate = isFrameworkOrder ? salesLedgerProduct.getDeliveryDate() : salesLedger.getDeliveryDate();
+ productionPlan.setRequiredDate(deliveryDate);//闇�姹傛棩鏈�=浜よ揣鏃ユ湡
+ productionPlan.setPromisedDeliveryDate(deliveryDate);//鎵胯鏃ユ湡=浜よ揣鏃ユ湡
productionPlanMapper.insert(productionPlan);
}
@@ -276,20 +301,11 @@
.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);
-
- Field amountField = mainEntityClass.getDeclaredField("contractAmount");
- amountField.setAccessible(true);
- amountField.set(entity, totalAmount);
-
- mainMapper.updateById(entity);
- } catch (Exception e) {
- throw new RuntimeException("鍔ㄦ�佹洿鏂颁富琛ㄩ噾棰濆け璐�", e);
- }
+ // 浠呮洿鏂伴噾棰濆垪锛岄伩鍏嶆暣瀹炰綋 updateById 鎶婂叾瀹冮潪绌哄瓧娈碉紙濡� contract_type 榛樿鍊� 1锛変竴骞惰鐩�
+ UpdateWrapper<S> wrapper = Wrappers.update();
+ wrapper.eq("id", mainId)
+ .set("contract_amount", totalAmount);
+ mainMapper.update(null, wrapper);
}
@Override
public R judgmentInventory(SalesLedgerProduct salesLedgerProduct) {
--
Gitblit v1.9.3