liujiandao
2023-09-21 840a11b1e17a743fbcc0e566639d718e2559be48
models/operation.go
@@ -2,7 +2,6 @@
import (
   "fmt"
   "github.com/shopspring/decimal"
   "gorm.io/gorm"
   "wms/constvar"
   "wms/pkg/mysqlx"
@@ -13,25 +12,28 @@
   Operation struct {
      WmsModel
      Id              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
      Number          string                   `json:"number" gorm:"type:varchar(255)"`                         //单号
      SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //源单号
      OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id
      Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`          //状态
      FromLocationId  int                      `json:"fromLocationId"   gorm:"type:int;not null;comment:源位置id"` //源位置id
      FromLocation    Location                 `json:"fromLocation"     gorm:"foreignKey:FromLocationId"`       //源位置
      ToLocationId    int                      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"` //目标位置id
      ToLocation      Location                 `json:"toLocation"      gorm:"foreignKey:ToLocationId"`          //目标位置
      Number          string                   `json:"number" gorm:"type:varchar(255)"`                                 //单号
      SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                           //源单号
      OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"`         //作业类型id
      Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`                  //状态
      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"`    //目标位置
      OperationDate   string                   `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"`
      CarrierID       int                      `json:"carrierID" gorm:"type:int;comment:承运商ID"`
      CarrierName     string                   `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"`
      Tracking        string                   `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"`
      ContacterID     int                      `json:"contacterID" gorm:"type:int;comment:联系人ID"`
      ContacterName   string                   `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"`
      Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"`
      TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"`
      CompanyID       int                      `json:"companyID" gorm:"type:int;comment:公司ID"`
      CompanyName     string                   `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"`
      Details         []*OperationDetails      `json:"details"`
      CompanyID       int                      `json:"companyID" gorm:"type:int;comment:公司ID-客户"`
      CompanyName     string                   `json:"companyName" gorm:"type:varchar(127);comment:公司名称-客户"`
      Comment         string                   `json:"comment" gorm:"type:text;comment:备注"`
      Details []*OperationDetails `json:"details" gorm:"foreignKey:OperationID;references:Id"`
      //Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"`
      //TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"`
      //CarrierID       int                      `json:"carrierID" gorm:"type:int;comment:承运商ID"`
      //CarrierName     string                   `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"`
      //Tracking        string                   `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"`
   }
   OperationSearch struct {
@@ -68,15 +70,15 @@
   return slf
}
func (slf *OperationSearch) SetID(id int) *OperationSearch {
   slf.Id = id
func (slf *OperationSearch) SetID(ID int) *OperationSearch {
   slf.Id = ID
   return slf
}
//func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch {
//   slf.Keyword = keyword
//   return slf
//}
func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch {
   slf.Keyword = keyword
   return slf
}
func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch {
   slf.OperationTypeId = operationTypeId
@@ -91,8 +93,8 @@
func (slf *OperationSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&Operation{})
   if slf.Id != 0 {
      db = db.Where("id = ?", slf.Id)
   if slf.ID != 0 {
      db = db.Where("id = ?", slf.ID)
   }
   if slf.Order != "" {
      db = db.Order(slf.Order)
@@ -107,7 +109,7 @@
   }
   if slf.Preload {
      db = db.Model(&Operation{}).Preload("Details")
      db = db.Model(&Operation{}).Preload("Details").Preload("FromLocation").Preload("ToLocation")
   }
   return db