From 8c65f898ed6e5b0c7a94c792c4562f6ec831dccd Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期六, 07 十一月 2026 08:50:53 +0800
Subject: [PATCH] feat: 完善质检、生产、销售、财务与人事模块并接入审批流程
---
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/task/MesWmStockTakingTaskResultServiceImpl.java | 79 ++++++++++++++++++++++++++++++++++-----
1 files changed, 69 insertions(+), 10 deletions(-)
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/task/MesWmStockTakingTaskResultServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/task/MesWmStockTakingTaskResultServiceImpl.java
index f7c8664..aad2c63 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/task/MesWmStockTakingTaskResultServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/task/MesWmStockTakingTaskResultServiceImpl.java
@@ -1,13 +1,17 @@
package cn.iocoder.yudao.module.mes.service.wm.stocktaking.task;
import cn.hutool.core.util.ObjUtil;
+import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.wm.stocktaking.task.vo.result.MesWmStockTakingTaskResultPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.stocktaking.task.vo.result.MesWmStockTakingTaskResultSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.stocktaking.task.MesWmStockTakingTaskLineDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.stocktaking.task.MesWmStockTakingTaskResultDO;
+import cn.iocoder.yudao.module.mes.dal.dataobject.wm.batch.MesWmBatchDO;
import cn.iocoder.yudao.module.mes.dal.mysql.wm.stocktaking.task.MesWmStockTakingTaskResultMapper;
+import cn.iocoder.yudao.module.mes.service.wm.batch.MesWmBatchService;
+import cn.iocoder.yudao.module.mes.service.mdm.MesMdmItemService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -15,10 +19,14 @@
import java.math.BigDecimal;
import java.util.List;
+import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_STOCK_TAKING_TASK_LINE_ALREADY_TAKEN;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_STOCK_TAKING_TASK_RESULT_NOT_EXISTS;
+import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_STOCK_TAKING_TASK_RESULT_LINE_INVALID;
+import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_STOCK_TAKING_TASK_RESULT_DUPLICATE;
+import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_TRANSACTION_BATCH_NOT_EXISTS;
+import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_TRANSACTION_BATCH_REQUIRED;
/**
* MES 鐩樼偣缁撴灉 Service 瀹炵幇绫�
@@ -36,6 +44,10 @@
private MesWmStockTakingTaskLineService stockTakingTaskLineService;
@Resource
private MesWmStockTakingTaskService stockTakingTaskService;
+ @Resource
+ private MesWmBatchService batchService;
+ @Resource
+ private MesMdmItemService mdmItemService;
@Override
public PageResult<MesWmStockTakingTaskResultDO> getStockTakingTaskResultPage(
@@ -58,10 +70,17 @@
Long lineId = createReqVO.getLineId();
MesWmStockTakingTaskLineDO existingLine = null;
if (lineId == null) {
+ resolveBatch(createReqVO);
// 2.1 鍩轰簬 taskId + itemId + areaId 鏌ヨ宸插瓨鍦ㄧ殑 line
existingLine = stockTakingTaskLineService.getStockTakingTaskLine(
- createReqVO.getTaskId(), createReqVO.getItemId(), createReqVO.getAreaId());
+ createReqVO.getTaskId(), createReqVO.getItemId(), createReqVO.getWarehouseId(),
+ createReqVO.getLocationId(), createReqVO.getAreaId(), createReqVO.getBatchId());
if (existingLine != null) {
+ if ((createReqVO.getBatchId() != null && !Objects.equals(existingLine.getBatchId(), createReqVO.getBatchId()))
+ || (StrUtil.isNotBlank(createReqVO.getBatchCode())
+ && !Objects.equals(existingLine.getBatchCode(), createReqVO.getBatchCode()))) {
+ throw exception(WM_STOCK_TAKING_TASK_RESULT_LINE_INVALID);
+ }
lineId = existingLine.getId();
} else {
// 2.2 鍒涘缓鏂扮殑 line锛堟敞鎰忥細褰撶洏鐐圭粨鏋滄病鏈夊搴旂殑鐩樼偣娓呭崟琛屾椂锛屼細鑷姩鍒涘缓涓�涓柊鐨勭洏鐐逛换鍔¤锛�
@@ -71,16 +90,26 @@
// 2.3 濡傛灉浼犻�掍簡 lineId锛屼粠 line 涓幏鍙� quantity
existingLine = stockTakingTaskLineService.validateStockTakingTaskLineExists(lineId);
}
- if (existingLine != null
- && existingLine.getTakingQuantity() != null
- && existingLine.getTakingQuantity().compareTo(BigDecimal.ZERO) > 0) {
- throw exception(WM_STOCK_TAKING_TASK_LINE_ALREADY_TAKEN);
+ if (existingLine == null) {
+ existingLine = stockTakingTaskLineService.validateStockTakingTaskLineExists(lineId);
}
- BigDecimal quantity = existingLine != null ? existingLine.getQuantity() : BigDecimal.ZERO; // 璐﹂潰鏁伴噺
+ if (!ObjUtil.equal(existingLine.getTaskId(), createReqVO.getTaskId())
+ || createReqVO.getTakingQuantity() == null || createReqVO.getTakingQuantity().signum() < 0) {
+ throw exception(WM_STOCK_TAKING_TASK_RESULT_LINE_INVALID);
+ }
+ Long resolvedLineId = lineId;
+ if (stockTakingTaskResultMapper.selectListByTaskId(createReqVO.getTaskId()).stream()
+ .anyMatch(result -> ObjUtil.equal(result.getLineId(), resolvedLineId))) {
+ throw exception(WM_STOCK_TAKING_TASK_RESULT_DUPLICATE);
+ }
// 3. 鎻掑叆 result 璁板綍
MesWmStockTakingTaskResultDO result = BeanUtils.toBean(createReqVO, MesWmStockTakingTaskResultDO.class)
- .setLineId(lineId).setQuantity(ObjUtil.defaultIfNull(quantity, createReqVO.getTakingQuantity()));
+ .setLineId(lineId).setQuantity(existingLine.getQuantity())
+ .setMaterialStockId(existingLine.getMaterialStockId()).setItemId(existingLine.getItemId())
+ .setBatchId(existingLine.getBatchId()).setBatchCode(existingLine.getBatchCode())
+ .setWarehouseId(existingLine.getWarehouseId()).setLocationId(existingLine.getLocationId())
+ .setAreaId(existingLine.getAreaId());
stockTakingTaskResultMapper.insert(result);
// 4. 鏇存柊 line 鐨勭洏鐐规暟閲忓拰鐘舵��
@@ -91,14 +120,21 @@
@Override
@Transactional(rollbackFor = Exception.class)
public void updateStockTakingTaskResult(MesWmStockTakingTaskResultSaveReqVO updateReqVO) {
- updateReqVO.setLineId(null); // lineId 涓嶈兘淇敼锛岄伩鍏嶈鎿嶄綔
// 1.1 鏍¢獙璁板綍瀛樺湪
MesWmStockTakingTaskResultDO oldResult = validateStockTakingTaskResultExists(updateReqVO.getId());
// 1.2 鏍¢獙浠诲姟澶勪簬鐩樼偣涓姸鎬�
stockTakingTaskService.validateStockTakingTaskExistsAndApproving(oldResult.getTaskId());
+ if (updateReqVO.getTakingQuantity() == null || updateReqVO.getTakingQuantity().signum() < 0) {
+ throw exception(WM_STOCK_TAKING_TASK_RESULT_LINE_INVALID);
+ }
// 2. 鏇存柊 result 璁板綍
MesWmStockTakingTaskResultDO result = BeanUtils.toBean(updateReqVO, MesWmStockTakingTaskResultDO.class);
+ result.setTaskId(oldResult.getTaskId()).setLineId(oldResult.getLineId())
+ .setMaterialStockId(oldResult.getMaterialStockId()).setItemId(oldResult.getItemId())
+ .setBatchId(oldResult.getBatchId()).setBatchCode(oldResult.getBatchCode())
+ .setWarehouseId(oldResult.getWarehouseId()).setLocationId(oldResult.getLocationId())
+ .setAreaId(oldResult.getAreaId()).setQuantity(oldResult.getQuantity());
stockTakingTaskResultMapper.updateById(result);
// 3. 鍏宠仈鏇存柊 line 鐨勭洏鐐规暟閲忥紙瑕嗙洊寮忔洿鏂帮級
@@ -119,7 +155,30 @@
// 3. 鏇存柊瀵瑰簲 line 鐨勭洏鐐规暟閲忓拰鐘舵��
stockTakingTaskLineService.updateStockTakingTaskLineTakingQuantity(
- result.getLineId(), result.getTakingQuantity().negate());
+ result.getLineId(), BigDecimal.ZERO);
+ stockTakingTaskLineService.deleteAutoGeneratedLine(result.getLineId());
+ }
+
+ private void resolveBatch(MesWmStockTakingTaskResultSaveReqVO reqVO) {
+ MesWmBatchDO batch = null;
+ if (reqVO.getBatchId() != null) {
+ batch = batchService.getBatch(reqVO.getBatchId());
+ } else if (StrUtil.isNotBlank(reqVO.getBatchCode())) {
+ batch = batchService.getBatchByCode(reqVO.getBatchCode());
+ }
+ if (batch != null) {
+ if (!Objects.equals(batch.getItemId(), reqVO.getItemId())
+ || (StrUtil.isNotBlank(reqVO.getBatchCode())
+ && !Objects.equals(batch.getCode(), reqVO.getBatchCode()))) {
+ throw exception(WM_STOCK_TAKING_TASK_RESULT_LINE_INVALID);
+ }
+ reqVO.setBatchId(batch.getId());
+ reqVO.setBatchCode(batch.getCode());
+ } else if (reqVO.getBatchId() != null || StrUtil.isNotBlank(reqVO.getBatchCode())) {
+ throw exception(WM_TRANSACTION_BATCH_NOT_EXISTS);
+ } else if (Boolean.TRUE.equals(mdmItemService.validateItemExists(reqVO.getItemId()).getIsBatchManaged())) {
+ throw exception(WM_TRANSACTION_BATCH_REQUIRED);
+ }
}
@Override
--
Gitblit v1.9.3