From fab7bd21ddc729ff1e288d1895a050f72f9cf26c Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Mon, 8 Jun 2026 22:39:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#13=20=E5=85=AC=E5=BC=80=E5=95=86?= =?UTF-8?q?=E5=93=81=20API=20=E8=A1=A5=E5=85=85=20code/barcode/batch.quant?= =?UTF-8?q?ity=EF=BC=8C=E6=8A=A5=E9=94=99=E5=8F=8D=E9=A6=88=E6=90=BA?= =?UTF-8?q?=E5=B8=A6=E5=95=86=E5=93=81=E5=92=8C=E9=97=A8=E5=BA=97=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- backend/internal/handler/error_report.go | 44 ++++++++++--------- backend/internal/handler/public.go | 3 ++ backend/internal/model/error_report.go | 5 ++- .../screens/public/public_product_screen.dart | 11 ++++- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/backend/internal/handler/error_report.go b/backend/internal/handler/error_report.go index 23e8027..e28c317 100644 --- a/backend/internal/handler/error_report.go +++ b/backend/internal/handler/error_report.go @@ -17,16 +17,17 @@ func NewErrorReportHandler(db *gorm.DB) *ErrorReportHandler { } type submitErrorRequest struct { - ErrorType string `json:"error_type" binding:"required"` - AppVersion string `json:"app_version"` - Platform string `json:"platform"` - Username string `json:"username"` - ShopID uint64 `json:"shop_id"` - ShopNo string `json:"shop_no"` - Role string `json:"role"` - ErrorMsg string `json:"error_msg" binding:"required"` - StackTrace string `json:"stack_trace"` - OccurredAt int64 `json:"occurred_at"` // Unix 毫秒 + ErrorType string `json:"error_type" binding:"required"` + AppVersion string `json:"app_version"` + Platform string `json:"platform"` + Username string `json:"username"` + ShopID uint64 `json:"shop_id"` + ShopNo string `json:"shop_no"` + Role string `json:"role"` + ProductInfo string `json:"product_info"` + ErrorMsg string `json:"error_msg" binding:"required"` + StackTrace string `json:"stack_trace"` + OccurredAt int64 `json:"occurred_at"` // Unix 毫秒 } // Submit POST /api/v1/public/errors @@ -49,17 +50,18 @@ func (h *ErrorReportHandler) Submit(c *gin.Context) { } report := model.ErrorReport{ - ErrorType: req.ErrorType, - AppVersion: req.AppVersion, - Platform: req.Platform, - Username: req.Username, - ShopID: req.ShopID, - ShopNo: req.ShopNo, - Role: req.Role, - ClientIP: c.ClientIP(), - ErrorMsg: req.ErrorMsg, - StackTrace: stack, - OccurredAt: occurredAt, + ErrorType: req.ErrorType, + AppVersion: req.AppVersion, + Platform: req.Platform, + Username: req.Username, + ShopID: req.ShopID, + ShopNo: req.ShopNo, + Role: req.Role, + ProductInfo: req.ProductInfo, + ClientIP: c.ClientIP(), + ErrorMsg: req.ErrorMsg, + StackTrace: stack, + OccurredAt: occurredAt, } if err := h.db.Create(&report).Error; err != nil { diff --git a/backend/internal/handler/public.go b/backend/internal/handler/public.go index 9abd79d..d2c6f78 100644 --- a/backend/internal/handler/public.go +++ b/backend/internal/handler/public.go @@ -72,6 +72,7 @@ func (h *PublicHandler) GetProduct(c *gin.Context) { "production_date": pdStr, "batch_no": inv.BatchNo, "in_stock_date": inv.CreatedAt.Format("2006-01-02"), + "quantity": inv.Quantity, } } @@ -100,6 +101,8 @@ func (h *PublicHandler) GetProduct(c *gin.Context) { "data": gin.H{ "id": product.ID, "name": product.Name, + "code": product.Code, + "barcode": product.Barcode, "series": product.Series, "spec": product.Spec, "brand": product.Brand, diff --git a/backend/internal/model/error_report.go b/backend/internal/model/error_report.go index e860328..4569cd4 100644 --- a/backend/internal/model/error_report.go +++ b/backend/internal/model/error_report.go @@ -12,8 +12,9 @@ type ErrorReport struct { Username string `gorm:"size:50;index" json:"username"` ShopID uint64 `gorm:"index" json:"shop_id"` ShopNo string `gorm:"size:50" json:"shop_no"` - Role string `gorm:"size:20" json:"role"` - ClientIP string `gorm:"size:60" json:"client_ip"` + Role string `gorm:"size:20" json:"role"` + ProductInfo string `gorm:"size:200" json:"product_info"` + ClientIP string `gorm:"size:60" json:"client_ip"` ErrorMsg string `gorm:"type:text;not null" json:"error_msg"` StackTrace string `gorm:"type:text" json:"stack_trace"` OccurredAt time.Time `json:"occurred_at"` diff --git a/client/lib/screens/public/public_product_screen.dart b/client/lib/screens/public/public_product_screen.dart index 0faa72d..b09ce59 100644 --- a/client/lib/screens/public/public_product_screen.dart +++ b/client/lib/screens/public/public_product_screen.dart @@ -70,13 +70,22 @@ class _PublicProductScreenState extends State { title: title, hint: hint, onSubmit: (msg) async { + final shopNo = (_data?['shop'] as Map?)?['code'] as String? ?? ''; + final productName = _data?['name'] as String? ?? ''; + final productCode = _data?['code'] as String? ?? ''; + final productInfo = [ + if (productName.isNotEmpty) productName, + if (productCode.isNotEmpty) productCode, + if (widget.publicId.isNotEmpty) widget.publicId, + ].join(' / '); await _dio.post( '${AppConfig.apiBaseUrl}/public/errors', data: { 'error_type': errorType, 'error_msg': msg, 'platform': 'web-scan', - 'shop_no': (_data?['shop'] as Map?)?['code'] as String? ?? '', + 'shop_no': shopNo, + if (productInfo.isNotEmpty) 'product_info': productInfo, }, ); },