controllers/location.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
controllers/reorder_rule_controller.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
docs/docs.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
docs/swagger.json | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
docs/swagger.yaml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
models/location.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
models/location_product_amount.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
request/reorder_rule_request.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
router/router.go | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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 获取位置详情 controllers/reorder_rule_controller.go
@@ -65,7 +65,7 @@ if params.PageInfo.Check() { search.SetPage(params.Page, params.PageSize) } rules, total, err := search.SetPreload(true).SetKeyword(params.KeyWord).Find() 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 @@ -76,29 +76,44 @@ 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} } //在库 var status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready} 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 } mp := make(map[int]decimal.Decimal) for _, rule := range rules { for _, productAmount := range amount { if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.ToLocationId && productAmount.Status == constvar.OperationStatus_Finish { rule.Amount = rule.Amount.Add(productAmount.Amount) } if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.ToLocationId && productAmount.Status == constvar.OperationStatus_Ready { mp[rule.Id] = mp[rule.Id].Add(productAmount.Amount) if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.ToLocationId { rule.Prediction = rule.Prediction.Add(productAmount.Amount) } } rule.Prediction = rule.Amount.Add(rule.Prediction) } //预测 status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready} //出库就绪 operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal} amount, err = GetProductAmount(productIds, nil, locationIds, status, operationType) if err != nil { @@ -108,13 +123,22 @@ for _, rule := range rules { for _, productAmount := range amount { if rule.ProductId == productAmount.ProductId && rule.LocationId == productAmount.FromLocationId { rule.Prediction = rule.Prediction.Add(productAmount.Amount) rule.Prediction = rule.Prediction.Sub(productAmount.Amount) } } rule.Prediction = rule.Amount.Add(mp[rule.Id]).Sub(rule.Prediction) } 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, rules, int(total)) util.ResponseFormatList(c, code.Success, result, int(total)) } // 计算在库与预测数量 @@ -124,7 +148,7 @@ 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.status"). "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) @@ -163,30 +187,24 @@ productIds = append(productIds, params.ProductId) locationIds = append(locationIds, params.LocationId) amount := decimal.NewFromInt(0) p := decimal.NewFromInt(0) prediction := decimal.NewFromInt(0) //在库 var status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready} var operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeIncoming, constvar.BaseOperationTypeInternal} list, err := GetProductAmount(productIds, locationIds, nil, status, operationType) find, err := models.NewLocationProductAmountSearch().SetProductIds(productIds).SetLocationIds(locationIds).Find() if err != nil { util.ResponseFormat(c, code.RequestParamError, "查询重订货规则列表失败") util.ResponseFormat(c, code.RequestParamError, "查询在库数量失败") return } for _, productAmount := range list { if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.ToLocationId && productAmount.Status == constvar.OperationStatus_Finish { for _, productAmount := range find { if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.LocationId { amount = amount.Add(productAmount.Amount) } if params.ProductId == productAmount.ProductId && params.LocationId == productAmount.ToLocationId && productAmount.Status == constvar.OperationStatus_Ready { p = p.Add(productAmount.Amount) } } //预测 status = []constvar.OperationStatus{constvar.OperationStatus_Finish, constvar.OperationStatus_Ready} operationType = []constvar.BaseOperationType{constvar.BaseOperationTypeOutgoing, constvar.BaseOperationTypeInternal} list, err = GetProductAmount(productIds, nil, locationIds, status, operationType) //入库就绪 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 @@ -196,7 +214,19 @@ prediction = prediction.Add(productAmount.Amount) } } prediction = amount.Add(p).Sub(prediction) 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() 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": [ @@ -2445,6 +2479,12 @@ "models.Location": { "type": "object", "properties": { "children": { "type": "array", "items": { "$ref": "#/definitions/models.Location" } }, "companyId": { "description": "公司id", "type": "integer" @@ -3438,6 +3478,9 @@ "keyWord": { "type": "string" }, "locationId": { "type": "integer" }, "page": { "description": "页码", "type": "integer" @@ -3445,6 +3488,10 @@ "pageSize": { "description": "每页大小", "type": "integer" }, "type": { "description": "类型:bh=补货", "type": "string" } } }, 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": [ @@ -2433,6 +2467,12 @@ "models.Location": { "type": "object", "properties": { "children": { "type": "array", "items": { "$ref": "#/definitions/models.Location" } }, "companyId": { "description": "公司id", "type": "integer" @@ -3426,6 +3466,9 @@ "keyWord": { "type": "string" }, "locationId": { "type": "integer" }, "page": { "description": "页码", "type": "integer" @@ -3433,6 +3476,10 @@ "pageSize": { "description": "每页大小", "type": "integer" }, "type": { "description": "类型:bh=补货", "type": "string" } } }, 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 @@ -937,12 +941,17 @@ 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: @@ -1701,6 +1710,25 @@ 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: post: parameters: 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 { 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) request/reorder_rule_request.go
@@ -7,15 +7,18 @@ type GetReorderRuleList struct { PageInfo KeyWord string `json:"keyWord"` 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"` Status constvar.OperationStatus `json:"status"` 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 { 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) //获取位置列表树 } // 业务类型