From acaf0e69a594f36ef9be6749c2b8d66e4ef6123b Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期五, 29 五月 2026 15:54:33 +0800
Subject: [PATCH] feat: 发货审批根据合同号合并到第一条(未审批)的记录中
---
src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java | 144 ++++++++++++++++++++++++++++++++++++------------
1 files changed, 108 insertions(+), 36 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..30b8b94 100644
--- a/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
+++ b/src/main/java/com/ruoyi/sales/controller/ShippingInfoController.java
@@ -4,6 +4,7 @@
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.pojo.ApproveProcess;
import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
import com.ruoyi.approve.vo.ApproveProcessVO;
import com.ruoyi.common.enums.FileNameType;
@@ -16,6 +17,7 @@
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.other.service.impl.TempFileServiceImpl;
+import com.ruoyi.procurementrecord.utils.StockUtils;
import com.ruoyi.sales.dto.ShippingInfoDto;
import com.ruoyi.sales.mapper.ShipmentApprovalMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
@@ -50,25 +52,22 @@
@Autowired
private ShippingInfoService shippingInfoService;
- @Autowired
- private ShipmentApprovalMapper shipmentApprovalMapper;
- @Autowired
- private ISalesLedgerProductService salesLedgerProductService;
-
- @Autowired
- private TempFileServiceImpl tempFileService;
@Autowired
private CommonFileServiceImpl commonFileService;
@Autowired
private ApproveProcessServiceImpl approveProcessService;
+ @Autowired
+ private StockUtils stockUtils;
+ @Autowired
+ private ISalesLedgerService salesLedgerService;
@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);
}
@@ -78,17 +77,73 @@
@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);
- // 娣诲姞鍙戣揣娑堟伅
+
+ // 鏌ヨ閿�鍞崟鍙�
+ String salesContractNo = "";
+ if (req.getSalesLedgerId() != null) {
+ SalesLedger salesLedger = salesLedgerService.getById(req.getSalesLedgerId());
+ if (salesLedger != null) {
+ salesContractNo = salesLedger.getSalesContractNo();
+ }
+ }
+
+ String sh = OrderUtils.countTodayByCreateTime(shippingInfoMapper, "SH", "shipping_no");
+
+ // 鏌ヨ璇ラ攢鍞悎鍚屼笅鏄惁鏈�"寰呭鏍�"鐨勫彂璐ц褰曪紝鐢ㄤ簬鍚堝苟瀹℃壒锛堥渶瀹℃壒浜虹浉鍚岋級
+ boolean shouldMergeApproval = false;
+ ApproveProcess existingApprove = null;
+ List<ShippingInfo> pendingShippings = shippingInfoMapper.selectList(
+ new LambdaQueryWrapper<ShippingInfo>()
+ .eq(ShippingInfo::getSalesLedgerId, req.getSalesLedgerId())
+ .eq(ShippingInfo::getStatus, "寰呭鏍�")
+ );
+ if (!CollectionUtils.isEmpty(pendingShippings) && salesContractNo != null && !salesContractNo.isEmpty()) {
+ // 鎵惧埌瀵瑰簲鐨勫鎵规祦绋嬶紙閫氳繃閿�鍞崟鍙峰尮閰嶏紝涓斿鎵逛汉鐩稿悓锛�
+ existingApprove = approveProcessService.getOne(
+ new LambdaQueryWrapper<ApproveProcess>()
+ .like(ApproveProcess::getApproveReason, "閿�鍞崟鍙�:" + salesContractNo)
+ .eq(ApproveProcess::getApproveType, 7) // 鍙戣揣瀹℃壒绫诲瀷
+ .eq(ApproveProcess::getApproveStatus, 0) // 寰呭鏍哥姸鎬�
+ .eq(ApproveProcess::getApproveUser, loginUser.getUserId()) // 瀹℃壒浜虹浉鍚�
+ .orderByDesc(ApproveProcess::getCreateTime)
+ .last("limit 1")
+ );
+ if (existingApprove != null) {
+ shouldMergeApproval = true;
+ }
+ }
+
+ // 鐢熸垚褰撳墠鍙戣揣淇℃伅鐨勬弿杩�
+ StringBuilder currentShippingDesc = new StringBuilder();
+ currentShippingDesc.append("鍙戣揣鍗曞彿:").append(sh);
+ if (salesContractNo != null && !salesContractNo.isEmpty()) {
+ currentShippingDesc.append("\n閿�鍞崟鍙�:").append(salesContractNo);
+ }
+ currentShippingDesc.append("\n").append(req.getType());
+ if ("璐ц溅".equals(req.getType()) && req.getShippingCarNumber() != null && !req.getShippingCarNumber().isEmpty()) {
+ currentShippingDesc.append(":").append(req.getShippingCarNumber());
+ } else if ("蹇��".equals(req.getType()) && req.getExpressCompany() != null && !req.getExpressCompany().isEmpty()) {
+ currentShippingDesc.append(":").append(req.getExpressCompany());
+ }
+
+ if (shouldMergeApproval && existingApprove != null) {
+ // 鍚堝苟瀹℃壒锛氬皢琚悎骞剁殑鍙戣揣鍗曞彿娣诲姞鍒板鎵瑰師鍥犱腑
+ String updatedReason = existingApprove.getApproveReason() + "\n\n" + currentShippingDesc.toString();
+ existingApprove.setApproveReason(updatedReason);
+ approveProcessService.updateById(existingApprove);
+ } else {
+ // 鍒涘缓鏂扮殑瀹℃壒娴佺▼
+ ApproveProcessVO approveProcessVO = new ApproveProcessVO();
+ approveProcessVO.setApproveType(7);
+ approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId());
+ approveProcessVO.setApproveReason(currentShippingDesc.toString());
+ 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);
@@ -100,20 +155,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 +176,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 +194,35 @@
util.exportExcel(response, list, "鍙戣揣淇℃伅");
}
+
+ @GetMapping("/getByCustomerName")
+ @ApiOperation("閫氳繃瀹㈡埛鍚嶇О鏌ヨ")
+ 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("鎵归噺鍙戣揣澶辫触");
+ }
}
--
Gitblit v1.9.3