From 04e4ca1225be00732153bb73ce88ed04e7a01ea0 Mon Sep 17 00:00:00 2001 From: jh_peng Date: Tue, 29 Apr 2025 18:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=86=E6=9E=90=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=20=E6=8A=A5=E8=AD=A6=E8=AE=BE=E7=BD=AE=E7=AA=97?= =?UTF-8?q?=E5=8F=A3-=E6=8C=89=E6=B5=8B=E8=AF=95=E5=8E=82=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=E6=8A=A5=E8=AD=A6=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=AA=97=E5=8F=A3-=E6=8C=89=E4=BA=A7=E5=93=81=E5=9E=8B?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/warning.go | 8 ++++---- repository/test.data/warning.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/model/warning.go b/model/warning.go index 84d45d1..5120d59 100644 --- a/model/warning.go +++ b/model/warning.go @@ -6,8 +6,8 @@ import ( ) type Warning struct { - ID int64 `json:"id" gorm:"primaryKey"` - ProductionControl []ProductionControl `json:"production_control" gorm:"foreignKey:WarningID;references:ID"` + ID int64 `json:"id" gorm:"primaryKey"` + //ProductionControl []ProductionControl `json:"production_control" gorm:"foreignKey:WarningID;references:ID"` PassProbabilityDiff []PassProbabilityDiff `json:"pass_probability_diff" gorm:"foreignKey:WarningID;references:ID"` BinControl []BinControl `json:"bin_control" gorm:"foreignKey:WarningID;references:ID"` SelectionDiffControl []SelectionDiffControl `json:"selection_diff_control" gorm:"foreignKey:WarningID;references:ID"` @@ -26,8 +26,8 @@ type Warning struct { } type ProductionControl struct { - ID int64 `json:"id" gorm:"primaryKey"` - WarningID int64 `json:"warning_id"` + ID int64 `json:"id" gorm:"primaryKey"` + //WarningID int64 `json:"warning_id"` Factory string `json:"factory"` TestQuantityDiffH string `json:"test_quantity_diff_h"` // 测试数量差异上限 TestQuantityDiffL string `json:"test_quantity_diff_l"` // 测试数量差异下限 diff --git a/repository/test.data/warning.go b/repository/test.data/warning.go index 6080b55..bb55dd4 100644 --- a/repository/test.data/warning.go +++ b/repository/test.data/warning.go @@ -90,7 +90,7 @@ func ShowListWarning(offset, limit int, keyWord string) ([]*model.Warning, int64 func DeleteWarning(req *model.Warning) error { var warning *model.Warning - if errors.Is(global.PostGreSQL.Find(&warning, req.ID).Error, gorm.ErrRecordNotFound) { + if errors.Is(global.PostGreSQL.First(&warning, req.ID).Error, gorm.ErrRecordNotFound) { return errors.New("未找到需要删除的型号信息") } global.PostGreSQL.Delete(&warning) @@ -99,7 +99,7 @@ func DeleteWarning(req *model.Warning) error { func UpdateWarningFactory(req *model.ProductionControl) error { var warning *model.ProductionControl - if errors.Is(global.PostGreSQL.Where("factory = ?", req.Factory).Find(&warning).Error, gorm.ErrRecordNotFound) { + if errors.Is(global.PostGreSQL.Where("factory = ?", req.Factory).First(&warning).Error, gorm.ErrRecordNotFound) { global.PostGreSQL.Create(&model.ProductionControl{ Factory: req.Factory, TestQuantityDiffH: req.TestQuantityDiffH, @@ -108,7 +108,7 @@ func UpdateWarningFactory(req *model.ProductionControl) error { PassQuantityDiffL: req.PassQuantityDiffL, }) } else { - global.PostGreSQL.Model(&req).Updates(map[string]interface{}{ + global.PostGreSQL.Model(&warning).Updates(map[string]interface{}{ "test_quantity_diff_h": req.TestQuantityDiffH, "test_quantity_diff_l": req.TestQuantityDiffL, "pass_quantity_diff_h": req.PassQuantityDiffH, @@ -133,7 +133,7 @@ func ShowListWarningFactory(offset, limit int, keyWord string) ([]*model.Product func DeleteWarningFactory(req *model.ProductionControl) error { var warning *model.ProductionControl - if errors.Is(global.PostGreSQL.Find(&warning, req.ID).Error, gorm.ErrRecordNotFound) { + if errors.Is(global.PostGreSQL.First(&warning, req.ID).Error, gorm.ErrRecordNotFound) { return errors.New("未找到需要删除的测试厂信息") } global.PostGreSQL.Delete(&warning)