liujiandao
2024-03-11 318c49da20ec30c4f85ef35e479499e82a841b25
models/operation_details.go
@@ -11,12 +11,18 @@
   // OperationDetails 操作明细表
   OperationDetails struct {
      WmsModel
      Id          int             `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
      OperationID int             `json:"operationId" gorm:"type:int;not null;comment:操作记录id"`        //操作id
      ProductId   string          `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"`   //产品id
      ProductName string          `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"` //产品名称
      Amount      decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:数量"`       //数量
      Unit        string          `json:"unit" gorm:"type:varchar(31);comment:单位"`
      Id          int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
      OperationID int    `json:"operationId" gorm:"type:int;not null;comment:操作记录id"`      //操作id
      ProductId   string `json:"productId" gorm:"type:varchar(191);not null;comment:产品id"` //产品id
      //ProductName string          `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"` //产品名称
      Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:数量"` //数量
      //Unit        string          `json:"unit" gorm:"type:varchar(31);comment:单位"`                    //单位
      Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"`
      FromLocationID int      `json:"fromLocationId"   gorm:"type:int;not null;comment:源位置id"`         //源位置id
      FromLocation   Location `json:"fromLocation"     gorm:"foreignKey:FromLocationID;references:Id"` //源位置
      ToLocationID   int      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"`         //目标位置id
      ToLocation     Location `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"`    //目标位置
   }
   OperationDetailsSearch struct {
@@ -73,6 +79,11 @@
   return slf
}
func (slf *OperationDetailsSearch) SetProductId(productId string) *OperationDetailsSearch {
   slf.ProductId = productId
   return slf
}
func (slf *OperationDetailsSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&OperationDetails{})
@@ -91,6 +102,12 @@
   if slf.OperationID != 0 {
      db = db.Where("operation_id = ?", slf.OperationID)
   }
   if slf.ProductId != "" {
      db = db.Where("product_id = ?", slf.ProductId)
   }
   if slf.Preload {
      db = db.Preload("Product")
   }
   return db
}