From 015c07410b59bafd606bd4f567a61355c4f15958 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期五, 03 十一月 2023 11:37:20 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- response/report_forms_response.go | 20 controllers/report_forms_controller.go | 11 models/location_product_amount.go | 15 controllers/reorder_rule_controller.go | 311 +++++++++++ docs/swagger.yaml | 200 +++++++ controllers/location.go | 28 + docs/docs.go | 321 +++++++++++ docs/swagger.json | 319 +++++++++++ models/reorder_rule.go | 165 +++++ router/router.go | 12 /dev/null | 244 -------- models/db.go | 3 models/location.go | 1 request/reorder_rule_request.go | 27 models/operation_details.go | 2 15 files changed, 1,411 insertions(+), 268 deletions(-) diff --git a/controllers/location.go b/controllers/location.go index 5bfec45..2ef2a95 100644 --- a/controllers/location.go +++ b/controllers/location.go @@ -76,6 +76,34 @@ util.ResponseFormatList(c, code.Success, list, int(total)) } +// GetLocationTreeList +// @Tags 浣嶇疆 +// @Summary 鑾峰彇浣嶇疆鍒楄〃鏍� +// @Produce application/json +// @Success 200 {object} util.ResponseList{data=[]models.Location} "鎴愬姛" +// @Router /api-wms/v1/location/getLocationTreeList [get] +func (slf LocationController) GetLocationTreeList(c *gin.Context) { + all, err := models.NewLocationSearch().SetType(3).FindAll() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") + return + } + var tree []*models.Location + m := make(map[int]*models.Location) + for _, location := range all { + m[location.Id] = location + } + for _, location := range all { + if location.ParentId == 0 { + tree = append(tree, location) + } else { + m[location.ParentId].Children = append(m[location.ParentId].Children, location) + } + } + + util.ResponseFormat(c, code.Success, tree) +} + // GetLocationDetails // @Tags 浣嶇疆 // @Summary 鑾峰彇浣嶇疆璇︽儏 diff --git a/controllers/reorder_rule_controller.go b/controllers/reorder_rule_controller.go new file mode 100644 index 0000000..0c04e43 --- /dev/null +++ b/controllers/reorder_rule_controller.go @@ -0,0 +1,311 @@ +package controllers + +import ( + "github.com/gin-gonic/gin" + "github.com/shopspring/decimal" + "gorm.io/gorm" + "strconv" + "strings" + "time" + "wms/constvar" + "wms/extend/code" + "wms/extend/util" + "wms/models" + "wms/pkg/timex" + "wms/request" +) + +type ReorderRuleController struct { +} + +// AddReorderRule +// @Tags 閲嶈璐ц鍒� +// @Summary 娣诲姞閲嶈璐ц鍒� +// @Produce application/json +// @Param object body models.ReorderRule true "閲嶈璐ц鍒�" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/reorderRule/addReorderRule [post] +func (slf ReorderRuleController) AddReorderRule(c *gin.Context) { + var params models.ReorderRule + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + count, err := models.NewReorderRuleSearch().SetProductId(params.ProductId).SetLocationId(params.LocationId).Count() + if err != nil { + util.ResponseFormat(c, code.RequestError, "鏁版嵁楠岃瘉閿欒") + return + } + if count > 0 { + util.ResponseFormat(c, code.RequestError, "褰撳墠浣嶇疆宸插瓨鍦ㄧ浉鍚屼骇鍝佺殑閲嶈璐ц鍒�") + return + } + err = models.NewReorderRuleSearch().Create(¶ms) + if err != nil { + util.ResponseFormat(c, code.RequestError, "閲嶈璐ц鍒欎繚瀛樺け璐�") + return + } + util.ResponseFormat(c, code.Success, "淇濆瓨鎴愬姛") +} + +// GetReorderRuleList +// @Tags 閲嶈璐ц鍒� +// @Summary 鑾峰彇閲嶈璐ц鍒欏垪琛� +// @Produce application/json +// @Param object body request.GetReorderRuleList true "鍙傛暟" +// @Success 200 {object} util.ResponseList{data=[]models.ReorderRule} "鎴愬姛" +// @Router /api-wms/v1/reorderRule/getReorderRuleList [post] +func (slf ReorderRuleController) GetReorderRuleList(c *gin.Context) { + var params request.GetReorderRuleList + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + search := models.NewReorderRuleSearch() + if params.PageInfo.Check() { + search.SetPage(params.Page, params.PageSize) + } + rules, total, err := search.SetPreload(true).SetKeyword(params.KeyWord).SetLocationId(params.LocationId).SetProductId(params.ProductId).Find() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�") + return + } + productIds := make([]string, 0) + locationIds := make([]int, 0) + for _, rule := range rules { + productIds = append(productIds, rule.ProductId) + locationIds = append(locationIds, rule.LocationId) + } + if params.LocationId != 0 { + locationIds = []int{params.LocationId} + } + if params.ProductId != "" { + productIds = []string{params.ProductId} + } + //鍦ㄥ簱 + amounts, err := models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触") + return + } + for _, rule := range rules { + for _, amount := range amounts { + if rule.ProductId == amount.ProductId && rule.LocationId == amount.LocationId { + rule.Amount = rule.Amount.Add(amount.Amount) + } + } + } + + //棰勬祴 + //鍏ュ簱灏辩华 + var status = []constvar.OperationStatus{constvar.OperationStatus_Ready} + var operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeInternal} + amount, err := GetProductAmount(productIds, locationIds, nil, status, operationType) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�") + return + } + for _, rule := range rules { + for _, productAmount := range amount { + if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.ToLocationId { + rule.Prediction = rule.Prediction.Add(productAmount.Amount) + } + } + rule.Prediction = rule.Amount.Add(rule.Prediction) + } + //鍑哄簱灏辩华 + operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal} + amount, err = GetProductAmount(productIds, nil, locationIds, status, operationType) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�") + return + } + for _, rule := range rules { + for _, productAmount := range amount { + if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.FromLocationId { + rule.Prediction = rule.Prediction.Sub(productAmount.Amount) + } + } + } + var result []*models.ReorderRule + if params.Type == "" { + result = rules + } else { + for _, rule := range rules { + if rule.MinInventory.GreaterThan(rule.Prediction) { + result = append(result, rule) + } + } + } + + util.ResponseFormatList(c, code.Success, result, int(total)) +} + +// 璁$畻鍦ㄥ簱涓庨娴嬫暟閲� +func GetProductAmount(productIds []string, toLocationIds []int, fromLocationIds []int, status []constvar.OperationStatus, + operationType []constvar.BaseOperationType) ([]request.ProductAmount, error) { + var pa []request.ProductAmount + search := models.NewOperationDetailsSearch() + search.Orm = search.Orm.Model(&models.OperationDetails{}). + Select("wms_operation_details.product_id, wms_operation_details.amount, wms_operation.to_location_id as to_location_id, " + + "wms_operation.from_location_id as from_location_id, wms_operation.base_operation_type"). + Joins("left join wms_operation on wms_operation_details.operation_id = wms_operation.id") + if len(productIds) > 0 { + search.Orm.Where("wms_operation_details.product_id in (?)", productIds) + } + if len(toLocationIds) > 0 { + search.Orm.Where("wms_operation.to_location_id in (?)", toLocationIds) + } + if len(fromLocationIds) > 0 { + search.Orm.Where("wms_operation.from_location_id in (?)", fromLocationIds) + } + if len(status) > 0 { + search.Orm.Where("wms_operation.status in (?)", status) + } + if len(operationType) > 0 { + search.Orm.Where("wms_operation.base_operation_type in (?)", operationType) + } + err := search.Orm.Find(&pa).Error + return pa, err +} + +// GetAmountAndPrediction +// @Tags 閲嶈璐ц鍒� +// @Summary 鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲� +// @Produce application/json +// @Param object body request.GetAmountAndPrediction true "閲嶈璐ц鍒�" +// @Success 200 {object} util.ResponseList{data=[]map[string]interface{}} "鎴愬姛" +// @Router /api-wms/v1/reorderRule/getAmountAndPrediction [post] +func (slf ReorderRuleController) GetAmountAndPrediction(c *gin.Context) { + var params request.GetAmountAndPrediction + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + productIds := make([]string, 0) + locationIds := make([]int, 0) + productIds = append(productIds, params.ProductId) + locationIds = append(locationIds, params.LocationId) + amount := decimal.NewFromInt(0) + prediction := decimal.NewFromInt(0) + //鍦ㄥ簱 + find, err := models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鍦ㄥ簱鏁伴噺澶辫触") + return + } + for _, productAmount := range find { + if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.LocationId { + amount = amount.Add(productAmount.Amount) + } + } + + //棰勬祴 + //鍏ュ簱灏辩华 + var status = []constvar.OperationStatus{constvar.OperationStatus_Ready} + var operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeInternal} + list, err := GetProductAmount(productIds, locationIds, nil, status, operationType) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�") + return + } + for _, productAmount := range list { + if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.ToLocationId { + prediction = prediction.Add(productAmount.Amount) + } + } + prediction = amount.Add(prediction) + //鍑哄簱灏辩华 + operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal} + list, err = GetProductAmount(productIds, nil, locationIds, status, operationType) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ閲嶈璐ц鍒欏垪琛ㄥけ璐�") + return + } + for _, productAmount := range list { + if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.FromLocationId { + prediction = prediction.Sub(productAmount.Amount) + } + } + m := make(map[string]int64) + m["amount"] = amount.IntPart() + m["prediction"] = prediction.IntPart() + util.ResponseFormat(c, code.Success, m) +} + +// UpdateReorderRule +// @Tags 閲嶈璐ц鍒� +// @Summary 鏇存柊閲嶈璐ц鍒� +// @Produce application/json +// @Param object body models.ReorderRule true "閲嶈璐ц鍒�" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/reorderRule/updateReorderRule [post] +func (slf ReorderRuleController) UpdateReorderRule(c *gin.Context) { + var params models.ReorderRule + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + err := models.NewReorderRuleSearch().SetID(params.Id).Update(¶ms) + if err != nil { + util.ResponseFormat(c, code.RequestError, "閲嶈璐ц鍒欐洿鏂板け璐�") + return + } + util.ResponseFormat(c, code.Success, "鏇存柊鎴愬姛") +} + +// OrderAgain +// @Tags 閲嶈璐ц鍒� +// @Summary 鍐嶈涓�娆� +// @Produce application/json +// @Param object body models.ReorderRule true "閲嶈璐ц鍒�" +// @Success 200 {object} util.Response "鎴愬姛" +// @Router /api-wms/v1/reorderRule/orderAgain [post] +func (slf ReorderRuleController) OrderAgain(c *gin.Context) { + var params models.ReorderRule + if err := c.BindJSON(¶ms); err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + location, err := models.NewLocationSearch().SetID(params.LocationId).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆淇℃伅澶辫触") + return + } + houseCode := strings.Split(location.JointName, "/")[0] + var operationType models.OperationType + err = models.NewOperationTypeSearch().Orm.Model(&models.OperationType{}).Joins("left join wms_warehouse on wms_job_type.warehouse_id = wms_warehouse.id"). + Where("wms_job_type.base_operation_type = 1 and wms_warehouse.code = ?", houseCode).First(&operationType).Error + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆淇℃伅澶辫触") + return + } + var operation models.Operation + var details models.OperationDetails + details.ProductId = params.ProductId + details.Amount = params.OrderNumber + operation.Details = append(operation.Details, &details) + operation.BaseOperationType = constvar.BaseOperationTypeIncoming + operation.Status = constvar.OperationStatus_Ready + operation.OperationTypeId = operationType.Id + operation.OperationTypeName = operationType.Name + operation.OperationDate = timex.TimeToString2(time.Now()) + //todo 渚涘簲鍟嗕綅缃� + operation.FromLocationID = 1 + operation.Number = strconv.FormatInt(time.Now().Unix(), 10) + operation.ToLocationID = params.LocationId + + err = models.WithTransaction(func(db *gorm.DB) error { + if err = models.NewOperationSearch().SetOrm(db).Create(&operation); err != nil { + return err + } + params.OrderNumber = decimal.NewFromInt(0) + err = models.NewReorderRuleSearch().SetID(params.Id).Update(¶ms) + return err + }) + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "閲嶈澶辫触") + return + } + util.ResponseFormat(c, code.Success, "閲嶈鎴愬姛") +} diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go index 88dc93a..7370006 100644 --- a/controllers/report_forms_controller.go +++ b/controllers/report_forms_controller.go @@ -132,7 +132,7 @@ if params.PageInfo.Check() { detailsSearch.SetPage(params.Page, params.PageSize) } - details, err := detailsSearch.SetProductId(params.ProduceId).FindNotTotal() + details, total, err := detailsSearch.SetProductId(params.ProduceId).Find() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鎿嶄綔璇︽儏澶辫触") return @@ -142,8 +142,8 @@ operationIds = append(operationIds, detail.OperationID) } //鑾峰彇宸插畬鎴愮殑鎿嶄綔璁板綍 - operations, total, err := models.NewOperationSearch().SetIds(operationIds).SetBaseOperationType(params.BaseOperationType). - SetStatus(constvar.OperationStatus_Finish).Find() + operations, err := models.NewOperationSearch().SetIds(operationIds).SetBaseOperationType(params.BaseOperationType). + SetStatus(constvar.OperationStatus_Finish).FindNotTotal() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鎿嶄綔璁板綍澶辫触") return @@ -152,8 +152,8 @@ for _, detail := range details { var resp response.InventoryHistory resp.Amount = detail.Amount - resp.Unit = params.Unit - resp.ProductName = params.ProductName + resp.Unit = detail.Product.Unit + resp.ProductName = detail.Product.Name for _, operation := range operations { if detail.OperationID == operation.Id { resp.Number = operation.Number @@ -162,6 +162,7 @@ resp.ContactedName = operation.ContacterName resp.FromLocation = operation.FromLocation.Name resp.ToLocation = operation.ToLocation.Name + resp.BaseOperationType = operation.BaseOperationType result = append(result, resp) break } diff --git a/docs/docs.go b/docs/docs.go index f287150..575933f 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -572,6 +572,40 @@ } } }, + "/api-wms/v1/location/getLocationTreeList": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "浣嶇疆" + ], + "summary": "鑾峰彇浣嶇疆鍒楄〃鏍�", + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Location" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/location/updateLocation": { "post": { "produces": [ @@ -1770,6 +1804,187 @@ } } }, + "/api-wms/v1/reorderRule/addReorderRule": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "娣诲姞閲嶈璐ц鍒�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.ReorderRule" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/reorderRule/getAmountAndPrediction": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetAmountAndPrediction" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": true + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/reorderRule/getReorderRuleList": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鑾峰彇閲嶈璐ц鍒欏垪琛�", + "parameters": [ + { + "description": "鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetReorderRuleList" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ReorderRule" + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/reorderRule/orderAgain": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鍐嶈涓�娆�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.ReorderRule" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/reorderRule/updateReorderRule": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鏇存柊閲嶈璐ц鍒�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.ReorderRule" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-wms/v1/warehouse/getWarehouseDetails/{id}": { "get": { "produces": [ @@ -2264,6 +2479,12 @@ "models.Location": { "type": "object", "properties": { + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Location" + } + }, "companyId": { "description": "鍏徃id", "type": "integer" @@ -2703,6 +2924,62 @@ } } }, + "models.ReorderRule": { + "type": "object", + "properties": { + "amount": { + "description": "鍦ㄥ簱鏁伴噺", + "type": "number" + }, + "createTime": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "location": { + "$ref": "#/definitions/models.Location" + }, + "locationId": { + "description": "浣嶇疆id", + "type": "integer" + }, + "maxInventory": { + "description": "鏈�澶у簱瀛�", + "type": "number" + }, + "minInventory": { + "description": "鏈�灏忓簱瀛�", + "type": "number" + }, + "orderNumber": { + "description": "璁㈣喘鏁伴噺", + "type": "number" + }, + "prediction": { + "description": "棰勬祴鏁伴噺", + "type": "number" + }, + "product": { + "$ref": "#/definitions/models.Material" + }, + "productId": { + "description": "浜у搧id", + "type": "string" + }, + "route": { + "description": "璺嚎", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + }, + "updateTime": { + "type": "string" + } + } + }, "models.Warehouse": { "type": "object", "required": [ @@ -3078,6 +3355,17 @@ } } }, + "request.GetAmountAndPrediction": { + "type": "object", + "properties": { + "locationId": { + "type": "integer" + }, + "productId": { + "type": "string" + } + } + }, "request.GetInventoryForms": { "type": "object", "properties": { @@ -3181,6 +3469,29 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + } + } + }, + "request.GetReorderRuleList": { + "type": "object", + "properties": { + "keyWord": { + "type": "string" + }, + "locationId": { + "type": "integer" + }, + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + }, + "type": { + "description": "绫诲瀷:bh=琛ヨ揣", + "type": "string" } } }, @@ -3661,6 +3972,14 @@ "description": "鏁伴噺", "type": "number" }, + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "contactedName": { "description": "瀹屾垚鑰�", "type": "string" @@ -3793,6 +4112,8 @@ Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index c3e37c3..16eff99 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -560,6 +560,40 @@ } } }, + "/api-wms/v1/location/getLocationTreeList": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "浣嶇疆" + ], + "summary": "鑾峰彇浣嶇疆鍒楄〃鏍�", + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Location" + } + } + } + } + ] + } + } + } + } + }, "/api-wms/v1/location/updateLocation": { "post": { "produces": [ @@ -1758,6 +1792,187 @@ } } }, + "/api-wms/v1/reorderRule/addReorderRule": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "娣诲姞閲嶈璐ц鍒�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.ReorderRule" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/reorderRule/getAmountAndPrediction": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetAmountAndPrediction" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": true + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/reorderRule/getReorderRuleList": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鑾峰彇閲嶈璐ц鍒欏垪琛�", + "parameters": [ + { + "description": "鍙傛暟", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.GetReorderRuleList" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/util.ResponseList" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/models.ReorderRule" + } + } + } + } + ] + } + } + } + } + }, + "/api-wms/v1/reorderRule/orderAgain": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鍐嶈涓�娆�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.ReorderRule" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, + "/api-wms/v1/reorderRule/updateReorderRule": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "閲嶈璐ц鍒�" + ], + "summary": "鏇存柊閲嶈璐ц鍒�", + "parameters": [ + { + "description": "閲嶈璐ц鍒�", + "name": "object", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/models.ReorderRule" + } + } + ], + "responses": { + "200": { + "description": "鎴愬姛", + "schema": { + "$ref": "#/definitions/util.Response" + } + } + } + } + }, "/api-wms/v1/warehouse/getWarehouseDetails/{id}": { "get": { "produces": [ @@ -2252,6 +2467,12 @@ "models.Location": { "type": "object", "properties": { + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Location" + } + }, "companyId": { "description": "鍏徃id", "type": "integer" @@ -2691,6 +2912,62 @@ } } }, + "models.ReorderRule": { + "type": "object", + "properties": { + "amount": { + "description": "鍦ㄥ簱鏁伴噺", + "type": "number" + }, + "createTime": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "location": { + "$ref": "#/definitions/models.Location" + }, + "locationId": { + "description": "浣嶇疆id", + "type": "integer" + }, + "maxInventory": { + "description": "鏈�澶у簱瀛�", + "type": "number" + }, + "minInventory": { + "description": "鏈�灏忓簱瀛�", + "type": "number" + }, + "orderNumber": { + "description": "璁㈣喘鏁伴噺", + "type": "number" + }, + "prediction": { + "description": "棰勬祴鏁伴噺", + "type": "number" + }, + "product": { + "$ref": "#/definitions/models.Material" + }, + "productId": { + "description": "浜у搧id", + "type": "string" + }, + "route": { + "description": "璺嚎", + "type": "string" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + }, + "updateTime": { + "type": "string" + } + } + }, "models.Warehouse": { "type": "object", "required": [ @@ -3066,6 +3343,17 @@ } } }, + "request.GetAmountAndPrediction": { + "type": "object", + "properties": { + "locationId": { + "type": "integer" + }, + "productId": { + "type": "string" + } + } + }, "request.GetInventoryForms": { "type": "object", "properties": { @@ -3169,6 +3457,29 @@ "pageSize": { "description": "姣忛〉澶у皬", "type": "integer" + } + } + }, + "request.GetReorderRuleList": { + "type": "object", + "properties": { + "keyWord": { + "type": "string" + }, + "locationId": { + "type": "integer" + }, + "page": { + "description": "椤电爜", + "type": "integer" + }, + "pageSize": { + "description": "姣忛〉澶у皬", + "type": "integer" + }, + "type": { + "description": "绫诲瀷:bh=琛ヨ揣", + "type": "string" } } }, @@ -3649,6 +3960,14 @@ "description": "鏁伴噺", "type": "number" }, + "baseOperationType": { + "description": "鍩虹浣滀笟绫诲瀷", + "allOf": [ + { + "$ref": "#/definitions/constvar.BaseOperationType" + } + ] + }, "contactedName": { "description": "瀹屾垚鑰�", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 96396c4..c318180 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -244,6 +244,10 @@ type: object models.Location: properties: + children: + items: + $ref: '#/definitions/models.Location' + type: array companyId: description: 鍏徃id type: integer @@ -552,6 +556,46 @@ description: 鍏徃 type: string type: object + models.ReorderRule: + properties: + amount: + description: 鍦ㄥ簱鏁伴噺 + type: number + createTime: + type: string + id: + type: integer + location: + $ref: '#/definitions/models.Location' + locationId: + description: 浣嶇疆id + type: integer + maxInventory: + description: 鏈�澶у簱瀛� + type: number + minInventory: + description: 鏈�灏忓簱瀛� + type: number + orderNumber: + description: 璁㈣喘鏁伴噺 + type: number + prediction: + description: 棰勬祴鏁伴噺 + type: number + product: + $ref: '#/definitions/models.Material' + productId: + description: 浜у搧id + type: string + route: + description: 璺嚎 + type: string + unit: + description: 鍗曚綅 + type: string + updateTime: + type: string + type: object models.Warehouse: properties: active: @@ -813,6 +857,13 @@ description: 浜у搧id type: string type: object + request.GetAmountAndPrediction: + properties: + locationId: + type: integer + productId: + type: string + type: object request.GetInventoryForms: properties: categoryIds: @@ -885,6 +936,22 @@ pageSize: description: 姣忛〉澶у皬 type: integer + type: object + request.GetReorderRuleList: + properties: + keyWord: + type: string + locationId: + type: integer + page: + description: 椤电爜 + type: integer + pageSize: + description: 姣忛〉澶у皬 + type: integer + type: + description: 绫诲瀷:bh=琛ヨ揣 + type: string type: object request.GetRuleList: properties: @@ -1215,6 +1282,10 @@ amount: description: 鏁伴噺 type: number + baseOperationType: + allOf: + - $ref: '#/definitions/constvar.BaseOperationType' + description: 鍩虹浣滀笟绫诲瀷 contactedName: description: 瀹屾垚鑰� type: string @@ -1637,6 +1708,25 @@ type: array type: object summary: 鑾峰彇浣嶇疆鍒楄〃 + tags: + - 浣嶇疆 + /api-wms/v1/location/getLocationTreeList: + get: + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/models.Location' + type: array + type: object + summary: 鑾峰彇浣嶇疆鍒楄〃鏍� tags: - 浣嶇疆 /api-wms/v1/location/updateLocation: @@ -2383,6 +2473,116 @@ summary: 淇敼浜у搧绫诲瀷 tags: - 浜у搧绫诲瀷 + /api-wms/v1/reorderRule/addReorderRule: + post: + parameters: + - description: 閲嶈璐ц鍒� + in: body + name: object + required: true + schema: + $ref: '#/definitions/models.ReorderRule' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 娣诲姞閲嶈璐ц鍒� + tags: + - 閲嶈璐ц鍒� + /api-wms/v1/reorderRule/getAmountAndPrediction: + post: + parameters: + - description: 閲嶈璐ц鍒� + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.GetAmountAndPrediction' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + additionalProperties: true + type: object + type: array + type: object + summary: 鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲� + tags: + - 閲嶈璐ц鍒� + /api-wms/v1/reorderRule/getReorderRuleList: + post: + parameters: + - description: 鍙傛暟 + in: body + name: object + required: true + schema: + $ref: '#/definitions/request.GetReorderRuleList' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + allOf: + - $ref: '#/definitions/util.ResponseList' + - properties: + data: + items: + $ref: '#/definitions/models.ReorderRule' + type: array + type: object + summary: 鑾峰彇閲嶈璐ц鍒欏垪琛� + tags: + - 閲嶈璐ц鍒� + /api-wms/v1/reorderRule/orderAgain: + post: + parameters: + - description: 閲嶈璐ц鍒� + in: body + name: object + required: true + schema: + $ref: '#/definitions/models.ReorderRule' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 鍐嶈涓�娆� + tags: + - 閲嶈璐ц鍒� + /api-wms/v1/reorderRule/updateReorderRule: + post: + parameters: + - description: 閲嶈璐ц鍒� + in: body + name: object + required: true + schema: + $ref: '#/definitions/models.ReorderRule' + produces: + - application/json + responses: + "200": + description: 鎴愬姛 + schema: + $ref: '#/definitions/util.Response' + summary: 鏇存柊閲嶈璐ц鍒� + tags: + - 閲嶈璐ц鍒� /api-wms/v1/warehouse/getWarehouseDetails/{id}: get: parameters: diff --git a/models/db.go b/models/db.go index a1570c8..480edaa 100644 --- a/models/db.go +++ b/models/db.go @@ -81,12 +81,11 @@ Operation{}, OperationDetails{}, Scrap{}, - MoveHistory{}, - //Product{}, ProductCategory{}, Material{}, LocationProduct{}, LocationProductAmount{}, + ReorderRule{}, ) return err } diff --git a/models/location.go b/models/location.go index ef755e6..028e875 100644 --- a/models/location.go +++ b/models/location.go @@ -26,6 +26,7 @@ RecentlyCount string `json:"recentlyCount" gorm:"type:varchar(255);comment:鏈�杩戠洏鐐�"` //鏈�杩戠洏鐐� NextCount string `json:"nextCount" gorm:"type:varchar(255);comment:涓嬫鐩樼偣"` //涓嬫鐩樼偣 JointName string `json:"jointName" gorm:"type:varchar(255);comment:鎷兼帴鍚嶇О"` //鎷兼帴鍚嶇О + Children []*Location `json:"children" gorm:"-"` } LocationSearch struct { diff --git a/models/location_product_amount.go b/models/location_product_amount.go index 00c7b92..94cf597 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -34,6 +34,7 @@ Preload bool //LocationProductIds []int LocationIds []int + ProductIds []string } LocationProductAmountWithOperation struct { @@ -102,10 +103,10 @@ return slf } -//func (slf *LocationProductAmountSearch) SetLocationProductIds(ids []int) *LocationProductAmountSearch { -// slf.LocationProductIds = ids -// return slf -//} +func (slf *LocationProductAmountSearch) SetProductIds(ids []string) *LocationProductAmountSearch { + slf.ProductIds = ids + return slf +} func (slf *LocationProductAmountSearch) SetLocationIds(ids []int) *LocationProductAmountSearch { slf.LocationIds = ids @@ -132,9 +133,9 @@ //if slf.LocationProductId != 0 { // db = db.Where("location_product_id=?", slf.LocationProductId) //} - //if len(slf.LocationProductIds) > 0 { - // db = db.Where("location_product_id in (?)", slf.LocationProductIds) - //} + if len(slf.ProductIds) > 0 { + db = db.Where("product_id in (?)", slf.ProductIds) + } if len(slf.LocationIds) > 0 { db = db.Where("location_id in (?)", slf.LocationIds) diff --git a/models/move_history.go b/models/move_history.go deleted file mode 100644 index 3bd9974..0000000 --- a/models/move_history.go +++ /dev/null @@ -1,244 +0,0 @@ -package models - -import ( - "fmt" - "google.golang.org/genproto/googleapis/type/decimal" - "gorm.io/gorm" - "wms/constvar" - "wms/pkg/mysqlx" -) - -type ( - // MoveHistory 绉诲姩鍘嗗彶 - MoveHistory struct { - WmsModel - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - Number string `json:"number" gorm:"column:number;type:varchar(255)"` //鍗曞彿 - BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷 - OperationTypeId int `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id - OperationId int `json:"operationRecordId" 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:鏁伴噺"` //鏁伴噺 - - FromLocationId int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d - FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationId"` //婧愪綅缃� - ToLocationId int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id - ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationId"` //鐩爣浣嶇疆 - } - - MoveHistorySearch struct { - MoveHistory - Order string - PageNum int - PageSize int - Keyword string - Orm *gorm.DB - Preload bool - } -) - -func (slf *MoveHistory) TableName() string { - return "wms_move_history" -} - -func NewMoveHistorySearch() *MoveHistorySearch { - return &MoveHistorySearch{Orm: mysqlx.GetDB()} -} - -func (slf *MoveHistorySearch) SetOrm(tx *gorm.DB) *MoveHistorySearch { - slf.Orm = tx - return slf -} - -func (slf *MoveHistorySearch) SetPage(page, size int) *MoveHistorySearch { - slf.PageNum, slf.PageSize = page, size - return slf -} - -func (slf *MoveHistorySearch) SetOrder(order string) *MoveHistorySearch { - slf.Order = order - return slf -} - -func (slf *MoveHistorySearch) SetID(id uint) *MoveHistorySearch { - slf.ID = id - return slf -} - -func (slf *MoveHistorySearch) SetKeyword(keyword string) *MoveHistorySearch { - slf.Keyword = keyword - return slf -} - -func (slf *MoveHistorySearch) SetPreload(preload bool) *MoveHistorySearch { - slf.Preload = preload - return slf -} - -func (slf *MoveHistorySearch) build() *gorm.DB { - var db = slf.Orm.Model(&MoveHistory{}) - - if slf.ID != 0 { - db = db.Where("id = ?", slf.ID) - } - - if slf.Order != "" { - db = db.Order(slf.Order) - } - - if slf.Keyword != "" { - db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) - } - - return db -} - -// Create 鍗曟潯鎻掑叆 -func (slf *MoveHistorySearch) Create(record *MoveHistory) error { - var db = slf.build() - - if err := db.Create(record).Error; err != nil { - return err - } - - return nil -} - -// CreateBatch 鎵归噺鎻掑叆 -func (slf *MoveHistorySearch) CreateBatch(records []*MoveHistory) error { - var db = slf.build() - - if err := db.Create(&records).Error; err != nil { - return fmt.Errorf("create batch err: %v, records: %+v", err, records) - } - - return nil -} - -func (slf *MoveHistorySearch) Update(record *MoveHistory) error { - var db = slf.build() - - if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { - return fmt.Errorf("save err: %v, record: %+v", err, record) - } - - return nil -} - -func (slf *MoveHistorySearch) UpdateByMap(upMap map[string]interface{}) error { - var ( - db = slf.build() - ) - - if err := db.Updates(upMap).Error; err != nil { - return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) - } - - return nil -} - -func (slf *MoveHistorySearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error { - var ( - db = slf.Orm.Table(slf.TableName()).Where(query, args...) - ) - - if err := db.Updates(upMap).Error; err != nil { - return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap) - } - - return nil -} - -func (slf *MoveHistorySearch) Delete() error { - var db = slf.build() - return db.Delete(&MoveHistory{}).Error -} - -func (slf *MoveHistorySearch) First() (*MoveHistory, error) { - var ( - record = new(MoveHistory) - db = slf.build() - ) - - if err := db.First(record).Error; err != nil { - return record, err - } - - return record, nil -} - -func (slf *MoveHistorySearch) Find() ([]*MoveHistory, int64, error) { - var ( - records = make([]*MoveHistory, 0) - total int64 - db = slf.build() - ) - - if err := db.Count(&total).Error; err != nil { - return records, total, fmt.Errorf("find count err: %v", err) - } - if slf.PageNum*slf.PageSize > 0 { - db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) - } - if err := db.Find(&records).Error; err != nil { - return records, total, fmt.Errorf("find records err: %v", err) - } - - return records, total, nil -} - -func (slf *MoveHistorySearch) FindNotTotal() ([]*MoveHistory, error) { - var ( - records = make([]*MoveHistory, 0) - db = slf.build() - ) - - if slf.PageNum*slf.PageSize > 0 { - db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) - } - if err := db.Find(&records).Error; err != nil { - return records, fmt.Errorf("find records err: %v", err) - } - - return records, nil -} - -// FindByQuery 鎸囧畾鏉′欢鏌ヨ. -func (slf *MoveHistorySearch) FindByQuery(query string, args []interface{}) ([]*MoveHistory, int64, error) { - var ( - records = make([]*MoveHistory, 0) - total int64 - db = slf.Orm.Table(slf.TableName()).Where(query, args...) - ) - - if err := db.Count(&total).Error; err != nil { - return records, total, fmt.Errorf("find by query count err: %v", err) - } - if slf.PageNum*slf.PageSize > 0 { - db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) - } - if err := db.Find(&records).Error; err != nil { - return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) - } - - return records, total, nil -} - -// FindByQueryNotTotal 鎸囧畾鏉′欢鏌ヨ&涓嶆煡璇㈡�绘潯鏁�. -func (slf *MoveHistorySearch) FindByQueryNotTotal(query string, args []interface{}) ([]*MoveHistory, error) { - var ( - records = make([]*MoveHistory, 0) - db = slf.Orm.Table(slf.TableName()).Where(query, args...) - ) - - if slf.PageNum*slf.PageSize > 0 { - db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) - } - if err := db.Find(&records).Error; err != nil { - return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args) - } - - return records, nil -} diff --git a/models/operation_details.go b/models/operation_details.go index 9e89e77..8517d8c 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -207,7 +207,7 @@ if slf.PageNum*slf.PageSize > 0 { db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) } - if err := db.Find(&records).Error; err != nil { + if err := db.Preload("Product").Find(&records).Error; err != nil { return records, fmt.Errorf("find records err: %v", err) } diff --git a/models/reorder_rule.go b/models/reorder_rule.go new file mode 100644 index 0000000..868ef41 --- /dev/null +++ b/models/reorder_rule.go @@ -0,0 +1,165 @@ +package models + +import ( + "fmt" + "github.com/shopspring/decimal" + "gorm.io/gorm" + "wms/pkg/mysqlx" +) + +type ( + ReorderRule struct { + WmsModel + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id + Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"` + LocationId int `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id + Location Location `json:"location" gorm:"foreignKey:LocationId;references:id"` + Route string `json:"route" gorm:"type:varchar(255);comment:璺嚎"` //璺嚎 + MinInventory decimal.Decimal `json:"minInventory" gorm:"type:decimal(35,18);comment:鏈�灏忓簱瀛�"` //鏈�灏忓簱瀛� + MaxInventory decimal.Decimal `json:"maxInventory" gorm:"type:decimal(35,18);comment:鏈�澶у簱瀛�"` //鏈�澶у簱瀛� + OrderNumber decimal.Decimal `json:"orderNumber" gorm:"type:decimal(35,18);comment:璁㈣喘鏁伴噺"` //璁㈣喘鏁伴噺 + Unit string `json:"unit" gorm:"type:varchar(100);comment:鍗曚綅"` //鍗曚綅 + Amount decimal.Decimal `json:"amount" gorm:"-"` //鍦ㄥ簱鏁伴噺 + Prediction decimal.Decimal `json:"prediction" gorm:"-"` //棰勬祴鏁伴噺 + } + ReorderRuleSearch struct { + ReorderRule + PageNum int + PageSize int + Keyword string + Orm *gorm.DB + Preload bool + } +) + +func (slf *ReorderRule) TableName() string { + return "wms_reorder_rule" +} + +func NewReorderRuleSearch() *ReorderRuleSearch { + return &ReorderRuleSearch{Orm: mysqlx.GetDB()} +} + +func (slf *ReorderRuleSearch) SetOrm(tx *gorm.DB) *ReorderRuleSearch { + slf.Orm = tx + return slf +} + +func (slf *ReorderRuleSearch) SetPage(page, size int) *ReorderRuleSearch { + slf.PageNum, slf.PageSize = page, size + return slf +} + +func (slf *ReorderRuleSearch) SetID(ID int) *ReorderRuleSearch { + slf.Id = ID + return slf +} + +func (slf *ReorderRuleSearch) SetKeyword(keyword string) *ReorderRuleSearch { + slf.Keyword = keyword + return slf +} + +func (slf *ReorderRuleSearch) SetProductId(productId string) *ReorderRuleSearch { + slf.ProductId = productId + return slf +} + +func (slf *ReorderRuleSearch) SetLocationId(locationId int) *ReorderRuleSearch { + slf.LocationId = locationId + return slf +} + +func (slf *ReorderRuleSearch) SetPreload(preload bool) *ReorderRuleSearch { + slf.Preload = preload + return slf +} + +func (slf *ReorderRuleSearch) build() *gorm.DB { + var db = slf.Orm.Model(&ReorderRule{}) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) + } + if slf.ProductId != "" { + db = db.Where("product_id = ?", slf.ProductId) + } + if slf.LocationId != 0 { + db = db.Where("location_id = ?", slf.LocationId) + } + + if slf.Preload { + db = db.Preload("Product").Preload("Location") + } + + return db +} + +// Create 鍗曟潯鎻掑叆 +func (slf *ReorderRuleSearch) Create(record *ReorderRule) error { + var db = slf.build() + + if err := db.Create(record).Error; err != nil { + return err + } + + return nil +} + +func (slf *ReorderRuleSearch) Update(record *ReorderRule) error { + var db = slf.build() + + if err := db.Omit("CreatedAt").Updates(record).Error; err != nil { + return fmt.Errorf("update err: %v, record: %+v", err, record) + } + + return nil +} + +func (slf *ReorderRuleSearch) Count() (int64, error) { + var ( + total int64 + db = slf.build() + ) + + err := db.Count(&total).Error + return total, err +} + +func (slf *ReorderRuleSearch) First() (*ReorderRule, error) { + var ( + record = new(ReorderRule) + db = slf.build() + ) + + if err := db.First(record).Error; err != nil { + return record, err + } + + return record, nil +} + +func (slf *ReorderRuleSearch) Find() ([]*ReorderRule, int64, error) { + var ( + records = make([]*ReorderRule, 0) + total int64 + db = slf.build() + ) + + if err := db.Count(&total).Error; err != nil { + return records, total, fmt.Errorf("find count err: %v", err) + } + if slf.PageNum*slf.PageSize > 0 { + db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) + } + if err := db.Order("created_at desc").Find(&records).Error; err != nil { + return records, total, fmt.Errorf("find records err: %v", err) + } + + return records, total, nil +} + +func (slf *ReorderRuleSearch) Delete() error { + var db = slf.build() + return db.Delete(&ReorderRule{}).Error +} diff --git a/request/reorder_rule_request.go b/request/reorder_rule_request.go new file mode 100644 index 0000000..53e5c53 --- /dev/null +++ b/request/reorder_rule_request.go @@ -0,0 +1,27 @@ +package request + +import ( + "github.com/shopspring/decimal" + "wms/constvar" +) + +type GetReorderRuleList struct { + PageInfo + KeyWord string `json:"keyWord"` + LocationId int `json:"locationId"` + ProductId string `json:"productId"` + Type string `json:"type"` //绫诲瀷:bh=琛ヨ揣 +} + +type ProductAmount struct { + ProductId string `json:"productId"` + ToLocationId int `json:"toLocationId"` + FromLocationId int `json:"fromLocationId"` + Amount decimal.Decimal `json:"amount"` + BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` +} + +type GetAmountAndPrediction struct { + ProductId string `json:"productId"` + LocationId int `json:"locationId"` +} diff --git a/response/report_forms_response.go b/response/report_forms_response.go index 8bf283c..200903d 100644 --- a/response/report_forms_response.go +++ b/response/report_forms_response.go @@ -2,6 +2,7 @@ import ( "github.com/shopspring/decimal" + "wms/constvar" ) type InventoryForms struct { @@ -18,15 +19,16 @@ } type InventoryHistory struct { - Number string `json:"number"` //鍗曞彿 - Date string `json:"date"` //鏃ユ湡 - ProductName string `json:"productName"` //浜у搧鍚嶇О - FromLocation string `json:"fromLocation"` //婧愪綅缃� - ToLocation string `json:"toLocation"` //鐩爣浣嶇疆 - Amount decimal.Decimal `json:"amount"` //鏁伴噺 - Unit string `json:"unit"` //鍗曚綅 - ContactedName string `json:"contactedName"` //瀹屾垚鑰� - Status string `json:"status"` //鐘舵�� + Number string `json:"number"` //鍗曞彿 + Date string `json:"date"` //鏃ユ湡 + ProductName string `json:"productName"` //浜у搧鍚嶇О + FromLocation string `json:"fromLocation"` //婧愪綅缃� + ToLocation string `json:"toLocation"` //鐩爣浣嶇疆 + Amount decimal.Decimal `json:"amount"` //鏁伴噺 + Unit string `json:"unit"` //鍗曚綅 + ContactedName string `json:"contactedName"` //瀹屾垚鑰� + Status string `json:"status"` //鐘舵�� + BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` //鍩虹浣滀笟绫诲瀷 } type LocationForms struct { diff --git a/router/router.go b/router/router.go index 4ac8ab8..7d527e8 100644 --- a/router/router.go +++ b/router/router.go @@ -61,6 +61,7 @@ locationAPI.POST("updateLocation", locationController.UpdateLocation) //淇敼浣嶇疆 locationAPI.GET("getLocationDetails/:id", locationController.GetLocationDetails) //鑾峰彇浣嶇疆璇︽儏 locationAPI.DELETE("deleteLocation/:id", locationController.DeleteLocation) //鍒犻櫎浣嶇疆 + locationAPI.GET("getLocationTreeList", locationController.GetLocationTreeList) //鑾峰彇浣嶇疆鍒楄〃鏍� } // 涓氬姟绫诲瀷 @@ -142,5 +143,16 @@ reportFormsAPI.POST("getLocationForms", reportFormsController.GetLocationForms) //鑾峰彇浣嶇疆鎶ヨ〃 } + //閲嶈璐ц鍒� + reorderRuleController := new(controllers.ReorderRuleController) + reorderRuleAPI := r.Group(urlPrefix + "/reorderRule") + { + reorderRuleAPI.POST("addReorderRule", reorderRuleController.AddReorderRule) //娣诲姞閲嶈璐ц鍒� + reorderRuleAPI.POST("getReorderRuleList", reorderRuleController.GetReorderRuleList) //鑾峰彇閲嶈璐ц鍒欏垪琛� + reorderRuleAPI.POST("getAmountAndPrediction", reorderRuleController.GetAmountAndPrediction) //鑾峰彇鍦ㄥ簱涓庨娴嬫暟閲� + reorderRuleAPI.POST("updateReorderRule", reorderRuleController.UpdateReorderRule) //鏇存柊閲嶈璐ц鍒� + reorderRuleAPI.POST("orderAgain", reorderRuleController.OrderAgain) //鍐嶈涓�娆� + } + return r } -- Gitblit v1.8.0