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

实现遍历选中的库存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;
}
}

View File

@@ -52,6 +52,15 @@ export function updateManagement(data) {
})
}
// 冻结/解冻库存
export function freezeStock(stockIds) {
return request({
url: '/stock/management/freeze',
method: 'post',
data: stockIds
})
}
// 删除库存信息
export function delManagement(stockId) {
return request({

View File

@@ -74,9 +74,13 @@
<el-table-column width="150" label="货位id" align="center" prop="cargoSpaceId" />
<el-table-column width="180" label="物料编码" align="center" prop="productId" />
<el-table-column width="180" label="物料名称" align="center" prop="productName" />
<el-table-column width="180" label="库存数量" align="center" prop="quantity" />
<el-table-column width="200" label="unitPrices" align="center" prop="spare5" />
<el-table-column width="180" label="units" align="center" prop="spare6" />
<el-table-column width="180" label="库存数量" align="center">
<template slot-scope="scope">
{{ scope.row.quantity != null ? Math.trunc(Number(scope.row.quantity)) : 0 }}
</template>
</el-table-column>
<!-- <el-table-column width="200" label="unitPrices" align="center" prop="spare5" />
<el-table-column width="180" label="units" align="center" prop="spare6" /> -->
<el-table-column label="库存状态" align="center" prop="stockStatus">
<template slot-scope="scope">
<dict-tag :options="dict.type.stock_status" :value="scope.row.stockStatus"/>
@@ -93,7 +97,11 @@
<!-- <el-table-column width="180" label="物料GUID" align="center" prop="productGuid" />-->
<el-table-column width="180" label="作业ID" align="center" prop="jobId" />
<el-table-column width="180" label="托盘条码" align="center" prop="trayCode" />
<el-table-column width="180" label="出库数量" align="center" prop="outQuantity" />
<el-table-column width="180" label="出库数量" align="center">
<template slot-scope="scope">
{{ scope.row.outQuantity != null ? Math.trunc(Number(scope.row.outQuantity)) : 0 }}
</template>
</el-table-column>
<el-table-column width="180" label="入库子单id" align="center" prop="stockinDetailId" />
<el-table-column width="180" label="入库主单" align="center" prop="stockinId" />
<el-table-column width="180" label="入库类型" align="center" prop="inType" >
@@ -102,7 +110,7 @@
</template>
</el-table-column>
<el-table-column width="180" label="合同号" align="center" prop="orderId" />
<!-- <el-table-column width="180" label="合同号" align="center" prop="orderId" /> -->
<!-- <el-table-column width="180" label="集合数据" align="center" prop="Rows" />-->
<!-- <el-table-column width="180" label="入库主题" align="center" prop="Title" />-->
<el-table-column width="180" label="首次入库时间" align="center" prop="inDate" />
@@ -170,7 +178,7 @@
<dict-tag :options="dict.type.cargo_space_lock_status" :value="scope.row.locked"/>
</template>
</el-table-column>
<el-table-column width="180" label="产品分类" align="center" prop="parentId" />
<!-- <el-table-column width="180" label="产品分类" align="center" prop="parentId" />
<el-table-column width="180" label="价格" align="center" prop="price" />
<el-table-column width="180" label="产品编码" align="center" prop="cargoNo" />
<el-table-column width="180" label="单位" align="center" prop="unit" />
@@ -178,7 +186,7 @@
<el-table-column width="180" label="单位名称" align="center" prop="spare1" />
<el-table-column width="180" label="url " align="center" prop="spare3" />
<el-table-column width="180" label="btnurl" align="center" prop="spare4" />
<el-table-column width="180" label="unitjb" align="center" prop="spare7" />
<el-table-column width="180" label="unitjb" align="center" prop="spare7" /> -->
<el-table-column width="180" label="备注" align="center" prop="remark" />
</el-table>

View File

@@ -67,6 +67,17 @@
v-hasPermi="['stock:management:remove']"
>删除 <!-- 删除 --></el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-lock"
size="mini"
:disabled="multiple"
@click="handleFreeze"
v-hasPermi="['stock:management:edit']"
>冻结/解冻</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
@@ -92,7 +103,11 @@
<el-table-column label="托盘" align="center" prop="trayCode"/>
<el-table-column label="物料编码" align="center" prop="productId"/>
<el-table-column label="物料名称" align="center" prop="productName" width="160" />
<el-table-column label="库存数量" align="center" prop="quantity" width="160" />
<el-table-column label="库存数量" align="center" width="160">
<template slot-scope="scope">
{{ scope.row.quantity != null ? Math.trunc(Number(scope.row.quantity)) : 0 }}
</template>
</el-table-column>
<el-table-column label="入库时间" align="center" prop="inDate" width="160" />
</el-table>
@@ -144,7 +159,7 @@
</el-form-item>
<el-form-item label="库存状态" prop="stockStatus"> <!-- 库存状态 -->
<el-select v-model="form.stockStatus" placeholder="请选择库存状态">
<el-select v-model="form.stockStatus" placeholder="请选择库存状态" style="width: 100%;">
<el-option
v-for="dict in dict.type.stock_status"
:key="dict.value"
@@ -155,7 +170,7 @@
</el-form-item>
<el-form-item label="库存数量" prop="quantity"> <!-- 库存数量 -->
<el-input v-model="form.quantity" placeholder="请输入库存数量" />
<el-input v-model.number="form.quantity" @blur="form.quantity = Math.trunc(form.quantity || 0)" placeholder="请输入库存数量" />
</el-form-item>
@@ -291,7 +306,7 @@
</template>
<script>
import {addManagement, delManagement, getManagement, stockManagementList, updateManagement} from "@/api/stock/management"
import {addManagement, delManagement, getManagement, stockManagementList, updateManagement, freezeStock} from "@/api/stock/management"
import {listWarehouse} from "@/api/bas/warehouse"
import {listBasProduct} from "@/api/bas/BasProduct"
import {listCargoSpace} from "@/api/bas/cargoSpace"
@@ -360,7 +375,7 @@ export default {
pdProductName: null,
pdBatchNo: null,
pdSerialNo: null,
cargoSpaceStockStatus:2,
cargoSpaceStockStatus: null,
productId:null,
productName:null
},
@@ -578,6 +593,16 @@ export default {
this.$modal.msgSuccess("删除成功") // 删除成功
}).catch(() => {})
},
/** 冻结/解冻按钮操作 */
handleFreeze(row) {
const stockIds = row.stockId ? [row.stockId] : this.ids;
this.$modal.confirm('是否确认冻结/解冻选中的库存货位?').then(function() {
return freezeStock(stockIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("操作成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('stock/management/export', {