当操作为出库或调拨时,操作详情明细返回产品相应位置的实时库存
| | |
| | | |
| | | // GetOperationInfo |
| | | // @Tags 入库/出库 |
| | | // @Summary 入库/出库列表 |
| | | // @Summary 操作详情接口 |
| | | // @Produce application/json |
| | | // |
| | | // @Param id path string true "id" |
| | | // |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Param id path string true "id" |
| | | // @Param Authorization header string true "token" |
| | | // @Success 200 {object} util.Response{data=models.Operation} "成功" |
| | | // @Router /api-wms/v1/operation/getOperationInfo/{id} [get] |
| | | func (slf OperationController) GetOperationInfo(c *gin.Context) { |
| | | number := c.Param("id") |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing || operation.BaseOperationType == constvar.BaseOperationTypeInternal { //查询实时在库库存 |
| | | productIds := make([]string, 0) |
| | | locationIds := make([]int, 0) |
| | | for _, v := range operation.Details { |
| | | productIds = append(productIds, v.ProductId) |
| | | locationIds = append(locationIds, v.FromLocationID) |
| | | } |
| | | locationAmountMap, err := service.GetLocationAmounts(productIds, locationIds) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询产品库存错误") |
| | | return |
| | | } |
| | | for _, v := range operation.Details { |
| | | if locationAmountMap[v.ProductId] != nil { |
| | | v.StockAmount = locationAmountMap[v.ProductId][v.FromLocationID] |
| | | } |
| | | } |
| | | } |
| | | |
| | | util.ResponseFormat(c, code.Success, operation) |
| | | } |
| | | |
| | |
| | | // Code generated by swaggo/swag. DO NOT EDIT. |
| | | |
| | | // Package docs Code generated by swaggo/swag. DO NOT EDIT |
| | | package docs |
| | | |
| | | import "github.com/swaggo/swag" |
| | |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "入库/出库列表", |
| | | "summary": "操作详情接口", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/models.Operation" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | |
| | | "tags": [ |
| | | "入库/出库" |
| | | ], |
| | | "summary": "入库/出库列表", |
| | | "summary": "操作详情接口", |
| | | "parameters": [ |
| | | { |
| | | "type": "string", |
| | |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | }, |
| | | { |
| | | "type": "string", |
| | | "description": "token", |
| | | "name": "Authorization", |
| | | "in": "header", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/models.Operation" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | |
| | | name: id |
| | | required: true |
| | | type: string |
| | | - description: token |
| | | in: header |
| | | name: Authorization |
| | | required: true |
| | | type: string |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 入库/出库列表 |
| | | allOf: |
| | | - $ref: '#/definitions/util.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/models.Operation' |
| | | type: object |
| | | summary: 操作详情接口 |
| | | tags: |
| | | - 入库/出库 |
| | | /api-wms/v1/operation/getPersonnelList: |
| | |
| | | ProductIds []string |
| | | Ids []int |
| | | Query string |
| | | Fields string |
| | | } |
| | | |
| | | LocationProductAmountWithOperation struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) SetFields(fields string) *LocationProductAmountSearch { |
| | | slf.Fields = fields |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationProductAmountSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&LocationProductAmount{}) |
| | | |
| | |
| | | db = db.Where("warehouse_id = ?", slf.WarehouseId) |
| | | } |
| | | |
| | | if slf.Fields != "" { |
| | | db = db.Select(slf.Fields) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "github.com/shopspring/decimal" |
| | | "wms/models" |
| | | ) |
| | | |
| | | func GetLocationAmounts(productIds []string, locationIds []int) (locationAmountMap map[string]map[int]decimal.Decimal, err error) { |
| | | locationAmounts, err := models.NewLocationProductAmountSearch(). |
| | | SetProductIds(productIds).SetLocationIds(locationIds). |
| | | SetFields("product_id, location_id, amount"). |
| | | Find() |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | locationAmountMap = make(map[string]map[int]decimal.Decimal) |
| | | for _, locationAmount := range locationAmounts { |
| | | if locationAmountMap[locationAmount.ProductId] == nil { |
| | | locationAmountMap[locationAmount.ProductId] = make(map[int]decimal.Decimal) |
| | | } |
| | | locationAmountMap[locationAmount.ProductId][locationAmount.LocationId] = locationAmount.Amount |
| | | } |
| | | return |
| | | } |
| | |
| | | if locAmount.Amount.Equal(v.Amount) { |
| | | continue |
| | | } |
| | | if v.Amount.GreaterThan(locAmount.Amount) { |
| | | if v.Amount.GreaterThan(locAmount.Amount) { //todo 改成stockAmount |
| | | inputDetails = append(inputDetails, &models.OperationDetails{ |
| | | ProductId: v.ProductId, |
| | | Amount: v.Amount.Sub(locAmount.Amount), |