From 49eda5931240f1a8894ee3edbfd2dc2538328b55 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期五, 29 五月 2026 15:19:19 +0800
Subject: [PATCH] feat: 添加一键发货,自动审批通过出库,取消车牌必填项,发货完成后产品状态自己变为不足->变为已发货
---
src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java | 116 ++++++++++++++++++++++++++++++++++++++
src/main/java/com/ruoyi/sales/service/ShippingInfoService.java | 15 +++++
src/main/resources/mapper/sales/InvoiceLedgerMapper.xml | 2
src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java | 25 ++++++++
4 files changed, 157 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java b/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
index eed5ffa..31b555d 100644
--- a/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
+++ b/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -141,4 +141,29 @@
public AjaxResult getByCustomerName(String customerName) {
return AjaxResult.success(shippingInfoService.getShippingInfoByCustomerName(customerName));
}
+
+ /**
+ * 涓�閿彂璐� - 鑷姩瀹℃壒閫氳繃骞跺嚭搴�
+ */
+ @PostMapping("/oneClickShipping")
+ @ApiOperation("涓�閿彂璐�")
+ @Transactional(rollbackFor = Exception.class)
+ @Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.INSERT)
+ public AjaxResult oneClickShipping(@RequestBody ShippingInfoDto req) throws IOException {
+ return shippingInfoService.oneClickShipping(req) ? AjaxResult.success("鍙戣揣鎴愬姛") : AjaxResult.error("鍙戣揣澶辫触");
+ }
+
+ /**
+ * 鎵归噺涓�閿彂璐� - 灏嗛攢鍞彴璐︿笅鎵�鏈夋湭鍙戣揣鐨勪骇鍝佸叏閮ㄥ彂璐�
+ */
+ @PostMapping("/batchOneClickShipping")
+ @ApiOperation("鎵归噺涓�閿彂璐�")
+ @Transactional(rollbackFor = Exception.class)
+ @Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.INSERT)
+ public AjaxResult batchOneClickShipping(@RequestBody ShippingInfoDto req) throws IOException {
+ if (req.getSalesLedgerId() == null) {
+ return AjaxResult.error("閿�鍞彴璐D涓嶈兘涓虹┖");
+ }
+ return shippingInfoService.batchOneClickShipping(req.getSalesLedgerId(), req) ? AjaxResult.success("鎵归噺鍙戣揣鎴愬姛") : AjaxResult.error("鎵归噺鍙戣揣澶辫触");
+ }
}
diff --git a/src/main/java/com/ruoyi/sales/service/ShippingInfoService.java b/src/main/java/com/ruoyi/sales/service/ShippingInfoService.java
index 2aa1a13..b032b0a 100644
--- a/src/main/java/com/ruoyi/sales/service/ShippingInfoService.java
+++ b/src/main/java/com/ruoyi/sales/service/ShippingInfoService.java
@@ -26,4 +26,19 @@
List<SalesLedgerProductDto> getReturnManagementDtoById( Long shippingId);
List<ShippingInfo> getShippingInfoByCustomerName(String customerName);
+
+ /**
+ * 涓�閿彂璐� - 鑷姩瀹℃壒閫氳繃骞跺嚭搴�
+ * @param req 鍙戣揣淇℃伅
+ * @return 鏄惁鎴愬姛
+ */
+ boolean oneClickShipping(ShippingInfoDto req) throws IOException;
+
+ /**
+ * 鎵归噺涓�閿彂璐� - 灏嗛攢鍞彴璐︿笅鎵�鏈夋湭鍙戣揣鐨勪骇鍝佸叏閮ㄥ彂璐�
+ * @param salesLedgerId 閿�鍞彴璐D
+ * @param req 鍙戣揣淇℃伅锛堝彂璐х被鍨嬨�佹棩鏈熺瓑锛�
+ * @return 鏄惁鎴愬姛
+ */
+ boolean batchOneClickShipping(Long salesLedgerId, ShippingInfoDto req) throws IOException;
}
diff --git a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
index c9651a7..f2b9555 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -21,8 +21,10 @@
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -119,4 +121,118 @@
public List<ShippingInfo> getShippingInfoByCustomerName(String customerName) {
return shippingInfoMapper.getShippingInfoByCustomerName(customerName);
}
+
+ /**
+ * 涓�閿彂璐� - 鑷姩瀹℃壒閫氳繃骞跺嚭搴�
+ * 涓嶅垱寤哄鎵规祦绋嬶紝鐩存帴鎵e噺搴撳瓨
+ */
+ @Override
+ @Transactional
+ public boolean oneClickShipping(ShippingInfoDto req) throws IOException {
+ // 鑾峰彇閿�鍞彴璐︿骇鍝佷俊鎭�
+ SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(req.getSalesLedgerProductId());
+ if (salesLedgerProduct == null) {
+ throw new RuntimeException("閿�鍞骇鍝佷笉瀛樺湪");
+ }
+
+ // 鐢熸垚鍙戣揣鍗曞彿
+ String shippingNo = com.ruoyi.common.utils.OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH", "shipping_no");
+
+ // 鍒涘缓鍙戣揣璁板綍锛岀姸鎬佺洿鎺ヤ负"宸插彂璐�"
+ ShippingInfo shippingInfo = new ShippingInfo();
+ shippingInfo.setShippingNo(shippingNo);
+ shippingInfo.setSalesLedgerId(req.getSalesLedgerId());
+ shippingInfo.setSalesLedgerProductId(req.getSalesLedgerProductId());
+ shippingInfo.setType(req.getType());
+ shippingInfo.setShippingDate(req.getShippingDate());
+ shippingInfo.setShippingCarNumber(req.getShippingCarNumber());
+ shippingInfo.setExpressCompany(req.getExpressCompany());
+ shippingInfo.setExpressNumber(req.getExpressNumber());
+ shippingInfo.setStatus("宸插彂璐�");
+ boolean save = this.save(shippingInfo);
+
+ if (save) {
+ // 鐩存帴鎵e噺搴撳瓨
+ stockUtils.substractStock(
+ salesLedgerProduct.getProductModelId(),
+ salesLedgerProduct.getQuantity(),
+ StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(),
+ shippingInfo.getId()
+ );
+
+ // 杩佺Щ闄勪欢
+ if (CollectionUtils.isNotEmpty(req.getTempFileIds())) {
+ tempFileService.migrateTempFilesToFormal(shippingInfo.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue());
+ }
+ }
+
+ return save;
+ }
+
+ /**
+ * 鎵归噺涓�閿彂璐� - 灏嗛攢鍞彴璐︿笅鎵�鏈夋湭鍙戣揣鐨勪骇鍝佸叏閮ㄥ彂璐�
+ */
+ @Override
+ @Transactional
+ public boolean batchOneClickShipping(Long salesLedgerId, ShippingInfoDto req) throws IOException {
+ // 鏌ヨ璇ラ攢鍞彴璐︿笅鎵�鏈変骇鍝�
+ List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(
+ new LambdaQueryWrapper<SalesLedgerProduct>()
+ .eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerId)
+ .eq(SalesLedgerProduct::getType, 1) // 閿�鍞被鍨�
+ );
+
+ if (CollectionUtils.isEmpty(products)) {
+ throw new RuntimeException("璇ラ攢鍞彴璐︿笅娌℃湁浜у搧");
+ }
+
+ // 杩囨护鍑烘湭鍙戣揣鐨勪骇鍝侊紙娌℃湁鍙戣揣璁板綍鎴栧彂璐х姸鎬佷笉鏄�"宸插彂璐�"锛�
+ List<SalesLedgerProduct> unshippedProducts = new ArrayList<>();
+ for (SalesLedgerProduct product : products) {
+ ShippingInfo existingShipping = shippingInfoMapper.selectOne(
+ new LambdaQueryWrapper<ShippingInfo>()
+ .eq(ShippingInfo::getSalesLedgerProductId, product.getId())
+ .eq(ShippingInfo::getStatus, "宸插彂璐�")
+ .last("limit 1")
+ );
+ if (existingShipping == null) {
+ unshippedProducts.add(product);
+ }
+ }
+
+ if (CollectionUtils.isEmpty(unshippedProducts)) {
+ throw new RuntimeException("璇ラ攢鍞彴璐︿笅鎵�鏈変骇鍝佸凡鍙戣揣");
+ }
+
+ // 涓烘瘡涓湭鍙戣揣鐨勪骇鍝佸垱寤哄彂璐ц褰�
+ for (SalesLedgerProduct product : unshippedProducts) {
+ // 鐢熸垚鍙戣揣鍗曞彿
+ String shippingNo = com.ruoyi.common.utils.OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH", "shipping_no");
+
+ // 鍒涘缓鍙戣揣璁板綍
+ ShippingInfo shippingInfo = new ShippingInfo();
+ shippingInfo.setShippingNo(shippingNo);
+ shippingInfo.setSalesLedgerId(salesLedgerId);
+ shippingInfo.setSalesLedgerProductId(product.getId());
+ shippingInfo.setType(req.getType());
+ shippingInfo.setShippingDate(req.getShippingDate());
+ shippingInfo.setShippingCarNumber(req.getShippingCarNumber());
+ shippingInfo.setExpressCompany(req.getExpressCompany());
+ shippingInfo.setExpressNumber(req.getExpressNumber());
+ shippingInfo.setStatus("宸插彂璐�");
+
+ boolean save = this.save(shippingInfo);
+ if (save) {
+ // 鎵e噺搴撳瓨
+ stockUtils.substractStock(
+ product.getProductModelId(),
+ product.getQuantity(),
+ StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(),
+ shippingInfo.getId()
+ );
+ }
+ }
+
+ return true;
+ }
}
diff --git a/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml b/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml
index 2874f48..4eb39aa 100644
--- a/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml
+++ b/src/main/resources/mapper/sales/InvoiceLedgerMapper.xml
@@ -123,7 +123,7 @@
T1.customer_name LIKE CONCAT ('%',#{invoiceLedgerDto.searchText},'%')
</if>
</where>
- GROUP BY T1.customer_name
+ GROUP BY T1.customer_id, T1.customer_name
</select>
<select id="invoiceLedgerProductInfo" resultType="com.ruoyi.sales.dto.InvoiceRegistrationProductDto">
--
Gitblit v1.9.3