fix: 更新库存查询SQL使用正确的计算公式 qty-order_lock-lock_qty
This commit is contained in:
parent
5bbb39c868
commit
1e67845970
@ -159,7 +159,7 @@ public class ThirdPartyDbService {
|
||||
|
||||
/**
|
||||
* 查询商品库存信息
|
||||
* @param barcode 商品条码
|
||||
* @param barcode 商品条码 (sku_id)
|
||||
* @return 库存数量,如果未找到返回0
|
||||
*/
|
||||
public Map<String, Object> checkInventory(String barcode) {
|
||||
@ -180,34 +180,35 @@ public class ThirdPartyDbService {
|
||||
conn = getConnection(config);
|
||||
|
||||
// 查询聚水潭库存信息表
|
||||
// 条件:wms_co_id='14138566',根据商品条码查询
|
||||
String sql = "SELECT sku_id, i_id, name, qty, lock_qty, qty - ISNULL(lock_qty, 0) AS available_qty " +
|
||||
"FROM jst_inventoryInfo " +
|
||||
"WHERE wms_co_id = '14138566' AND (sku_id = ? OR i_id = ?)";
|
||||
// 可用库存 = qty - order_lock - lock_qty
|
||||
// 条件:wms_co_id='14138566',根据sku_id查询
|
||||
String sql = "SELECT sku_id, qty, order_lock, lock_qty, " +
|
||||
"qty - ISNULL(order_lock, 0) - ISNULL(lock_qty, 0) AS available_qty " +
|
||||
"FROM jst_inventoryInfo WITH(NOLOCK) " +
|
||||
"WHERE wms_co_id = '14138566' AND sku_id = ?";
|
||||
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setString(1, barcode);
|
||||
pstmt.setString(2, barcode);
|
||||
|
||||
rs = pstmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int availableQty = rs.getInt("available_qty");
|
||||
result.put("found", true);
|
||||
result.put("skuId", rs.getString("sku_id"));
|
||||
result.put("itemId", rs.getString("i_id"));
|
||||
result.put("name", rs.getString("name"));
|
||||
result.put("quantity", rs.getInt("qty"));
|
||||
result.put("orderLock", rs.getInt("order_lock"));
|
||||
result.put("lockQty", rs.getInt("lock_qty"));
|
||||
result.put("availableQty", rs.getInt("available_qty"));
|
||||
result.put("availableQty", availableQty);
|
||||
|
||||
log.info("查询到商品库存: barcode={}, name={}, qty={}, available={}",
|
||||
barcode, rs.getString("name"), rs.getInt("qty"), rs.getInt("available_qty"));
|
||||
log.info("查询到商品库存: sku_id={}, qty={}, order_lock={}, lock_qty={}, available={}",
|
||||
barcode, rs.getInt("qty"), rs.getInt("order_lock"), rs.getInt("lock_qty"), availableQty);
|
||||
} else {
|
||||
log.info("未找到商品库存信息: barcode={}", barcode);
|
||||
log.info("未找到商品库存信息: sku_id={}", barcode);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.error("查询库存失败: barcode={}, error={}", barcode, e.getMessage());
|
||||
log.error("查询库存失败: sku_id={}, error={}", barcode, e.getMessage());
|
||||
throw new BusinessException("查询库存失败: " + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user