From 0beb4e197c13ccce94a943e158993c503700f4da Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 20 八月 2026 17:57:23 +0800
Subject: [PATCH] feat(sales): 实现发货模块部分发货与批量发货功能
---
src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java | 109 +++++++++++++++++++++++++++---------------------------
1 files changed, 54 insertions(+), 55 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java b/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
index b07730d..6041f3d 100644
--- a/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
+++ b/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -1,27 +1,16 @@
package com.ruoyi.sales.controller;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.ruoyi.approve.mapper.ApproveProcessMapper;
-import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
-import com.ruoyi.approve.vo.ApproveProcessVO;
-import com.ruoyi.common.enums.FileNameType;
-import com.ruoyi.common.utils.OrderUtils;
-import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
-import com.ruoyi.other.service.impl.TempFileServiceImpl;
import com.ruoyi.sales.dto.ShippingInfoDto;
-import com.ruoyi.sales.mapper.ShipmentApprovalMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
-import com.ruoyi.sales.pojo.ShipmentApproval;
import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import com.ruoyi.sales.service.ISalesLedgerService;
@@ -29,15 +18,15 @@
import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.time.LocalDate;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
/**
* @author :yys
@@ -50,25 +39,21 @@
@Autowired
private ShippingInfoService shippingInfoService;
- @Autowired
- private ShipmentApprovalMapper shipmentApprovalMapper;
- @Autowired
- private ISalesLedgerProductService salesLedgerProductService;
-
- @Autowired
- private TempFileServiceImpl tempFileService;
@Autowired
private CommonFileServiceImpl commonFileService;
@Autowired
- private ApproveProcessServiceImpl approveProcessService;
+ private ISalesLedgerService salesLedgerService;
+
+ @Autowired
+ private ISalesLedgerProductService salesLedgerProductService;
@GetMapping("/listPage")
@ApiOperation("鍙戣揣淇℃伅鍒楄〃")
public AjaxResult listPage(Page page, ShippingInfo req) {
- IPage<ShippingInfo> listPage = shippingInfoService.listPage(page,req);
+ IPage<ShippingInfoDto> listPage = shippingInfoService.listPage(page,req);
return AjaxResult.success(listPage);
}
@@ -77,22 +62,44 @@
@Transactional(rollbackFor = Exception.class)
@Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.INSERT)
public AjaxResult add(@RequestBody ShippingInfoDto req) throws Exception {
- LoginUser loginUser = SecurityUtils.getLoginUser();
- String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH");
- // 鍙戣揣瀹℃壒
- ApproveProcessVO approveProcessVO = new ApproveProcessVO();
- approveProcessVO.setApproveType(7);
- approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId());
- approveProcessVO.setApproveReason(req.getType() + ":" +sh);
- approveProcessVO.setApproveUserIds(req.getApproveUserIds());
- approveProcessVO.setApproveUser(loginUser.getUserId());
- approveProcessVO.setApproveTime(LocalDate.now().toString());
- approveProcessService.addApprove(approveProcessVO);
- // 娣诲姞鍙戣揣娑堟伅
- req.setShippingNo(sh);
- req.setStatus("寰呭鏍�");
- boolean save = shippingInfoService.save(req);
- return save ? AjaxResult.success() : AjaxResult.error();
+ return shippingInfoService.addShipping(req) ? AjaxResult.success() : AjaxResult.error();
+ }
+
+ @PostMapping("/batchAdd")
+ @ApiOperation("鎵归噺鍙戣揣锛氬悓涓�瀹㈡埛澶氭潯璁㈠崟锛岄�愭潯鍒涘缓鍙戣揣鍗曞苟鍙戣捣瀹℃壒")
+ @Transactional(rollbackFor = Exception.class)
+ @Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.INSERT)
+ public AjaxResult batchAdd(@RequestBody List<ShippingInfoDto> reqs) throws Exception {
+ if (reqs == null || reqs.isEmpty()) {
+ return AjaxResult.error("璇烽�夋嫨瑕佸彂璐х殑浜у搧");
+ }
+ // 鏍¢獙鎵�鏈変骇鍝佽鎵�灞為攢鍞彴璐︿负鍚屼竴瀹㈡埛
+ List<Long> productIds = reqs.stream()
+ .map(ShippingInfoDto::getSalesLedgerProductId)
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+ List<SalesLedgerProduct> products = salesLedgerProductService.listByIds(productIds);
+ List<Long> ledgerIds = products.stream()
+ .map(SalesLedgerProduct::getSalesLedgerId)
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+ List<SalesLedger> ledgers = salesLedgerService.listByIds(ledgerIds);
+ long customerCount = ledgers.stream()
+ .map(SalesLedger::getCustomerName)
+ .filter(cn -> cn != null && !cn.trim().isEmpty())
+ .distinct()
+ .count();
+ if (customerCount > 1) {
+ return AjaxResult.error("鎵归噺鍙戣揣浠呮敮鎸佸悓涓�瀹㈡埛鐨勫鏉¤鍗�");
+ }
+ for (ShippingInfoDto req : reqs) {
+ if (!shippingInfoService.addShipping(req)) {
+ throw new RuntimeException("鎵归噺鍙戣揣澶辫触");
+ }
+ }
+ return AjaxResult.success();
}
@ApiOperation("鍙戣揣鎵e簱瀛�")
@@ -100,20 +107,7 @@
@Transactional(rollbackFor = Exception.class)
@Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.UPDATE)
public AjaxResult deductStock(@RequestBody ShippingInfoDto req) throws IOException {
- ShippingInfo byId = shippingInfoService.getById(req.getId());
- if (byId == null) {
- return AjaxResult.error("鍙戣揣淇℃伅涓嶅瓨鍦�");
- }
- byId.setExpressNumber(req.getExpressNumber());
- byId.setExpressCompany(req.getExpressCompany());
- byId.setStatus("宸插彂璐�");
- byId.setShippingCarNumber(req.getShippingCarNumber());
- boolean update = shippingInfoService.updateById(req);
- // 杩佺Щ鏂囦欢
- if(CollectionUtils.isNotEmpty(req.getTempFileIds())){
- tempFileService.migrateTempFilesToFormal(req.getId(), req.getTempFileIds(), FileNameType.SHIP.getValue());
- }
- return update ? AjaxResult.success() : AjaxResult.error();
+ return shippingInfoService.deductStock( req) ? AjaxResult.success() : AjaxResult.error();
}
@PostMapping("/update")
@@ -134,9 +128,8 @@
@Transactional(rollbackFor = Exception.class)
@Log(title = "鍙戣揣淇℃伅绠$悊", businessType = BusinessType.DELETE)
public AjaxResult delete(@RequestBody List<Long> ids) {
- commonFileService.deleteByBusinessIds(ids, FileNameType.SHIP.getValue());
- boolean delete = shippingInfoService.removeBatchByIds(ids);
- return delete ? AjaxResult.success("鍒犻櫎鎴愬姛") : AjaxResult.error("鍒犻櫎澶辫触");
+
+ return shippingInfoService.delete(ids) ? AjaxResult.success("鍒犻櫎鎴愬姛") : AjaxResult.error("鍒犻櫎澶辫触");
}
@Autowired
@@ -153,4 +146,10 @@
util.exportExcel(response, list, "鍙戣揣淇℃伅");
}
+
+ @GetMapping("/getByCustomerName")
+ @ApiOperation("閫氳繃瀹㈡埛鍚嶇О鏌ヨ")
+ public AjaxResult getByCustomerName(String customerName) {
+ return AjaxResult.success(shippingInfoService.getShippingInfoByCustomerName(customerName));
+ }
}
--
Gitblit v1.9.3