新增库存货位冻结/解冻功能,包含前端按钮和后端逻辑

实现遍历选中的库存ID,找到对应的货位。
确定操作方向(冻结/解冻)。
查找同组 (groupCodingNo) 的所有关联货位。
遍历所有涉及的货位时,先检查该货位是否有库存。
如果有库存:执行冻结/解冻操作(锁定货位 + 更新库存状态 + 记录日志)。
如果没有库存:跳过该货位,不执行任何操作(不锁货位,也不处理库存)。

修改了库存明细中库存数量和出库数量的小数显示为向下取整显示整数
This commit is contained in:
escapemoon
2025-12-19 09:10:31 +08:00
parent 032efd9aae
commit 806f868f57
6 changed files with 165 additions and 12 deletions

View File

@@ -96,6 +96,17 @@ public class BasStockController extends BaseController
return toAjax(basStockService.deleteBasStockByStockIds(stockIds));
}
/**
* 冻结/解冻库存货位
*/
@PreAuthorize("@ss.hasPermi('stock:management:edit')")
@Log(title = "库存信息", businessType = BusinessType.UPDATE)
@PostMapping("/freeze")
public AjaxResult freeze(@RequestBody List<String> stockIds)
{
return toAjax(basStockService.freezeOrUnfreeze(stockIds));
}
/**
* 重置盘点记录
*/

View File

@@ -90,4 +90,10 @@ public interface IBasStockService
AjaxResult resetPdRecord();
/**
* 冻结/解冻库存货位
* @param stockIds 库存ID集合
* @return 结果
*/
public int freezeOrUnfreeze(List<String> stockIds);
}

View File

@@ -17,8 +17,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 库存信息Service业务层处理
@@ -224,4 +227,95 @@ public class BasStockServiceImpl implements IBasStockService
{
return basStockMapper.insertBasStock(basStock);
}
/**
* 冻结/解冻库存货位
* @param stockIds 库存ID集合
* @return 结果
*/
@Override
@Transactional
public int freezeOrUnfreeze(List<String> stockIds) {
int count = 0;
Set<String> processedCargoSpaceIds = new HashSet<>();
for (String stockId : stockIds) {
BasStock stock = basStockMapper.selectBasStockByStockId(stockId);
if (stock == null || stock.getCargoSpaceId() == null) {
continue;
}
String cargoSpaceId = stock.getCargoSpaceId();
if (processedCargoSpaceIds.contains(cargoSpaceId)) {
continue;
}
BasCargoSpace cargoSpace = basCargoSpaceService.selectBasCargoSpaceByCargoSpaceId(cargoSpaceId);
if (cargoSpace == null) {
continue;
}
// 确定操作方向:基于当前货位的锁定状态
String currentLockStatus = cargoSpace.getLocked();
// If Y (Locked) -> N (Open), If N (Open) -> Y (Locked)
boolean isFreezing = !"Y".equals(currentLockStatus); // 如果不是Y,那就是要冻结
String newLockStatus = isFreezing ? "Y" : "N";
String newStockStatus = isFreezing ? "2" : "1"; // 2:冻结, 1:正常
// 获取所有需要处理的货位(包括联查的)
List<BasCargoSpace> spacesToProcess = new ArrayList<>();
spacesToProcess.add(cargoSpace);
String groupCodingNo = cargoSpace.getGroupCodingNo();
if (groupCodingNo != null && !groupCodingNo.isEmpty()) {
List<BasCargoSpace> groupSpaces = basCargoSpaceService.selectBasCargoSpaceListByGroupCodingNo(groupCodingNo);
for (BasCargoSpace space : groupSpaces) {
if (!space.getCargoSpaceId().equals(cargoSpaceId)) {
spacesToProcess.add(space);
}
}
}
for (BasCargoSpace space : spacesToProcess) {
if (processedCargoSpaceIds.contains(space.getCargoSpaceId())) {
continue;
}
// 检查该货位是否有库存
BasStock queryStock = new BasStock();
queryStock.setCargoSpaceId(space.getCargoSpaceId());
List<BasStock> stockList = basStockMapper.selectBasStockList(queryStock);
// 如果没有库存,则不进行冻结/解冻操作(既不锁货位,也不处理库存)
if (stockList == null || stockList.isEmpty()) {
continue;
}
// 1. 更新货位锁定状态
space.setLocked(newLockStatus);
basCargoSpaceService.updateBasCargoSpace(space);
processedCargoSpaceIds.add(space.getCargoSpaceId());
count++;
// 2. 处理该货位上的库存
for (BasStock oldStock : stockList) {
// 构造 newStock 用于传给 insertFreezeRecord
BasStock newStock = new BasStock();
// 复制必要属性
newStock.setStockId(oldStock.getStockId());
newStock.setCargoSpaceId(oldStock.getCargoSpaceId());
newStock.setTrayCode(oldStock.getTrayCode());
newStock.setWarehouseId(oldStock.getWarehouseId());
newStock.setProductId(oldStock.getProductId());
newStock.setProductName(oldStock.getProductName());
// 设置新状态
newStock.setStockStatus(newStockStatus);
// 调用用户提供的记录方法 (该方法会更新库存状态并插入记录)
insertFreezeRecord(oldStock, newStock);
}
}
}
return count;
}
}