From 0c65eeb1f1ac4b3dd14727f41a25582fc3ee701e Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期四, 21 九月 2023 09:52:21 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- controllers/operation.go | 64 +++++++++++---- docs/swagger.yaml | 24 ++---- request/operation.go | 25 +++-- docs/docs.go | 31 ++----- models/operation_details.go | 15 +++ docs/swagger.json | 29 ++----- router/router.go | 2 7 files changed, 100 insertions(+), 90 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index 06b3c19..97ba0fd 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -2,7 +2,9 @@ import ( "errors" + "fmt" "github.com/gin-gonic/gin" + "github.com/shopspring/decimal" "github.com/spf13/cast" "gorm.io/gorm" "strconv" @@ -110,7 +112,7 @@ //妫�鏌ユ槑缁嗛儴鍒� for _, v := range params.Details { if v.ProductId == "" { - return errors.New("productID涓�0") + return errors.New("productID涓虹┖") } if v.ProductName == "" { return errors.New("浜у搧鍚嶇О寮傚父") @@ -170,7 +172,7 @@ // @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/operation/{id} [post] func (slf OperationController) Update(c *gin.Context) { id := cast.ToUint(c.Param("id")) if id == 0 { @@ -199,6 +201,11 @@ 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 @@ -284,28 +291,47 @@ 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("璇烽�夋嫨鐩爣浣嶇疆") - // } - //} + operationType, err := models.NewOperationTypeSearch().SetID(uint(operation.OperationTypeId)).First() + if err != nil { + util.ResponseFormat(c, code.RequestError, err.Error()) + return + } 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 + if operationType.BaseOperationType == constvar.BaseOperationTypeIncoming { + 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 + } + } else if operationType.BaseOperationType == constvar.BaseOperationTypeOutgoing { + var listProdtId []string + var listProdt []*models.Material + mapProdt := make(map[string]decimal.Decimal) + listDetails, err := models.NewOperationDetailsSearch().SetOperationId(operation.Id).FindAll() + if err != nil { + return err + } + for _, v := range listDetails { + listProdtId = append(listProdtId, v.ProductId) + mapProdt[v.ProductId] = v.Quantity + } + if err := models.NewMaterialSearch().Orm.Where("id IN ?", listProdtId).Find(&listProdt).Error; err != nil { + return err + } + for _, v := range listProdt { + if value, ok := mapProdt[v.ID]; !ok { + return errors.New("浜у搧绉嶇被寮傚父") + } else { + if v.Amount.LessThan(value) { + return errors.New(fmt.Sprintf("浜у搧锛�%v,搴撳瓨锛�%v,鍑哄簱锛�%v,鏁伴噺涓嶅锛屾棤娉曞畬鎴愬嚭搴撴搷浣�", v.Name, v.Amount.String(), value.String())) + } + } + } + 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 { diff --git a/docs/docs.go b/docs/docs.go index e08cc06..bc7b478 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -565,7 +565,7 @@ } }, "/api-wms/v1/operation/operation/{id}": { - "put": { + "post": { "produces": [ "application/json" ], @@ -2114,6 +2114,7 @@ "type": "object", "properties": { "comment": { + "description": "澶囨敞", "type": "string" }, "companyID": { @@ -2319,9 +2320,13 @@ "request.OperationDetails": { "type": "object", "properties": { + "OperationId": { + "description": "鎿嶄綔id", + "type": "integer" + }, "productId": { "description": "浜у搧id", - "type": "integer" + "type": "string" }, "productName": { "description": "浜у搧鍚嶇О", @@ -2375,12 +2380,8 @@ "request.UpdateOperation": { "type": "object", "properties": { - "carrierID": { - "description": "鎵胯繍鍟咺D-闈炲繀濉�", - "type": "integer" - }, - "carrierName": { - "description": "鎵胯繍鍟嗗悕绉�-闈炲繀濉�", + "comment": { + "description": "澶囨敞", "type": "string" }, "companyID": { @@ -2439,18 +2440,6 @@ "toLocationId": { "description": "鐩爣浣嶇疆id", "type": "integer" - }, - "tracking": { - "description": "杩借釜鍙傝��-闈炲繀濉�", - "type": "string" - }, - "transferWeight": { - "description": "鐗╂祦閲嶉噺(kg)-闈炲繀濉�", - "type": "number" - }, - "weight": { - "description": "閲嶉噺(kg)-闈炲繀濉�", - "type": "number" } } }, @@ -2572,8 +2561,6 @@ Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index c925da1..281bd04 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -553,7 +553,7 @@ } }, "/api-wms/v1/operation/operation/{id}": { - "put": { + "post": { "produces": [ "application/json" ], @@ -2102,6 +2102,7 @@ "type": "object", "properties": { "comment": { + "description": "澶囨敞", "type": "string" }, "companyID": { @@ -2307,9 +2308,13 @@ "request.OperationDetails": { "type": "object", "properties": { + "OperationId": { + "description": "鎿嶄綔id", + "type": "integer" + }, "productId": { "description": "浜у搧id", - "type": "integer" + "type": "string" }, "productName": { "description": "浜у搧鍚嶇О", @@ -2363,12 +2368,8 @@ "request.UpdateOperation": { "type": "object", "properties": { - "carrierID": { - "description": "鎵胯繍鍟咺D-闈炲繀濉�", - "type": "integer" - }, - "carrierName": { - "description": "鎵胯繍鍟嗗悕绉�-闈炲繀濉�", + "comment": { + "description": "澶囨敞", "type": "string" }, "companyID": { @@ -2427,18 +2428,6 @@ "toLocationId": { "description": "鐩爣浣嶇疆id", "type": "integer" - }, - "tracking": { - "description": "杩借釜鍙傝��-闈炲繀濉�", - "type": "string" - }, - "transferWeight": { - "description": "鐗╂祦閲嶉噺(kg)-闈炲繀濉�", - "type": "number" - }, - "weight": { - "description": "閲嶉噺(kg)-闈炲繀濉�", - "type": "number" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 184cba4..024ec46 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -589,6 +589,7 @@ request.AddOperation: properties: comment: + description: 澶囨敞 type: string companyID: description: 鍏徃ID-瀹㈡埛 @@ -730,9 +731,12 @@ type: object request.OperationDetails: properties: + OperationId: + description: 鎿嶄綔id + type: integer productId: description: 浜у搧id - type: integer + type: string productName: description: 浜у搧鍚嶇О type: string @@ -769,11 +773,8 @@ type: object request.UpdateOperation: properties: - carrierID: - description: 鎵胯繍鍟咺D-闈炲繀濉� - type: integer - carrierName: - description: 鎵胯繍鍟嗗悕绉�-闈炲繀濉� + comment: + description: 澶囨敞 type: string companyID: description: 鍏徃ID-瀹㈡埛 @@ -815,15 +816,6 @@ toLocationId: description: 鐩爣浣嶇疆id type: integer - tracking: - description: 杩借釜鍙傝��-闈炲繀濉� - type: string - transferWeight: - description: 鐗╂祦閲嶉噺(kg)-闈炲繀濉� - type: number - weight: - description: 閲嶉噺(kg)-闈炲繀濉� - type: number type: object request.UpdateOperationType: properties: @@ -1255,7 +1247,7 @@ summary: 鍒犻櫎鍏ュ簱/鍑哄簱淇℃伅 tags: - 鍏ュ簱/鍑哄簱 - put: + post: parameters: - description: 鍏ュ簱淇℃伅 in: body diff --git a/models/operation_details.go b/models/operation_details.go index 7901215..270e34d 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -154,7 +154,7 @@ func (slf *OperationDetailsSearch) Delete() error { var db = slf.build() - return db.Delete(&OperationDetails{}).Error + return db.Unscoped().Delete(&OperationDetails{}).Error } func (slf *OperationDetailsSearch) First() (*OperationDetails, error) { @@ -243,3 +243,16 @@ return records, nil } + +func (slf *OperationDetailsSearch) FindAll() ([]*OperationDetails, error) { + var ( + records = make([]*OperationDetails, 0) + db = slf.build() + ) + + if err := db.Find(&records).Error; err != nil { + return records, fmt.Errorf("find records err: %v", err) + } + + return records, nil +} diff --git a/request/operation.go b/request/operation.go index 44d5402..a87eeb0 100644 --- a/request/operation.go +++ b/request/operation.go @@ -19,7 +19,7 @@ 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:澶囨敞"` + 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)-闈炲繀濉� @@ -29,7 +29,8 @@ } type OperationDetails struct { - ProductId int `json:"productId" gorm:"type:int;not null;comment:浜у搧id"` //浜у搧id + 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:鍗曚綅"` @@ -50,13 +51,15 @@ 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"` - 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:鍏徃鍚嶇О"` //鍏徃鍚嶇О-瀹㈡埛鍚嶇О + 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:鎵胯繍鍟嗗悕绉�"` //鎵胯繍鍟嗗悕绉�-闈炲繀濉� + //Tracking string `json:"tracking" gorm:"type:varchar(127);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)-闈炲繀濉� } diff --git a/router/router.go b/router/router.go index 084dc11..623eab5 100644 --- a/router/router.go +++ b/router/router.go @@ -79,7 +79,7 @@ { operationAPI.GET("operation", operationController.List) operationAPI.POST("operation", operationController.Add) - operationAPI.PUT("operation/:id", operationController.Update) + operationAPI.POST("operation/:id", operationController.Update) operationAPI.DELETE("operation/:id", operationController.Delete) operationAPI.PUT("Finish/:id", operationController.Finish) } -- Gitblit v1.8.0