zhangqian
2024-07-29 5c61bdb147458adbb0a87b27c2299f86f739da0a
新增出入库调拨操作时明细支持多单位传参
6个文件已修改
74 ■■■■■ 已修改文件
docs/docs.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation_details.go 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/operation.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go
@@ -5636,6 +5636,12 @@
                    "description": "是否调拨产生的出库",
                    "type": "boolean"
                },
                "moreUnitList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.UnitItems"
                    }
                },
                "operationId": {
                    "description": "操作记录id",
                    "type": "integer"
@@ -6947,6 +6953,12 @@
                    "description": "Unit        string          ` + "`" + `json:\"unit\"` + "`" + `                    //单位\nProduct models.Material ` + "`" + `json:\"product\" ` + "`" + ` // 产品",
                    "type": "integer"
                },
                "moreUnitList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.UnitItems"
                    }
                },
                "productId": {
                    "description": "产品id",
                    "type": "string"
docs/swagger.json
@@ -5625,6 +5625,12 @@
                    "description": "是否调拨产生的出库",
                    "type": "boolean"
                },
                "moreUnitList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.UnitItems"
                    }
                },
                "operationId": {
                    "description": "操作记录id",
                    "type": "integer"
@@ -6936,6 +6942,12 @@
                    "description": "Unit        string          `json:\"unit\"`                    //单位\nProduct models.Material `json:\"product\" ` // 产品",
                    "type": "integer"
                },
                "moreUnitList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.UnitItems"
                    }
                },
                "productId": {
                    "description": "产品id",
                    "type": "string"
docs/swagger.yaml
@@ -1118,6 +1118,10 @@
      isInternalOutput:
        description: 是否调拨产生的出库
        type: boolean
      moreUnitList:
        items:
          $ref: '#/definitions/models.UnitItems'
        type: array
      operationId:
        description: 操作记录id
        type: integer
@@ -2023,6 +2027,10 @@
          Unit        string          `json:"unit"`                    //单位
          Product models.Material `json:"product" ` // 产品
        type: integer
      moreUnitList:
        items:
          $ref: '#/definitions/models.UnitItems'
        type: array
      productId:
        description: 产品id
        type: string
models/operation.go
@@ -93,11 +93,12 @@
    return &OperationSearch{Orm: mysqlx.GetDB()}
}
func (slf *OperationSearch) BeforeCreate(tx *gorm.DB) {
func (slf *OperationSearch) BeforeCreate(tx *gorm.DB) error {
    for k := range slf.Details {
        slf.Details[k].BaseOperationType = slf.BaseOperationType
        slf.Details[k].DealerType = slf.DealerType
    }
    return nil
}
func (slf *OperationSearch) SetOrm(tx *gorm.DB) *OperationSearch {
models/operation_details.go
@@ -1,6 +1,7 @@
package models
import (
    "encoding/json"
    "fmt"
    "github.com/shopspring/decimal"
    "gorm.io/gorm"
@@ -39,6 +40,9 @@
        // 嘉联仓储添加 SilkMarket、SilkMarketClose
        SilkMarket      string `json:"silkMarket" gorm:"type:varchar(255);comment:庄口"`       // 庄口
        SilkMarketClose string `json:"silkMarketClose" gorm:"type:varchar(10);comment:庄口关闭"` // 庄口关闭
        MoreUnitList  []UnitItems `json:"moreUnitList" gorm:"-"`
        MoreUnitValue string      `json:"-" gorm:"type:varchar(255);comment:多单位值"`
    }
    OperationDetailsSearch struct {
@@ -62,6 +66,37 @@
    return &OperationDetailsSearch{Orm: mysqlx.GetDB()}
}
func (slf *OperationDetails) AfterFind(tx *gorm.DB) (err error) {
    if slf.MoreUnitValue != "" {
        var arr []UnitItems
        err := json.Unmarshal([]byte(slf.MoreUnitValue), &arr)
        if err != nil {
            return err
        }
        slf.MoreUnitList = arr
    }
    return
}
func (slf *OperationDetails) BeforeCreate(tx *gorm.DB) (err error) {
    if len(slf.MoreUnitList) != 0 {
        items := make([]UnitItems, 0)
        for k, item := range slf.MoreUnitList {
            if item.Unit != "" && !item.Amount.IsZero() {
                items = append(items, slf.MoreUnitList[k])
            }
        }
        str, err := json.Marshal(items)
        if err != nil {
            return err
        }
        slf.MoreUnitValue = string(str)
    }
    return
}
func (slf *OperationDetailsSearch) SetOrm(tx *gorm.DB) *OperationDetailsSearch {
    slf.Orm = tx
    return slf
request/operation.go
@@ -3,6 +3,7 @@
import (
    "github.com/shopspring/decimal"
    "wms/constvar"
    "wms/models"
)
type AddOperation struct {
@@ -62,6 +63,9 @@
    SalePrice       decimal.Decimal `json:"salePrice"`       //销售单价
    SilkMarket      string          `json:"silkMarket"`      // 庄口
    SilkMarketClose string          `json:"silkMarketClose"` // 庄口关闭
    MoreUnitList  []models.UnitItems `json:"moreUnitList" gorm:"-"`
    MoreUnitValue string             `json:"-" gorm:"type:varchar(255);comment:多单位值"`
}
type OperationList struct {