From f3b1ba6c5d2f8f479b41e4e36093322d383b4e9c Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期三, 20 九月 2023 19:32:10 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- constvar/const.go | 7 + models/operation_type.go | 5 + controllers/operation_type.go | 8 controllers/operation.go | 133 ++++++++++++++++++++++++-- models/operation.go | 28 +++-- request/operation.go | 50 +++++---- models/operation_details.go | 12 +- router/router.go | 3 8 files changed, 185 insertions(+), 61 deletions(-) diff --git a/constvar/const.go b/constvar/const.go index 009b7e9..85b175d 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -173,3 +173,10 @@ OperationStatus_Ready //灏辩华 OperationStatus_Finish //瀹屾垚 ) + +type PostType int + +const ( + PostType_Soon PostType = iota + 1 //灏藉揩 + PostType_AfterReady //褰撴墍鏈変骇鍝佸氨缁椂 +) diff --git a/controllers/operation.go b/controllers/operation.go index 581f085..06b3c19 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -6,6 +6,7 @@ "github.com/spf13/cast" "gorm.io/gorm" "strconv" + "wms/constvar" "wms/extend/code" "wms/extend/util" "wms/models" @@ -39,12 +40,54 @@ util.ResponseFormat(c, code.RequestParamError, err.Error()) return } + if err := slf.FormatLocation(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + + params.Status = constvar.OperationStatus_Ready if err := models.NewOperationSearch().Create(¶ms); err != nil { logx.Errorf("Operation create err: %v", err) util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error()) return } util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛") +} + +func (slf OperationController) FormatLocation(params *models.Operation) error { + operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() + if err != nil { + return err + } + if operationType.BaseOperationType == constvar.BaseOperationTypeIncoming { + if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeVendor)).First(); err != nil { + return err + } else { + params.FromLocationId = location.Id + } + if params.ToLocationId == 0 { + return errors.New("璇烽�夋嫨鐩爣浣嶇疆") + } + } + if operationType.BaseOperationType == constvar.BaseOperationTypeOutgoing { + if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeCustomer)).First(); err != nil { + return err + } else { + params.ToLocationId = location.Id + } + if params.FromLocationId == 0 { + return errors.New("璇烽�夋嫨婧愪綅缃�") + } + } + if operationType.BaseOperationType == constvar.BaseOperationTypeInternal { + if params.ToLocationId == 0 { + return errors.New("璇烽�夋嫨鐩爣浣嶇疆") + } + if params.FromLocationId == 0 { + return errors.New("璇烽�夋嫨婧愪綅缃�") + } + } + return nil } func (slf OperationController) CheckParams(params models.Operation) error { @@ -54,14 +97,6 @@ if params.OperationTypeId == 0 { return errors.New("operationTypeId涓�0") - } - - if params.FromLocationId == 0 { - return errors.New("璇烽�夋嫨婧愪綅缃�") - } - - if params.ToLocationId == 0 { - return errors.New("璇烽�夋嫨鐩爣浣嶇疆") } if params.OperationDate == "" { @@ -74,16 +109,13 @@ //妫�鏌ユ槑缁嗛儴鍒� for _, v := range params.Details { - if v.ProductId == 0 { + if v.ProductId == "" { return errors.New("productID涓�0") } if v.ProductName == "" { return errors.New("浜у搧鍚嶇О寮傚父") } if v.Quantity.IsNegative() { - return errors.New("浜у搧鏁伴噺鍑洪敊") - } - if v.FinishQuantity.IsNegative() { return errors.New("浜у搧鏁伴噺鍑洪敊") } } @@ -151,11 +183,19 @@ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇細"+err.Error()) return } + if reqParams.Status != constvar.OperationStatus_Ready { + util.ResponseFormat(c, code.RequestParamError, "璇ュ叆搴撲俊鎭凡瀹屾垚锛屾棤娉曡繘琛屼慨鏀�") + return + } if err := structx.AssignTo(reqParams, ¶ms); err != nil { util.ResponseFormat(c, code.RequestParamError, "鏁版嵁杞崲閿欒"+err.Error()) return } if err := slf.CheckParams(params); err != nil { + util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + if err := slf.FormatLocation(¶ms); err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) return } @@ -190,7 +230,16 @@ return } if id == 0 { - util.ResponseFormat(c, code.RequestParamError, "绌虹殑璁板綍id") + util.ResponseFormat(c, code.RequestParamError, "id涓�0") + return + } + operation, err := models.NewOperationSearch().SetID(id).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏈壘鍒扮浉鍏冲嚭鍏ュ簱淇℃伅:"+err.Error()) + return + } + if operation.Status != constvar.OperationStatus_Ready { + util.ResponseFormat(c, code.RequestError, "璇ュ叆搴撲俊鎭棤娉曡繘琛屽垹闄�") return } if err := models.WithTransaction(func(tx *gorm.DB) error { @@ -207,3 +256,61 @@ } util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛") } + +// DeleteDevice +// +// @Tags 鍏ュ簱/鍑哄簱 +// @Summary 鏇存敼璁板綍鐘舵�� +// @Produce application/json +// @Param id path int true "id" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/operation/finish/{id} [put] +func (slf OperationController) Finish(c *gin.Context) { + id, err := strconv.Atoi(c.Param("id")) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "閿欒鐨刬d鍊�") + return + } + if id == 0 { + util.ResponseFormat(c, code.RequestParamError, "id涓�0") + return + } + operation, err := models.NewOperationSearch().SetID(id).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏈壘鍒扮浉鍏冲嚭鍏ュ簱淇℃伅:"+err.Error()) + return + } + if operation.Status != constvar.OperationStatus_Ready { + util.ResponseFormat(c, code.RequestError, "璇ュ嚭鍏ュ簱淇℃伅鏃犳硶瀹屾垚") + return + } + //operationType, err := models.NewOperationTypeSearch().SetID(uint(operation.OperationTypeId)).First() + //if err != nil { + // util.ResponseFormat(c, code.RequestError, err.Error()) + // return + //} + //if operationType.BaseOperationType == constvar.BaseOperationTypeIncoming { + // if location, err := models.NewLocationSearch().SetType(int(constvar.LocationTypeVendor)).First(); err != nil { + // return err + // } else { + // params.FromLocationId = location.Id + // } + // if params.ToLocationId == 0 { + // return errors.New("璇烽�夋嫨鐩爣浣嶇疆") + // } + //} + if err := models.WithTransaction(func(tx *gorm.DB) error { + + if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Update(&models.Operation{Status: constvar.OperationStatus_Finish}); err != nil { + return err + } + if err := models.NewMaterialSearch().Orm.Exec("update material INNER JOIN wms_operation_details on wms_operation_details.product_id=material.id INNER JOIN wms_operation on wms_operation.id=wms_operation_details.operation_id set material.amount=material.amount + wms_operation_details.quantity where wms_operation.id=?", id).Error; err != nil { + return err + } + return nil + }); err != nil { + util.ResponseFormat(c, code.RequestError, err.Error()) + return + } + util.ResponseFormat(c, code.Success, "鎿嶄綔鎴愬姛") +} diff --git a/controllers/operation_type.go b/controllers/operation_type.go index 03bf227..3d21412 100644 --- a/controllers/operation_type.go +++ b/controllers/operation_type.go @@ -17,7 +17,7 @@ type OperationTypeController struct{} // Add -// @Tags 浣滀笟绫诲瀷 +// @Tags 涓氬姟绫诲瀷 // @Summary 娣诲姞浣滀笟绫诲瀷 // @Produce application/json // @Param object body request.AddOperationType true "浣滀笟绫诲瀷淇℃伅" @@ -49,7 +49,7 @@ } // Update -// @Tags 浣滀笟绫诲瀷 +// @Tags 涓氬姟绫诲瀷 // @Summary 缂栬緫浣滀笟绫诲瀷 // @Produce application/json // @Param object body request.UpdateOperationType true "浣滀笟绫诲瀷淇℃伅" @@ -102,7 +102,7 @@ } // List -// @Tags 浣滀笟绫诲瀷 +// @Tags 涓氬姟绫诲瀷 // @Summary 鏌ヨ浣滀笟绫诲瀷鍒楄〃 // @Produce application/json // @Param object query request.GetOperationTypeList true "鏌ヨ鍙傛暟" @@ -124,7 +124,7 @@ } // Delete -// @Tags 浣滀笟绫诲瀷 +// @Tags 涓氬姟绫诲瀷 // @Summary 鍒犻櫎浣滀笟绫诲瀷 // @Produce application/json // @Param id path string true "浣滀笟绫诲瀷id" diff --git a/models/operation.go b/models/operation.go index 76b7797..6b31864 100644 --- a/models/operation.go +++ b/models/operation.go @@ -2,7 +2,6 @@ import ( "fmt" - "github.com/shopspring/decimal" "gorm.io/gorm" "wms/constvar" "wms/pkg/mysqlx" @@ -22,16 +21,19 @@ ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationId"` //鐩爣浣嶇疆 OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` - CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` - CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` - Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` - Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"` - TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"` - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О(kg)"` - Details []*OperationDetails `json:"details"` + 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"` + + //Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"` + //TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"` + //CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` + //CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` + //Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` } OperationSearch struct { @@ -73,10 +75,10 @@ return slf } -//func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch { -// slf.Keyword = keyword -// return slf -//} +func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch { + slf.Keyword = keyword + return slf +} func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch { slf.OperationTypeId = operationTypeId diff --git a/models/operation_details.go b/models/operation_details.go index 6792f45..7901215 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -12,12 +12,12 @@ OperationDetails struct { WmsModel - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - OperationId int `json:"OperationId" gorm:"type:int;not null;comment:鎿嶄綔璁板綍id"` //鎿嶄綔id - ProductId int `json:"productId" gorm:"type:int;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:鏁伴噺"` //鏁伴噺 - FinishQuantity decimal.Decimal `json:"finishQuantity" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //瀹屾垚鏁伴噺 + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + 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:鏁伴噺"` //鏁伴噺 + Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"` } OperationDetailsSearch struct { diff --git a/models/operation_type.go b/models/operation_type.go index 92c244c..aac39b3 100644 --- a/models/operation_type.go +++ b/models/operation_type.go @@ -88,6 +88,11 @@ return slf } +func (slf *OperationTypeSearch) SetBaseOperationType(baseOperationType constvar.BaseOperationType) *OperationTypeSearch { + slf.BaseOperationType = baseOperationType + return slf +} + func (slf *OperationTypeSearch) build() *gorm.DB { var db = slf.Orm.Model(&OperationType{}) diff --git a/request/operation.go b/request/operation.go index 3df3d69..44d5402 100644 --- a/request/operation.go +++ b/request/operation.go @@ -13,24 +13,26 @@ 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:瀹夋帓鏃ユ湡"` + OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` //瀹夋帓鏃ユ湡 Details []*OperationDetails `json:"details"` - CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` - CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` - Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` - ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` - ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` - Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"` - TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"` - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О(kg)"` + 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)-闈炲繀濉� + //CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` //鎵胯繍鍟咺D-闈炲繀濉� + //CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` //鎵胯繍鍟嗗悕绉�-闈炲繀濉� + //Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` //杩借釜鍙傝��-闈炲繀濉� } type OperationDetails struct { - ProductId int `json:"productId" gorm:"type:int;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:鏁伴噺"` //鏁伴噺 - FinishQuantity decimal.Decimal `json:"finishQuantity" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //瀹屾垚鏁伴噺 + ProductId int `json:"productId" gorm:"type:int;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:鏁伴噺"` //鏁伴噺 + Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"` } type OperationList struct { @@ -46,15 +48,15 @@ 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:瀹夋帓鏃ユ湡"` + OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"` //瀹夋帓鏃ユ湡 Details []*OperationDetails `json:"details"` - CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` - CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` - Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` - ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` - ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"` - Weight decimal.Decimal `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"` - TransferWeight decimal.Decimal `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"` - CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` - CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О(kg)"` + CarrierID int `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"` //鎵胯繍鍟咺D-闈炲繀濉� + CarrierName string `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"` //鎵胯繍鍟嗗悕绉�-闈炲繀濉� + Tracking string `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"` //杩借釜鍙傝��-闈炲繀濉� + ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"` //鑱旂郴浜篒D-闈炲繀濉� + ContacterName string `json:"contacterName" gorm:"type:varchar(63);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)-闈炲繀濉� + CompanyID int `json:"companyID" gorm:"type:int;comment:鍏徃ID"` //鍏徃ID-瀹㈡埛 + CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О"` //鍏徃鍚嶇О-瀹㈡埛鍚嶇О } diff --git a/router/router.go b/router/router.go index e727dce..084dc11 100644 --- a/router/router.go +++ b/router/router.go @@ -63,7 +63,7 @@ locationAPI.DELETE("deleteLocation/:id", locationController.DeleteLocation) //鍒犻櫎浣嶇疆 } - // 浣滀笟绫诲瀷 + // 涓氬姟绫诲瀷 operationTypeController := new(controllers.OperationTypeController) operationTypeAPI := r.Group(urlPrefix + "/operationType") { @@ -81,6 +81,7 @@ operationAPI.POST("operation", operationController.Add) operationAPI.PUT("operation/:id", operationController.Update) operationAPI.DELETE("operation/:id", operationController.Delete) + operationAPI.PUT("Finish/:id", operationController.Finish) } //浜у搧 -- Gitblit v1.8.0