zhangqian
2024-04-07 a8914a16b23e93f6bfd12bcfd5cbe8b24cf7eb84
models/operation.go
@@ -14,7 +14,7 @@
      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)"`                     //源单号
      SourceNumber      string                   `json:"sourceNumber" gorm:"index;type:varchar(255)"`               //源单号
      OperationTypeId   int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"`   //作业类型id
      OperationTypeName string                   `json:"operationTypeName" gorm:"type:varchar(127);comment:作业类型名称"` //作业类型名称
      Status            constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`            //状态
@@ -22,18 +22,19 @@
      //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:安排日期"`
      ContacterID       int             `json:"contacterID" gorm:"type:int;comment:联系人ID"`
      ContacterName     string          `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"`
      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:备注"`
      LogisticCompanyId string          `json:"logisticCompanyId"   gorm:"type:varchar(191);comment:物流公司id"`
      LogisticCompany   LogisticCompany `json:"logisticCompany"      gorm:"foreignKey:LogisticCompanyId"`
      WaybillNumber     string          `json:"waybillNumber" gorm:"type:varchar(255);comment:运单号"`    //运单号
      Weight            decimal.Decimal `gorm:"type:decimal(20,2);comment:重量" json:"weight"`           //重量
      LogisticWeight    decimal.Decimal `gorm:"type:decimal(20,2);comment:物流重量" json:"logisticWeight"` //物流重量
      Source            string          `json:"source" gorm:"type:varchar(255);comment:来源系统,用于返回修改状态"`
      OperationDate     string                   `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"`
      ContacterID       int                      `json:"contacterID" gorm:"type:int;comment:联系人ID"`
      ContacterName     string                   `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"`
      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:备注"`
      LogisticCompanyId string                   `json:"logisticCompanyId"   gorm:"type:varchar(191);comment:物流公司id"`
      LogisticCompany   LogisticCompany          `json:"logisticCompany"      gorm:"foreignKey:LogisticCompanyId"`
      WaybillNumber     string                   `json:"waybillNumber" gorm:"type:varchar(255);comment:运单号"`    //运单号
      Weight            decimal.Decimal          `gorm:"type:decimal(20,2);comment:重量" json:"weight"`           //重量
      LogisticWeight    decimal.Decimal          `gorm:"type:decimal(20,2);comment:物流重量" json:"logisticWeight"` //物流重量
      Source            string                   `json:"source" gorm:"type:varchar(255);comment:来源系统,用于返回修改状态"`
      OperationSource   constvar.OperationSource `json:"operationSource" gorm:"type:tinyint(3);not null;default:0;comment:操作来源"` //操作来源
      Details           []*OperationDetails        `json:"details" gorm:"foreignKey:OperationID;references:Id"`
      BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:基础作业类型"` //基础作业类型
@@ -52,15 +53,16 @@
   OperationSearch struct {
      Operation
      Order    string
      PageNum  int
      PageSize int
      Keyword  string
      Orm      *gorm.DB
      Preload  bool
      Disuse   bool
      Ids      []int
      Numbers  []string
      Order               string
      PageNum             int
      PageSize            int
      Keyword             string
      Orm                 *gorm.DB
      Preload             bool
      Disuse              bool
      Ids                 []int
      SourceNumbers       []string
      SalesDetailsNumbers []string
   }
)
@@ -117,6 +119,11 @@
   return slf
}
func (slf *OperationSearch) SetSourceNumbers(numbers []string) *OperationSearch {
   slf.SourceNumbers = numbers
   return slf
}
func (slf *OperationSearch) SetDisuse(disuse bool) *OperationSearch {
   slf.Disuse = disuse
   return slf
@@ -142,6 +149,16 @@
   return slf
}
func (slf *OperationSearch) SetSalesDetailsNumbers(salesDetailsNumbers []string) *OperationSearch {
   slf.SalesDetailsNumbers = salesDetailsNumbers
   return slf
}
func (slf *OperationSearch) SetOperationSource(operationSource constvar.OperationSource) *OperationSearch {
   slf.OperationSource = operationSource
   return slf
}
func (slf *OperationSearch) build() *gorm.DB {
   var db = slf.Orm.Model(&Operation{})
@@ -158,6 +175,10 @@
   if slf.SourceNumber != "" {
      db = db.Where("source_number = ?", slf.SourceNumber)
   }
   if len(slf.SourceNumbers) > 0 {
      db = db.Where("source_number in (?)", slf.SourceNumbers)
   }
   if slf.Number != "" {
@@ -190,6 +211,14 @@
   if slf.SalesDetailsNumber != "" {
      db = db.Where("sales_details_number = ?", slf.SalesDetailsNumber)
   }
   if len(slf.SalesDetailsNumbers) > 0 {
      db = db.Where("sales_details_number in (?)", slf.SalesDetailsNumbers)
   }
   if slf.OperationSource != 0 {
      db = db.Where("operation_source = ?", slf.OperationSource)
   }
   return db
@@ -364,3 +393,13 @@
   }
   return int(total), nil
}
func (slf *OperationSearch) Count() (int64, error) {
   var (
      total int64
      db    = slf.build()
   )
   err := db.Count(&total).Error
   return total, err
}