zhangqian
2024-07-05 d91f181819984ed68d928bec6e926da6566e7a3f
当操作为出库或调拨时,操作详情明细返回产品相应位置的实时库存
1个文件已添加
6个文件已修改
128 ■■■■ 已修改文件
controllers/operation.go 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/location_product_amount.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/location_amount.go 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/operation.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/operation.go
@@ -287,12 +287,11 @@
// 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")
@@ -306,6 +305,26 @@
        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)
}
docs/docs.go
@@ -1,5 +1,4 @@
// 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"
@@ -2032,7 +2031,7 @@
                "tags": [
                    "入库/出库"
                ],
                "summary": "入库/出库列表",
                "summary": "操作详情接口",
                "parameters": [
                    {
                        "type": "string",
@@ -2040,13 +2039,32 @@
                        "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"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
docs/swagger.json
@@ -2020,7 +2020,7 @@
                "tags": [
                    "入库/出库"
                ],
                "summary": "入库/出库列表",
                "summary": "操作详情接口",
                "parameters": [
                    {
                        "type": "string",
@@ -2028,13 +2028,32 @@
                        "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"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
docs/swagger.yaml
@@ -3669,14 +3669,24 @@
        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:
models/location_product_amount.go
@@ -36,6 +36,7 @@
        ProductIds  []string
        Ids         []int
        Query       string
        Fields      string
    }
    LocationProductAmountWithOperation struct {
@@ -131,6 +132,11 @@
    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{})
@@ -181,6 +187,10 @@
        db = db.Where("warehouse_id = ?", slf.WarehouseId)
    }
    if slf.Fields != "" {
        db = db.Select(slf.Fields)
    }
    return db
}
service/location_amount.go
New file
@@ -0,0 +1,24 @@
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
}
service/operation.go
@@ -336,7 +336,7 @@
            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),