From eae7648dfc2085a849401f9e49de184002f1cece Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期四, 21 九月 2023 17:46:31 +0800 Subject: [PATCH] 1.出入库一部分代码 --- controllers/operation.go | 18 +---- models/operation.go | 35 ++++++----- request/operation.go | 60 ++++++++++--------- models/operation_details.go | 4 router/router.go | 4 5 files changed, 58 insertions(+), 63 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index f340d6c..32d16bb 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -5,7 +5,6 @@ "fmt" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" - "github.com/spf13/cast" "gorm.io/gorm" "strconv" "wms/constvar" @@ -170,15 +169,9 @@ // @Summary 淇敼鍏ュ簱/鍑哄簱淇℃伅 // @Produce application/json // @Param object body request.UpdateOperation true "鍏ュ簱淇℃伅" -// @Param id path int true "鍏ュ簱淇℃伅id" // @Success 200 {object} util.Response "鎴愬姛" -// @Router /api-wms/v1/operation/operation/{id} [put] +// @Router /api-wms/v1/operation/update [post] func (slf OperationController) Update(c *gin.Context) { - id := cast.ToUint(c.Param("id")) - if id == 0 { - util.ResponseFormat(c, code.RequestParamError, "绌虹殑璁板綍id") - return - } var reqParams request.UpdateOperation var params models.Operation if err := c.BindJSON(&reqParams); err != nil { @@ -201,15 +194,14 @@ util.ResponseFormat(c, code.RequestParamError, err.Error()) return } - fmt.Printf("%+v\n", *reqParams.Details[0]) - fmt.Printf("%+v\n", *reqParams.Details[1]) - fmt.Println("===============================================") - fmt.Printf("%+v\n", *params.Details[0]) - fmt.Printf("%+v\n", *params.Details[1]) if err := models.WithTransaction(func(tx *gorm.DB) error { if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(params.Id).Delete(); err != nil { return err } + operationSearch := models.NewOperationSearch().SetOrm(tx) + if err := operationSearch.Orm.Model(¶ms).Association("Details").Replace(params.Details); err != nil { + return err + } if err := models.NewOperationSearch().SetOrm(tx).SetID(params.Id).Save(¶ms); err != nil { return err } diff --git a/models/operation.go b/models/operation.go index 60b8b5a..d1c7545 100644 --- a/models/operation.go +++ b/models/operation.go @@ -11,21 +11,22 @@ // Operation 鎿嶄綔琛� Operation struct { WmsModel - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - Number string `json:"number" gorm:"type:varchar(255)"` //鍗曞彿 - SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� - OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id - Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� - FromLocationID int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d - FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃� - ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id - ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆 - OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` - ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` - ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"` - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"` - Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + Number string `json:"number" gorm:"type:varchar(255)"` //鍗曞彿 + SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� + OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id + OperationTypeName string `json:"operationTypeName" gorm:"type:varchar(127);comment:浣滀笟绫诲瀷鍚嶇О"` //浣滀笟绫诲瀷鍚嶇О + Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� + FromLocationID int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d + FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃� + ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id + ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆 + OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` + ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` + ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` + CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"` + CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"` + Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` Details []*OperationDetails `json:"details" gorm:"foreignKey:OperationID;references:Id"` @@ -93,8 +94,8 @@ func (slf *OperationSearch) build() *gorm.DB { var db = slf.Orm.Model(&Operation{}) - if slf.ID != 0 { - db = db.Where("id = ?", slf.ID) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) } if slf.Order != "" { db = db.Order(slf.Order) diff --git a/models/operation_details.go b/models/operation_details.go index e79cbf8..18e8cfd 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -76,8 +76,8 @@ func (slf *OperationDetailsSearch) build() *gorm.DB { var db = slf.Orm.Model(&OperationDetails{}) - if slf.ID != 0 { - db = db.Where("id = ?", slf.ID) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) } if slf.Order != "" { diff --git a/request/operation.go b/request/operation.go index 2417a79..b3b0bc2 100644 --- a/request/operation.go +++ b/request/operation.go @@ -6,20 +6,21 @@ ) type AddOperation struct { - ID int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿 - SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� - OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id - Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� - FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d - ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id - OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` //瀹夋帓鏃ユ湡 - Details []*OperationDetails `json:"details"` - ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` //鑱旂郴浜篒D-闈炲繀濉� - ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` //鑱旂郴浜哄鍚�-闈炲繀濉� - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` //鍏徃ID-瀹㈡埛 - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О"` //鍏徃鍚嶇О-瀹㈡埛鍚嶇О - Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` //澶囨敞 + ID int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿 + SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� + OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id + OperationTypeName string `json:"operationTypeName" gorm:"type:varchar(127);comment:浣滀笟绫诲瀷鍚嶇О"` //浣滀笟绫诲瀷鍚嶇О + Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� + FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d + ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id + OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` //瀹夋帓鏃ユ湡 + Details []*OperationDetails `json:"details"` + ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` //鑱旂郴浜篒D-闈炲繀濉� + ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` //鑱旂郴浜哄鍚�-闈炲繀濉� + CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` //鍏徃ID-瀹㈡埛 + CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О"` //鍏徃鍚嶇О-瀹㈡埛鍚嶇О + Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` //澶囨敞 //Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"` //閲嶉噺(kg)-闈炲繀濉� //TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"` //鐗╂祦閲嶉噺(kg)-闈炲繀濉� @@ -32,7 +33,7 @@ OperationId int `json:"OperationId" gorm:"type:int;not null;comment:鎿嶄綔璁板綍id"` //鎿嶄綔id ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О - Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺 + Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺 Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"` } @@ -42,20 +43,21 @@ } type UpdateOperation struct { - ID int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿 - SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� - OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id - Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� - FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d - ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id - OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` //瀹夋帓鏃ユ湡 - Details []*OperationDetails `json:"details"` - ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` //鑱旂郴浜篒D-闈炲繀濉� - ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` //鑱旂郴浜哄鍚�-闈炲繀濉� - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` //鍏徃ID-瀹㈡埛 - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О"` //鍏徃鍚嶇О-瀹㈡埛鍚嶇О - Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` //澶囨敞 + ID int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿 + SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙� + OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id + OperationTypeName string `json:"operationTypeName" gorm:"type:varchar(127);comment:浣滀笟绫诲瀷鍚嶇О"` //浣滀笟绫诲瀷鍚嶇О + Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵�� + FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d + ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id + OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` //瀹夋帓鏃ユ湡 + Details []*OperationDetails `json:"details"` + ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` //鑱旂郴浜篒D-闈炲繀濉� + ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` //鑱旂郴浜哄鍚�-闈炲繀濉� + CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` //鍏徃ID-瀹㈡埛 + CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О"` //鍏徃鍚嶇О-瀹㈡埛鍚嶇О + Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"` //澶囨敞 //CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` //鎵胯繍鍟咺D-闈炲繀濉� //CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` //鎵胯繍鍟嗗悕绉�-闈炲繀濉� diff --git a/router/router.go b/router/router.go index 084dc11..ac257be 100644 --- a/router/router.go +++ b/router/router.go @@ -79,9 +79,9 @@ { operationAPI.GET("operation", operationController.List) operationAPI.POST("operation", operationController.Add) - operationAPI.PUT("operation/:id", operationController.Update) + operationAPI.POST("update", operationController.Update) operationAPI.DELETE("operation/:id", operationController.Delete) - operationAPI.PUT("Finish/:id", operationController.Finish) + operationAPI.PUT("finish/:id", operationController.Finish) } //浜у搧 -- Gitblit v1.8.0