fix(backend): 架构质量改进批次三 (#41-44)

- #41 CheckInventoryAvailability Scan 加错误检查,DB 故障不再误报库存不足
- #42 finance ListRecords 和 inventory Logs 补加 pageSize 上限(500)
- #43 ReconcileInventory 两条 Scan 加错误检查,DB 故障返回 500 而非误导性空结果
- #44 license Info 改用 CountDevices(licenseID) 统计当前 license 绑定数,修复跨 license 计数偏差

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-11 08:21:42 +08:00
parent 3ab78dbf7a
commit f928d5c6a3
6 changed files with 28 additions and 11 deletions
+7
View File
@@ -118,6 +118,13 @@ func (s *LicenseService) ShopInfo(shopID uint64) (*model.License, error) {
return &lic, nil
}
// CountDevices 返回指定 license 下已绑定设备数。
func (s *LicenseService) CountDevices(licenseID uint64) (int64, error) {
var count int64
err := s.db.Model(&model.LicenseDevice{}).Where("license_id = ?", licenseID).Count(&count).Error
return count, err
}
// ListDevices 列出许可证下所有已绑定设备。
func (s *LicenseService) ListDevices(shopID uint64) ([]model.LicenseDevice, error) {
var devs []model.LicenseDevice
+4 -2
View File
@@ -305,11 +305,13 @@ func (s *StockService) CheckInventoryAvailability(shopID, warehouseID uint64, it
Total float64
}
var sums []inventorySum
s.db.Model(&model.Inventory{}).
if err := s.db.Model(&model.Inventory{}).
Select("product_id, COALESCE(SUM(quantity), 0) AS total").
Where("shop_id = ? AND warehouse_id = ? AND product_id IN ? AND deleted_at IS NULL",
shopID, warehouseID, productIDs).
Group("product_id").Scan(&sums)
Group("product_id").Scan(&sums).Error; err != nil {
return err
}
sumMap := make(map[uint64]float64, len(sums))
for _, s := range sums {